diff --git a/data/themes/_initial.cfg b/data/themes/_initial.cfg index d3e70e3df887..9ad749f2f545 100644 --- a/data/themes/_initial.cfg +++ b/data/themes/_initial.cfg @@ -391,7 +391,7 @@ #define COUNTDOWN_THEME_STATUS FONT_SMALL_SIZE [report_countdown] - id=report_timeout + id=report_countdown font_size={FONT_SMALL_SIZE} ref=timeout-box-center rect="=,=-3,+80,+20" diff --git a/data/themes/default.cfg b/data/themes/default.cfg index c684f1b6c3f2..92ca92f5cb45 100644 --- a/data/themes/default.cfg +++ b/data/themes/default.cfg @@ -501,6 +501,19 @@ [/unit_weapons] [/status] + # If the device has no battery, remove the battery charge indicator + # and move the timer to its position. + [no_battery] + [remove] + id=battery + [/remove] + [change] + id=report_countdown + ref=battery-box-center + rect="=+5,=-3,+80,+18" + [/change] + [/no_battery] + {REPLAY_THEME {DEFAULT_FONT_SMALL}} [/resolution] diff --git a/src/reports.cpp b/src/reports.cpp index 5587d7a456f1..d595909e9f54 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -1569,10 +1569,8 @@ REPORT_GENERATOR(battery, /*rc*/) { config report; - if(desktop::battery_info::does_device_have_battery()) { - add_image(report, game_config::images::battery_icon, ""); - add_text(report, (boost::format("%.0f %%") % desktop::battery_info::get_battery_percentage()).str(), _("Battery")); - } + add_image(report, game_config::images::battery_icon, ""); + add_text(report, (boost::format("%.0f %%") % desktop::battery_info::get_battery_percentage()).str(), _("Battery")); return report; } diff --git a/src/theme.cpp b/src/theme.cpp index 5876e9d99f9a..a888775ec614 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -26,6 +26,7 @@ #include "serialization/string_utils.hpp" #include "wml_exception.hpp" +#include #include static lg::log_domain log_display("display"); @@ -460,19 +461,6 @@ theme::status_item::status_item(const config& cfg) } } -SDL_Rect& theme::countdown::location(const SDL_Rect& screen) const -{ - if(!desktop::battery_info::does_device_have_battery()) { - const object* battery = display::get_singleton()->get_theme(). - get_status_item("battery"); - if(battery != nullptr) { - return battery->location(screen); - } - } - - return status_item::location(screen); -} - theme::panel::panel(const config& cfg) : object(cfg) , image_(cfg["image"]) @@ -708,11 +696,7 @@ void theme::add_object(const config& cfg) if(const config& status_cfg = cfg.child("status")) { for(const config::any_child& i : status_cfg.all_children_range()) { - if(i.key != "report_countdown") { - status_[i.key].reset(new status_item(i.cfg)); - } else { - status_[i.key].reset(new countdown(i.cfg)); - } + status_[i.key].reset(new status_item(i.cfg)); } if(const config& unit_image_cfg = status_cfg.child("unit_image")) { unit_image_ = object(unit_image_cfg); @@ -771,40 +755,54 @@ void theme::add_object(const config& cfg) if(const config& c = cfg.child("main_map_border")) { border_ = border_t(c); } + + if(!desktop::battery_info::does_device_have_battery()) { + if(const config& c = cfg.child("no_battery")) { + modify(c); + } + } } void theme::remove_object(const std::string& id) { - for(std::vector::iterator p = panels_.begin(); p != panels_.end(); ++p) { + if(status_.erase(id) > 0u) { + return; + } + + for(auto p = panels_.begin(); p != panels_.end(); ++p) { if(p->get_id() == id) { panels_.erase(p); return; } } - for(std::vector::iterator l = labels_.begin(); l != labels_.end(); ++l) { + for(auto l = labels_.begin(); l != labels_.end(); ++l) { if(l->get_id() == id) { labels_.erase(l); return; } } - for(std::vector::iterator m = menus_.begin(); m != menus_.end(); ++m) { + for(auto m = menus_.begin(); m != menus_.end(); ++m) { if(m->get_id() == id) { menus_.erase(m); return; } } - for(std::vector::iterator a = actions_.begin(); a != actions_.end(); ++a) { + for(auto a = actions_.begin(); a != actions_.end(); ++a) { if(a->get_id() == id) { actions_.erase(a); return; } } - for(std::vector::iterator s = sliders_.begin(); s != sliders_.end(); ++s) { + for(auto s = sliders_.begin(); s != sliders_.end(); ++s) { if(s->get_id() == id) { sliders_.erase(s); return; } } + + std::stringstream stream; + stream << "theme object " << id << " not found"; + throw config::error(stream.str()); } void theme::set_object_location(theme::object& element, std::string rect_str, std::string ref_id) @@ -869,6 +867,12 @@ theme::object& theme::find_element(const std::string& id) { static theme::object empty_object; theme::object* res = &empty_object; + + auto status_item_it = status_.find(id); + if(status_item_it != status_.end()) { + res = status_item_it->second.get(); + } + for(std::vector::iterator p = panels_.begin(); p != panels_.end(); ++p) { if(p->get_id() == id) { res = &(*p); diff --git a/src/theme.hpp b/src/theme.hpp index 495cc2fc794c..9c05339ecbc9 100644 --- a/src/theme.hpp +++ b/src/theme.hpp @@ -142,15 +142,6 @@ class theme color_t font_rgb_; }; - class countdown : public status_item - { - public: - explicit countdown(const config& cfg) : status_item(cfg) - {} - - SDL_Rect& location(const SDL_Rect& screen) const override; - }; - class panel : public object { public: