diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua new file mode 100644 index 0000000..87e2803 --- /dev/null +++ b/Assets/Scripts/Gui/unitGui.lua @@ -0,0 +1,14 @@ +res = graphics.resolution +sz = 210 + +resTextScale = {x = .5, y = .5} +buttonInitPos = {x = sz, y = res.y - .75 * sz, z = 0} +buttonSize = {x = 20, y = 20} + +--[[ + { + guiType = GuiType.GUI_RECTANGLE, + pos = {x = sz, y = res.y - .75 * sz, z = 0}, + color = {x = .6, y = .6, z = .6, w = .4} + } + ]]-- diff --git a/activeGameState.cpp b/activeGameState.cpp index 7472049..a0d53d5 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -27,6 +27,7 @@ #include "gameObjectFrameController.h" #include "gameObjectFactory.h" #include "cameraController.h" +#include "unitButton.h" #include "concreteGuiManager.h" using namespace vb01; @@ -182,6 +183,13 @@ namespace battleship{ renderUnits(); + vector currSelectedUnits = mainPlayer->getSelectedUnits(); + + if(prevSelectedUnits != currSelectedUnits){ + addUnitGui(); + prevSelectedUnits = currSelectedUnits; + } + if(fc->isRotating() || fc->isPlacingOnSurface() || fc->isPlacingVertically()) fc->update(); @@ -351,14 +359,6 @@ namespace battleship{ if(!u->getLosLightNode()) u->initLosLight(); model->setVisible(true); - - Vector2 pos = u->getScreenPos(); - string guiScreen = u->getGuiScreen(); - - if(!selUnits.empty() && u == selUnits[0] && guiScreen != "" && guiScreen != unitGuiScreen){ - guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); - unitGuiScreen = guiScreen; - } } else{ if(u->getLosLightNode()) u->destroyLosLight(); @@ -457,6 +457,40 @@ namespace battleship{ for(Unit *unit : selectedUnits) unit->setState(state); } + + //TODO replace script path literal + void ActiveGameState::addUnitGui(){ + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + + for(UnitButton *button : unitButtons) + guiManager->removeButton((Button*)button); + + unitButtons.clear(); + + vector currSelectedUnits = mainPlayer->getSelectedUnits(); + + if(!currSelectedUnits.empty()){ + int mainUnitId = currSelectedUnits[0]->getId(); + + sol::state_view SOL_LUA_VIEW = generateView(); + string path = GameManager::getSingleton()->getPath(); + + SOL_LUA_VIEW.script_file(path + "Scripts/Gui/unitGui.lua"); + sol::table posTbl = SOL_LUA_VIEW["buttonInitPos"], sizeTbl = SOL_LUA_VIEW["buttonSize"]; + Vector3 initPos = Vector3(posTbl["x"], posTbl["y"], posTbl["z"]); + Vector2 size = Vector2(sizeTbl["x"], sizeTbl["y"]); + + string fp = path + "Fonts/batang.ttf"; + + for(int i = 0; i < 2; i++){ + for(int j = 0; j < 2; j++){ + UnitButton *button = new UnitButton(initPos + Vector3(i * size.x, j * size.y, 0), size, "", fp, -1, "", mainUnitId); + guiManager->addButton(button); + unitButtons.push_back(button); + } + } + } + } void ActiveGameState::onAction(int bind, bool isPressed) { GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); diff --git a/activeGameState.h b/activeGameState.h index 358125b..c0e69cd 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -19,6 +19,8 @@ namespace vb01Gui{ namespace battleship{ class GameObject; + class Unit; + class UnitButton; class ActiveGameState : public gameBase::AbstractAppState { public: @@ -60,6 +62,7 @@ namespace battleship{ void issueOrder(Order::TYPE, std::vector, bool); bool isInLineOfSight(vb01::Vector3, float, Unit*); void enableUnitState(Unit::State); + void addUnitGui(); inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;} CursorState cursorState = CursorState::NORMAL; @@ -69,9 +72,10 @@ namespace battleship{ GameObject *gameObjHoveredOn = nullptr; vb01::Node *dragboxNode = nullptr; vb01::Vector2 clickPoint; - std::vector unitGroups[9]; + std::vector unitGroups[9], prevSelectedUnits; std::vector targets; std::vector buttons; + std::vector unitButtons; bool isSelectionBox = false; bool shiftPressed = false; bool controlPressed = false;