implemented buildable structure selection buttons

This commit is contained in:
devZoGok
2023-09-23 09:59:47 +03:00
parent 21db6584e0
commit 85811fca7c
9 changed files with 45 additions and 33 deletions
+14
View File
@@ -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
}
}
+2 -1
View File
@@ -22,7 +22,8 @@ ButtonType = {
RESUME = 18,
CONSOLE = 19,
MAIN_MENU = 20,
CONSOLE_COMMAND_OK = 21
CONSOLE_COMMAND_OK = 21,
BUILD = 22
}
ListboxType = {
+2 -1
View File
@@ -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})
+14 -25
View File
@@ -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);
+1
View File
@@ -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;
+4
View File
@@ -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};
+2 -1
View File
@@ -31,7 +31,8 @@ namespace battleship{
RESUME,
CONSOLE_SCREEN,
MAIN_MENU,
CONSOLE_COMMAND_OK
CONSOLE_COMMAND_OK,
BUILD
};
enum ListboxType {
CONTROLS,
+6 -5
View File
@@ -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();
}
}
}