feat: add switching to settings and back.
This commit is contained in:
+1
-1
@@ -69,7 +69,7 @@ void UpdateApp(App *app){
|
|||||||
}break;
|
}break;
|
||||||
case SETTINGS:
|
case SETTINGS:
|
||||||
{
|
{
|
||||||
UpdateSettings(&app->settings, &app->flags);
|
UpdateSettings(&app->settings, &app->state, &app->flags);
|
||||||
RenderSettings(&app->settings, &app->flags);
|
RenderSettings(&app->settings, &app->flags);
|
||||||
}
|
}
|
||||||
default: break;
|
default: break;
|
||||||
|
|||||||
+46
-13
@@ -21,6 +21,7 @@ typedef struct
|
|||||||
ImageElement board;
|
ImageElement board;
|
||||||
ImageButton playButton;
|
ImageButton playButton;
|
||||||
ImageButton quitButton;
|
ImageButton quitButton;
|
||||||
|
ImageButton settingsButton;
|
||||||
int menuScale;
|
int menuScale;
|
||||||
Background background;
|
Background background;
|
||||||
Background midground;
|
Background midground;
|
||||||
@@ -79,27 +80,52 @@ void InitMenu(MenuState *m)
|
|||||||
int buttonHeight = (int)(m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight * buttonScaleFactor);
|
int buttonHeight = (int)(m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight * buttonScaleFactor);
|
||||||
int buttonSpacing = buttonHeight;
|
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 = {
|
//Button texture dimensions
|
||||||
.x = windowCenter.x - (buttonWidth / 2),
|
float menuButtonWidth = m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameWidth;
|
||||||
.y = windowCenter.y - (buttonHeight / 2),
|
float menuButtonHeight = m->assets.textureAssets[MENU_BIG_BUTTONS_TEX].frameHeight;
|
||||||
.width = buttonWidth,
|
|
||||||
.height = buttonHeight};
|
//Quit Button
|
||||||
|
Vector2 quitButtonNotPressed = {0.0f, 0.0f};
|
||||||
|
Vector2 quitButtonHover = {menuButtonWidth, 0.0f};
|
||||||
|
Vector2 quitButtonPressed = {menuButtonWidth * 2, 0.0f};
|
||||||
|
|
||||||
Rectangle quitButtonDestRec = {
|
Rectangle quitButtonDestRec = {
|
||||||
.x = windowCenter.x - (buttonWidth / 2),
|
.x = windowCenter.x - (buttonWidth / 2),
|
||||||
.y = windowCenter.y - (buttonHeight / 2) + buttonSpacing,
|
.y = windowCenter.y - (buttonHeight / 2) + buttonSpacing,
|
||||||
.width = buttonWidth,
|
.width = buttonWidth,
|
||||||
.height = buttonHeight};
|
.height = buttonHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
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);
|
|
||||||
|
//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)
|
void UpdateMenu(MenuState *m, State *state, Flags *flags)
|
||||||
@@ -126,11 +152,17 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags)
|
|||||||
state->currentView = GAMEPLAY;
|
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)))
|
if (isImageButtonClicked(&m->quitButton, m->sounds[HOVER_SOUND], m->sounds[CLICK_SOUND]) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)))
|
||||||
{
|
{
|
||||||
state->running = false;
|
state->running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UpdateBackground(&m->background);
|
UpdateBackground(&m->background);
|
||||||
UpdateBackground(&m->midground);
|
UpdateBackground(&m->midground);
|
||||||
UpdateBackground(&m->foreground);
|
UpdateBackground(&m->foreground);
|
||||||
@@ -148,6 +180,7 @@ void RenderMenu(MenuState *m, Font *font, const char *title, Flags *flags)
|
|||||||
renderImageElement(&m->board);
|
renderImageElement(&m->board);
|
||||||
renderImageButton(&m->playButton);
|
renderImageButton(&m->playButton);
|
||||||
renderImageButton(&m->quitButton);
|
renderImageButton(&m->quitButton);
|
||||||
|
renderImageButton(&m->settingsButton);
|
||||||
int textWidth = MeasureText(title, font->baseSize);
|
int textWidth = MeasureText(title, font->baseSize);
|
||||||
DrawTextEx(*font, title, (Vector2){GetScreenWidth() / 2 - textWidth / 2, textWidth / 4}, (float)font->baseSize, 2, WHITE);
|
DrawTextEx(*font, title, (Vector2){GetScreenWidth() / 2 - textWidth / 2, textWidth / 4}, (float)font->baseSize, 2, WHITE);
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ typedef enum
|
|||||||
|
|
||||||
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
|
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
|
||||||
{"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.0f, 0.0f},
|
{"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/SproutLandsUI/Spritesheets/Settingmenu.png", 128.0f, 144.0f, 0.0f},
|
||||||
{"assets/Clouds/Clouds1/1.png", 576.0f, 324.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},
|
{"assets/Clouds/Clouds1/2.png", 576.0f, 324.0f, 0.0f},
|
||||||
|
|||||||
+7
-1
@@ -28,7 +28,7 @@ void InitSettings(SettingsState *s)
|
|||||||
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button2Pos);
|
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button2Pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateSettings(SettingsState *s, Flags *flags)
|
void UpdateSettings(SettingsState *s, State *state,Flags *flags)
|
||||||
{
|
{
|
||||||
ShowCursor();
|
ShowCursor();
|
||||||
|
|
||||||
@@ -39,6 +39,12 @@ void UpdateSettings(SettingsState *s, Flags *flags)
|
|||||||
if(isButtonClicked(&s->soundtrackOn)){
|
if(isButtonClicked(&s->soundtrackOn)){
|
||||||
flags->soundtrackOn = !flags->soundtrackOn;
|
flags->soundtrackOn = !flags->soundtrackOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_ESCAPE)){
|
||||||
|
state->currentView = MENU;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSettings(SettingsState *s, Flags *flags)
|
void RenderSettings(SettingsState *s, Flags *flags)
|
||||||
|
|||||||
Reference in New Issue
Block a user