feat: add switching to settings and back.
This commit is contained in:
+46
-13
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user