mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
class CArtifactsOfHeroMain : public CKeyShortcut
This commit is contained in:
parent
ce9d2d8ab8
commit
ce68b3f45d
@ -314,20 +314,12 @@ CKeyShortcut::CKeyShortcut(EShortcut key)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CKeyShortcut::CKeyShortcut(const EShortcut & key, const KeyPressedFunctor & keyPressedCallback)
|
|
||||||
: CKeyShortcut(key)
|
|
||||||
{
|
|
||||||
this->keyPressedCallback = keyPressedCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CKeyShortcut::keyPressed(EShortcut key)
|
void CKeyShortcut::keyPressed(EShortcut key)
|
||||||
{
|
{
|
||||||
if( assignedKey == key && assignedKey != EShortcut::NONE && !shortcutPressed)
|
if( assignedKey == key && assignedKey != EShortcut::NONE && !shortcutPressed)
|
||||||
{
|
{
|
||||||
shortcutPressed = true;
|
shortcutPressed = true;
|
||||||
clickPressed(GH.getCursorPosition());
|
clickPressed(GH.getCursorPosition());
|
||||||
if(keyPressedCallback)
|
|
||||||
keyPressedCallback();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,18 +134,12 @@ public:
|
|||||||
class CKeyShortcut : public virtual CIntObject
|
class CKeyShortcut : public virtual CIntObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using KeyPressedFunctor = std::function<void()>;
|
bool shortcutPressed;
|
||||||
|
|
||||||
EShortcut assignedKey;
|
EShortcut assignedKey;
|
||||||
CKeyShortcut();
|
CKeyShortcut();
|
||||||
CKeyShortcut(EShortcut key);
|
CKeyShortcut(EShortcut key);
|
||||||
CKeyShortcut(const EShortcut & key, const KeyPressedFunctor & keyPressedCallback);
|
|
||||||
void keyPressed(EShortcut key) override;
|
void keyPressed(EShortcut key) override;
|
||||||
void keyReleased(EShortcut key) override;
|
void keyReleased(EShortcut key) override;
|
||||||
|
|
||||||
private:
|
|
||||||
bool shortcutPressed;
|
|
||||||
KeyPressedFunctor keyPressedCallback;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindowBase : public CIntObject
|
class WindowBase : public CIntObject
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
class CButton;
|
class CButton;
|
||||||
|
|
||||||
class CArtifactsOfHeroBase : public CIntObject
|
class CArtifactsOfHeroBase : virtual public CIntObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
using ArtPlacePtr = std::shared_ptr<CHeroArtPlace>;
|
using ArtPlacePtr = std::shared_ptr<CHeroArtPlace>;
|
||||||
|
@ -35,15 +35,56 @@ CArtifactsOfHeroMain::~CArtifactsOfHeroMain()
|
|||||||
|
|
||||||
void CArtifactsOfHeroMain::enableArtifactsCostumeSwitcher()
|
void CArtifactsOfHeroMain::enableArtifactsCostumeSwitcher()
|
||||||
{
|
{
|
||||||
size_t costumeIdx = 0;
|
addUsedEvents(AEventsReceiver::KEYBOARD);
|
||||||
for(const auto & hotkey : costumesSwitcherHotkeys)
|
}
|
||||||
|
|
||||||
|
void CArtifactsOfHeroMain::keyPressed(EShortcut key)
|
||||||
|
{
|
||||||
|
if(!shortcutPressed)
|
||||||
{
|
{
|
||||||
auto keyProc = costumesSwitcherProcessors.emplace_back(std::make_shared<CKeyShortcut>(hotkey,
|
uint32_t costumeIdx;
|
||||||
[this, costumeIdx]()
|
switch(key)
|
||||||
{
|
{
|
||||||
LOCPLINT->cb->manageHeroCostume(getHero()->id, costumeIdx, GH.isKeyboardCtrlDown());
|
case EShortcut::HERO_COSTUME_0:
|
||||||
}));
|
costumeIdx = 0;
|
||||||
keyProc->addUsedEvents(AEventsReceiver::KEYBOARD);
|
break;
|
||||||
costumeIdx++;
|
case EShortcut::HERO_COSTUME_1:
|
||||||
|
costumeIdx = 1;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_2:
|
||||||
|
costumeIdx = 2;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_3:
|
||||||
|
costumeIdx = 3;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_4:
|
||||||
|
costumeIdx = 4;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_5:
|
||||||
|
costumeIdx = 5;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_6:
|
||||||
|
costumeIdx = 6;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_7:
|
||||||
|
costumeIdx = 7;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_8:
|
||||||
|
costumeIdx = 8;
|
||||||
|
break;
|
||||||
|
case EShortcut::HERO_COSTUME_9:
|
||||||
|
costumeIdx = 9;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shortcutPressed = true;
|
||||||
|
LOCPLINT->cb->manageHeroCostume(getHero()->id, costumeIdx, GH.isKeyboardCtrlDown());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CArtifactsOfHeroMain::keyReleased(EShortcut key)
|
||||||
|
{
|
||||||
|
if(vstd::contains(costumesSwitcherHotkeys, key))
|
||||||
|
shortcutPressed = false;
|
||||||
|
}
|
||||||
|
@ -13,12 +13,14 @@
|
|||||||
|
|
||||||
#include "../gui/Shortcut.h"
|
#include "../gui/Shortcut.h"
|
||||||
|
|
||||||
class CArtifactsOfHeroMain : public CArtifactsOfHeroBase
|
class CArtifactsOfHeroMain : public CArtifactsOfHeroBase, public CKeyShortcut
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CArtifactsOfHeroMain(const Point & position);
|
CArtifactsOfHeroMain(const Point & position);
|
||||||
~CArtifactsOfHeroMain() override;
|
~CArtifactsOfHeroMain() override;
|
||||||
void enableArtifactsCostumeSwitcher();
|
void enableArtifactsCostumeSwitcher();
|
||||||
|
void keyPressed(EShortcut key) override;
|
||||||
|
void keyReleased(EShortcut key) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::vector<EShortcut> costumesSwitcherHotkeys =
|
const std::vector<EShortcut> costumesSwitcherHotkeys =
|
||||||
@ -34,5 +36,4 @@ private:
|
|||||||
EShortcut::HERO_COSTUME_8,
|
EShortcut::HERO_COSTUME_8,
|
||||||
EShortcut::HERO_COSTUME_9
|
EShortcut::HERO_COSTUME_9
|
||||||
};
|
};
|
||||||
std::vector<std::shared_ptr<CKeyShortcut>> costumesSwitcherProcessors;
|
|
||||||
};
|
};
|
||||||
|
@ -343,7 +343,7 @@ void CWindowWithArtifacts::deactivate()
|
|||||||
CWindowObject::deactivate();
|
CWindowObject::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowWithArtifacts::enableArtifactsCostumeSwitcher()
|
void CWindowWithArtifacts::enableArtifactsCostumeSwitcher() const
|
||||||
{
|
{
|
||||||
for(auto artSet : artSets)
|
for(auto artSet : artSets)
|
||||||
std::visit(
|
std::visit(
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
void gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
void gestureArtPlaceHero(const CArtifactsOfHeroBase & artsInst, CArtPlace & artPlace, const Point & cursorPosition);
|
||||||
void activate() override;
|
void activate() override;
|
||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
void enableArtifactsCostumeSwitcher();
|
void enableArtifactsCostumeSwitcher() const;
|
||||||
|
|
||||||
virtual void artifactRemoved(const ArtifactLocation & artLoc);
|
virtual void artifactRemoved(const ArtifactLocation & artLoc);
|
||||||
virtual void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw);
|
virtual void artifactMoved(const ArtifactLocation & srcLoc, const ArtifactLocation & destLoc, bool withRedraw);
|
||||||
|
@ -249,7 +249,7 @@ class DLL_LINKAGE CArtifactFittingSet : public CArtifactSet
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CArtifactFittingSet(ArtBearer::ArtBearer Bearer);
|
CArtifactFittingSet(ArtBearer::ArtBearer Bearer);
|
||||||
CArtifactFittingSet(const CArtifactSet & artSet);
|
explicit CArtifactFittingSet(const CArtifactSet & artSet);
|
||||||
ArtBearer::ArtBearer bearerType() const override;
|
ArtBearer::ArtBearer bearerType() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -1078,7 +1078,7 @@ void ChangeArtifactsCostume::applyGs(CGameState * gs) const
|
|||||||
if(const auto & costume = allCostumes.find(costumeIdx); costume != allCostumes.end())
|
if(const auto & costume = allCostumes.find(costumeIdx); costume != allCostumes.end())
|
||||||
costume->second = costumeSet;
|
costume->second = costumeSet;
|
||||||
else
|
else
|
||||||
allCostumes.emplace(costumeIdx, costumeSet);
|
allCostumes.try_emplace(costumeIdx, costumeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerEndsGame::applyGs(CGameState * gs) const
|
void PlayerEndsGame::applyGs(CGameState * gs) const
|
||||||
|
@ -1291,14 +1291,14 @@ struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
|
|||||||
struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
|
struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
|
||||||
{
|
{
|
||||||
std::map<ArtifactPosition, ArtifactID> costumeSet;
|
std::map<ArtifactPosition, ArtifactID> costumeSet;
|
||||||
size_t costumeIdx = 0;
|
uint32_t costumeIdx = 0;
|
||||||
const PlayerColor player = PlayerColor::NEUTRAL;
|
const PlayerColor player = PlayerColor::NEUTRAL;
|
||||||
|
|
||||||
void applyGs(CGameState * gs) const;
|
void applyGs(CGameState * gs) const;
|
||||||
void visitTyped(ICPackVisitor & visitor) override;
|
void visitTyped(ICPackVisitor & visitor) override;
|
||||||
|
|
||||||
ChangeArtifactsCostume() = default;
|
ChangeArtifactsCostume() = default;
|
||||||
ChangeArtifactsCostume(const PlayerColor & player, const size_t costumeIdx)
|
ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
|
||||||
: costumeIdx(costumeIdx)
|
: costumeIdx(costumeIdx)
|
||||||
, player(player)
|
, player(player)
|
||||||
{
|
{
|
||||||
|
@ -432,7 +432,7 @@ struct DLL_LINKAGE ManageBackpackArtifacts : public CPackForServer
|
|||||||
struct DLL_LINKAGE ManageEquippedArtifacts : public CPackForServer
|
struct DLL_LINKAGE ManageEquippedArtifacts : public CPackForServer
|
||||||
{
|
{
|
||||||
ManageEquippedArtifacts() = default;
|
ManageEquippedArtifacts() = default;
|
||||||
ManageEquippedArtifacts(const ObjectInstanceID & artHolder, const size_t costumeIdx, bool saveCostume = false)
|
ManageEquippedArtifacts(const ObjectInstanceID & artHolder, const uint32_t costumeIdx, bool saveCostume = false)
|
||||||
: artHolder(artHolder)
|
: artHolder(artHolder)
|
||||||
, costumeIdx(costumeIdx)
|
, costumeIdx(costumeIdx)
|
||||||
, saveCostume(saveCostume)
|
, saveCostume(saveCostume)
|
||||||
@ -440,7 +440,7 @@ struct DLL_LINKAGE ManageEquippedArtifacts : public CPackForServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectInstanceID artHolder;
|
ObjectInstanceID artHolder;
|
||||||
size_t costumeIdx;
|
uint32_t costumeIdx;
|
||||||
bool saveCostume;
|
bool saveCostume;
|
||||||
|
|
||||||
void visitTyped(ICPackVisitor & visitor) override;
|
void visitTyped(ICPackVisitor & visitor) override;
|
||||||
|
@ -2892,7 +2892,7 @@ bool CGameHandler::scrollBackpackArtifacts(const PlayerColor & player, const Obj
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameHandler::saveArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, size_t costumeIdx)
|
bool CGameHandler::saveArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, uint32_t costumeIdx)
|
||||||
{
|
{
|
||||||
auto artSet = getArtSet(heroID);
|
auto artSet = getArtSet(heroID);
|
||||||
COMPLAIN_RET_FALSE_IF(artSet == nullptr, "saveArtifactsCostume: wrong hero's ID");
|
COMPLAIN_RET_FALSE_IF(artSet == nullptr, "saveArtifactsCostume: wrong hero's ID");
|
||||||
@ -2908,7 +2908,7 @@ bool CGameHandler::saveArtifactsCostume(const PlayerColor & player, const Object
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGameHandler::switchArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, size_t costumeIdx)
|
bool CGameHandler::switchArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, uint32_t costumeIdx)
|
||||||
{
|
{
|
||||||
const auto artSet = getArtSet(heroID);
|
const auto artSet = getArtSet(heroID);
|
||||||
COMPLAIN_RET_FALSE_IF(artSet == nullptr, "switchArtifactsCostume: wrong hero's ID");
|
COMPLAIN_RET_FALSE_IF(artSet == nullptr, "switchArtifactsCostume: wrong hero's ID");
|
||||||
|
@ -130,8 +130,8 @@ public:
|
|||||||
bool moveArtifact(const PlayerColor & player, const ArtifactLocation & src, const ArtifactLocation & dst) override;
|
bool moveArtifact(const PlayerColor & player, const ArtifactLocation & src, const ArtifactLocation & dst) override;
|
||||||
bool bulkMoveArtifacts(const PlayerColor & player, ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack);
|
bool bulkMoveArtifacts(const PlayerColor & player, ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack);
|
||||||
bool scrollBackpackArtifacts(const PlayerColor & player, const ObjectInstanceID heroID, bool left);
|
bool scrollBackpackArtifacts(const PlayerColor & player, const ObjectInstanceID heroID, bool left);
|
||||||
bool saveArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, size_t costumeIdx);
|
bool saveArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, uint32_t costumeIdx);
|
||||||
bool switchArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, size_t costumeIdx);
|
bool switchArtifactsCostume(const PlayerColor & player, const ObjectInstanceID heroID, uint32_t costumeIdx);
|
||||||
bool eraseArtifactByClient(const ArtifactLocation & al);
|
bool eraseArtifactByClient(const ArtifactLocation & al);
|
||||||
void synchronizeArtifactHandlerLists();
|
void synchronizeArtifactHandlerLists();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user