mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
implementation of AbstractGuiManager from vb01
recreated main menu screen using the implementation
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
||||
set(UTIL util.cpp binds.h)
|
||||
set(GUI tooltip.cpp mapEditorButton.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
|
||||
set(GUI tooltip.cpp concreteGuiManager.cpp singlePlayerButton.cpp mapEditorButton.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
|
||||
set(CONTROLLERS unitFrameController.cpp cameraController.cpp)
|
||||
set(CORE gameManager.cpp defConfigs.cpp ${CONTROLLERS})
|
||||
set(PROJECTILES projectile.cpp)
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#include <luaManager.h>
|
||||
|
||||
#include "concreteGuiManager.h"
|
||||
#include "gameManager.h"
|
||||
#include "singlePlayerButton.h"
|
||||
#include "mapEditorButton.h"
|
||||
#include "optionsButton.h"
|
||||
#include "exitButton.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
static ConcreteGuiManager *concreteGuiManager = nullptr;
|
||||
|
||||
ConcreteGuiManager* ConcreteGuiManager::getSingleton(){
|
||||
if(!concreteGuiManager)
|
||||
concreteGuiManager = new ConcreteGuiManager();
|
||||
|
||||
return concreteGuiManager;
|
||||
}
|
||||
|
||||
Button* createButton(int guiId){
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
|
||||
string guiTable = "gui", posTable = "pos", sizeTable = "size";
|
||||
float posX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("x")});
|
||||
float posY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(posTable), Index("y")});
|
||||
Vector2 pos = Vector2(posX, posY);
|
||||
|
||||
float sizeX = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("x")});
|
||||
float sizeY = lm->getFloatFromTable(guiTable, vector<Index>{Index(guiId + 1), Index(sizeTable), Index("y")});
|
||||
Vector2 size = Vector2(sizeX, sizeY);
|
||||
|
||||
string name = lm->getStringFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("name")});
|
||||
ButtonType type = (ButtonType)lm->getIntFromTable(guiTable, vector<Index>{Index(guiId + 1), Index("buttonType")});
|
||||
|
||||
Button *button = nullptr;
|
||||
|
||||
switch(type){
|
||||
case SINGLE_PLAYER:
|
||||
button = new SinglePlayerButton(pos, size, name);
|
||||
break;
|
||||
case EDITOR:
|
||||
button = new MapEditorButton(pos, size);
|
||||
break;
|
||||
case OPTIONS:
|
||||
button = new OptionsButton(pos, size, name, true);
|
||||
break;
|
||||
case EXIT:
|
||||
button = new ExitButton(pos, size);
|
||||
break;
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Listbox* createListbox(int guiId){
|
||||
Listbox *listbox = nullptr;
|
||||
return listbox;
|
||||
}
|
||||
|
||||
Checkbox* createCheckbox(int guiId){
|
||||
Checkbox *checkbox = nullptr;
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
Slider* createSlider(int guiId){
|
||||
Slider *slider = nullptr;
|
||||
return slider;
|
||||
}
|
||||
|
||||
Textbox* createTextbox(int guiId){
|
||||
Textbox *textbox = nullptr;
|
||||
return textbox;
|
||||
}
|
||||
|
||||
void ConcreteGuiManager::readLuaScreenScript(string script){
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath() + "Scripts/Gui/" + script;
|
||||
lm->buildScript(vector<string>{path});
|
||||
|
||||
int numGuiElements = lm->getInt("numGui");
|
||||
|
||||
for(int i = 0; i < numGuiElements; i++){
|
||||
int guiTypeId = lm->getIntFromTable("gui", vector<Index>{Index(i + 1), Index("guiType")});
|
||||
|
||||
switch((GuiElementType)guiTypeId){
|
||||
case BUTTON:
|
||||
addButton(createButton(i));
|
||||
break;
|
||||
case LISTBOX:
|
||||
addListbox(createListbox(i));
|
||||
break;
|
||||
case CHECKBOX:
|
||||
addCheckbox(createCheckbox(i));
|
||||
break;
|
||||
case SLIDER:
|
||||
addSlider(createSlider(i));
|
||||
break;
|
||||
case TEXTBOX:
|
||||
addTextbox(createTextbox(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CONCRETE_GUI_MANAGER_H
|
||||
#define CONCRETE_GUI_MANAGER_H
|
||||
|
||||
#include <abstractGuiManager.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace battleship{
|
||||
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX};
|
||||
enum ButtonType {SINGLE_PLAYER, EDITOR, OPTIONS, EXIT};
|
||||
|
||||
class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{
|
||||
public:
|
||||
static ConcreteGuiManager* getSingleton();
|
||||
void readLuaScreenScript(std::string);
|
||||
private:
|
||||
ConcreteGuiManager(){}
|
||||
vb01Gui::Button* parseButton(int);
|
||||
vb01Gui::Listbox* parseListbox(int);
|
||||
vb01Gui::Checkbox parseCheckbox(int);
|
||||
vb01Gui::Slider* parseSlider(int);
|
||||
vb01Gui::Textbox* parseTextbox(int);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,22 +1,26 @@
|
||||
#include "util.h"
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
|
||||
using namespace battleship;
|
||||
using namespace vb01;
|
||||
|
||||
int main() {
|
||||
GameManager *gameManager = GameManager::getSingleton();
|
||||
gameManager->start();
|
||||
GuiAppState *state = new GuiAppState();
|
||||
gameManager->getStateManager()->attachAppState(state);
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->start();
|
||||
gm->getStateManager()->attachAppState(new GuiAppState());
|
||||
|
||||
makeTitlescreenButtons(state);
|
||||
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
|
||||
|
||||
while(true){
|
||||
gameManager->update();
|
||||
gm->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "singlePlayerButton.h"
|
||||
#include "gameManager.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <listbox.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
|
||||
namespace battleship{
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
SinglePlayerButton::SinglePlayerButton(Vector2 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {}
|
||||
|
||||
void SinglePlayerButton::onMouseOver(){
|
||||
setColor(Vector4(.8, .8, .8, 1));
|
||||
}
|
||||
|
||||
void SinglePlayerButton::onMouseOff(){
|
||||
setColor(Vector4(.6, .6, .6, 1));
|
||||
}
|
||||
|
||||
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:
|
||||
|
||||
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_B, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllListboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
makeTitlescreenButtons(state);
|
||||
state->removeButton("Play");
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
|
||||
/*
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
|
||||
difficulties.push_back("Easy");
|
||||
difficulties.push_back("Medium");
|
||||
difficulties.push_back("Hard");
|
||||
factions.push_back("0");
|
||||
factions.push_back("1");
|
||||
|
||||
|
||||
string font = gm->getPath() + "Fonts/batang.ttf";
|
||||
Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font);
|
||||
Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font);
|
||||
Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font);
|
||||
|
||||
vector<string> folders = readDir(gm->getPath() + "Models/Maps", true);
|
||||
int numMinDirs = 3;
|
||||
int numShowDirs = folders.size() < numMinDirs ? folders.size() : numMinDirs;
|
||||
Listbox *map = new Listbox(Vector2(pos.x + 110, pos.y + 100), Vector2(100, 20), folders, numShowDirs, font);
|
||||
Listbox **difficultyListboxes = new Listbox*[1];
|
||||
Listbox **factionListboxes = new Listbox*[2];
|
||||
|
||||
difficultyListboxes[0] = cpuDifficulty;
|
||||
factionListboxes[0] = playerFaction;
|
||||
factionListboxes[1] = cpuFaction;
|
||||
|
||||
int lengths[]{1, 2};
|
||||
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, map, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
|
||||
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);
|
||||
state->addButton(playButton);
|
||||
state->addButton(returnButton);
|
||||
state->addListbox(cpuDifficulty);
|
||||
state->addListbox(cpuFaction);
|
||||
state->addListbox(playerFaction);
|
||||
state->addListbox(map);
|
||||
state->removeButton("Options");
|
||||
state->removeButton("Exit");
|
||||
state->removeButton("Singleplayer");
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef SINGLE_PLAYER_BUTTON_H
|
||||
#define SINGLE_PLAYER_BUTTON_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
namespace battleship{
|
||||
class SinglePlayerButton : public vb01Gui::Button {
|
||||
public:
|
||||
SinglePlayerButton(vb01::Vector2, vb01::Vector2, std::string);
|
||||
void onClick();
|
||||
void onMouseOver();
|
||||
void onMouseOff();
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user