cleaned up statistics screen

This commit is contained in:
devZoGok
2023-12-26 17:25:07 +02:00
parent d43d7e3ba3
commit ee6208ce96
9 changed files with 93 additions and 4 deletions
+6
View File
@@ -48,6 +48,7 @@ namespace battleship{
}
ActiveGameState::~ActiveGameState() {
removeDragbox();
}
void ActiveGameState::initDragbox(){
@@ -66,6 +67,11 @@ namespace battleship{
root->getGuiNode()->attachChild(dragboxNode);
}
void ActiveGameState::removeDragbox(){
Root::getSingleton()->getRootNode()->dettachChild(dragboxNode);
delete dragboxNode;
}
void ActiveGameState::onAttached() {
AbstractAppState::onAttached();
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
+1
View File
@@ -33,6 +33,7 @@ namespace battleship{
private:
void updateGameObjHoveredOn();
void initDragbox();
void removeDragbox();
void deselectUnits();
void renderUnits();
void updateSelectionBox();
+6 -1
View File
@@ -91,7 +91,12 @@ namespace battleship{
stateManager->attachAppState(activeState);
}
void InGameAppState::onDettached() {}
void InGameAppState::onDettached() {
StateManager *sm = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)sm->getAppStateByType(int(AppStateType::ACTIVE_STATE));
sm->dettachAppState(activeState);
delete activeState;
}
void InGameAppState::update() {
Game::getSingleton()->update();
+54 -1
View File
@@ -7,6 +7,7 @@
#include <solUtil.h>
#include "map.h"
#include "game.h"
#include "player.h"
#include "gameObject.h"
#include "gameObjectFactory.h"
@@ -262,7 +263,59 @@ namespace battleship{
}
}
void Map::unload() {}
void Map::unloadSkybox(){
Root::getSingleton()->removeSkybox();
//unload skybox assets
}
void Map::unloadCells(){
while(cellNode->getNumChildren() > 0){
Node *node = cellNode->getChild(0);
cellNode->dettachChild(node);
//delete node;
}
cells.clear();
}
void Map::unloadTerrainObjects(){
//unload terrain assets
while(terrainNode->getNumChildren() > 0){
Node *node = terrainNode->getChild(0);
terrainNode->dettachChild(node);
//delete node;
}
}
void Map::unloadPlayerObjects(){
for(Player *pl : Game::getSingleton()->getPlayers()){
while(pl->getNumUnits() > 0){
pl->removeUnit(0);
}
while(pl->getNumResourceDeposits() > 0){
pl->removeResourceDeposit(0);
}
}
}
void Map::destroyScene(){
Node *rootNode = Root::getSingleton()->getRootNode();
rootNode->dettachChild(terrainNode);
rootNode->dettachChild(cellNode);
delete terrainNode;
delete cellNode;
}
void Map::unload(){
unloadSkybox();
unloadCells();
unloadTerrainObjects();
unloadPlayerObjects();
spawnPoints.clear();
destroyScene();
}
template<typename T> int Map::bsearch(vector<T> haystack, T needle, float eps){
T haystackMidVal;
+5
View File
@@ -71,6 +71,11 @@ namespace battleship{
void loadSkybox();
void loadCells();
void loadTerrainObject(int);
void unloadTerrainObjects();
void unloadCells();
void unloadSkybox();
void unloadPlayerObjects();
void destroyScene();
template<typename T> int bsearch(std::vector<T>, T, float);
};
}
+2 -2
View File
@@ -42,9 +42,9 @@ namespace battleship{
Game::getSingleton()->addPlayer(player);
}
ConcreteGuiManager::getSingleton()->readLuaScreenScript("inGame.lua");
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
stateManager->attachAppState(new InGameAppState(difficulties, factions));
ConcreteGuiManager::getSingleton()->readLuaScreenScript("inGame.lua");
}
}
+5
View File
@@ -114,6 +114,11 @@ namespace battleship{
units.erase(units.begin() + id);
}
void Player::removeResourceDeposit(int id){
delete resourceDeposits[id];
resourceDeposits.erase(resourceDeposits.begin() + id);
}
vector<Unit*> Player::getSelectedUnitsByClass(UnitClass uc){
vector<Unit*> selectedUnits = getSelectedUnits(), unitsByClass;
+2
View File
@@ -18,6 +18,7 @@ namespace battleship{
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
void removeUnit(Unit*);
void removeUnit(int);
void removeResourceDeposit(int);
bool isThisPlayersUnit(GameObject*);
std::vector<Unit*> getSelectedUnitsByClass(UnitClass);
void selectUnits(std::vector<Unit*>);
@@ -30,6 +31,7 @@ namespace battleship{
inline void addUnit(Unit *u){units.push_back(u);}
inline std::vector<ResourceDeposit*>& getResourceDeposits(){return resourceDeposits;}
inline void addResourceDeposit(ResourceDeposit *rd){resourceDeposits.push_back(rd);}
inline int getNumResourceDeposits(){return resourceDeposits.size();}
inline Unit* getUnit(int i){return units[i];}
inline std::vector<Unit*>& getUnits(){return units;}
inline void setTeam(int t){team = t;}
+12
View File
@@ -1,14 +1,26 @@
#include "statsButton.h"
#include "gameManager.h"
#include "concreteGuiManager.h"
#include "inGameAppState.h"
#include "map.h"
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
StatsButton::StatsButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath){}
void StatsButton::onClick(){
Map::getSingleton()->unload();
StateManager *sm = GameManager::getSingleton()->getStateManager();
InGameAppState *inGameState = (InGameAppState*)sm->getAppStateByType(int(AppStateType::IN_GAME_STATE));
sm->dettachAppState(inGameState);
delete inGameState;
ConcreteGuiManager::getSingleton()->readLuaScreenScript("statistics.lua");
}
}