[SettingsMenuState] 'Esc' key issue fixed.

master
Quentin Bazin 2019-12-30 21:08:25 +09:00
parent e8f0198c3c
commit 3d126bd9bf
4 changed files with 31 additions and 17 deletions

View File

@ -13,7 +13,7 @@
- [How to compile](#how-to-compile)
- [Discussion](#discussion)
- [Project status](#project-status)
- [Previous versions](#previous-versions)
- [Previous attempts](#previous-attempts)
- [Credits](#credits)
## Wiki

4
TODO
View File

@ -5,18 +5,20 @@ TODO
• TODO: Use Faithful 32x for buttons, backgrounds and font (or use Minecraftia for the latter)
• TODO: Add a texture pack system
◦ TODO: It should be able to accept any type of texture resolution
• TODO: Add fullscreen, resolution options and handle window resize
• TODO: Include server code in the client for singleplayer games
# Issues
• DONE: Crafting doesnt always work
• DONE: A mix of pickaxe + axe recipes gives a pickaxe?!
• DONE: Lighting doesnt propagate between chunks
• DONE: Pressing `Esc` key in `SettingsMenuState` should just quit the category, not the state
• TODO: Shapeless recipe code isnt working
• TODO: `Workbench` and `Furnace` are not scaled correctly with lower GUI scale settings
◦ TODO: Send client screen size and GUI scale to server
• TODO: `Hotbar` doesnt update when GUI scale is changed
• TODO: `SettingsMenuState` should update scaling when the setting is changed
• TODO: Pressing `Esc` key in `SettingsMenuState` should just quit the category, not the state
• TODO: Blocks can be accessed from outside the world (will need a refactoring)
• TODO: Collisions are fucked up with blocks placed at `x = -1` from `x = 0`
• TODO: Blocks can be placed inside the player (check for AABB?)

View File

@ -29,6 +29,8 @@ class SettingsMenuState : public InterfaceState {
void update() override;
private:
void doneButtonAction();
void addMainButtons();
void addGameplayButtons();
void addGraphicsButtons();
@ -45,6 +47,15 @@ class SettingsMenuState : public InterfaceState {
u8 m_currentKey = GameKey::Undefined;
TextButton *m_currentKeyButton = nullptr;
enum class MenuState {
Main,
Gameplay,
Graphics,
Input
};
MenuState m_state = MenuState::Main;
};
#endif // SETTINGSMENUSTATE_HPP_

View File

@ -34,6 +34,9 @@ SettingsMenuState::SettingsMenuState(gk::ApplicationState *parent) : InterfaceSt
m_doneButton.setPosition(SCREEN_WIDTH / 2 - m_doneButton.getGlobalBounds().width * GUI_SCALE / 2, SCREEN_HEIGHT - 291);
m_doneButton.setScale(GUI_SCALE, GUI_SCALE, 1);
m_doneButton.setText("Done");
m_doneButton.setCallback([this] (TextButton &) {
doneButtonAction();
});
addMainButtons();
}
@ -43,7 +46,7 @@ void SettingsMenuState::onEvent(const SDL_Event &event) {
m_doneButton.onEvent(event);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
m_stateStack->pop();
doneButtonAction();
}
else if (m_currentKeyButton && event.type == SDL_KEYDOWN) {
gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler();
@ -57,22 +60,32 @@ void SettingsMenuState::onEvent(const SDL_Event &event) {
void SettingsMenuState::update() {
}
void SettingsMenuState::doneButtonAction() {
if (m_state != MenuState::Main) {
m_state = MenuState::Main;
addMainButtons();
} else {
m_stateStack->pop();
}
}
void SettingsMenuState::addMainButtons() {
m_menuWidget.reset(1, 8);
m_menuWidget.addButton("Gameplay...", [this] (TextButton &) {
m_state = MenuState::Gameplay;
addGameplayButtons();
});
m_menuWidget.addButton("Graphics...", [this] (TextButton &) {
m_state = MenuState::Graphics;
addGraphicsButtons();
});
m_menuWidget.addButton("Input...", [this] (TextButton &) {
m_state = MenuState::Input;
addInputButtons();
});
m_doneButton.setCallback([this] (TextButton &) { m_stateStack->pop(); });
}
void SettingsMenuState::addGameplayButtons() {
@ -80,10 +93,6 @@ void SettingsMenuState::addGameplayButtons() {
addToggleButton("Fly Mode", Config::isFlyModeEnabled, false);
addToggleButton("No Clip", Config::isNoClipEnabled, false);
m_doneButton.setCallback([this] (TextButton &) {
addMainButtons();
});
}
void SettingsMenuState::addGraphicsButtons() {
@ -107,10 +116,6 @@ void SettingsMenuState::addGraphicsButtons() {
m_menuWidget.addButton("Fullscreen: OFF", [] (TextButton &) {}).setEnabled(false);
m_menuWidget.addButton("Use VSync: OFF", [] (TextButton &) {}).setEnabled(false);
m_doneButton.setCallback([this] (TextButton &) {
addMainButtons();
});
}
void SettingsMenuState::addInputButtons() {
@ -138,10 +143,6 @@ void SettingsMenuState::addInputButtons() {
m_currentKeyButton = &button;
});
}
m_doneButton.setCallback([this] (TextButton &) {
addMainButtons();
});
}
TextButton &SettingsMenuState::addToggleButton(const std::string &text, bool &configOption, bool worldReloadRequested) {