@@ -40,8 +40,8 @@ static void reset_timer(void) {
40
40
last_update = time_get_millis ();
41
41
}
42
42
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 = " " ;
45
45
}
46
46
47
47
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
65
65
button_tooltip_info.buffer_id = graphics_save_to_texture (button_tooltip_info.buffer_id , {x, y}, {width, height});
66
66
}
67
67
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) {
69
69
graphics_draw_rect (vec2i{x, y}, vec2i{width, height}, COLOR_TOOLTIP_BORDER);
70
70
graphics_fill_rect (vec2i{x + 1 , y + 1 }, vec2i{width - 2 , height - 2 }, COLOR_TOOLTIP_FILL);
71
71
}
@@ -218,80 +218,35 @@ static void draw_tile_tooltip(tooltip_context* c) {
218
218
text_draw_label_and_number (" y: " , y_tile, " " , x + 2 , y + 19 , FONT_SMALL_SHADED, COLOR_TOOLTIP_TEXT);
219
219
}
220
220
}
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
- }
274
221
275
222
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 ();
281
225
}
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
+ // }
282
233
}
283
234
284
235
static bool should_draw_tooltip (tooltip_context* c) {
285
- if (c->type == TOOLTIP_NONE ) {
236
+ if (! c->text ) {
286
237
reset_timer ();
287
238
return false ;
288
239
}
240
+
289
241
if (!c->high_priority && g_settings.tooltips != e_tooltip_show_full) {
290
242
reset_timer ();
291
243
return false ;
292
244
}
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
294
247
return false ;
248
+ }
249
+
295
250
return true ;
296
251
}
297
252
@@ -304,16 +259,17 @@ void tooltip_handle(const mouse* m, void (*func)(tooltip_context*)) {
304
259
reset_timer ();
305
260
return ;
306
261
}
262
+
307
263
static tooltip_context context;
308
264
context.mpos = *m;
309
265
context.text = " " ;
310
266
if (g_settings.tooltips && func) {
311
267
func (&context);
312
268
}
313
269
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 ;
317
273
}
318
274
319
275
if (should_draw_tooltip (&context)) {
@@ -326,11 +282,9 @@ void tooltip_handle(const mouse* m, void (*func)(tooltip_context*)) {
326
282
}
327
283
328
284
void tooltip_context::set (int t, textid tx) {
329
- type = t;
330
285
text = (pcstr)lang_get_string (tx);
331
286
}
332
287
333
288
void tooltip_context::set (int t, pcstr tx) {
334
- type = t;
335
289
text = tx;
336
290
}
0 commit comments