Better implementation of placing the clock (resolves #3582)
This commit is contained in:
parent
42853719b4
commit
e9a6b95fd8
5 changed files with 43 additions and 37 deletions
|
@ -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"
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "serialization/string_utils.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
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<theme::panel>::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<theme::label>::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<theme::menu>::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<theme::action>::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<theme::slider>::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<theme::panel>::iterator p = panels_.begin(); p != panels_.end(); ++p) {
|
||||
if(p->get_id() == id) {
|
||||
res = &(*p);
|
||||
|
|
|
@ -142,15 +142,6 @@ public:
|
|||
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue