From f8132205f63bbdd724e7d54c8ceabd4434552f56 Mon Sep 17 00:00:00 2001 From: huaqo-games Date: Fri, 17 Oct 2025 22:25:39 +0200 Subject: [PATCH] feat: add switching to settings and back. --- include/app.h | 2 +- include/menu.h | 59 ++++++++++++++++++++++++++++++++++---------- include/menuassets.h | 2 +- include/settings.h | 8 +++++- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/include/app.h b/include/app.h index 6237ead..6f8c71e 100644 --- a/include/app.h +++ b/include/app.h @@ -69,7 +69,7 @@ void UpdateApp(App *app){ }break; case SETTINGS: { - UpdateSettings(&app->settings, &app->flags); + UpdateSettings(&app->settings, &app->state, &app->flags); RenderSettings(&app->settings, &app->flags); } default: break; diff --git a/include/menu.h b/include/menu.h index f84aa1d..3f28e5f 100644 --- a/include/menu.h +++ b/include/menu.h @@ -21,6 +21,7 @@ typedef struct ImageElement board; ImageButton playButton; ImageButton quitButton; + ImageButton settingsButton; int menuScale; Background background; Background midground; @@ -79,27 +80,52 @@ void InitMenu(MenuState *m) int buttonHeight = (int)(m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight * buttonScaleFactor); int buttonSpacing = buttonHeight; - Vector2 playButtonNotPressed = {0.0f, 96.0f}; - Vector2 quitButtonNotPressed = {0.0f, 0.0f}; - Vector2 playButtonHover = {96.0f, 96.0f}; - Vector2 quitButtonHover = {96.0f, 0.0f}; - Vector2 playButtonPressed = {192.0f, 96.0f}; - Vector2 quitButtonPressed = {192.0f, 0.0f}; - Rectangle playButtonDestRec = { - .x = windowCenter.x - (buttonWidth / 2), - .y = windowCenter.y - (buttonHeight / 2), - .width = buttonWidth, - .height = buttonHeight}; + //Button texture dimensions + float menuButtonWidth = m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameWidth; + float menuButtonHeight = m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight; + + //Quit Button + Vector2 quitButtonNotPressed = {0.0f, 0.0f}; + Vector2 quitButtonHover = {menuButtonWidth, 0.0f}; + Vector2 quitButtonPressed = {menuButtonWidth * 2, 0.0f}; Rectangle quitButtonDestRec = { .x = windowCenter.x - (buttonWidth / 2), .y = windowCenter.y - (buttonHeight / 2) + buttonSpacing, .width = buttonWidth, - .height = buttonHeight}; + .height = buttonHeight + }; - m->playButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &playButtonNotPressed, &playButtonPressed, &playButtonHover, &playButtonDestRec); m->quitButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &quitButtonNotPressed, &quitButtonPressed, &quitButtonHover, &quitButtonDestRec); + + //Play Button + Vector2 playButtonNotPressed = {0.0f, menuButtonHeight}; + Vector2 playButtonHover = {menuButtonWidth, menuButtonHeight}; + Vector2 playButtonPressed = {menuButtonWidth * 2, menuButtonHeight}; + + Rectangle playButtonDestRec = { + .x = windowCenter.x - (buttonWidth / 2), + .y = windowCenter.y - (buttonHeight / 2), + .width = buttonWidth, + .height = buttonHeight + }; + + m->playButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &playButtonNotPressed, &playButtonPressed, &playButtonHover, &playButtonDestRec); + + //Settings Button + Vector2 settingsButtonNotPressed = {0.0f, menuButtonHeight * 2}; + Vector2 settingsButtonHover = {menuButtonWidth, menuButtonHeight * 2}; + Vector2 settingsButtonPressed = {menuButtonWidth * 2, menuButtonHeight * 2}; + + Rectangle settingsButtonDestRec = { + .x = windowCenter.x - (buttonWidth / 2), + .y = windowCenter.y - (buttonHeight / 2) + buttonSpacing * 2, + .width = buttonWidth, + .height = buttonHeight + }; + + m->settingsButton = CreateImageButton(NOT_CLICKED, &m->textures[MENU_BIG_BUTTONS_TEX], &m->assets.textureAssets[MENU_BIG_BUTTONS_TEX], &settingsButtonNotPressed, &settingsButtonPressed, &settingsButtonHover, &settingsButtonDestRec); } void UpdateMenu(MenuState *m, State *state, Flags *flags) @@ -126,10 +152,16 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags) state->currentView = GAMEPLAY; } + if (isImageButtonClicked(&m->settingsButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND])) + { + state->currentView = SETTINGS; + } + if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))) { state->running = false; } + UpdateBackground(&m->background); UpdateBackground(&m->midground); @@ -148,6 +180,7 @@ void RenderMenu(MenuState *m, Font *font, const char *title, Flags *flags) renderImageElement(&m->board); renderImageButton(&m->playButton); renderImageButton(&m->quitButton); + renderImageButton(&m->settingsButton); int textWidth = MeasureText(title, font->baseSize); DrawTextEx(*font, title, (Vector2){GetScreenWidth() / 2 - textWidth / 2, textWidth / 4}, (float)font->baseSize, 2, WHITE); DrawTexturePro( diff --git a/include/menuassets.h b/include/menuassets.h index 235cf4b..2553985 100644 --- a/include/menuassets.h +++ b/include/menuassets.h @@ -15,7 +15,7 @@ typedef enum const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = { {"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.0f, 0.0f}, - {"assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover.png", 96.0f, 32.0f, 0.0f}, + {"assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover2.png", 288.0f/3, 96.0f/3, 0.0f}, {"assets/SproutLandsUI/Spritesheets/Settingmenu.png", 128.0f, 144.0f, 0.0f}, {"assets/Clouds/Clouds1/1.png", 576.0f, 324.0f, 0.0f}, {"assets/Clouds/Clouds1/2.png", 576.0f, 324.0f, 0.0f}, diff --git a/include/settings.h b/include/settings.h index 5fc568f..9acf1df 100644 --- a/include/settings.h +++ b/include/settings.h @@ -28,7 +28,7 @@ void InitSettings(SettingsState *s) s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button2Pos); } -void UpdateSettings(SettingsState *s, Flags *flags) +void UpdateSettings(SettingsState *s, State *state,Flags *flags) { ShowCursor(); @@ -39,6 +39,12 @@ void UpdateSettings(SettingsState *s, Flags *flags) if(isButtonClicked(&s->soundtrackOn)){ flags->soundtrackOn = !flags->soundtrackOn; } + + if (IsKeyPressed(KEY_ESCAPE)){ + state->currentView = MENU; + } + + } void RenderSettings(SettingsState *s, Flags *flags)