From dcf87da4653f3913f263529aa71827029f18cfb3 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 29 Mar 2025 20:27:56 +0200 Subject: [PATCH 1/8] refactored unit button loading --- Assets/Scripts/Gui/unitGui.lua | 14 ++++++++++ activeGameState.cpp | 50 ++++++++++++++++++++++++++++------ activeGameState.h | 6 +++- 3 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 Assets/Scripts/Gui/unitGui.lua 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; From 27414237743db0d4109387a9755017d335b38140 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 30 Mar 2025 11:58:45 +0300 Subject: [PATCH 2/8] unit buttons are loaded from a lua script --- Assets/Scripts/GameObjects/Units/unitData.lua | 34 +++++------ Assets/Scripts/Gui/main.lua | 28 +++++---- Assets/Scripts/Gui/unitGui.lua | 52 +++++++++++++++-- activeGameState.cpp | 34 +++-------- activeGameState.h | 3 +- concreteGuiManager.cpp | 58 +++++++++---------- concreteGuiManager.h | 14 ++++- 7 files changed, 122 insertions(+), 101 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 2b35f4e..459f70a 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -254,14 +254,14 @@ units = { {type = WeaponClass.HITSCAN, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 20, maxRange = 8}, }, buildableUnits = { - {id = UnitId.LAND_FACTORY, buildable = true}, - {id = UnitId.NAVAL_FACTORY, buildable = true}, - {id = UnitId.TRADE_CENTER, buildable = true}, - {id = UnitId.LAB, buildable = true}, - {id = UnitId.POINT_DEFENSE, buildable = true}, - {id = UnitId.FORT, buildable = true}, - {id = UnitId.EXTRACTOR, buildable = true}, - {id = UnitId.REFINERY, buildable = true}, + {id = UnitId.LAND_FACTORY, buildable = true, trigger = 76}, + {id = UnitId.NAVAL_FACTORY, buildable = true, trigger = 78}, + {id = UnitId.TRADE_CENTER, buildable = true, trigger = 77}, + {id = UnitId.LAB, buildable = true, trigger = 84}, + {id = UnitId.POINT_DEFENSE, buildable = true, trigger = 80}, + {id = UnitId.FORT, buildable = true, trigger = 70}, + {id = UnitId.EXTRACTOR, buildable = true, trigger = 69}, + {id = UnitId.REFINERY, buildable = true, trigger = 82}, }, unitClass = UnitClass.ENGINEER, unitType = UnitType.HOVER, @@ -280,7 +280,6 @@ units = { albedoPath = 'engineer.jpg', colorNodes = {'Cube.008'}, meshPath = 'engineer2.xml', - guiScreen = 'engineerCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Engineers/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', speed = .1, @@ -777,10 +776,10 @@ units = { }, { buildableUnits = { - {id = UnitId.WAR_MECH, buildable = true}, - {id = UnitId.TANK, buildable = true}, - {id = UnitId.ARTILLERY, buildable = true}, - {id = UnitId.RESOURCE_ROVER, buildable = true} + {id = UnitId.WAR_MECH, buildable = true, trigger = 87}, + {id = UnitId.TANK, buildable = true, trigger = 84}, + {id = UnitId.ARTILLERY, buildable = true, trigger = 65}, + {id = UnitId.RESOURCE_ROVER, buildable = true, trigger = 82} }, unitClass = UnitClass.LAND_FACTORY, unitType = UnitType.LAND, @@ -796,7 +795,6 @@ units = { albedoPath = 'factory.jpg', basePath = PATH .. structurePrefix .. 'LandFactories/', meshPath = 'landFactory.xml', - guiScreen = 'landFactoryCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -814,7 +812,6 @@ units = { basePath = PATH .. structurePrefix .. 'NavalFactories/', meshPath = 'navalFactory.xml', albedoPath = 'factory.jpg', - guiScreen = 'navalFactoryCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -833,7 +830,7 @@ units = { basePath = PATH .. structurePrefix .. 'TradeCenters/', meshPath = 'tradeCenter.xml', albedoPath = 'tradeCenter.jpg', - guiScreen = 'tradingCenterCommands.lua', + --guiScreen = 'tradingCenterCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -855,7 +852,7 @@ units = { basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab2.xml', albedoPath = 'lab.jpg', - guiScreen = 'researchStructCommands.lua', + --guiScreen = 'researchStructCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, @@ -957,7 +954,7 @@ units = { deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { - buildableUnits = {{id = UnitId.ENGINEER, buildable = true}}, + buildableUnits = {{id = UnitId.ENGINEER, buildable = true, trigger = 69}}, unitClass = UnitClass.FORT, unitType = UnitType.LAND, isVehicle = false, @@ -972,7 +969,6 @@ units = { meshPath = 'fort2.xml', colorNodes = {'Cube.004'}, albedoPath = 'fort.jpg', - guiScreen = 'fortCommands.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 0affb41..0225aac 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -24,21 +24,19 @@ ButtonType = { MAIN_MENU = 20, CONSOLE_COMMAND_OK = 21, BUILD = 22, - LAND_FACTORY_TRAIN = 23, - NAVAL_FACTORY_TRAIN = 24, - FORT_TRAIN = 25, - STATISTICS = 26, - RESEARCH = 27, - BUY_REFINEDS = 28, - SELL_REFINEDS = 29, - BUY_RESEARCH = 30, - SELL_RESEARCH = 31, - ACTIVE_GAME_STATE = 32, - PLAYER_TRADE = 33, - TRADING_SCREEN = 34, - TRADE_OFFER = 35, - RESOURCE_AMMOUNT = 36, - MINIMAP = 37 + TRAIN = 23, + STATISTICS = 24, + RESEARCH = 25, + BUY_REFINEDS = 26, + SELL_REFINEDS = 27, + BUY_RESEARCH = 28, + SELL_RESEARCH = 29, + ACTIVE_GAME_STATE = 30, + PLAYER_TRADE = 31, + TRADING_SCREEN = 32, + TRADE_OFFER = 33, + RESOURCE_AMMOUNT = 34, + MINIMAP = 35 } ListboxType = { diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua index 87e2803..a3a5845 100644 --- a/Assets/Scripts/Gui/unitGui.lua +++ b/Assets/Scripts/Gui/unitGui.lua @@ -5,10 +5,50 @@ 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} +function generateButton(numGui, buttonData) + xOffset = math.floor(.5 * (numGui + 1)) * buttonSize.x + yOffset = (numGui + 1) % 2 == 0 and 0 or buttonSize.y + + button = { + pos = {x = buttonInitPos.x + xOffset, y = buttonInitPos.y + yOffset, z = .5}, + size = buttonSize, + guiType = GuiType.BUTTON, + buttonType = buttonData.buttonType, + trigger = buttonData.trigger, + factoryId = buttonData.factoryId } - ]]-- + + return button +end + +function generateGui(unitId) + gui = {} + + if units[unitId + 1].buildableUnits then + for i = 1, #units[unitId + 1].buildableUnits do + buildUnit = units[unitId + 1].buildableUnits[i] + + if not buildUnit.buildable then goto continue end + + isFactory = ( + buildUnit.unitClass == UnitClass.LAND_FACTORY or + buildUnit.unitClass == UnitClass.NAVAL_FACTORY or + buildUnit.unitClass == UnitClass.FORT + ) + + buttonData = { + trigger = buildUnit.trigger, + name = units[unitId + 1].name, + factoryId = (isFactory and unitId or nil), + buttonType = (buildUnit.isVehicle and ButtonType.TRAIN or ButtonType.BUILD) + } + gui[#gui + 1] = generateButton(#gui, buttonData) + + ::continue:: + end + end + + return gui +end + +gui = generateGui(_mainUnitId) diff --git a/activeGameState.cpp b/activeGameState.cpp index a0d53d5..8ae98c1 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -458,38 +458,22 @@ namespace battleship{ 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(); + if(currSelectedUnits.empty()) return; - sol::state_view SOL_LUA_VIEW = generateView(); - string path = GameManager::getSingleton()->getPath(); + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - 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"]); + sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script("_mainUnitId = " + to_string(currSelectedUnits[0]->getId())); + guiManager->readLuaScreenScriptDel("unitGui.lua", unitButtons); - string fp = path + "Fonts/batang.ttf"; + SOL_LUA_VIEW.script("numGui = #gui"); + int numButtons = SOL_LUA_VIEW["numGui"]; - 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); - } - } - } + for(int i = 0; i < numButtons; i++) + unitButtons.push_back(guiManager->getButtons()[guiManager->getButtons().size() - (i + 1)]); } void ActiveGameState::onAction(int bind, bool isPressed) { diff --git a/activeGameState.h b/activeGameState.h index c0e69cd..0b84ac6 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -74,8 +74,7 @@ namespace battleship{ vb01::Vector2 clickPoint; std::vector unitGroups[9], prevSelectedUnits; std::vector targets; - std::vector buttons; - std::vector unitButtons; + std::vector buttons, unitButtons; bool isSelectionBox = false; bool shiftPressed = false; bool controlPressed = false; diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index d994c6a..b1f87fd 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -181,37 +181,11 @@ namespace battleship{ break; } case BUILD: - { - int unitId = SOL_LUA_STATE["UnitId"]["ENGINEER"]; - int strId = SOL_LUA_STATE["units"][unitId + 1]["buildableUnits"][guiId + 1]["id"]; - string buttonName = SOL_LUA_STATE["units"][strId + 1]["name"]; - button = new BuildButton(pos, size, buttonName, (int)guiTable["trigger"], imagePath, unitId, guiId); + button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["ENGINEER"], guiId); break; - } - case LAND_FACTORY_TRAIN: - { - int facId = SOL_LUA_STATE["UnitId"]["LAND_FACTORY"]; - int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; - string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], imagePath, facId, guiId); + case TRAIN: + button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["factoryId"], guiId); break; - } - case NAVAL_FACTORY_TRAIN: - { - int facId = SOL_LUA_STATE["UnitId"]["NAVAL_FACTORY"]; - int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; - string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], imagePath, facId, guiId); - break; - } - case FORT_TRAIN: - { - int facId = SOL_LUA_STATE["UnitId"]["FORT"]; - int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"]; - string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"]; - button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], imagePath, facId, guiId); - break; - } case STATISTICS: button = new StatsButton(pos, size, name, (int)guiTable["trigger"], imagePath); break; @@ -547,10 +521,32 @@ namespace battleship{ vector checkboxExceptions, vector sliderExceptions, vector textboxExceptions, - vector guiRecttboxExceptions, + vector guiRectboxExceptions, vector textExceptions ){ - removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRecttboxExceptions, textExceptions); + removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions); + guiElements.clear(); + parseLuaScript(script); + } + + void ConcreteGuiManager::readLuaScreenScriptDel( + string script, + vector buttons, + vector listboxs, + vector checkboxs, + vector sliders, + vector textboxs, + vector guiRectboxs, + vector texts + ){ + for(Button *b : buttons) removeButton(b); + for(Listbox *l : listboxs) removeListbox(l); + for(Checkbox *c : checkboxs) removeCheckbox(c); + for(Slider *s : sliders) removeSlider(s); + for(Textbox *t : textboxs) removeTextbox(t); + for(Node *r : guiRectboxs) removeGuiRectangle(r); + for(Text *t : texts) removeText(t); + guiElements.clear(); parseLuaScript(script); } diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 1f0dec5..a1b85e2 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -38,9 +38,7 @@ namespace battleship{ MAIN_MENU, CONSOLE_COMMAND_OK, BUILD, - LAND_FACTORY_TRAIN, - NAVAL_FACTORY_TRAIN, - FORT_TRAIN, + TRAIN, STATISTICS, RESEARCH, BUY_REFINEDS, @@ -84,6 +82,16 @@ namespace battleship{ std::vector = std::vector{}, std::vector = std::vector{} ); + void readLuaScreenScriptDel( + std::string, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{} + ); void parseLuaScript(std::string); private: ConcreteGuiManager(); From 9eea473bef2cdf707a9c5fc1f27ef0f2f8a99eb9 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Mon, 31 Mar 2025 19:47:05 +0300 Subject: [PATCH 3/8] placeable unit order buttons working unit ability buttons --- Assets/Scripts/Core/player.lua | 11 ++- Assets/Scripts/GameObjects/Units/unitData.lua | 23 +++++- Assets/Scripts/Gui/main.lua | 4 +- Assets/Scripts/Gui/unitGui.lua | 76 +++++++++++++++---- CMakeLists.txt | 2 +- activeStateButton.cpp | 20 +---- concreteGuiManager.cpp | 13 +++- concreteGuiManager.h | 2 + orderButton.cpp | 43 +++++++++++ orderButton.h | 16 ++++ stateToggleButton.cpp | 40 ++++++++++ stateToggleButton.h | 15 ++++ unit.h | 3 +- 13 files changed, 221 insertions(+), 47 deletions(-) create mode 100644 orderButton.cpp create mode 100644 orderButton.h create mode 100644 stateToggleButton.cpp create mode 100644 stateToggleButton.h diff --git a/Assets/Scripts/Core/player.lua b/Assets/Scripts/Core/player.lua index bb3fd9d..b92186e 100644 --- a/Assets/Scripts/Core/player.lua +++ b/Assets/Scripts/Core/player.lua @@ -11,7 +11,6 @@ Player.taskForceData = { Player.taskForces = {} ---TODO use enum-like values instead of literals for order types --TODO simplify building construction function Player:buildFort(arguments) forts = self:getUnitsByClass(UnitClass.FORT, 1) @@ -47,7 +46,7 @@ function Player:buildFort(arguments) angle = self.baseDir:getAngleBetween(Vector3:new(0, 0, 1)) * (right and -1 or 1) fort = GameObjectFactory.createUnit(self, UnitId.FORT, sp, Quaternion:new(angle, Vector3:new(0, 1, 0)), 0) self:addUnit(fort) - self:issueOrder(1, Vector3:new(0, 0, 0), {Target:new(fort, Vector3:new(0, 0, 0))}, false) + self:issueOrder(OrderType.BUILD, Vector3:new(0, 0, 0), {Target:new(fort, Vector3:new(0, 0, 0))}, false) return BTNodeResult.RUNNING end @@ -85,7 +84,7 @@ function Player:buildStructure(engineer, buildingId, buildPos, buildAngle) building = GameObjectFactory.createUnit(self, buildingId, buildPos, Quaternion:new(1, 0, 0, 0), 0) self:addUnit(building) - self:issueOrder(1, Vector3:new(0, 0, 0), {Target:new(building, Vector3:new(0, 0, 0))}, false) + self:issueOrder(OrderType.BUILD, Vector3:new(0, 0, 0), {Target:new(building, Vector3:new(0, 0, 0))}, false) end building = self:getUnitsByClass(unitClass, 1)[1] @@ -156,7 +155,7 @@ function Player:startHarvesting() self:deselectUnits() self:selectUnits({harvesters[1]}) - self:issueOrder(7, Vector3:new(0, 0, 0), {Target:new(extractor, Vector3:new(0, 0, 0))}, false) + self:issueOrder(OrderType.SUPPLY, Vector3:new(0, 0, 0), {Target:new(extractor, Vector3:new(0, 0, 0))}, false) return BTNodeResult.SUCCESS end @@ -259,7 +258,7 @@ function Player:clearNearEnemies(arguments) if not taskForce.clearing and targUnit then self:deselectUnits() self:selectUnits(taskForce.units) - self:issueOrder(2, Vector3:new(0, 0, 0), {Target:new(targUnit, Vector3:new(0, 0, 0))}, false) + self:issueOrder(OrderType.MOVE, Vector3:new(0, 0, 0), {Target:new(targUnit, Vector3:new(0, 0, 0))}, false) self.taskForces[arguments.tfId].clearing = true elseif taskForce.clearing and not targUnit then @@ -281,7 +280,7 @@ function Player:attackSpawnPoint(arguments) for i = 1, #taskForce.units do taskForce.units[i]:setState(0) end enemySpawnPoint = Map.getSingleton():getSpawnPoint(taskForce.spawnPointId) - self:issueOrder(2, Vector3:new(0, 0, 0), {Target:new(nil, enemySpawnPoint)}, false) + self:issueOrder(OrderType.MOVE, Vector3:new(0, 0, 0), {Target:new(nil, enemySpawnPoint)}, false) self.taskForces[arguments.tfId].attacking = true return BTNodeResult.RUNNING diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 459f70a..f7808fe 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -1,4 +1,15 @@ ---TYPE = {ATTACK = 0, BUILD = 1, MOVE = 2, GARRISON = 3, EJECT = 4, PATROL = 5, LAUNCH = 6}; +OrderType = { + HALT = -1, + ATTACK = 0, + BUILD = 1, + MOVE = 2, + GARRISON = 3, + EJECT = 4, + PATROL = 5, + LAUNCH = 6, + SUPPLY = 7, + HACK = 8 +} UnitId = { WAR_MECH = 0, TANK = 1, @@ -263,6 +274,7 @@ units = { {id = UnitId.EXTRACTOR, buildable = true, trigger = 69}, {id = UnitId.REFINERY, buildable = true, trigger = 82}, }, + abilityButtons = {{buttonType = ButtonType.ORDER, name = 'Hack', orderType = OrderType.HACK}}, unitClass = UnitClass.ENGINEER, unitType = UnitType.HOVER, armor = {ArmorType.MECHANIC}, @@ -818,6 +830,12 @@ units = { { unitClass = UnitClass.TRADE_CENTER, unitType = UnitType.LAND, + abilityButtons = { + {buttonType = ButtonType.BUY_REFINEDS, name = 'Buy ref', trigger = 73}, + {buttonType = ButtonType.SELL_REFINEDS, name = 'Sell ref', trigger = 79}, + {buttonType = ButtonType.BUY_RESEARCH, name = 'Buy rsch', trigger = 75}, + {buttonType = ButtonType.SELL_RESEARCH, name = 'Sell rsch', trigger = 76} + }, isVehicle = false, health = 500, buildTime = 1000, @@ -830,13 +848,13 @@ units = { basePath = PATH .. structurePrefix .. 'TradeCenters/', meshPath = 'tradeCenter.xml', albedoPath = 'tradeCenter.jpg', - --guiScreen = 'tradingCenterCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { unitClass = UnitClass.LAB, unitType = UnitType.LAND, + abilityButtons = {{buttonType = ButtonType.ACTIVE_GAME_STATE, name = 'Tech tree', guiScreen = 'techTree.lua'}}, isVehicle = false, health = 500, buildTime = 1000, @@ -852,7 +870,6 @@ units = { basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab2.xml', albedoPath = 'lab.jpg', - --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 0225aac..5664fdb 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -36,7 +36,9 @@ ButtonType = { TRADING_SCREEN = 32, TRADE_OFFER = 33, RESOURCE_AMMOUNT = 34, - MINIMAP = 35 + UNIT_STATE = 35, + ORDER = 36, + MINIMAP = 37, } ListboxType = { diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua index a3a5845..db278e4 100644 --- a/Assets/Scripts/Gui/unitGui.lua +++ b/Assets/Scripts/Gui/unitGui.lua @@ -3,44 +3,92 @@ sz = 210 resTextScale = {x = .5, y = .5} buttonInitPos = {x = sz, y = res.y - .75 * sz, z = 0} -buttonSize = {x = 20, y = 20} +buttonSize = {x = 50, y = 50} +buttonSpace = {x = 10, y = 10} function generateButton(numGui, buttonData) - xOffset = math.floor(.5 * (numGui + 1)) * buttonSize.x - yOffset = (numGui + 1) % 2 == 0 and 0 or buttonSize.y + xOffset = math.floor(.5 * numGui) * (buttonSize.x + buttonSpace.x) + yOffset = (numGui + 1) % 2 == 0 and (buttonSize.y + buttonSpace.y) or 0 button = { pos = {x = buttonInitPos.x + xOffset, y = buttonInitPos.y + yOffset, z = .5}, size = buttonSize, guiType = GuiType.BUTTON, + name = buttonData.name, buttonType = buttonData.buttonType, - trigger = buttonData.trigger, - factoryId = buttonData.factoryId + trigger = (buttonData.trigger or -1), + orderType = buttonData.orderType, + factoryId = buttonData.factoryId, + engineerId = buttonData.engineerId, + guiScreen = buttonData.guiScreen, + slotId = buttonData.slotId } return button end function generateGui(unitId) - gui = {} + local gui = {} + vehicleButtonData = { + {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'}, + {buttonType = ButtonType.ORDER, orderType = OrderType.GARRISON, name = 'Garrison'}, + {buttonType = ButtonType.ORDER, orderType = OrderType.PATROL, name = 'Patrol'}, + {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'} + } + structureButtonData = { + {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'}, + {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'} + } - if units[unitId + 1].buildableUnits then - for i = 1, #units[unitId + 1].buildableUnits do - buildUnit = units[unitId + 1].buildableUnits[i] + mainUnit = units[unitId + 1] + unitButtonData = mainUnit.isVehicle and vehicleButtonData or structureButtonData + + if mainUnit.garrisonCapacity then + unitButtonData[#unitButtonData + 1] = { + buttonType = ButtonType.ORDER, + orderType = OrderType.EJECT, + name = 'Eject' + } + end + + for i = 1, #unitButtonData do + gui[#gui + 1] = generateButton(#gui, unitButtonData[i]) + end + + if mainUnit.abilityButtons then + for i = 1, #mainUnit.abilityButtons do + abilButton = mainUnit.abilityButtons[i] + + buttonData = { + trigger = abilButton.trigger, + name = abilButton.name, + buttonType = abilButton.buttonType, + guiScreen = abilButton.guiScreen, + orderType = abilButton.orderType + } + gui[#gui + 1] = generateButton(#gui, buttonData) + end + end + + if mainUnit.buildableUnits then + for i = 1, #mainUnit.buildableUnits do + buildUnit = mainUnit.buildableUnits[i] if not buildUnit.buildable then goto continue end isFactory = ( - buildUnit.unitClass == UnitClass.LAND_FACTORY or - buildUnit.unitClass == UnitClass.NAVAL_FACTORY or - buildUnit.unitClass == UnitClass.FORT + mainUnit.unitClass == UnitClass.LAND_FACTORY or + mainUnit.unitClass == UnitClass.NAVAL_FACTORY or + mainUnit.unitClass == UnitClass.FORT ) buttonData = { trigger = buildUnit.trigger, - name = units[unitId + 1].name, + name = units[buildUnit.id + 1].name, + buttonType = (mainUnit.isVehicle and ButtonType.BUILD or ButtonType.TRAIN), factoryId = (isFactory and unitId or nil), - buttonType = (buildUnit.isVehicle and ButtonType.TRAIN or ButtonType.BUILD) + engineerId = (mainUnit.unitClass == UnitClass.ENGINEER and unitId or nil), + slotId = (ButtonType.BUILD and i - 1 or nil) } gui[#gui + 1] = generateButton(#gui, buttonData) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50058ef..4c6d671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(BUILD_TESTS ON) set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED) cmake_policy(SET CMP0015 NEW) -set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp) +set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp orderButton.cpp stateToggleButton.cpp) set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp) set(TRADING_BUTTONS playerTradeButton.cpp tradingScreenButton.cpp offerButton.cpp resourceAmmountButton.cpp) set(MENU_BUTTONS mainMenuButton.cpp singlePlayerButton.cpp exitButton.cpp backButton.cpp playButton.cpp) diff --git a/activeStateButton.cpp b/activeStateButton.cpp index 275feec..529495d 100644 --- a/activeStateButton.cpp +++ b/activeStateButton.cpp @@ -27,24 +27,6 @@ namespace battleship{ } void ActiveStateButton::onClick(){ - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - - vector listboxes{}; - vector checkboxes{}; - vector sliders{}; - vector textboxes{}; - vector guiRects{ - guiManager->getGuiRectangle("refineds"), - guiManager->getGuiRectangle("wealth"), - guiManager->getGuiRectangle("research"), - }; - vector texts{ - guiManager->getText("depth"), - guiManager->getText("refineds"), - guiManager->getText("wealth"), - guiManager->getText("research") - }; - - guiManager->readLuaScreenScript(guiScreen, buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); + ConcreteGuiManager::getSingleton()->parseLuaScript(guiScreen); } } diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index b1f87fd..3ef3762 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -3,6 +3,7 @@ #include #include "concreteGuiManager.h" +#include "unit.h" #include "gameManager.h" #include "singlePlayerButton.h" #include "mapEditorButton.h" @@ -32,6 +33,8 @@ #include "tradingScreenButton.h" #include "offerButton.h" #include "resourceAmmountButton.h" +#include "orderButton.h" +#include "stateToggleButton.h" #include "minimapButton.h" namespace battleship{ @@ -181,10 +184,10 @@ namespace battleship{ break; } case BUILD: - button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["ENGINEER"], guiId); + button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["engineerId"], (int)guiTable["slotId"]); break; case TRAIN: - button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["factoryId"], guiId); + button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["factoryId"], (int)guiTable["slotId"]); break; case STATISTICS: button = new StatsButton(pos, size, name, (int)guiTable["trigger"], imagePath); @@ -226,6 +229,12 @@ namespace battleship{ case RESOURCE_AMMOUNT: button = new ResourceAmmountButton(pos, size, name, (int)guiTable["ammount"], (int)guiTable["trigger"], imagePath); break; + case ORDER: + button = new OrderButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["orderType"]); + break; + case UNIT_STATE: + button = new StateToggleButton(pos, size, name, (int)guiTable["trigger"], imagePath); + break; case MINIMAP:{ string minimapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + Map::getSingleton()->getMapName() + "/minimap.jpg"; button = new MinimapButton(pos, size, minimapPath); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index a1b85e2..8eaf240 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -50,6 +50,8 @@ namespace battleship{ TRADING_SCREEN, TRADE_OFFER, RESOURCE_AMMOUNT, + UNIT_STATE, + ORDER, MINIMAP }; enum ListboxType { diff --git a/orderButton.cpp b/orderButton.cpp new file mode 100644 index 0000000..567c0b6 --- /dev/null +++ b/orderButton.cpp @@ -0,0 +1,43 @@ +#include "orderButton.h" +#include "gameManager.h" +#include "activeGameState.h" +#include "player.h" +#include "unit.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + OrderButton::OrderButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int oid) : + Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), + orderId(oid) + {} + + void OrderButton::onClick(){ + Player *player = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE))->getPlayer(); + vector units = player->getSelectedUnits(); + + if(orderId > -1){ + switch(Order::TYPE(orderId)){ + case Order::TYPE::EJECT: + { + for(Unit *unit : units) + unit->receiveOrder(Order(Order::TYPE::EJECT, vector{}), false); + + break; + } + default: + { + break; + } + } + } + else + for(Unit *unit : units) + unit->halt(); + } +} diff --git a/orderButton.h b/orderButton.h new file mode 100644 index 0000000..fa05fc0 --- /dev/null +++ b/orderButton.h @@ -0,0 +1,16 @@ +#ifndef ORDER_BUTTON_H +#define ORDER_BUTTON_H + +#include + +namespace battleship{ + class OrderButton : public vb01Gui::Button{ + public: + OrderButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int); + void onClick(); + private: + int orderId; + }; +} + +#endif diff --git a/stateToggleButton.cpp b/stateToggleButton.cpp new file mode 100644 index 0000000..116a8a4 --- /dev/null +++ b/stateToggleButton.cpp @@ -0,0 +1,40 @@ +#include "stateToggleButton.h" +#include "gameManager.h" +#include "activeGameState.h" +#include "player.h" +#include "unit.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : + Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) {} + + void StateToggleButton::onClick(){ + const int NUM_STATES = 3; + int numUnitsByState[NUM_STATES]{0, 0, 0}; + + Player *player = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE))->getPlayer(); + vector units = player->getSelectedUnits(); + + for(Unit *unit : units) + numUnitsByState[(int)unit->getState()]++; + + int maxId = 0, maxNum = numUnitsByState[maxId]; + + for(int i = 0; i < NUM_STATES; i++) + if(maxNum < numUnitsByState[i]){ + maxId = i; + maxNum = numUnitsByState[maxId]; + } + + Unit::State nextState = (maxId + 1 == NUM_STATES ? Unit::State(0) : Unit::State(maxId + 1)); + + for(Unit *unit : units) unit->setState(nextState); + } +} diff --git a/stateToggleButton.h b/stateToggleButton.h new file mode 100644 index 0000000..1303468 --- /dev/null +++ b/stateToggleButton.h @@ -0,0 +1,15 @@ +#ifndef STATE_TOGGLE_BUTTON_H +#define STATE_TOGGLE_BUTTON_H + +#include + +namespace battleship{ + class StateToggleButton : public vb01Gui::Button{ + public: + StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string); + void onClick(); + private: + }; +} + +#endif diff --git a/unit.h b/unit.h index a02d90b..ecd2ea5 100755 --- a/unit.h +++ b/unit.h @@ -53,7 +53,7 @@ namespace battleship{ std::vector targets; Order(){} - Order(TYPE t, std::vector targ, vb01::Vector3 dir, int lid = -1, bool pa = true) : type(t), playerAssigned(pa), lineId(lid), targets(targ), direction(dir){} + Order(TYPE t, std::vector targ, vb01::Vector3 dir = vb01::Vector3::VEC_ZERO, int lid = -1, bool pa = true) : type(t), playerAssigned(pa), lineId(lid), targets(targ), direction(dir){} }; enum class MoveDir {LEFT, UP, FORW}; @@ -138,6 +138,7 @@ namespace battleship{ void initLosLight(); void destroyLosLight(); inline void setState(State s){state = s;} + inline State getState(){return state;} inline Engineer* toEngineer(){return (Engineer*)this;} inline Structure* toStructure(){return (Structure*)this;} inline Factory* toFactory(){return (Factory*)this;} From cf00b0f9ceb9cc5ac5c1c852da7c5d3b9f1671db Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 5 Apr 2025 16:15:37 +0300 Subject: [PATCH 4/8] rendering the correct order cursor icon depending on game object hovered over --- Assets/Scripts/Gui/activeGameState.lua | 5 + Assets/Scripts/Gui/tradingCenterCommands.lua | 39 ------ Assets/Textures/Icons/Cursors/hack.png | Bin 0 -> 2377 bytes Assets/Textures/Icons/Cursors/noGarrison.png | Bin 0 -> 1420 bytes Assets/Textures/Icons/Cursors/noGarrison.svg | 63 ++++++++++ Assets/Textures/Icons/Cursors/noHack.png | Bin 0 -> 3334 bytes Assets/Textures/Icons/Cursors/noHack.svg | 92 ++++++++++++++ Assets/Textures/Icons/Cursors/noSupply.png | Bin 0 -> 3174 bytes Assets/Textures/Icons/Cursors/noSupply.svg | 96 +++++++++++++++ Assets/Textures/Icons/Cursors/supply.png | Bin 0 -> 1398 bytes activeGameState.cpp | 123 ++++++++++++++----- activeGameState.h | 23 ++-- inGameAppState.cpp | 2 +- orderButton.cpp | 22 +++- 14 files changed, 387 insertions(+), 78 deletions(-) delete mode 100644 Assets/Scripts/Gui/tradingCenterCommands.lua create mode 100644 Assets/Textures/Icons/Cursors/hack.png create mode 100644 Assets/Textures/Icons/Cursors/noGarrison.png create mode 100644 Assets/Textures/Icons/Cursors/noGarrison.svg create mode 100644 Assets/Textures/Icons/Cursors/noHack.png create mode 100644 Assets/Textures/Icons/Cursors/noHack.svg create mode 100644 Assets/Textures/Icons/Cursors/noSupply.png create mode 100644 Assets/Textures/Icons/Cursors/noSupply.svg create mode 100644 Assets/Textures/Icons/Cursors/supply.png diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index ff32bd7..3cabdbe 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -13,6 +13,11 @@ resIconBasePath = 'Icons/Resources/' pointerTex = 'pointer.png' attackTex = 'attack.png' garrisonTex = 'garrison.png' +supplyTex = 'supply.png' +hackTex = 'hack.png' +noGarrisonTex = 'noGarrison.png' +noSupplyTex = 'noSupply.png' +noHackTex = 'noHack.png' gui = { { diff --git a/Assets/Scripts/Gui/tradingCenterCommands.lua b/Assets/Scripts/Gui/tradingCenterCommands.lua deleted file mode 100644 index 4a4dbda..0000000 --- a/Assets/Scripts/Gui/tradingCenterCommands.lua +++ /dev/null @@ -1,39 +0,0 @@ -res = graphics.resolution -Size = {x = 70, y = 70} -margin = 10 -sz = {x = Size.x - margin, y = Size.y - margin} - -gui = { - { - pos = {x = res.x - Size.x, y = res.y - Size.y, z = 0}, - size = sz, - name = 'Buy ref', - guiType = GuiType.BUTTON, - buttonType = ButtonType.BUY_REFINEDS, - trigger = 73, - }, - { - pos = {x = res.x - 2 * Size.x, y = res.y - Size.y, z = 0}, - size = sz, - name = 'Sell ref', - guiType = GuiType.BUTTON, - buttonType = ButtonType.SELL_REFINEDS, - trigger = 79, - }, - { - pos = {x = res.x - Size.x, y = res.y - 2 * Size.y, z = 0}, - size = sz, - name = 'Buy rsch', - guiType = GuiType.BUTTON, - buttonType = ButtonType.BUY_RESEARCH, - trigger = 75, - }, - { - pos = {x = res.x - 2 * Size.x, y = res.y - 2 * Size.y, z = 0}, - size = sz, - name = 'Sell rsch', - guiType = GuiType.BUTTON, - buttonType = ButtonType.SELL_RESEARCH, - trigger = 76, - } -} diff --git a/Assets/Textures/Icons/Cursors/hack.png b/Assets/Textures/Icons/Cursors/hack.png new file mode 100644 index 0000000000000000000000000000000000000000..d096ca81bad0f813a403a8ed602876bd798f115d GIT binary patch literal 2377 zcmV-P3AXl$P)=r=_#0k=F3Z&g-k$uoV zA_>~Wa5hDdKcMUGx@>@K0we)~*r^jm){IrVl17&1Q{)V1hUC5H>4GC8ADS8K!;td; z1bN^0<>m7`=e+kEP_}uLB>i*c_4a?Lh`XU%N%DK+NvWHZy_XkCf(Xb5F^05U%I}RQ z<;6-8ALNB*Lm*;LqSY*yij8qzUYtqd)_9^ux#WpWv^5)oxAP*LsU-3Kc%oLh{BIDb^L^TY{#g zvg~!E%T@T9#TR6+7-hma(!l1=CBJ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{6`&P3=476cfTFl|Afpau7f|N1x{b;1$h*fF zS(bhMw7L^PB!x6hzf~%gTF=hf&334M{q#=2(zUr}Gb4md$@M)*fHIUa!+`xBvdQ z{IMYIcKeNLwffv=51o4t8TaZVyDx2>33tl2U4rm-fT9T zpW4}YsAjX7HX4mLemC|JNSdbSvn+d!Px)*dN!@Pu3t5(3dKmZ!q|s=6Z*Fd`@qBze zzM9SE+|10(zdpPU0Q2+n=dvvO5>R?>&K^^eLbu!fQoG&$GdKdNR;%A>wOW5Nv++=A znl|h8`nLeo>-82E7Z-1|+wD(%lRrv3J3IZmckh0#)ND52ID7W&=XLb&#h;q0)oQul v@7J}wyu8tBwPqw0&)d|K$abmU?~nc;V`8`UZ9sC300000NkvXXu0mjfw8x14 literal 0 HcmV?d00001 diff --git a/Assets/Textures/Icons/Cursors/noGarrison.png b/Assets/Textures/Icons/Cursors/noGarrison.png new file mode 100644 index 0000000000000000000000000000000000000000..fa4ff20ce2b144b3613503524758ec1e2235946d GIT binary patch literal 1420 zcmV;71#|j|P)P000>X1^@s6#OZ}&00009a7bBm0001Q z0001Q0r8^TLjV8(8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H11sO?1 zK~zYIjh0(%Tvru_zqQXE+hdQ-oMR^racrwndFTU|B+3PfP!$PP0vZHWF9cGWR*Ikx z1q2o3g*JjxDncI8RE0<+ts2p)s!$q`N@>~zh$^s?kc1dfAXH!{4Ng20pEI^+?3wfP z;7d|x#&D$da`syPzt>)S{d<`t8h&QYaTsg@Hal#+U#U|$ zhn@t|MI7nO#A}aB@063g|1oGQFm9>)0!DTg&-@&SNTSU4IP@CN2U{gk&suxld?nXE zq8txs zrIojz1JKOh_7~i9ZNi=foMhj~6|29vRxG8?^aQXnj{GJEYzC$#GPPgV1J8E<d{D|*ul9GrT%t4$N`mCWsxZ&g;_Q!i}Us7k<~$<{iF9Jmd}>%oVrP4{L8K4zSg~5Ef4%a zI-V>Q2d)cr*_m-sXjMZ$GfVQpzMC|*Hn!aKmh3ZJR_!$!nov8X#m)G zWtp|tbKKv#@g!ysOp#6R&F(F}6ZC=0-;(Pa9BS`B@t17(Ge4~tcX_$xfb}N*!C`h7 zXl_Y^+ZQ{QI-9oNm7Z8VW1a_Fce~Smb@yy?nO>~*7OZ7uIx(=f9!a(qd_xz1Jo4z3^IK5m@9#bE>GM+)yPvF=MUv0lXRsQxok-L3TH}+* zpNKL;vn%MDP6ng-0tprs34w z*ANEOe44%vEC{9~)smNYB9*EWhrciB+WTVWlCbIi)N~y1X=-<5$8=3a7VjpG_-GRP zKh0+2PbE=s_vkWm3zDDz`ofztx{O>B1$WQMy5h(WPDZR+jM;EnNuta)q(_;ZRw}@N zVgH7-04@^h1J(o0zzAkL+Y2+#{$JC|BC_T<^0y&vHrYCi9_HsRaY3d*%no-Hs>ha^ ayZ#Gg*9q0Ca_4XW0000 + + + + + + + + + + + diff --git a/Assets/Textures/Icons/Cursors/noHack.png b/Assets/Textures/Icons/Cursors/noHack.png new file mode 100644 index 0000000000000000000000000000000000000000..9b01432fbd72fb706a5a1666b4c8651891002131 GIT binary patch literal 3334 zcmV+h4f*nkP)`vELULxl^=xI zt}=;YNQ6TCK(;ZI!9@ZtLyTpx9arqQ9N}^~AQG!665AjoKoZegTJ2+IS3CQh>Aqin z%wuO}XLeVwuWD-g+;h&o=XCcy_uO-vl5im~nc|Y7b#6A~H4?4_umV5|K)5V24k1V4 zFo^f8)o(l}_|J|ZoxBj^^L!i`PH?FUcN2h50$6*F-RuMKeV6_V9a$YeS6j}>k@0wF zgNQAHZU^9;>);It2>y`ZS0cITx6fAjtQ;AOGA-A66y#CYfsE}8+ zhRnyjyFh&nrHEI-$w2bk1u?t@Cepk*@ZJ9g z(N@!(n{xeS=>d&3(`oJq>E+|@Pf_%v9B8VBK*qt4^qdg6n)!6Pf zHjE|R+v=UrGtr#C1ps8&=dBHA0i+~&B!>a{5FJ5InGPg+fJh<>KoUX#Kq3o)0z80n zs4N5{z;nc4$CD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Di9}*n zm4715UI1&#q>K~nGUfA$N&;qrqIYMbVt04<6QNLO){DMzWDuV^eYCFabXzhiE7oAd4V||W6{J$B^_fg&CJ2#)@aY>Qhmz+ zKu1=`3I3oWOmHhmCX>laQmNE6wH+@iOyl7r@1osSt3>cge0ljQ><>qAF_26quT3Np zOF+*}(c4#kR{!E2m0G?WM z1%4ZCx!9jK!r^dlcX#(!@(J(LASxl*lH6XAsX7wLO}`E4JE%(Ov2}^qMwBO2n=G~- zc^69xQ+0!Ucky!kDv`m(#@bldMl01!d_CKlo!(cW>W{sG;0pk9Wk%w`p%cAEf-B*{ zBk$p=iF}>-&g3HeYkJ8=G`|E#!b3wRdd*A~Gz&j?s8(iHH9ntkKL+sMQGODyMY_-U z5I#6QT31|tqrG!%OJ>;#9~Tz}z}D=EMIRbJQ`t8O(rwXU|KDomnjR~RCEO<~)$bN~ zE!yq>DGqCD4w>@@$$Z@14&bk6n()oeZ1Jj z2LRWEBCs|C!$4qKX@oQs_a5-JExCo z#u9C70sXC@JJ94n^&H^?e39h#+7)}DIIqu~%F*SMC>=}8Rpn_30dKPOnNu|ZJQtjo zBej@FbFm*d8!27`Viigso+SxH$_9@E$O1S7VZW&VaopgQ$iM>1qYJ?Q1HdrK_sXc> QSpWb407*qoM6N<$g8MZ`TmS$7 literal 0 HcmV?d00001 diff --git a/Assets/Textures/Icons/Cursors/noHack.svg b/Assets/Textures/Icons/Cursors/noHack.svg new file mode 100644 index 0000000..e919fa9 --- /dev/null +++ b/Assets/Textures/Icons/Cursors/noHack.svg @@ -0,0 +1,92 @@ + + + + diff --git a/Assets/Textures/Icons/Cursors/noSupply.png b/Assets/Textures/Icons/Cursors/noSupply.png new file mode 100644 index 0000000000000000000000000000000000000000..f8bacac27086f6799b8adda3199be2f5027a4689 GIT binary patch literal 3174 zcmV-s44LzZP)L0%%TAPM_mce9(#&iCE^k$tlpk`Vm; zH+Sybxxf8pXYRc-#LVak1p827SXV0*q8piUHGqKt`T)p|sI-9LBEr`o9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Supply.svg new file mode 100644 index 0000000..0818b29 --- /dev/null +++ b/Assets/Textures/Icons/Cursors/noSupply.svg @@ -0,0 +1,96 @@ + + + + diff --git a/Assets/Textures/Icons/Cursors/supply.png b/Assets/Textures/Icons/Cursors/supply.png new file mode 100644 index 0000000000000000000000000000000000000000..17b1bb656ce1d246167a6c41c2b266ffff8bd4f1 GIT binary patch literal 1398 zcmV-+1&R8JP)o#Pq_5Xq+~t0R=NH%MzB96tpFwX%GF;9#84tX}{fAhpyOmvOSmY z_rA~jJm34B^L+?o4F4w@8XB7R?Ag;}Hk%DPoo#|N%myY_3*z2C(MLa3~#r>A4*&YhhM!+cO%TWcXnQttQrIgaBX8jVT~ z2E$g0qKHztL!r>02M!$g)Z_64iqcZ55u?#)QmfU&dc9u9FieG3tIhB{ALlr(OrcOH zOeT};ZM$6x9zTA3v#+o3GmLSzP;N;^5JKg4yWOtW>)Ug&g@uK{wr$%8sZ{#jztsCS z;44?IoI7#i#CL@fOB(s5OP9vhn*adVzJ0s;!Gj0!Y&M%HRb>%CeSLj{0|NtJ6ih63 zB1exN{qfMDL*D~{DBt?++qXSdtCcQIXJKTsSv)&CoA!FWEX%SPK@e_?jEsEqW?oT7 z`uqF$4-E~C5(H7TQH~%8cz%99#xRWR9dzThwKWI^gBhRCmt0<67SidosI#+EN>LPg zX)Jd7^y#lIUc5M7l964zcI_A*9=<7)$qMc^%d$9=$>6%Wx`Ia*V+=gcr(e8yK|~^v zq}S_BMx#+dtJO*^7E6UhBH6H(=XuZI;9&2=hYwvv8BwWJmE+^%clCPxM}>st;B-2{ zXf(o`LgMi_gu`LrI1W4>4?KVV98@Y*nx<(~Utdoa%b$bW?Vhn(t)F0wQyUs-Y;5eH zDC#GJ!O+y--@k<Ul0XRMZ6F8&*zI;`YH9+G;~*Z71JCmyl}bS_ zmxIx0go=uaQg!FW#KgoeM~)mB%xgrW(I{;;+g-I<{b4S4=gu9kQmL#V2;!~hKaofP zMNy#B>0ZU|-@gy7t*syyi#J95dSHx`XU?4Yc4TDa!fQqlLWIp`yV26p()(u7=;-JZ zhGFyokarXqV-N%ZT3cKHu{Jq5348bM-9!t2Bauj~96o$_zv$%2ldpnevG_t)SJ#*M z3YwdntEQ)?mz7H8)_m(M%fjy6yYn`yudj#M*;&wPwVNRQb%;cwEd)U{yqd_tg9pDp zcI?wc|PtBS>9Bu&$x(P#=6y@bQzU^_ZGsu4o3y)09yR5%VPl4J@Y zRPd=_x7)#Dv8?!fzD1YIwKO#~<#ae4_b|qMsXB7_3-7)(>A%d>RsaA107*qoM6N<$ Eg75*MF#rGn literal 0 HcmV?d00001 diff --git a/activeGameState.cpp b/activeGameState.cpp index 8ae98c1..efdf7f4 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -28,6 +28,8 @@ #include "gameObjectFactory.h" #include "cameraController.h" #include "unitButton.h" +#include "extractor.h" +#include "resourceDeposit.h" #include "concreteGuiManager.h" using namespace vb01; @@ -75,12 +77,27 @@ namespace battleship{ string pt = SOL_LUA_VIEW["pointerTex"], at = SOL_LUA_VIEW["attackTex"], gt = SOL_LUA_VIEW["garrisonTex"], + st = SOL_LUA_VIEW["supplyTex"], + ht = SOL_LUA_VIEW["hackTex"], + ngt = SOL_LUA_VIEW["noGarrisonTex"], + nst = SOL_LUA_VIEW["noSupplyTex"], + nht = SOL_LUA_VIEW["noHackTex"], p1[]{basePath + pt}, p2[]{basePath + at}, - p3[]{basePath + gt}; + p3[]{basePath + gt}, + p4[]{basePath + st}, + p5[]{basePath + ht}, + p6[]{basePath + ngt}, + p7[]{basePath + nst}, + p8[]{basePath + nht}; pointerTex = new Texture(p1, 1, false); attackTex = new Texture(p2, 1, false); garrisonTex = new Texture(p3, 1, false); + supplyTex = new Texture(p4, 1, false); + hackTex = new Texture(p5, 1, false); + noGarrisonTex = new Texture(p6, 1, false); + noSupplyTex = new Texture(p7, 1, false); + noHackTex = new Texture(p8, 1, false); Root *root = Root::getSingleton(); Material *mat = new Material(root->getLibPath() + "gui"); @@ -115,13 +132,52 @@ namespace battleship{ Vector2 cursorPos = getCursorPos(); cursorNode->setPosition(Vector3(cursorPos.x, cursorPos.y, .8)); - bool canSelect = canSelectHoveredOnGameObj(); - bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); + if(mainPlayer->getNumSelectedUnits() > 0){ + bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); + bool gameObjUnit = (gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT); + bool gameObjTransport = (gameObjUnit && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0); + bool canGarrison = true; - if(controlPressed || (gameObjHoveredOn && !ownGameObj && gameObjHoveredOn->getType() == GameObject::Type::UNIT)) - cursorState = CursorState::ATTACK; - else - cursorState = CursorState::NORMAL; + if(gameObjUnit && gameObjTransport) + for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++) + if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){ + canGarrison = false; + break; + } + + bool supply = ( + gameObjUnit && + ((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR && + mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::RESOURCE_ROVER + ); + + if(!forceCursorState){ + if(gameObjUnit && gameObjTransport){ + orderPossible = (ownGameObj && canGarrison); + cursorState = CursorState::GARRISON; + } + else if(supply){ + orderPossible = (ownGameObj && ((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount()); + cursorState = CursorState::SUPPLY; + } + else if(gameObjUnit && !ownGameObj) + cursorState = CursorState::ATTACK; + else + cursorState = CursorState::NORMAL; + } + else{ + if(cursorState == CursorState::GARRISON) + orderPossible = (ownGameObj && gameObjTransport && canGarrison); + else if(cursorState == CursorState::SUPPLY) + orderPossible = (ownGameObj && supply && ((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount()); + else if(cursorState == CursorState::HACK) + orderPossible = (!ownGameObj && gameObjUnit && mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::ENGINEER); + else if(gameObjUnit) + cursorState = CursorState::ATTACK; + else + cursorState = CursorState::NORMAL; + } + } cursorNode->setVisible(cursorState != CursorState::NORMAL); Texture *tex = nullptr; @@ -131,7 +187,13 @@ namespace battleship{ tex = attackTex; break; case CursorState::GARRISON: - tex = garrisonTex; + tex = (orderPossible ? garrisonTex : noGarrisonTex); + break; + case CursorState::SUPPLY: + tex = (orderPossible ? supplyTex : noSupplyTex); + break; + case CursorState::HACK: + tex = (orderPossible ? hackTex : noHackTex); break; } @@ -435,6 +497,7 @@ namespace battleship{ } mainPlayer->issueOrder(type, destDir, targets, addOrder); + forceCursorState = false; this->targets.clear(); } @@ -541,29 +604,25 @@ namespace battleship{ } } else if(!isSelectionBox){ - bool canSelect = canSelectHoveredOnGameObj(); bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); - if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && ownGameObj && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0){ - bool canGarrison = true; - - for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++) - if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){ - canGarrison = false; - break; - } - - if(canGarrison) - issueOrder(Order::TYPE::GARRISON, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); + if(cursorState == CursorState::GARRISON){ + if(orderPossible) issueOrder(Order::TYPE::GARRISON, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); } - else if(gameObjHoveredOn && ownGameObj && ((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR && !controlPressed){ - issueOrder(Order::TYPE::SUPPLY, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + else if(cursorState == CursorState::SUPPLY){ + if(orderPossible) issueOrder(Order::TYPE::SUPPLY, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); } - else if(gameObjHoveredOn && (controlPressed || (!ownGameObj && gameObjHoveredOn->getType() == GameObject::Type::UNIT))) - issueOrder(Order::TYPE::ATTACK, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); - else if(controlPressed && !gameObjHoveredOn){ - castRayToTerrain(); - issueOrder(Order::TYPE::ATTACK, targets, shiftPressed); + else if(cursorState == CursorState::ATTACK){ + if(controlPressed && !gameObjHoveredOn){ + castRayToTerrain(); + issueOrder(Order::TYPE::ATTACK, targets, shiftPressed); + } + else{ + if(orderPossible) issueOrder(Order::TYPE::ATTACK, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); + } + } + else if(cursorState == CursorState::HACK){ + if(orderPossible) issueOrder(Order::TYPE::HACK, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); } else if(selectedUnits[0]->getUnitClass() == UnitClass::ENGINEER && ufCtr->isPlacingOnSurface()){ castRayToTerrain(); @@ -579,7 +638,7 @@ namespace battleship{ buildableStructSelected = false; } - else if(!canSelect){ + else if(!canSelectHoveredOnGameObj()){ if(targets.empty()) castRayToTerrain(); issueOrder(Order::TYPE::MOVE, targets, shiftPressed); @@ -609,6 +668,7 @@ namespace battleship{ } break; + /* case Bind::HACK: if(isPressed){ if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && gameObjHoveredOn->getPlayer()->getTeam() != mainPlayer->getTeam()) @@ -616,6 +676,7 @@ namespace battleship{ break; } + */ case Bind::SHIFT_SUB_DEPTH: ufCtr->toggleFrameTransformations(false, false, isPressed); break; @@ -644,7 +705,10 @@ namespace battleship{ break; //TODO reimplement submarine diving mechanic case Bind::LEFT_CONTROL: - controlPressed = isPressed; + if(isPressed) cursorState = CursorState::ATTACK; + + forceCursorState = isPressed; + controlPressed = isPressed; break; case Bind::LEFT_SHIFT: { @@ -694,6 +758,7 @@ namespace battleship{ break; case Bind::DESELECT_STRUCTURE: + forceCursorState = false; buildableStructSelected = false; ufCtr->toggleFrameTransformations(false, false, false); ufCtr->removeGameObjectFrames(); diff --git a/activeGameState.h b/activeGameState.h index 0b84ac6..579e50e 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -24,6 +24,14 @@ namespace battleship{ class ActiveGameState : public gameBase::AbstractAppState { public: + enum CursorState{ + NORMAL, + ATTACK, + GARRISON, + SUPPLY, + HACK + }; + ActiveGameState(GuiAppState*, int); ~ActiveGameState(); void onAttached(); @@ -32,6 +40,8 @@ namespace battleship{ void onAction(int, bool); void onAnalog(int, float); void onRawMouseWheelScroll(bool); + inline CursorState getCursorState(){return cursorState;} + inline void setCursorState(CursorState cs){this->cursorState = cs;} inline void addButton(vb01Gui::Button *b){buttons.push_back(b);} inline std::vector getButtons(){return buttons;} inline Player* getPlayer(){return mainPlayer;} @@ -39,14 +49,9 @@ namespace battleship{ inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;} inline bool isBuildableStructSelected(){return buildableStructSelected;} inline float getDepth(){return depth;} + inline void setForceCursorState(bool force){this->forceCursorState = force;} + inline bool isForceCursorState(){return forceCursorState;} private: - enum CursorState{ - NORMAL, - ATTACK, - GARRISON, - SUPPLY - }; - bool selectedUnitsAmongst(std::vector); void updateGameObjHoveredOn(); void initCursor(); @@ -83,12 +88,14 @@ namespace battleship{ bool buildableStructSelected = false; bool selectingPatrolPoints = false; bool selectingDestOrient = false; + bool forceCursorState = false; + bool orderPossible = false; int playerId, zooms = 0; const int NUM_MAX_ZOOMS = 10; float depth = 1; vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0; vb01::Node *cursorNode = nullptr; - vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr; + vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr; }; } diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 232a947..ea67c27 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -100,7 +100,7 @@ namespace battleship{ void InGameAppState::onAction(int bind, bool isPressed) { switch((Bind)bind){ case Bind::TOGGLE_MAIN_MENU: - if(isPressed && !GameObjectFrameController::getSingleton()->isPlacingOnSurface()) + if(isPressed && !(GameObjectFrameController::getSingleton()->isPlacingOnSurface() || activeState->isForceCursorState())) Game::getSingleton()->togglePause(); break; } diff --git a/orderButton.cpp b/orderButton.cpp index 567c0b6..fe92653 100644 --- a/orderButton.cpp +++ b/orderButton.cpp @@ -18,7 +18,8 @@ namespace battleship{ {} void OrderButton::onClick(){ - Player *player = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE))->getPlayer(); + ActiveGameState *activeState = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE)); + Player *player = activeState->getPlayer(); vector units = player->getSelectedUnits(); if(orderId > -1){ @@ -32,6 +33,25 @@ namespace battleship{ } default: { + ActiveGameState::CursorState cs; + + switch((Order::TYPE)orderId){ + case Order::TYPE::ATTACK: + cs = ActiveGameState::CursorState::ATTACK; + break; + case Order::TYPE::GARRISON: + cs = ActiveGameState::CursorState::GARRISON; + break; + case Order::TYPE::SUPPLY: + cs = ActiveGameState::CursorState::SUPPLY; + break; + case Order::TYPE::HACK: + cs = ActiveGameState::CursorState::HACK; + break; + } + + activeState->setCursorState(cs); + activeState->setForceCursorState(true); break; } } From 73c7c3b96f1ac62f90a1ef64cc075082b1974956 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 5 Apr 2025 16:41:09 +0300 Subject: [PATCH 5/8] Rearranged active state GUI --- Assets/Scripts/GameObjects/Units/unitData.lua | 1 + Assets/Scripts/Gui/activeGameState.lua | 30 ++++++------------- Assets/Scripts/Gui/unitGui.lua | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index f7808fe..e2c7d88 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -353,6 +353,7 @@ units = { }, { weapons = {}, + abilityButtons = {{buttonType = ButtonType.ORDER, name = 'Supply', orderType = OrderType.SUPPLY}}, unitClass = UnitClass.RESOURCE_ROVER, unitType = UnitType.HOVER, armor = {ArmorType.CAST}, diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 3cabdbe..83a4dcc 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -6,7 +6,7 @@ s = 40 eyeIcon = 'eye.png' refIcon = 'refineds.png' minimapSize = {x = 200, y = 200} -minimapPos = {x = res.x - minimapSize.x, y = 0, z = .9} +minimapPos = {x = 0, y = res.y - minimapSize.y, z = .9} resTextScale = {x = .5, y = .5} resIconBasePath = 'Icons/Resources/' @@ -43,7 +43,7 @@ gui = { guiType = GuiType.TEXT, name = 'wealth', text = '', - pos = {x = 200 + s, y = s, z = 0}, + pos = {x = s, y = 2 * s, z = 0}, scale = resTextScale, font = 'batang.ttf', fontFirstChar = 0, @@ -54,7 +54,7 @@ gui = { guiType = GuiType.TEXT, name = 'research', text = '', - pos = {x = 400 + s, y = s, z = 0}, + pos = {x = s, y = 3 * s, z = 0}, scale = resTextScale, font = 'batang.ttf', fontFirstChar = 0, @@ -71,14 +71,14 @@ gui = { { guiType = GuiType.GUI_RECTANGLE, name = 'wealth', - pos = {x = 200, y = 0, z = 0}, + pos = {x = 0, y = 1 * s, z = 0}, size = {x = s, y = s}, imagePath = resIconBasePath .. 'wealth.png', }, { guiType = GuiType.GUI_RECTANGLE, name = 'research', - pos = {x = 400, y = 0, z = 0}, + pos = {x = 0, y = 2 * s, z = 0}, size = {x = s, y = s}, imagePath = resIconBasePath .. 'research.png', }, @@ -98,26 +98,14 @@ gui = { buttonType = ButtonType.PLAYER_TRADE, name = 'Trade', guiScreen = 'tradingHub.lua', - pos = {x = res.x - Size.x, y = 200, z = 0}, - size = Size, + pos = {x = minimapSize.x, y = res.y - minimapSize.y, z = 0}, + size = {x = Size.x, y = minimapSize.y - .75 * sz}, trigger = 10 }, { guiType = GuiType.GUI_RECTANGLE, - pos = {x = res.x - sz, y = res.y - sz, z = 0}, - size = {x = sz, y = sz}, - color = {x = .6, y = .6, z = .6, w = .4} - }, - { - guiType = GuiType.GUI_RECTANGLE, - pos = {x = 0, y = res.y - sz, z = 0}, - size = {x = sz, y = sz}, - color = {x = .6, y = .6, z = .6, w = .4} - }, - { - guiType = GuiType.GUI_RECTANGLE, - pos = {x = sz, y = res.y - .75 * sz, z = 0}, - size = {x = res.x - 2 * sz, y = sz * .75}, + pos = {x = minimapPos.x, y = res.y - .75 * sz, z = 0}, + size = {x = res.x - minimapPos.x, y = sz * .75}, color = {x = .6, y = .6, z = .6, w = .4} }, } diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua index db278e4..2fb8d74 100644 --- a/Assets/Scripts/Gui/unitGui.lua +++ b/Assets/Scripts/Gui/unitGui.lua @@ -2,7 +2,7 @@ res = graphics.resolution sz = 210 resTextScale = {x = .5, y = .5} -buttonInitPos = {x = sz, y = res.y - .75 * sz, z = 0} +buttonInitPos = {x = sz, y = res.y - .65 * sz, z = 0} buttonSize = {x = 50, y = 50} buttonSpace = {x = 10, y = 10} From ae87aedb5555e46dd9619a87f37667ffcc71d743 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 6 Apr 2025 16:50:25 +0300 Subject: [PATCH 6/8] visuals for the unit state toggle button --- Assets/Scripts/Gui/unitGui.lua | 5 +- Assets/Textures/Icons/Buttons/chase.png | Bin 0 -> 843 bytes Assets/Textures/Icons/Buttons/holdFire.png | Bin 0 -> 549 bytes Assets/Textures/Icons/Buttons/standGround.png | Bin 0 -> 979 bytes Assets/Textures/Icons/Buttons/state.svg | 98 ++++++++++++++++++ stateToggleButton.cpp | 39 ++++++- stateToggleButton.h | 4 + 7 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 Assets/Textures/Icons/Buttons/chase.png create mode 100644 Assets/Textures/Icons/Buttons/holdFire.png create mode 100644 Assets/Textures/Icons/Buttons/standGround.png create mode 100644 Assets/Textures/Icons/Buttons/state.svg diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua index 2fb8d74..5a1f44f 100644 --- a/Assets/Scripts/Gui/unitGui.lua +++ b/Assets/Scripts/Gui/unitGui.lua @@ -15,6 +15,7 @@ function generateButton(numGui, buttonData) size = buttonSize, guiType = GuiType.BUTTON, name = buttonData.name, + imagePath = buttonData.imagePath, buttonType = buttonData.buttonType, trigger = (buttonData.trigger or -1), orderType = buttonData.orderType, @@ -30,10 +31,10 @@ end function generateGui(unitId) local gui = {} vehicleButtonData = { - {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'}, + {buttonType = ButtonType.UNIT_STATE, imagePath = 'Icons/Buttons/chase.png'}, {buttonType = ButtonType.ORDER, orderType = OrderType.GARRISON, name = 'Garrison'}, {buttonType = ButtonType.ORDER, orderType = OrderType.PATROL, name = 'Patrol'}, - {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'} + {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'}, } structureButtonData = { {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'}, diff --git a/Assets/Textures/Icons/Buttons/chase.png b/Assets/Textures/Icons/Buttons/chase.png new file mode 100644 index 0000000000000000000000000000000000000000..75ec3fcc541471aa4a7cb8e92337da5b72cbe1e6 GIT binary patch literal 843 zcmV-R1GM~!P)P000^Y1^@s6LVfqm00009a7bBm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I(PDQAg0zD-}gz= z6s>j5Tr3u}+ie`jVKf>cgrF!2eBZD7;6d7w4Ef0xL&V~z;mUR-EQ{+;JPkZmbH^45ik9C2qCa- nyOdH^U(eP{gFjn;<>~qf^hnjdO7Xk(00000NkvXXu0mjfp|tm) literal 0 HcmV?d00001 diff --git a/Assets/Textures/Icons/Buttons/standGround.png b/Assets/Textures/Icons/Buttons/standGround.png new file mode 100644 index 0000000000000000000000000000000000000000..4a56b92669c1138da5f3e79250d22f9f55127494 GIT binary patch literal 979 zcmV;^11$WBP)P000^Y1^@s6LVfqm00009a7bBm000-g z000-g0j5gPPXGV_8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H117Jx+ zK~zYIotE8hs#p}q|C<3n08y!cjgBeyBW7lL(KP90dwVi3GOsc3F^|)$CQVKgGi_=b zPkL&k7%Iv}ilySYXe0uD^ql_{i@n$Wt;Jq@ZOHlg`9D~rAPCsU$Hx=LasKpue=iI} zDGWoNVHl5P*_UiK`(2jhuZ>3I|J&Q!zlX!&7mnlltyb&5QmJGu)*%-c7xPsB(=^fT zcJcQ1wl0Q9f*`>2Jj~}GOVw&M92^`(e4)u?60?2ZkJ(Jpq1)~L z6kwGW87&mc#C2WtdcBlWCX<1tX%GYf9LFID0#HgZ7z_{u!B%JtVi-m$ih8{cUDv@d z@uW3PL$ldLr_+IHnj0Z8Psed$gOVg+e}6v(h@2S)tyT+?Bz+!|tfXzu3n_{cvpJ4i z56NUQu|Z1dry!L|1uXmV{m&>gTA_frz0rh%4RmNc$ z!m=z_)<>rxgg_KU6bc0ti$%z?9DS~>5CCX4n+SqnV_DAUb5Ke_DMi2E2g5K>6a~7j zBb&{p=Kr?0xA*Vz3qlAgl?r&Chv#{pI&Aa#9FxfehG8I|&u`w7WvQwPRaG$_k73(3 zMxzm2*Trl$TML`bX1Ke%1Iw}~m&@BB3l)n+6pO{k_B;=iQaFwS+qUug`kKnB)9K*s z>?|sd6eJA8wI>_^c%BE(^UyR60ASlT9v&Xxd0sTf_kGy54Ox}}EFDJIb#Zldh0DuJ zwA*cjVYn?x06@81#_{oSs-%}&R0Mf?dW!CW;c$q-VDKpj@Nq_xRkd6&5hQuh^!xo( zM_wn-^Dv!GWABzbLqU@coBtINLU4F^7|Q}!+LLOv z8qs;4N2Af$*xr+pBnc-cC)nNHO~aRe?kvlyQc6`#(;j%9_ktkcdcEEsqtWQE>2&)0 z`}=z(3`3p}5-<$oaU5sn^Z9RzqI|7ZtKZiJ@B@mGY5)ARM5q7&002ovPDHLkV1n2f By*2;< literal 0 HcmV?d00001 diff --git a/Assets/Textures/Icons/Buttons/state.svg b/Assets/Textures/Icons/Buttons/state.svg new file mode 100644 index 0000000..9eba101 --- /dev/null +++ b/Assets/Textures/Icons/Buttons/state.svg @@ -0,0 +1,98 @@ + + + + diff --git a/stateToggleButton.cpp b/stateToggleButton.cpp index 116a8a4..52b09af 100644 --- a/stateToggleButton.cpp +++ b/stateToggleButton.cpp @@ -12,10 +12,12 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : - Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) {} + StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) { + updateStateId(); + toggleImage(); + } - void StateToggleButton::onClick(){ + void StateToggleButton::updateStateId(){ const int NUM_STATES = 3; int numUnitsByState[NUM_STATES]{0, 0, 0}; @@ -33,8 +35,37 @@ namespace battleship{ maxNum = numUnitsByState[maxId]; } - Unit::State nextState = (maxId + 1 == NUM_STATES ? Unit::State(0) : Unit::State(maxId + 1)); + currStateId = maxId; + } + + void StateToggleButton::toggleImage(){ + string imgPath = ""; + + switch(Unit::State(currStateId)){ + case Unit::State::HOLD_FIRE: + imgPath = "holdFire.png"; + break; + case Unit::State::CHASE: + imgPath = "chase.png"; + break; + case Unit::State::STAND_GROUND: + imgPath = "standGround.png"; + break; + } + + setImage(GameManager::getSingleton()->getPath() + "Textures/Icons/Buttons/" + imgPath); + } + + void StateToggleButton::onClick(){ + const int NUM_STATES = 3; + Unit::State nextState = (currStateId + 1 == NUM_STATES ? Unit::State(0) : Unit::State(currStateId + 1)); + + Player *player = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE))->getPlayer(); + vector units = player->getSelectedUnits(); for(Unit *unit : units) unit->setState(nextState); + + updateStateId(); + toggleImage(); } } diff --git a/stateToggleButton.h b/stateToggleButton.h index 1303468..774e087 100644 --- a/stateToggleButton.h +++ b/stateToggleButton.h @@ -9,6 +9,10 @@ namespace battleship{ StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string); void onClick(); private: + void updateStateId(); + void toggleImage(); + + int currStateId, x; }; } From 1ef3ecbb2ab83f658740811ff47b1e3efd1bc2b3 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 6 Apr 2025 16:54:40 +0300 Subject: [PATCH 7/8] updated vb01 --- external/vb01 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/vb01 b/external/vb01 index 8938958..c8538aa 160000 --- a/external/vb01 +++ b/external/vb01 @@ -1 +1 @@ -Subproject commit 89389589de8b1ef87483b9974aa87f083a3ab476 +Subproject commit c8538aaa40c7cc18fc627eefc6d1ffd3ab497bdc From 8a2cc97252c1b4ec324746b278907c980f5ccf8e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Mon, 7 Apr 2025 20:42:59 +0300 Subject: [PATCH 8/8] removed states button for structures --- Assets/Scripts/Gui/unitGui.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua index 5a1f44f..deb6fbf 100644 --- a/Assets/Scripts/Gui/unitGui.lua +++ b/Assets/Scripts/Gui/unitGui.lua @@ -37,7 +37,6 @@ function generateGui(unitId) {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'}, } structureButtonData = { - {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'}, {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'} }