2121#include < algorithm>
2222#include < iomanip>
2323#include < limits>
24+ #include < numeric>
2425
2526#include < simplesquirrel/table.hpp>
2627
@@ -262,70 +263,79 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
262263{
263264 if (m_status != FINAL) return ;
264265
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 ;
266272
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 ;
271277
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 };
276279
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 ) ;
280283
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 ;
288285
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 );
290299
291300 context.push_transform ();
292301 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);
294303 context.pop_transform ();
295304
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);
297307 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);
299309
300- y += 10 . f + y_offset ;
310+ float y = box_y + padding_top ;
301311
302312 Color tcolor = Statistics::text_color;
303313 if (target_time == 0 .0f || (m_time != 0 .0f && m_time < target_time))
304314 tcolor = Statistics::perfect_color;
305315
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);
308318 if (best_stats)
309319 {
310320 float time_best = (best_stats->m_time < m_time && best_stats->m_time > 0 .0f ) ? best_stats->m_time : m_time;
311321 if (target_time == 0 .0f || (time_best != 0 .0f && time_best < target_time))
312322 tcolor = Statistics::perfect_color;
313323 else
314324 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);
316326 }
317327
318328 if (m_preferences.enable_coins )
319329 {
320- y += y_offset ;
330+ y += row_height ;
321331
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);
323333
324334 if (m_coins >= m_total_coins)
325335 tcolor = Statistics::perfect_color;
326336 else
327337 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);
329339
330340 if (best_stats)
331341 {
@@ -335,43 +345,43 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
335345 tcolor = Statistics::perfect_color;
336346 else
337347 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);
339349 }
340350 }
341351
342352 if (m_preferences.enable_badguys )
343353 {
344- y += y_offset ;
354+ y += row_height ;
345355
346356 if (m_badguys >= m_total_badguys)
347357 tcolor = Statistics::perfect_color;
348358 else
349359 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);
352362
353363 if (best_stats)
354364 {
355365 int badguys_best = (best_stats->m_badguys > m_badguys) ? best_stats->m_badguys : m_badguys;
356366 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);
362372 }
363373 }
364374
365375 if (m_preferences.enable_secrets )
366376 {
367- y += y_offset ;
377+ y += row_height ;
368378
369379 if (m_secrets >= m_total_secrets)
370380 tcolor = Statistics::perfect_color;
371381 else
372382 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);
375385
376386 if (best_stats)
377387 {
@@ -381,7 +391,7 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, c
381391 tcolor = Statistics::perfect_color;
382392 else
383393 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);
385395 }
386396 }
387397}
0 commit comments