summaryrefslogtreecommitdiff
path: root/src/scenes/loading_scene.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 21:52:24 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 21:52:24 +0100
commit6f7374c2fa58c8692b51018864b802e6b876d305 (patch)
treea7e8ead757e9f4de1920395336dcac1c8a989576 /src/scenes/loading_scene.c
A new start
Diffstat (limited to 'src/scenes/loading_scene.c')
-rw-r--r--src/scenes/loading_scene.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/scenes/loading_scene.c b/src/scenes/loading_scene.c
new file mode 100644
index 0000000..2240aa8
--- /dev/null
+++ b/src/scenes/loading_scene.c
@@ -0,0 +1,85 @@
+
+#define MAX_CREDITED_NAMES 5
+#define MAX_CREDIT_NAME_LENGTH 30
+#define COMPLETE_CREDIT_LENGTH (MAX_CREDIT_NAME_LENGTH*MAX_CREDITED_NAMES)+20
+char complete_credit_text[COMPLETE_CREDIT_LENGTH];
+
+void loading_scene_init()
+{
+ strcpy(complete_credit_text, "Music by ");
+
+ // Load names to credit.
+ {
+ platform_set_active_directory(binary_path);
+
+ array files = array_create(sizeof(found_file));
+ array filters = string_split("AUTHOR.txt");
+ bool is_cancelled = false;
+ platform_list_files_block(&files, "data/music/", filters, true, 0, true, &is_cancelled, 0);
+ log_assert(files.length <= MAX_CREDITED_NAMES, "Not enough space for credited names.");
+ for (s32 i = 0; i < files.length; i++)
+ {
+ found_file *file = array_at(&files, i);
+
+ if (platform_file_exists(file->path))
+ {
+ file_content name = platform_read_file_content(file->path, "rb");
+ if (name.file_error) continue;
+
+ string_appendn(complete_credit_text, name.content, COMPLETE_CREDIT_LENGTH);
+ if (i != files.length-1) {
+ string_appendn(complete_credit_text, ", ", COMPLETE_CREDIT_LENGTH);
+ }
+ platform_destroy_file_content(&name);
+ }
+
+ mem_free(file->matched_filter);
+ mem_free(file->path);
+ }
+
+ array_destroy(&files);
+ array_destroy(&filters);
+ }
+}
+
+void loading_scene_render(platform_window* window)
+{
+ renderer->render_rectangle(area.x, area.y, area.w, area.h, COLOR_WHITE);
+
+ font* font_reg = FONT_REGULAR(SIZE_RD(area.w, 36));
+ s32 target_size = area.h/5;
+ s32 logo_text_pad = 20;
+ s32 total_height = target_size + logo_text_pad + font_reg->px_h;
+
+ s32 screen_center_x = area.x + (area.w/2);
+ s32 screen_center_y = area.y + (area.h/2);
+ s32 logo_x = screen_center_x - (target_size/2);
+ s32 logo_y = screen_center_y - (total_height/2);
+ renderer->render_image(img_logo, logo_x, logo_y, target_size, target_size);
+
+ s32 text_y = logo_y + target_size + logo_text_pad;
+ char* company_name = "Tar Software";
+ s32 company_name_width = renderer->calculate_text_width(font_reg, company_name);
+ s32 text_x = screen_center_x - (company_name_width/2);
+
+ renderer->render_text(font_reg, text_x, text_y, company_name, COLOR_TITLE);
+
+ // Credits
+ font* font_s = FONT_REGULAR(SIZE_RD(area.w, 20));
+ s32 credit_pad = 30*scale;
+ renderer->render_text(font_s, area.x + credit_pad, area.y+area.h-credit_pad-font_s->px_h, complete_credit_text, COLOR_TITLE);
+}
+
+void loading_scene_update(platform_window* window)
+{
+ platform_set_cursor(window, CURSOR_LOADING);
+
+ if (global_asset_collection.done_loading_assets) {
+ game_set_active_scene(GAME_STATE_MENU);
+ }
+}
+
+void loading_scene_destroy()
+{
+
+} \ No newline at end of file