From a088bd6cacf464f61b1d207f4bb79ed269697048 Mon Sep 17 00:00:00 2001 From: cursedarcangel Date: Thu, 21 Jul 2022 18:16:50 -0400 Subject: [PATCH] Add best previous score to load in screen --- data/ui/ui.ui | 14 +++++++++++++- src/golf/ui.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/data/ui/ui.ui b/data/ui/ui.ui index 2fb95e0..2f1f354 100644 --- a/data/ui/ui.ui +++ b/data/ui/ui.ui @@ -36,7 +36,7 @@ "name": "level_num_text", "type": "text", "font": "data/font/FiraSans-Bold.ttf", - "anchor": [0.5, 0.5], + "anchor": [0.5, 0.425], "pos": [0, 0], "horiz_align": 0, "vert_align": 0, @@ -44,6 +44,18 @@ "color": [1.0, 1.0, 1.0, 1], "text": "LEVEL 1" }, + { + "name": "level_best_text", + "type": "text", + "font": "data/font/FiraSans-Bold.ttf", + "anchor": [0.5, 0.575], + "pos": [0, 0], + "horiz_align": 0, + "vert_align": 0, + "font_size": 100, + "color": [1.0, 1.0, 1.0, 1], + "text": "Best: -" + }, { "name": "play_button", "type": "button", diff --git a/src/golf/ui.c b/src/golf/ui.c index 4fa0c5f..a605a6c 100644 --- a/src/golf/ui.c +++ b/src/golf/ui.c @@ -1255,6 +1255,26 @@ static void _golf_ui_in_game(float dt) { golf_string_appendf(&entity->text.text, "LEVEL %d", golf->level_num + 1); _golf_ui_text(layout, *entity, alpha); } + + if (_golf_ui_layout_get_entity_of_type(layout, "level_best_text", GOLF_UI_TEXT, &entity)) { + float alpha = 1; + if (golf->in_game.t > time_to_show_level_num) { + alpha = 1 - (golf->in_game.t - time_to_show_level_num) / fade_in_length; + } + entity->text.text.len = 0; + + char storage_key[256]; + snprintf(storage_key, 256, "stroke_count_level_%d", golf->level_num); + + float storage_stroke_count; + bool is_key_set = golf_storage_get_num(storage_key, &storage_stroke_count); + if (!is_key_set) { + golf_string_appendf(&entity->text.text, "Best: -"); + } else { + golf_string_appendf(&entity->text.text, "Best: %d", (int)storage_stroke_count); + } + _golf_ui_text(layout, *entity, alpha); + } } if (golf->in_game.t < fade_in_length) {