diff --git a/Assets/Scripts/Gui/console.lua b/Assets/Scripts/Gui/console.lua new file mode 100644 index 0000000..ce82d7a --- /dev/null +++ b/Assets/Scripts/Gui/console.lua @@ -0,0 +1,28 @@ +numGui = 3 +gui = { + { + pos = {x = 100, y = 100}, + size = {x = 300, y = 20}, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.CONSOLE, + numMaxDisplay = 20, + closable = false + }, + { + pos = {x = 100, y = 510}, + size = {x = 270, y = 20}, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 380, y = 510}, + size = {x = 20, y = 20}, + guiType = GuiType.BUTTON, + buttonType = ButtonType.CONSOLE_COMMAND_OK, + name = 'OK', + numDependencies = 2, + dependencies = { + {id = 0}, + {id = 1} + } + } +} diff --git a/Assets/Scripts/Gui/gamePaused.lua b/Assets/Scripts/Gui/gamePaused.lua new file mode 100644 index 0000000..2fdfbe8 --- /dev/null +++ b/Assets/Scripts/Gui/gamePaused.lua @@ -0,0 +1,39 @@ +Size = {x = 150, y = 50} +numGui = 5 +gui = { + { + pos = {x = 100, y = 100}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESUME, + name = 'Resume' + }, + { + pos = {x = 100, y = 100 + 1 * (Size.y + 10)}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.CONSOLE, + name = 'Console' + }, + { + pos = {x = 100, y = 100 + 2 * (Size.y + 10)}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.OPTIONS, + name = 'Options' + }, + { + pos = {x = 100, y = 100 + 3 * (Size.y + 10)}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.MAIN_MENU, + name = 'Main menu' + }, + { + pos = {x = 100, y = 100 + 4 * (Size.y + 10)}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.EXIT, + name = 'Exit' + } +} diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 0fd106e..29964e7 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -18,7 +18,11 @@ ButtonType = { LOAD_MAP = 14, LOAD_MAP_OK = 15, EXPORT = 16, - PLAY = 17 + PLAY = 17, + RESUME = 18, + CONSOLE = 19, + MAIN_MENU = 20, + CONSOLE_COMMAND_OK = 21 } ListboxType = { @@ -29,5 +33,6 @@ ListboxType = { SKYBOX_TEXTURES = 4, LAND_TEXTURES = 5, CPU_DIFFICULTIES = 6, - FACTIONS = 7 + FACTIONS = 7, + CONSOLE = 8 } diff --git a/CMakeLists.txt b/CMakeLists.txt index 153f2ff..6651895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,10 @@ set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) -set(BUTTONS singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp exportButton.cpp playButton.cpp) +set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp) +set(IN_GAME_APP_STATE_BUTTONS mainMenuButton.cpp) +set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp) +set(BUTTONS singlePlayerButton.cpp exitButton.cpp backButton.cpp consoleCommand.cpp playButton.cpp ${OPTIONS_BUTTONS} ${IN_GAME_APP_STATE_BUTTONS} ${MAP_EDITOR_BUTTONS}) set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp unitListbox.cpp) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index c0b0305..c148b79 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -17,6 +17,8 @@ #include "landTextureListbox.h" #include "unitListbox.h" #include "playButton.h" +#include "inGameAppState.h" +#include "mainMenuButton.h" namespace battleship{ using namespace std; @@ -135,6 +137,25 @@ namespace battleship{ button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true); break; } + case RESUME: + button = new InGameAppState::ResumeButton(pos, size); + break; + case CONSOLE_SCREEN: + button = new InGameAppState::ConsoleButton(pos, size); + break; + case MAIN_MENU: + button = new MainMenuButton(pos, size, name); + break; + case CONSOLE_COMMAND_OK:{ + int lid = lm->getIntFromTable(guiTable, vector{Index(guiId + 1), Index("dependencies"), Index(1), Index("id")}); + Listbox *listbox = (Listbox*)guiElements[lid].second; + + int tid = lm->getIntFromTable(guiTable, vector{Index(guiId + 1), Index("dependencies"), Index(2), Index("id")}); + Textbox *textbox = (Textbox*)guiElements[tid].second; + + button = new InGameAppState::ConsoleButton::ConsoleCommandEntryButton(textbox, listbox, pos, size, name); + break; + } } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; @@ -252,6 +273,15 @@ namespace battleship{ listbox = new Listbox(pos, size, lines, maxDisplay, fontPath); break; + case CONSOLE:{ + for(int i = 0; i < numMaxDisplay; i++) + lines.push_back(""); + + closable = false; + + listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + } + break; } int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index c4e8177..23886a6 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -27,7 +27,11 @@ namespace battleship{ LOAD_MAP, LOAD_MAP_OK, EXPORT, - PLAY + PLAY, + RESUME, + CONSOLE_SCREEN, + MAIN_MENU, + CONSOLE_COMMAND_OK }; enum ListboxType { CONTROLS, @@ -37,7 +41,8 @@ namespace battleship{ SKYBOX_TEXTURES, LAND_TEXTURES, CPU_DIFFICULTIES, - FACTIONS + FACTIONS, + CONSOLE }; class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{ diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 9b7af2a..c54ca10 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -14,6 +14,7 @@ #include "inGameAppState.h" #include "consoleCommand.h" #include "unitFrameController.h" +#include "concreteGuiManager.h" #include "vessel.h" using namespace vb01; @@ -23,25 +24,17 @@ using namespace std; namespace battleship{ using namespace configData; - InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->guiState = guiState; - this->inGameState = inGameState; - } + InGameAppState::ResumeButton::ResumeButton(Vector2 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void InGameAppState::ResumeButton::onClick() { - inGameState->toggleMainMenu(); + StateManager *sm = GameManager::getSingleton()->getStateManager(); + ((InGameAppState*)sm->getAppStateByType((int)AppStateType::IN_GAME_STATE))->toggleMainMenu(); } - GuiAppState* InGameAppState::ResumeButton::getGuiState() { - return guiState; - } - - InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { - this->guiState = guiState; - this->inGameState = inGameState; - } + InGameAppState::ConsoleButton::ConsoleButton(Vector2 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { } void InGameAppState::ConsoleButton::onClick() { + ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua"); /* vector list; int emptyEntries = 20; @@ -80,8 +73,7 @@ namespace battleship{ */ } - InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) { - this->inGameState = inGameState; + InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { textbox = t; listbox = l; } @@ -218,46 +210,26 @@ namespace battleship{ void InGameAppState::toggleMainMenu() { GameManager *gm = GameManager::getSingleton(); - /* + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + if (!isMainMenuActive) { isMainMenuActive = true; gm->getStateManager()->dettachAppState(activeState); - Vector2 pos = Vector2(100, 100); - resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50)); - consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50)); - optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50)); - mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50)); - exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50)); - guiState->addButton(resumeButton); - guiState->addButton(consoleButton); - guiState->addButton(optionsButton); - guiState->addButton(mainMenuButton); - guiState->addButton(exitButton); + guiManager->readLuaScreenScript("gamePaused.lua"); } else { isMainMenuActive = false; gm->getStateManager()->attachAppState(activeState); - guiState->removeAllCheckboxes(); - guiState->removeAllListboxes(); - guiState->removeAllSliders(); - guiState->removeAllTextboxes(); - guiState->removeButton(consoleButton->getEntryButton()); - guiState->removeButton(consoleButton); - guiState->removeButton(mainMenuButton); - guiState->removeButton(optionsButton); - guiState->removeButton(exitButton); - guiState->removeButton(resumeButton); - AssetManager::getSingleton()->load(gm->getPath() + LuaManager::getSingleton()->getString("modelPrefix"), true); + guiManager->readLuaScreenScript("inGame.lua"); + for(Player *p : Map::getSingleton()->getPlayers()) for(Unit *u : p->getUnits()) u->reinitUnit(); } - */ - } void InGameAppState::onAction(int bind, bool isPressed) { diff --git a/inGameAppState.h b/inGameAppState.h index 0c22b6c..65a2e8a 100755 --- a/inGameAppState.h +++ b/inGameAppState.h @@ -20,6 +20,29 @@ namespace battleship{ class InGameAppState : public gameBase::AbstractAppState { public: + class ResumeButton : public vb01Gui::Button { + public: + ResumeButton(vb01::Vector2, vb01::Vector2); + void onClick(); + private: + }; + + class ConsoleButton : public vb01Gui::Button { + public: + class ConsoleCommandEntryButton : public Button { + public: + ConsoleCommandEntryButton(vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector2, vb01::Vector2, std::string); + void onClick(); + private: + vb01Gui::Textbox *textbox; + vb01Gui::Listbox *listbox; + }; + + ConsoleButton(vb01::Vector2, vb01::Vector2); + void onClick(); + private: + }; + InGameAppState(std::vector, std::vector, std::string); ~InGameAppState(); void onAttached(); @@ -32,37 +55,6 @@ namespace battleship{ inline void addFx(Fx fx){this->fx.push_back(fx);} inline void addProjectile(Projectile *p){projectiles.push_back(p);} private: - class ResumeButton : public vb01Gui::Button { - public: - ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2); - void onClick(); - GuiAppState *getGuiState(); - private: - GuiAppState *guiState; - InGameAppState *inGameState; - }; - - class ConsoleButton : public vb01Gui::Button { - public: - class ConsoleCommandEntryButton : public Button { - public: - ConsoleCommandEntryButton(InGameAppState*, vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector2, vb01::Vector2, std::string, bool); - void onClick(); - private: - InGameAppState *inGameState; - vb01Gui::Textbox *textbox; - vb01Gui::Listbox *listbox; - }; - - ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2); - void onClick(); - inline ConsoleCommandEntryButton* getEntryButton(){return entryButton;} - private: - GuiAppState *guiState; - InGameAppState *inGameState; - ConsoleCommandEntryButton *entryButton = nullptr; - }; - class MainMenuButton : public vb01Gui::Button { public: MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2); diff --git a/mainMenuButton.cpp b/mainMenuButton.cpp new file mode 100644 index 0000000..1888907 --- /dev/null +++ b/mainMenuButton.cpp @@ -0,0 +1,14 @@ +#include "mainMenuButton.h" +#include "gameManager.h" +#include "concreteGuiManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + MainMenuButton::MainMenuButton(Vector2 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} + + void MainMenuButton::onClick(){ + } +} diff --git a/mainMenuButton.h b/mainMenuButton.h new file mode 100644 index 0000000..17f8d66 --- /dev/null +++ b/mainMenuButton.h @@ -0,0 +1,15 @@ +#ifndef MAIN_MENU_BUTTON_H +#define MAIN_MENU_BUTTON_H + +#include + +namespace battleship{ + class MainMenuButton : public vb01Gui::Button{ + public: + MainMenuButton(vb01::Vector2, vb01::Vector2, std::string); + void onClick(); + private: + }; +} + +#endif