technology research button

This commit is contained in:
devZoGok
2024-03-09 14:49:04 +02:00
parent aaf1ee61b9
commit feef91c999
12 changed files with 70 additions and 10 deletions
@@ -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',
},
+2 -1
View File
@@ -27,7 +27,8 @@ ButtonType = {
LAND_FACTORY_TRAIN = 23,
NAVAL_FACTORY_TRAIN = 24,
FORT_TRAIN = 25,
STATISTICS = 26
STATISTICS = 26,
RESEARCH = 27
}
ListboxType = {
@@ -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,
}
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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;
}
+4
View File
@@ -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};
+2 -1
View File
@@ -41,7 +41,8 @@ namespace battleship{
LAND_FACTORY_TRAIN,
NAVAL_FACTORY_TRAIN,
FORT_TRAIN,
STATISTICS
STATISTICS,
RESEARCH
};
enum ListboxType {
CONTROLS,
+24
View File
@@ -0,0 +1,24 @@
#include "researchButton.h"
#include "activeGameState.h"
#include "researchStruct.h"
#include <stateManager.h>
#include <solUtil.h>
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<Unit*> selUnits = player->getSelectedUnits(), researchStructs = player->getUnitsById(unitId);
for(Unit *rs : researchStructs)
if(find(selUnits.begin(), selUnits.end(), rs) != selUnits.end())
((ResearchStruct*)rs)->appendToQueue(techId);
}
}
+16
View File
@@ -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
+1 -1
View File
@@ -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<sol::table> 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];
+2 -2
View File
@@ -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<Order> orders;
std::string buildableUnitGuiScreen = "";
std::string guiScreen = "";
int health, maxHealth, playerId, lenHpBar = 200;
vb01::s64 orderLineDispTime = 0, lastFireTime = 0;
float lineOfSight;
-1
View File
@@ -11,7 +11,6 @@ namespace battleship{
UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int);
protected:
int unitId;
std::vector<Unit*> units;
};
}