From 2d417f6eaa1bcde97c6deea19a2a16302f3e91ed Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Mon, 27 Jan 2020 15:33:06 +0900 Subject: [PATCH] [GameState|HUD|InterfaceState] Fullscreen and resize handling added. --- client/include/core/ClientApplication.hpp | 2 + client/include/hud/Crosshair.hpp | 2 + client/include/hud/HUD.hpp | 2 + client/include/states/InterfaceState.hpp | 6 +++ client/include/states/InventoryState.hpp | 2 - client/include/states/LuaGUIState.hpp | 2 - client/include/states/PauseMenuState.hpp | 2 - client/include/states/SettingsMenuState.hpp | 2 - client/source/core/ClientApplication.cpp | 9 ++++ client/source/gui/MenuWidget.cpp | 12 ++++- client/source/hud/Crosshair.cpp | 4 ++ client/source/hud/HUD.cpp | 6 +++ client/source/states/GameState.cpp | 52 ++++++++++++--------- client/source/states/InterfaceState.cpp | 26 ++++++++++- client/source/states/InventoryState.cpp | 15 +++--- client/source/states/LuaGUIState.cpp | 7 +-- client/source/states/PauseMenuState.cpp | 44 +++++++++++------ client/source/states/ServerConnectState.cpp | 8 ++++ client/source/states/SettingsMenuState.cpp | 39 +++++++++------- client/source/states/TitleScreenState.cpp | 2 + common/include/core/Config.hpp | 15 ++++-- common/source/core/Config.cpp | 12 ++++- 22 files changed, 189 insertions(+), 82 deletions(-) diff --git a/client/include/core/ClientApplication.hpp b/client/include/core/ClientApplication.hpp index 68b7d8040..fd4ce4782 100644 --- a/client/include/core/ClientApplication.hpp +++ b/client/include/core/ClientApplication.hpp @@ -26,6 +26,8 @@ class ClientApplication : public gk::CoreApplication { void init() override; private: + void handleEvents() override; + void initOpenGL(); gk::KeyboardHandler m_keyboardHandler; diff --git a/client/include/hud/Crosshair.hpp b/client/include/hud/Crosshair.hpp index 264a4fc22..d6c6fd6c5 100644 --- a/client/include/hud/Crosshair.hpp +++ b/client/include/hud/Crosshair.hpp @@ -20,6 +20,8 @@ class Crosshair : public gk::Drawable { public: Crosshair(); + void setup(); + private: void draw(gk::RenderTarget &target, gk::RenderStates states) const override; diff --git a/client/include/hud/HUD.hpp b/client/include/hud/HUD.hpp index e695865c2..16b995f84 100644 --- a/client/include/hud/HUD.hpp +++ b/client/include/hud/HUD.hpp @@ -26,6 +26,8 @@ class HUD : public gk::Transformable, public gk::Drawable { public: HUD(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client); + void setup(); + void onEvent(const SDL_Event &event); void update(); diff --git a/client/include/states/InterfaceState.hpp b/client/include/states/InterfaceState.hpp index 6e33a8983..fe79d13ee 100644 --- a/client/include/states/InterfaceState.hpp +++ b/client/include/states/InterfaceState.hpp @@ -16,12 +16,16 @@ #include #include +#include class InterfaceState : public gk::ApplicationState { public: InterfaceState(gk::ApplicationState *parent = nullptr); protected: + void setup(); + void onEvent(const SDL_Event &event) override; + void prepareDraw(gk::RenderTarget &target, gk::RenderStates &states) const; private: @@ -29,6 +33,8 @@ class InterfaceState : public gk::ApplicationState { // gk::View m_view; glm::mat4 m_projectionMatrix; + + gk::RectangleShape m_background; }; #endif // INTERFACESTATE_HPP_ diff --git a/client/include/states/InventoryState.hpp b/client/include/states/InventoryState.hpp index 8e5fcec3c..eded29142 100644 --- a/client/include/states/InventoryState.hpp +++ b/client/include/states/InventoryState.hpp @@ -44,8 +44,6 @@ class InventoryState : public InterfaceState { void draw(gk::RenderTarget &target, gk::RenderStates states) const override; std::unique_ptr m_widget; - - gk::RectangleShape m_background; }; #endif // INVENTORYSTATE_HPP_ diff --git a/client/include/states/LuaGUIState.hpp b/client/include/states/LuaGUIState.hpp index b1c435feb..b89e5716c 100644 --- a/client/include/states/LuaGUIState.hpp +++ b/client/include/states/LuaGUIState.hpp @@ -51,8 +51,6 @@ class LuaGUIState : public InterfaceState { std::deque m_inventoryWidgets; std::vector> m_widgets; std::vector> m_drawables; - - gk::RectangleShape m_background; }; #endif // LUAGUISTATE_HPP_ diff --git a/client/include/states/PauseMenuState.hpp b/client/include/states/PauseMenuState.hpp index b4e356e02..f6f4e9514 100644 --- a/client/include/states/PauseMenuState.hpp +++ b/client/include/states/PauseMenuState.hpp @@ -34,8 +34,6 @@ class PauseMenuState : public InterfaceState { MenuWidget m_menuWidget{1, 4}; - gk::RectangleShape m_background; - Client &m_client; }; diff --git a/client/include/states/SettingsMenuState.hpp b/client/include/states/SettingsMenuState.hpp index 72b15f47d..f1458f9a4 100644 --- a/client/include/states/SettingsMenuState.hpp +++ b/client/include/states/SettingsMenuState.hpp @@ -40,8 +40,6 @@ class SettingsMenuState : public InterfaceState { void draw(gk::RenderTarget &target, gk::RenderStates states) const override; - gk::RectangleShape m_background; - MenuWidget m_menuWidget; TextButton m_doneButton; diff --git a/client/source/core/ClientApplication.cpp b/client/source/core/ClientApplication.cpp index f39c5d164..64fb50bb0 100644 --- a/client/source/core/ClientApplication.cpp +++ b/client/source/core/ClientApplication.cpp @@ -62,6 +62,15 @@ void ClientApplication::init() { // m_stateStack.push(game); } +void ClientApplication::handleEvents() { + gk::CoreApplication::handleEvents(); + + if ((Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Fullscreen) + || (!Config::isFullscreenModeEnabled && m_window.getWindowMode() != gk::Window::Mode::Windowed)) { + m_window.setWindowMode(Config::isFullscreenModeEnabled ? gk::Window::Mode::Fullscreen : gk::Window::Mode::Windowed); + } +} + void ClientApplication::initOpenGL() { // Enable transparency glCheck(glEnable(GL_BLEND)); diff --git a/client/source/gui/MenuWidget.cpp b/client/source/gui/MenuWidget.cpp index cbb0d0e18..78d2ef89e 100644 --- a/client/source/gui/MenuWidget.cpp +++ b/client/source/gui/MenuWidget.cpp @@ -27,8 +27,16 @@ void MenuWidget::reset(u16 width, u16 height) { } void MenuWidget::onEvent(const SDL_Event &event) { - for (TextButton &button : m_buttons) { - button.onEvent(event); + for (std::size_t i = 0 ; i < m_buttons.size() ; ++i) { + m_buttons.at(i).onEvent(event); + + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + int x = i % m_width; + int y = i / m_width; + + m_buttons.at(i).setPosition(SCREEN_WIDTH / getScale().x / 2 - (m_width * (m_buttons.at(i).width() + s_horizontalSpacing) - s_horizontalSpacing) / 2 + x * (m_buttons.at(i).width() + s_horizontalSpacing), + SCREEN_HEIGHT / getScale().y / 2 - (m_height * (m_buttons.at(i).height() + s_verticalSpacing) - s_verticalSpacing) / 2 + y * (m_buttons.at(i).height() + s_verticalSpacing), 0); + } } } diff --git a/client/source/hud/Crosshair.cpp b/client/source/hud/Crosshair.cpp index 71ba8f2c5..b930928e4 100644 --- a/client/source/hud/Crosshair.cpp +++ b/client/source/hud/Crosshair.cpp @@ -15,6 +15,10 @@ #include "Crosshair.hpp" Crosshair::Crosshair() { + setup(); +} + +void Crosshair::setup() { float xFactor = SCREEN_WIDTH * SCREEN_HEIGHT / 100; float yFactor = SCREEN_HEIGHT * SCREEN_WIDTH / 100; diff --git a/client/source/hud/HUD.cpp b/client/source/hud/HUD.cpp index 792a78405..02f2e3968 100644 --- a/client/source/hud/HUD.cpp +++ b/client/source/hud/HUD.cpp @@ -31,11 +31,17 @@ HUD::HUD(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client) m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl"); m_shader.linkProgram(); + setup(); +} + +void HUD::setup() { m_orthoMatrix = glm::ortho(0.0f, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.0f); m_hotbar.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_hotbar.width() / 2, SCREEN_HEIGHT / getScale().y - m_hotbar.height(), 0); m_blockInfoWidget.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_blockInfoWidget.width() / 2, 2, 0); + + m_crosshair.setup(); } void HUD::onEvent(const SDL_Event &event) { diff --git a/client/source/states/GameState.cpp b/client/source/states/GameState.cpp index 0c31ad7e1..fa99e1daf 100644 --- a/client/source/states/GameState.cpp +++ b/client/source/states/GameState.cpp @@ -53,33 +53,43 @@ GameState::GameState(const std::string &host, int port) { } void GameState::onEvent(const SDL_Event &event) { - if (event.type == SDL_MOUSEMOTION) { - if(SCREEN_WIDTH / 2 != event.motion.x || SCREEN_HEIGHT / 2 != event.motion.y) { - m_player.turnH(event.motion.xrel * 0.01 * Config::mouseSensitivity); - m_player.turnV(-event.motion.yrel * 0.01 * Config::mouseSensitivity); + if (&m_stateStack->top() == this) { + if (event.type == SDL_MOUSEMOTION) { + if(SCREEN_WIDTH / 2 != event.motion.x || SCREEN_HEIGHT / 2 != event.motion.y) { + m_player.turnH(event.motion.xrel * 0.01 * Config::mouseSensitivity); + m_player.turnV(-event.motion.yrel * 0.01 * Config::mouseSensitivity); - gk::Mouse::resetToWindowCenter(); + gk::Mouse::resetToWindowCenter(); + } } - } - else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE && &m_stateStack->top() == this) { - m_stateStack->push(m_client, this); - } - else if (event.type == SDL_WINDOWEVENT) { - if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { - // FIXME - // m_stateStack->push(this); - - gk::Mouse::setCursorGrabbed(false); - gk::Mouse::setCursorVisible(true); + else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + m_stateStack->push(m_client, this); } - else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { - gk::Mouse::setCursorGrabbed(true); - gk::Mouse::setCursorVisible(false); + else if (event.type == SDL_WINDOWEVENT) { + if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { + // FIXME + // m_stateStack->push(this); + + gk::Mouse::setCursorGrabbed(false); + gk::Mouse::setCursorVisible(true); + } + else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + gk::Mouse::setCursorGrabbed(true); + gk::Mouse::setCursorVisible(false); + } } + + if (m_clientCommandHandler.isRegistryInitialized()) + m_hud.onEvent(event); } - if (m_clientCommandHandler.isRegistryInitialized()) - m_hud.onEvent(event); + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + SCREEN_WIDTH = event.window.data1; + SCREEN_HEIGHT = event.window.data2; + + m_camera.setAspectRatio((float)SCREEN_WIDTH / SCREEN_HEIGHT); + m_hud.setup(); + } } void GameState::update() { diff --git a/client/source/states/InterfaceState.cpp b/client/source/states/InterfaceState.cpp index cf9a6f02b..64a4204b3 100644 --- a/client/source/states/InterfaceState.cpp +++ b/client/source/states/InterfaceState.cpp @@ -22,13 +22,34 @@ InterfaceState::InterfaceState(gk::ApplicationState *parent) : gk::ApplicationSt m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl"); m_shader.linkProgram(); + m_background.setFillColor(gk::Color{0, 0, 0, 127}); + + setup(); +} + +void InterfaceState::setup() { m_projectionMatrix = glm::ortho(0.0f, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.0f); + m_background.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); + // m_view.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); // m_view.setCenter(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2); } -void InterfaceState::prepareDraw(gk::RenderTarget &, gk::RenderStates &states) const { +void InterfaceState::onEvent(const SDL_Event &event) { + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (m_parent) + m_parent->onEvent(event); + else { + SCREEN_WIDTH = event.window.data1; + SCREEN_HEIGHT = event.window.data2; + } + + setup(); + } +} + +void InterfaceState::prepareDraw(gk::RenderTarget &target, gk::RenderStates &states) const { states.transform *= getTransform(); states.shader = &m_shader; // states.vertexAttributes = gk::VertexAttribute::Only2d; @@ -36,5 +57,8 @@ void InterfaceState::prepareDraw(gk::RenderTarget &, gk::RenderStates &states) c states.projectionMatrix = m_projectionMatrix; // target.setView(m_view); + + if (m_parent) + target.draw(m_background, states); } diff --git a/client/source/states/InventoryState.cpp b/client/source/states/InventoryState.cpp index 524373e64..17fde38eb 100644 --- a/client/source/states/InventoryState.cpp +++ b/client/source/states/InventoryState.cpp @@ -22,14 +22,17 @@ InventoryState::InventoryState(gk::ApplicationState *parent) : InterfaceState(pa gk::Mouse::setCursorGrabbed(false); gk::Mouse::setCursorVisible(true); gk::Mouse::resetToWindowCenter(); - - m_background.setFillColor(gk::Color{0, 0, 0, 127}); - m_background.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); } void InventoryState::onEvent(const SDL_Event &event) { - // if (m_parent) - // m_parent->onEvent(event); + InterfaceState::onEvent(event); + + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (m_widget) { + m_widget->setPosition(SCREEN_WIDTH / 2.0 - m_widget->getGlobalBounds().width / 2.0, + SCREEN_HEIGHT / 2.0 - m_widget->getGlobalBounds().height / 2.0, 0); + } + } if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { gk::Mouse::setCursorGrabbed(true); @@ -57,8 +60,6 @@ void InventoryState::draw(gk::RenderTarget &target, gk::RenderStates states) con prepareDraw(target, states); - target.draw(m_background, states); - if (m_widget) target.draw(*m_widget, states); } diff --git a/client/source/states/LuaGUIState.cpp b/client/source/states/LuaGUIState.cpp index 32507e97a..35e3c2924 100644 --- a/client/source/states/LuaGUIState.cpp +++ b/client/source/states/LuaGUIState.cpp @@ -35,9 +35,6 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli gk::Mouse::setCursorVisible(true); gk::Mouse::resetToWindowCenter(); - m_background.setFillColor(gk::Color{0, 0, 0, 127}); - m_background.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); - m_mainWidget.setScale(GUI_SCALE, GUI_SCALE); while (!packet.endOfPacket()) @@ -45,6 +42,8 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli } void LuaGUIState::onEvent(const SDL_Event &event) { + InterfaceState::onEvent(event); + if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { gk::Mouse::setCursorGrabbed(true); gk::Mouse::setCursorVisible(false); @@ -98,8 +97,6 @@ void LuaGUIState::draw(gk::RenderTarget &target, gk::RenderStates states) const states.transform *= m_mainWidget.getTransform(); states.viewMatrix = gk::Transform::Identity; - target.draw(m_background, states); - for (auto &it : m_drawables) target.draw(*it, states); diff --git a/client/source/states/PauseMenuState.cpp b/client/source/states/PauseMenuState.cpp index a73c1022d..c7d6c3c8e 100644 --- a/client/source/states/PauseMenuState.cpp +++ b/client/source/states/PauseMenuState.cpp @@ -29,12 +29,18 @@ PauseMenuState::PauseMenuState(Client &client, gk::ApplicationState *parent) gk::Mouse::setCursorVisible(true); gk::Mouse::resetToWindowCenter(); - m_background.setFillColor(gk::Color{0, 0, 0, 127}); - m_background.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); - m_menuWidget.setScale(GUI_SCALE, GUI_SCALE, 1); - m_menuWidget.addButton("Back to Game", [this] (TextButton &) { gk::Mouse::setCursorGrabbed(true); gk::Mouse::setCursorVisible(false); m_stateStack->pop(); }); - m_menuWidget.addButton("Options...", [this] (TextButton &) { m_stateStack->push(m_parent); }); + + m_menuWidget.addButton("Back to Game", [this] (TextButton &) { + gk::Mouse::setCursorGrabbed(true); + gk::Mouse::setCursorVisible(false); + + m_stateStack->pop(); + }); + + m_menuWidget.addButton("Options...", [this] (TextButton &) { + m_stateStack->push(this); + }); m_menuWidget.addButton("Title Screen", [this] (TextButton &) { // m_client.disconnect(); @@ -52,14 +58,23 @@ PauseMenuState::PauseMenuState(Client &client, gk::ApplicationState *parent) } void PauseMenuState::onEvent(const SDL_Event &event) { - m_menuWidget.onEvent(event); + InterfaceState::onEvent(event); - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { - gk::Mouse::setCursorGrabbed(true); - gk::Mouse::setCursorVisible(false); - gk::Mouse::resetToWindowCenter(); + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (&m_stateStack->top() != this) + m_menuWidget.onEvent(event); + } - m_stateStack->pop(); + if (&m_stateStack->top() == this) { + m_menuWidget.onEvent(event); + + if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + gk::Mouse::setCursorGrabbed(true); + gk::Mouse::setCursorVisible(false); + gk::Mouse::resetToWindowCenter(); + + m_stateStack->pop(); + } } } @@ -70,9 +85,10 @@ void PauseMenuState::draw(gk::RenderTarget &target, gk::RenderStates states) con if (m_parent) target.draw(*m_parent, states); - prepareDraw(target, states); + if (&m_stateStack->top() == this) { + prepareDraw(target, states); - target.draw(m_background, states); - target.draw(m_menuWidget, states); + target.draw(m_menuWidget, states); + } } diff --git a/client/source/states/ServerConnectState.cpp b/client/source/states/ServerConnectState.cpp index 0fd09758d..3f5f6e8c3 100644 --- a/client/source/states/ServerConnectState.cpp +++ b/client/source/states/ServerConnectState.cpp @@ -55,6 +55,14 @@ ServerConnectState::ServerConnectState() { } void ServerConnectState::onEvent(const SDL_Event &event) { + InterfaceState::onEvent(event); + + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + m_textInput.setPosition(SCREEN_WIDTH / 2 - m_textInput.getSize().x / 2, SCREEN_HEIGHT / 2 - m_textInput.getSize().y / 2); + m_connectButton.setPosition(SCREEN_WIDTH / 2 - m_connectButton.getGlobalBounds().width / 2, SCREEN_HEIGHT - 340); + m_cancelButton.setPosition(SCREEN_WIDTH / 2 - m_cancelButton.getGlobalBounds().width / 2, SCREEN_HEIGHT - 261); + } + m_textInput.onEvent(event); m_connectButton.onEvent(event); diff --git a/client/source/states/SettingsMenuState.cpp b/client/source/states/SettingsMenuState.cpp index e4e791397..9268cb8b3 100644 --- a/client/source/states/SettingsMenuState.cpp +++ b/client/source/states/SettingsMenuState.cpp @@ -26,9 +26,6 @@ #include "World.hpp" SettingsMenuState::SettingsMenuState(gk::ApplicationState *parent) : InterfaceState(parent) { - m_background.setFillColor(gk::Color{0, 0, 0, 127}); - m_background.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); - m_menuWidget.setScale(GUI_SCALE, GUI_SCALE, 1); m_doneButton.setPosition(SCREEN_WIDTH / 2 - m_doneButton.getGlobalBounds().width * GUI_SCALE / 2, SCREEN_HEIGHT - 291); @@ -42,18 +39,29 @@ SettingsMenuState::SettingsMenuState(gk::ApplicationState *parent) : InterfaceSt } void SettingsMenuState::onEvent(const SDL_Event &event) { - m_menuWidget.onEvent(event); - m_doneButton.onEvent(event); + InterfaceState::onEvent(event); - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { - doneButtonAction(); + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + m_doneButton.setPosition(SCREEN_WIDTH / 2 - m_doneButton.getGlobalBounds().width / 2, SCREEN_HEIGHT - 291); + + if (&m_stateStack->top() != this) + m_menuWidget.onEvent(event); } - else if (m_currentKeyButton && event.type == SDL_KEYDOWN) { - gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler(); - keyboardHandler->setKeycode(m_currentKey, event.key.keysym.sym); - m_currentKeyButton->setText(m_currentKeyButton->text() + keyboardHandler->getKeyName(m_currentKey)); - m_currentKeyButton = nullptr; + if (&m_stateStack->top() == this) { + m_menuWidget.onEvent(event); + m_doneButton.onEvent(event); + + if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { + doneButtonAction(); + } + else if (m_currentKeyButton && event.type == SDL_KEYDOWN) { + gk::KeyboardHandler *keyboardHandler = (gk::KeyboardHandler *)gk::GamePad::getInputHandler(); + keyboardHandler->setKeycode(m_currentKey, event.key.keysym.sym); + + m_currentKeyButton->setText(m_currentKeyButton->text() + keyboardHandler->getKeyName(m_currentKey)); + m_currentKeyButton = nullptr; + } } } @@ -114,8 +122,8 @@ void SettingsMenuState::addGraphicsButtons() { button.setText("GUI Scale: " + std::to_string(GUI_SCALE)); }); - m_menuWidget.addButton("Fullscreen: OFF", [] (TextButton &) {}).setEnabled(false); - m_menuWidget.addButton("Use VSync: OFF", [] (TextButton &) {}).setEnabled(false); + addToggleButton("Fullscreen", Config::isFullscreenModeEnabled, false); + m_menuWidget.addButton("Use VSync: ON", [] (TextButton &) {}).setEnabled(false); } void SettingsMenuState::addInputButtons() { @@ -166,9 +174,6 @@ void SettingsMenuState::draw(gk::RenderTarget &target, gk::RenderStates states) prepareDraw(target, states); - if (m_parent) - target.draw(m_background, states); - target.draw(m_menuWidget, states); target.draw(m_doneButton, states); diff --git a/client/source/states/TitleScreenState.cpp b/client/source/states/TitleScreenState.cpp index daa18cff2..0fa66ab72 100644 --- a/client/source/states/TitleScreenState.cpp +++ b/client/source/states/TitleScreenState.cpp @@ -37,6 +37,8 @@ TitleScreenState::TitleScreenState() { } void TitleScreenState::onEvent(const SDL_Event &event) { + InterfaceState::onEvent(event); + m_menuWidget.onEvent(event); } diff --git a/common/include/core/Config.hpp b/common/include/core/Config.hpp index 2d8ad9779..0c1e011d1 100644 --- a/common/include/core/Config.hpp +++ b/common/include/core/Config.hpp @@ -19,9 +19,6 @@ namespace { constexpr const char *APP_NAME = "OpenMiner"; - constexpr float SCREEN_WIDTH = 1600; - constexpr float SCREEN_HEIGHT = 1050; - constexpr float DIST_NEAR = 0.1f; constexpr float DIST_FAR = 1000.0f; @@ -32,7 +29,12 @@ namespace { constexpr int SEALEVEL = 4; } -extern int GUI_SCALE; // FIXME +// FIXME +extern float SCREEN_WIDTH; +extern float SCREEN_HEIGHT; + +// FIXME +extern int GUI_SCALE; namespace Config { // Gameplay @@ -40,12 +42,15 @@ namespace Config { extern bool isNoClipEnabled; // Graphics + extern u16 renderDistance; extern bool isTorchSmoothLightingEnabled; extern bool isSunSmoothLightingEnabled; extern bool isAmbientOcclusionEnabled; extern bool isWireframeModeEnabled; - extern u16 renderDistance; + extern bool isFullscreenModeEnabled; extern float cameraFOV; + + // Input extern u8 mouseSensitivity; } diff --git a/common/source/core/Config.cpp b/common/source/core/Config.cpp index b8bf8725c..e6170056e 100644 --- a/common/source/core/Config.cpp +++ b/common/source/core/Config.cpp @@ -13,18 +13,26 @@ */ #include "Config.hpp" -int GUI_SCALE = 3; // FIXME +// FIXME +float SCREEN_WIDTH = 1600; +float SCREEN_HEIGHT = 1050; + +// FIXME +int GUI_SCALE = 3; // Gameplay bool Config::isFlyModeEnabled = false; bool Config::isNoClipEnabled = false; // Graphics +u16 Config::renderDistance = 8; bool Config::isTorchSmoothLightingEnabled = true; bool Config::isSunSmoothLightingEnabled = true; bool Config::isAmbientOcclusionEnabled = false; bool Config::isWireframeModeEnabled = false; -u16 Config::renderDistance = 8; +bool Config::isFullscreenModeEnabled = false; float Config::cameraFOV = 70.0f; + +// Input u8 Config::mouseSensitivity = 8;