From feef91c9990f7fc7e1ef2d289660177bd5226639 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 9 Mar 2024 14:49:04 +0200 Subject: [PATCH] technology research button --- Assets/Scripts/GameObjects/Units/unitData.lua | 2 +- Assets/Scripts/Gui/main.lua | 3 ++- Assets/Scripts/Gui/researchStructCommands.lua | 15 ++++++++++++ CMakeLists.txt | 2 +- activeGameState.cpp | 4 ++-- concreteGuiManager.cpp | 4 ++++ concreteGuiManager.h | 3 ++- researchButton.cpp | 24 +++++++++++++++++++ researchButton.h | 16 +++++++++++++ unit.cpp | 2 +- unit.h | 4 ++-- unitButton.h | 1 - 12 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Gui/researchStructCommands.lua create mode 100644 researchButton.cpp create mode 100644 researchButton.h diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 1933a47..5e42330 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -532,7 +532,7 @@ units = { name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', - guiScreen = '', + guiScreen = 'researchStructCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index c0dc13a..390113d 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -27,7 +27,8 @@ ButtonType = { LAND_FACTORY_TRAIN = 23, NAVAL_FACTORY_TRAIN = 24, FORT_TRAIN = 25, - STATISTICS = 26 + STATISTICS = 26, + RESEARCH = 27 } ListboxType = { diff --git a/Assets/Scripts/Gui/researchStructCommands.lua b/Assets/Scripts/Gui/researchStructCommands.lua new file mode 100644 index 0000000..166afe1 --- /dev/null +++ b/Assets/Scripts/Gui/researchStructCommands.lua @@ -0,0 +1,15 @@ +res = graphics.resolution +Size = {x = 100, y = 100} + +gui = { + { + pos = {x = res.x - 200, y = res.y - 200}, + size = Size, + name = "Research", + imagePath = '', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.APT, + trigger = 82, + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index ec20ad1..bb506e5 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 unitButton.cpp buildButton.cpp trainButton.cpp) +set(UNIT_BUTTONS unitButton.cpp buildButton.cpp trainButton.cpp researchButton.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 8cbdb43..3e10f66 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -202,10 +202,10 @@ namespace battleship{ Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize(); Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize; Vector2 pos = u->getScreenPos(); - string guiScreen = u->getBuildableUnitGuiScreen(); + string guiScreen = u->getGuiScreen(); if(!selUnits.empty() && u == selUnits[0] && guiScreen != "" && guiScreen != unitGuiScreen){ - guiManager->readLuaScreenScript(u->getBuildableUnitGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); + guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); unitGuiScreen = guiScreen; } diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 404e6ba..7c04e61 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -24,6 +24,7 @@ #include "buildButton.h" #include "trainButton.h" #include "statsButton.h" +#include "researchButton.h" namespace battleship{ using namespace std; @@ -196,6 +197,9 @@ namespace battleship{ case STATISTICS: button = new StatsButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"]); break; + case RESEARCH: + button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["LAB"], (int)guiTable["techId"]); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index c141da2..d9bfb29 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -41,7 +41,8 @@ namespace battleship{ LAND_FACTORY_TRAIN, NAVAL_FACTORY_TRAIN, FORT_TRAIN, - STATISTICS + STATISTICS, + RESEARCH }; enum ListboxType { CONTROLS, diff --git a/researchButton.cpp b/researchButton.cpp new file mode 100644 index 0000000..c950e9c --- /dev/null +++ b/researchButton.cpp @@ -0,0 +1,24 @@ +#include "researchButton.h" +#include "activeGameState.h" +#include "researchStruct.h" + +#include +#include + +namespace battleship{ + using namespace vb01; + using namespace std; + + ResearchButton::ResearchButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int tid) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), techId(tid){} + + void ResearchButton::onClick(){ + ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); + Player *player = activeState->getPlayer(); + vector selUnits = player->getSelectedUnits(), researchStructs = player->getUnitsById(unitId); + + for(Unit *rs : researchStructs) + if(find(selUnits.begin(), selUnits.end(), rs) != selUnits.end()) + ((ResearchStruct*)rs)->appendToQueue(techId); + } +} diff --git a/researchButton.h b/researchButton.h new file mode 100644 index 0000000..337bc2f --- /dev/null +++ b/researchButton.h @@ -0,0 +1,16 @@ +#ifndef RESEARCH_BUTTON_H +#define RESEARCH_BUTTON_H + +#include "unitButton.h" + +namespace battleship{ + class ResearchButton : public UnitButton{ + public: + ResearchButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int); + void onClick(); + private: + int techId; + }; +} + +#endif diff --git a/unit.cpp b/unit.cpp index 833d6a2..d800920 100755 --- a/unit.cpp +++ b/unit.cpp @@ -141,6 +141,7 @@ namespace battleship{ lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; type = (UnitType)unitTable["unitType"]; + guiScreen = unitTable["guiScreen"]; string tblName = "garrisonCapacity"; sol::optional gc = unitTable[tblName]; @@ -180,7 +181,6 @@ namespace battleship{ if(bu != sol::nullopt){ SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName); int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"]; - buildableUnitGuiScreen = unitTable["guiScreen"]; for(int i = 0; i < numBuildableUnits; i++){ sol::table buTable = unitTable[tblName][i + 1]; diff --git a/unit.h b/unit.h index 815c6f9..0d8d31e 100755 --- a/unit.h +++ b/unit.h @@ -149,7 +149,7 @@ namespace battleship{ inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;} inline Order getOrder(int i){return orders[i];} inline int getNumOrders(){return orders.size();} - inline std::string getBuildableUnitGuiScreen(){return buildableUnitGuiScreen;} + inline std::string getGuiScreen(){return guiScreen;} inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];} private: void renderOrderLine(bool); @@ -167,7 +167,7 @@ namespace battleship{ UnitClass unitClass; UnitType type; std::vector orders; - std::string buildableUnitGuiScreen = ""; + std::string guiScreen = ""; int health, maxHealth, playerId, lenHpBar = 200; vb01::s64 orderLineDispTime = 0, lastFireTime = 0; float lineOfSight; diff --git a/unitButton.h b/unitButton.h index db682e5..3184544 100644 --- a/unitButton.h +++ b/unitButton.h @@ -11,7 +11,6 @@ namespace battleship{ UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int); protected: int unitId; - std::vector units; }; }