individual player trading screen

This commit is contained in:
devZoGok
2024-03-23 10:25:58 +02:00
parent 8c02e0d98c
commit d85152f065
7 changed files with 226 additions and 18 deletions
+4 -3
View File
@@ -45,21 +45,21 @@ gui = {
pos = {x = 0, y = 0},
zIndex = .9,
size = {x = s, y = s},
imagePath = 'defaultTexture.jpg',
imagePath = 'Icons/refineds.png',
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 0, y = 100},
zIndex = .9,
size = {x = s, y = s},
imagePath = 'defaultTexture.jpg',
imagePath = 'Icons/wealth.png',
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = 0, y = 200},
zIndex = .9,
size = {x = s, y = s},
imagePath = 'defaultTexture.jpg',
imagePath = 'Icons/research.png',
},
{
guiType = GuiType.TEXT,
@@ -78,6 +78,7 @@ gui = {
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = 'Trade',
imagePath = '',
guiScreen = 'tradingHub.lua',
pos = {x = res.x - Size.x, y = 200},
size = Size,
trigger = 10
+47
View File
@@ -0,0 +1,47 @@
res = graphics.resolution
Pos = {x = 10, y = 10}
Size = {x = res.x * .8, y = res.y * .8}
buttonSize = {x = 100, y = 20}
margin = {top = 10, left = 10, right = 10, bottom = 10}
gui = {
{
guiType = GuiType.GUI_RECTANGLE,
pos = Pos,
zIndex = .9,
size = Size,
color = {x = 0, y = 0, z = 0, w = .6}
},
{
guiType = GuiType.TEXT,
name = 'P0',
text = 'P0',
pos = {x = Pos.x + margin.left, y = Pos.y + margin.top},
zIndex = 0,
scale = 1,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = 'Trade',
imagePath = '',
guiScreen = 'tradingScreen.lua',
pos = {x = Pos.x + Size.x - buttonSize.x - margin.right, y = Pos.y + buttonSize.y + margin.top},
size = buttonSize,
trigger = 10
},
{
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = 'Back',
imagePath = '',
guiScreen = 'activeGameState.lua',
pos = {x = Pos.x + Size.x - buttonSize.x - margin.right, y = Pos.y + Size.y - buttonSize.y - margin.bottom},
size = buttonSize,
trigger = 10
},
}
+131
View File
@@ -0,0 +1,131 @@
res = graphics.resolution
Pos = {x = 10, y = 10}
Size = {x = res.x * .8, y = res.y * .8}
margin = {top = 100, left = 100, right = 100, bottom = 100}
resTrayPos = {x = Pos.x + margin.left, y = Pos.y + margin.top}
iconSize = {x = 25, y = 25}
textboxSize = {x = 200, y = 25}
buttonSize = {x = 100, y = 20}
ResourceTrayGuiId = {ICON = 0, TEXTBOX = 1, INCREMENT = 2, DECREMENT = 3}
IconPath = {WEALTH = 'Icons/wealth.png', RESEARCH = 'Icons/research.png', REFINEDS = 'Icons/refineds.png', TIME = 'Icons/time.png'}
function createResourceTrayGui(cpuPlayer, lineId, guiId, imgPath)
height = margin.top + lineId * iconSize.y
if guiId == ResourceTrayGuiId.ICON then
guiElPos = {x = Pos.x + (cpuPlayer and margin.left or Size.x -(margin.right + 3 * iconSize.x + textboxSize.x)), y = height}
return {
guiType = GuiType.GUI_RECTANGLE,
pos = guiElPos,
zIndex = .8,
size = iconSize,
imagePath = imgPath
}
elseif guiId == ResourceTrayGuiId.TEXTBOX then
guiElPos = {x = Pos.x + (cpuPlayer and margin.left + iconSize.x or Size.x -(margin.right + 2 * iconSize.x + textboxSize.x)), y = height}
return {
pos = guiElPos,
size = textboxSize,
guiType = GuiType.TEXTBOX,
}
elseif guiId == ResourceTrayGuiId.INCREMENT then
guiElPos = {x = Pos.x + (cpuPlayer and margin.left + iconSize.x + textboxSize.x or Size.x -(margin.right + 2 * iconSize.x)), y = height}
return {
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = '+',
imagePath = '',
guiScreen = 'tradingScreen.lua',
pos = guiElPos,
size = iconSize,
trigger = 10
}
elseif guiId == ResourceTrayGuiId.DECREMENT then
guiElPos = {x = Pos.x + (cpuPlayer and margin.left + 2 * iconSize.x + textboxSize.x or Size.x -(margin.right + iconSize.x)), y = height}
return {
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = '-',
imagePath = '',
guiScreen = 'tradingScreen.lua',
pos = guiElPos,
size = iconSize,
trigger = 10
}
end
end
gui = {
{
guiType = GuiType.TEXT,
name = 'P0',
text = 'P0',
pos = {x = Pos.x + margin.left, y = Pos.y + margin.top},
zIndex = 0,
scale = 1,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.TEXT,
name = 'You',
text = 'You',
pos = {x = Pos.x + margin.left, y = Pos.y + margin.top},
zIndex = 0,
scale = 1,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
createResourceTrayGui(true, 0, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(true, 0, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(true, 0, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(true, 0, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(false, 0, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(false, 0, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(false, 0, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(false, 0, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(true, 1, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(true, 1, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(true, 1, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(true, 1, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(false, 1, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(false, 1, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(false, 1, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(false, 1, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(true, 2, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(true, 2, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(true, 2, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(true, 2, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(false, 2, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(false, 2, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(false, 2, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(false, 2, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(true, 3, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(true, 3, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(true, 3, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(true, 3, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
createResourceTrayGui(false, 3, ResourceTrayGuiId.ICON, IconPath.WEALTH),
createResourceTrayGui(false, 3, ResourceTrayGuiId.TEXTBOX, IconPath.RESEARCH),
createResourceTrayGui(false, 3, ResourceTrayGuiId.INCREMENT, IconPath.REFINEDS),
createResourceTrayGui(false, 3, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
{
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
name = 'Back',
imagePath = '',
guiScreen = 'tradingHub.lua',
pos = {x = Pos.x + Size.x - buttonSize.x - margin.right, y = Pos.y + Size.y - buttonSize.y - margin.bottom},
size = buttonSize,
trigger = 10
},
}
+26 -1
View File
@@ -1,15 +1,24 @@
#include "activeStateButton.h"
#include "gameManager.h"
#include "activeGameState.h"
#include "concreteGuiManager.h"
#include <listbox.h>
#include <checkbox.h>
#include <slider.h>
#include <textbox.h>
#include <text.h>
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
ActiveStateButton::ActiveStateButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath){
ActiveStateButton::ActiveStateButton(Vector2 pos, Vector2 size, string gs, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), guiScreen(gs){
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
@@ -18,5 +27,21 @@ namespace battleship{
}
void ActiveStateButton::onClick(){
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
vector<Button*> buttons{};
vector<Listbox*> listboxes{};
vector<Checkbox*> checkboxes{};
vector<Slider*> sliders{};
vector<Textbox*> textboxes{};
vector<Node*> guiRects = guiManager->getGuiRectangles();
vector<Text*> texts{
guiManager->getText("depth"),
guiManager->getText("refineds"),
guiManager->getText("wealth"),
guiManager->getText("research")
};
guiManager->readLuaScreenScript(guiScreen, buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
}
}
+2 -1
View File
@@ -6,9 +6,10 @@
namespace battleship{
class ActiveStateButton : public vb01Gui::Button{
public:
ActiveStateButton(vb01::Vector2, vb01::Vector2, std::string, int = -1, std::string = "");
ActiveStateButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int = -1, std::string = "");
void onClick();
private:
std::string guiScreen = "";
};
}
+14 -12
View File
@@ -36,6 +36,12 @@ namespace battleship{
static ConcreteGuiManager *concreteGuiManager = nullptr;
ConcreteGuiManager::ConcreteGuiManager(){
string assetPath = GameManager::getSingleton()->getPath();
texBasePath = assetPath + "Textures/";
fontBasePath = assetPath + "Fonts/";
}
ConcreteGuiManager* ConcreteGuiManager::getSingleton(){
if(!concreteGuiManager)
concreteGuiManager = new ConcreteGuiManager();
@@ -215,7 +221,7 @@ namespace battleship{
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_RESEARCH);
break;
case ACTIVE_GAME_STATE:
button = new ActiveStateButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
button = new ActiveStateButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
break;
}
@@ -246,7 +252,7 @@ namespace battleship{
bool closable;
Listbox *listbox = nullptr;
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
string fontPath = fontBasePath + "batang.ttf";
switch(listboxType){
case CONTROLS:{
@@ -310,7 +316,7 @@ namespace battleship{
break;
}
case SKYBOX_TEXTURES:
lines = readDir(GameManager::getSingleton()->getPath() + "Textures/Skyboxes", true);
lines = readDir(texBasePath + "Skyboxes", true);
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
@@ -318,7 +324,7 @@ namespace battleship{
listbox = new SkyboxTextureListbox(pos, size, lines, maxDisplay, fontPath);
break;
case LAND_TEXTURES:
lines = readDir(GameManager::getSingleton()->getPath() + "Textures/Landmass", false);
lines = readDir(texBasePath + "Landmass", false);
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
@@ -365,9 +371,7 @@ namespace battleship{
string posTable = "pos";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
Checkbox *checkbox = new Checkbox(pos, fontPath);
Checkbox *checkbox = new Checkbox(pos, fontBasePath + "batang.ttf");
int typeArr[2]{(int)GuiElementType::CHECKBOX, -1};
guiElements.push_back(make_pair(typeArr, (void*)checkbox));
@@ -398,9 +402,7 @@ namespace battleship{
string posTable = "pos", sizeTable = "size";
Vector2 pos = Vector2(guiTable[posTable]["x"], guiTable[posTable]["y"]);
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf";
Textbox *textbox = new Textbox(pos, size, fontPath);
Textbox *textbox = new Textbox(pos, size, fontBasePath + "batang.ttf");
int typeArr[2]{(int)GuiElementType::TEXTBOX, -1};
guiElements.push_back(make_pair(typeArr, (void*)textbox));
@@ -423,7 +425,7 @@ namespace battleship{
mat->addBoolUniform("texturingEnabled", texturingEnabled);
if(texturingEnabled){
string p[]{GameManager::getSingleton()->getPath() + "Textures/" + (string)guiTable[ipk]};
string p[]{texBasePath + (string)guiTable[ipk]};
Texture *tex = new Texture(p, 1, false);
mat->addTexUniform("diffuseMap", tex, false);
}
@@ -459,7 +461,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"], (wstring)guiTable["text"], guiTable["fontFirstChar"], guiTable["fontLastChar"]);
Text *text = new Text(fontBasePath + (string)guiTable["font"], (wstring)guiTable["text"], guiTable["fontFirstChar"], guiTable["fontLastChar"]);
text->setScale((float)guiTable["scale"]);
text->setMaterial(mat);
+2 -1
View File
@@ -77,7 +77,7 @@ namespace battleship{
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
);
private:
ConcreteGuiManager(){}
ConcreteGuiManager();
vb01Gui::Button* parseButton(int);
vb01Gui::Listbox* parseGameObjectListbox();
vb01Gui::Listbox* parseListbox(int);
@@ -88,6 +88,7 @@ namespace battleship{
vb01::Text* parseText(int);
std::vector<std::pair<int*, void*>> guiElements;
std::string texBasePath, fontBasePath;
};
}