starting the game using the new GUI subsystem

This commit is contained in:
devZoGok
2023-07-02 10:12:50 +03:00
parent ca2d492efc
commit 01f56eca5e
9 changed files with 165 additions and 46 deletions
+2
View File
@@ -0,0 +1,2 @@
numGui = 0
gui = {}
+5 -2
View File
@@ -17,7 +17,8 @@ ButtonType = {
NEW_MAP_OK = 13,
LOAD_MAP = 14,
LOAD_MAP_OK = 15,
EXPORT = 16
EXPORT = 16,
PLAY = 17
}
ListboxType = {
@@ -26,5 +27,7 @@ ListboxType = {
MAPS = 2,
UNITS = 3,
SKYBOX_TEXTURES = 4,
LAND_TEXTURES = 5
LAND_TEXTURES = 5,
CPU_DIFFICULTIES = 6,
FACTIONS = 7
}
+52
View File
@@ -0,0 +1,52 @@
Size = {x = 100, y = 20}
numGui = 6
gui = {
{
pos = {x = 100, y = 100},
size = Size,
guiType = GuiType.LISTBOX,
listboxType = ListboxType.CPU_DIFFICULTIES
},
{
pos = {x = 210, y = 100},
size = Size,
guiType = GuiType.LISTBOX,
listboxType = ListboxType.FACTIONS
},
{
pos = {x = 100, y = 230},
size = Size,
guiType = GuiType.LISTBOX,
listboxType = ListboxType.FACTIONS
},
{
pos = {x = 110, y = 310},
size = Size,
guiType = GuiType.LISTBOX,
listboxType = ListboxType.MAPS,
numMaxDisplay = 5
},
{
pos = {x = 110, y = 460},
size = Size,
guiType = GuiType.BUTTON,
buttonType = ButtonType.PLAY,
name = 'Play',
numDependencies = 4,
dependencies = {
{id = 0},
{id = 1},
{id = 2},
{id = 3}
}
},
{
pos = {x = 110 + Size.x + 10, y = 460},
size = Size,
guiType = GuiType.BUTTON,
buttonType = ButtonType.BACK,
name = 'Back',
screen = 'mainMenu.lua'
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS ON)
cmake_policy(SET CMP0015 NEW)
set(BUTTONS singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp exportButton.cpp)
set(BUTTONS singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp exportButton.cpp playButton.cpp)
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp unitListbox.cpp)
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
+36
View File
@@ -16,6 +16,7 @@
#include "skyboxTextureListbox.h"
#include "landTextureListbox.h"
#include "unitListbox.h"
#include "playButton.h"
namespace battleship{
using namespace std;
@@ -32,6 +33,7 @@ namespace battleship{
return concreteGuiManager;
}
//TODO refactor player difficulty and faction listbox selection
Button* ConcreteGuiManager::parseButton(int guiId){
LuaManager *lm = LuaManager::getSingleton();
@@ -115,6 +117,24 @@ namespace battleship{
case EXPORT:
button = new ExportButton(pos, size);
break;
case PLAY:{
int did = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(1), Index("id")});
vector<Listbox*> difficultyListboxes = vector<Listbox*>{(Listbox*)guiElements[did].second};
vector<Listbox*> factionsListboxes;
int numPlayers = 2;
for(int i = 0; i < numPlayers; i++){
int fid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(i + 2), Index("id")});
factionsListboxes.push_back((Listbox*)guiElements[fid].second);
}
int mid = lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("dependencies"), Index(4), Index("id")});
Listbox *mapListbox = (Listbox*)guiElements[mid].second;
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
break;
}
}
int typeArr[2]{(int)GuiElementType::BUTTON, (int)type};
@@ -216,6 +236,22 @@ namespace battleship{
listbox = new LandTextureListbox(pos, size, lines, maxDisplay, fontPath);
break;
case CPU_DIFFICULTIES:
lines = vector<string>{"Easy", "Medium", "Hard"};
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
break;
case FACTIONS:
lines = vector<string>{"Empire", "Mutants", "Shapeshifters"};
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
break;
}
int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType};
+5 -2
View File
@@ -26,7 +26,8 @@ namespace battleship{
NEW_MAP_OK,
LOAD_MAP,
LOAD_MAP_OK,
EXPORT
EXPORT,
PLAY
};
enum ListboxType {
CONTROLS,
@@ -34,7 +35,9 @@ namespace battleship{
MAPS,
UNITS,
SKYBOX_TEXTURES,
LAND_TEXTURES
LAND_TEXTURES,
CPU_DIFFICULTIES,
FACTIONS
};
class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{
+38
View File
@@ -0,0 +1,38 @@
#include "playButton.h"
#include "gameManager.h"
#include "inGameAppState.h"
#include "concreteGuiManager.h"
#include <stateManager.h>
#include <glfw3.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
PlayButton::PlayButton(vector<Listbox*> difficulties, vector<Listbox*> factions, Listbox *mapListbox, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
difficultiesListboxes = difficulties;
factionsListboxes = factions;
this->mapListbox = mapListbox;
}
void PlayButton::onClick() {
std::vector<string> difficulties, factions;
for(int i = 0; i < difficultiesListboxes.size(); i++)
difficulties.push_back(wstringToString(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]));
for(int i = 0; i < factionsListboxes.size(); i++)
factions.push_back(to_string(factionsListboxes[i]->getSelectedOption()));
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
int selectedMap = mapListbox->getSelectedOption();
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
stateManager->attachAppState(new InGameAppState(difficulties, factions, mapName));
ConcreteGuiManager::getSingleton()->readLuaScreenScript("inGame.lua");
}
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef PLAY_BUTTON_H
#define PLAY_BUTTON_H
#include <button.h>
namespace vb01Gui{
class Listbox;
}
namespace battleship{
class PlayButton : public vb01Gui::Button {
public:
PlayButton(std::vector<vb01Gui::Listbox*>, std::vector<vb01Gui::Listbox*>, vb01Gui::Listbox*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
private:
std::vector<vb01Gui::Listbox*> difficultiesListboxes, factionsListboxes;
vb01Gui::Listbox *mapListbox = nullptr;
int lengths[2];
};
}
#endif
+4 -41
View File
@@ -1,6 +1,7 @@
#include "singlePlayerButton.h"
#include "gameManager.h"
#include "inGameAppState.h"
#include "concreteGuiManager.h"
#include <stateManager.h>
@@ -28,45 +29,8 @@ namespace battleship{
void SinglePlayerButton::onClick() {
vector<string> difficulties, factions;
class PlayButton : public Button {
public:
PlayButton(Listbox **difficulties, Listbox **factions, Listbox *mapListbox, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::GUI_STATE));
this->lengths[0] = lengths[0];
this->lengths[1] = lengths[1];
difficultiesListboxes = difficulties;
factionsListboxes = factions;
this->mapListbox = mapListbox;
}
void onClick() {
GameManager *gm = GameManager::getSingleton();
std::vector<string> difficulties, factions;
for(int i = 0; i < lengths[0]; i++)
difficulties.push_back(wstringToString(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]));
for(int i = 0; i < lengths[1]; i++)
factions.push_back(to_string(factionsListboxes[i]->getSelectedOption()));
delete[] difficultiesListboxes;
delete[] factionsListboxes;
StateManager *stateManager = gm->getStateManager();
int selectedMap = mapListbox->getSelectedOption();
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
stateManager->attachAppState(new InGameAppState(difficulties, factions, mapName));
state->removeAllListboxes();
state->removeButton("Back");
state->removeButton("Play");
}
private:
GuiAppState *state;
Listbox **difficultiesListboxes, **factionsListboxes, *mapListbox = nullptr;
int lengths[2];
};
/*
class ReturnButton : public Button {
public:
@@ -87,8 +51,7 @@ namespace battleship{
private:
GuiAppState *state;
};
/*
GameManager *gm = GameManager::getSingleton();
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
difficulties.push_back("Easy");
@@ -127,6 +90,6 @@ namespace battleship{
state->removeButton("Exit");
state->removeButton("Singleplayer");
*/
ConcreteGuiManager::getSingleton()->readLuaScreenScript("singlePlayerMenu.lua");
}
}