21
21
#include < algorithm>
22
22
#include < iomanip>
23
23
#include < limits>
24
+ #include < numeric>
24
25
25
26
#include < simplesquirrel/table.hpp>
26
27
@@ -262,70 +263,79 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
262
263
{
263
264
if (m_status != FINAL) return ;
264
265
265
- int layer = LAYER_GUI + 50 ;
266
+ constexpr int layer = LAYER_GUI + 50 ;
267
+ constexpr float row_height = 22 .f ;
268
+ constexpr float header_padding_top = 10 .f ;
269
+ constexpr float padding_top = 40 .f ;
270
+ constexpr float padding_bottom = 10 .f ;
271
+ constexpr float label_indent = 16 .f ;
266
272
267
- int box_w = 220 + 110 + 110 ;
268
- int box_h = 30 + 20 + 20 + 20 ;
269
- int box_x = static_cast < int >(( static_cast < int >(context. get_width ()) - box_w) / 2 ) ;
270
- int box_y = static_cast < int >(SCREEN_HEIGHT / 2 ) - box_h ;
273
+ int visible_rows = 1 ;
274
+ if (m_preferences. enable_coins ) ++visible_rows ;
275
+ if (m_preferences. enable_badguys ) ++visible_rows ;
276
+ if (m_preferences. enable_secrets ) ++visible_rows ;
271
277
272
- int bd_w = static_cast <int >(backdrop->get_width ());
273
- int bd_h = static_cast <int >(backdrop->get_height ());
274
- int bd_x = static_cast <int >((static_cast <int >(context.get_width ()) - bd_w) / 2 );
275
- int bd_y = box_y + (box_h / 2 ) - (bd_h / 2 );
278
+ const std::vector<float > column_widths = { 215 .f , 130 .f , 130 .f };
276
279
277
- float col1_x = static_cast < float >(box_x );
278
- float col2_x = col1_x + 200 . 0f ;
279
- float col3_x = col2_x + 130 . 0f ;
280
+ const float box_w = std::accumulate (column_widths. begin (), column_widths. end (), 0 . f );
281
+ const float box_h = padding_top + ( static_cast < float >(visible_rows) * row_height) + padding_bottom ;
282
+ const float box_x = ((context. get_width () - box_w) / 2 . f ) ;
280
283
281
- float y_offset = 47 .f ;
282
- if (m_preferences.enable_coins )
283
- y_offset -= 9 .f ;
284
- if (m_preferences.enable_badguys )
285
- y_offset -= 9 .f ;
286
- if (m_preferences.enable_secrets )
287
- y_offset -= 9 .f ;
284
+ const float box_y = (static_cast <float >(SCREEN_HEIGHT) - box_h) / 2 .f ;
288
285
289
- float y = static_cast <float >(box_y);
286
+ std::vector<float > col_x_positions;
287
+ col_x_positions.reserve (column_widths.size ());
288
+ float current_x = box_x;
289
+ for (const float width : column_widths)
290
+ {
291
+ col_x_positions.push_back (current_x);
292
+ current_x += width;
293
+ }
294
+
295
+ const float bd_w = static_cast <float >(backdrop->get_width ());
296
+ const float bd_h = static_cast <float >(backdrop->get_height ());
297
+ const float bd_x = (context.get_width () - bd_w) / 2 .f ;
298
+ const float bd_y = box_y + (box_h / 2 .f ) - (bd_h / 2 .f );
290
299
291
300
context.push_transform ();
292
301
context.set_alpha (0 .5f );
293
- context.color ().draw_surface (backdrop, Vector (static_cast < float >( bd_x), static_cast < float >( bd_y) ), layer);
302
+ context.color ().draw_surface (backdrop, Vector (bd_x, bd_y), layer);
294
303
context.pop_transform ();
295
304
296
- context.color ().draw_text (Resources::normal_font, _ (" You" ), Vector (col2_x, y), ALIGN_LEFT, layer, Statistics::header_color);
305
+ const float header_y = box_y + header_padding_top;
306
+ context.color ().draw_text (Resources::normal_font, _ (" You" ), Vector (col_x_positions[1 ], header_y), ALIGN_LEFT, layer, Statistics::header_color);
297
307
if (best_stats)
298
- context.color ().draw_text (Resources::normal_font, _ (" Best" ), Vector (col3_x, y ), ALIGN_LEFT, layer, Statistics::header_color);
308
+ context.color ().draw_text (Resources::normal_font, _ (" Best" ), Vector (col_x_positions[ 2 ], header_y ), ALIGN_LEFT, layer, Statistics::header_color);
299
309
300
- y += 10 . f + y_offset ;
310
+ float y = box_y + padding_top ;
301
311
302
312
Color tcolor = Statistics::text_color;
303
313
if (target_time == 0 .0f || (m_time != 0 .0f && m_time < target_time))
304
314
tcolor = Statistics::perfect_color;
305
315
306
- context.color ().draw_text (Resources::normal_font, _ (" Time" ), Vector (col2_x - 16 . f , y), ALIGN_RIGHT, layer, Statistics::header_color);
307
- context.color ().draw_text (Resources::normal_font, time_to_string (m_time), Vector (col2_x , y), ALIGN_LEFT, layer, tcolor);
316
+ context.color ().draw_text (Resources::normal_font, _ (" Time" ), Vector (col_x_positions[ 1 ] - label_indent , y), ALIGN_RIGHT, layer, Statistics::header_color);
317
+ context.color ().draw_text (Resources::normal_font, time_to_string (m_time), Vector (col_x_positions[ 1 ] , y), ALIGN_LEFT, layer, tcolor);
308
318
if (best_stats)
309
319
{
310
320
float time_best = (best_stats->m_time < m_time && best_stats->m_time > 0 .0f ) ? best_stats->m_time : m_time;
311
321
if (target_time == 0 .0f || (time_best != 0 .0f && time_best < target_time))
312
322
tcolor = Statistics::perfect_color;
313
323
else
314
324
tcolor = Statistics::text_color;
315
- context.color ().draw_text (Resources::normal_font, time_to_string (time_best), Vector (col3_x , y), ALIGN_LEFT, layer, tcolor);
325
+ context.color ().draw_text (Resources::normal_font, time_to_string (time_best), Vector (col_x_positions[ 2 ] , y), ALIGN_LEFT, layer, tcolor);
316
326
}
317
327
318
328
if (m_preferences.enable_coins )
319
329
{
320
- y += y_offset ;
330
+ y += row_height ;
321
331
322
- context.color ().draw_text (Resources::normal_font, _ (" Coins" ), Vector (col2_x - 16 . f , y), ALIGN_RIGHT, layer, Statistics::header_color);
332
+ context.color ().draw_text (Resources::normal_font, _ (" Coins" ), Vector (col_x_positions[ 1 ] - label_indent , y), ALIGN_RIGHT, layer, Statistics::header_color);
323
333
324
334
if (m_coins >= m_total_coins)
325
335
tcolor = Statistics::perfect_color;
326
336
else
327
337
tcolor = Statistics::text_color;
328
- context.color ().draw_text (Resources::normal_font, coins_to_string (m_coins, m_total_coins), Vector (col2_x , y), ALIGN_LEFT, layer, tcolor);
338
+ context.color ().draw_text (Resources::normal_font, coins_to_string (m_coins, m_total_coins), Vector (col_x_positions[ 1 ] , y), ALIGN_LEFT, layer, tcolor);
329
339
330
340
if (best_stats)
331
341
{
@@ -335,43 +345,43 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
335
345
tcolor = Statistics::perfect_color;
336
346
else
337
347
tcolor = Statistics::text_color;
338
- context.color ().draw_text (Resources::normal_font, coins_to_string (coins_best, total_coins_best), Vector (col3_x , y), ALIGN_LEFT, layer, tcolor);
348
+ context.color ().draw_text (Resources::normal_font, coins_to_string (coins_best, total_coins_best), Vector (col_x_positions[ 2 ] , y), ALIGN_LEFT, layer, tcolor);
339
349
}
340
350
}
341
351
342
352
if (m_preferences.enable_badguys )
343
353
{
344
- y += y_offset ;
354
+ y += row_height ;
345
355
346
356
if (m_badguys >= m_total_badguys)
347
357
tcolor = Statistics::perfect_color;
348
358
else
349
359
tcolor = Statistics::text_color;
350
- context.color ().draw_text (Resources::normal_font, _ (" Badguys" ), Vector (col2_x - 16 . f , y), ALIGN_RIGHT, layer, Statistics::header_color);
351
- context.color ().draw_text (Resources::normal_font, frags_to_string (m_badguys, m_total_badguys), Vector (col2_x , y), ALIGN_LEFT, layer, tcolor);
360
+ context.color ().draw_text (Resources::normal_font, _ (" Badguys" ), Vector (col_x_positions[ 1 ] - label_indent , y), ALIGN_RIGHT, layer, Statistics::header_color);
361
+ context.color ().draw_text (Resources::normal_font, frags_to_string (m_badguys, m_total_badguys), Vector (col_x_positions[ 1 ] , y), ALIGN_LEFT, layer, tcolor);
352
362
353
363
if (best_stats)
354
364
{
355
365
int badguys_best = (best_stats->m_badguys > m_badguys) ? best_stats->m_badguys : m_badguys;
356
366
int total_badguys_best = (best_stats->m_total_badguys > m_total_badguys) ? best_stats->m_total_badguys : m_total_badguys;
357
- if (badguys_best >= total_badguys_best)
358
- tcolor = Statistics::perfect_color;
359
- else
360
- tcolor = Statistics::text_color;
361
- context.color ().draw_text (Resources::normal_font, frags_to_string (badguys_best, total_badguys_best), Vector (col3_x , y), ALIGN_LEFT, layer, tcolor);
367
+ if (badguys_best >= total_badguys_best)
368
+ tcolor = Statistics::perfect_color;
369
+ else
370
+ tcolor = Statistics::text_color;
371
+ context.color ().draw_text (Resources::normal_font, frags_to_string (badguys_best, total_badguys_best), Vector (col_x_positions[ 2 ] , y), ALIGN_LEFT, layer, tcolor);
362
372
}
363
373
}
364
374
365
375
if (m_preferences.enable_secrets )
366
376
{
367
- y += y_offset ;
377
+ y += row_height ;
368
378
369
379
if (m_secrets >= m_total_secrets)
370
380
tcolor = Statistics::perfect_color;
371
381
else
372
382
tcolor = Statistics::text_color;
373
- context.color ().draw_text (Resources::normal_font, _ (" Secrets" ), Vector (col2_x - 16 . f , y), ALIGN_RIGHT, layer, Statistics::header_color);
374
- context.color ().draw_text (Resources::normal_font, secrets_to_string (m_secrets, m_total_secrets), Vector (col2_x , y), ALIGN_LEFT, layer, tcolor);
383
+ context.color ().draw_text (Resources::normal_font, _ (" Secrets" ), Vector (col_x_positions[ 1 ] - label_indent , y), ALIGN_RIGHT, layer, Statistics::header_color);
384
+ context.color ().draw_text (Resources::normal_font, secrets_to_string (m_secrets, m_total_secrets), Vector (col_x_positions[ 1 ] , y), ALIGN_LEFT, layer, tcolor);
375
385
376
386
if (best_stats)
377
387
{
@@ -381,7 +391,7 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
381
391
tcolor = Statistics::perfect_color;
382
392
else
383
393
tcolor = Statistics::text_color;
384
- context.color ().draw_text (Resources::normal_font, secrets_to_string (secrets_best, total_secrets_best), Vector (col3_x , y), ALIGN_LEFT, layer, tcolor);
394
+ context.color ().draw_text (Resources::normal_font, secrets_to_string (secrets_best, total_secrets_best), Vector (col_x_positions[ 2 ] , y), ALIGN_LEFT, layer, tcolor);
385
395
}
386
396
}
387
397
}
0 commit comments