From e3c577160409ff898665049c2b1ebcd2c605bf8a Mon Sep 17 00:00:00 2001 From: cypress Date: Sun, 20 Oct 2024 15:33:28 -0700 Subject: [PATCH] MENU: More dynamic background changing --- source/menu/defs/menu_defs.qc | 1 + source/menu/m_menu.qc | 24 +++++++++++++++++++++++- source/menu/main.qc | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/source/menu/defs/menu_defs.qc b/source/menu/defs/menu_defs.qc index 28356f4..4f7fd12 100644 --- a/source/menu/defs/menu_defs.qc +++ b/source/menu/defs/menu_defs.qc @@ -6,6 +6,7 @@ float music_duration_time; string menu_background; float menu_changetime; +float menu_starttime; float current_menu; diff --git a/source/menu/m_menu.qc b/source/menu/m_menu.qc index 349fd0a..b046823 100644 --- a/source/menu/m_menu.qc +++ b/source/menu/m_menu.qc @@ -443,9 +443,31 @@ void() Menu_DrawBackground = #ifdef MENU - sui_pic([0, 0], sui_current_frame_size(), menu_background, [1, 1, 1], 1, 1); + float elapsed_background_time = time - menu_starttime; + + // + // Slight background pan + // + float x_pos = 0 - (((sui_current_frame_size()[0] * 1.05) - sui_current_frame_size()[0]) * (elapsed_background_time/7)); + + sui_pic([x_pos, 0], [sui_current_frame_size()[0] * 1.05, sui_current_frame_size()[1]], menu_background, [1, 1, 1], 1, 1); sui_fill([0, 0], sui_current_frame_size(), [0, 0, 0], 0.7, 0); + // + // Fade new images in/out + // + float alpha = 0; + + if (elapsed_background_time < 1.0) { + alpha = 1.0f - sin((elapsed_background_time / 1.0f) * (M_PI / 2)); // Opacity from 1 -> 0 + } else if (elapsed_background_time < 6.0f) { + alpha = 0.0f; + } else if (elapsed_background_time < 7.0f) { + alpha = sin(((elapsed_background_time - 6.0f) / 1.0f) * (M_PI / 2)); // Opacity from 0 -> 1 + } + + sui_fill([0, 0], sui_current_frame_size(), [0, 0, 0], alpha, 0); + #else sui_fill([0, 0], sui_current_frame_size(), [0, 0, 0], 0.8, 0); diff --git a/source/menu/main.qc b/source/menu/main.qc index 7b748ac..501ef91 100644 --- a/source/menu/main.qc +++ b/source/menu/main.qc @@ -230,7 +230,8 @@ void(vector screensize) m_draw = // Menu Background Changing if (time > menu_changetime) { menu_background = Menu_PickBackground(); - menu_changetime = time + 5; + menu_changetime = time + 7; + menu_starttime = time; } sui_begin(screensize_x, screensize_y);