|
|
@@ -16,11 +16,13 @@
|
|
|
#include "../widgets/Images.h"
|
|
|
#include "../widgets/Buttons.h"
|
|
|
#include "../widgets/ObjectLists.h"
|
|
|
+#include "../widgets/RadialMenu.h"
|
|
|
#include "../windows/InfoWindows.h"
|
|
|
#include "../CGameInfo.h"
|
|
|
#include "../CPlayerInterface.h"
|
|
|
#include "../PlayerLocalState.h"
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
+#include "../gui/WindowHandler.h"
|
|
|
#include "../render/Canvas.h"
|
|
|
#include "../render/Colors.h"
|
|
|
|
|
|
@@ -216,7 +218,8 @@ CHeroList::CEmptyHeroItem::CEmptyHeroItem()
|
|
|
|
|
|
CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero)
|
|
|
: CListItem(parent),
|
|
|
- hero(Hero)
|
|
|
+ hero(Hero),
|
|
|
+ parentList(parent)
|
|
|
{
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
movement = std::make_shared<CAnimImage>(AnimationPath::builtin("IMOBIL"), 0, 0, 0, 1);
|
|
|
@@ -227,6 +230,8 @@ CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero)
|
|
|
pos.h = std::max(std::max<int>(movement->pos.h + 1, mana->pos.h + 1), portrait->pos.h);
|
|
|
|
|
|
update();
|
|
|
+
|
|
|
+ addUsedEvents(GESTURE);
|
|
|
}
|
|
|
|
|
|
void CHeroList::CHeroItem::update()
|
|
|
@@ -262,6 +267,43 @@ std::string CHeroList::CHeroItem::getHoverText()
|
|
|
return boost::str(boost::format(CGI->generaltexth->allTexts[15]) % hero->getNameTranslated() % hero->type->heroClass->getNameTranslated());
|
|
|
}
|
|
|
|
|
|
+void CHeroList::CHeroItem::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
|
|
+{
|
|
|
+ if(!on)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if(!hero)
|
|
|
+ return;
|
|
|
+
|
|
|
+ auto & heroes = LOCPLINT->localState->getWanderingHeroes();
|
|
|
+
|
|
|
+ if(heroes.size() < 2)
|
|
|
+ return;
|
|
|
+
|
|
|
+ int heroPos = vstd::find_pos(heroes, hero);
|
|
|
+ const CGHeroInstance * heroUpper = (heroPos < 1) ? nullptr : heroes[heroPos - 1];
|
|
|
+ const CGHeroInstance * heroLower = (heroPos > heroes.size() - 2) ? nullptr : heroes[heroPos + 1];
|
|
|
+
|
|
|
+ std::vector<RadialMenuConfig> menuElements = {
|
|
|
+ { RadialMenuConfig::ITEM_ALT_NN, heroUpper != nullptr, "altUpTop", "vcmi.radialWheel.moveTop", [this, heroPos]()
|
|
|
+ {
|
|
|
+ for (int i = heroPos; i > 0; i--)
|
|
|
+ LOCPLINT->localState->swapWanderingHero(i, i - 1);
|
|
|
+ parentList->updateWidget();
|
|
|
+ } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_NW, heroUpper != nullptr, "altUp", "vcmi.radialWheel.moveUp", [this, heroPos](){LOCPLINT->localState->swapWanderingHero(heroPos, heroPos - 1); parentList->updateWidget(); } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_SW, heroLower != nullptr, "altDown", "vcmi.radialWheel.moveDown", [this, heroPos](){ LOCPLINT->localState->swapWanderingHero(heroPos, heroPos + 1); parentList->updateWidget(); } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_SS, heroLower != nullptr, "altDownBottom", "vcmi.radialWheel.moveBottom", [this, heroPos, heroes]()
|
|
|
+ {
|
|
|
+ for (int i = heroPos; i < heroes.size() - 1; i++)
|
|
|
+ LOCPLINT->localState->swapWanderingHero(i, i + 1);
|
|
|
+ parentList->updateWidget();
|
|
|
+ } },
|
|
|
+ };
|
|
|
+
|
|
|
+ GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
|
|
|
+}
|
|
|
+
|
|
|
std::shared_ptr<CIntObject> CHeroList::createItem(size_t index)
|
|
|
{
|
|
|
if (LOCPLINT->localState->getWanderingHeroes().size() > index)
|
|
|
@@ -293,7 +335,7 @@ void CHeroList::updateWidget()
|
|
|
|
|
|
for (size_t i = 0; i < heroes.size(); ++i)
|
|
|
{
|
|
|
- auto item = std::dynamic_pointer_cast<CHeroItem>(listBox->getItem(i));
|
|
|
+ auto item = std::dynamic_pointer_cast<CHeroItem>(listBox->getItem(i));
|
|
|
|
|
|
if (!item)
|
|
|
continue;
|
|
|
@@ -324,12 +366,17 @@ std::shared_ptr<CIntObject> CTownList::createItem(size_t index)
|
|
|
|
|
|
CTownList::CTownItem::CTownItem(CTownList *parent, const CGTownInstance *Town):
|
|
|
CListItem(parent),
|
|
|
- town(Town)
|
|
|
+ parentList(parent)
|
|
|
{
|
|
|
+ const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns();
|
|
|
+ townIndex = std::distance(towns.begin(), std::find(towns.begin(), towns.end(), Town));
|
|
|
+
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
picture = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), 0);
|
|
|
pos = picture->pos;
|
|
|
update();
|
|
|
+
|
|
|
+ addUsedEvents(GESTURE);
|
|
|
}
|
|
|
|
|
|
std::shared_ptr<CIntObject> CTownList::CTownItem::genSelection()
|
|
|
@@ -339,6 +386,7 @@ std::shared_ptr<CIntObject> CTownList::CTownItem::genSelection()
|
|
|
|
|
|
void CTownList::CTownItem::update()
|
|
|
{
|
|
|
+ const CGTownInstance * town = LOCPLINT->localState->getOwnedTowns()[townIndex];
|
|
|
size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
|
|
|
|
|
|
picture->setFrame(iconIndex + 2);
|
|
|
@@ -348,22 +396,58 @@ void CTownList::CTownItem::update()
|
|
|
void CTownList::CTownItem::select(bool on)
|
|
|
{
|
|
|
if(on)
|
|
|
- LOCPLINT->localState->setSelection(town);
|
|
|
+ LOCPLINT->localState->setSelection(LOCPLINT->localState->getOwnedTowns()[townIndex]);
|
|
|
}
|
|
|
|
|
|
void CTownList::CTownItem::open()
|
|
|
{
|
|
|
- LOCPLINT->openTownWindow(town);
|
|
|
+ LOCPLINT->openTownWindow(LOCPLINT->localState->getOwnedTowns()[townIndex]);
|
|
|
}
|
|
|
|
|
|
void CTownList::CTownItem::showTooltip()
|
|
|
{
|
|
|
- CRClickPopup::createAndPush(town, GH.getCursorPosition());
|
|
|
+ CRClickPopup::createAndPush(LOCPLINT->localState->getOwnedTowns()[townIndex], GH.getCursorPosition());
|
|
|
+}
|
|
|
+
|
|
|
+void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
|
|
+{
|
|
|
+ if(!on)
|
|
|
+ return;
|
|
|
+
|
|
|
+ const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns();
|
|
|
+
|
|
|
+ if(townIndex < 0 || townIndex > towns.size() - 1 || !towns[townIndex])
|
|
|
+ return;
|
|
|
+
|
|
|
+ if(towns.size() < 2)
|
|
|
+ return;
|
|
|
+
|
|
|
+ int townUpperPos = (townIndex < 1) ? -1 : townIndex - 1;
|
|
|
+ int townLowerPos = (townIndex > towns.size() - 2) ? -1 : townIndex + 1;
|
|
|
+
|
|
|
+ std::vector<RadialMenuConfig> menuElements = {
|
|
|
+ { RadialMenuConfig::ITEM_ALT_NN, townUpperPos > -1, "altUpTop", "vcmi.radialWheel.moveTop", [this]()
|
|
|
+ {
|
|
|
+ for (int i = townIndex; i > 0; i--)
|
|
|
+ LOCPLINT->localState->swapOwnedTowns(i, i - 1);
|
|
|
+ parentList->updateWidget();
|
|
|
+ } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_NW, townUpperPos > -1, "altUp", "vcmi.radialWheel.moveUp", [this, townUpperPos](){LOCPLINT->localState->swapOwnedTowns(townIndex, townUpperPos); parentList->updateWidget(); } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_SW, townLowerPos > -1, "altDown", "vcmi.radialWheel.moveDown", [this, townLowerPos](){ LOCPLINT->localState->swapOwnedTowns(townIndex, townLowerPos); parentList->updateWidget(); } },
|
|
|
+ { RadialMenuConfig::ITEM_ALT_SS, townLowerPos > -1, "altDownBottom", "vcmi.radialWheel.moveBottom", [this, towns]()
|
|
|
+ {
|
|
|
+ for (int i = townIndex; i < towns.size() - 1; i++)
|
|
|
+ LOCPLINT->localState->swapOwnedTowns(i, i + 1);
|
|
|
+ parentList->updateWidget();
|
|
|
+ } },
|
|
|
+ };
|
|
|
+
|
|
|
+ GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements, true);
|
|
|
}
|
|
|
|
|
|
std::string CTownList::CTownItem::getHoverText()
|
|
|
{
|
|
|
- return town->getObjectName();
|
|
|
+ return LOCPLINT->localState->getOwnedTowns()[townIndex]->getObjectName();
|
|
|
}
|
|
|
|
|
|
CTownList::CTownList(int visibleItemsCount, Rect widgetPosition, Point firstItemOffset, Point itemOffsetDelta, size_t initialItemsCount)
|
|
|
@@ -390,20 +474,12 @@ void CTownList::updateWidget()
|
|
|
|
|
|
for (size_t i = 0; i < towns.size(); ++i)
|
|
|
{
|
|
|
- auto item = std::dynamic_pointer_cast<CTownItem>(listBox->getItem(i));
|
|
|
+ auto item = std::dynamic_pointer_cast<CTownItem>(listBox->getItem(i));
|
|
|
|
|
|
if (!item)
|
|
|
continue;
|
|
|
|
|
|
- if (item->town == towns[i])
|
|
|
- {
|
|
|
- item->update();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- listBox->reset();
|
|
|
- break;
|
|
|
- }
|
|
|
+ listBox->reset();
|
|
|
}
|
|
|
|
|
|
if (LOCPLINT->localState->getCurrentTown())
|