1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

CSecSkillPlace

This commit is contained in:
SoundSSGood 2024-10-20 15:27:21 +03:00
parent 7955960901
commit 03b4733c64
8 changed files with 131 additions and 89 deletions

View File

@ -116,8 +116,8 @@ set(vcmiclientcommon_SRCS
globalLobby/GlobalLobbyWindow.cpp
widgets/Buttons.cpp
widgets/CArtPlace.cpp
widgets/CComponent.cpp
widgets/CComponentHolder.cpp
widgets/CExchangeController.cpp
widgets/CGarrisonInt.cpp
widgets/CreatureCostBox.cpp
@ -327,8 +327,8 @@ set(vcmiclientcommon_HEADERS
globalLobby/GlobalLobbyWindow.h
widgets/Buttons.h
widgets/CArtPlace.h
widgets/CComponent.h
widgets/CComponentHolder.h
widgets/CExchangeController.h
widgets/CGarrisonInt.h
widgets/CreatureCostBox.h

View File

@ -89,31 +89,40 @@ void CArtifactsOfHeroBase::init(
setRedrawParent(true);
}
void CArtifactsOfHeroBase::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
void CArtifactsOfHeroBase::clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
{
if(artPlace.isLocked())
auto ownedPlace = getArtPlace(cursorPosition);
assert(ownedPlace != nullptr);
if(ownedPlace->isLocked())
return;
if(clickPressedCallback)
clickPressedCallback(artPlace, cursorPosition);
clickPressedCallback(*ownedPlace, cursorPosition);
}
void CArtifactsOfHeroBase::showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
void CArtifactsOfHeroBase::showPopupArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
{
if(artPlace.isLocked())
auto ownedPlace = getArtPlace(cursorPosition);
assert(ownedPlace != nullptr);
if(ownedPlace->isLocked())
return;
if(showPopupCallback)
showPopupCallback(artPlace, cursorPosition);
showPopupCallback(*ownedPlace, cursorPosition);
}
void CArtifactsOfHeroBase::gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
void CArtifactsOfHeroBase::gestureArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
{
if(artPlace.isLocked())
auto ownedPlace = getArtPlace(cursorPosition);
assert(ownedPlace != nullptr);
if(ownedPlace->isLocked())
return;
if(gestureCallback)
gestureCallback(artPlace, cursorPosition);
gestureCallback(*ownedPlace, cursorPosition);
}
void CArtifactsOfHeroBase::setHero(const CGHeroInstance * hero)
@ -156,24 +165,16 @@ CArtifactsOfHeroBase::ArtPlacePtr CArtifactsOfHeroBase::getArtPlace(const Artifa
{
if(ArtifactUtils::isSlotEquipment(slot))
{
if(artWorn.find(slot) == artWorn.end())
{
logGlobal->error("CArtifactsOfHero::getArtPlace: invalid slot %d", slot);
return nullptr;
}
return artWorn[slot];
if(artWorn.find(slot) != artWorn.end())
return artWorn[slot];
}
if(ArtifactUtils::isSlotBackpack(slot))
{
for(ArtPlacePtr artPlace : backpack)
if(artPlace->slot == slot)
return artPlace;
return nullptr;
}
else
{
return nullptr;
if(slot - ArtifactPosition::BACKPACK_START < backpack.size())
return(backpack[slot - ArtifactPosition::BACKPACK_START]);
}
logGlobal->error("CArtifactsOfHero::getArtPlace: invalid slot %d", slot);
return nullptr;
}
CArtifactsOfHeroBase::ArtPlacePtr CArtifactsOfHeroBase::getArtPlace(const Point & cursorPosition)

View File

@ -9,7 +9,7 @@
*/
#pragma once
#include "CArtPlace.h"
#include "CComponentHolder.h"
#include "Scrollable.h"
#include "../gui/Shortcut.h"
@ -33,9 +33,9 @@ public:
CArtifactsOfHeroBase();
virtual void putBackPickedArtifact();
virtual void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void showPopupArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void gestureArtPlace(CArtPlace & artPlace, const Point & cursorPosition);
virtual void clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
virtual void showPopupArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
virtual void gestureArtPlace(CComponentHolder & artPlace, const Point & cursorPosition);
virtual void setHero(const CGHeroInstance * hero);
virtual const CGHeroInstance * getHero() const;
virtual void scrollBackpack(bool left);

View File

@ -22,18 +22,21 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position, const int
artPlace->setSelectionWidth(selectionWidth);
};
void CArtifactsOfHeroMarket::clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition)
void CArtifactsOfHeroMarket::clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition)
{
if(artPlace.isLocked())
auto ownedPlace = getArtPlace(cursorPosition);
assert(ownedPlace != nullptr);
if(ownedPlace->isLocked())
return;
if(const auto art = getArt(artPlace.slot))
if(const auto art = getArt(ownedPlace->slot))
{
if(onSelectArtCallback && art->artType->isTradable())
{
unmarkSlots();
artPlace.selectSlot(true);
onSelectArtCallback(&artPlace);
onSelectArtCallback(ownedPlace.get());
}
else
{

View File

@ -18,5 +18,5 @@ public:
std::function<void()> onClickNotTradableCallback;
CArtifactsOfHeroMarket(const Point & position, const int selectionWidth);
void clickPrassedArtPlace(CArtPlace & artPlace, const Point & cursorPosition) override;
void clickPrassedArtPlace(CComponentHolder & artPlace, const Point & cursorPosition) override;
};

View File

@ -1,5 +1,5 @@
/*
* CArtPlace.cpp, part of VCMI engine
* CComponentHolder.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@ -8,14 +8,14 @@
*
*/
#include "StdInc.h"
#include "CArtPlace.h"
#include "CComponentHolder.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "CComponent.h"
#include "Images.h"
#include "../windows/GUIClasses.h"
#include "../render/Canvas.h"
#include "../render/Colors.h"
#include "../render/IRenderHandler.h"
@ -28,9 +28,51 @@
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/networkPacks/ArtifactLocation.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CSkillHandler.h"
CComponentHolder::CComponentHolder(const Rect & area, const Point & selectionOversize)
: SelectableSlot(area, selectionOversize)
{
}
void CComponentHolder::setClickPressedCallback(const ClickFunctor & callback)
{
clickPressedCallback = callback;
}
void CComponentHolder::setShowPopupCallback(const ClickFunctor & callback)
{
showPopupCallback = callback;
}
void CComponentHolder::setGestureCallback(const ClickFunctor & callback)
{
gestureCallback = callback;
}
void CComponentHolder::clickPressed(const Point & cursorPosition)
{
if(clickPressedCallback)
clickPressedCallback(*this, cursorPosition);
}
void CComponentHolder::showPopupWindow(const Point & cursorPosition)
{
if(showPopupCallback)
showPopupCallback(*this, cursorPosition);
}
void CComponentHolder::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
if(!on)
return;
if(gestureCallback)
gestureCallback(*this, initialPosition);
}
CArtPlace::CArtPlace(Point position, const ArtifactID & artId, const SpellID & spellId)
: SelectableSlot(Rect(position, Point(44, 44)), Point(1, 1))
: CComponentHolder(Rect(position, Point(44, 44)), Point(1, 1))
, locked(false)
, imageIndex(0)
{
@ -171,42 +213,6 @@ bool CArtPlace::isLocked() const
return locked;
}
void CArtPlace::clickPressed(const Point & cursorPosition)
{
if(clickPressedCallback)
clickPressedCallback(*this, cursorPosition);
}
void CArtPlace::showPopupWindow(const Point & cursorPosition)
{
if(showPopupCallback)
showPopupCallback(*this, cursorPosition);
}
void CArtPlace::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
{
if(!on)
return;
if(gestureCallback)
gestureCallback(*this, initialPosition);
}
void CArtPlace::setClickPressedCallback(const ClickFunctor & callback)
{
clickPressedCallback = callback;
}
void CArtPlace::setShowPopupCallback(const ClickFunctor & callback)
{
showPopupCallback = callback;
}
void CArtPlace::setGestureCallback(const ClickFunctor & callback)
{
gestureCallback = callback;
}
void CArtPlace::addCombinedArtInfo(const std::map<const ArtifactID, std::vector<ArtifactID>> & arts)
{
for(auto [combinedId, availableArts] : arts)
@ -244,3 +250,17 @@ void CArtPlace::addCombinedArtInfo(const std::map<const ArtifactID, std::vector<
text += info.toString();
}
}
CSecSkillPlace::CSecSkillPlace(const Point & position, const SecondarySkill & skillId)
: CComponentHolder(Rect(position, Point(44, 44)), Point())
{
OBJECT_CONSTRUCTION;
image = std::make_shared<CAnimImage>(AnimationPath::builtin("SECSKILL"), 0);
setSkill(skillId);
}
void CSecSkillPlace::setSkill(const SecondarySkill & skillId)
{
//skillId.toSkill()->getIconIndex();
}

View File

@ -1,5 +1,5 @@
/*
* CArtPlace.h, part of VCMI engine
* CComponentHolder.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@ -13,11 +13,29 @@
class CAnimImage;
class CArtPlace : public SelectableSlot
class CComponentHolder : public SelectableSlot
{
public:
using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
using ClickFunctor = std::function<void(CComponentHolder&, const Point&)>;
ClickFunctor clickPressedCallback;
ClickFunctor showPopupCallback;
ClickFunctor gestureCallback;
std::shared_ptr<CAnimImage> image;
CComponentHolder(const Rect & area, const Point & selectionOversize);
void setClickPressedCallback(const ClickFunctor & callback);
void setShowPopupCallback(const ClickFunctor & callback);
void setGestureCallback(const ClickFunctor & callback);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
virtual ~CComponentHolder() = default;
};
class CArtPlace : public CComponentHolder
{
public:
ArtifactPosition slot;
CArtPlace(Point position, const ArtifactID & artId = ArtifactID::NONE, const SpellID & spellId = SpellID::NONE);
@ -26,12 +44,6 @@ public:
ArtifactID getArtifactId() const;
void lockSlot(bool on);
bool isLocked() const;
void setClickPressedCallback(const ClickFunctor & callback);
void setShowPopupCallback(const ClickFunctor & callback);
void setGestureCallback(const ClickFunctor & callback);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
void addCombinedArtInfo(const std::map<const ArtifactID, std::vector<ArtifactID>> & arts);
private:
@ -39,10 +51,6 @@ private:
SpellID spellId;
bool locked;
int32_t imageIndex;
std::shared_ptr<CAnimImage> image;
ClickFunctor clickPressedCallback;
ClickFunctor showPopupCallback;
ClickFunctor gestureCallback;
};
class CCommanderArtPlace : public CArtPlace
@ -59,3 +67,13 @@ public:
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
};
class CSecSkillPlace : public CComponentHolder
{
public:
CSecSkillPlace(const Point & position, const SecondarySkill & skillId = SecondarySkill::NONE);
void setSkill(const SecondarySkill & skillId);
private:
SecondarySkill skillId;
};

View File

@ -17,8 +17,8 @@
#include "../CPlayerInterface.h"
#include "../render/Canvas.h"
#include "../widgets/Buttons.h"
#include "../widgets/CArtPlace.h"
#include "../widgets/CComponent.h"
#include "../widgets/CComponentHolder.h"
#include "../widgets/Images.h"
#include "../widgets/TextControls.h"
#include "../widgets/ObjectLists.h"
@ -619,7 +619,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
if(art)
{
parent->stackArtifact = std::make_shared<CArtPlace>(pos, art->getTypeId());
parent->stackArtifact->setShowPopupCallback([](CArtPlace & artPlace, const Point & cursorPosition)
parent->stackArtifact->setShowPopupCallback([](CComponentHolder & artPlace, const Point & cursorPosition)
{
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
});