The Battle for Wesnoth  1.17.6+dev
item_palette.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2022
3  by Fabian Mueller <fabianmueller5@gmx.de>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * Manage the item-palette in the editor.
18  */
19 
20 #define GETTEXT_DOMAIN "wesnoth-editor"
21 
23 #include "gettext.hpp"
24 #include "game_config_view.hpp"
25 
26 #include <string>
27 
28 namespace editor {
29 
31 {
32  return selected_fg_item().name;
33 }
34 
36 {
37  for(const config& group : cfg.child_range("item_group")) {
38  groups_.emplace_back(group);
39 
40  for(const config& item : group.child_range("item")) {
41  item_map_.emplace(item["id"], overlay(item));
42  group_map_[group["id"]].push_back(item["id"]);
43  if(!group["core"].to_bool(false))
44  non_core_items_.insert(item["id"]);
45  }
46  }
47 
48  select_fg_item("anvil");
49  select_bg_item("altar");
50 
51  // Set the default group
52  set_group("items");
53 
54  if(active_group().empty()) {
55  ERR_ED << "No items found.";
56  }
57 }
58 
60  const overlay& item,
61  texture& base_image,
62  texture& /*overlay_image*/,
63  std::stringstream& tooltip_text)
64 {
65  std::stringstream filename;
66  filename << item.image;
67  if(item.image.empty()) {
68  filename << item.halo;
69  }
70 
71  base_image = image::get_texture(filename.str());
72  if(!base_image) {
73  tooltip_text << "IMAGE NOT FOUND\n";
74  ERR_ED << "image for item type: '" << filename.str() << "' not found";
76  if(!base_image) {
77  ERR_ED << "Placeholder image not found";
78  return;
79  }
80  }
81 
82  tooltip_text << item.name;
83 }
84 
86  editor_toolkit &toolkit)
87 //TODO avoid magic numbers
88  : editor_palette<overlay>(gui, cfg, 36, 4, toolkit)
89 {
90 }
91 
92 const std::string& item_palette::get_id(const overlay& item)
93 {
94  return item.id;
95 }
96 
97 }
virtual void select_fg_item(const std::string &item_id) override
Select a foreground item.
virtual void select_bg_item(const std::string &item_id) override
virtual const std::string & get_id(const overlay &item)
config_array_view child_range(config_key_type key) const
General purpose widgets.
void set_group(std::size_t index) override
const std::vector< std::string > & active_group()
virtual void setup(const game_config_view &cfg)
Setup the internal data structure.
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:32
std::string id
Definition: overlay.hpp:59
item_palette(editor_display &gui, const game_config_view &cfg, editor_toolkit &toolkit)
std::map< std::string, std::vector< std::string > > group_map_
t_string name
Definition: overlay.hpp:58
Manage the empty-palette in the editor.
Definition: action.cpp:30
std::set< std::string > non_core_items_
std::string halo
Definition: overlay.hpp:56
const overlay & selected_fg_item() const
Return the currently selected foreground/background item.
virtual std::string get_help_string()
#define ERR_ED
std::vector< item_group > groups_
The editor_groups as defined in editor-groups.cfg.
virtual void setup_item(const overlay &item, texture &item_base_image, texture &item_overlay_image, std::stringstream &tooltip)
Setup item image and tooltip.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
Definition: picture.cpp:1136
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:414
std::string image
Definition: overlay.hpp:55