mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
players trade panel
This commit is contained in:
parent
f043c417a1
commit
791ee78cc4
@ -17,6 +17,9 @@
|
||||
#include "../windows/InfoWindows.h"
|
||||
|
||||
#include "../CGameInfo.h"
|
||||
#include "../CPlayerInterface.h"
|
||||
|
||||
#include "../../CCallback.h"
|
||||
|
||||
#include "../../lib/CGeneralTextHandler.h"
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
@ -126,23 +129,24 @@ void CTradeableItem::showAll(Canvas & to)
|
||||
{
|
||||
case RESOURCE:
|
||||
posToBitmap = Point(19, 9);
|
||||
posToSubCenter = Point(36, 59);
|
||||
posToSubCenter = Point(35, 57);
|
||||
break;
|
||||
case CREATURE_PLACEHOLDER:
|
||||
case CREATURE:
|
||||
posToSubCenter = Point(29, 77);
|
||||
break;
|
||||
case PLAYER:
|
||||
posToSubCenter = Point(31, 76);
|
||||
posToSubCenter = Point(31, 77);
|
||||
break;
|
||||
case ARTIFACT_PLACEHOLDER:
|
||||
case ARTIFACT_INSTANCE:
|
||||
posToSubCenter = Point(19, 54);
|
||||
posToSubCenter = Point(22, 51);
|
||||
if (downSelection)
|
||||
posToSubCenter.y += 8;
|
||||
break;
|
||||
case ARTIFACT_TYPE:
|
||||
posToSubCenter = Point(19, 58);
|
||||
posToSubCenter = Point(35, 57);
|
||||
posToBitmap = Point(13, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -293,7 +297,8 @@ SResourcesPanel::SResourcesPanel(CTradeableItem::ClickPressedFunctor clickPresse
|
||||
slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[res.num], EType::RESOURCE, res.num, true, res.num));
|
||||
slots.back()->clickPressedCallback = clickPressedCallback;
|
||||
slots.back()->pos.w = 69; slots.back()->pos.h = 66;
|
||||
slots.back()->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[res.num], slots.back()->pos.dimensions()));
|
||||
slots.back()->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[res.num], slots.back()->pos.dimensions()),
|
||||
Point(1, 1), selectionWidth);
|
||||
}
|
||||
updateSlotsCallback = updateSubtitles;
|
||||
}
|
||||
@ -311,12 +316,35 @@ SArtifactsPanel::SArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPresse
|
||||
{
|
||||
slot = std::make_shared<CTradeableItem>(slotsPos[slotNum], EType::ARTIFACT_TYPE, arts[slotNum].getNum(), false, slotNum);
|
||||
slot->clickPressedCallback = clickPressedCallback;
|
||||
slot->pos.w = slot->pos.h = 44;
|
||||
slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotNum++], slot->pos.dimensions()));
|
||||
slot->pos.w = 69; slot->pos.h = 66;
|
||||
slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotNum++], slot->pos.dimensions()), Point(1, 1), selectionWidth);
|
||||
}
|
||||
updateSlotsCallback = updateSubtitles;
|
||||
}
|
||||
|
||||
SPlayersPanel::SPlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback)
|
||||
{
|
||||
assert(PlayerColor::PLAYER_LIMIT_I <= slotsPos.size());
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
||||
|
||||
std::vector<PlayerColor> players;
|
||||
for(auto player = PlayerColor(0); player < PlayerColor::PLAYER_LIMIT_I; player++)
|
||||
{
|
||||
if(player != LOCPLINT->playerID && LOCPLINT->cb->getPlayerStatus(player) == EPlayerStatus::INGAME)
|
||||
players.emplace_back(player);
|
||||
}
|
||||
|
||||
slots.resize(players.size());
|
||||
int slotNum = 0;
|
||||
for(auto & slot : slots)
|
||||
{
|
||||
slot = std::make_shared<CTradeableItem>(slotsPos[slotNum], EType::PLAYER, players[slotNum].num, false, slotNum);
|
||||
slot->clickPressedCallback = clickPressedCallback;
|
||||
slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotNum], slot->pos.dimensions()), Point(1, 1), selectionWidth);
|
||||
slot->subtitle = CGI->generaltexth->capColors[players[slotNum++].num];
|
||||
}
|
||||
}
|
||||
|
||||
CTradeBase::CTradeBase(const IMarket * market, const CGHeroInstance * hero)
|
||||
: market(market)
|
||||
, hero(hero)
|
||||
|
@ -72,6 +72,7 @@ struct STradePanel : public CIntObject
|
||||
std::vector<std::shared_ptr<CTradeableItem>> slots;
|
||||
std::function<void()> updateSlotsCallback;
|
||||
std::shared_ptr<CTradeableItem> selected;
|
||||
const int selectionWidth = 2;
|
||||
|
||||
virtual void updateSlots();
|
||||
virtual void deselect();
|
||||
@ -111,6 +112,17 @@ struct SArtifactsPanel : public STradePanel
|
||||
std::vector<TradeItemBuy> & arts);
|
||||
};
|
||||
|
||||
struct SPlayersPanel : public STradePanel
|
||||
{
|
||||
const std::vector<Point> slotsPos =
|
||||
{
|
||||
Point(0, 0), Point(83, 0), Point(166, 0),
|
||||
Point(0, 118), Point(83, 118), Point(166, 118),
|
||||
Point(83, 236)
|
||||
};
|
||||
SPlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback);
|
||||
};
|
||||
|
||||
class CTradeBase
|
||||
{
|
||||
public:
|
||||
@ -119,7 +131,7 @@ public:
|
||||
|
||||
//all indexes: 1 = left, 0 = right
|
||||
std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items;
|
||||
std::vector<std::shared_ptr<STradePanel>> tradePanels;
|
||||
std::shared_ptr<STradePanel> leftTradePanel, rightTradePanel;
|
||||
|
||||
//highlighted items (nullptr if no highlight)
|
||||
std::shared_ptr<CTradeableItem> hLeft;
|
||||
|
@ -84,91 +84,75 @@ void CTradeWindow::initItems(bool Left)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Left && itemsType[1] == RESOURCE)
|
||||
auto updRightSub = [this](EMarketMode mode) -> void
|
||||
{
|
||||
tradePanels.emplace_back(std::make_shared<SResourcesPanel>(
|
||||
[this](std::shared_ptr<CTradeableItem> marketSlot) -> void
|
||||
if(hLeft)
|
||||
for(auto & slot : rightTradePanel->slots)
|
||||
{
|
||||
if(hLeft != marketSlot)
|
||||
{
|
||||
if(hLeft)
|
||||
hLeft->selection->selectSlot(false);
|
||||
hLeft = marketSlot;
|
||||
hLeft->selection->selectSlot(true);
|
||||
selectionChanged(true);
|
||||
}
|
||||
},
|
||||
[this]() -> void
|
||||
{
|
||||
for(auto & slot : tradePanels[1]->slots)
|
||||
slot->subtitle = std::to_string(LOCPLINT->cb->getResourceAmount(static_cast<EGameResID>(slot->serial)));
|
||||
}));
|
||||
tradePanels.back()->moveBy(Point(39, 182));
|
||||
tradePanels.back()->updateSlots();
|
||||
return;
|
||||
}
|
||||
if(!Left && itemsType[0] == RESOURCE)
|
||||
{
|
||||
tradePanels.emplace_back(std::make_shared<SResourcesPanel>(
|
||||
[this](std::shared_ptr<CTradeableItem> marketSlot) -> void
|
||||
{
|
||||
if(hRight != marketSlot)
|
||||
{
|
||||
if(hRight)
|
||||
hRight->selection->selectSlot(false);
|
||||
hRight = marketSlot;
|
||||
hRight->selection->selectSlot(true);
|
||||
selectionChanged(false);
|
||||
initSubs(false);
|
||||
}
|
||||
},
|
||||
[this]() -> void
|
||||
{
|
||||
if(hLeft)
|
||||
for(auto & slot : tradePanels[0]->slots)
|
||||
{
|
||||
int h1, h2; //hlp variables for getting offer
|
||||
market->getOffer(hLeft->id, slot->id, h1, h2, EMarketMode::RESOURCE_RESOURCE);
|
||||
int h1, h2; //hlp variables for getting offer
|
||||
market->getOffer(hLeft->id, slot->id, h1, h2, mode);
|
||||
|
||||
if(slot->id != hLeft->id)
|
||||
tradePanels[0]->updateOffer(slot->serial, h1, h2);
|
||||
else
|
||||
slot->subtitle = CGI->generaltexth->allTexts[164]; // n/a
|
||||
}
|
||||
else
|
||||
tradePanels[0]->clearSubtitles();
|
||||
}));
|
||||
tradePanels.back()->moveBy(Point(327, 182));
|
||||
return;
|
||||
}
|
||||
if(!Left && itemsType[0] == ARTIFACT_TYPE)
|
||||
rightTradePanel->updateOffer(slot->serial, h1, h2);
|
||||
}
|
||||
else
|
||||
rightTradePanel->clearSubtitles();
|
||||
};
|
||||
|
||||
auto clickPressedTradePanel = [this](std::shared_ptr<CTradeableItem> newSlot, bool left)
|
||||
{
|
||||
tradePanels.emplace_back(std::make_shared<SArtifactsPanel>(
|
||||
[this](std::shared_ptr<CTradeableItem> marketSlot) -> void
|
||||
{
|
||||
if(hRight != marketSlot)
|
||||
{
|
||||
if(hRight)
|
||||
hRight->selection->selectSlot(false);
|
||||
hRight = marketSlot;
|
||||
hRight->selection->selectSlot(true);
|
||||
selectionChanged(false);
|
||||
initSubs(false);
|
||||
}
|
||||
},
|
||||
auto * selectedSlot = &hRight;
|
||||
if(left)
|
||||
selectedSlot = &hLeft;
|
||||
|
||||
if(*selectedSlot)
|
||||
(*selectedSlot)->selection->selectSlot(false);
|
||||
*selectedSlot = newSlot;
|
||||
newSlot->selection->selectSlot(true);
|
||||
selectionChanged(left);
|
||||
};
|
||||
|
||||
if(Left && (mode == EMarketMode::RESOURCE_RESOURCE || mode == EMarketMode::RESOURCE_ARTIFACT || mode == EMarketMode::RESOURCE_PLAYER))
|
||||
{
|
||||
leftTradePanel = std::make_shared<SResourcesPanel>(std::bind(clickPressedTradePanel, _1, true),
|
||||
[this]() -> void
|
||||
{
|
||||
for(auto & slot : leftTradePanel->slots)
|
||||
slot->subtitle = std::to_string(LOCPLINT->cb->getResourceAmount(static_cast<EGameResID>(slot->serial)));
|
||||
});
|
||||
leftTradePanel->moveBy(Point(39, 182));
|
||||
leftTradePanel->updateSlots();
|
||||
return;
|
||||
}
|
||||
if(!Left && mode == EMarketMode::RESOURCE_RESOURCE)
|
||||
{
|
||||
rightTradePanel = std::make_shared<SResourcesPanel>(std::bind(clickPressedTradePanel, _1, false),
|
||||
[this, updRightSub]() -> void
|
||||
{
|
||||
updRightSub(EMarketMode::RESOURCE_RESOURCE);
|
||||
if(hLeft)
|
||||
for(auto & slot : tradePanels[0]->slots)
|
||||
{
|
||||
int h1, h2; //hlp variables for getting offer
|
||||
market->getOffer(hLeft->id, slot->id, h1, h2, EMarketMode::RESOURCE_ARTIFACT);
|
||||
tradePanels[0]->updateOffer(slot->serial, h1, h2);
|
||||
}
|
||||
else
|
||||
tradePanels[0]->clearSubtitles();
|
||||
}, market->availableItemsIds(mode)));
|
||||
tradePanels.back()->moveBy(Point(340, 182));
|
||||
rightTradePanel->slots[hLeft->serial]->subtitle = CGI->generaltexth->allTexts[164]; // n/a
|
||||
});
|
||||
rightTradePanel->moveBy(Point(327, 181));
|
||||
return;
|
||||
}
|
||||
if(!Left && (mode == EMarketMode::ARTIFACT_RESOURCE || mode == EMarketMode::CREATURE_RESOURCE))
|
||||
{
|
||||
rightTradePanel = std::make_shared<SResourcesPanel>(std::bind(clickPressedTradePanel, _1, false),
|
||||
std::bind(updRightSub, EMarketMode::ARTIFACT_RESOURCE));
|
||||
rightTradePanel->moveBy(Point(327, 181));
|
||||
return;
|
||||
}
|
||||
if(!Left && mode == EMarketMode::RESOURCE_ARTIFACT)
|
||||
{
|
||||
rightTradePanel = std::make_shared<SArtifactsPanel>(std::bind(clickPressedTradePanel, _1, false),
|
||||
std::bind(updRightSub, EMarketMode::RESOURCE_ARTIFACT), market->availableItemsIds(mode));
|
||||
rightTradePanel->moveBy(Point(327, 181));
|
||||
return;
|
||||
}
|
||||
if(!Left && mode == EMarketMode::RESOURCE_PLAYER)
|
||||
{
|
||||
rightTradePanel = std::make_shared<SPlayersPanel>(std::bind(clickPressedTradePanel, _1, false));
|
||||
rightTradePanel->moveBy(Point(333, 83));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -267,15 +251,6 @@ void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType typ
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case PLAYER:
|
||||
dx = 83;
|
||||
dy = 118;
|
||||
h = 64;
|
||||
w = 58;
|
||||
x = 44;
|
||||
y = 83;
|
||||
assert(!Left);
|
||||
break;
|
||||
case CREATURE://45,123
|
||||
x = 45;
|
||||
y = 123;
|
||||
@ -313,9 +288,9 @@ void CTradeWindow::initSubs(bool Left)
|
||||
if(itemsType[Left] == RESOURCE || itemsType[Left] == ARTIFACT_TYPE)
|
||||
{
|
||||
if(Left)
|
||||
tradePanels[1]->updateSlots();
|
||||
leftTradePanel->updateSlots();
|
||||
else
|
||||
tradePanels[0]->updateSlots();
|
||||
rightTradePanel->updateSlots();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -330,13 +305,6 @@ void CTradeWindow::initSubs(bool Left)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else //right side
|
||||
{
|
||||
if(itemsType[0] == PLAYER)
|
||||
{
|
||||
item->subtitle = CGI->generaltexth->capColors[item->id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -598,8 +566,10 @@ void CMarketplaceWindow::makeDeal()
|
||||
madeTransaction = true;
|
||||
hLeft = nullptr;
|
||||
hRight = nullptr;
|
||||
for(auto & panel : tradePanels)
|
||||
panel->deselect();
|
||||
if(leftTradePanel)
|
||||
leftTradePanel->deselect();
|
||||
assert(rightTradePanel);
|
||||
rightTradePanel->deselect();
|
||||
selectionChanged(true);
|
||||
}
|
||||
|
||||
@ -760,11 +730,11 @@ Point CMarketplaceWindow::selectionOffset(bool Left) const
|
||||
switch(itemsType[1])
|
||||
{
|
||||
case RESOURCE:
|
||||
return Point(122, 446);
|
||||
return Point(122, 448);
|
||||
case CREATURE:
|
||||
return Point(128, 450);
|
||||
case ARTIFACT_INSTANCE:
|
||||
return Point(134, 466);
|
||||
return Point(134, 469);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -772,12 +742,12 @@ Point CMarketplaceWindow::selectionOffset(bool Left) const
|
||||
switch(itemsType[0])
|
||||
{
|
||||
case RESOURCE:
|
||||
if(mode == EMarketMode::ARTIFACT_RESOURCE)
|
||||
return Point(410, 469);
|
||||
if(mode == EMarketMode::ARTIFACT_RESOURCE)
|
||||
return Point(410, 471);
|
||||
else
|
||||
return Point(410, 446);
|
||||
return Point(410, 448);
|
||||
case ARTIFACT_TYPE:
|
||||
return Point(425, 447);
|
||||
return Point(411, 449);
|
||||
case PLAYER:
|
||||
return Point(417, 451);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user