mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
createable trade offers
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
res = graphics.resolution
|
res = graphics.resolution
|
||||||
|
|
||||||
buttonSize = {x = 100, y = 20}
|
buttonSize = {x = 100, y = 20}
|
||||||
textboxSize = {x = 200, y = 25}
|
textboxSize = {x = 200, y = 20}
|
||||||
|
|
||||||
height = HubPos.y + HubMargin.top + lineId * 30
|
height = HubPos.y + HubMargin.top + lineId * 30
|
||||||
warIcon = 'Icons/PlayerStates/war.png'
|
warIcon = 'Icons/PlayerStates/war.png'
|
||||||
@@ -19,22 +19,19 @@ gui = {
|
|||||||
fontLastChar = 256,
|
fontLastChar = 256,
|
||||||
color = {x = 1, y = 1, z = 1, w = 1}
|
color = {x = 1, y = 1, z = 1, w = 1}
|
||||||
},
|
},
|
||||||
--[[
|
|
||||||
{
|
{
|
||||||
guiType = GuiType.GUI_RECTANGLE,
|
guiType = GuiType.GUI_RECTANGLE,
|
||||||
pos = {x = Pos.x + margin.left + 20, y = height},
|
pos = {x = HubPos.x + HubMargin.left + 20, y = height, z = .11},
|
||||||
size = Size,
|
size = {x = 20, y = 20},
|
||||||
color = {x = 0, y = 0, z = 0, w = .6}
|
color = {x = 0, y = 0, z = 0, w = .6}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos = {x = Pos.x + margin.left + 40, y = height},
|
pos = {x = HubPos.x + HubMargin.left + 40, y = height, z = .11},
|
||||||
size = textboxSize,
|
size = textboxSize,
|
||||||
guiType = GuiType.LISTBOX,
|
guiType = GuiType.LISTBOX,
|
||||||
listboxType = ListboxType.TRADE_OFFERS,
|
listboxType = ListboxType.TRADE_OFFERS,
|
||||||
numMaxDisplay = 1,
|
numMaxDisplay = 3
|
||||||
lines = {''}
|
|
||||||
},
|
},
|
||||||
]]--
|
|
||||||
{
|
{
|
||||||
guiType = GuiType.BUTTON,
|
guiType = GuiType.BUTTON,
|
||||||
buttonType = ButtonType.TRADING_SCREEN,
|
buttonType = ButtonType.TRADING_SCREEN,
|
||||||
@@ -42,6 +39,7 @@ gui = {
|
|||||||
guiScreen = 'tradingScreen.lua',
|
guiScreen = 'tradingScreen.lua',
|
||||||
pos = {x = HubPos.x + HubSize.x - buttonSize.x - HubMargin.right, y = height, z = .11},
|
pos = {x = HubPos.x + HubSize.x - buttonSize.x - HubMargin.right, y = height, z = .11},
|
||||||
size = buttonSize,
|
size = buttonSize,
|
||||||
trigger = 10
|
trigger = 10,
|
||||||
|
dependencies = {{id = 2}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -237,9 +237,13 @@ namespace battleship{
|
|||||||
case PLAYER_TRADE:
|
case PLAYER_TRADE:
|
||||||
button = new PlayerTradeButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
|
button = new PlayerTradeButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
|
||||||
break;
|
break;
|
||||||
case TRADING_SCREEN:
|
case TRADING_SCREEN:{
|
||||||
button = new TradingScreenButton(pos, size, (int)SOL_LUA_STATE["playerId"], (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
|
int lid = guiTable["dependencies"][1]["id"];
|
||||||
|
Listbox *listbox = (Listbox*)guiElements[lid].second;
|
||||||
|
|
||||||
|
button = new TradingScreenButton(pos, size, listbox, (int)SOL_LUA_STATE["playerId"], (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case TRADE_OFFER:
|
case TRADE_OFFER:
|
||||||
button = new OfferButton(pos, size, (int)SOL_LUA_STATE["playerId"], name, (int)guiTable["trigger"], imagePath);
|
button = new OfferButton(pos, size, (int)SOL_LUA_STATE["playerId"], name, (int)guiTable["trigger"], imagePath);
|
||||||
break;
|
break;
|
||||||
@@ -380,6 +384,10 @@ namespace battleship{
|
|||||||
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
|
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TRADE_OFFERS:
|
||||||
|
closable = true;
|
||||||
|
listbox = new Listbox(pos, size, lines, numMaxDisplay, fontPath, closable);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType};
|
int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType};
|
||||||
|
|||||||
@@ -298,4 +298,14 @@ namespace battleship{
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<TradeOffer*> Game::findTradeOffers(Player *pl1, Player *pl2){
|
||||||
|
vector<TradeOffer*> offers;
|
||||||
|
|
||||||
|
for(TradeOffer *to : tradeOffers)
|
||||||
|
if((to->initPlayer == pl1 || to->recPlayer == pl1) && (to->initPlayer == pl2 || to->recPlayer == pl2))
|
||||||
|
offers.push_back(to);
|
||||||
|
|
||||||
|
return offers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "fx.h"
|
#include "fx.h"
|
||||||
#include "technology.h"
|
#include "technology.h"
|
||||||
#include "ability.h"
|
#include "ability.h"
|
||||||
|
#include "tradeOffer.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ namespace battleship{
|
|||||||
void initTechnologies();
|
void initTechnologies();
|
||||||
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
|
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
|
||||||
bool isUnitUnlocked(std::vector<int>, int);
|
bool isUnitUnlocked(std::vector<int>, int);
|
||||||
|
std::vector<TradeOffer*> findTradeOffers(Player*, Player*);
|
||||||
|
inline void addTradeOffer(TradeOffer *to){tradeOffers.push_back(to);}
|
||||||
inline void addFx(Fx f){fx.push_back(f);}
|
inline void addFx(Fx f){fx.push_back(f);}
|
||||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||||
inline std::vector<Player*>& getPlayers(){return players;}
|
inline std::vector<Player*>& getPlayers(){return players;}
|
||||||
@@ -46,6 +49,7 @@ namespace battleship{
|
|||||||
std::vector<Technology> technologies;
|
std::vector<Technology> technologies;
|
||||||
std::vector<Ability> abilities;
|
std::vector<Ability> abilities;
|
||||||
std::vector<Player*> players;
|
std::vector<Player*> players;
|
||||||
|
std::vector<TradeOffer*> tradeOffers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -1,8 +1,10 @@
|
|||||||
#include "offerButton.h"
|
#include "offerButton.h"
|
||||||
#include "concreteGuiManager.h"
|
#include "concreteGuiManager.h"
|
||||||
#include "gameManager.h"
|
|
||||||
#include "activeGameState.h"
|
#include "activeGameState.h"
|
||||||
|
#include "gameManager.h"
|
||||||
|
#include "tradeOffer.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
#include <stateManager.h>
|
#include <stateManager.h>
|
||||||
|
|
||||||
@@ -19,5 +21,19 @@ namespace battleship{
|
|||||||
void OfferButton::onClick(){
|
void OfferButton::onClick(){
|
||||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||||
vector<Textbox*> textboxes = guiManager->getTextboxes();
|
vector<Textbox*> textboxes = guiManager->getTextboxes();
|
||||||
|
|
||||||
|
int recRef = (textboxes[0]->getText() == L"" ? 0 : stoi(textboxes[0]->getText()));
|
||||||
|
int initRef = (textboxes[1]->getText() == L"" ? 0 : stoi(textboxes[1]->getText()));
|
||||||
|
int recWealth = (textboxes[2]->getText() == L"" ? 0 : stoi(textboxes[2]->getText()));
|
||||||
|
int initWealth = (textboxes[3]->getText() == L"" ? 0 : stoi(textboxes[3]->getText()));
|
||||||
|
int recRes = (textboxes[4]->getText() == L"" ? 0 : stoi(textboxes[4]->getText()));
|
||||||
|
int initRes = (textboxes[5]->getText() == L"" ? 0 : stoi(textboxes[5]->getText()));
|
||||||
|
|
||||||
|
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||||
|
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
|
||||||
|
Player *mainPlayer = activeState->getPlayer();
|
||||||
|
|
||||||
|
Game *game = Game::getSingleton();
|
||||||
|
game->addTradeOffer(new TradeOffer(mainPlayer, game->getPlayer(playerId), initRef, recRef, initWealth, recWealth, initRes, recRes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-3
@@ -1,6 +1,7 @@
|
|||||||
#include "playerTradeButton.h"
|
#include "playerTradeButton.h"
|
||||||
#include "activeGameState.h"
|
|
||||||
#include "concreteGuiManager.h"
|
#include "concreteGuiManager.h"
|
||||||
|
#include "activeGameState.h"
|
||||||
|
#include "offerButton.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#include <stateManager.h>
|
#include <stateManager.h>
|
||||||
@@ -20,8 +21,9 @@ namespace battleship{
|
|||||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||||
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
|
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
|
||||||
Player *mainPlayer = activeState->getPlayer();
|
Player *mainPlayer = activeState->getPlayer();
|
||||||
|
Game *game = Game::getSingleton();
|
||||||
|
|
||||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
vector<Player*> players = game->getPlayers();
|
||||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||||
sol::state_view SOL_LUA_VIEW = generateView();
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
|
|
||||||
@@ -39,8 +41,22 @@ namespace battleship{
|
|||||||
SOL_LUA_VIEW.script("playerId = " + to_string(i));
|
SOL_LUA_VIEW.script("playerId = " + to_string(i));
|
||||||
guiManager->readLuaScreenScript("tradingPlayerGuiTray.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
guiManager->readLuaScreenScript("tradingPlayerGuiTray.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||||
|
|
||||||
int numButtons = guiManager->getButtons().size();
|
vector<Button*> guiButtons = guiManager->getButtons();
|
||||||
|
|
||||||
|
for(int j = guiButtons.size() - 1; j > 0; j--)
|
||||||
|
if(guiButtons[j]->getName() == "Offer")
|
||||||
|
((OfferButton*)guiButtons[j])->setPlayerId(i);
|
||||||
|
|
||||||
int numListboxes = guiManager->getListboxes().size();
|
int numListboxes = guiManager->getListboxes().size();
|
||||||
|
Listbox *listbox = guiManager->getListboxes()[numListboxes - 1];
|
||||||
|
int numOffers = game->findTradeOffers(mainPlayer, players[i]).size();
|
||||||
|
|
||||||
|
for(int j = 0; j < numOffers; j++)
|
||||||
|
listbox->addLine(L"TRADE_OFFER_" + to_wstring(j));
|
||||||
|
|
||||||
|
if(listbox->getNumLines() < listbox->getMaxDisplay())
|
||||||
|
listbox->setMaxDisplay(listbox->getNumLines());
|
||||||
|
|
||||||
int numTexts = guiManager->getTexts().size();
|
int numTexts = guiManager->getTexts().size();
|
||||||
guiManager->getTexts()[numTexts - 1]->setText(stringToWstring(players[i]->getName()));
|
guiManager->getTexts()[numTexts - 1]->setText(stringToWstring(players[i]->getName()));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef TRADE_OFFER_H
|
||||||
|
#define TRADE_OFFER_H
|
||||||
|
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
|
namespace battleship{
|
||||||
|
struct TradeOffer{
|
||||||
|
Player *initPlayer = nullptr, *recPlayer = nullptr;
|
||||||
|
int initRefineds = 0, recRefineds = 0, initWealth = 0, recWealth = 0, initResearch = 0, recResearch = 0;
|
||||||
|
bool initPlAgreed = true, recPlAgreed = false;
|
||||||
|
|
||||||
|
TradeOffer(Player *ip, Player *rp, int ir, int rr, int iw, int rw, int it, int rt) :
|
||||||
|
initPlayer(ip),
|
||||||
|
recPlayer(rp),
|
||||||
|
initRefineds(ir),
|
||||||
|
recRefineds(rr),
|
||||||
|
initWealth(iw),
|
||||||
|
recWealth(rw),
|
||||||
|
initResearch(it),
|
||||||
|
recResearch(rr)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+36
-8
@@ -1,23 +1,51 @@
|
|||||||
#include "tradingScreenButton.h"
|
#include "tradingScreenButton.h"
|
||||||
#include "concreteGuiManager.h"
|
#include "concreteGuiManager.h"
|
||||||
|
#include "activeGameState.h"
|
||||||
#include "offerButton.h"
|
#include "offerButton.h"
|
||||||
#include "gameManager.h"
|
#include "gameManager.h"
|
||||||
|
#include "tradeOffer.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
#include <listbox.h>
|
||||||
|
#include <textbox.h>
|
||||||
|
|
||||||
|
#include <stateManager.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
using namespace vb01Gui;
|
using namespace vb01Gui;
|
||||||
|
using namespace gameBase;
|
||||||
|
|
||||||
TradingScreenButton::TradingScreenButton(Vector3 pos, Vector2 size, int plId, string gs, string name, int trigger, string imagePath) : ActiveStateButton(pos, size, gs, name, trigger, imagePath), playerId(plId){}
|
TradingScreenButton::TradingScreenButton(Vector3 pos, Vector2 size, Listbox *lb, int plId, string gs, string name, int trigger, string imagePath) :
|
||||||
|
ActiveStateButton(pos, size, gs, name, trigger, imagePath),
|
||||||
|
listbox(lb),
|
||||||
|
playerId(plId)
|
||||||
|
{}
|
||||||
|
|
||||||
//TODO add method to get buttons by name
|
|
||||||
void TradingScreenButton::onClick(){
|
void TradingScreenButton::onClick(){
|
||||||
buttons.push_back(this);
|
if(listbox->getNumLines() > 0){
|
||||||
ActiveStateButton::onClick();
|
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||||
|
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
|
||||||
|
Player *mainPlayer = activeState->getPlayer();
|
||||||
|
|
||||||
|
Game *game = Game::getSingleton();
|
||||||
|
TradeOffer *tradeOffer = game->findTradeOffers(mainPlayer, game->getPlayer(playerId))[listbox->getSelectedOption()];
|
||||||
|
|
||||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
ActiveStateButton::onClick();
|
||||||
int numButtons = guiManager->getButtons().size();
|
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||||
((OfferButton*)guiManager->getButtons()[numButtons - 1])->setPlayerId(playerId);
|
vector<Textbox*> textboxes = guiManager->getTextboxes();
|
||||||
guiManager->removeButton(this);
|
|
||||||
|
textboxes[0]->setEntry(to_wstring(tradeOffer->recRefineds));
|
||||||
|
textboxes[1]->setEntry(to_wstring(tradeOffer->initRefineds));
|
||||||
|
textboxes[2]->setEntry(to_wstring(tradeOffer->recWealth));
|
||||||
|
textboxes[3]->setEntry(to_wstring(tradeOffer->initWealth));
|
||||||
|
textboxes[4]->setEntry(to_wstring(tradeOffer->recResearch));
|
||||||
|
textboxes[5]->setEntry(to_wstring(tradeOffer->initResearch));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ActiveStateButton::onClick();
|
||||||
|
|
||||||
|
ConcreteGuiManager::getSingleton()->removeButton(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,18 @@
|
|||||||
|
|
||||||
#include "activeStateButton.h"
|
#include "activeStateButton.h"
|
||||||
|
|
||||||
|
namespace vb01Gui{
|
||||||
|
class Listbox;
|
||||||
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class TradingScreenButton : public ActiveStateButton{
|
class TradingScreenButton : public ActiveStateButton{
|
||||||
public:
|
public:
|
||||||
TradingScreenButton(vb01::Vector3, vb01::Vector2, int, std::string, std::string, int, std::string);
|
TradingScreenButton(vb01::Vector3, vb01::Vector2, vb01Gui::Listbox*, int, std::string, std::string, int, std::string);
|
||||||
void onClick();
|
void onClick();
|
||||||
private:
|
private:
|
||||||
int playerId;
|
int playerId;
|
||||||
|
vb01Gui::Listbox *listbox;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user