Improved handling of race icons (fixes #2030)
* The editor_icon= key will now be respected in the Unit Preview Pane * If no appropriate icon is found, a generic icon will be used instead, in both the editor and unit preview pane.
This commit is contained in:
parent
8903ea9446
commit
207e763401
4 changed files with 35 additions and 6 deletions
|
@ -50,11 +50,7 @@ void unit_palette::setup(const config& /*cfg*/)
|
|||
config cfg;
|
||||
cfg["id"] = i.second.id();
|
||||
cfg["name"] = i.second.plural_name();
|
||||
if(i.second.editor_icon().empty()) {
|
||||
cfg["icon"] = "icons/unit-groups/race_" + i.second.id();
|
||||
} else {
|
||||
cfg["icon"] = i.second.editor_icon();
|
||||
}
|
||||
cfg["icon"] = i.second.get_icon_path_stem();
|
||||
cfg["core"] = true;
|
||||
groups_.emplace_back(cfg);
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ void unit_preview_pane::set_displayed_type(const unit_type& type)
|
|||
}
|
||||
|
||||
if(icon_race_) {
|
||||
icon_race_->set_label("icons/unit-groups/race_" + type.race_id() + "_30.png");
|
||||
icon_race_->set_label(type.race()->get_icon_path_stem() + "_30.png");
|
||||
}
|
||||
|
||||
if(icon_alignment_) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "units/race.hpp"
|
||||
|
||||
#include "filesystem.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "serialization/unicode_cast.hpp"
|
||||
|
@ -145,3 +146,20 @@ unit_race::GENDER string_gender(const std::string& str, unit_race::GENDER def) {
|
|||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
std::string unit_race::get_icon_path_stem() const
|
||||
{
|
||||
if(!icon_.empty()) {
|
||||
return icon_;
|
||||
}
|
||||
|
||||
std::string path = "icons/unit-groups/race_" + id_;
|
||||
|
||||
// FIXME: hardcoded '30' is bad...
|
||||
if(!filesystem::file_exists(filesystem::get_binary_file_location("images", path + "_30.png"))) {
|
||||
std::cerr << "path not found: " << "images/" + path + "_30.png" << std::endl;
|
||||
path = "icons/unit-groups/race_custom";
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,21 @@ public:
|
|||
unsigned int num_traits() const;
|
||||
const std::string& undead_variation() const { return undead_variation_; }
|
||||
|
||||
/**
|
||||
* Gets this race's icon path without state/size suffix and extension.
|
||||
*
|
||||
* This doesn't return the full path. Its output looks something like this:
|
||||
* @c icons/unit-groups/race_elf
|
||||
*
|
||||
* This is because this output is used in the editor for a GUI1 button's icon,
|
||||
* and GUI1 automatically appends the state extension, such as "_30-pressed.png"
|
||||
*
|
||||
* If a custom icon has been provided, that is used. Else, it checks if an
|
||||
* appropriate icon exists in icons/unit-groups/. If not, a generic custom race
|
||||
* icon will be used.
|
||||
*/
|
||||
std::string get_icon_path_stem() const;
|
||||
|
||||
/// Dummy race used when a race is not yet known.
|
||||
static const unit_race null_race;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue