diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-06-23 17:09:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-06-23 17:09:31 +0300 |
commit | 59425e630f91a1ad7de847142ef21ab99a1ca194 (patch) | |
tree | 35bc8f9e5b457d669c6758b6bcbb973a99b451cb /src | |
parent | 4327ba13441b3f7cf8b7c5e66d0e445463142779 (diff) | |
download | manaplus-59425e630f91a1ad7de847142ef21ab99a1ca194.tar.gz manaplus-59425e630f91a1ad7de847142ef21ab99a1ca194.tar.bz2 manaplus-59425e630f91a1ad7de847142ef21ab99a1ca194.tar.xz manaplus-59425e630f91a1ad7de847142ef21ab99a1ca194.zip |
Move equipment window slot names into file equipmentslots.xml
Diffstat (limited to 'src')
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.cpp | 32 | ||||
-rw-r--r-- | src/resources/equipmentslots.h | 62 |
3 files changed, 29 insertions, 66 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp index 15d5a4538..e6653942b 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -621,6 +621,7 @@ DefaultsData* getPathsDefaults() AddDEF("badgesFile", "badges.xml"); AddDEF("badgesPatchFile", "badges_patch.xml"); AddDEF("badgesPatchDir", "badges.d"); + AddDEF("equipmentSlotsFile", "equipmentslots.xml"); AddDEF("weaponsFile", "weapons.xml"); AddDEF("poisonEffectName", "poison"); AddDEF("cartEffectName", "cart"); diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index 3aa4ca241..ce2d9fa67 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -46,9 +46,11 @@ #include "resources/equipmentslots.h" #include "resources/imageset.h" +#include "utils/checkutils.h" #include "utils/delete2.h" #include "utils/dtor.h" #include "utils/gettext.h" +#include "utils/xml.h" #include "net/inventoryhandler.h" @@ -741,12 +743,34 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode, void EquipmentWindow::prepareSlotNames() { - const int sz = sizeof(equipmentSlots) / sizeof(EquipmentSlotMap); mSlotNames.clear(); - for (int f = 0; f < sz; f ++) + XML::Document doc(paths.getStringValue("equipmentSlotsFile"), + UseResman_true, + SkipError_false); + const XmlNodePtrConst root = doc.rootNode(); + if (!root) + return; + + for_each_xml_child_node(slotNode, root) { - const EquipmentSlotMap &slotMap = equipmentSlots[f]; - mSlotNames[slotMap.name] = slotMap.id; + if (!xmlNameEqual(slotNode, "slot")) + continue; + const std::string name = XML::getProperty(slotNode, "name", ""); + if (name.empty()) + { + reportAlways("Empty slot name detected."); + continue; + } + + const int slot = XML::getProperty(slotNode, "slot", -1); + if (slot < 0 || slot >= BOX_COUNT) + { + reportAlways("Wrong slot id '%d' for slot with name '%s'", + slot, + name.c_str()); + continue; + } + mSlotNames[name] = slot; } } diff --git a/src/resources/equipmentslots.h b/src/resources/equipmentslots.h index ec1eb9b27..7e4b8482d 100644 --- a/src/resources/equipmentslots.h +++ b/src/resources/equipmentslots.h @@ -31,66 +31,4 @@ struct EquipmentSlotMap final const int id; }; -static const EquipmentSlotMap equipmentSlots[] = -{ - {"topclothes", 0}, - {"top", 0}, - {"torso", 0}, - {"body", 0}, - {"slot0", 0}, - {"glove", 1}, - {"gloves", 1}, - {"slot1", 1}, - {"hat", 2}, - {"hats", 2}, - {"slot2", 2}, - {"bottomclothes", 3}, - {"bottom", 3}, - {"pants", 3}, - {"slot3", 3}, - {"shoes", 4}, - {"boot", 4}, - {"boots", 4}, - {"slot4", 4}, - {"misc1", 5}, - {"cape", 5}, - {"slot5", 5}, - {"wings", 6}, - {"slot6", 6}, - {"misc2", 7}, - {"scarf", 7}, - {"scarfs", 7}, - {"slot7", 7}, - {"weapon", 8}, - {"weapons", 8}, - {"slot8", 8}, - {"shield", 9}, - {"shields", 9}, - {"slot9", 9}, - {"arrow", 10}, - {"arrows", 10}, - {"ammo", 10}, - {"slot10", 10}, - {"amulet", 11}, - {"amulets", 11}, - {"slot11", 11}, - {"ring", 12}, - {"rings", 12}, - {"slot12", 12}, - {"slot13", 13}, - {"slot14", 14}, - {"slot15", 15}, - {"slot16", 16}, - {"slot17", 17}, - {"slot18", 18}, - {"slot19", 19}, - {"slot20", 20}, - {"slot21", 21}, - {"slot22", 22}, - {"slot23", 23}, - {"slot24", 24}, - {"slot25", 25}, - {"slot26", 26} -}; - #endif // RESOURCES_EQUIPMENTSLOTS_H |