mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
tech research graph screen
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
res = graphics.resolution
|
||||
Size = {x = res.x * .5, y = res.y * .5}
|
||||
techButtonSize = {x = 50, y = 50}
|
||||
Pos = {x = res.x * .3, y = res.y * .1}
|
||||
margin = {top = 10, left = 10, right = 10, bottom = 10}
|
||||
baseTechPath = 'Icons/Technologies/'
|
||||
heightOffset = techButtonSize.y + 10
|
||||
|
||||
gui = {
|
||||
{
|
||||
guiType = GuiType.GUI_RECTANGLE,
|
||||
pos = Pos,
|
||||
zIndex = .9,
|
||||
size = Size,
|
||||
color = {x = 0, y = 0, z = 0, w = .6}
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'apt.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.APT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'fpt.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.FPT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + 2 * heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'fpt.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.FPT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top + heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'ept.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.EFT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + .5 * (Size.x - 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'ept.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.EFT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + .5 * (Size.x + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'ept.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.EFT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'pct.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.PCT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + Size.x - (margin.right + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'pct.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.PCT,
|
||||
trigger = 82,
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset},
|
||||
size = techButtonSize,
|
||||
name = "Research",
|
||||
imagePath = baseTechPath .. 'pct.jpg',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.RESEARCH,
|
||||
techId = TechId.PCT,
|
||||
trigger = 82,
|
||||
},
|
||||
--[[
|
||||
]]--
|
||||
}
|
||||
+72
-7
@@ -1,24 +1,89 @@
|
||||
#include "researchButton.h"
|
||||
#include "activeGameState.h"
|
||||
#include "researchStruct.h"
|
||||
#include "game.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <quad.h>
|
||||
#include <material.h>
|
||||
#include <node.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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){}
|
||||
UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), techId(tid){
|
||||
Root *root = Root::getSingleton();
|
||||
Material *mat = new Material(root->getLibPath() + "gui");
|
||||
mat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL);
|
||||
|
||||
Quad *quad = new Quad(Vector3(size.x, size.y, 1), false);
|
||||
quad->setMaterial(mat);
|
||||
|
||||
overlay = new Node(Vector3(pos.x, pos.y, -.8));
|
||||
overlay->attachMesh(quad);
|
||||
root->getGuiNode()->attachChild(overlay);
|
||||
}
|
||||
|
||||
ResearchButton::~ResearchButton(){
|
||||
Root::getSingleton()->getGuiNode()->dettachChild(overlay);
|
||||
delete overlay;
|
||||
}
|
||||
|
||||
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);
|
||||
vector<Unit*> labs = getUnits(unitId);
|
||||
|
||||
for(Unit *rs : researchStructs)
|
||||
if(find(selUnits.begin(), selUnits.end(), rs) != selUnits.end())
|
||||
((ResearchStruct*)rs)->appendToQueue(techId);
|
||||
for(Unit *lab : labs)
|
||||
((ResearchStruct*)lab)->appendToQueue(techId);
|
||||
}
|
||||
|
||||
void ResearchButton::update(){
|
||||
Button::update();
|
||||
|
||||
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
|
||||
vector<int> technologies = activeState->getPlayer()->getTechnologies();
|
||||
bool hasTech = (find(technologies.begin(), technologies.end(), techId) != technologies.end());
|
||||
|
||||
float alpha = .6;
|
||||
string uniform = "diffuseColor";
|
||||
|
||||
if(!hasTech){
|
||||
vector<int> techParents = Game::getSingleton()->getTechnology(techId).parents;
|
||||
bool hasTechParents = true;
|
||||
|
||||
for(int tp : techParents)
|
||||
if(find(technologies.begin(), technologies.end(), techId) == technologies.end()){
|
||||
hasTechParents = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(hasTechParents){
|
||||
overlay->setVisible(false);
|
||||
|
||||
vector<Unit*> labs = getUnits(unitId);
|
||||
|
||||
for(Unit *lab : labs){
|
||||
vector<int> researchQueue = ((ResearchStruct*)lab)->getQueue();
|
||||
|
||||
if(find(researchQueue.begin(), researchQueue.end(), techId) != researchQueue.end()){
|
||||
overlay->setVisible(true);
|
||||
overlay->getMesh(0)->getMaterial()->setVec4Uniform(uniform, Vector4(0, 0, 1, alpha));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
overlay->getMesh(0)->getMaterial()->setVec4Uniform(uniform, Vector4(1, 0, 0, alpha));
|
||||
}
|
||||
else
|
||||
overlay->getMesh(0)->getMaterial()->setVec4Uniform(uniform, Vector4(0, 0, 0, alpha));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ namespace battleship{
|
||||
class ResearchButton : public UnitButton{
|
||||
public:
|
||||
ResearchButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int);
|
||||
~ResearchButton();
|
||||
void onClick();
|
||||
void update();
|
||||
private:
|
||||
int techId;
|
||||
vb01::Node *overlay = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace battleship{
|
||||
~ResearchStruct();
|
||||
void update();
|
||||
inline void appendToQueue(int tid){researchQueue.push_back(tid);}
|
||||
inline std::vector<int> getQueue(){return researchQueue;}
|
||||
private:
|
||||
vb01::s64 lastUpdateTime = 0;
|
||||
int researchCost, generationRate, generationSpeed, researchStatus = 0;
|
||||
|
||||
+3
-6
@@ -16,12 +16,9 @@ namespace battleship{
|
||||
slotId(slId) {}
|
||||
|
||||
void TrainButton::onClick(){
|
||||
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
|
||||
Player *player = activeState->getPlayer();
|
||||
vector<Unit*> selUnits = player->getSelectedUnits(), factories = player->getUnitsById(unitId);
|
||||
vector<Unit*> labs = getUnits(unitId);
|
||||
|
||||
for(Unit *fac : factories)
|
||||
if(fac->getBuildableUnit(slotId).buildable && find(selUnits.begin(), selUnits.end(), fac) != selUnits.end())
|
||||
((Factory*)fac)->appendToQueue(slotId);
|
||||
for(Unit *lab : labs)
|
||||
((Factory*)lab)->appendToQueue(slotId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,19 @@ namespace battleship{
|
||||
if(activeState)
|
||||
activeState->addButton(this);
|
||||
}
|
||||
|
||||
//TODO optimize this code
|
||||
vector<Unit*> UnitButton::getUnits(int unitId){
|
||||
vector<Unit*> units;
|
||||
|
||||
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())
|
||||
units.push_back(rs);
|
||||
|
||||
return units;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace battleship{
|
||||
UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int);
|
||||
protected:
|
||||
int unitId;
|
||||
|
||||
std::vector<Unit*> getUnits(int);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user