1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

heroes and more buttons

This commit is contained in:
Laserlicht 2023-10-17 21:13:08 +02:00 committed by GitHub
parent d5b16ac96c
commit e05102192b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -42,8 +42,10 @@
"vcmi.radialWheel.moveUnit" : "Move creatures to another army",
"vcmi.radialWheel.splitUnit" : "Split creature to another slot",
"vcmi.radialWheel.townUp" : "Move town up",
"vcmi.radialWheel.townDown" : "Move town down",
"vcmi.radialWheel.moveTop" : "Move to top",
"vcmi.radialWheel.moveUp" : "Move up",
"vcmi.radialWheel.moveDown" : "Move down",
"vcmi.radialWheel.moveBottom" : "Move to bottom",
"vcmi.mainMenu.serverConnecting" : "Connecting...",
"vcmi.mainMenu.serverAddressEnter" : "Enter address:",

View File

@ -235,6 +235,12 @@ void PlayerLocalState::removeWanderingHero(const CGHeroInstance * hero)
setSelection(ownedTowns.front());
}
void PlayerLocalState::swapWanderingHero(int pos1, int pos2)
{
assert(wanderingHeroes[pos1] && wanderingHeroes[pos2]);
std::swap(wanderingHeroes[pos1], wanderingHeroes[pos2]);
}
const std::vector<const CGTownInstance *> & PlayerLocalState::getOwnedTowns()
{
return ownedTowns;

View File

@ -73,6 +73,7 @@ public:
const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
void addWanderingHero(const CGHeroInstance * hero);
void removeWanderingHero(const CGHeroInstance * hero);
void swapWanderingHero(int pos1, int pos2);
void setPath(const CGHeroInstance * h, const CGPath & path);
bool setPath(const CGHeroInstance * h, const int3 & destination);

View File

@ -304,6 +304,7 @@ void AdventureMapInterface::onSelectionChanged(const CArmedInstance *sel)
auto town = dynamic_cast<const CGTownInstance*>(sel);
widget->getInfoBar()->showTownSelection(town);
widget->getTownList()->updateWidget();;
widget->getTownList()->select(town);
widget->getHeroList()->select(nullptr);
onHeroChanged(nullptr);

View File

@ -218,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);
@ -229,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()
@ -264,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)
@ -374,8 +414,8 @@ void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const
if(!on)
return;
const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns();
const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns();
if(townIndex < 0 || townIndex > towns.size() - 1 || !towns[townIndex])
return;
@ -386,8 +426,20 @@ void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const
int townLowerPos = (townIndex > towns.size() - 2) ? -1 : townIndex + 1;
std::vector<RadialMenuConfig> menuElements = {
{ RadialMenuConfig::ITEM_ALT_NW, townUpperPos > -1, "altUp", "vcmi.radialWheel.townUp", [this, townUpperPos](){LOCPLINT->localState->swapOwnedTowns(townIndex, townUpperPos); parentList->updateWidget(); } },
{ RadialMenuConfig::ITEM_ALT_SW, townLowerPos > -1, "altDown", "vcmi.radialWheel.townDown", [this, townLowerPos](){ LOCPLINT->localState->swapOwnedTowns(townIndex, townLowerPos); parentList->updateWidget(); } },
{ RadialMenuConfig::ITEM_ALT_NN, townUpperPos > -1, "altUpTop", "vcmi.radialWheel.moveTop", [this, townUpperPos]()
{
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, townLowerPos, 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);

View File

@ -117,6 +117,7 @@ class CHeroList : public CList
std::shared_ptr<CAnimImage> movement;
std::shared_ptr<CAnimImage> mana;
std::shared_ptr<CAnimImage> portrait;
CHeroList *parentList;
public:
const CGHeroInstance * const hero;
@ -127,6 +128,7 @@ class CHeroList : public CList
void select(bool on) override;
void open() override;
void showTooltip() override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
std::string getHoverText() override;
};
@ -152,7 +154,7 @@ class CTownList : public CList
std::shared_ptr<CAnimImage> picture;
CTownList *parentList;
public:
int townIndex;
int townPos;
CTownItem(CTownList *parent, const CGTownInstance * town);