diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 564bb3d..f863dd5 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -5,6 +5,7 @@ gui = { text = '', pos = {x = 0, y = 100}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, @@ -16,6 +17,7 @@ gui = { text = '', pos = {x = 0, y = 200}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, @@ -27,6 +29,7 @@ gui = { text = '', pos = {x = 0, y = 300}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, @@ -38,6 +41,7 @@ gui = { text = '', pos = {x = 0, y = 400}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, diff --git a/Assets/Scripts/Gui/defeat.lua b/Assets/Scripts/Gui/defeat.lua index 8d9b3e7..78e89b4 100644 --- a/Assets/Scripts/Gui/defeat.lua +++ b/Assets/Scripts/Gui/defeat.lua @@ -7,6 +7,7 @@ gui = { name = 'D', pos = {x = 100, y = 100}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, diff --git a/Assets/Scripts/Gui/statistics.lua b/Assets/Scripts/Gui/statistics.lua index 372ed4d..cc22a67 100644 --- a/Assets/Scripts/Gui/statistics.lua +++ b/Assets/Scripts/Gui/statistics.lua @@ -2,9 +2,94 @@ gui = { { guiType = GuiType.TEXT, text = 'Statistics', - name = 'D', - pos = {x = 100, y = 100}, + name = 'stat', + pos = {x = 850, y = 100}, zIndex = 0, + scale = 0.5, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Player', + name = 'pl', + pos = {x = 50, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Vehicles built', + name = 'vb', + pos = {x = 150, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Vehicles destroyed', + name = 'vd', + pos = {x = 450, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Vehicles lost', + name = 'vl', + pos = {x = 850, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Structures built', + name = 'sb', + pos = {x = 1050, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Structures destroyed', + name = 'sd', + pos = {x = 1350, y = 200}, + zIndex = 0, + scale = 0.3, + font = 'batang.ttf', + fontFirstChar = 0, + fontLastChar = 256, + color = {x = 1, y = 1, z = 1, w = 1} + }, + { + guiType = GuiType.TEXT, + text = 'Structures lost', + name = 'sl', + pos = {x = 1720, y = 200}, + zIndex = 0, + scale = 0.3, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, @@ -15,6 +100,14 @@ gui = { pos = {x = 100, y = 200}, zIndex = 1, size = {x = 600, y = 600}, - color = {x = 0, y = 0, z = 0, w = 0.1} + color = {x = 0, y = 0, z = 1, w = 1} }, + { + pos = {x = 1700, y = 1000}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Back', + screen = 'mainMenu.lua', + buttonType = ButtonType.BACK + } } diff --git a/Assets/Scripts/Gui/victory.lua b/Assets/Scripts/Gui/victory.lua index a5e0f43..d172a1d 100644 --- a/Assets/Scripts/Gui/victory.lua +++ b/Assets/Scripts/Gui/victory.lua @@ -7,6 +7,7 @@ gui = { name = 'V', pos = {x = 100, y = 100}, zIndex = 0, + scale = 1, font = 'batang.ttf', fontFirstChar = 0, fontLastChar = 256, diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index a4c1de1..df50aa0 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -400,6 +400,7 @@ namespace battleship{ mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"])); Text *text = new Text(GameManager::getSingleton()->getPath() + "Fonts/" + (string)guiTable["font"], (wstring)guiTable["text"], guiTable["fontFirstChar"], guiTable["fontLastChar"]); + text->setScale((float)guiTable["scale"]); text->setMaterial(mat); Vector3 pos = Vector3(posTable["x"], posTable["y"], guiTable["zIndex"]); diff --git a/game.cpp b/game.cpp index f5be24e..e9447cd 100644 --- a/game.cpp +++ b/game.cpp @@ -91,6 +91,7 @@ namespace battleship{ } } + //TODO remove the bool flag void Game::removeFx(int id, bool vfx){ const sf::SoundBuffer *buffer = fx[id].sfx->getBuffer(); @@ -108,6 +109,18 @@ namespace battleship{ } } + void Game::removeAllElements(){ + resetLuaGameObjects(); + + while(!players.empty()){ + delete players[0]; + players.erase(players.begin()); + } + + ended = false; + paused = false; + } + void Game::togglePause(){ GameManager *gm = GameManager::getSingleton(); ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); diff --git a/game.h b/game.h index b45fe48..c4dcb10 100644 --- a/game.h +++ b/game.h @@ -15,6 +15,7 @@ namespace battleship{ void update(); void togglePause(); void removeFx(int, bool); + void removeAllElements(); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline void addProjectile(Projectile *proj){projectiles.push_back(proj);} diff --git a/gameManager.cpp b/gameManager.cpp index 8b23c68..2839941 100755 --- a/gameManager.cpp +++ b/gameManager.cpp @@ -69,7 +69,7 @@ namespace battleship{ ); SOL_LUA_STATE.new_usertype( - "Player", sol::constructors(), + "Player", sol::constructors(), "addUnit", &Player::addUnit, "getUnit", &Player::getUnit, "getNumUnits", &Player::getNumUnits, diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 3dec5b0..7d317ad 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -56,7 +56,7 @@ namespace battleship{ map->load(name, newMap); if(newMap){ - addPlayer(new Player(0, 0, 0)); + addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); map->addSpawnPoint(Vector3::VEC_ZERO); generatePlane(size); } @@ -64,7 +64,7 @@ namespace battleship{ int numPlayers = map->getNumSpawnPoints(); for(int i = 0; i < numPlayers; i++){ - Player *player = new Player(0, 0, 0); + Player *player = new Player(0, 0, 0, Vector3(1, 1, 1)); map->loadPlayerGameObjects(player); addPlayer(player); } diff --git a/playButton.cpp b/playButton.cpp index 31a74e9..b6cab8a 100644 --- a/playButton.cpp +++ b/playButton.cpp @@ -37,7 +37,9 @@ namespace battleship{ int numPlayers = map->getNumSpawnPoints(); for(int i = 0; i < numPlayers; i++){ - Player *player = new Player(0, 0, i, i < numPlayers - 1, map->getSpawnPoint(i)); + bool cpuPlayer = (i < numPlayers - 1); + string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player"); + Player *player = new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name); map->loadPlayerGameObjects(player); Game::getSingleton()->addPlayer(player); } diff --git a/player.cpp b/player.cpp index a7db17c..cedf3e5 100755 --- a/player.cpp +++ b/player.cpp @@ -11,7 +11,7 @@ namespace battleship{ using namespace gameBase; using namespace std; - Player::Player(int diff, int fac, int t, bool cpuPl, Vector3 sp) : difficulty(diff), faction(fac), team(t), cpuPlayer(cpuPl), spawnPoint(sp) {} + Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n) {} Player::~Player() {} diff --git a/player.h b/player.h index 61f0dc8..6fd3613 100755 --- a/player.h +++ b/player.h @@ -12,7 +12,7 @@ namespace battleship{ class Player { public: - Player(int, int, int, bool = true, vb01::Vector3 = vb01::Vector3::VEC_ZERO); + Player(int, int, int, vb01::Vector3, bool = true, vb01::Vector3 = vb01::Vector3::VEC_ZERO, std::string = ""); ~Player(); void update(); void issueOrder(Order::TYPE, vb01::Vector3, std::vector, bool); @@ -49,13 +49,28 @@ namespace battleship{ inline void setResearch(int r){this->research = r;} inline void addResearch(int r){this->research += r;} inline bool isCpuPlayer(){return cpuPlayer;} + inline int getNumVehiclesBuilt(){return vehiclesBuilt;} + inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;} + inline int getNumVehiclesLost(){return vehiclesLost;} + inline int getNumStructuresBuilt(){return structuresBuilt;} + inline int getNumStructuresDestroyed(){return structuresDestroyed;} + inline int getNumStructuresLost(){return structuresLost;} + inline void setNumVehiclesBuilt(int vb){vehiclesBuilt = vb;} + inline void setNumVehiclesDestroyed(int vd){vehiclesDestroyed = vd;} + inline void setNumVehiclesLost(int vl){vehiclesLost = vl;} + inline void setNumStructuresBuilt(int sb){structuresBuilt = sb;} + inline void setNumStructuresDestroyed(int sd){structuresDestroyed = sd;} + inline void setNumStructuresLost(int sl){structuresLost = sl;} + inline vb01::Vector3 getColor(){return color;} + inline std::string getName(){return name;} private: bool cpuPlayer = false; - int refineds = 0, wealth = 0, research = 0, faction, difficulty, team, luaPlayerId; + int refineds = 0, wealth = 0, research = 0, faction, difficulty, team, luaPlayerId, vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0, structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0; + std::string name; std::vector units, selectedUnits; std::vector projectiles; std::vector resourceDeposits; - vb01::Vector3 spawnPoint; + vb01::Vector3 spawnPoint, color; int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3); }; diff --git a/statsButton.cpp b/statsButton.cpp index e0a760a..7ac4da2 100644 --- a/statsButton.cpp +++ b/statsButton.cpp @@ -2,6 +2,7 @@ #include "gameManager.h" #include "concreteGuiManager.h" #include "inGameAppState.h" +#include "game.h" #include "map.h" #include @@ -13,7 +14,50 @@ namespace battleship{ 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::addPlayerDataGuiElements(int playerId){ + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; + Player *player = Game::getSingleton()->getPlayer(playerId); + + Root *root = Root::getSingleton(); + Material *mat = new Material(root->getLibPath() + "text"); + mat->addBoolUniform("texturingEnabled", false); + mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1)); + + const int numPairs = 7; + pair unitDataPairs[numPairs]{ + make_pair("pl", stringToWstring(player->getName())), + make_pair("vb", to_wstring(player->getNumVehiclesBuilt())), + make_pair("vd", to_wstring(player->getNumVehiclesDestroyed())), + make_pair("vl", to_wstring(player->getNumVehiclesLost())), + make_pair("sb", to_wstring(player->getNumStructuresBuilt())), + make_pair("sd", to_wstring(player->getNumStructuresDestroyed())), + make_pair("sl", to_wstring(player->getNumStructuresLost())), + }; + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + Vector3 plCol = player->getColor(); + + for(int i = 0; i < numPairs; i++){ + Text *category = guiManager->getText(unitDataPairs[i].first); + + Material *categoryMat = new Material(root->getLibPath() + "text"); + categoryMat->addBoolUniform("texturingEnabled", false); + categoryMat->addVec4Uniform("diffuseColor", Vector4(plCol.x, plCol.y, plCol.z, 1)); + + Text *categoryVal = new Text(fontPath, unitDataPairs[i].second); + categoryVal->setScale(category->getScale()); + categoryVal->setMaterial(categoryMat); + + Node *categoryValNode = new Node(category->getNode()->getPosition() + Vector3(0, 100 * playerId, 0)); + categoryValNode->addText(categoryVal); + root->getGuiNode()->attachChild(categoryValNode); + + guiManager->addText(categoryVal); + } + } + void StatsButton::onClick(){ + ConcreteGuiManager::getSingleton()->readLuaScreenScript("statistics.lua"); + Map::getSingleton()->unload(); StateManager *sm = GameManager::getSingleton()->getStateManager(); @@ -21,6 +65,12 @@ namespace battleship{ sm->dettachAppState(inGameState); delete inGameState; - ConcreteGuiManager::getSingleton()->readLuaScreenScript("statistics.lua"); + Game *game = Game::getSingleton(); + int numPlayers = game->getNumPlayers(); + + for(int i = 1; i < numPlayers; i++) + addPlayerDataGuiElements(i); + + game->removeAllElements(); } } diff --git a/statsButton.h b/statsButton.h index f254a0d..f6cf165 100644 --- a/statsButton.h +++ b/statsButton.h @@ -9,6 +9,7 @@ namespace battleship { StatsButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string); void onClick(); private: + void addPlayerDataGuiElements(int); }; }