mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Commander skill description support (#266)
* Added commander skill description support * Add support for ZNPC00.txt not found
This commit is contained in:
parent
b5daa24982
commit
5127061e28
@ -435,17 +435,31 @@ void CStackWindow::CWindowSection::createCommander()
|
||||
return skillToFile(skillIndex, parent->info->commander->secondarySkills[skillIndex], selected);
|
||||
};
|
||||
|
||||
auto getSkillDescription = [this](int skillIndex) -> std::string
|
||||
{
|
||||
if (CGI->generaltexth->znpc00.size() == 0)
|
||||
return "";
|
||||
|
||||
return CGI->generaltexth->znpc00[151 + (12 * skillIndex) + (parent->info->commander->secondarySkills[skillIndex] * 2)];
|
||||
};
|
||||
|
||||
for (int index = ECommander::ATTACK; index <= ECommander::SPELL_POWER; ++index)
|
||||
{
|
||||
Point skillPos = getSkillPos(index);
|
||||
|
||||
auto icon = new CClickableObject(new CPicture(getSkillImage(index), skillPos.x, skillPos.y), [=]{});
|
||||
auto icon = new CCommanderSkillIcon(new CPicture(getSkillImage(index), skillPos.x, skillPos.y),
|
||||
[=] { LOCPLINT->showInfoDialog(getSkillDescription(index)); });
|
||||
|
||||
if (parent->selectedSkill == index)
|
||||
icon->text = getSkillDescription(index); //used to handle right click description via LRClickableAreaWText::ClickRight()
|
||||
|
||||
if(parent->selectedSkill == index)
|
||||
parent->selectedIcon = icon;
|
||||
|
||||
if (parent->info->levelupInfo && vstd::contains(parent->info->levelupInfo->skills, index)) // can be upgraded - enable selection switch
|
||||
if(parent->info->levelupInfo && vstd::contains(parent->info->levelupInfo->skills, index)) // can be upgraded - enable selection switch
|
||||
{
|
||||
if(parent->selectedSkill == index)
|
||||
parent->setSelection(index, icon);
|
||||
|
||||
icon->callback = [=]
|
||||
{
|
||||
parent->setSelection(index, icon);
|
||||
@ -472,7 +486,7 @@ CIntObject * CStackWindow::createSkillEntry(int index)
|
||||
{
|
||||
const auto bonus = CGI->creh->skillRequirements[skillID-100].first;
|
||||
const CStackInstance *stack = info->commander;
|
||||
CClickableObject * icon = new CClickableObject(new CPicture(stack->bonusToGraphics(bonus)), []{});
|
||||
CCommanderSkillIcon * icon = new CCommanderSkillIcon(new CPicture(stack->bonusToGraphics(bonus)), []{});
|
||||
icon->callback = [=]
|
||||
{
|
||||
setSelection(skillID, icon);
|
||||
@ -518,8 +532,19 @@ void CStackWindow::CWindowSection::createCommanderAbilities()
|
||||
}
|
||||
}
|
||||
|
||||
void CStackWindow::setSelection(si32 newSkill, CClickableObject * newIcon)
|
||||
void CStackWindow::setSelection(si32 newSkill, CCommanderSkillIcon * newIcon)
|
||||
{
|
||||
auto getSkillDescription = [this](int skillIndex, bool selected) -> std::string
|
||||
{
|
||||
if (CGI->generaltexth->znpc00.size() == 0)
|
||||
return "";
|
||||
|
||||
if(selected)
|
||||
return CGI->generaltexth->znpc00[151 + (12 * skillIndex) + ((info->commander->secondarySkills[skillIndex] + 1) * 2)]; //upgrade description
|
||||
else
|
||||
return CGI->generaltexth->znpc00[151 + (12 * skillIndex) + (info->commander->secondarySkills[skillIndex] * 2)];
|
||||
};
|
||||
|
||||
auto getSkillImage = [this](int skillIndex) -> std::string
|
||||
{
|
||||
bool selected = ((selectedSkill == skillIndex) && info->levelupInfo );
|
||||
@ -533,9 +558,14 @@ void CStackWindow::setSelection(si32 newSkill, CClickableObject * newIcon)
|
||||
if (selectedIcon && oldSelection < 100) // recreate image on old selection, only for skills
|
||||
selectedIcon->setObject(new CPicture(getSkillImage(oldSelection)));
|
||||
|
||||
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(new CPicture(getSkillImage(newSkill)));
|
||||
newIcon->text = getSkillDescription(newSkill, true); //update currently selected icon's message to show upgrade description
|
||||
}
|
||||
}
|
||||
|
||||
void CStackWindow::CWindowSection::createBonuses(boost::optional<size_t> preferredSize)
|
||||
@ -646,7 +676,7 @@ CStackWindow::CWindowSection::CWindowSection(CStackWindow * parent):
|
||||
{
|
||||
}
|
||||
|
||||
CClickableObject::CClickableObject(CIntObject *object, std::function<void()> callback):
|
||||
CCommanderSkillIcon::CCommanderSkillIcon(CIntObject *object, std::function<void()> callback):
|
||||
object(nullptr),
|
||||
callback(callback)
|
||||
{
|
||||
@ -654,7 +684,7 @@ CClickableObject::CClickableObject(CIntObject *object, std::function<void()> cal
|
||||
setObject(object);
|
||||
}
|
||||
|
||||
void CClickableObject::setObject(CIntObject *newObject)
|
||||
void CCommanderSkillIcon::setObject(CIntObject *newObject)
|
||||
{
|
||||
delete object;
|
||||
object = newObject;
|
||||
@ -663,12 +693,18 @@ void CClickableObject::setObject(CIntObject *newObject)
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CClickableObject::clickLeft(tribool down, bool previousState)
|
||||
void CCommanderSkillIcon::clickLeft(tribool down, bool previousState)
|
||||
{
|
||||
if (down)
|
||||
if(down)
|
||||
callback();
|
||||
}
|
||||
|
||||
void CCommanderSkillIcon::clickRight(tribool down, bool previousState)
|
||||
{
|
||||
if(down)
|
||||
LRClickableAreaWText::clickRight(down, previousState);
|
||||
}
|
||||
|
||||
CIntObject * CStackWindow::createBonusEntry(size_t index)
|
||||
{
|
||||
auto section = new CWindowSection(this);
|
||||
|
@ -22,16 +22,16 @@ struct UpgradeInfo;
|
||||
class CTabbedInt;
|
||||
class CButton;
|
||||
|
||||
class CClickableObject : public LRClickableAreaWText
|
||||
class CCommanderSkillIcon : public LRClickableAreaWText //TODO: maybe bring commander skill button initialization logic inside?
|
||||
{
|
||||
CIntObject * object; // passive object that will be used to determine clickable area
|
||||
public:
|
||||
CClickableObject(CIntObject * object, std::function<void()> callback);
|
||||
CCommanderSkillIcon(CIntObject * object, std::function<void()> callback);
|
||||
|
||||
std::function<void()> callback; //TODO: create more generic clickable class than AdvMapButton?
|
||||
std::function<void()> callback;
|
||||
|
||||
void clickLeft(tribool down, bool previousState) override;
|
||||
//void clickRight(tribool down, bool previousState){};
|
||||
void clickRight(tribool down, bool previousState) override;
|
||||
|
||||
void setObject(CIntObject * object);
|
||||
};
|
||||
@ -83,8 +83,8 @@ class CStackWindow : public CWindowObject
|
||||
|
||||
std::map<int, CButton *> switchButtons;
|
||||
|
||||
void setSelection(si32 newSkill, CClickableObject * newIcon);
|
||||
CClickableObject * selectedIcon;
|
||||
void setSelection(si32 newSkill, CCommanderSkillIcon * newIcon);
|
||||
CCommanderSkillIcon * selectedIcon;
|
||||
si32 selectedSkill;
|
||||
|
||||
CIntObject * createBonusEntry(size_t index);
|
||||
|
@ -490,4 +490,21 @@ CGeneralTextHandler::CGeneralTextHandler()
|
||||
}
|
||||
while (parser.endLine());
|
||||
}
|
||||
if (VLC->modh->modules.COMMANDERS)
|
||||
{
|
||||
try
|
||||
{
|
||||
CLegacyConfigParser parser("DATA/ZNPC00.TXT");
|
||||
parser.endLine();//header
|
||||
|
||||
do
|
||||
{
|
||||
znpc00.push_back(parser.readString());
|
||||
} while (parser.endLine());
|
||||
}
|
||||
catch (std::runtime_error)
|
||||
{
|
||||
logGlobal->warn("WoG file ZNPC00.TXT containing commander texts was not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,8 @@ public:
|
||||
std::vector<std::vector<std::string>> skillInfoTexts; //[id][level] : level 0 - basic; 2 - advanced
|
||||
std::vector<std::string> levels;
|
||||
std::vector<std::string> zcrexp; //more or less useful content of that file
|
||||
//commanders
|
||||
std::vector<std::string> znpc00; //more or less useful content of that file
|
||||
|
||||
//campaigns
|
||||
std::vector<std::string> campaignMapNames;
|
||||
|
Loading…
Reference in New Issue
Block a user