|
@@ -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,27 +28,97 @@
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
#include "../../lib/networkPacks/ArtifactLocation.h"
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
+#include "../../lib/CSkillHandler.h"
|
|
|
|
|
|
-void CArtPlace::setInternals(const CArtifactInstance * artInst)
|
|
|
+CComponentHolder::CComponentHolder(const Rect & area, const Point & selectionOversize)
|
|
|
+ : SelectableSlot(area, selectionOversize)
|
|
|
{
|
|
|
- ourArt = artInst;
|
|
|
- if(!artInst)
|
|
|
+ setClickPressedCallback([this](const CComponentHolder &, const Point & cursorPosition)
|
|
|
+ {
|
|
|
+ if(text.size())
|
|
|
+ LRClickableAreaWTextComp::clickPressed(cursorPosition);
|
|
|
+ });
|
|
|
+ setShowPopupCallback([this](const CComponentHolder &, const Point & cursorPosition)
|
|
|
+ {
|
|
|
+ if(text.size())
|
|
|
+ LRClickableAreaWTextComp::showPopupWindow(cursorPosition);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+ : CComponentHolder(Rect(position, Point(44, 44)), Point(1, 1))
|
|
|
+ , locked(false)
|
|
|
+ , imageIndex(0)
|
|
|
+{
|
|
|
+ OBJECT_CONSTRUCTION;
|
|
|
+
|
|
|
+ image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), 0);
|
|
|
+ setArtifact(artId, spellId);
|
|
|
+ moveSelectionForeground();
|
|
|
+}
|
|
|
+
|
|
|
+void CArtPlace::setArtifact(const SpellID & newSpellId)
|
|
|
+{
|
|
|
+ setArtifact(ArtifactID::SPELL_SCROLL, newSpellId);
|
|
|
+}
|
|
|
+
|
|
|
+void CArtPlace::setArtifact(const ArtifactID & newArtId, const SpellID & newSpellId)
|
|
|
+{
|
|
|
+ artId = newArtId;
|
|
|
+ if(artId == ArtifactID::NONE)
|
|
|
{
|
|
|
image->disable();
|
|
|
text.clear();
|
|
|
- hoverText = CGI->generaltexth->allTexts[507];
|
|
|
+ lockSlot(false);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- imageIndex = artInst->artType->getIconIndex();
|
|
|
- if(artInst->getTypeId() == ArtifactID::SPELL_SCROLL)
|
|
|
+ const auto artType = artId.toArtifact();
|
|
|
+ imageIndex = artType->getIconIndex();
|
|
|
+ if(artId == ArtifactID::SPELL_SCROLL)
|
|
|
{
|
|
|
- auto spellID = artInst->getScrollSpellID();
|
|
|
- assert(spellID.num >= 0);
|
|
|
+ spellId = newSpellId;
|
|
|
+ assert(spellId.num > 0);
|
|
|
|
|
|
if(settings["general"]["enableUiEnhancements"].Bool())
|
|
|
{
|
|
|
- imageIndex = spellID.num;
|
|
|
+ imageIndex = spellId.num;
|
|
|
if(component.type != ComponentType::SPELL_SCROLL)
|
|
|
{
|
|
|
image->setScale(Point(pos.w, 34));
|
|
@@ -58,7 +128,7 @@ void CArtPlace::setInternals(const CArtifactInstance * artInst)
|
|
|
}
|
|
|
// Add spell component info (used to provide a pic in r-click popup)
|
|
|
component.type = ComponentType::SPELL_SCROLL;
|
|
|
- component.subType = spellID;
|
|
|
+ component.subType = spellId;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -69,47 +139,33 @@ void CArtPlace::setInternals(const CArtifactInstance * artInst)
|
|
|
image->moveTo(Point(pos.x, pos.y));
|
|
|
}
|
|
|
component.type = ComponentType::ARTIFACT;
|
|
|
- component.subType = artInst->getTypeId();
|
|
|
+ component.subType = artId;
|
|
|
}
|
|
|
image->enable();
|
|
|
- text = artInst->getDescription();
|
|
|
-}
|
|
|
-
|
|
|
-CArtPlace::CArtPlace(Point position, const CArtifactInstance * art)
|
|
|
- : SelectableSlot(Rect(position, Point(44, 44)), Point(1, 1))
|
|
|
- , ourArt(art)
|
|
|
- , locked(false)
|
|
|
-{
|
|
|
- OBJECT_CONSTRUCTION;
|
|
|
+ lockSlot(locked);
|
|
|
|
|
|
- imageIndex = 0;
|
|
|
- if(locked)
|
|
|
- imageIndex = ArtifactID::ART_LOCK;
|
|
|
- else if(ourArt)
|
|
|
- imageIndex = ourArt->artType->getIconIndex();
|
|
|
-
|
|
|
- image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), imageIndex);
|
|
|
- image->disable();
|
|
|
- moveSelectionForeground();
|
|
|
+ text = artType->getDescriptionTranslated();
|
|
|
+ if(artType->isScroll())
|
|
|
+ ArtifactUtils::insertScrrollSpellName(text, spellId);
|
|
|
}
|
|
|
|
|
|
-const CArtifactInstance * CArtPlace::getArt() const
|
|
|
+ArtifactID CArtPlace::getArtifactId() const
|
|
|
{
|
|
|
- return ourArt;
|
|
|
+ return artId;
|
|
|
}
|
|
|
|
|
|
-CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * art)
|
|
|
- : CArtPlace(position, art),
|
|
|
+CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot,
|
|
|
+ const ArtifactID & artId, const SpellID & spellId)
|
|
|
+ : CArtPlace(position, artId, spellId),
|
|
|
commanderOwner(commanderOwner),
|
|
|
commanderSlotID(artSlot.num)
|
|
|
{
|
|
|
- setArtifact(art);
|
|
|
}
|
|
|
|
|
|
void CCommanderArtPlace::returnArtToHeroCallback()
|
|
|
{
|
|
|
ArtifactPosition artifactPos = commanderSlotID;
|
|
|
- ArtifactPosition freeSlot = ArtifactUtils::getArtBackpackPosition(commanderOwner, getArt()->getTypeId());
|
|
|
+ ArtifactPosition freeSlot = ArtifactUtils::getArtBackpackPosition(commanderOwner, getArtifactId());
|
|
|
if(freeSlot == ArtifactPosition::PRE_FIRST)
|
|
|
{
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("core.genrltxt.152"));
|
|
@@ -120,10 +176,10 @@ void CCommanderArtPlace::returnArtToHeroCallback()
|
|
|
src.creature = SlotID::COMMANDER_SLOT_PLACEHOLDER;
|
|
|
ArtifactLocation dst(commanderOwner->id, freeSlot);
|
|
|
|
|
|
- if(getArt()->canBePutAt(commanderOwner, freeSlot, true))
|
|
|
+ if(getArtifactId().toArtifact()->canBePutAt(commanderOwner, freeSlot, true))
|
|
|
{
|
|
|
LOCPLINT->cb->swapArtifacts(src, dst);
|
|
|
- setArtifact(nullptr);
|
|
|
+ setArtifact(ArtifactID(ArtifactID::NONE));
|
|
|
parent->redraw();
|
|
|
}
|
|
|
}
|
|
@@ -131,88 +187,40 @@ void CCommanderArtPlace::returnArtToHeroCallback()
|
|
|
|
|
|
void CCommanderArtPlace::clickPressed(const Point & cursorPosition)
|
|
|
{
|
|
|
- if(getArt() && text.size())
|
|
|
+ if(getArtifactId() != ArtifactID::NONE && text.size())
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->translate("vcmi.commanderWindow.artifactMessage"), [this]() { returnArtToHeroCallback(); }, []() {});
|
|
|
}
|
|
|
|
|
|
void CCommanderArtPlace::showPopupWindow(const Point & cursorPosition)
|
|
|
{
|
|
|
- if(getArt() && text.size())
|
|
|
+ if(getArtifactId() != ArtifactID::NONE && text.size())
|
|
|
CArtPlace::showPopupWindow(cursorPosition);
|
|
|
}
|
|
|
|
|
|
void CArtPlace::lockSlot(bool on)
|
|
|
{
|
|
|
- if(locked == on)
|
|
|
- return;
|
|
|
-
|
|
|
locked = on;
|
|
|
-
|
|
|
if(on)
|
|
|
+ {
|
|
|
image->setFrame(ArtifactID::ART_LOCK);
|
|
|
- else if(ourArt)
|
|
|
- image->setFrame(imageIndex);
|
|
|
- else
|
|
|
- image->setFrame(0);
|
|
|
-}
|
|
|
-
|
|
|
-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::setArtifact(const CArtifactInstance * art)
|
|
|
-{
|
|
|
- setInternals(art);
|
|
|
- if(art)
|
|
|
+ hoverText = CGI->generaltexth->allTexts[507];
|
|
|
+ }
|
|
|
+ else if(artId != ArtifactID::NONE)
|
|
|
{
|
|
|
- image->setFrame(locked ? static_cast<int>(ArtifactID::ART_LOCK) : imageIndex);
|
|
|
-
|
|
|
- if(locked) // Locks should appear as empty.
|
|
|
- hoverText = CGI->generaltexth->allTexts[507];
|
|
|
- else
|
|
|
- hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % ourArt->artType->getNameTranslated());
|
|
|
+ image->setFrame(imageIndex);
|
|
|
+ auto hoverText = MetaString::createFromRawString(CGI->generaltexth->heroscrn[1]);
|
|
|
+ hoverText.replaceName(artId);
|
|
|
+ this->hoverText = hoverText.toString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- lockSlot(false);
|
|
|
+ hoverText = CGI->generaltexth->allTexts[507];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CArtPlace::setClickPressedCallback(const ClickFunctor & callback)
|
|
|
-{
|
|
|
- clickPressedCallback = callback;
|
|
|
-}
|
|
|
-
|
|
|
-void CArtPlace::setShowPopupCallback(const ClickFunctor & callback)
|
|
|
-{
|
|
|
- showPopupCallback = callback;
|
|
|
-}
|
|
|
-
|
|
|
-void CArtPlace::setGestureCallback(const ClickFunctor & callback)
|
|
|
+bool CArtPlace::isLocked() const
|
|
|
{
|
|
|
- gestureCallback = callback;
|
|
|
+ return locked;
|
|
|
}
|
|
|
|
|
|
void CArtPlace::addCombinedArtInfo(const std::map<const ArtifactID, std::vector<ArtifactID>> & arts)
|
|
@@ -252,3 +260,55 @@ void CArtPlace::addCombinedArtInfo(const std::map<const ArtifactID, std::vector<
|
|
|
text += info.toString();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+CSecSkillPlace::CSecSkillPlace(const Point & position, const ImageSize & imageSize, const SecondarySkill & newSkillId, const uint8_t level)
|
|
|
+ : CComponentHolder(Rect(position, Point()), Point())
|
|
|
+{
|
|
|
+ OBJECT_CONSTRUCTION;
|
|
|
+
|
|
|
+ auto imagePath = AnimationPath::builtin("SECSKILL");
|
|
|
+ if(imageSize == ImageSize::MEDIUM)
|
|
|
+ imagePath = AnimationPath::builtin("SECSK32");
|
|
|
+ if(imageSize == ImageSize::SMALL)
|
|
|
+ imagePath = AnimationPath::builtin("SECSK82");
|
|
|
+
|
|
|
+ image = std::make_shared<CAnimImage>(imagePath, 0);
|
|
|
+ component.type = ComponentType::SEC_SKILL;
|
|
|
+ pos.w = image->pos.w;
|
|
|
+ pos.h = image->pos.h;
|
|
|
+ setSkill(newSkillId, level);
|
|
|
+}
|
|
|
+
|
|
|
+void CSecSkillPlace::setSkill(const SecondarySkill & newSkillId, const uint8_t level)
|
|
|
+{
|
|
|
+ skillId = newSkillId;
|
|
|
+ component.subType = newSkillId;
|
|
|
+ setLevel(level);
|
|
|
+}
|
|
|
+
|
|
|
+void CSecSkillPlace::setLevel(const uint8_t level)
|
|
|
+{
|
|
|
+ // 0 - none
|
|
|
+ // 1 - base
|
|
|
+ // 2 - advanced
|
|
|
+ // 3 - expert
|
|
|
+ assert(level <= 3);
|
|
|
+ if(skillId != SecondarySkill::NONE && level > 0)
|
|
|
+ {
|
|
|
+ const auto secSkill = skillId.toSkill();
|
|
|
+ image->setFrame(secSkill->getIconIndex(level - 1));
|
|
|
+ image->enable();
|
|
|
+ auto hoverText = MetaString::createFromRawString(CGI->generaltexth->heroscrn[21]);
|
|
|
+ hoverText.replaceRawString(CGI->generaltexth->levels[level - 1]);
|
|
|
+ hoverText.replaceTextID(secSkill->getNameTextID());
|
|
|
+ this->hoverText = hoverText.toString();
|
|
|
+ component.value = level;
|
|
|
+ text = secSkill->getDescriptionTranslated(level);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ image->disable();
|
|
|
+ hoverText.clear();
|
|
|
+ text.clear();
|
|
|
+ }
|
|
|
+}
|