diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-10-22 16:17:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-10-22 16:17:03 +0300 |
commit | 2131f55532ee9e71b41de99aff0718346fb184c6 (patch) | |
tree | 1aa214c995d2d5a05d8a02cf6b35dc4c6129d687 | |
parent | abdb8299382a797728b8dac80f6e687c90fb07ab (diff) | |
download | plus-2131f55532ee9e71b41de99aff0718346fb184c6.tar.gz plus-2131f55532ee9e71b41de99aff0718346fb184c6.tar.bz2 plus-2131f55532ee9e71b41de99aff0718346fb184c6.tar.xz plus-2131f55532ee9e71b41de99aff0718346fb184c6.zip |
Move equipment window slots names mapping to id to separate file.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/client.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.cpp | 109 | ||||
-rw-r--r-- | src/gui/windows/equipmentwindow.h | 4 | ||||
-rw-r--r-- | src/resources/equipmentslots.h | 91 |
6 files changed, 114 insertions, 94 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 684f6afd4..83860b0a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -615,6 +615,7 @@ SET(SRCS resources/effectdescription.h resources/emoteinfo.h resources/emotesprite.h + resources/equipmentslots.h resources/db/emotedb.cpp resources/db/emotedb.h resources/db/homunculusdb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index da4e77bf4..7b948ac50 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -79,6 +79,7 @@ dyecmd_SOURCES = gui/cliprect.cpp \ resources/effectdescription.h \ resources/emoteinfo.h \ resources/emotesprite.h \ + resources/equipmentslots.h \ resources/image.cpp \ resources/image.h \ resources/imagehelper.cpp \ diff --git a/src/client.cpp b/src/client.cpp index 497717339..690c2b434 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -62,6 +62,7 @@ #include "gui/windows/changepassworddialog.h" #include "gui/windows/charselectdialog.h" #include "gui/windows/connectiondialog.h" +#include "gui/windows/equipmentwindow.h" #include "gui/windows/logindialog.h" #include "gui/windows/npcdialog.h" #include "gui/windows/okdialog.h" @@ -1262,6 +1263,7 @@ int Client::gameExec() // ModDB::load(); StatusEffect::load(); Units::loadUnits(); + EquipmentWindow::prepareSlotNames(); ActorSprite::load(); diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index c5933b106..e37d623d6 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -45,6 +45,7 @@ #include "gui/widgets/playerbox.h" #include "gui/widgets/tabstrip.h" +#include "resources/equipmentslots.h" #include "resources/imageset.h" #include "resources/itemslot.h" @@ -57,6 +58,7 @@ EquipmentWindow *equipmentWindow = nullptr; EquipmentWindow *beingEquipmentWindow = nullptr; static const int BOX_COUNT = 22; +std::map<std::string, int> EquipmentWindow::mSlotNames; EquipmentWindow::EquipmentWindow(Equipment *const equipment, Being *const being, @@ -644,104 +646,23 @@ void EquipmentWindow::loadSlot(const XmlNodePtr slotNode, mMaxY = y + mBoxSize; } -int EquipmentWindow::parseSlotName(const std::string &name) +void EquipmentWindow::prepareSlotNames() { - int id = -1; - if (name == "shoes" || name == "boot" - || name == "boots" || name == "slot4") - { - id = 4; - } - else if (name == "bottomclothes" || name == "bottom" - || name == "pants" || name == "slot3") - { - id = 3; - } - else if (name == "topclothes" || name == "top" - || name == "torso" || name == "body" || name == "slot0") - { - id = 0; - } - else if (name == "misc1" || name == "cape" || name == "slot5") - { - id = 5; - } - else if (name == "misc2" || name == "scarf" - || name == "scarfs" || name == "slot7") - { - id = 7; - } - else if (name == "hat" || name == "hats" || name == "slot2") - { - id = 2; - } - else if (name == "wings" || name == "slot6") - { - id = 6; - } - else if (name == "glove" || name == "gloves" || name == "slot1") - { - id = 1; - } - else if (name == "weapon" || name == "weapons" || name == "slot8") - { - id = 8; - } - else if (name == "shield" || name == "shields" || name == "slot9") - { - id = 9; - } - else if (name == "amulet" || name == "amulets" || name == "slot11") - { - id = 11; - } - else if (name == "ring" || name == "rings" || name == "slot12") + const int sz = sizeof(equipmentSlots) / sizeof(EquipmentSlotMap); + mSlotNames.clear(); + for (int f = 0; f < sz; f ++) { - id = 12; - } - else if (name == "arrow" || name == "arrows" - || name == "ammo" || name == "slot10") - { - id = 10; - } - else if (name == "slot13") - { - id = 13; - } - else if (name == "slot14") - { - id = 14; - } - else if (name == "slot15") - { - id = 15; - } - else if (name == "slot16") - { - id = 16; - } - else if (name == "slot17") - { - id = 17; - } - else if (name == "slot18") - { - id = 18; - } - else if (name == "slot19") - { - id = 19; - } - else if (name == "slot20") - { - id = 20; - } - else if (name == "slot21") - { - id = 21; + const EquipmentSlotMap &slotMap = equipmentSlots[f]; + mSlotNames[slotMap.name] = slotMap.id; } +} - return id; +int EquipmentWindow::parseSlotName(const std::string &name) +{ + std::map<std::string, int>::const_iterator it = mSlotNames.find(name); + if (it != mSlotNames.end()) + return (*it).second; + return -1; } void EquipmentWindow::fillDefault() diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h index 8c77b6d28..5295e20b5 100644 --- a/src/gui/windows/equipmentwindow.h +++ b/src/gui/windows/equipmentwindow.h @@ -94,6 +94,8 @@ class EquipmentWindow final : public Window, void recalcSize(); + static void prepareSlotNames(); + private: Item *getItem(const int x, const int y) const A_WARN_UNUSED; @@ -123,6 +125,8 @@ class EquipmentWindow final : public Window, static int parseSlotName(const std::string &name) A_WARN_UNUSED; + static std::map<std::string, int> mSlotNames; + Equipment *mEquipment; PlayerBox *mPlayerBox; diff --git a/src/resources/equipmentslots.h b/src/resources/equipmentslots.h new file mode 100644 index 000000000..31373a8e4 --- /dev/null +++ b/src/resources/equipmentslots.h @@ -0,0 +1,91 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_EQUIPMENTSLOTS_H +#define RESOURCES_EQUIPMENTSLOTS_H + +#include "localconsts.h" + +struct EquipmentSlotMap final +{ + const char *const name; + 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} +}; + +#endif // RESOURCES_EQUIPMENTSLOTS_H |