diff --git a/Assets/Scripts/Gui/loadMap.lua b/Assets/Scripts/Gui/loadMap.lua new file mode 100644 index 0000000..f0b149c --- /dev/null +++ b/Assets/Scripts/Gui/loadMap.lua @@ -0,0 +1,17 @@ +numGui = 2 +gui = { + { + pos = {x = 110, y = 190}, + size = {x = 360, y = 20}, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.MAPS, + numMaxDisplay = 5 + }, + { + pos = {x = 110, y = 250}, + size = {x = 140, y = 40}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.LOAD_MAP_OK + } +} diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 0d8d539..178babf 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -12,10 +12,15 @@ ButtonType = { MOUSE_TAB = 8, VIDEO_TAB = 9, AUDIO_TAB = 10, - MULTIPLAYER_TAB = 11 + MULTIPLAYER_TAB = 11, + NEW_MAP = 12, + NEW_MAP_OK = 13, + LOAD_MAP = 14, + LOAD_MAP_OK = 15 } ListboxType = { CONTROLS = 0, - RESOLUTION = 1 + RESOLUTION = 1, + MAPS = 2 } diff --git a/Assets/Scripts/Gui/mapEditor/loadMap/ok.lua b/Assets/Scripts/Gui/mapEditor/loadMap/ok.lua new file mode 100644 index 0000000..e69de29 diff --git a/Assets/Scripts/Gui/mapEditor/newMap/ok.lua b/Assets/Scripts/Gui/mapEditor/newMap/ok.lua new file mode 100644 index 0000000..e69de29 diff --git a/Assets/Scripts/Gui/mapEditorMenu.lua b/Assets/Scripts/Gui/mapEditorMenu.lua new file mode 100644 index 0000000..31f0603 --- /dev/null +++ b/Assets/Scripts/Gui/mapEditorMenu.lua @@ -0,0 +1,19 @@ +Size = {x = 150, y = 40} + +numGui = 2 +gui = { + { + pos = {x = 110, y = 40}, + size = Size, + guiType = GuiType.BUTTON, + name = 'New map', + buttonType = ButtonType.NEW_MAP + }, + { + pos = {x = 110, y = 90}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Load map', + buttonType = ButtonType.LOAD_MAP + } +} diff --git a/Assets/Scripts/Gui/newMap.lua b/Assets/Scripts/Gui/newMap.lua new file mode 100644 index 0000000..f99f324 --- /dev/null +++ b/Assets/Scripts/Gui/newMap.lua @@ -0,0 +1,27 @@ +Size = {x = 140, y = 40} + +numGui = 4 +gui = { + { + pos = {x = 110, y = 150}, + size = Size, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 110, y = 190}, + size = Size, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 110, y = 220}, + size = Size, + guiType = GuiType.TEXTBOX + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 50}, + guiType = GuiType.BUTTON, + name = 'Ok', + buttonType = ButtonType.NEW_MAP_OK + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index db7e929..07417fe 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 tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp) +set(GUI tooltip.cpp concreteGuiManager.cpp singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.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/concreteGuiManager.cpp b/concreteGuiManager.cpp index 78a5d38..ae7dd68 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -10,6 +10,8 @@ #include "okButton.h" #include "defaultsButton.h" #include "backButton.h" +#include "newMapButton.h" +#include "loadMapButton.h" namespace battleship{ using namespace std; @@ -83,6 +85,18 @@ namespace battleship{ button = new TabButton(pos, size, name, screens[diff]); break; } + case NEW_MAP: + button = new NewMapButton(pos, size); + break; + case NEW_MAP_OK: + button = new NewMapButton::OkButton(pos, size, nullptr, nullptr, nullptr); + break; + case LOAD_MAP: + button = new LoadMapButton(pos, size); + break; + case LOAD_MAP_OK: + button = new LoadMapButton::OkButton(pos, size, nullptr); + break; } return button; @@ -125,6 +139,11 @@ namespace battleship{ closable = true; } break; + case MAPS: + lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true); + numLines = lines.size(); + closable = true; + break; } maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 0556e2d..d244968 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -19,11 +19,16 @@ namespace battleship{ MOUSE_TAB, VIDEO_TAB, AUDIO_TAB, - MULTIPLAYER_TAB + MULTIPLAYER_TAB, + NEW_MAP, + NEW_MAP_OK, + LOAD_MAP, + LOAD_MAP_OK }; enum ListboxType { CONTROLS, - RESOLUTION + RESOLUTION, + MAPS }; class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{ diff --git a/loadMapButton.cpp b/loadMapButton.cpp new file mode 100644 index 0000000..a78d43e --- /dev/null +++ b/loadMapButton.cpp @@ -0,0 +1,54 @@ +#include "loadMapButton.h" +#include "concreteGuiManager.h" +#include "gameManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + LoadMapButton::OkButton::OkButton(vb01::Vector2 pos, vb01::Vector2 size, vb01Gui::Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){ this->listbox = listbox; } + + void LoadMapButton::OkButton::onClick(){ + /* + string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]); + + StateManager *sm = GameManager::getSingleton()->getStateManager(); + GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); + guiState->removeAllListboxes(); + guiState->removeAllButtons(vector{this}); + + sm->attachAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false)); + + guiState->removeButton(this); + */ + } + + LoadMapButton::LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + + void LoadMapButton::onClick(){ + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + guiManager->readLuaScreenScript("loadMap.lua"); + /* + + GameManager *gm = GameManager::getSingleton(); + StateManager *sm = gm->getStateManager(); + GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); + guiState->removeAllButtons(vector{this}); + + string basePath = gm->getPath(); + vector maps = readDir(basePath + "Models/Maps/", true); + int displayLimit = 2; + Listbox *mapsListbox = new Listbox(Vector2(100, 150), Vector2(140, 20), maps, (maps.size() > displayLimit ? maps.size() : displayLimit), basePath + "Fonts/batang.ttf"); + guiState->addListbox(mapsListbox); + guiState->addButton(new OkButton(Vector2(100, 350), Vector2(100, 20), mapsListbox)); + + guiState->removeButton(this); + */ + } +} diff --git a/loadMapButton.h b/loadMapButton.h new file mode 100644 index 0000000..afe733f --- /dev/null +++ b/loadMapButton.h @@ -0,0 +1,27 @@ +#ifndef LOAD_MAP_BUTTON_H +#define LOAD_MAP_BUTTON_H + +#include + +namespace vb01Gui{ + class Listbox; +} + +namespace battleship{ + class LoadMapButton : public vb01Gui::Button{ + public: + class OkButton : public vb01Gui::Button{ + public: + OkButton(vb01::Vector2, vb01::Vector2, vb01Gui::Listbox*); + void onClick(); + private: + vb01Gui::Listbox *listbox; + }; + + LoadMapButton(vb01::Vector2, vb01::Vector2); + void onClick(); + private: + }; +} + +#endif diff --git a/mapEditorButton.cpp b/mapEditorButton.cpp index e73859d..c7ce59b 100644 --- a/mapEditorButton.cpp +++ b/mapEditorButton.cpp @@ -2,6 +2,7 @@ #include "guiAppState.h" #include "inGameAppState.h" #include "mapEditorAppState.h" +#include "concreteGuiManager.h" #include @@ -12,104 +13,13 @@ namespace battleship{ using namespace gameBase; void MapEditorButton::onClick(){ - /* - class NewMapButton : public Button{ - public: - NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} - void onClick(){ - class OkButton : public Button{ - public: - OkButton(Vector2 pos, Vector2 size, Textbox *name, Textbox *sx, Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){ - this->name = name; - this->sizeX = sx; - this->sizeY = sy; - } - void onClick(){ - GameManager *gm = GameManager::getSingleton(); - StateManager *stateManager = gm->getStateManager(); - GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); - - state->removeAllTextboxes(); - state->removeAllButtons(vector{this}); - - Vector2 size = Vector2( - atof(wstringToString(sizeX->getText()).c_str()), - atof(wstringToString(sizeY->getText()).c_str()) - ); - stateManager->attachAppState(new MapEditorAppState(wstringToString(name->getText()), size, true)); - - state->removeButton(this); - } - private: - Textbox *name, *sizeX, *sizeY; - }; - - GameManager *gm = GameManager::getSingleton(); - StateManager *stateManager = gm->getStateManager(); - GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); - state->removeAllButtons(vector{this}); - - Vector2 size = Vector2(140, 20); - - string fontPath = gm->getPath() + "Fonts/batang.ttf"; - Textbox *name = new Textbox(Vector2(100, 150), size, fontPath); - Textbox *sizeX = new Textbox(Vector2(100, 150 + (size.y + 10)), size, fontPath); - Textbox *sizeY = new Textbox(Vector2(100, 150 + 2 * (size.y + 10)), size, fontPath); - state->addTextbox(name); - state->addTextbox(sizeX); - state->addTextbox(sizeY); - - state->addButton(new OkButton(Vector2(200, gm->getHeight() - 150), Vector2(140, 50), name, sizeX, sizeY)); - - state->removeButton(this); - } - private: - }; - class LoadMapButton : public Button{ - public: - LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} - void onClick(){ - class OkButton : public Button{ - public: - OkButton(Vector2 pos, Vector2 size, Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){ - this->listbox = listbox; - } - - void onClick(){ - string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]); - - StateManager *sm = GameManager::getSingleton()->getStateManager(); - GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); - guiState->removeAllListboxes(); - guiState->removeAllButtons(vector{this}); - - sm->attachAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false)); - - guiState->removeButton(this); - } - private: - Listbox *listbox; - }; - - GameManager *gm = GameManager::getSingleton(); - StateManager *sm = gm->getStateManager(); - GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); - guiState->removeAllButtons(vector{this}); - - string basePath = gm->getPath(); - vector maps = readDir(basePath + "Models/Maps/", true); - int displayLimit = 2; - Listbox *mapsListbox = new Listbox(Vector2(100, 150), Vector2(140, 20), maps, (maps.size() > displayLimit ? maps.size() : displayLimit), basePath + "Fonts/batang.ttf"); - guiState->addListbox(mapsListbox); - guiState->addButton(new OkButton(Vector2(100, 350), Vector2(100, 20), mapsListbox)); - - guiState->removeButton(this); - } - private: - }; - */ - - + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + guiManager->readLuaScreenScript("mapEditorMenu.lua"); /* GameManager *gm = GameManager::getSingleton(); GuiAppState *guiState = (GuiAppState*)gm->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE); diff --git a/newMapButton.cpp b/newMapButton.cpp new file mode 100644 index 0000000..b4cbbf3 --- /dev/null +++ b/newMapButton.cpp @@ -0,0 +1,68 @@ +#include "newMapButton.h" +#include "concreteGuiManager.h" +#include "gameManager.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + NewMapButton::OkButton::OkButton(vb01::Vector2 pos, vb01::Vector2 size, vb01Gui::Textbox *name, vb01Gui::Textbox *sx, vb01Gui::Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){ + this->name = name; + this->sizeX = sx; + this->sizeY = sy; + } + + void NewMapButton::OkButton::onClick(){ + /* + GameManager *gm = GameManager::getSingleton(); + StateManager *stateManager = gm->getStateManager(); + GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); + + state->removeAllTextboxes(); + state->removeAllButtons(vector{this}); + + Vector2 size = Vector2( + atof(wstringToString(sizeX->getText()).c_str()), + atof(wstringToString(sizeY->getText()).c_str()) + ); + stateManager->attachAppState(new MapEditorAppState(wstringToString(name->getText()), size, true)); + + state->removeButton(this); + */ + } + + NewMapButton::NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + + void NewMapButton::onClick(){ + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->removeAllButtons(); + guiManager->removeAllListboxes(); + guiManager->removeAllCheckboxes(); + guiManager->removeAllSliders(); + guiManager->removeAllTextboxes(); + guiManager->readLuaScreenScript("newMap.lua"); + /* + + GameManager *gm = GameManager::getSingleton(); + StateManager *stateManager = gm->getStateManager(); + GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); + state->removeAllButtons(vector{this}); + + Vector2 size = Vector2(140, 20); + + string fontPath = gm->getPath() + "Fonts/batang.ttf"; + Textbox *name = new Textbox(Vector2(100, 150), size, fontPath); + Textbox *sizeX = new Textbox(Vector2(100, 150 + (size.y + 10)), size, fontPath); + Textbox *sizeY = new Textbox(Vector2(100, 150 + 2 * (size.y + 10)), size, fontPath); + state->addTextbox(name); + state->addTextbox(sizeX); + state->addTextbox(sizeY); + + state->addButton(new OkButton(Vector2(200, gm->getHeight() - 150), Vector2(140, 50), name, sizeX, sizeY)); + + state->removeButton(this); + */ + } +} + diff --git a/newMapButton.h b/newMapButton.h new file mode 100644 index 0000000..371e394 --- /dev/null +++ b/newMapButton.h @@ -0,0 +1,27 @@ +#ifndef NEW_MAP_BUTTON_H +#define NEW_MAP_BUTTON_H + +#include + +namespace vb01Gui{ + class Textbox; +} + +namespace battleship{ + class NewMapButton : public vb01Gui::Button{ + public: + class OkButton : public vb01Gui::Button{ + public: + OkButton(vb01::Vector2, vb01::Vector2, vb01Gui::Textbox*, vb01Gui::Textbox*, vb01Gui::Textbox*); + void onClick(); + private: + vb01Gui::Textbox *name, *sizeX, *sizeY; + }; + + NewMapButton(vb01::Vector2, vb01::Vector2); + void onClick(); + private: + }; +} + +#endif