From adaa472fd71378757faae4ec1a74e7ddc987b8b1 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Jun 2023 15:44:35 +0300 Subject: [PATCH] factored out options screen GUI elements using the new GUI subsystem --- Assets/Scripts/Gui/audioTab.lua | 36 ++++++++++ Assets/Scripts/Gui/controlsTab.lua | 33 +++++++++ Assets/Scripts/Gui/main.lua | 10 ++- Assets/Scripts/Gui/mainMenu.lua | 2 - Assets/Scripts/Gui/mouseTab.lua | 41 ++++++++++++ Assets/Scripts/Gui/multiplayerTab.lua | 40 +++++++++++ Assets/Scripts/Gui/options.lua | 48 ++++++++++++++ Assets/Scripts/Gui/videoTab.lua | 51 ++++++++++++++ CMakeLists.txt | 2 +- backButton.cpp | 26 ++++++++ backButton.h | 16 +++++ concreteGuiManager.cpp | 96 +++++++++++++++++++++++++-- concreteGuiManager.h | 15 ++++- defaultsButton.cpp | 12 ++++ defaultsButton.h | 15 +++++ okButton.cpp | 12 ++++ okButton.h | 15 +++++ optionsButton.cpp | 71 ++++---------------- optionsButton.h | 55 --------------- tabButton.cpp | 26 ++++++++ tabButton.h | 16 +++++ 21 files changed, 514 insertions(+), 124 deletions(-) create mode 100644 Assets/Scripts/Gui/audioTab.lua create mode 100644 Assets/Scripts/Gui/controlsTab.lua create mode 100644 Assets/Scripts/Gui/mouseTab.lua create mode 100644 Assets/Scripts/Gui/multiplayerTab.lua create mode 100644 Assets/Scripts/Gui/options.lua create mode 100644 Assets/Scripts/Gui/videoTab.lua create mode 100644 backButton.cpp create mode 100644 backButton.h create mode 100644 defaultsButton.cpp create mode 100644 defaultsButton.h create mode 100644 okButton.cpp create mode 100644 okButton.h create mode 100644 tabButton.cpp create mode 100644 tabButton.h diff --git a/Assets/Scripts/Gui/audioTab.lua b/Assets/Scripts/Gui/audioTab.lua new file mode 100644 index 0000000..188ecc9 --- /dev/null +++ b/Assets/Scripts/Gui/audioTab.lua @@ -0,0 +1,36 @@ +numGui = 5 +gui = { + { + pos = {x = 110, y = 40}, + size = {x = 100, y = 10}, + guiType = GuiType.SLIDER, + }, + { + pos = {x = 110, y = 90}, + size = {x = 100, y = 10}, + guiType = GuiType.TEXTBOX, + }, + { + pos = {x = 100, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.OK + }, + { + pos = {x = 260, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Restore defaults', + buttonType = ButtonType.DEFAULTS + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'options.lua', + buttonType = ButtonType.BACK + } + +} diff --git a/Assets/Scripts/Gui/controlsTab.lua b/Assets/Scripts/Gui/controlsTab.lua new file mode 100644 index 0000000..d0648c2 --- /dev/null +++ b/Assets/Scripts/Gui/controlsTab.lua @@ -0,0 +1,33 @@ +numGui = 4 +gui = { + { + pos = {x = 110, y = 190}, + size = {x = 360, y = 20}, + guiType = GuiType.LISTBOX, + font = 'batang.ttf', + closable = false, + numMaxDisplay = 5 + }, + { + pos = {x = 100, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.OK + }, + { + pos = {x = 260, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Restore defaults', + buttonType = ButtonType.DEFAULTS + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'options.lua', + buttonType = ButtonType.BACK + } +} diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 0d2ea78..2b2838f 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -4,5 +4,13 @@ ButtonType = { SINGLE_PLAYER = 0, MAP_EDITOR = 1, OPTIONS = 2, - EXIT = 3 + EXIT = 3, + OK = 4, + DEFAULTS = 5, + BACK = 6, + CONTROLS_TAB = 7, + MOUSE_TAB = 8, + VIDEO_TAB = 9, + AUDIO_TAB = 10, + MULTIPLAYER_TAB = 11 } diff --git a/Assets/Scripts/Gui/mainMenu.lua b/Assets/Scripts/Gui/mainMenu.lua index e9d601a..6195049 100644 --- a/Assets/Scripts/Gui/mainMenu.lua +++ b/Assets/Scripts/Gui/mainMenu.lua @@ -1,5 +1,3 @@ -dofile("main.lua") - Size = {x = 150, y = 40} numGui = 4 diff --git a/Assets/Scripts/Gui/mouseTab.lua b/Assets/Scripts/Gui/mouseTab.lua new file mode 100644 index 0000000..3efeb1b --- /dev/null +++ b/Assets/Scripts/Gui/mouseTab.lua @@ -0,0 +1,41 @@ +numGui = 6 +gui = { + { + pos = {x = 110, y = 40}, + size = {x = 300, y = 10}, + minVal = 0, + maxVal = 2, + guiType = GuiType.SLIDER + }, + { + pos = {x = 110, y = 80}, + size = {x = 300, y = 10}, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 110, y = 110}, + guiType = GuiType.CHECKBOX + }, + { + pos = {x = 100, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.OK + }, + { + pos = {x = 260, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Restore defaults', + buttonType = ButtonType.DEFAULTS + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'options.lua', + buttonType = ButtonType.BACK + } +} diff --git a/Assets/Scripts/Gui/multiplayerTab.lua b/Assets/Scripts/Gui/multiplayerTab.lua new file mode 100644 index 0000000..bec5ea2 --- /dev/null +++ b/Assets/Scripts/Gui/multiplayerTab.lua @@ -0,0 +1,40 @@ +numGui = 6 +gui = { + { + pos = {x = 110, y = 40}, + size = {x = 100, y = 20}, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 110, y = 70}, + size = {x = 100, y = 20}, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 110, y = 100}, + size = {x = 100, y = 20}, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 100, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.OK + }, + { + pos = {x = 260, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Restore defaults', + buttonType = ButtonType.DEFAULTS + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'options.lua', + buttonType = ButtonType.BACK + } +} diff --git a/Assets/Scripts/Gui/options.lua b/Assets/Scripts/Gui/options.lua new file mode 100644 index 0000000..551a0e1 --- /dev/null +++ b/Assets/Scripts/Gui/options.lua @@ -0,0 +1,48 @@ +Size = {x = 150, y = 40} + +numGui = 6 +gui = { + { + pos = {x = 110, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Controls', + buttonType = ButtonType.CONTROLS_TAB + }, + { + pos = {x = 230, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Mouse', + buttonType = ButtonType.MOUSE_TAB + }, + { + pos = {x = 350, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Video', + buttonType = ButtonType.VIDEO_TAB + }, + { + pos = {x = 480, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Audio', + buttonType = ButtonType.AUDIO_TAB + }, + { + pos = {x = 590, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Multiplayer', + buttonType = ButtonType.MULTIPLAYER_TAB + }, + { + pos = {x = 110, y = 100}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'mainMenu.lua', + buttonType = ButtonType.BACK + } +} diff --git a/Assets/Scripts/Gui/videoTab.lua b/Assets/Scripts/Gui/videoTab.lua new file mode 100644 index 0000000..a1d21b4 --- /dev/null +++ b/Assets/Scripts/Gui/videoTab.lua @@ -0,0 +1,51 @@ +numGui = 9 +gui = { + { + pos = {x = 210, y = 190}, + size = {x = 360, y = 20}, + guiType = GuiType.LISTBOX, + numMaxDisplay = 5 + }, + { + pos = {x = 110, y = 40}, + buttonType = ButtonType.CHECKBOX + }, + { + pos = {x = 110, y = 70}, + buttonType = ButtonType.CHECKBOX + }, + { + pos = {x = 110, y = 100}, + buttonType = ButtonType.CHECKBOX + }, + { + pos = {x = 110, y = 130}, + buttonType = ButtonType.CHECKBOX + }, + { + pos = {x = 110, y = 160}, + buttonType = ButtonType.CHECKBOX + }, + { + pos = {x = 100, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.OK + }, + { + pos = {x = 260, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Restore defaults', + buttonType = ButtonType.DEFAULTS + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 20}, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'options.lua', + buttonType = ButtonType.BACK + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d6e628..db7e929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_policy(SET CMP0015 NEW) set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) set(UTIL util.cpp binds.h) -set(GUI tooltip.cpp concreteGuiManager.cpp singlePlayerButton.cpp mapEditorButton.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp) +set(GUI tooltip.cpp concreteGuiManager.cpp singlePlayerButton.cpp mapEditorButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp) set(CONTROLLERS unitFrameController.cpp cameraController.cpp) set(CORE gameManager.cpp defConfigs.cpp ${CONTROLLERS}) set(PROJECTILES projectile.cpp) diff --git a/backButton.cpp b/backButton.cpp new file mode 100644 index 0000000..a0d7d55 --- /dev/null +++ b/backButton.cpp @@ -0,0 +1,26 @@ +#include "backButton.h" +#include "gameManager.h" +#include "concreteGuiManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + BackButton::BackButton(Vector2 pos, Vector2 size, string name, string screen) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { + this->screen = screen; + } + + void BackButton::onClick() { + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(vector{this}); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + + guiManager->readLuaScreenScript(screen); + + guiManager->removeButton(this); + } +} diff --git a/backButton.h b/backButton.h new file mode 100644 index 0000000..b0f7fc3 --- /dev/null +++ b/backButton.h @@ -0,0 +1,16 @@ +#ifndef BACK_BUTTON_H +#define BACK_BUTTON_H + +#include + +namespace battleship{ + class BackButton : public vb01Gui::Button{ + public: + BackButton(vb01::Vector2, vb01::Vector2, std::string, std::string); + void onClick(); + private: + std::string screen; + }; +} + +#endif diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index d199e5d..5c98dbd 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -6,6 +6,10 @@ #include "mapEditorButton.h" #include "optionsButton.h" #include "exitButton.h" +#include "tabButton.h" +#include "okButton.h" +#include "defaultsButton.h" +#include "backButton.h" namespace battleship{ using namespace std; @@ -52,35 +56,115 @@ namespace battleship{ case EXIT: button = new ExitButton(pos, size); break; + case OK: + button = new OkButton(pos, size, name); + break; + case DEFAULTS: + button = new DefaultsButton(pos, size, name); + break; + case BACK: { + string screen = lm->getStringFromTable(guiTable, vector{Index(guiId + 1), Index("screen")}); + button = new BackButton(pos, size, name, screen); + break; + } + case CONTROLS_TAB: + case MOUSE_TAB: + case VIDEO_TAB: + case AUDIO_TAB: + case MULTIPLAYER_TAB: { + string screens[]{ + "controlsTab.lua", + "mouseTab.lua", + "videoTab.lua", + "audioTab.lua", + "multiplayerTab.lua" + }; + int diff = ((int)type - (int)CONTROLS_TAB); + button = new TabButton(pos, size, name, screens[diff]); + break; + } } return button; } Listbox* createListbox(int guiId){ - Listbox *listbox = nullptr; + LuaManager *lm = LuaManager::getSingleton(); + + string guiTable = "gui", posTable = "pos", sizeTable = "size"; + float posX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("x")}); + float posY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("y")}); + Vector2 pos = Vector2(posX, posY); + + float sizeX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("x")}); + float sizeY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("y")}); + Vector2 size = Vector2(sizeX, sizeY); + + int numMaxDisplay = lm->getIntFromTable(guiTable, vector{Index(guiId + 1), Index("numMaxDisplay")}); + string fontFile = lm->getStringFromTable(guiTable, vector{Index(guiId + 1), Index("font")}); + bool closable = lm->getBoolFromTable(guiTable, vector{Index(guiId + 1), Index("closable")}); + + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/" + fontFile; + Listbox *listbox = new Listbox(pos, size, vector{"a", "b"}, 2, fontPath, closable); return listbox; } Checkbox* createCheckbox(int guiId){ - Checkbox *checkbox = nullptr; + LuaManager *lm = LuaManager::getSingleton(); + + string guiTable = "gui", posTable = "pos", sizeTable = "size"; + float posX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("x")}); + float posY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("y")}); + Vector2 pos = Vector2(posX, posY); + + string fontFile = "batang.ttf"; + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/" + fontFile; + Checkbox *checkbox = new Checkbox(pos, fontPath); return checkbox; } Slider* createSlider(int guiId){ - Slider *slider = nullptr; + LuaManager *lm = LuaManager::getSingleton(); + + string guiTable = "gui", posTable = "pos", sizeTable = "size"; + float posX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("x")}); + float posY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("y")}); + Vector2 pos = Vector2(posX, posY); + + float sizeX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("x")}); + float sizeY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("y")}); + Vector2 size = Vector2(sizeX, sizeY); + + float minVal = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index("minValue")}); + float maxVal = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index("maxValue")}); + + Slider *slider = new Slider(pos, size, minVal, maxVal); return slider; } Textbox* createTextbox(int guiId){ - Textbox *textbox = nullptr; + LuaManager *lm = LuaManager::getSingleton(); + + string guiTable = "gui", posTable = "pos", sizeTable = "size"; + float posX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("x")}); + float posY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(posTable), Index("y")}); + Vector2 pos = Vector2(posX, posY); + + float sizeX = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("x")}); + float sizeY = lm->getFloatFromTable(guiTable, vector{Index(guiId + 1), Index(sizeTable), Index("y")}); + Vector2 size = Vector2(sizeX, sizeY); + + string fontFile = "batang.ttf"; + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/" + fontFile; + Textbox *textbox = new Textbox(pos, size, fontPath); + return textbox; } void ConcreteGuiManager::readLuaScreenScript(string script){ LuaManager *lm = LuaManager::getSingleton(); - string path = GameManager::getSingleton()->getPath() + "Scripts/Gui/" + script; - lm->buildScript(vector{path}); + string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/"; + lm->buildScript(vector{basePath + "main.lua", basePath + script}); int numGuiElements = lm->getInt("numGui"); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 30da50b..993eb73 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -7,7 +7,20 @@ namespace battleship{ enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX}; - enum ButtonType {SINGLE_PLAYER, EDITOR, OPTIONS, EXIT}; + enum ButtonType { + SINGLE_PLAYER, + EDITOR, + OPTIONS, + EXIT, + OK, + DEFAULTS, + BACK, + CONTROLS_TAB, + MOUSE_TAB, + VIDEO_TAB, + AUDIO_TAB, + MULTIPLAYER_TAB + }; class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{ public: diff --git a/defaultsButton.cpp b/defaultsButton.cpp new file mode 100644 index 0000000..78d4cdc --- /dev/null +++ b/defaultsButton.cpp @@ -0,0 +1,12 @@ +#include "defaultsButton.h" +#include "gameManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + DefaultsButton::DefaultsButton(Vector2 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + + void DefaultsButton::onClick() {} +} diff --git a/defaultsButton.h b/defaultsButton.h new file mode 100644 index 0000000..ede19dd --- /dev/null +++ b/defaultsButton.h @@ -0,0 +1,15 @@ +#ifndef DEFAULTS_BUTTON_H +#define DEFAULTS_BUTTON_H + +#include + +namespace battleship{ + class DefaultsButton : public vb01Gui::Button{ + public: + DefaultsButton(vb01::Vector2, vb01::Vector2, std::string); + void onClick(); + private: + }; +} + +#endif diff --git a/okButton.cpp b/okButton.cpp new file mode 100644 index 0000000..16b382b --- /dev/null +++ b/okButton.cpp @@ -0,0 +1,12 @@ +#include "okButton.h" +#include "gameManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + OkButton::OkButton(Vector2 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + + void OkButton::onClick() {} +} diff --git a/okButton.h b/okButton.h new file mode 100644 index 0000000..07a0007 --- /dev/null +++ b/okButton.h @@ -0,0 +1,15 @@ +#ifndef OK_BUTTON_H +#define OK_BUTTON_H + +#include + +namespace battleship{ + class OkButton : public vb01Gui::Button{ + public: + OkButton(vb01::Vector2, vb01::Vector2, std::string); + void onClick(); + private: + }; +} + +#endif diff --git a/optionsButton.cpp b/optionsButton.cpp index 1243c5e..ae1154d 100755 --- a/optionsButton.cpp +++ b/optionsButton.cpp @@ -2,6 +2,7 @@ #include "util.h" #include "defConfigs.h" #include "gameManager.h" +#include "concreteGuiManager.h" #include @@ -12,49 +13,7 @@ using namespace std; namespace battleship{ using namespace configData; - OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); - } - void OptionsButton::OkButton::onClick() { - - } - - OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); - } - void OptionsButton::DefaultsButton::onClick() { - - } - - OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); - } - void OptionsButton::BackButton::onClick() { - GameManager *gm = GameManager::getSingleton(); - state->removeAllListboxes(); - state->removeAllCheckboxes(); - state->removeAllSliders(); - state->removeAllTextboxes(); - state->removeButton("Ok"); - state->removeButton("Restore defaults"); - OptionsButton *optionsButton = new OptionsButton(Vector2(), Vector2(), "Options", true); - optionsButton->onClick(); - state->removeButton("Back"); - } - - OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE)); - } - void OptionsButton::TabButton::onClick() { - state->removeButton("Back"); - OkButton *okButton = new OkButton(); - DefaultsButton *defaultsButton = new DefaultsButton(); - BackButton *returnButton = new BackButton(); - state->addButton(okButton); - state->addButton(defaultsButton); - state->addButton(returnButton); - } - + /* OptionsButton::ControlsTab::ControlsTab() : TabButton( Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10), Vector2(100, 50), @@ -179,20 +138,16 @@ namespace battleship{ state->removeButton("Multiplayer"); } - OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { - this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::GUI_STATE)); - } + */ + OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} + void OptionsButton::onClick() { - ControlsTab *controlsTab = new ControlsTab(); - MouseTab *mouseTab = new MouseTab(); - VideoTab *videoTab = new VideoTab(); - AudioTab *audioTab = new AudioTab(); - MultiplayerTab *mupltiplayerTab = new MultiplayerTab(); - state->addButton(controlsTab); - state->addButton(mouseTab); - state->addButton(videoTab); - state->addButton(audioTab); - state->addButton(mupltiplayerTab); - state->removeButton(this); - } + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + guiManager->readLuaScreenScript("options.lua"); + } } diff --git a/optionsButton.h b/optionsButton.h index 91bfa60..d389c86 100755 --- a/optionsButton.h +++ b/optionsButton.h @@ -11,62 +11,7 @@ namespace battleship { class OptionsButton : public vb01Gui::Button { public: OptionsButton(vb01::Vector2, vb01::Vector2, std::string, bool); - class OkButton : public Button { - public: - OkButton(); - void onClick(); - private: - GuiAppState *state; - }; - class DefaultsButton : public Button { - public: - DefaultsButton(); - void onClick(); - private: - GuiAppState *state; - }; - class BackButton : public Button { - public: - BackButton(); - void onClick(); - private: - GuiAppState *state; - }; - class TabButton : public Button { - public: - TabButton(vb01::Vector2, vb01::Vector2, std::string); - void onClick(); - protected: - GuiAppState *state; - }; - class ControlsTab : public TabButton { - public: - ControlsTab(); - void onClick(); - }; - class MouseTab : public TabButton { - public: - MouseTab(); - void onClick(); - private: - }; - class VideoTab : public TabButton { - public: - VideoTab(); - void onClick(); - }; - class AudioTab : public TabButton { - public: - AudioTab(); - void onClick(); - }; - class MultiplayerTab : public TabButton { - public: - MultiplayerTab(); - void onClick(); - }; virtual void onClick(); - GuiAppState *state; }; } diff --git a/tabButton.cpp b/tabButton.cpp new file mode 100644 index 0000000..98adba8 --- /dev/null +++ b/tabButton.cpp @@ -0,0 +1,26 @@ +#include "tabButton.h" +#include "concreteGuiManager.h" +#include "gameManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + TabButton::TabButton(Vector2 pos, Vector2 size, string name, string screenScript) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { + this->screenScript = screenScript; + } + + void TabButton::onClick() { + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(vector{this}); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + + guiManager->readLuaScreenScript(screenScript); + + guiManager->removeButton(this); + } +} diff --git a/tabButton.h b/tabButton.h new file mode 100644 index 0000000..5c084af --- /dev/null +++ b/tabButton.h @@ -0,0 +1,16 @@ +#ifndef TAB_BUTTON_H +#define TAB_BUTTON_H + +#include + +namespace battleship{ + class TabButton : public vb01Gui::Button{ + public: + TabButton(vb01::Vector2, vb01::Vector2, std::string, std::string); + void onClick(); + private: + std::string screenScript; + }; +} + +#endif