diff --git a/CMakeLists.txt b/CMakeLists.txt index f89e379..0ae7005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) -set(UNIT_BUTTONS buildButton.cpp) +set(UNIT_BUTTONS unitButton.cpp buildButton.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) diff --git a/activeGameState.cpp b/activeGameState.cpp index 723731a..6a8dd7e 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -116,6 +116,9 @@ namespace battleship{ UnitFrameController *ufCtr = UnitFrameController::getSingleton(); ufCtr->removeUnitFrames(); ufCtr->setPlacingFrames(false); + + ConcreteGuiManager::getSingleton()->removeAllGuiElements(); + buttons.clear(); } //TODO fix fog of war for hostile units diff --git a/activeGameState.h b/activeGameState.h index a6a804c..2db8e28 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -10,6 +10,10 @@ namespace vb01{ class Node; } +namespace vb01Gui{ + class Button; +} + namespace battleship{ class ActiveGameState : public gameBase::AbstractAppState { public: @@ -20,6 +24,8 @@ namespace battleship{ void update(); void onAction(int, bool); void onAnalog(int, float); + inline void addButton(vb01Gui::Button *b){buttons.push_back(b);} + inline std::vector getButtons(){return buttons;} inline Player* getPlayer(){return mainPlayer;} inline std::vector& getUnitGroup(int i){return unitGroups[i];} private: @@ -43,6 +49,7 @@ namespace battleship{ std::vector unitLightNodes; std::vector unitGroups[9]; std::vector targets; + std::vector buttons; bool isSelectionBox = false, shiftPressed = false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false; int playerId, zooms = 0; const int NUM_MAX_ZOOMS = 10; diff --git a/buildButton.cpp b/buildButton.cpp new file mode 100644 index 0000000..b5f93cc --- /dev/null +++ b/buildButton.cpp @@ -0,0 +1,27 @@ +#include "buildButton.h" +#include "gameManager.h" +#include "unit.h" +#include "unitFrameController.h" + +#include + +namespace battleship{ + using namespace sol; + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + BuildButton::BuildButton(Vector2 pos, Vector2 size, int structureId, string name, int trigger, string imagePath) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath){ + this->structureId = structureId; + } + + void BuildButton::onClick(){ + sol::state_view SOL_LUA_STATE = generateView(); + string modelPath = (string)SOL_LUA_STATE["basePath"][structureId + 1] + (string)SOL_LUA_STATE["meshPath"][structureId + 1]; + + UnitFrameController *ufCtr = UnitFrameController::getSingleton(); + ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, structureId, (int)UnitType::LAND)); + ufCtr->setPlacingFrames(true); + } +} diff --git a/buildButton.h b/buildButton.h new file mode 100644 index 0000000..ae4802b --- /dev/null +++ b/buildButton.h @@ -0,0 +1,16 @@ +#ifndef BUILD_BUTTON_H +#define BUILD_BUTTON_H + +#include "unitButton.h" + +namespace battleship{ + class BuildButton : public UnitButton{ + public: + BuildButton(vb01::Vector2, vb01::Vector2, int, std::string, int, std::string); + void onClick(); + private: + int structureId; + }; +} + +#endif diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 973b28b..bec5f96 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -338,9 +338,15 @@ namespace battleship{ return textbox; } - void ConcreteGuiManager::readLuaScreenScript(string script){ - removeAllGuiElements(); - + void ConcreteGuiManager::readLuaScreenScript( + string script, + vector buttonExceptions, + vector listboxExceptions, + vector checkboxExceptions, + vector sliderExceptions, + vector textboxExceptions + ){ + removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions); guiElements.clear(); string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/"; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 94163ab..606413f 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -49,7 +49,14 @@ namespace battleship{ class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{ public: static ConcreteGuiManager* getSingleton(); - void readLuaScreenScript(std::string); + void readLuaScreenScript( + std::string, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{} + ); private: ConcreteGuiManager(){} vb01Gui::Button* parseButton(int); diff --git a/inGameAppState.cpp b/inGameAppState.cpp index ab48332..188bf82 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -112,7 +112,7 @@ namespace battleship{ isMainMenuActive = true; gm->getStateManager()->dettachAppState(activeState); - guiManager->readLuaScreenScript("gamePaused.lua"); + guiManager->readLuaScreenScript("gamePaused.lua", activeState->getButtons()); } else { isMainMenuActive = false; @@ -120,7 +120,7 @@ namespace battleship{ AssetManager::getSingleton()->load(gm->getPath() + (string)generateView()["modelPrefix"], true); - guiManager->readLuaScreenScript("inGame.lua"); + guiManager->readLuaScreenScript("inGame.lua", activeState->getButtons()); for(Player *p : Map::getSingleton()->getPlayers()) for(Unit *u : p->getUnits()) diff --git a/unitButton.cpp b/unitButton.cpp index e3844c6..c9aaf30 100644 --- a/unitButton.cpp +++ b/unitButton.cpp @@ -1,9 +1,20 @@ #include "unitButton.h" +#include "gameManager.h" +#include "activeGameState.h" + +#include namespace battleship{ using namespace std; using namespace vb01; using namespace vb01Gui; + using namespace gameBase; - UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, true, trigger, imagePath){} + UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, true, trigger, imagePath){ + StateManager *stateManager = GameManager::getSingleton()->getStateManager(); + ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE); + + if(activeState) + activeState->addButton(this); + } } diff --git a/unitButton.h b/unitButton.h index 8430ea4..696ae1e 100644 --- a/unitButton.h +++ b/unitButton.h @@ -8,7 +8,7 @@ namespace battleship{ class UnitButton : public vb01Gui::Button{ public: - UnitButton(vb01::Vector2 pos, vb01::Vector2 size, std::string name, std::string fontPath, int trigger, std::string imagePath) : Button(pos, size, name, fontPath, trigger, true, imagePath){} + UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string); protected: std::vector units; };