Skip to content

Commit b4ec361

Browse files
committed
ui: show tooltip for palace
1 parent 2d4dad9 commit b4ec361

10 files changed

+114
-116
lines changed

src/building/building.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class building_quarry;
6767
class building_palace;
6868
class building_festival_square;
6969
class building_bandstand;
70+
struct tooltip_context;
7071
struct object_info;
7172
struct painter;
7273
struct mouse;
@@ -515,6 +516,7 @@ class building_impl {
515516
virtual textid get_tooltip() const { return {0, 0}; }
516517
virtual int ready_production() const { return params().production_rate; }
517518
virtual void draw_normal_anim(painter &ctx, vec2i point, tile2i tile, color mask);
519+
virtual void draw_tooltip(tooltip_context *c) {};
518520
virtual const static_params &params() const { return params(type()); }
519521

520522
virtual building_farm *dcast_farm() { return nullptr; }

src/building/building_palace.cpp

+58-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "city/ratings.h"
77
#include "city/city.h"
88
#include "game/resource.h"
9-
#include "graphics/elements/panel.h"
109
#include "graphics/elements/lang_text.h"
10+
#include "graphics/elements/tooltip.h"
11+
#include "graphics/elements/panel.h"
1112
#include "graphics/view/view.h"
1213
#include "graphics/graphics.h"
1314
#include "graphics/image.h"
@@ -22,6 +23,8 @@
2223
#include "window/window_building_info.h"
2324
#include "widget/city/ornaments.h"
2425
#include "window/advisors.h"
26+
#include "scenario/criteria.h"
27+
#include "scenario/scenario.h"
2528
#include "sound/sound_building.h"
2629
#include "game/game.h"
2730
#include "js/js_game.h"
@@ -38,14 +41,6 @@ buildings::model_t<building_town_palace> town_building_palace_m;
3841
buildings::model_t<building_city_palace> city_building_palace_m;
3942
palace_info_window palace_infow;
4043

41-
ANK_REGISTER_CONFIG_ITERATOR(config_load_building_palace_model);
42-
void config_load_building_palace_model() {
43-
village_building_palace_m.load();
44-
town_building_palace_m.load();
45-
city_building_palace_m.load();
46-
palace_infow.load("info_window_palace");
47-
}
48-
4944
void building_palace::on_create(int orientation) {
5045
base.labor_category = village_building_palace_m.labor_category;
5146
}
@@ -75,6 +70,60 @@ void building_palace::update_graphic() {
7570
//}
7671
}
7772

73+
void building_palace::draw_tooltip(tooltip_context *c) {
74+
int x, y;
75+
int width = 220;
76+
int height = 80;
77+
78+
if (c->mpos.x < width + 20)
79+
x = c->mpos.x + 20;
80+
else {
81+
x = c->mpos.x - width - 20;
82+
}
83+
84+
if (c->mpos.y < 200) {
85+
y = c->mpos.y + 10;
86+
} else if (c->mpos.y + height - 32 > screen_height()) {
87+
y = screen_height() - height;
88+
} else {
89+
y = c->mpos.y - 32;
90+
}
91+
92+
//save_window_under_tooltip_to_buffer(x, y, width, height);
93+
draw_tooltip_box(x, y, width, height);
94+
95+
// unemployment
96+
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_unemployed, x + 5, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
97+
width = text_draw_number_colored(g_city.labor.unemployment_percentage, '@', "%", x + 140, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
98+
text_draw_number_colored(g_city.labor.workers_unemployed - g_city.labor.workers_needed, '(', ")", x + 140 + width, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
99+
100+
// ratings
101+
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_culture, x + 5, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
102+
text_draw_number_colored(g_city.ratings.culture, '@', " ", x + 140, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
103+
if (!scenario_is_open_play() && winning_culture()) {
104+
text_draw_number_colored(winning_culture(), '(', ")", x + 140 + width, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
105+
}
106+
107+
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_prosperity, x + 5, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
108+
text_draw_number_colored(g_city.ratings.prosperity, '@', " ", x + 140, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
109+
110+
if (!scenario_is_open_play() && winning_prosperity()) {
111+
text_draw_number_colored(winning_prosperity(), '(', ")", x + 140 + width, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
112+
}
113+
114+
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_monuments, x + 5, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
115+
text_draw_number_colored(g_city.ratings.monument, '@', " ", x + 140, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
116+
if (!scenario_is_open_play() && winning_monuments()) {
117+
text_draw_number_colored(winning_monuments(), '(', ")", x + 140 + width, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
118+
}
119+
120+
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_kingdom, x + 5, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
121+
text_draw_number_colored(g_city.ratings.kingdom, '@', " ", x + 140, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
122+
if (!scenario_is_open_play() && winning_kingdom()) {
123+
text_draw_number_colored(winning_kingdom(), '(', ")", x + 140 + width, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
124+
}
125+
}
126+
78127
bool building_palace::draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) {
79128
draw_normal_anim(ctx, point, tile, color_mask);
80129

src/building/building_palace.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class building_palace : public building_impl {
1212
virtual void on_destroy() override;
1313
virtual bool can_play_animation() const override;
1414
virtual void update_graphic() override;
15+
virtual void draw_tooltip(tooltip_context *c) override;
1516
virtual bool draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color mask) override;
1617
};
1718

src/graphics/elements/tooltip.cpp

+22-68
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ static void reset_timer(void) {
4040
last_update = time_get_millis();
4141
}
4242
static void reset_tooltip(tooltip_context* c) {
43-
if (c->type != TOOLTIP_NONE)
44-
c->type = TOOLTIP_NONE;
43+
c->_drawtooltip = nullptr;
44+
c->text = "";
4545
}
4646

4747
static void restore_window_under_tooltip_from_buffer(void) {
@@ -65,7 +65,7 @@ static void save_window_under_tooltip_to_buffer(int x, int y, int width, int hei
6565
button_tooltip_info.buffer_id = graphics_save_to_texture(button_tooltip_info.buffer_id, {x, y}, {width, height});
6666
}
6767

68-
static void draw_tooltip_box(int x, int y, int width, int height) {
68+
void draw_tooltip_box(int x, int y, int width, int height) {
6969
graphics_draw_rect(vec2i{x, y}, vec2i{width, height}, COLOR_TOOLTIP_BORDER);
7070
graphics_fill_rect(vec2i{x + 1, y + 1}, vec2i{width - 2, height - 2}, COLOR_TOOLTIP_FILL);
7171
}
@@ -218,80 +218,35 @@ static void draw_tile_tooltip(tooltip_context* c) {
218218
text_draw_label_and_number("y: ", y_tile, " ", x + 2, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
219219
}
220220
}
221-
static void draw_senate_tooltip(tooltip_context* c) {
222-
int x, y;
223-
int width = 220;
224-
int height = 80;
225-
226-
if (c->mpos.x < width + 20)
227-
x = c->mpos.x + 20;
228-
else {
229-
x = c->mpos.x - width - 20;
230-
}
231-
232-
if (c->mpos.y < 200) {
233-
y = c->mpos.y + 10;
234-
} else if (c->mpos.y + height - 32 > screen_height()) {
235-
y = screen_height() - height;
236-
} else {
237-
y = c->mpos.y - 32;
238-
}
239-
240-
//save_window_under_tooltip_to_buffer(x, y, width, height);
241-
draw_tooltip_box(x, y, width, height);
242-
243-
// unemployment
244-
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_unemployed, x + 5, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
245-
width = text_draw_number_colored(g_city.labor.unemployment_percentage, '@', "%", x + 140, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
246-
text_draw_number_colored(g_city.labor.workers_unemployed - g_city.labor.workers_needed, '(', ")", x + 140 + width, y + 5, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
247-
248-
// ratings
249-
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_culture, x + 5, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
250-
text_draw_number_colored(g_city.ratings.culture, '@', " ", x + 140, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
251-
if (!scenario_is_open_play() && winning_culture()) {
252-
text_draw_number_colored(winning_culture(), '(', ")", x + 140 + width, y + 19, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
253-
}
254-
255-
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_prosperity, x + 5, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
256-
text_draw_number_colored(g_city.ratings.prosperity, '@', " ", x + 140, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
257-
258-
if (!scenario_is_open_play() && winning_prosperity()) {
259-
text_draw_number_colored(winning_prosperity(), '(', ")", x + 140 + width, y + 33, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
260-
}
261-
262-
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_monuments, x + 5, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
263-
text_draw_number_colored(g_city.ratings.monument, '@', " ", x + 140, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
264-
if (!scenario_is_open_play() && winning_monuments()) {
265-
text_draw_number_colored(winning_monuments(), '(', ")", x + 140 + width, y + 47, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
266-
}
267-
268-
lang_text_draw_colored(e_text_senate_tooltip, e_text_senate_tooltip_kingdom, x + 5, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
269-
text_draw_number_colored(g_city.ratings.kingdom, '@', " ", x + 140, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
270-
if (!scenario_is_open_play() && winning_kingdom()) {
271-
text_draw_number_colored(winning_kingdom(), '(', ")", x + 140 + width, y + 61, FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
272-
}
273-
}
274221

275222
static void draw_tooltip(tooltip_context* c) {
276-
switch (c->type) {
277-
case TOOLTIP_BUTTON: draw_button_tooltip(c); break;
278-
case TOOLTIP_OVERLAY: draw_overlay_tooltip(c); break;
279-
case TOOLTIP_TILES: draw_tile_tooltip(c); break;
280-
case TOOLTIP_SENATE: draw_senate_tooltip(c); break;
223+
if (c->_drawtooltip) {
224+
c->_drawtooltip();
281225
}
226+
227+
//switch (c->type) {
228+
//case TOOLTIP_BUTTON: draw_button_tooltip(c); break;
229+
//case TOOLTIP_OVERLAY: draw_overlay_tooltip(c); break;
230+
//case TOOLTIP_TILES: draw_tile_tooltip(c); break;
231+
//case TOOLTIP_SENATE: draw_senate_tooltip(c); break;
232+
//}
282233
}
283234

284235
static bool should_draw_tooltip(tooltip_context* c) {
285-
if (c->type == TOOLTIP_NONE) {
236+
if (!c->text) {
286237
reset_timer();
287238
return false;
288239
}
240+
289241
if (!c->high_priority && g_settings.tooltips != e_tooltip_show_full) {
290242
reset_timer();
291243
return false;
292244
}
293-
if (time_get_millis() - last_update < TOOLTIP_DELAY_MILLIS) // delay drawing tooltip
245+
246+
if (time_get_millis() - last_update < TOOLTIP_DELAY_MILLIS) { // delay drawing tooltip
294247
return false;
248+
}
249+
295250
return true;
296251
}
297252

@@ -304,16 +259,17 @@ void tooltip_handle(const mouse* m, void (*func)(tooltip_context*)) {
304259
reset_timer();
305260
return;
306261
}
262+
307263
static tooltip_context context;
308264
context.mpos = *m;
309265
context.text = "";
310266
if (g_settings.tooltips && func) {
311267
func(&context);
312268
}
313269

314-
const tooltip_context &uitooltip = ui::get_tooltip();
315-
if (uitooltip.type) {
316-
context.set(uitooltip.type, uitooltip.text);
270+
if (!context.text) {
271+
const tooltip_context &uitooltip = ui::get_tooltip();
272+
context.text = uitooltip.text;
317273
}
318274

319275
if (should_draw_tooltip(&context)) {
@@ -326,11 +282,9 @@ void tooltip_handle(const mouse* m, void (*func)(tooltip_context*)) {
326282
}
327283

328284
void tooltip_context::set(int t, textid tx) {
329-
type = t;
330285
text = (pcstr)lang_get_string(tx);
331286
}
332287

333288
void tooltip_context::set(int t, pcstr tx) {
334-
type = t;
335289
text = tx;
336290
}

src/graphics/elements/tooltip.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
#include "core/vec2i.h"
44
#include "core/string.h"
55

6+
#include <functional>
7+
68
#define TOOLTIP_MAX_EXTRA_VALUES 5
79
struct mouse;
810

9-
enum e_tooltip_mode {
10-
TOOLTIP_NONE = 0,
11-
TOOLTIP_BUTTON = 1,
12-
TOOLTIP_OVERLAY = 2,
13-
TOOLTIP_SENATE = 3,
14-
TOOLTIP_TILES = 4
15-
};
16-
1711
struct tooltip_context {
1812
vec2i mpos;
19-
int type = 0;
2013
int high_priority = 0;
2114
bstring256 text;
2215
int has_numeric_prefix = 0;
@@ -25,9 +18,12 @@ struct tooltip_context {
2518
int extra_value_text_groups[TOOLTIP_MAX_EXTRA_VALUES] = {0};
2619
int extra_value_text_ids[TOOLTIP_MAX_EXTRA_VALUES] = {0};
2720

21+
std::function<void()> _drawtooltip;
22+
2823
void set(int t, textid tx);
2924
void set(int t, pcstr tx);
3025
};
3126

3227
void tooltip_invalidate();
28+
void draw_tooltip_box(int x, int y, int width, int height);
3329
void tooltip_handle(const mouse* m, void (*func)(tooltip_context*));

src/graphics/elements/ui.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void ui::begin_frame() {
190190
g_state._offset = {};
191191
g_state.buttons.clear();
192192
g_state.scrollbars.clear();
193-
tooltipctx.set(TOOLTIP_NONE, textid{});
193+
tooltipctx.set(0, "");
194194
}
195195

196196
void ui::end_frame() {
@@ -859,7 +859,7 @@ void ui::eimage_button::draw() {
859859
btn->tooltip(_tooltip);
860860

861861
if (_tooltip.id && btn->hovered) {
862-
tooltipctx.set(TOOLTIP_BUTTON, _tooltip);
862+
tooltipctx.set(0, _tooltip);
863863
}
864864
}
865865

@@ -1011,7 +1011,7 @@ void ui::egeneric_button::draw() {
10111011
btn->tooltip(_tooltip);
10121012

10131013
if (_tooltip.id && btn->hovered) {
1014-
tooltipctx.set(TOOLTIP_BUTTON, _tooltip);
1014+
tooltipctx.set(0, _tooltip);
10151015
}
10161016
}
10171017

src/widget/widget_city.cpp

+22-20
Original file line numberDiff line numberDiff line change
@@ -592,25 +592,27 @@ void widget_city_get_tooltip(tooltip_context* c) {
592592
}
593593

594594
int building_id = map_building_at(grid_offset);
595+
building_impl *b = building_get(building_id)->dcast();
596+
b->draw_tooltip(c);
595597
// cheat tooltips
596-
if (game.current_overlay == OVERLAY_NONE && game_cheat_tooltip_enabled()) {
597-
c->type = TOOLTIP_TILES;
598-
c->high_priority = 1;
599-
return;
600-
}
601-
602-
// regular tooltips
603-
if (game.current_overlay == OVERLAY_NONE && building_id && building_get(building_id)->is_palace()) {
604-
c->type = TOOLTIP_SENATE;
605-
c->high_priority = 1;
606-
return;
607-
}
608-
609-
// overlay tooltips
610-
if (game.current_overlay != OVERLAY_NONE) {
611-
c->type = TOOLTIP_OVERLAY;
612-
c->high_priority = 1;
613-
int id = widget_city_overlay_get_tooltip_text(c, grid_offset);
614-
c->text = ui::str(66, id);
615-
}
598+
//if (game.current_overlay == OVERLAY_NONE && game_cheat_tooltip_enabled()) {
599+
// c->type = TOOLTIP_TILES;
600+
// c->high_priority = 1;
601+
// return;
602+
//}
603+
//
604+
//// regular tooltips
605+
//if (game.current_overlay == OVERLAY_NONE && building_id && building_get(building_id)->is_palace()) {
606+
// c->type = TOOLTIP_SENATE;
607+
// c->high_priority = 1;
608+
// return;
609+
//}
610+
//
611+
//// overlay tooltips
612+
//if (game.current_overlay != OVERLAY_NONE) {
613+
// c->type = TOOLTIP_OVERLAY;
614+
// c->high_priority = 1;
615+
// int id = widget_city_overlay_get_tooltip_text(c, grid_offset);
616+
// c->text = ui::str(66, id);
617+
//}
616618
}

src/window/trade_prices.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ static void get_tooltip(tooltip_context* c) {
6262
return;
6363
}
6464

65-
c->type = TOOLTIP_BUTTON;
6665
c->text = (pcstr)lang_get_string(0, 131 + resource);
6766
}
6867

0 commit comments

Comments
 (0)