2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CCreatureWindow.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "CCreatureWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include <vcmi/spells/Spell.h>
|
|
|
|
#include <vcmi/spells/Service.h>
|
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/Buttons.h"
|
2016-11-04 18:54:09 +02:00
|
|
|
#include "../widgets/CArtifactHolder.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
|
|
|
#include "../widgets/Images.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
2014-07-14 17:44:15 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-02-02 21:15:13 +02:00
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "../../lib/CStack.h"
|
2014-07-14 17:23:24 +03:00
|
|
|
#include "../../lib/CBonusTypeHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CModHandler.h"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "../../lib/GameSettings.h"
|
2014-07-14 17:23:24 +03:00
|
|
|
#include "../../lib/CHeroHandler.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/CGameState.h"
|
2023-02-12 23:52:35 +02:00
|
|
|
#include "../../lib/TextOperations.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-02-10 13:32:21 +03:00
|
|
|
class CCreatureArtifactInstance;
|
2012-07-03 11:07:34 +03:00
|
|
|
class CSelectableSkill;
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
class UnitView
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
public:
|
2014-06-27 18:33:30 +03:00
|
|
|
// helper structs
|
|
|
|
struct CommanderLevelInfo
|
2011-05-13 17:33:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
std::vector<ui32> skills;
|
|
|
|
std::function<void(ui32)> callback;
|
|
|
|
};
|
|
|
|
struct StackDismissInfo
|
|
|
|
{
|
|
|
|
std::function<void()> callback;
|
|
|
|
};
|
|
|
|
struct StackUpgradeInfo
|
|
|
|
{
|
|
|
|
UpgradeInfo info;
|
|
|
|
std::function<void(CreatureID)> callback;
|
|
|
|
};
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// pointers to permament objects in game state
|
|
|
|
const CCreature * creature;
|
|
|
|
const CCommanderInstance * commander;
|
|
|
|
const CStackInstance * stackNode;
|
2014-09-19 16:31:01 +03:00
|
|
|
const CStack * stack;
|
2014-06-27 18:33:30 +03:00
|
|
|
const CGHeroInstance * owner;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// temporary objects which should be kept as copy if needed
|
2023-04-16 19:42:56 +02:00
|
|
|
std::optional<CommanderLevelInfo> levelupInfo;
|
|
|
|
std::optional<StackDismissInfo> dismissInfo;
|
|
|
|
std::optional<StackUpgradeInfo> upgradeInfo;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// misc fields
|
|
|
|
unsigned int creatureCount;
|
|
|
|
bool popupWindow;
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
UnitView()
|
|
|
|
: creature(nullptr),
|
|
|
|
commander(nullptr),
|
|
|
|
stackNode(nullptr),
|
|
|
|
stack(nullptr),
|
|
|
|
owner(nullptr),
|
|
|
|
creatureCount(0),
|
|
|
|
popupWindow(false)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::string getName() const
|
|
|
|
{
|
|
|
|
if(commander)
|
2023-01-02 18:00:51 +02:00
|
|
|
return commander->type->getNameSingularTranslated();
|
2018-04-07 13:34:11 +02:00
|
|
|
else
|
2023-01-02 18:00:51 +02:00
|
|
|
return creature->getNamePluralTranslated();
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
private:
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
};
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CCommanderSkillIcon::CCommanderSkillIcon(std::shared_ptr<CIntObject> object_, std::function<void()> callback)
|
|
|
|
: object(),
|
|
|
|
callback(callback)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
pos = object_->pos;
|
|
|
|
setObject(object_);
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CCommanderSkillIcon::setObject(std::shared_ptr<CIntObject> newObject)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(object)
|
|
|
|
removeChild(object.get());
|
|
|
|
object = newObject;
|
|
|
|
addChild(object.get());
|
|
|
|
object->moveTo(pos.topLeft());
|
|
|
|
redraw();
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-08-05 10:59:15 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CCommanderSkillIcon::clickLeft(tribool down, bool previousState)
|
2014-07-04 12:48:09 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(down)
|
|
|
|
callback();
|
2014-07-04 12:48:09 +03:00
|
|
|
}
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CCommanderSkillIcon::clickRight(tribool down, bool previousState)
|
2014-07-05 11:48:03 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(down)
|
|
|
|
LRClickableAreaWText::clickRight(down, previousState);
|
2014-07-05 11:48:03 +03:00
|
|
|
}
|
2013-03-06 21:49:56 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
static std::string skillToFile(int skill, int level, bool selected)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
// FIXME: is this a correct hadling?
|
|
|
|
// level 0 = skill not present, use image with "no" suffix
|
|
|
|
// level 1-5 = skill available, mapped to images indexed as 0-4
|
|
|
|
// selecting skill means that it will appear one level higher (as if alredy upgraded)
|
|
|
|
std::string file = "zvs/Lib1.res/_";
|
|
|
|
switch (skill)
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
case ECommander::ATTACK:
|
|
|
|
file += "AT";
|
|
|
|
break;
|
|
|
|
case ECommander::DEFENSE:
|
|
|
|
file += "DF";
|
|
|
|
break;
|
|
|
|
case ECommander::HEALTH:
|
|
|
|
file += "HP";
|
|
|
|
break;
|
|
|
|
case ECommander::DAMAGE:
|
|
|
|
file += "DM";
|
|
|
|
break;
|
|
|
|
case ECommander::SPEED:
|
|
|
|
file += "SP";
|
|
|
|
break;
|
|
|
|
case ECommander::SPELL_POWER:
|
|
|
|
file += "MP";
|
|
|
|
break;
|
2012-07-04 17:41:53 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
std::string sufix;
|
|
|
|
if (selected)
|
|
|
|
level++; // UI will display resulting level
|
|
|
|
if (level == 0)
|
|
|
|
sufix = "no"; //not avaliable - no number
|
2012-05-16 20:29:05 +03:00
|
|
|
else
|
2023-03-09 15:36:46 +02:00
|
|
|
sufix = std::to_string(level-1);
|
2018-04-07 13:34:11 +02:00
|
|
|
if (selected)
|
|
|
|
sufix += "="; //level-up highlight
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
return file + sufix + ".bmp";
|
|
|
|
}
|
2016-10-30 17:32:28 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CWindowSection::CWindowSection(CStackWindow * parent, std::string backgroundPath, int yOffset)
|
|
|
|
: parent(parent)
|
|
|
|
{
|
|
|
|
pos.y += yOffset;
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
if(!backgroundPath.empty())
|
2016-10-30 17:32:28 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
background = std::make_shared<CPicture>("stackWindow/" + backgroundPath);
|
|
|
|
pos.w = background->pos.w;
|
|
|
|
pos.h = background->pos.h;
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::ActiveSpellsSection::ActiveSpellsSection(CStackWindow * owner, int yOffset)
|
|
|
|
: CWindowSection(owner, "spell-effects", yOffset)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-09-19 16:31:01 +03:00
|
|
|
static const Point firstPos(6, 2); // position of 1st spell box
|
2014-06-26 22:07:33 +03:00
|
|
|
static const Point offset(54, 0); // offset of each spell box from previous
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
const CStack * battleStack = parent->info->stack;
|
2011-04-10 08:41:24 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
assert(battleStack); // Section should be created only for battles
|
|
|
|
|
|
|
|
//spell effects
|
|
|
|
int printed=0; //how many effect pics have been printed
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
|
|
|
for(si32 effect : spells)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const spells::Spell * spell = CGI->spells()->getByIndex(effect);
|
2016-10-01 08:07:18 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
std::string spellText;
|
2016-10-01 08:07:18 +02:00
|
|
|
|
2015-01-18 18:38:35 +02:00
|
|
|
//not all effects have graphics (for eg. Acid Breath)
|
|
|
|
//for modded spells iconEffect is added to SpellInt.def
|
2016-10-01 08:07:18 +02:00
|
|
|
const bool hasGraphics = (effect < SpellID::THUNDERBOLT) || (effect >= SpellID::AFTER_LAST);
|
|
|
|
|
|
|
|
if (hasGraphics)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
2023-01-02 00:06:42 +02:00
|
|
|
boost::replace_first(spellText, "%s", spell->getNameTranslated());
|
2018-04-07 13:34:11 +02:00
|
|
|
//FIXME: support permanent duration
|
2014-06-26 22:07:33 +03:00
|
|
|
int duration = battleStack->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(spellText, "%d", std::to_string(duration));
|
2014-06-26 22:07:33 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
spellIcons.push_back(std::make_shared<CAnimImage>("SpellInt", effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
|
|
|
|
clickableAreas.push_back(std::make_shared<LRClickableAreaWText>(Rect(firstPos + offset * printed, Point(50, 38)), spellText, spellText));
|
|
|
|
if(++printed >= 8) // interface limit reached
|
2014-06-26 22:07:33 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t lineIndex)
|
|
|
|
: CWindowSection(owner, "bonus-effects", 0)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
static const std::array<Point, 2> offset =
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
Point(6, 4),
|
|
|
|
Point(214, 4)
|
2014-06-26 22:07:33 +03:00
|
|
|
};
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
for(size_t leftRight : {0, 1})
|
|
|
|
{
|
|
|
|
auto position = offset[leftRight];
|
|
|
|
size_t bonusIndex = lineIndex * 2 + leftRight;
|
|
|
|
|
|
|
|
if(parent->activeBonuses.size() > bonusIndex)
|
|
|
|
{
|
|
|
|
BonusInfo & bi = parent->activeBonuses[bonusIndex];
|
|
|
|
icon[leftRight] = std::make_shared<CPicture>(bi.imagePath, position.x, position.y);
|
2022-11-26 23:12:20 +02:00
|
|
|
name[leftRight] = std::make_shared<CLabel>(position.x + 60, position.y + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, bi.name);
|
|
|
|
description[leftRight] = std::make_shared<CMultiLineLabel>(Rect(position.x + 60, position.y + 17, 137, 30), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, bi.description);
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset, std::optional<size_t> preferredSize):
|
|
|
|
CWindowSection(owner, "", yOffset)
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
// size of single image for an item
|
|
|
|
static const int itemHeight = 59;
|
|
|
|
|
|
|
|
size_t totalSize = (owner->activeBonuses.size() + 1) / 2;
|
2023-04-16 19:42:56 +02:00
|
|
|
size_t visibleSize = preferredSize.value_or(std::min<size_t>(3, totalSize));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
pos.w = owner->pos.w;
|
2020-10-01 10:38:06 +02:00
|
|
|
pos.h = itemHeight * (int)visibleSize;
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
auto onCreate = [=](size_t index) -> std::shared_ptr<CIntObject>
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
return std::make_shared<BonusLineSection>(owner, index);
|
2014-06-26 22:07:33 +03:00
|
|
|
};
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
lines = std::make_shared<CListBox>(onCreate, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, 1, Rect(pos.w - 15, 0, pos.h, pos.h));
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::ButtonsSection::ButtonsSection(CStackWindow * owner, int yOffset)
|
|
|
|
: CWindowSection(owner, "button-panel", yOffset)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
if(parent->info->dismissInfo && parent->info->dismissInfo->callback)
|
2014-06-27 18:33:30 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
auto onDismiss = [=]()
|
|
|
|
{
|
|
|
|
parent->info->dismissInfo->callback();
|
|
|
|
parent->close();
|
|
|
|
};
|
|
|
|
auto onClick = [=] ()
|
|
|
|
{
|
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[12], onDismiss, nullptr);
|
|
|
|
};
|
|
|
|
dismiss = std::make_shared<CButton>(Point(5, 5),"IVIEWCR2.DEF", CGI->generaltexth->zelp[445], onClick, SDLK_d);
|
2014-06-27 18:33:30 +03:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(parent->info->upgradeInfo && !parent->info->commander)
|
|
|
|
{
|
|
|
|
// used space overlaps with commander switch button
|
|
|
|
// besides - should commander really be upgradeable?
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
auto & upgradeInfo = parent->info->upgradeInfo.value();
|
2018-04-07 13:34:11 +02:00
|
|
|
const size_t buttonsToCreate = std::min<size_t>(upgradeInfo.info.newID.size(), upgrade.size());
|
|
|
|
|
|
|
|
for(size_t buttonIndex = 0; buttonIndex < buttonsToCreate; buttonIndex++)
|
|
|
|
{
|
|
|
|
TResources totalCost = upgradeInfo.info.cost[buttonIndex] * parent->info->creatureCount;
|
|
|
|
|
|
|
|
auto onUpgrade = [=]()
|
|
|
|
{
|
|
|
|
upgradeInfo.callback(upgradeInfo.info.newID[buttonIndex]);
|
|
|
|
parent->close();
|
|
|
|
};
|
|
|
|
auto onClick = [=]()
|
|
|
|
{
|
|
|
|
std::vector<std::shared_ptr<CComponent>> resComps;
|
|
|
|
for(TResources::nziterator i(totalCost); i.valid(); i++)
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
resComps.push_back(std::make_shared<CComponent>(CComponent::resource, i->resType, (int)i->resVal));
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(LOCPLINT->cb->getResourceAmount().canAfford(totalCost))
|
|
|
|
{
|
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[207], onUpgrade, nullptr, resComps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314], resComps);
|
|
|
|
}
|
|
|
|
};
|
2020-10-01 10:38:06 +02:00
|
|
|
auto upgradeBtn = std::make_shared<CButton>(Point(221 + (int)buttonIndex * 40, 5), "stackWindow/upgradeButton", CGI->generaltexth->zelp[446], onClick, SDLK_1);
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
upgradeBtn->addOverlay(std::make_shared<CAnimImage>("CPRSMALL", VLC->creh->objects[upgradeInfo.info.newID[buttonIndex]]->getIconIndex()));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2022-09-03 12:52:15 +02:00
|
|
|
if(buttonsToCreate == 1) // single upgrade avaialbe
|
|
|
|
{
|
|
|
|
upgradeBtn->assignedKeys.insert(SDLK_u);
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
upgrade[buttonIndex] = upgradeBtn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parent->info->commander)
|
|
|
|
{
|
|
|
|
for(size_t buttonIndex = 0; buttonIndex < 2; buttonIndex++)
|
|
|
|
{
|
|
|
|
std::string btnIDs[2] = { "showSkills", "showBonuses" };
|
|
|
|
auto onSwitch = [buttonIndex, this]()
|
|
|
|
{
|
|
|
|
logAnim->debug("Switch %d->%d", parent->activeTab, buttonIndex);
|
|
|
|
|
|
|
|
parent->switchButtons[parent->activeTab]->enable();
|
|
|
|
parent->commanderTab->setActive(buttonIndex);
|
|
|
|
parent->switchButtons[buttonIndex]->disable();
|
|
|
|
parent->redraw(); // FIXME: enable/disable don't redraw screen themselves
|
|
|
|
};
|
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
std::string tooltipText = "vcmi.creatureWindow." + btnIDs[buttonIndex];
|
|
|
|
parent->switchButtons[buttonIndex] = std::make_shared<CButton>(Point(302 + (int)buttonIndex*40, 5), "stackWindow/upgradeButton", CButton::tooltipLocalized(tooltipText), onSwitch);
|
2018-04-07 13:34:11 +02:00
|
|
|
parent->switchButtons[buttonIndex]->addOverlay(std::make_shared<CAnimImage>("stackWindow/switchModeIcons", buttonIndex));
|
|
|
|
}
|
|
|
|
parent->switchButtons[parent->activeTab]->disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit = std::make_shared<CButton>(Point(382, 5), "hsbtns.def", CGI->generaltexth->zelp[447], [=](){ parent->close(); }, SDLK_RETURN);
|
|
|
|
exit->assignedKeys.insert(SDLK_ESCAPE);
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CommanderMainSection::CommanderMainSection(CStackWindow * owner, int yOffset)
|
|
|
|
: CWindowSection(owner, "commander-bg", yOffset)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2016-11-03 15:25:17 +02:00
|
|
|
auto getSkillPos = [](int index)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
return Point(10 + 80 * (index%3), 20 + 80 * (index/3));
|
|
|
|
};
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
auto getSkillImage = [this](int skillIndex) -> std::string
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
bool selected = ((parent->selectedSkill == skillIndex) && parent->info->levelupInfo );
|
|
|
|
return skillToFile(skillIndex, parent->info->commander->secondarySkills[skillIndex], selected);
|
|
|
|
};
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2017-05-26 21:58:33 +02:00
|
|
|
auto getSkillDescription = [this](int skillIndex) -> std::string
|
|
|
|
{
|
2022-12-28 00:17:16 +02:00
|
|
|
return CGI->generaltexth->znpc00[152 + (12 * skillIndex) + (parent->info->commander->secondarySkills[skillIndex] * 2)];
|
2017-05-26 21:58:33 +02:00
|
|
|
};
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(int index = ECommander::ATTACK; index <= ECommander::SPELL_POWER; ++index)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
Point skillPos = getSkillPos(index);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
auto icon = std::make_shared<CCommanderSkillIcon>(std::make_shared<CPicture>(getSkillImage(index), skillPos.x, skillPos.y), [=]()
|
|
|
|
{
|
|
|
|
LOCPLINT->showInfoDialog(getSkillDescription(index));
|
|
|
|
});
|
2017-05-26 21:58:33 +02:00
|
|
|
|
|
|
|
icon->text = getSkillDescription(index); //used to handle right click description via LRClickableAreaWText::ClickRight()
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2017-05-26 21:58:33 +02:00
|
|
|
if(parent->selectedSkill == index)
|
2014-06-27 18:33:30 +03:00
|
|
|
parent->selectedIcon = icon;
|
|
|
|
|
2017-05-26 21:58:33 +02:00
|
|
|
if(parent->info->levelupInfo && vstd::contains(parent->info->levelupInfo->skills, index)) // can be upgraded - enable selection switch
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2017-05-26 21:58:33 +02:00
|
|
|
if(parent->selectedSkill == index)
|
|
|
|
parent->setSelection(index, icon);
|
|
|
|
|
2017-07-19 01:06:05 +02:00
|
|
|
icon->callback = [=]()
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
parent->setSelection(index, icon);
|
2014-06-27 18:33:30 +03:00
|
|
|
};
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
skillIcons.push_back(icon);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
2016-11-03 15:25:17 +02:00
|
|
|
|
|
|
|
auto getArtifactPos = [](int index)
|
|
|
|
{
|
|
|
|
return Point(269 + 47 * (index % 3), 22 + 47 * (index / 3));
|
|
|
|
};
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
for(auto equippedArtifact : parent->info->commander->artifactsWorn)
|
2016-11-03 15:25:17 +02:00
|
|
|
{
|
|
|
|
Point artPos = getArtifactPos(equippedArtifact.first);
|
2018-04-07 13:34:11 +02:00
|
|
|
auto artPlace = std::make_shared<CCommanderArtPlace>(artPos, parent->info->owner, equippedArtifact.first, equippedArtifact.second.artifact);
|
|
|
|
artifacts.push_back(artPlace);
|
2016-11-03 15:25:17 +02:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(parent->info->levelupInfo)
|
2012-05-07 15:54:22 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
abilitiesBackground = std::make_shared<CPicture>("stackWindow/commander-abilities.png");
|
|
|
|
abilitiesBackground->moveBy(Point(0, pos.h));
|
|
|
|
|
|
|
|
size_t abilitiesCount = boost::range::count_if(parent->info->levelupInfo->skills, [](ui32 skillID)
|
2014-07-04 20:58:18 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
return skillID >= 100;
|
|
|
|
});
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
auto onCreate = [=](size_t index)->std::shared_ptr<CIntObject>
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
|
|
|
for(auto skillID : parent->info->levelupInfo->skills)
|
|
|
|
{
|
|
|
|
if(index == 0 && skillID >= 100)
|
|
|
|
{
|
|
|
|
const auto bonus = CGI->creh->skillRequirements[skillID-100].first;
|
|
|
|
const CStackInstance * stack = parent->info->commander;
|
|
|
|
auto icon = std::make_shared<CCommanderSkillIcon>(std::make_shared<CPicture>(stack->bonusToGraphics(bonus)), [](){});
|
|
|
|
icon->callback = [=]()
|
|
|
|
{
|
|
|
|
parent->setSelection(skillID, icon);
|
|
|
|
};
|
|
|
|
icon->text = stack->bonusToString(bonus, true);
|
|
|
|
icon->hoverText = stack->bonusToString(bonus, false);
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
if(skillID >= 100)
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
abilities = std::make_shared<CListBox>(onCreate, Point(38, 3+pos.h), Point(63, 0), 6, abilitiesCount);
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
leftBtn = std::make_shared<CButton>(Point(10, pos.h + 6), "hsbtns3.def", CButton::tooltip(), [=](){ abilities->moveToPrev(); }, SDLK_LEFT);
|
|
|
|
rightBtn = std::make_shared<CButton>(Point(411, pos.h + 6), "hsbtns5.def", CButton::tooltip(), [=](){ abilities->moveToNext(); }, SDLK_RIGHT);
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(abilitiesCount <= 6)
|
|
|
|
{
|
|
|
|
leftBtn->block(true);
|
|
|
|
rightBtn->block(true);
|
|
|
|
}
|
2014-07-03 19:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
pos.h += abilitiesBackground->pos.h;
|
2012-07-04 17:41:53 +03:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool showExp, bool showArt)
|
|
|
|
: CWindowSection(owner, getBackgroundName(showExp, showArt), yOffset)
|
2011-08-05 10:59:15 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
statNames =
|
2017-05-26 21:58:33 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
CGI->generaltexth->primarySkillNames[0], //ATTACK
|
|
|
|
CGI->generaltexth->primarySkillNames[1],//DEFENCE
|
|
|
|
CGI->generaltexth->allTexts[198],//SHOTS
|
|
|
|
CGI->generaltexth->allTexts[199],//DAMAGE
|
2017-05-26 21:58:33 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CGI->generaltexth->allTexts[388],//HEALTH
|
|
|
|
CGI->generaltexth->allTexts[200],//HEALTH_LEFT
|
|
|
|
CGI->generaltexth->zelp[441].first,//SPEED
|
|
|
|
CGI->generaltexth->allTexts[399]//MANA
|
2017-05-26 21:58:33 +02:00
|
|
|
};
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
statFormats =
|
2014-07-03 19:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
"%d (%d)",
|
|
|
|
"%d (%d)",
|
|
|
|
"%d (%d)",
|
|
|
|
"%d - %d",
|
2011-08-05 10:59:15 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
"%d (%d)",
|
|
|
|
"%d (%d)",
|
|
|
|
"%d (%d)",
|
|
|
|
"%d (%d)"
|
|
|
|
};
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
animation = std::make_shared<CCreaturePic>(5, 41, parent->info->creature);
|
2017-05-26 21:58:33 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(parent->info->stackNode != nullptr && parent->info->commander == nullptr)
|
2017-05-26 21:58:33 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
//normal stack, not a commander and not non-existing stack (e.g. recruitment dialog)
|
|
|
|
animation->setAmount(parent->info->creatureCount);
|
2017-05-26 21:58:33 +02:00
|
|
|
}
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
name = std::make_shared<CLabel>(215, 12, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, parent->info->getName());
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
int dmgMultiply = 1;
|
|
|
|
if(parent->info->owner && parent->info->stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
|
|
|
dmgMultiply += parent->info->owner->getPrimSkillLevel(PrimarySkill::ATTACK);
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
icons = std::make_shared<CPicture>("stackWindow/icons", 117, 32);
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
const CStack * battleStack = parent->info->stack;
|
2014-06-26 22:07:33 +03:00
|
|
|
|
2023-02-03 19:17:59 +02:00
|
|
|
morale = std::make_shared<MoraleLuckBox>(true, Rect(Point(321, 110), Point(42, 42) ));
|
|
|
|
luck = std::make_shared<MoraleLuckBox>(false, Rect(Point(375, 110), Point(42, 42) ));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
if(battleStack != nullptr) // in battle
|
2012-05-13 18:04:21 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
addStatLabel(EStat::ATTACK, parent->info->creature->getAttack(battleStack->isShooter()), battleStack->getAttack(battleStack->isShooter()));
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(battleStack->isShooter()), battleStack->getDefense(battleStack->isShooter()));
|
2018-04-07 13:34:11 +02:00
|
|
|
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(battleStack->isShooter()) * dmgMultiply, battleStack->getMaxDamage(battleStack->isShooter()) * dmgMultiply);
|
|
|
|
addStatLabel(EStat::HEALTH, parent->info->creature->MaxHealth(), battleStack->MaxHealth());
|
|
|
|
addStatLabel(EStat::SPEED, parent->info->creature->Speed(), battleStack->Speed());
|
|
|
|
|
|
|
|
if(battleStack->isShooter())
|
|
|
|
addStatLabel(EStat::SHOTS, battleStack->shots.total(), battleStack->shots.available());
|
|
|
|
if(battleStack->isCaster())
|
|
|
|
addStatLabel(EStat::MANA, battleStack->casts.total(), battleStack->casts.available());
|
|
|
|
addStatLabel(EStat::HEALTH_LEFT, battleStack->getFirstHPleft());
|
|
|
|
|
|
|
|
morale->set(battleStack);
|
|
|
|
luck->set(battleStack);
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
else
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
const bool shooter = parent->info->stackNode->hasBonusOfType(Bonus::SHOOTER) && parent->info->stackNode->valOfBonuses(Bonus::SHOTS);
|
|
|
|
const bool caster = parent->info->stackNode->valOfBonuses(Bonus::CASTS);
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
addStatLabel(EStat::ATTACK, parent->info->creature->getAttack(shooter), parent->info->stackNode->getAttack(shooter));
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(shooter), parent->info->stackNode->getDefense(shooter));
|
2018-04-07 13:34:11 +02:00
|
|
|
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(shooter) * dmgMultiply, parent->info->stackNode->getMaxDamage(shooter) * dmgMultiply);
|
|
|
|
addStatLabel(EStat::HEALTH, parent->info->creature->MaxHealth(), parent->info->stackNode->MaxHealth());
|
|
|
|
addStatLabel(EStat::SPEED, parent->info->creature->Speed(), parent->info->stackNode->Speed());
|
2012-02-10 13:32:21 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(shooter)
|
|
|
|
addStatLabel(EStat::SHOTS, parent->info->stackNode->valOfBonuses(Bonus::SHOTS));
|
|
|
|
if(caster)
|
|
|
|
addStatLabel(EStat::MANA, parent->info->stackNode->valOfBonuses(Bonus::CASTS));
|
2016-09-30 20:45:23 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
morale->set(parent->info->stackNode);
|
|
|
|
luck->set(parent->info->stackNode);
|
|
|
|
}
|
2012-04-17 17:50:23 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(showExp)
|
|
|
|
{
|
|
|
|
const CStackInstance * stack = parent->info->stackNode;
|
|
|
|
Point pos = showArt ? Point(321, 32) : Point(347, 32);
|
|
|
|
if(parent->info->commander)
|
|
|
|
{
|
|
|
|
const CCommanderInstance * commander = parent->info->commander;
|
|
|
|
expRankIcon = std::make_shared<CAnimImage>("PSKIL42", 4, 0, pos.x, pos.y);
|
|
|
|
|
|
|
|
auto area = std::make_shared<LRClickableAreaWTextComp>(Rect(pos.x, pos.y, 44, 44), CComponent::experience);
|
|
|
|
expArea = area;
|
|
|
|
area->text = CGI->generaltexth->allTexts[2];
|
|
|
|
area->bonusValue = commander->getExpRank();
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(area->text, "%d", std::to_string(commander->getExpRank()));
|
|
|
|
boost::replace_first(area->text, "%d", std::to_string(CGI->heroh->reqExp(commander->getExpRank() + 1)));
|
|
|
|
boost::replace_first(area->text, "%d", std::to_string(commander->experience));
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expRankIcon = std::make_shared<CAnimImage>("stackWindow/levels", stack->getExpRank(), 0, pos.x, pos.y);
|
|
|
|
expArea = std::make_shared<LRClickableAreaWText>(Rect(pos.x, pos.y, 44, 44));
|
|
|
|
expArea->text = parent->generateStackExpDescription();
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
expLabel = std::make_shared<CLabel>(
|
2022-11-26 23:12:20 +02:00
|
|
|
pos.x + 21, pos.y + 52, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE,
|
2023-02-12 23:52:35 +02:00
|
|
|
TextOperations::formatMetric(stack->experience, 6));
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(showArt)
|
2012-05-25 18:10:38 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
Point pos = showExp ? Point(375, 32) : Point(347, 32);
|
|
|
|
// ALARMA: do not refactor this into a separate function
|
|
|
|
// otherwise, artifact icon is drawn near the hero's portrait
|
|
|
|
// this is really strange
|
|
|
|
auto art = parent->info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
|
|
|
|
if(art)
|
2014-06-27 18:33:30 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
parent->stackArtifactIcon = std::make_shared<CAnimImage>("ARTIFACT", art->artType->iconIndex, 0, pos.x, pos.y);
|
|
|
|
parent->stackArtifactHelp = std::make_shared<LRClickableAreaWTextComp>(Rect(pos, Point(44, 44)), CComponent::artifact);
|
2023-01-02 15:58:56 +02:00
|
|
|
parent->stackArtifactHelp->type = art->artType->getId();
|
2014-06-27 18:33:30 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(parent->info->owner)
|
|
|
|
{
|
|
|
|
parent->stackArtifactButton = std::make_shared<CButton>(
|
|
|
|
Point(pos.x - 2 , pos.y + 46), "stackWindow/cancelButton",
|
2022-12-27 22:19:05 +02:00
|
|
|
CButton::tooltipLocalized("vcmi.creatureWindow.returnArtifact"), [=]()
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
|
|
|
parent->removeStackArtifact(ArtifactPosition::CREATURE_SLOT);
|
|
|
|
});
|
|
|
|
}
|
2014-06-27 18:33:30 +03:00
|
|
|
}
|
2012-05-25 18:10:38 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CStackWindow::MainSection::getBackgroundName(bool showExp, bool showArt)
|
|
|
|
{
|
|
|
|
if(showExp && showArt)
|
|
|
|
return "info-panel-2";
|
|
|
|
else if(showExp || showArt)
|
|
|
|
return "info-panel-1";
|
|
|
|
else
|
|
|
|
return "info-panel-0";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStackWindow::MainSection::addStatLabel(EStat index, int64_t value1, int64_t value2)
|
|
|
|
{
|
|
|
|
const auto title = statNames.at(static_cast<size_t>(index));
|
2022-11-26 23:12:20 +02:00
|
|
|
stats.push_back(std::make_shared<CLabel>(145, 32 + (int)index*19, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, title));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
const bool useRange = value1 != value2;
|
|
|
|
std::string formatStr = useRange ? statFormats.at(static_cast<size_t>(index)) : "%d";
|
|
|
|
|
|
|
|
boost::format fmt(formatStr);
|
|
|
|
fmt % value1;
|
|
|
|
if(useRange)
|
|
|
|
fmt % value2;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
stats.push_back(std::make_shared<CLabel>(307, 48 + (int)index*19, FONT_SMALL, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, fmt.str()));
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CStackWindow::MainSection::addStatLabel(EStat index, int64_t value)
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
addStatLabel(index, value, value);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CStack * stack, bool popup)
|
|
|
|
: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new UnitView())
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->stack = stack;
|
|
|
|
info->stackNode = stack->base;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->getCount();
|
|
|
|
info->popupWindow = popup;
|
|
|
|
init();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CCreature * creature, bool popup)
|
|
|
|
: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new UnitView())
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->creature = creature;
|
|
|
|
info->popupWindow = popup;
|
|
|
|
init();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CStackInstance * stack, bool popup)
|
|
|
|
: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new UnitView())
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->stackNode = stack;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->count;
|
|
|
|
info->popupWindow = popup;
|
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
|
|
|
|
init();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & upgradeInfo, std::function<void(CreatureID)> callback)
|
|
|
|
: CWindowObject(BORDERED),
|
|
|
|
info(new UnitView())
|
2017-05-26 21:58:33 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->stackNode = stack;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->count;
|
2017-05-26 21:58:33 +02:00
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
info->upgradeInfo = std::make_optional(UnitView::StackUpgradeInfo());
|
|
|
|
info->dismissInfo = std::make_optional(UnitView::StackDismissInfo());
|
2018-04-07 13:34:11 +02:00
|
|
|
info->upgradeInfo->info = upgradeInfo;
|
|
|
|
info->upgradeInfo->callback = callback;
|
|
|
|
info->dismissInfo->callback = dismiss;
|
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
|
|
|
|
init();
|
2011-03-13 18:06:20 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CCommanderInstance * commander, bool popup)
|
|
|
|
: CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new UnitView())
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->stackNode = commander;
|
|
|
|
info->creature = commander->type;
|
|
|
|
info->commander = commander;
|
|
|
|
info->creatureCount = 1;
|
|
|
|
info->popupWindow = popup;
|
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
|
|
|
|
init();
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback)
|
|
|
|
: CWindowObject(BORDERED),
|
|
|
|
info(new UnitView())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
info->stackNode = commander;
|
|
|
|
info->creature = commander->type;
|
|
|
|
info->commander = commander;
|
|
|
|
info->creatureCount = 1;
|
2023-04-16 19:42:56 +02:00
|
|
|
info->levelupInfo = std::make_optional(UnitView::CommanderLevelInfo());
|
2018-04-07 13:34:11 +02:00
|
|
|
info->levelupInfo->skills = skills;
|
|
|
|
info->levelupInfo->callback = callback;
|
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
|
|
|
|
init();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CStackWindow::~CStackWindow()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(info->levelupInfo && !info->levelupInfo->skills.empty())
|
|
|
|
info->levelupInfo->callback(vstd::find_pos(info->levelupInfo->skills, selectedSkill));
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CStackWindow::init()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(!info->stackNode)
|
2022-10-04 20:30:18 +02:00
|
|
|
info->stackNode = new CStackInstance(info->creature, 1, true);// FIXME: free data
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
selectedIcon = nullptr;
|
|
|
|
selectedSkill = -1;
|
|
|
|
if(info->levelupInfo && !info->levelupInfo->skills.empty())
|
|
|
|
selectedSkill = info->levelupInfo->skills.front();
|
2014-06-26 22:07:33 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
activeTab = 0;
|
|
|
|
|
|
|
|
initBonusesList();
|
|
|
|
initSections();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::initBonusesList()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
BonusList output, input;
|
2016-10-01 08:07:18 +02:00
|
|
|
input = *(info->stackNode->getBonuses(CSelector(Bonus::Permanent), Selector::all));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
while(!input.empty())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2016-09-19 23:36:35 +02:00
|
|
|
auto b = input.front();
|
|
|
|
output.push_back(std::make_shared<Bonus>(*b));
|
2014-06-26 22:07:33 +03:00
|
|
|
output.back()->val = input.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
|
|
|
|
input.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
BonusInfo bonusInfo;
|
2016-09-19 23:36:35 +02:00
|
|
|
for(auto b : output)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
bonusInfo.name = info->stackNode->bonusToString(b, false);
|
2014-11-15 19:22:50 +02:00
|
|
|
bonusInfo.description = info->stackNode->bonusToString(b, true);
|
2014-06-27 18:33:30 +03:00
|
|
|
bonusInfo.imagePath = info->stackNode->bonusToGraphics(b);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
//if it's possible to give any description or image for this kind of bonus
|
|
|
|
//TODO: figure out why half of bonuses don't have proper description
|
2018-04-07 13:34:11 +02:00
|
|
|
if(!bonusInfo.name.empty() || !bonusInfo.imagePath.empty())
|
2014-06-26 22:07:33 +03:00
|
|
|
activeBonuses.push_back(bonusInfo);
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CStackWindow::initSections()
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
2014-08-11 16:28:15 +03:00
|
|
|
|
2023-03-15 21:34:29 +02:00
|
|
|
bool showArt = CGI->settings()->getBoolean(EGameSettings::MODULE_STACK_ARTIFACT) && info->commander == nullptr && info->stackNode;
|
|
|
|
bool showExp = (CGI->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE) || info->commander != nullptr) && info->stackNode;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
mainSection = std::make_shared<MainSection>(this, pos.h, showExp, showArt);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
pos.w = mainSection->pos.w;
|
|
|
|
pos.h += mainSection->pos.h;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(info->stack) // in battle
|
|
|
|
{
|
|
|
|
activeSpellsSection = std::make_shared<ActiveSpellsSection>(this, pos.h);
|
|
|
|
pos.h += activeSpellsSection->pos.h;
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(info->commander)
|
|
|
|
{
|
|
|
|
auto onCreate = [=](size_t index) -> std::shared_ptr<CIntObject>
|
|
|
|
{
|
|
|
|
auto obj = switchTab(index);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
obj->activate();
|
|
|
|
obj->recActions |= (UPDATE | SHOWALL);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto deactivateObj = [=](std::shared_ptr<CIntObject> obj)
|
|
|
|
{
|
|
|
|
obj->deactivate();
|
|
|
|
obj->recActions &= ~(UPDATE | SHOWALL);
|
|
|
|
};
|
|
|
|
|
|
|
|
commanderMainSection = std::make_shared<CommanderMainSection>(this, 0);
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
auto size = std::make_optional<size_t>((info->levelupInfo) ? 4 : 3);
|
2018-04-07 13:34:11 +02:00
|
|
|
commanderBonusesSection = std::make_shared<BonusesSection>(this, 0, size);
|
|
|
|
deactivateObj(commanderBonusesSection);
|
|
|
|
|
|
|
|
commanderTab = std::make_shared<CTabbedInt>(onCreate, Point(0, pos.h), 0);
|
|
|
|
|
|
|
|
pos.h += commanderMainSection->pos.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!info->commander && !activeBonuses.empty())
|
|
|
|
{
|
|
|
|
bonusesSection = std::make_shared<BonusesSection>(this, pos.h);
|
|
|
|
pos.h += bonusesSection->pos.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!info->popupWindow)
|
|
|
|
{
|
|
|
|
buttonsSection = std::make_shared<ButtonsSection>(this, pos.h);
|
|
|
|
pos.h += buttonsSection->pos.h;
|
|
|
|
//FIXME: add status bar to image?
|
|
|
|
}
|
|
|
|
updateShadow();
|
|
|
|
pos = center(pos);
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::string CStackWindow::generateStackExpDescription()
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
const CStackInstance * stack = info->stackNode;
|
|
|
|
const CCreature * creature = info->creature;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
int tier = stack->type->getLevel();
|
2018-04-07 13:34:11 +02:00
|
|
|
int rank = stack->getExpRank();
|
|
|
|
if (!vstd::iswithin(tier, 1, 7))
|
|
|
|
tier = 0;
|
|
|
|
int number;
|
2022-12-28 00:17:16 +02:00
|
|
|
std::string expText = CGI->generaltexth->translate("vcmi.stackExperience.description");
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::replace_first(expText, "%s", creature->getNamePluralTranslated());
|
2022-12-28 00:17:16 +02:00
|
|
|
boost::replace_first(expText, "%s", CGI->generaltexth->translate("vcmi.stackExperience.rank", rank));
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(rank));
|
|
|
|
boost::replace_first(expText, "%i", std::to_string(stack->experience));
|
2020-10-01 10:38:06 +02:00
|
|
|
number = static_cast<int>(CGI->creh->expRanks[tier][rank] - stack->experience);
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(number));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
number = CGI->creh->maxExpPerBattle[tier]; //percent
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i%", std::to_string(number));
|
2018-04-07 13:34:11 +02:00
|
|
|
number *= CGI->creh->expRanks[tier].back() / 100; //actual amount
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(number));
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(stack->count)); //Number of Creatures in stack
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
int expmin = std::max(CGI->creh->expRanks[tier][std::max(rank-1, 0)], (ui32)1);
|
2020-10-01 10:38:06 +02:00
|
|
|
number = static_cast<int>((stack->count * (stack->experience - expmin)) / expmin); //Maximum New Recruits without losing current Rank
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(number)); //TODO
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%.2f", std::to_string(1)); //TODO Experience Multiplier
|
2018-04-07 13:34:11 +02:00
|
|
|
number = CGI->creh->expAfterUpgrade;
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%.2f", std::to_string(number) + "%"); //Upgrade Multiplier
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
expmin = CGI->creh->expRanks[tier][9];
|
|
|
|
int expmax = CGI->creh->expRanks[tier][10];
|
|
|
|
number = expmax - expmin;
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(number)); //Experience after Rank 10
|
2018-04-07 13:34:11 +02:00
|
|
|
number = (stack->count * (expmax - expmin)) / expmin;
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(expText, "%i", std::to_string(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
return expText;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CStackWindow::setSelection(si32 newSkill, std::shared_ptr<CCommanderSkillIcon> newIcon)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
auto getSkillDescription = [this](int skillIndex, bool selected) -> std::string
|
|
|
|
{
|
|
|
|
if(selected)
|
2022-12-28 00:17:16 +02:00
|
|
|
return CGI->generaltexth->znpc00[152 + (12 * skillIndex) + ((info->commander->secondarySkills[skillIndex] + 1) * 2)]; //upgrade description
|
2018-04-07 13:34:11 +02:00
|
|
|
else
|
2022-12-28 00:17:16 +02:00
|
|
|
return CGI->generaltexth->znpc00[152 + (12 * skillIndex) + (info->commander->secondarySkills[skillIndex] * 2)];
|
2018-04-07 13:34:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
auto getSkillImage = [this](int skillIndex) -> std::string
|
|
|
|
{
|
|
|
|
bool selected = ((selectedSkill == skillIndex) && info->levelupInfo );
|
|
|
|
return skillToFile(skillIndex, info->commander->secondarySkills[skillIndex], selected);
|
|
|
|
};
|
|
|
|
|
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
|
|
|
int oldSelection = selectedSkill; // update selection
|
|
|
|
selectedSkill = newSkill;
|
|
|
|
|
|
|
|
if(selectedIcon && oldSelection < 100) // recreate image on old selection, only for skills
|
|
|
|
selectedIcon->setObject(std::make_shared<CPicture>(getSkillImage(oldSelection)));
|
|
|
|
|
|
|
|
if(selectedIcon)
|
|
|
|
selectedIcon->text = getSkillDescription(oldSelection, false); //update previously selected icon's message to existing skill level
|
|
|
|
|
|
|
|
selectedIcon = newIcon; // update new selection
|
|
|
|
if(newSkill < 100)
|
|
|
|
{
|
|
|
|
newIcon->setObject(std::make_shared<CPicture>(getSkillImage(newSkill)));
|
|
|
|
newIcon->text = getSkillDescription(newSkill, true); //update currently selected icon's message to show upgrade description
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> CStackWindow::switchTab(size_t index)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> ret;
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
activeTab = 0;
|
|
|
|
ret = commanderMainSection;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
activeTab = 1;
|
|
|
|
ret = commanderBonusesSection;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CStackWindow::removeStackArtifact(ArtifactPosition pos)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
auto art = info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
|
|
|
|
if(!art)
|
|
|
|
{
|
|
|
|
logGlobal->error("Attempt to remove missing artifact");
|
|
|
|
return;
|
|
|
|
}
|
2023-03-21 12:13:53 +02:00
|
|
|
const auto slot = ArtifactUtils::getArtBackpackPosition(info->owner, art->getTypeId());
|
|
|
|
if(slot != ArtifactPosition::PRE_FIRST)
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(info->stackNode, pos), ArtifactLocation(info->owner, slot));
|
|
|
|
stackArtifactButton.reset();
|
|
|
|
stackArtifactHelp.reset();
|
|
|
|
stackArtifactIcon.reset();
|
|
|
|
redraw();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
|