diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-07-21 16:54:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-07-21 16:54:59 +0300 |
commit | 70b8dc1a827e878ef899cf9824362706e86f30e5 (patch) | |
tree | 02bc072bd0d3663f726e3b86f725087090042a3b /src/gui | |
parent | fdd6a8ff123f32090d5c417803fd909558530a15 (diff) | |
download | mv-70b8dc1a827e878ef899cf9824362706e86f30e5.tar.gz mv-70b8dc1a827e878ef899cf9824362706e86f30e5.tar.bz2 mv-70b8dc1a827e878ef899cf9824362706e86f30e5.tar.xz mv-70b8dc1a827e878ef899cf9824362706e86f30e5.zip |
Move skill loading into separate function.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/windows/skilldialog.cpp | 124 | ||||
-rw-r--r-- | src/gui/windows/skilldialog.h | 7 |
2 files changed, 75 insertions, 56 deletions
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index 995ebe822..0c6b2d42c 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -310,7 +310,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName, // TRANSLATORS: skills dialog default skill tab strprintf(_("Skill Set %d"), setCount)); - SkillModel *const model = new SkillModel(); + SkillModel *const model = new SkillModel; if (!mDefaultModel) mDefaultModel = model; @@ -318,58 +318,15 @@ void SkillDialog::loadXmlFile(const std::string &fileName, { if (xmlNameEqual(node, "skill")) { - int id = XML::getIntProperty(node, "id", -1, -1, 1000000); - if (id == -1) + SkillInfo *const skill = loadSkill(node, model); + if (skill == nullptr) + continue; + for_each_xml_child_node(levelNode, node) { - id = XML::getIntProperty(node, "var", -1, -1, 100000); - if (id == -1) + if (!xmlNameEqual(levelNode, "level")) continue; - id += SKILL_VAR_MIN_ID; + loadSkillData(node, skill); } - - std::string name = XML::langProperty(node, "name", - // TRANSLATORS: skills dialog. skill id - strprintf(_("Skill %d"), id)); - - SkillInfo *skill = getSkill(id); - if (!skill) - { - skill = new SkillInfo; - skill->id = CAST_U32(id); - skill->modifiable = Modifiable_false; - skill->model = model; - skill->update(); - skill->useButton = XML::getProperty( - // TRANSLATORS: skills dialog button - node, "useButton", _("Use")); - skill->owner = parseOwner(XML::getProperty( - node, "owner", "player")); - skill->errorText = XML::getProperty( - node, "errorText", name); - skill->alwaysVisible = fromBool(XML::getBoolProperty( - node, "alwaysVisible", false), Visible); - skill->castingSrcEffectId = XML::getProperty( - node, "castingSrcEffectId", -1); - skill->castingDstEffectId = XML::getProperty( - node, "castingDstEffectId", -1); - skill->castingAction = XML::getProperty(node, - "castingAction", SpriteAction::CAST); - skill->castingRideAction = XML::getProperty(node, - "castingRideAction", SpriteAction::CASTRIDE); - skill->castingSkyAction = XML::getProperty(node, - "castingSkyAction", SpriteAction::CASTSKY); - skill->castingWaterAction = XML::getProperty(node, - "castingWaterAction", SpriteAction::CASTWATER); - skill->useTextParameter = XML::getBoolProperty( - node, "useTextParameter", false); - skill->visible = skill->alwaysVisible; - model->addSkill(skill); - mSkills[id] = skill; - } - - const int level = (skill->alwaysVisible == Visible_true) - ? 0 : XML::getProperty(node, "level", 0); - loadSkillData(node, name, skill, level); } } @@ -391,15 +348,76 @@ void SkillDialog::loadXmlFile(const std::string &fileName, } } +SkillInfo *SkillDialog::loadSkill(XmlNodePtr node, + SkillModel *const model) +{ + int id = XML::getIntProperty(node, "id", -1, -1, 1000000); + if (id == -1) + { + id = XML::getIntProperty(node, "var", -1, -1, 100000); + if (id == -1) + return nullptr; + id += SKILL_VAR_MIN_ID; + } + + std::string name = XML::langProperty(node, "name", + // TRANSLATORS: skills dialog. skill id + strprintf(_("Skill %d"), id)); + + SkillInfo *skill = getSkill(id); + if (!skill) + { + skill = new SkillInfo; + skill->id = CAST_U32(id); + skill->modifiable = Modifiable_false; + skill->model = model; + skill->update(); + skill->useButton = XML::getProperty( + // TRANSLATORS: skills dialog button + node, "useButton", _("Use")); + skill->owner = parseOwner(XML::getProperty( + node, "owner", "player")); + skill->errorText = XML::getProperty( + node, "errorText", name); + skill->alwaysVisible = fromBool(XML::getBoolProperty( + node, "alwaysVisible", false), Visible); + skill->castingSrcEffectId = XML::getProperty( + node, "castingSrcEffectId", -1); + skill->castingDstEffectId = XML::getProperty( + node, "castingDstEffectId", -1); + skill->castingAction = XML::getProperty(node, + "castingAction", SpriteAction::CAST); + skill->castingRideAction = XML::getProperty(node, + "castingRideAction", SpriteAction::CASTRIDE); + skill->castingSkyAction = XML::getProperty(node, + "castingSkyAction", SpriteAction::CASTSKY); + skill->castingWaterAction = XML::getProperty(node, + "castingWaterAction", SpriteAction::CASTWATER); + skill->useTextParameter = XML::getBoolProperty( + node, "useTextParameter", false); + skill->visible = skill->alwaysVisible; + model->addSkill(skill); + mSkills[id] = skill; + } + + loadSkillData(node, skill); + return skill; +} + void SkillDialog::loadSkillData(XmlNodePtr node, - const std::string &name, - SkillInfo *const skill, - const int level) + SkillInfo *const skill) { + if (!skill) + return; + const int level = (skill->alwaysVisible == Visible_true) ? + 0 : XML::getProperty(node, "level", 0); SkillData *data = skill->getData(level); if (!data) data = new SkillData; + const std::string name = XML::langProperty(node, "name", + // TRANSLATORS: skills dialog. skill id + strprintf(_("Skill %u"), skill->id)); data->name = name; const std::string icon = XML::getProperty(node, "icon", ""); data->setIcon(icon); diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h index 2b5e4f070..b4ef43e38 100644 --- a/src/gui/windows/skilldialog.h +++ b/src/gui/windows/skilldialog.h @@ -167,10 +167,11 @@ class SkillDialog final : public Window, private: void addSkillDuration(SkillInfo *const skill); + SkillInfo *loadSkill(XmlNodePtr node, + SkillModel *const model); + void loadSkillData(XmlNodePtr node, - const std::string &name, - SkillInfo *const skill, - const int level); + SkillInfo *const skill); typedef std::map<int, SkillInfo*> SkillMap; SkillMap mSkills; |