The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
item_palette.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Fabian Mueller <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * Manage the item-palette in the editor.
17  */
18 
19 #define GETTEXT_DOMAIN "wesnoth-editor"
20 
21 #include "item_palette.hpp"
22 #include "gettext.hpp"
23 
24 #include <string>
25 
26 namespace editor {
27 
29 {
30  return selected_fg_item().name;
31 }
32 
33 void item_palette::setup(const config& cfg)
34 {
35 
36  for (const config& group : cfg.child_range("item_group")) {
37 
38  groups_.push_back(item_group(group));
39 
40  for (const config& item : group.child_range("item")) {
41 
42  item_map_.insert(std::pair<std::string, overlay>(item["id"], overlay(item)));
43  group_map_[group["id"]].push_back(item["id"]);
44  if (!group["core"].to_bool(false))
45  non_core_items_.insert(item["id"]);
46  }
47  nmax_items_ = std::max<int>(nmax_items_, group_map_[group["id"]].size());
48  }
49 
50  select_fg_item("anvil");
51  select_bg_item("altar");
52 
53  // Set the default group
54  set_group("items");
55 
56  if(active_group().empty()) {
57  ERR_ED << "No items found." << std::endl;
58  }
59 }
60 
61 void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text)
62 {
63 
64  std::stringstream filename;
65  filename << item.image;
66  if (item.image.empty())
67  filename << item.halo;
68 
69  image = image::get_image(filename.str());
70  if(image == nullptr) {
71  tooltip_text << "IMAGE NOT FOUND\n";
72  ERR_ED << "image for item type: '" << filename.str() << "' not found" << std::endl;
74  if (image == nullptr) {
75  ERR_ED << "Placeholder image not found" << std::endl;
76  return;
77  }
78  }
79 
80  if(image->w != item_size_ || image->h != item_size_) {
81  image.assign(scale_surface(image,
83  }
84 
85  tooltip_text << item.name;
86 }
87 
89  mouse_action** active_mouse_action)
90 //TODO avoid magic numbers
91  : editor_palette<overlay>(gui, cfg, 36, 4, active_mouse_action)
92 {
93 }
94 
96 {
97  return item.id;
98 }
99 
100 
101 }
102 
virtual void draw_item(const overlay &item, surface &image, std::stringstream &tooltip_text)
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:878
child_itors child_range(const std::string &key)
Definition: config.cpp:613
const overlay & selected_fg_item() const
Return the currently selected foreground/background item.
item_palette(editor_display &gui, const config &cfg, mouse_action **active_mouse_action)
virtual void select_bg_item(const std::string &item_id)
virtual void select_fg_item(const std::string &item_id)
Select a foreground item.
Stores the info about the groups in a nice format.
virtual const std::string & get_id(const overlay &item)
virtual void setup(const config &cfg)
Setup the internal data structure.
General purpose widgets.
const std::vector< std::string > & active_group()
surface scale_surface(const surface &surf, int w, int h)
Definition: utils.cpp:443
std::string id
Definition: overlay.hpp:40
std::map< std::string, std::vector< std::string > > group_map_
t_string name
Definition: overlay.hpp:39
Manage the empty-palette in the editor.
Definition: action.cpp:28
std::set< std::string > non_core_items_
std::string halo
Definition: overlay.hpp:37
GLboolean GLuint group
Definition: glew.h:2589
virtual std::string get_help_string()
#define ERR_ED
this module manages the cache of images.
Definition: image.cpp:75
void assign(const surface &o)
Definition: utils.hpp:83
std::vector< item_group > groups_
The editor_groups as defined in editor-groups.cfg.
A mouse action receives events from the controller, and responds to them by creating an appropriate e...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::string image
Definition: overlay.hpp:36