-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
item_palette.cpp
97 lines (77 loc) · 2.44 KB
/
item_palette.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright (C) 2012 - 2018 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Manage the item-palette in the editor.
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "editor/palette/item_palette.hpp"
#include "gettext.hpp"
#include "game_config_view.hpp"
#include <string>
namespace editor {
std::string item_palette::get_help_string()
{
return selected_fg_item().name;
}
void item_palette::setup(const game_config_view& cfg)
{
for(const config& group : cfg.child_range("item_group")) {
groups_.emplace_back(group);
for(const config& item : group.child_range("item")) {
item_map_.emplace(item["id"], overlay(item));
group_map_[group["id"]].push_back(item["id"]);
if(!group["core"].to_bool(false))
non_core_items_.insert(item["id"]);
}
nmax_items_ = std::max<int>(nmax_items_, group_map_[group["id"]].size());
}
select_fg_item("anvil");
select_bg_item("altar");
// Set the default group
set_group("items");
if(active_group().empty()) {
ERR_ED << "No items found." << std::endl;
}
}
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text)
{
std::stringstream filename;
filename << item.image;
if(item.image.empty()) {
filename << item.halo;
}
image = image::get_image(filename.str());
if(image == nullptr) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for item type: '" << filename.str() << "' not found" << std::endl;
image = image::get_image(game_config::images::missing);
if(image == nullptr) {
ERR_ED << "Placeholder image not found" << std::endl;
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image = scale_surface(image, item_size_, item_size_);
}
tooltip_text << item.name;
}
item_palette::item_palette(editor_display &gui, const game_config_view& cfg,
editor_toolkit &toolkit)
//TODO avoid magic numbers
: editor_palette<overlay>(gui, cfg, 36, 4, toolkit)
{
}
const std::string& item_palette::get_id(const overlay& item)
{
return item.id;
}
}