extended ConcreteGuiManager to parse texts and GUI nodes

using parsed texts in the ActiveGameState
This commit is contained in:
devZoGok
2023-12-26 11:31:06 +02:00
parent 070a77f9dc
commit fd02c64765
6 changed files with 114 additions and 43 deletions
+42
View File
@@ -0,0 +1,42 @@
gui = {
{
guiType = GuiType.TEXT,
name = 'refineds',
pos = {x = 0, y = 100},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.TEXT,
name = 'wealth',
pos = {x = 0, y = 200},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.TEXT,
name = 'research',
pos = {x = 0, y = 300},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.TEXT,
name = 'depth',
pos = {x = 0, y = 400},
zIndex = 0,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
GuiType = {BUTTON = 0, LISTBOX = 1, CHECKBOX = 2, SLIDER = 3, TEXTBOX = 4}
GuiType = {BUTTON = 0, LISTBOX = 1, CHECKBOX = 2, SLIDER = 3, TEXTBOX = 4, GUI_RECTANGLE = 5, TEXT = 6}
ButtonType = {
SINGLE_PLAYER = 0,
+7 -33
View File
@@ -41,16 +41,10 @@ namespace battleship{
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
this->guiState = guiState;
this->playerId = playerId;
mainPlayer = Game::getSingleton()->getPlayer(playerId);
depth = 1;
initDragbox();
refinedsText = initText(Vector2(0, 100));
wealthText = initText(Vector2(0, 200));
researchText = initText(Vector2(0, 300));
textNode = initText(Vector2(0, 400));
depth = 1;
}
ActiveGameState::~ActiveGameState() {
@@ -72,41 +66,21 @@ namespace battleship{
root->getGuiNode()->attachChild(dragboxNode);
}
Node* ActiveGameState::initText(Vector2 pos){
Material *tm = new Material(Root::getSingleton()->getLibPath() + "text");
tm->addBoolUniform("texturingEnabled", false);
tm->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
Text *t = new Text(GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", L"");
t->setMaterial(tm);
Node *node = new Node(Vector3(pos.x, pos.y, 0));
node->addText(t);
return node;
}
void ActiveGameState::onAttached() {
AbstractAppState::onAttached();
Root::getSingleton()->getGuiNode()->attachChild(textNode);
Root::getSingleton()->getGuiNode()->attachChild(refinedsText);
Root::getSingleton()->getGuiNode()->attachChild(wealthText);
Root::getSingleton()->getGuiNode()->attachChild(researchText);
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
}
void ActiveGameState::onDettached() {
AbstractAppState::onDettached();
Root::getSingleton()->getGuiNode()->dettachChild(textNode);
Root::getSingleton()->getGuiNode()->dettachChild(refinedsText);
Root::getSingleton()->getGuiNode()->dettachChild(wealthText);
Root::getSingleton()->getGuiNode()->dettachChild(researchText);
}
void ActiveGameState::update() {
textNode->getText(0)->setText(L"Depth: " + to_wstring(depth));
refinedsText->getText(0)->setText(L"Refineds: " + to_wstring(mainPlayer->getRefineds()));
wealthText->getText(0)->setText(L"Wealth: " + to_wstring(mainPlayer->getWealth()));
researchText->getText(0)->setText(L"Research: " + to_wstring(mainPlayer->getResearch()));
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
guiManager->getText("depth")->setText(L"Depth: " + to_wstring(depth));
guiManager->getText("refineds")->setText(L"Refineds: " + to_wstring(mainPlayer->getRefineds()));
guiManager->getText("wealth")->setText(L"Wealth: " + to_wstring(mainPlayer->getWealth()));
guiManager->getText("research")->setText(L"Research: " + to_wstring(mainPlayer->getResearch()));
if(!isSelectionBox && leftMouseClicked && getTime() - lastLeftMouseClicked > 10)
isSelectionBox = true;
+1 -2
View File
@@ -33,7 +33,6 @@ namespace battleship{
private:
void updateGameObjHoveredOn();
void initDragbox();
vb01::Node* initText(vb01::Vector2);
void deselectUnits();
void renderUnits();
void updateSelectionBox();
@@ -46,7 +45,7 @@ namespace battleship{
GuiAppState *guiState;
Player *mainPlayer;
GameObject *gameObjHoveredOn = nullptr;
vb01::Node *dragboxNode = nullptr, *textNode = nullptr, *refinedsText = nullptr, *wealthText = nullptr, *researchText = nullptr;
vb01::Node *dragboxNode = nullptr;
vb01::Vector2 clickPoint;
std::vector<Unit*> unitGroups[9];
std::vector<Order::Target> targets;
+52 -5
View File
@@ -356,25 +356,66 @@ namespace battleship{
return textbox;
}
Node* ConcreteGuiManager::parseGuiRectangle(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
Node *guiRectangle;
int typeArr[2]{(int)GuiElementType::GUI_RECTANGLE, -1};
guiElements.push_back(make_pair(typeArr, (void*)guiRectangle));
return nullptr;
}
Text* ConcreteGuiManager::parseText(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
sol::table posTable = guiTable["pos"];
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "text");
mat->addBoolUniform("texturingEnabled", false);
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->setMaterial(mat);
Vector3 pos = Vector3(posTable["x"], posTable["y"], guiTable["zIndex"]);
Node *node = new Node(pos, Quaternion::QUAT_W, Vector3::VEC_IJK, guiTable["name"]);
node->addText(text);
root->getGuiNode()->attachChild(node);
int typeArr[2]{(int)GuiElementType::TEXT, -1};
guiElements.push_back(make_pair(typeArr, (void*)text));
return text;
}
void ConcreteGuiManager::readLuaScreenScript(
string script,
vector<Button*> buttonExceptions,
vector<Listbox*> listboxExceptions,
vector<Checkbox*> checkboxExceptions,
vector<Slider*> sliderExceptions,
vector<Textbox*> textboxExceptions
vector<Textbox*> textboxExceptions,
vector<Node*> guiRecttboxExceptions,
vector<Text*> textExceptions
){
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions);
guiElements.clear();
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
sol::state_view SOL_LUA_STATE = generateView();
SOL_LUA_STATE.script_file(basePath + script);
sol::state_view SOL_LUA_VIEW = generateView();
SOL_LUA_VIEW.script_file(basePath + script);
int numGuiElements = SOL_LUA_STATE["numGui"];
SOL_LUA_VIEW.script("numGui = #gui");
int numGuiElements = SOL_LUA_VIEW["numGui"];
for(int i = 0; i < numGuiElements; i++){
int guiTypeId = SOL_LUA_STATE["gui"][i + 1]["guiType"];
int guiTypeId = SOL_LUA_VIEW["gui"][i + 1]["guiType"];
switch((GuiElementType)guiTypeId){
case BUTTON:
@@ -392,6 +433,12 @@ namespace battleship{
case TEXTBOX:
addTextbox(parseTextbox(i));
break;
case GUI_RECTANGLE:
addGuiRectangle(parseGuiRectangle(i));
break;
case TEXT:
addText(parseText(i));
break;
}
}
}
+11 -2
View File
@@ -7,8 +7,13 @@
#include <utility>
#include <vector>
namespace vb01{
class Node;
class Text;
}
namespace battleship{
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX};
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT};
enum ButtonType {
SINGLE_PLAYER,
EDITOR,
@@ -59,7 +64,9 @@ namespace battleship{
std::vector<vb01Gui::Listbox*> = std::vector<vb01Gui::Listbox*>{},
std::vector<vb01Gui::Checkbox*> = std::vector<vb01Gui::Checkbox*>{},
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{}
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
);
private:
ConcreteGuiManager(){}
@@ -69,6 +76,8 @@ namespace battleship{
vb01Gui::Checkbox* parseCheckbox(int);
vb01Gui::Slider* parseSlider(int);
vb01Gui::Textbox* parseTextbox(int);
vb01::Node* parseGuiRectangle(int);
vb01::Text* parseText(int);
std::vector<std::pair<int*, void*>> guiElements;
};