Skip to content

Commit

Permalink
Include battery percentage into GUI and add 2 versions of battery icon
Browse files Browse the repository at this point in the history
  • Loading branch information
hrubymar10 authored and jyrkive committed Oct 30, 2018
1 parent 0dfa442 commit de183ee
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
Binary file added data/core/images/themes/battery-bw-lighting-bolt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/core/images/themes/battery-bw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/core/images/themes/battery-lighting-bolt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/core/images/themes/battery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/themes/_initial.cfg
Expand Up @@ -386,7 +386,7 @@
#enddef

#define COUNTDOWN_THEME
{STATUS_BOX_BORDERLESS +3 =+0 +90 +15 timeout income-box-topright fixed fixed}
{STATUS_BOX_BORDERLESS +3 =+0 +90 +15 timeout battery-box-topright fixed fixed}
[label]
id=time-icon
#icon=themes/units.png
Expand Down
35 changes: 35 additions & 0 deletions data/themes/classic.cfg
Expand Up @@ -169,6 +169,13 @@
xanchor=fixed
yanchor=fixed
[/panel]
[panel]
id=battery-panel
image=themes/legacy/status-bg.png
rect="+5,=,+85,="
xanchor=fixed
yanchor=fixed
[/panel]

# {COUNTDOWN_THEME}
[panel]
Expand Down Expand Up @@ -253,6 +260,15 @@
xanchor=fixed
yanchor=fixed
[/label]
[label]
id=battery-icon
icon=themes/battery.png
text= _ "battery"
ref=battery-panel
rect="=+5,=+1,+25,+17"
xanchor=fixed
yanchor=fixed
[/label]

[status]
# the time of day image
Expand Down Expand Up @@ -333,6 +349,16 @@
prefix="" #wmllint: ignore
prefix_literal=""
[/income]
[battery]
id=status-battery
font_size={DEFAULT_FONT_SMALL}
ref=battery-icon
rect="+4,=,+50,+16"
xanchor=fixed
yanchor=fixed
prefix="" #wmllint: ignore
prefix_literal=""
[/battery]

{COUNTDOWN_THEME_STATUS {DEFAULT_FONT_SMALL}}

Expand Down Expand Up @@ -597,6 +623,10 @@
id=income-panel
rect="+5,=,+55,="
[/change]
[change]
id=battery-panel
rect="+5,=,+55,="
[/change]
[change]
id=turn
rect="+4,=,+55,+16"
Expand Down Expand Up @@ -627,6 +657,11 @@
rect="+4,=,+50,+16"
font_size={DEFAULT_FONT_TINY}
[/change]
[change]
id=status-battery
rect="+4,=,+40,+16"
font_size={DEFAULT_FONT_TINY}
[/change]
[change]
id=timeout-panel
rect="+5,=,+75,="
Expand Down
26 changes: 26 additions & 0 deletions data/themes/default.cfg
Expand Up @@ -108,6 +108,7 @@
{STATUS_BOX_BORDERLESS +3 =+0 +65 +15 units villages-box-topright fixed fixed}
{STATUS_BOX_BORDERLESS +3 =+0 +85 +15 upkeep units-box-topright fixed fixed}
{STATUS_BOX_BORDERLESS +3 =+0 +85 +15 income upkeep-box-topright fixed fixed}
{STATUS_BOX_BORDERLESS +3 =+0 +85 +15 battery income-box-topright fixed fixed}
{COUNTDOWN_THEME}
[menu]
is_context_menu=true
Expand Down Expand Up @@ -216,6 +217,15 @@
xanchor=fixed
yanchor=fixed
[/label]
[label]
id=battery-icon
icon=themes/battery.png
text= _ "battery"
ref=battery-box-center
rect="=+1,=-1,+17,+17"
xanchor=fixed
yanchor=fixed
[/label]

[status]
# The size of these rectangles only accommodates hex coordinates
Expand Down Expand Up @@ -345,6 +355,16 @@
prefix="" #wmllint: ignore
prefix_literal=""
[/income]
[battery]
id=status-battery
font_size={DEFAULT_FONT_SMALL}
ref=battery-icon
rect="+4,=-2,+60,+16"
xanchor=fixed
yanchor=fixed
prefix="" #wmllint: ignore
prefix_literal=""
[/battery]

{COUNTDOWN_THEME_STATUS {DEFAULT_FONT_SMALL}}

Expand Down Expand Up @@ -569,6 +589,7 @@
{CHANGE_STATUS_BOX +1 =+0 +45 +15 units villages-box-topright}
{CHANGE_STATUS_BOX +1 =+0 +60 +15 upkeep units-box-topright}
{CHANGE_STATUS_BOX +1 =+0 +55 +15 income upkeep-box-topright}
{CHANGE_STATUS_BOX +1 =+0 +55 +15 battery income-box-topright}

[change]
id=menu-main
Expand Down Expand Up @@ -612,6 +633,11 @@
rect="+4,=+1,+50,+{DEFAULT_FONT_TINY_HEIGHT}"
font_size={DEFAULT_FONT_TINY}
[/change]
[change]
id=status-battery
rect="+4,=+1,+40,+{DEFAULT_FONT_TINY_HEIGHT}"
font_size={DEFAULT_FONT_TINY}
[/change]
[change]
id=timeout-panel
rect="+5,=,+75,="
Expand Down
1 change: 1 addition & 0 deletions src/game_display.cpp
Expand Up @@ -370,6 +370,7 @@ void game_display::draw_sidebar()
return;

refresh_report("report_clock");
refresh_report("report_battery");
refresh_report("report_countdown");

if (invalidateGameStatus_)
Expand Down
14 changes: 14 additions & 0 deletions src/reports.cpp
Expand Up @@ -14,6 +14,7 @@

#include "actions/attack.hpp"
#include "attack_prediction.hpp"
#include "desktop/battery_info.hpp"
#include "font/pango/escape.hpp"
#include "font/text_formatting.hpp"
#include "formatter.hpp"
Expand All @@ -35,6 +36,7 @@
#include <ctime>
#include <iomanip>
#include <boost/dynamic_bitset.hpp>
#include <boost/lexical_cast.hpp>

static void add_text(config &report, const std::string &text,
const std::string &tooltip, const std::string &help = "")
Expand Down Expand Up @@ -1552,6 +1554,18 @@ REPORT_GENERATOR(report_clock, /*rc*/)
return text_report(ss.str(), _("Clock"));
}


REPORT_GENERATOR(battery, /*rc*/)
{
std::ostringstream ss;
std::string battery = "";
if (desktop::battery_info::does_device_have_battery()) {
ss << boost::lexical_cast<std::string>(desktop::battery_info::get_battery_percentage()) + "%";
}

return text_report(ss.str(), _("Battery"));
}

REPORT_GENERATOR(report_countdown, rc)
{
int viewing_side = rc.screen().viewing_side();
Expand Down

0 comments on commit de183ee

Please sign in to comment.