diff --git a/Assets/Scripts/Gui/engineerCommands.lua b/Assets/Scripts/Gui/engineerCommands.lua new file mode 100644 index 0000000..a6b0297 --- /dev/null +++ b/Assets/Scripts/Gui/engineerCommands.lua @@ -0,0 +1,14 @@ +numGui = 1 +res = graphics.resolution + +gui = { + { + pos = {x = res.x - 200, y = res.y - 200}, + size = {x = 100, y = 100}, + name = 'Structure', + guiType = GuiType.BUTTON, + buttonType = ButtonType.BUILD, + trigger = 66, + structureId = 3 + } +} diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 29964e7..3436c20 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -22,7 +22,8 @@ ButtonType = { RESUME = 18, CONSOLE = 19, MAIN_MENU = 20, - CONSOLE_COMMAND_OK = 21 + CONSOLE_COMMAND_OK = 21, + BUILD = 22 } ListboxType = { diff --git a/Assets/Scripts/Gui/vehicleCommands.lua b/Assets/Scripts/Gui/vehicleCommands.lua new file mode 100644 index 0000000..e69de29 diff --git a/CMakeLists.txt b/CMakeLists.txt index 562ea13..f89e379 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,11 @@ set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) +set(UNIT_BUTTONS 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) -set(BUTTONS singlePlayerButton.cpp exitButton.cpp backButton.cpp consoleCommand.cpp playButton.cpp ${OPTIONS_BUTTONS} ${IN_GAME_APP_STATE_BUTTONS} ${MAP_EDITOR_BUTTONS}) +set(BUTTONS singlePlayerButton.cpp exitButton.cpp backButton.cpp consoleCommand.cpp playButton.cpp ${OPTIONS_BUTTONS} ${IN_GAME_APP_STATE_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS}) set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp unitListbox.cpp) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) diff --git a/activeGameState.cpp b/activeGameState.cpp index f141e9c..f32302f 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -22,6 +22,7 @@ #include "tooltip.h" #include "unitFrameController.h" #include "cameraController.h" +#include "concreteGuiManager.h" using namespace vb01; using namespace vb01Gui; @@ -141,6 +142,11 @@ namespace battleship{ mainPlayer->selectUnit(u); u->toggleSelection(true); + + if(engineersSelected()){ + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->readLuaScreenScript("engineerCommands.lua"); + } } } @@ -304,6 +310,14 @@ namespace battleship{ targets.push_back(Order::Target((it != unitData.end() ? unitData[node] : unit), results[0].pos)); } } + + bool ActiveGameState::engineersSelected(){ + for(Unit *u : mainPlayer->getSelectedUnits()) + if(u->getUnitClass() == UnitClass::ENGINEER) + return true; + + return false; + } void ActiveGameState::onAction(int bind, bool isPressed) { GameManager *gm = GameManager::getSingleton(); @@ -415,31 +429,6 @@ namespace battleship{ } break; - case Bind::SELECT_STRUCTURE: - { - if(isPressed){ - bool engineersSelected = false; - - for(Unit *u : mainPlayer->getSelectedUnits()) - if(u->getUnitClass() == UnitClass::ENGINEER){ - engineersSelected = true; - break; - } - - if(!engineersSelected) - break; - - //TODO fix the magic value - int id = 3; - sol::state_view SOL_LUA_STATE = generateView(); - string modelPath = (string)SOL_LUA_STATE["basePath"][id + 1] + (string)SOL_LUA_STATE["meshPath"][id + 1]; - ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, id, (int)UnitType::LAND)); - - ufCtr->setPlacingFrames(true); - } - - break; - } case Bind::DESELECT_STRUCTURE: ufCtr->removeUnitFrames(); ufCtr->setPlacingFrames(false); diff --git a/activeGameState.h b/activeGameState.h index e321222..a6a804c 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -32,6 +32,7 @@ namespace battleship{ void addTarget(); void issueOrder(Order::TYPE, bool); bool isInLineOfSight(vb01::Vector3, float, Unit*); + bool engineersSelected(); GuiAppState *guiState; Player *mainPlayer; diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index c82e13f..973b28b 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -19,6 +19,7 @@ #include "playButton.h" #include "inGameAppState.h" #include "mainMenuButton.h" +#include "buildButton.h" namespace battleship{ using namespace std; @@ -154,6 +155,9 @@ namespace battleship{ button = new InGameAppState::ConsoleButton::ConsoleCommandEntryButton(textbox, listbox, pos, size, name); break; } + case BUILD: + button = new BuildButton(pos, size, (int)guiTable["structureId"], name, (int)guiTable["trigger"], ""); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 23886a6..94163ab 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -31,7 +31,8 @@ namespace battleship{ RESUME, CONSOLE_SCREEN, MAIN_MENU, - CONSOLE_COMMAND_OK + CONSOLE_COMMAND_OK, + BUILD }; enum ListboxType { CONTROLS, diff --git a/engineer.cpp b/engineer.cpp index f09a96c..433af48 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -10,11 +10,6 @@ namespace battleship{ } void Engineer::build(Order order){ - navigate(order, 0.5 * Map::getSingleton()->getCellSize().x); - - if(type == UnitType::LAND) - alignToSurface(); - if(pathPoints.empty()){ if(!order.targets[0].unit){ player->addUnit(order.targets[0].unit); @@ -30,5 +25,11 @@ namespace battleship{ removeOrder(0); } } + else{ + navigate(order, 0.5 * Map::getSingleton()->getCellSize().x); + + if(type == UnitType::LAND) + alignToSurface(); + } } }