git repos / saland

commit 832b0fdd

Poul Sander · 2025-12-10 16:32
832b0fdd488b713962fe309b98733bcf197b1620 patch · browse files
parent e3147b1cf6df8fba388a87a9a4b56d1594be0c2d

Convert main menu to ImGui to make it more flexible going forward. We only need mouse input anyway.

Changed files

A src/ImGuiMainMenu.cpp
A src/ImGuiMainMenu.hpp
A src/ImGuiOptions.cpp
A src/ImGuiOptions.hpp
A src/ImGuiPlayerSelect.cpp
A src/ImGuiPlayerSelect.hpp
A src/ImGuiWorldSelect.cpp
A src/ImGuiWorldSelect.hpp
M src/saland.cpp before
diff --git a/src/ImGuiMainMenu.cpp b/src/ImGuiMainMenu.cpp new file mode 100644 index 0000000..25fb222 --- /dev/null +++ b/src/ImGuiMainMenu.cpp
@@ -0,0 +1,151 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#include "ImGuiMainMenu.hpp"
+#include "Libs/imgui/imgui.h"
+#include "common.h"
+#include "saland/globals.hpp"
+#include <SDL.h>
+#include <format>
+
+ImGuiMainMenu::ImGuiMainMenu() {
+ UpdateLabels();
+}
+
+bool ImGuiMainMenu::IsActive() {
+ return active;
+}
+
+void ImGuiMainMenu::UpdateLabels() {
+ worldLabel = std::format("World: {}", Config::getInstance()->getString("world"));
+ playerLabel = std::format("Player: {}", Config::getInstance()->getString("player"));
+}
+
+void ImGuiMainMenu::Draw(SDL_Renderer* target) {
+ // Center the menu window
+ ImGuiIO& io = ImGui::GetIO();
+ ImVec2 window_size(400, 500);
+ ImVec2 window_pos(
+ (io.DisplaySize.x - window_size.x) * 0.5f,
+ (io.DisplaySize.y - window_size.y) * 0.5f
+ );
+
+ ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
+ ImGui::SetNextWindowSize(window_size, ImGuiCond_Always);
+
+ if (!ImGui::Begin("Saland Adventures", &active,
+ ImGuiWindowFlags_NoResize |
+ ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoCollapse)) {
+ ImGui::End();
+ return;
+ }
+
+ // Center buttons horizontally
+ float button_width = 300.0f;
+ float button_height = 60.0f;
+ float window_width = ImGui::GetWindowSize().x;
+ float button_x = (window_width - button_width) * 0.5f;
+
+ // Add some top spacing
+ ImGui::SetCursorPosY(50);
+
+ // Start button
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("Start", ImVec2(button_width, button_height))) {
+ pendingAction = PendingAction::StartGame;
+ }
+
+ // World Select button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button(worldLabel.c_str(), ImVec2(button_width, button_height))) {
+ pendingAction = PendingAction::WorldSelect;
+ }
+
+ // Player Select button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button(playerLabel.c_str(), ImVec2(button_width, button_height))) {
+ pendingAction = PendingAction::PlayerSelect;
+ }
+
+ // Options button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("Options", ImVec2(button_width, button_height))) {
+ pendingAction = PendingAction::Options;
+ }
+
+ // About button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("About", ImVec2(button_width, button_height))) {
+ pendingAction = PendingAction::About;
+ }
+
+ ImGui::End();
+}
+
+void ImGuiMainMenu::ProcessInput(const SDL_Event& event, bool& processed) {
+ // Handle Escape key to close menu
+ if (event.type == SDL_KEYDOWN) {
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ active = false;
+ processed = true;
+ }
+ }
+}
+
+void ImGuiMainMenu::ExecutePendingAction() {
+ switch (pendingAction) {
+ case PendingAction::StartGame:
+ runStartGame();
+ active = false;
+ break;
+ case PendingAction::WorldSelect:
+ runWorldSelect();
+ UpdateLabels();
+ break;
+ case PendingAction::PlayerSelect:
+ runPlayerSelect();
+ UpdateLabels();
+ break;
+ case PendingAction::Options:
+ runMenuOptions();
+ break;
+ case PendingAction::About:
+ runHelpAbout();
+ break;
+ case PendingAction::None:
+ // No action to execute
+ break;
+ }
+ pendingAction = PendingAction::None;
+}
+
+void ImGuiMainMenu::Update() {
+ if (pendingAction != PendingAction::None) {
+ ExecutePendingAction();
+ }
+}
diff --git a/src/ImGuiMainMenu.hpp b/src/ImGuiMainMenu.hpp new file mode 100644 index 0000000..ca8e1e8 --- /dev/null +++ b/src/ImGuiMainMenu.hpp
@@ -0,0 +1,71 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#ifndef IMGUI_MAIN_MENU_HPP
+#define IMGUI_MAIN_MENU_HPP
+
+#include "sago/GameStateInterface.hpp"
+#include <string>
+
+struct SDL_Renderer;
+union SDL_Event;
+
+// Forward declarations for menu actions
+void runStartGame();
+void runWorldSelect();
+void runPlayerSelect();
+void runMenuOptions();
+void runHelpAbout();
+
+class ImGuiMainMenu : public sago::GameStateInterface {
+public:
+ ImGuiMainMenu();
+ virtual bool IsActive() override;
+ virtual void Draw(SDL_Renderer* target) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
+ virtual void Update() override;
+
+ ImGuiMainMenu(const ImGuiMainMenu&) = delete;
+ ImGuiMainMenu& operator=(const ImGuiMainMenu&) = delete;
+ virtual ~ImGuiMainMenu() = default;
+
+private:
+ enum class PendingAction {
+ None,
+ StartGame,
+ WorldSelect,
+ PlayerSelect,
+ Options,
+ About
+ };
+
+ void UpdateLabels();
+ void ExecutePendingAction();
+
+ bool active = true;
+ std::string worldLabel;
+ std::string playerLabel;
+ PendingAction pendingAction = PendingAction::None;
+};
+
+#endif /* IMGUI_MAIN_MENU_HPP */
diff --git a/src/ImGuiOptions.cpp b/src/ImGuiOptions.cpp new file mode 100644 index 0000000..050be1c --- /dev/null +++ b/src/ImGuiOptions.cpp
@@ -0,0 +1,95 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#include "ImGuiOptions.hpp"
+#include "Libs/imgui/imgui.h"
+#include "saland/globals.hpp"
+#include <SDL.h>
+
+ImGuiOptions::ImGuiOptions() {
+}
+
+bool ImGuiOptions::IsActive() {
+ return active;
+}
+
+void ImGuiOptions::Draw(SDL_Renderer* target) {
+ // Center the menu window
+ ImGuiIO& io = ImGui::GetIO();
+ ImVec2 window_size(400, 250);
+ ImVec2 window_pos(
+ (io.DisplaySize.x - window_size.x) * 0.5f,
+ (io.DisplaySize.y - window_size.y) * 0.5f
+ );
+
+ ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
+ ImGui::SetNextWindowSize(window_size, ImGuiCond_Always);
+
+ if (!ImGui::Begin("Options", &active,
+ ImGuiWindowFlags_NoResize |
+ ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoCollapse)) {
+ ImGui::End();
+ return;
+ }
+
+ // Center buttons horizontally
+ float button_width = 300.0f;
+ float button_height = 60.0f;
+ float window_width = ImGui::GetWindowSize().x;
+ float button_x = (window_width - button_width) * 0.5f;
+
+ // Add some top spacing
+ ImGui::SetCursorPosY(50);
+
+ // Fullscreen toggle button
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("Toggle Fullscreen", ImVec2(button_width, button_height))) {
+ pendingFullscreenToggle = true;
+ }
+
+ // Display current fullscreen status
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 20);
+ ImGui::SetCursorPosX(button_x);
+ const char* status = globalData.fullscreen ? "Currently: Fullscreen" : "Currently: Windowed";
+ ImGui::Text("%s", status);
+
+ ImGui::End();
+}
+
+void ImGuiOptions::ProcessInput(const SDL_Event& event, bool& processed) {
+ // Handle Escape key to close menu
+ if (event.type == SDL_KEYDOWN) {
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ active = false;
+ processed = true;
+ }
+ }
+}
+
+void ImGuiOptions::Update() {
+ if (pendingFullscreenToggle) {
+ toggleFullscreen();
+ pendingFullscreenToggle = false;
+ }
+}
diff --git a/src/ImGuiOptions.hpp b/src/ImGuiOptions.hpp new file mode 100644 index 0000000..3e7c17e --- /dev/null +++ b/src/ImGuiOptions.hpp
@@ -0,0 +1,52 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#ifndef IMGUI_OPTIONS_HPP
+#define IMGUI_OPTIONS_HPP
+
+#include "sago/GameStateInterface.hpp"
+
+struct SDL_Renderer;
+union SDL_Event;
+
+// Forward declaration
+void toggleFullscreen();
+
+class ImGuiOptions : public sago::GameStateInterface {
+public:
+ ImGuiOptions();
+ virtual bool IsActive() override;
+ virtual void Draw(SDL_Renderer* target) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
+ virtual void Update() override;
+
+ ImGuiOptions(const ImGuiOptions&) = delete;
+ ImGuiOptions& operator=(const ImGuiOptions&) = delete;
+ virtual ~ImGuiOptions() = default;
+
+private:
+ bool active = true;
+ bool pendingFullscreenToggle = false;
+};
+
+#endif /* IMGUI_OPTIONS_HPP */
diff --git a/src/ImGuiPlayerSelect.cpp b/src/ImGuiPlayerSelect.cpp new file mode 100644 index 0000000..8a9f31e --- /dev/null +++ b/src/ImGuiPlayerSelect.cpp
@@ -0,0 +1,102 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#include "ImGuiPlayerSelect.hpp"
+#include "Libs/imgui/imgui.h"
+#include "common.h"
+#include <SDL.h>
+
+ImGuiPlayerSelect::ImGuiPlayerSelect() {
+ currentPlayer = Config::getInstance()->getString("player");
+}
+
+bool ImGuiPlayerSelect::IsActive() {
+ return active;
+}
+
+void ImGuiPlayerSelect::Draw(SDL_Renderer* target) {
+ // Center the menu window
+ ImGuiIO& io = ImGui::GetIO();
+ ImVec2 window_size(400, 300);
+ ImVec2 window_pos(
+ (io.DisplaySize.x - window_size.x) * 0.5f,
+ (io.DisplaySize.y - window_size.y) * 0.5f
+ );
+
+ ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
+ ImGui::SetNextWindowSize(window_size, ImGuiCond_Always);
+
+ if (!ImGui::Begin("Player Select", &active,
+ ImGuiWindowFlags_NoResize |
+ ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoCollapse)) {
+ ImGui::End();
+ return;
+ }
+
+ // Center buttons horizontally
+ float button_width = 300.0f;
+ float button_height = 60.0f;
+ float window_width = ImGui::GetWindowSize().x;
+ float button_x = (window_width - button_width) * 0.5f;
+
+ // Add some top spacing
+ ImGui::SetCursorPosY(50);
+
+ // Player 1 button
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("Player 1", ImVec2(button_width, button_height))) {
+ pendingPlayer = "player1";
+ }
+
+ // Player 2 button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("Player 2", ImVec2(button_width, button_height))) {
+ pendingPlayer = "player2";
+ }
+
+ ImGui::End();
+}
+
+void ImGuiPlayerSelect::ProcessInput(const SDL_Event& event, bool& processed) {
+ // Handle Escape key to close menu
+ if (event.type == SDL_KEYDOWN) {
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ active = false;
+ processed = true;
+ }
+ }
+}
+
+void ImGuiPlayerSelect::SelectPlayer(const std::string& playerName) {
+ Config::getInstance()->setString("player", playerName);
+ active = false;
+}
+
+void ImGuiPlayerSelect::Update() {
+ if (!pendingPlayer.empty()) {
+ SelectPlayer(pendingPlayer);
+ pendingPlayer.clear();
+ }
+}
diff --git a/src/ImGuiPlayerSelect.hpp b/src/ImGuiPlayerSelect.hpp new file mode 100644 index 0000000..98a4a83 --- /dev/null +++ b/src/ImGuiPlayerSelect.hpp
@@ -0,0 +1,53 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#ifndef IMGUI_PLAYER_SELECT_HPP
+#define IMGUI_PLAYER_SELECT_HPP
+
+#include "sago/GameStateInterface.hpp"
+#include <string>
+
+struct SDL_Renderer;
+union SDL_Event;
+
+class ImGuiPlayerSelect : public sago::GameStateInterface {
+public:
+ ImGuiPlayerSelect();
+ virtual bool IsActive() override;
+ virtual void Draw(SDL_Renderer* target) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
+ virtual void Update() override;
+
+ ImGuiPlayerSelect(const ImGuiPlayerSelect&) = delete;
+ ImGuiPlayerSelect& operator=(const ImGuiPlayerSelect&) = delete;
+ virtual ~ImGuiPlayerSelect() = default;
+
+private:
+ void SelectPlayer(const std::string& playerName);
+
+ bool active = true;
+ std::string pendingPlayer;
+ std::string currentPlayer;
+};
+
+#endif /* IMGUI_PLAYER_SELECT_HPP */
diff --git a/src/ImGuiWorldSelect.cpp b/src/ImGuiWorldSelect.cpp new file mode 100644 index 0000000..1964121 --- /dev/null +++ b/src/ImGuiWorldSelect.cpp
@@ -0,0 +1,116 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#include "ImGuiWorldSelect.hpp"
+#include "Libs/imgui/imgui.h"
+#include "common.h"
+#include <SDL.h>
+
+ImGuiWorldSelect::ImGuiWorldSelect() {
+ currentWorld = Config::getInstance()->getString("world");
+}
+
+bool ImGuiWorldSelect::IsActive() {
+ return active;
+}
+
+void ImGuiWorldSelect::Draw(SDL_Renderer* target) {
+ // Center the menu window
+ ImGuiIO& io = ImGui::GetIO();
+ ImVec2 window_size(400, 400);
+ ImVec2 window_pos(
+ (io.DisplaySize.x - window_size.x) * 0.5f,
+ (io.DisplaySize.y - window_size.y) * 0.5f
+ );
+
+ ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
+ ImGui::SetNextWindowSize(window_size, ImGuiCond_Always);
+
+ if (!ImGui::Begin("World Select", &active,
+ ImGuiWindowFlags_NoResize |
+ ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoCollapse)) {
+ ImGui::End();
+ return;
+ }
+
+ // Center buttons horizontally
+ float button_width = 300.0f;
+ float button_height = 60.0f;
+ float window_width = ImGui::GetWindowSize().x;
+ float button_x = (window_width - button_width) * 0.5f;
+
+ // Add some top spacing
+ ImGui::SetCursorPosY(50);
+
+ // World 1 button
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("World 1", ImVec2(button_width, button_height))) {
+ pendingWorld = "world1";
+ }
+
+ // World 2 button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("World 2", ImVec2(button_width, button_height))) {
+ pendingWorld = "world2";
+ }
+
+ // World 3 button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("World 3", ImVec2(button_width, button_height))) {
+ pendingWorld = "world3";
+ }
+
+ // World 4 button
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
+ ImGui::SetCursorPosX(button_x);
+ if (ImGui::Button("World 4", ImVec2(button_width, button_height))) {
+ pendingWorld = "world4";
+ }
+
+ ImGui::End();
+}
+
+void ImGuiWorldSelect::ProcessInput(const SDL_Event& event, bool& processed) {
+ // Handle Escape key to close menu
+ if (event.type == SDL_KEYDOWN) {
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ active = false;
+ processed = true;
+ }
+ }
+}
+
+void ImGuiWorldSelect::SelectWorld(const std::string& worldName) {
+ Config::getInstance()->setString("world", worldName);
+ active = false;
+}
+
+void ImGuiWorldSelect::Update() {
+ if (!pendingWorld.empty()) {
+ SelectWorld(pendingWorld);
+ pendingWorld.clear();
+ }
+}
diff --git a/src/ImGuiWorldSelect.hpp b/src/ImGuiWorldSelect.hpp new file mode 100644 index 0000000..a38b96c --- /dev/null +++ b/src/ImGuiWorldSelect.hpp
@@ -0,0 +1,53 @@
+/*
+===========================================================================
+ * Saland Adventures
+Copyright (C) 2014-2024 Poul Sander
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+https://github.com/sago007/saland
+===========================================================================
+ */
+
+#ifndef IMGUI_WORLD_SELECT_HPP
+#define IMGUI_WORLD_SELECT_HPP
+
+#include "sago/GameStateInterface.hpp"
+#include <string>
+
+struct SDL_Renderer;
+union SDL_Event;
+
+class ImGuiWorldSelect : public sago::GameStateInterface {
+public:
+ ImGuiWorldSelect();
+ virtual bool IsActive() override;
+ virtual void Draw(SDL_Renderer* target) override;
+ virtual void ProcessInput(const SDL_Event& event, bool& processed) override;
+ virtual void Update() override;
+
+ ImGuiWorldSelect(const ImGuiWorldSelect&) = delete;
+ ImGuiWorldSelect& operator=(const ImGuiWorldSelect&) = delete;
+ virtual ~ImGuiWorldSelect() = default;
+
+private:
+ void SelectWorld(const std::string& worldName);
+
+ bool active = true;
+ std::string pendingWorld;
+ std::string currentWorld;
+};
+
+#endif /* IMGUI_WORLD_SELECT_HPP */
diff --git a/src/saland.cpp b/src/saland.cpp index 6759c33..c6f4b75 100644 --- a/src/saland.cpp +++ b/src/saland.cpp
@@ -50,6 +50,10 @@ https://github.com/salandgame/saland
#include "MenuSystem.h"
#include "help/HelpAboutState.hpp"
+#include "ImGuiMainMenu.hpp"
+#include "ImGuiWorldSelect.hpp"
+#include "ImGuiPlayerSelect.hpp"
+#include "ImGuiOptions.hpp"
#include "common.h"
#include "os.hpp"
@@ -312,36 +316,12 @@ public:
};
void runWorldSelect() {
- Menu m(globalData.screen, true);
- ButtonConfigValue bWorld1;
- bWorld1.setLabel("World 1");
- bWorld1.setConfigValues("world", "world1");
- m.addButton(&bWorld1);
- ButtonConfigValue bWorld2;
- bWorld2.setLabel("World 2");
- bWorld1.setConfigValues("world", "world2");
- m.addButton(&bWorld2);
- ButtonConfigValue bWorld3;
- bWorld3.setLabel("World 3");
- bWorld1.setConfigValues("world", "world3");
- m.addButton(&bWorld3);
- ButtonConfigValue bWorld4;
- bWorld4.setLabel("World 4");
- bWorld1.setConfigValues("world", "world4");
- m.addButton(&bWorld4);
+ ImGuiWorldSelect m;
RunGameState(m);
}
void runPlayerSelect() {
- Menu m(globalData.screen, true);
- ButtonConfigValue bPlayer1;
- bPlayer1.setLabel("Player 1");
- bPlayer1.setConfigValues("player", "player1");
- m.addButton(&bPlayer1);
- ButtonConfigValue bPlayer2;
- bPlayer2.setLabel("Player 2");
- bPlayer2.setConfigValues("player", "player2");
- m.addButton(&bPlayer2);
+ ImGuiPlayerSelect m;
RunGameState(m);
}
@@ -367,15 +347,11 @@ void toggleFullscreen() {
}
void runMenuOptions() {
- Menu m(globalData.screen, true);
- Button bFullscreen;
- bFullscreen.setLabel("Fullscreen");
- bFullscreen.setAction(toggleFullscreen);
- m.addButton(&bFullscreen);
+ ImGuiOptions m;
RunGameState(m);
}
-static void runHelpAbout() {
+void runHelpAbout() {
HelpAboutState helpAbout;
RunGameState(helpAbout);
}
@@ -463,23 +439,7 @@ void runGame() {
RunGameState(ts);
standardButton.setSurfaces();
- Menu m(globalData.screen, false);
- Button bStart;
- bStart.setLabel("Start");
- bStart.setAction(runStartGame);
- m.addButton(&bStart);
- WorldSelectButton bWorldSelect;
- m.addButton(&bWorldSelect);
- PlayerSelectButton bPlayerSelect;
- m.addButton(&bPlayerSelect);
- Button bOptions;
- bOptions.setLabel("Options");
- bOptions.setAction(runMenuOptions);
- m.addButton(&bOptions);
- Button bAbout;
- bAbout.setLabel(_("About"));
- bAbout.setAction(runHelpAbout);
- m.addButton(&bAbout);
+ ImGuiMainMenu m;
if (!globalData.isShuttingDown) {
RunGameState(m);
}