victory and defeat screens

This commit is contained in:
devZoGok
2023-12-26 15:13:54 +02:00
parent 950411f515
commit f884fc1647
16 changed files with 186 additions and 14 deletions
+4
View File
@@ -2,6 +2,7 @@ gui = {
{
guiType = GuiType.TEXT,
name = 'refineds',
text = '',
pos = {x = 0, y = 100},
zIndex = 0,
font = 'batang.ttf',
@@ -12,6 +13,7 @@ gui = {
{
guiType = GuiType.TEXT,
name = 'wealth',
text = '',
pos = {x = 0, y = 200},
zIndex = 0,
font = 'batang.ttf',
@@ -22,6 +24,7 @@ gui = {
{
guiType = GuiType.TEXT,
name = 'research',
text = '',
pos = {x = 0, y = 300},
zIndex = 0,
font = 'batang.ttf',
@@ -32,6 +35,7 @@ gui = {
{
guiType = GuiType.TEXT,
name = 'depth',
text = '',
pos = {x = 0, y = 400},
zIndex = 0,
font = 'batang.ttf',
+31
View File
@@ -0,0 +1,31 @@
Size = {x = 150, y = 40}
gui = {
{
guiType = GuiType.TEXT,
text = 'Defeat',
name = 'D',
pos = {x = 100, y = 100},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 100, y = 200},
zIndex = 1,
size = {x = 600, y = 600},
color = {x = 0, y = 0, z = 0, w = 0.1}
},
{
pos = {x = 110, y = 350},
size = Size,
guiType = GuiType.BUTTON,
name = 'Leave',
buttonType = ButtonType.STATISTICS,
trigger = -1,
imagePath = ''
}
}
+2 -1
View File
@@ -25,7 +25,8 @@ ButtonType = {
CONSOLE_COMMAND_OK = 21,
BUILD = 22,
LAND_FACTORY_TRAIN = 23,
NAVAL_FACTORY_TRAIN = 24
NAVAL_FACTORY_TRAIN = 24,
STATISTICS = 25
}
ListboxType = {
+20
View File
@@ -0,0 +1,20 @@
gui = {
{
guiType = GuiType.TEXT,
text = 'Statistics',
name = 'D',
pos = {x = 100, y = 100},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 100, y = 200},
zIndex = 1,
size = {x = 600, y = 600},
color = {x = 0, y = 0, z = 0, w = 0.1}
},
}
+38
View File
@@ -0,0 +1,38 @@
Size = {x = 150, y = 40}
gui = {
{
guiType = GuiType.TEXT,
text = 'VICTORY!!!',
name = 'V',
pos = {x = 100, y = 100},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 100, y = 200},
zIndex = 1,
size = {x = 600, y = 600},
color = {x = 0, y = 0, z = 0, w = 0.1}
},
{
pos = {x = 100, y = 350},
size = Size,
guiType = GuiType.BUTTON,
name = 'Resume',
buttonType = ButtonType.RESUME
},
{
pos = {x = 110, y = 400},
size = Size,
guiType = GuiType.BUTTON,
name = 'Leave',
buttonType = ButtonType.STATISTICS,
trigger = -1,
imagePath = ''
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ set(UNIT_BUTTONS unitButton.cpp buildButton.cpp trainButton.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 playButton.cpp ${OPTIONS_BUTTONS} ${IN_GAME_APP_STATE_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
set(BUTTONS singlePlayerButton.cpp exitButton.cpp backButton.cpp playButton.cpp statsButton.cpp ${OPTIONS_BUTTONS} ${IN_GAME_APP_STATE_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp)
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
+22 -3
View File
@@ -1,5 +1,7 @@
#include <solUtil.h>
#include <quad.h>
#include "concreteGuiManager.h"
#include "gameManager.h"
#include "singlePlayerButton.h"
@@ -21,6 +23,7 @@
#include "mainMenuButton.h"
#include "buildButton.h"
#include "trainButton.h"
#include "statsButton.h"
namespace battleship{
using namespace std;
@@ -165,6 +168,9 @@ namespace battleship{
case NAVAL_FACTORY_TRAIN:
button = new TrainButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)UnitClass::NAVAL_FACTORY, (int)guiTable["unitId"]);
break;
case STATISTICS:
button = new StatsButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
break;
}
int typeArr[2]{(int)GuiElementType::BUTTON, (int)type};
@@ -360,12 +366,25 @@ namespace battleship{
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
Node *guiRectangle;
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "gui");
mat->addBoolUniform("texturingEnabled", false);
sol::table colorTable = guiTable["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"]));
sol::table sizeTable = guiTable["size"];
Quad *quad = new Quad(Vector3(sizeTable["x"], sizeTable["y"], 1), false);
quad->setMaterial(mat);
sol::table posTable = guiTable["pos"];
Node *guiRectangle = new Node(Vector3(posTable["x"], posTable["y"], guiTable["zIndex"]));
guiRectangle->attachMesh(quad);
root->getGuiNode()->attachChild(guiRectangle);
int typeArr[2]{(int)GuiElementType::GUI_RECTANGLE, -1};
guiElements.push_back(make_pair(typeArr, (void*)guiRectangle));
return nullptr;
return guiRectangle;
}
Text* ConcreteGuiManager::parseText(int guiId){
@@ -380,7 +399,7 @@ namespace battleship{
sol::table colorTable = guiTable["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"]));
Text *text = new Text(GameManager::getSingleton()->getPath() + "Fonts/" + (string)guiTable["font"], L"", guiTable["fontFirstChar"], guiTable["fontLastChar"]);
Text *text = new Text(GameManager::getSingleton()->getPath() + "Fonts/" + (string)guiTable["font"], (wstring)guiTable["text"], guiTable["fontFirstChar"], guiTable["fontLastChar"]);
text->setMaterial(mat);
Vector3 pos = Vector3(posTable["x"], posTable["y"], guiTable["zIndex"]);
+2 -1
View File
@@ -39,7 +39,8 @@ namespace battleship{
CONSOLE_COMMAND_OK,
BUILD,
LAND_FACTORY_TRAIN,
NAVAL_FACTORY_TRAIN
NAVAL_FACTORY_TRAIN,
STATISTICS
};
enum ListboxType {
CONTROLS,
+31 -1
View File
@@ -43,12 +43,42 @@ namespace battleship{
}
}
void Game::endGame(bool victory){
ended = true;
StateManager *sm = GameManager::getSingleton()->getStateManager();
sm->dettachAppState(sm->getAppStateByType(AppStateType::ACTIVE_STATE));
togglePause();
string endGameScreen = (victory ? "victory.lua" : "defeat.lua");
ConcreteGuiManager::getSingleton()->readLuaScreenScript(endGameScreen);
}
void Game::update(){
resetLuaGameObjects();
for(int i = 0; i < players.size(); i++)
int numPlayersWithUnits = 0;
for(int i = 0; i < players.size(); i++){
players[i]->update();
if(players[i]->getNumUnits() > 0)
numPlayersWithUnits++;
}
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
if(mainPlayer && !ended){
int numMainPlayerUnits = mainPlayer->getNumUnits();
if(numMainPlayerUnits > 0 && numPlayersWithUnits == 1)
endGame(true);
else if(numMainPlayerUnits == 0)
endGame(false);
}
for(Projectile *proj : projectiles)
proj->update();
+2 -1
View File
@@ -24,8 +24,9 @@ namespace battleship{
private:
Game(){}
void resetLuaGameObjects();
void endGame(bool);
bool paused = false;
bool paused = false, ended = false;
std::vector<Fx> fx;
std::vector<Player*> players;
std::vector<Projectile*> projectiles;
+1 -1
View File
@@ -72,7 +72,7 @@ namespace battleship{
"Player", sol::constructors<Player(int, int, int, bool, Vector3)>(),
"addUnit", &Player::addUnit,
"getUnit", &Player::getUnit,
"getNumUnits", &Player::getNumberOfUnits,
"getNumUnits", &Player::getNumUnits,
"issueOrder", &Player::issueOrder,
"selectUnits", &Player::selectUnits,
"deselectUnits", &Player::deselectUnits,
+1 -1
View File
@@ -443,7 +443,7 @@ namespace battleship{
mapScript += "},\n";
}
int numUnits = players[i]->getNumberOfUnits();
int numUnits = players[i]->getNumUnits();
mapScript += "numUnits = " + to_string(numUnits) + ",\n";
if(numUnits > 0){
+1 -3
View File
@@ -37,13 +37,11 @@ namespace battleship{
int numPlayers = map->getNumSpawnPoints();
for(int i = 0; i < numPlayers; i++){
Player *player = new Player(0, 0, i, true, map->getSpawnPoint(i));
Player *player = new Player(0, 0, i, i < numPlayers - 1, map->getSpawnPoint(i));
map->loadPlayerGameObjects(player);
Game::getSingleton()->addPlayer(player);
}
Game::getSingleton()->addPlayer(new Player(0, 0, 0, false));
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
stateManager->attachAppState(new InGameAppState(difficulties, factions));
+1 -1
View File
@@ -34,7 +34,7 @@ namespace battleship{
inline std::vector<Unit*>& getUnits(){return units;}
inline void setTeam(int t){team = t;}
inline int getTeam(){return team;}
inline int getNumberOfUnits(){return units.size();}
inline int getNumUnits(){return units.size();}
inline int getFaction(){return faction;}
inline vb01::Vector3 getSpawnPoint(){return spawnPoint;}
inline int getRefineds(){return refineds;}
+14
View File
@@ -0,0 +1,14 @@
#include "statsButton.h"
#include "gameManager.h"
#include "concreteGuiManager.h"
namespace battleship{
using namespace std;
using namespace vb01;
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(){
ConcreteGuiManager::getSingleton()->readLuaScreenScript("statistics.lua");
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef STATS_BUTTON_H
#define STATS_BUTTON_H
#include <button.h>
namespace battleship {
class StatsButton : public vb01Gui::Button{
public:
StatsButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string);
void onClick();
private:
};
}
#endif