creating correct number GUI elements in the trading hub screen according to the number of players

This commit is contained in:
devZoGok
2024-03-23 14:50:19 +02:00
parent ff8f14e602
commit 1bb23231cb
11 changed files with 134 additions and 30 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ gui = {
},
{
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
buttonType = ButtonType.PLAYER_TRADE,
name = 'Trade',
imagePath = '',
guiScreen = 'tradingHub.lua',
+4 -2
View File
@@ -33,7 +33,8 @@ ButtonType = {
SELL_REFINEDS = 29,
BUY_RESEARCH = 30,
SELL_RESEARCH = 31,
ACTIVE_GAME_STATE = 32
ACTIVE_GAME_STATE = 32,
PLAYER_TRADE = 33
}
ListboxType = {
@@ -47,5 +48,6 @@ ListboxType = {
LAND_TEXTURES = 7,
CPU_DIFFICULTIES = 8,
FACTIONS = 9,
CONSOLE = 10
CONSOLE = 10,
TRADE_OFFERS = 11
}
+1 -22
View File
@@ -2,6 +2,7 @@ res = graphics.resolution
Pos = {x = 10, y = 10}
Size = {x = res.x * .8, y = res.y * .8}
buttonSize = {x = 100, y = 20}
textboxSize = {x = 200, y = 25}
margin = {top = 10, left = 10, right = 10, bottom = 10}
gui = {
@@ -12,28 +13,6 @@ gui = {
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,
@@ -0,0 +1,52 @@
res = graphics.resolution
Pos = {x = 10, y = 10}
Size = {x = res.x * .8, y = res.y * .8}
buttonSize = {x = 100, y = 20}
textboxSize = {x = 200, y = 25}
margin = {top = 10, left = 10, right = 10, bottom = 10}
height = Pos.y + margin.top + lineId * 30
warIcon = 'Icons/war.png'
allianceIcon = 'Icons/alliance.png'
gui = {
{
guiType = GuiType.TEXT,
name = 'playerName',
text = '',
pos = {x = Pos.x + margin.left, y = height},
zIndex = 0,
scale = 1,
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
--[[
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = Pos.x + margin.left + 20, y = height},
zIndex = .9,
size = Size,
color = {x = 0, y = 0, z = 0, w = .6}
},
{
pos = {x = Pos.x + margin.left + 40, y = height},
size = textboxSize,
guiType = GuiType.LISTBOX,
listboxType = ListboxType.TRADE_OFFERS,
numMaxDisplay = 1,
lines = {''}
},
]]--
{
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 = height},
size = buttonSize,
trigger = 10
}
}
+1 -1
View File
@@ -120,7 +120,7 @@ gui = {
createResourceTrayGui(false, 3, ResourceTrayGuiId.DECREMENT, IconPath.TIME),
{
guiType = GuiType.BUTTON,
buttonType = ButtonType.ACTIVE_GAME_STATE,
buttonType = ButtonType.PLAYER_TRADE,
name = 'Back',
imagePath = '',
guiScreen = 'tradingHub.lua',
+1 -1
View File
@@ -12,7 +12,7 @@ set(UNIT_BUTTONS unitButton.cpp tradeButton.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 statsButton.cpp activeStateButton.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 activeStateButton.cpp playerTradeButton.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})
+4
View File
@@ -27,6 +27,7 @@
#include "researchButton.h"
#include "tradeButton.h"
#include "activeStateButton.h"
#include "playerTradeButton.h"
namespace battleship{
using namespace std;
@@ -223,6 +224,9 @@ namespace battleship{
case ACTIVE_GAME_STATE:
button = new ActiveStateButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
break;
case PLAYER_TRADE:
button = new PlayerTradeButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
break;
}
int typeArr[2]{(int)GuiElementType::BUTTON, (int)type};
+4 -2
View File
@@ -47,7 +47,8 @@ namespace battleship{
SELL_REFINEDS,
BUY_RESEARCH,
SELL_RESEARCH,
ACTIVE_GAME_STATE
ACTIVE_GAME_STATE,
PLAYER_TRADE
};
enum ListboxType {
CONTROLS,
@@ -60,7 +61,8 @@ namespace battleship{
LAND_TEXTURES,
CPU_DIFFICULTIES,
FACTIONS,
CONSOLE
CONSOLE,
TRADE_OFFERS
};
class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{
+1 -1
View File
@@ -12,7 +12,7 @@ namespace battleship{
using namespace gameBase;
using namespace std;
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n), refineds(30000), trader(new Trader()) {}
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name("pl"), refineds(30000), trader(new Trader()) {}
Player::~Player() {}
+50
View File
@@ -0,0 +1,50 @@
#include "playerTradeButton.h"
#include "activeGameState.h"
#include "concreteGuiManager.h"
#include "game.h"
#include <stateManager.h>
#include <solUtil.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
PlayerTradeButton::PlayerTradeButton(Vector2 pos, Vector2 size, string gs, string name, int trigger, string imagePath) : ActiveStateButton(pos, size, gs, name, trigger, imagePath){}
void PlayerTradeButton::onClick(){
ActiveStateButton::onClick();
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
Player *mainPlayer = activeState->getPlayer();
vector<Player*> players = Game::getSingleton()->getPlayers();
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
sol::state_view SOL_LUA_VIEW = generateView();
for(int i = 0, plId = 0; i < players.size(); i++){
if(players[i] != mainPlayer){
vector<Button*> buttons = guiManager->getButtons();
vector<Listbox*> listboxes = guiManager->getListboxes();
vector<Checkbox*> checkboxes = guiManager->getCheckboxes();
vector<Slider*> sliders = guiManager->getSliders();
vector<Textbox*> textboxes = guiManager->getTextboxes();
vector<Node*> guiRects = guiManager->getGuiRectangles();
vector<Text*> texts = guiManager->getTexts();
SOL_LUA_VIEW.script("lineId = " + to_string(plId));
guiManager->readLuaScreenScript("tradingPlayerGuiTray.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
int numButtons = guiManager->getButtons().size();
int numListboxes = guiManager->getListboxes().size();
int numTexts = guiManager->getTexts().size();
guiManager->getTexts()[numTexts - 1]->setText(stringToWstring(players[i]->getName()));
plId++;
}
}
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef PLAYER_TRADE_BUTTON_H
#define PLAYER_TRADE_BUTTON_H
#include "activeStateButton.h"
namespace battleship{
class PlayerTradeButton : public ActiveStateButton{
public:
PlayerTradeButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string);
void onClick();
private:
};
}
#endif