diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 282e029..c6c5aa0 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -75,7 +75,7 @@ gui = { }, { guiType = GuiType.BUTTON, - buttonType = ButtonType.ACTIVE_GAME_STATE, + buttonType = ButtonType.PLAYER_TRADE, name = 'Trade', imagePath = '', guiScreen = 'tradingHub.lua', diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 71238fa..d66fc4c 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -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 } diff --git a/Assets/Scripts/Gui/tradingHub.lua b/Assets/Scripts/Gui/tradingHub.lua index 244252e..63117e6 100644 --- a/Assets/Scripts/Gui/tradingHub.lua +++ b/Assets/Scripts/Gui/tradingHub.lua @@ -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, diff --git a/Assets/Scripts/Gui/tradingPlayerGuiTray.lua b/Assets/Scripts/Gui/tradingPlayerGuiTray.lua new file mode 100644 index 0000000..d6d98c1 --- /dev/null +++ b/Assets/Scripts/Gui/tradingPlayerGuiTray.lua @@ -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 + } +} diff --git a/Assets/Scripts/Gui/tradingScreen.lua b/Assets/Scripts/Gui/tradingScreen.lua index 6b72b11..040acbc 100644 --- a/Assets/Scripts/Gui/tradingScreen.lua +++ b/Assets/Scripts/Gui/tradingScreen.lua @@ -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', diff --git a/CMakeLists.txt b/CMakeLists.txt index f2f54ca..726d5d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 7eb707d..e130446 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -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}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index e5f19e3..0284574 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -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{ diff --git a/player.cpp b/player.cpp index cdc1ebc..5d4c947 100755 --- a/player.cpp +++ b/player.cpp @@ -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() {} diff --git a/playerTradeButton.cpp b/playerTradeButton.cpp new file mode 100644 index 0000000..f368d64 --- /dev/null +++ b/playerTradeButton.cpp @@ -0,0 +1,50 @@ +#include "playerTradeButton.h" +#include "activeGameState.h" +#include "concreteGuiManager.h" +#include "game.h" + +#include +#include + +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 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 buttons = guiManager->getButtons(); + vector listboxes = guiManager->getListboxes(); + vector checkboxes = guiManager->getCheckboxes(); + vector sliders = guiManager->getSliders(); + vector textboxes = guiManager->getTextboxes(); + vector guiRects = guiManager->getGuiRectangles(); + vector 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++; + } + } + } +} diff --git a/playerTradeButton.h b/playerTradeButton.h new file mode 100644 index 0000000..35e5b5c --- /dev/null +++ b/playerTradeButton.h @@ -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