Skip to content

Commit 4573a7b

Browse files
author
s.kushnirenko
committed
ui: redesigned tax collector window info
1 parent dc77e65 commit 4573a7b

12 files changed

+187
-121
lines changed

src/building/building.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "building/building_bazaar.h"
1010
#include "building/building_firehouse.h"
1111
#include "building_architect_post.h"
12+
#include "building/building_tax_collector.h"
1213
#include "building/storage_yard.h"
1314
#include "building/building_brewery.h"
1415
#include "building/monument_mastaba.h"
@@ -332,6 +333,10 @@ building_impl *building::dcast() {
332333
case BUILDING_POTTERY_WORKSHOP: _ptr = new building_pottery(*this); break;
333334
case BUILDING_WELL: _ptr = new building_well(*this); break;
334335
case BUILDING_BREWERY_WORKSHOP: _ptr = new building_brewery(*this); break;
336+
case BUILDING_TAX_COLLECTOR:
337+
case BUILDING_TAX_COLLECTOR_UPGRADED:
338+
_ptr = new building_tax_collector(*this);
339+
break;
335340

336341
case BUILDING_SHRINE_OSIRIS:
337342
case BUILDING_SHRINE_RA:
@@ -504,7 +509,6 @@ e_overlay building::get_overlay() const {
504509
case BUILDING_FIREHOUSE: return OVERLAY_FIRE;
505510
case BUILDING_POLICE_STATION: return OVERLAY_CRIME;
506511
case BUILDING_APOTHECARY: return OVERLAY_APOTHECARY;
507-
case BUILDING_TAX_COLLECTOR: return OVERLAY_TAX_INCOME;
508512
case BUILDING_WATER_SUPPLY: return OVERLAY_WATER;
509513
case BUILDING_COURTHOUSE: return OVERLAY_COUTHOUSE;
510514
case BUILDING_SCRIBAL_SCHOOL: return OVERLAY_SCRIBAL_SCHOOL;

src/building/building_tax_collector.cpp

+43-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "building/building.h"
44
#include "city/object_info.h"
5+
#include "figure/figure.h"
56
#include "game/resource.h"
67
#include "graphics/elements/panel.h"
78
#include "graphics/view/view.h"
@@ -13,38 +14,62 @@
1314
#include "sound/sound_building.h"
1415
#include "game/game.h"
1516

16-
void building_tax_collector_draw_info(object_info* c) {
17-
painter ctx = game.painter();
18-
c->help_id = e_text_building_tax_collector;
19-
window_building_play_sound(c, snd::get_building_info_sound("tax_collector"));
20-
outer_panel_draw(c->offset, c->width_blocks, c->height_blocks);
21-
lang_text_draw_centered(106, 0, c->offset.x, c->offset.y + 10, 16 * c->width_blocks, FONT_LARGE_BLACK_ON_LIGHT);
22-
ImageDraw::img_generic(ctx, image_id_resource_icon(RESOURCE_DEBEN), c->offset.x + 16, c->offset.y + 36);
17+
void building_tax_collector::window_info_background(object_info &c) {
18+
ui::begin_window(c.offset);
2319

24-
building* b = building_get(c->building_id);
25-
int width = lang_text_draw(106, 2, c->offset.x + 44, c->offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
20+
c.help_id = e_text_building_tax_collector;
21+
c.go_to_advisor.left_a = ADVISOR_RATINGS;
22+
c.go_to_advisor.left_b = ADVISOR_FINANCIAL;
23+
24+
window_building_play_sound(&c, snd::get_building_info_sound("tax_collector"));
25+
26+
{
27+
ui::panel(vec2i{0, 0}, {c.width_blocks, c.height_blocks}, UiFlags_PanelOuter);
28+
ui::label(106, 0, vec2i{0, 10}, 16 * c.width_blocks, FONT_LARGE_BLACK_ON_LIGHT, UiFlags_LabelCentered);
29+
ui::icon(vec2i{16, 36}, RESOURCE_DEBEN);
30+
}
31+
32+
building* b = building_get(c.building_id);
33+
int width = lang_text_draw(106, 2, c.offset.x + 44, c.offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
2634
if (config_get(CONFIG_GP_CH_NEW_TAX_COLLECTION_SYSTEM)) {
27-
lang_text_draw_amount(8, 0, b->deben_storage, c->offset.x + 44 + width, c->offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
35+
lang_text_draw_amount(8, 0, b->deben_storage, c.offset.x + 44 + width, c.offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
2836
} else {
29-
lang_text_draw_amount(8, 0, b->tax_income_or_storage, c->offset.x + 44 + width, c->offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
37+
lang_text_draw_amount(8, 0, b->tax_income_or_storage, c.offset.x + 44 + width, c.offset.y + 43, FONT_NORMAL_BLACK_ON_LIGHT);
3038
}
3139

32-
if (!c->has_road_access) {
40+
if (!c.has_road_access) {
3341
window_building_draw_description(c, 69, 25);
3442
} else if (b->num_workers <= 0) {
3543
window_building_draw_description_at(c, 72, 106, 10);
36-
} else if (c->worker_percentage >= 100) {
44+
} else if (c.worker_percentage >= 100) {
3745
window_building_draw_description_at(c, 72, 106, 5);
38-
} else if (c->worker_percentage >= 75) {
46+
} else if (c.worker_percentage >= 75) {
3947
window_building_draw_description_at(c, 72, 106, 6);
40-
} else if (c->worker_percentage >= 50) {
48+
} else if (c.worker_percentage >= 50) {
4149
window_building_draw_description_at(c, 72, 106, 7);
42-
} else if (c->worker_percentage >= 25) {
50+
} else if (c.worker_percentage >= 25) {
4351
window_building_draw_description_at(c, 72, 106, 8);
4452
} else {
4553
window_building_draw_description_at(c, 72, 106, 9);
4654
}
4755

48-
inner_panel_draw(c->offset.x + 16, c->offset.y + 136, c->width_blocks - 2, 4);
49-
window_building_draw_employment(c, 142);
56+
inner_panel_draw(c.offset.x + 16, c.offset.y + 136, c.width_blocks - 2, 4);
57+
window_building_draw_employment(&c, 142);
58+
}
59+
60+
void building_tax_collector::update_month() {
61+
if (!config_get(CONFIG_GP_CH_NEW_TAX_COLLECTION_SYSTEM)) {
62+
return;
63+
}
64+
65+
if (base.has_figure_of_type(BUILDING_SLOT_CARTPUSHER, FIGURE_CART_PUSHER)) {
66+
return;
67+
}
68+
69+
if (base.has_road_access && base.deben_storage > 100) {
70+
int may_send = std::min<int>((base.deben_storage / 100) * 100, 400);
71+
figure *f = base.create_cartpusher(RESOURCE_GOLD, may_send, FIGURE_ACTION_20_CARTPUSHER_INITIAL, BUILDING_SLOT_CARTPUSHER);
72+
base.deben_storage -= may_send;
73+
f->sender_building_id = base.id;
74+
}
5075
}

src/building/building_tax_collector.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#pragma once
22

3-
struct object_info;
3+
#include "building/building.h"
44

5-
void building_tax_collector_draw_info(object_info* c);
5+
class building_tax_collector : public building_impl {
6+
public:
7+
building_tax_collector(building &b) : building_impl(b) {}
8+
virtual bool is_workshop() const override { return true; }
9+
virtual void window_info_background(object_info &c) override;
10+
virtual e_overlay get_overlay() const override { return OVERLAY_TAX_INCOME; }
11+
virtual void update_month() override;
12+
virtual e_sound_channel_city sound_channel() const override { return SOUND_CHANNEL_CITY_TAX_COLLECTOR; }
13+
};

src/building/figure.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -1108,24 +1108,6 @@ void building::update_month() {
11081108
data.entertainment.spawned_entertainer_this_month = false;
11091109
break;
11101110

1111-
case BUILDING_TAX_COLLECTOR:
1112-
case BUILDING_TAX_COLLECTOR_UPGRADED:
1113-
if (!config_get(CONFIG_GP_CH_NEW_TAX_COLLECTION_SYSTEM)) {
1114-
break;
1115-
}
1116-
1117-
if (has_figure_of_type(BUILDING_SLOT_CARTPUSHER, FIGURE_CART_PUSHER)) {
1118-
break;
1119-
}
1120-
1121-
if (has_road_access && deben_storage > 100) {
1122-
int may_send = std::min<int>((deben_storage / 100) * 100, 400);
1123-
figure *f = create_cartpusher(RESOURCE_GOLD, may_send, FIGURE_ACTION_20_CARTPUSHER_INITIAL, BUILDING_SLOT_CARTPUSHER);
1124-
deben_storage -= may_send;
1125-
f->sender_building_id = this->id;
1126-
}
1127-
break;
1128-
11291111
case BUILDING_WATER_SUPPLY: {
11301112
int avg_desirability = map_desirabilty_avg(tile, 4);
11311113
if (avg_desirability > 30) {

src/graphics/elements/button.cpp

-67
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "graphics/boilerplate.h"
44
#include "graphics/view/view.h"
55
#include "game/game.h"
6-
#include "generic_button.h"
7-
#include "image_button.h"
86

97
void button_none(int param1, int param2) {
108
}
@@ -52,69 +50,4 @@ void button_border_draw(int x, int y, int width_pixels, int height_pixels, bool
5250
}
5351
}
5452
}
55-
}
56-
57-
namespace ui {
58-
struct state {
59-
vec2i offset;
60-
std::vector<generic_button> buttons;
61-
std::vector<image_button> img_buttons;
62-
};
63-
64-
state g_state;
65-
generic_button dummy;
66-
}
67-
68-
void ui::begin_window(vec2i offset) {
69-
g_state.offset = offset;
70-
g_state.buttons.clear();
71-
g_state.img_buttons.clear();
72-
}
73-
74-
bool ui::handle_mouse(const mouse *m) {
75-
bool handle = false;
76-
int tmp_btn = 0;
77-
handle |= !!generic_buttons_handle_mouse(m, g_state.offset, g_state.buttons, tmp_btn);
78-
handle |= image_buttons_handle_mouse(m, g_state.offset, g_state.img_buttons, tmp_btn);
79-
80-
return handle;
81-
}
82-
83-
int ui::button_hover(const mouse *m) {
84-
for (auto &btn : g_state.buttons) {
85-
if (is_button_hover(btn, g_state.offset)) {
86-
return (std::distance(&g_state.buttons.front(), &btn) + 1);
87-
}
88-
}
89-
90-
return 0;
91-
}
92-
93-
generic_button &ui::button(pcstr label, vec2i pos, vec2i size) {
94-
const vec2i offset = g_state.offset;
95-
96-
g_state.buttons.push_back({pos.x, pos.y, size.x + 4, size.y + 4, button_none, button_none, 0, 0});
97-
int focused = is_button_hover(g_state.buttons.back(), offset);
98-
99-
button_border_draw(offset.x + pos.x, offset.y + pos.y, size.x, size.y, focused ? 1 : 0);
100-
text_draw_centered((uint8_t *)label, offset.x + pos.x + 1, offset.y + pos.y + 4, 20, FONT_NORMAL_BLACK_ON_LIGHT, 0);
101-
102-
return g_state.buttons.back();
103-
}
104-
105-
generic_button &ui::button(uint32_t id) {
106-
return (id < g_state.buttons.size()) ? g_state.buttons[id] : dummy;
107-
}
108-
109-
image_button &ui::img_button(uint32_t group, uint32_t id, vec2i pos, vec2i size, int offset) {
110-
const vec2i img_offset = g_state.offset;
111-
const mouse *m = mouse_get();
112-
113-
g_state.img_buttons.push_back({pos.x, pos.y, size.x + 4, size.y + 4, IB_NORMAL, group, id, offset, button_none, button_none, 0, 0, true});
114-
auto &button = g_state.img_buttons.back();
115-
button.focused = is_button_hover(g_state.img_buttons.back(), img_offset);
116-
button.pressed = button.focused && m->left.is_down;
117-
image_buttons_draw(img_offset, button);
118-
119-
return g_state.img_buttons.back();
12053
}

src/graphics/elements/button.h

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ struct mouse;
2222

2323
namespace ui {
2424

25-
void begin_window(vec2i offset);
26-
bool handle_mouse(const mouse *m);
2725
int button_hover(const mouse *m);
2826
generic_button &button(pcstr label, vec2i pos, vec2i size);
2927
generic_button &button(uint32_t id);

src/graphics/elements/lang_text.h

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "graphics/color.h"
44
#include "core/vec2i.h"
55
#include "graphics/font.h"
6+
#include "ui.h"
67

78
int lang_text_get_width(int group, int number, font_t font);
89
int lang_text_get_width(const char* str, font_t font);
@@ -29,3 +30,7 @@ int lang_text_draw_year(int year, int x_offset, int y_offset, font_t font);
2930
void lang_text_draw_month_year_max_width(int month, int year, int x_offset, int y_offset, int box_width, font_t font, color color);
3031

3132
int lang_text_draw_multiline(int group, int number, vec2i offset, int box_width, font_t font);
33+
34+
namespace ui {
35+
void label(int group, int number, vec2i pos, int box_width, font_t font, UiFlags_ flags);
36+
}

src/graphics/elements/panel.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3-
#include <cstdint>
43
#include "core/vec2i.h"
4+
#include "game/resource.h"
5+
#include "ui.h"
56

67
#define DEFAULT_BLOCK_SIZE 16
78

@@ -17,3 +18,8 @@ void label_draw(int x, int y, int width_blocks, int type);
1718
void label_draw_colored(painter &ctx, int x, int y, int width_blocks, int type, uint32_t mask);
1819

1920
void large_label_draw(int x, int y, int width_blocks, int type);
21+
22+
namespace ui {
23+
void panel(vec2i pos, vec2i size, UiFlags_ flags);
24+
void icon(vec2i pos, e_resource img);
25+
}

src/graphics/elements/ui.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "ui.h"
2+
3+
#include "generic_button.h"
4+
#include "image_button.h"
5+
#include "lang_text.h"
6+
#include "panel.h"
7+
#include "game/game.h"
8+
#include "graphics/boilerplate.h"
9+
10+
namespace ui {
11+
struct state {
12+
vec2i offset;
13+
std::vector<generic_button> buttons;
14+
std::vector<image_button> img_buttons;
15+
};
16+
17+
state g_state;
18+
generic_button dummy;
19+
}
20+
21+
void ui::begin_window(vec2i offset) {
22+
g_state.offset = offset;
23+
g_state.buttons.clear();
24+
g_state.img_buttons.clear();
25+
}
26+
27+
bool ui::handle_mouse(const mouse *m) {
28+
bool handle = false;
29+
int tmp_btn = 0;
30+
handle |= !!generic_buttons_handle_mouse(m, g_state.offset, g_state.buttons, tmp_btn);
31+
handle |= image_buttons_handle_mouse(m, g_state.offset, g_state.img_buttons, tmp_btn);
32+
33+
return handle;
34+
}
35+
36+
int ui::button_hover(const mouse *m) {
37+
for (auto &btn : g_state.buttons) {
38+
if (is_button_hover(btn, g_state.offset)) {
39+
return (std::distance(&g_state.buttons.front(), &btn) + 1);
40+
}
41+
}
42+
43+
return 0;
44+
}
45+
46+
generic_button &ui::button(pcstr label, vec2i pos, vec2i size) {
47+
const vec2i offset = g_state.offset;
48+
49+
g_state.buttons.push_back({pos.x, pos.y, size.x + 4, size.y + 4, button_none, button_none, 0, 0});
50+
int focused = is_button_hover(g_state.buttons.back(), offset);
51+
52+
button_border_draw(offset.x + pos.x, offset.y + pos.y, size.x, size.y, focused ? 1 : 0);
53+
text_draw_centered((uint8_t *)label, offset.x + pos.x + 1, offset.y + pos.y + 4, 20, FONT_NORMAL_BLACK_ON_LIGHT, 0);
54+
55+
return g_state.buttons.back();
56+
}
57+
58+
generic_button &ui::button(uint32_t id) {
59+
return (id < g_state.buttons.size()) ? g_state.buttons[id] : dummy;
60+
}
61+
62+
image_button &ui::img_button(uint32_t group, uint32_t id, vec2i pos, vec2i size, int offset) {
63+
const vec2i img_offset = g_state.offset;
64+
const mouse *m = mouse_get();
65+
66+
g_state.img_buttons.push_back({pos.x, pos.y, size.x + 4, size.y + 4, IB_NORMAL, group, id, offset, button_none, button_none, 0, 0, true});
67+
auto &button = g_state.img_buttons.back();
68+
button.focused = is_button_hover(g_state.img_buttons.back(), img_offset);
69+
button.pressed = button.focused && m->left.is_down;
70+
image_buttons_draw(img_offset, button);
71+
72+
return g_state.img_buttons.back();
73+
}
74+
75+
void ui::label(int group, int number, vec2i pos, int box_width, font_t font, UiFlags_ flags) {
76+
const vec2i offset = g_state.offset;
77+
if (!!(flags & UiFlags_LabelCentered)) {
78+
lang_text_draw_centered(group, number, offset.x + pos.x, offset.y + pos.y, box_width, font);
79+
}
80+
}
81+
82+
void ui::panel(vec2i pos, vec2i size, UiFlags_ flags) {
83+
const vec2i offset = g_state.offset;
84+
if (!!(flags & UiFlags_PanelOuter)) {
85+
outer_panel_draw(offset + pos, size.x, size.y);
86+
}
87+
}
88+
89+
void ui::icon(vec2i pos, e_resource img) {
90+
const vec2i offset = g_state.offset;
91+
painter ctx = game.painter();
92+
ImageDraw::img_generic(ctx, image_id_resource_icon(RESOURCE_DEBEN), offset.x + pos.x, offset.y + pos.y);
93+
}

0 commit comments

Comments
 (0)