Skip to content

Commit 92feed3

Browse files
committed
ui: update_buttons() moved to window_draw_background()
1 parent f0a1495 commit 92feed3

5 files changed

+32
-29
lines changed

src/city/object_info.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "grid/point.h"
66
#include "core/vec2i.h"
77
#include "city/constants.h"
8+
#include "overlays/city_overlay_fwd.h"
89
#include "core/svector.h"
910

1011
enum terrain_info_type {
@@ -68,7 +69,7 @@ struct object_info {
6869
int warehouse_space_text;
6970
common_info_window *ui = nullptr;
7071
terrain_info_type terrain_type;
71-
int show_overlay;
72+
e_overlay show_overlay;
7273
struct {
7374
e_advisor first = ADVISOR_NONE;
7475
e_advisor left_a = ADVISOR_NONE;

src/window/window_building_info.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ void building_info_window::fill_employment_details(object_info &c, int text_id)
112112
}
113113

114114
void building_info_window::window_info_background(object_info &c) {
115+
common_info_window::window_info_background(c);
116+
117+
building *b = building_get(c);
118+
b->dcast()->window_info_background(c);
119+
120+
update_buttons(c);
121+
}
122+
123+
textid building_info_window::get_tooltip(object_info &c) {
124+
common_info_window::init(c);
125+
126+
if (!c.storage_show_special_orders) {
127+
return {0, 0};
128+
}
129+
130+
building *b = building_get(c);
131+
if (b->type == BUILDING_STORAGE_YARD) {
132+
return window_building_get_tooltip_warehouse_orders();
133+
}
134+
135+
return b->dcast()->get_tooltip();
136+
}
137+
138+
void building_info_window::init(object_info &c) {
115139
g_debug_building_id = c.building_id;
116140
building *b = building_get(c);
117141

@@ -176,25 +200,11 @@ void building_info_window::window_info_background(object_info &c) {
176200
c.help_id = params.meta.help_id;
177201
c.group_id = params.meta.text_id;
178202

179-
ui["title"] = ui::str(c.group_id, 0);
180-
181-
common_info_window::window_info_background(c);
182-
}
183-
184-
textid building_info_window::get_tooltip(object_info &c) {
185-
if (!c.storage_show_special_orders) {
186-
return {0, 0};
187-
}
188-
189-
building *b = building_get(c);
190-
if (b->type == BUILDING_STORAGE_YARD) {
191-
return window_building_get_tooltip_warehouse_orders();
192-
}
193-
194-
return b->dcast()->get_tooltip();
203+
ui["title"] = ui::str(28, b->type);
195204
}
196205

197206
void building_info_window::update_buttons(object_info &c) {
207+
common_info_window::update_buttons(c);
198208
building *b = building_get(c);
199209

200210
int workers_needed = model_get_building(b->type)->laborers;
@@ -233,8 +243,6 @@ void building_info_window::update_buttons(object_info &c) {
233243
}
234244
window_invalidate();
235245
});
236-
237-
common_info_window::update_buttons(c);
238246
}
239247

240248
building *building_info_window::building_get(object_info &c) {

src/window/window_building_info.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ struct building_info_window : public common_info_window {
1717
virtual void window_info_foreground(object_info &c) override;
1818
virtual void window_info_background(object_info &c) override;
1919
virtual textid get_tooltip(object_info &c) override;
20-
20+
21+
virtual void init(object_info &c) override;
2122
virtual void update_buttons(object_info &c) override;
2223

2324
building *building_get(object_info &c);

src/window/window_info.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,6 @@ void common_info_window::load(archive arch, pcstr section) {
381381
}
382382
}
383383

384-
void common_info_window::init(object_info &c) {
385-
building *b = c.building_get();
386-
ui["title"] = ui::str(28, b->type);
387-
388-
update_buttons(c);
389-
}
390-
391384
void common_info_window::draw_tooltip(tooltip_context *c) {
392385
textid tx = get_tooltip(g_object_info);
393386
pcstr tooltip = (pcstr)lang_get_string(tx);

src/window/window_info.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ struct common_info_window : public ui::widget {
1010
virtual pcstr section() const { return ""; }
1111
virtual bool check(object_info &c) { return false; }
1212
virtual int get_height_id(object_info &c) { return 0; }
13-
virtual void window_info_background(object_info &c) {}
13+
virtual void window_info_background(object_info &c) { update_buttons(c); }
1414
virtual void window_info_foreground(object_info &c) { draw(); }
1515
virtual int window_info_handle_mouse(const mouse *m, object_info &c) { return 0; }
1616
virtual textid get_tooltip(object_info &c) { return {0, 0}; }
1717
virtual void update_buttons(object_info &c);
1818

1919
using widget::load;
2020
virtual void load(archive arch, pcstr section) override;
21-
virtual void init(object_info &c);
21+
virtual void init(object_info &c) {}
2222

2323
void draw_tooltip(tooltip_context *c);
2424
};

0 commit comments

Comments
 (0)