summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-09 18:47:10 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-09 18:47:10 +0300
commitb3fa7a53a29a1001935514a38f140af2b816771a (patch)
treea1d9449975a266e64bcc377ca692eb8d04f645e4 /src/resources/db
parentc0dbb0d20fb321ecf12cdcc22d960b3572e35286 (diff)
downloadmv-b3fa7a53a29a1001935514a38f140af2b816771a.tar.gz
mv-b3fa7a53a29a1001935514a38f140af2b816771a.tar.bz2
mv-b3fa7a53a29a1001935514a38f140af2b816771a.tar.xz
mv-b3fa7a53a29a1001935514a38f140af2b816771a.zip
Allow for each item replace equip/use menu item to custom menu.
Separate menus supproted for inventory, storage, cart.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/itemdb.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 6a7ed29eb..93c0e845a 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -236,6 +236,56 @@ void ItemDB::load()
}
}
+static void loadMenu(XmlNodePtrConst parentNode,
+ STD_VECTOR<ItemMenuItem> &menu)
+{
+ for_each_xml_child_node(node, parentNode)
+ {
+ if (xmlNameEqual(node, "menu"))
+ {
+ const std::string name1 = XML::langProperty(node,
+ "name1", "");
+ const std::string name2 = XML::langProperty(node,
+ "name2", "");
+ const std::string command1 = XML::getProperty(node,
+ "command1", "");
+ const std::string command2 = XML::getProperty(node,
+ "command2", command1);
+ menu.push_back(ItemMenuItem(name1,
+ name2,
+ command1,
+ command2));
+ }
+ }
+}
+
+static bool getIsEquipment(const ItemDbType type)
+{
+ switch (type)
+ {
+ case ItemDbType::EQUIPMENT_ONE_HAND_WEAPON:
+ case ItemDbType::EQUIPMENT_TWO_HANDS_WEAPON:
+ case ItemDbType::EQUIPMENT_TORSO:
+ case ItemDbType::EQUIPMENT_ARMS:
+ case ItemDbType::EQUIPMENT_HEAD:
+ case ItemDbType::EQUIPMENT_LEGS:
+ case ItemDbType::EQUIPMENT_SHIELD:
+ case ItemDbType::EQUIPMENT_RING:
+ case ItemDbType::EQUIPMENT_NECKLACE:
+ case ItemDbType::EQUIPMENT_FEET:
+ case ItemDbType::EQUIPMENT_AMMO:
+ case ItemDbType::EQUIPMENT_CHARM:
+ return true;
+ case ItemDbType::UNUSABLE:
+ case ItemDbType::USABLE:
+ case ItemDbType::CARD:
+ case ItemDbType::SPRITE_RACE:
+ case ItemDbType::SPRITE_HAIR:
+ default:
+ return false;
+ }
+}
+
void ItemDB::loadXmlFile(const std::string &fileName,
int &tagNum,
const SkipError skipError)
@@ -582,6 +632,18 @@ void ItemDB::loadXmlFile(const std::string &fileName,
{
loadOrderSprite(itemInfo, itemChild, false);
}
+ else if (xmlNameEqual(itemChild, "inventory"))
+ {
+ loadMenu(itemChild, itemInfo->getInventoryMenu());
+ }
+ else if (xmlNameEqual(itemChild, "storage"))
+ {
+ loadMenu(itemChild, itemInfo->getStorageMenu());
+ }
+ else if (xmlNameEqual(itemChild, "cart"))
+ {
+ loadMenu(itemChild, itemInfo->getCartMenu());
+ }
}
/*
@@ -643,6 +705,47 @@ void ItemDB::loadXmlFile(const std::string &fileName,
}
}
+ STD_VECTOR<ItemMenuItem> &inventoryMenu = itemInfo->getInventoryMenu();
+
+ if (inventoryMenu.empty())
+ {
+ std::string name1 = itemInfo->getUseButton();
+ std::string name2 = itemInfo->getUseButton2();
+ const bool isEquipment = getIsEquipment(itemInfo->getType());
+
+ if (isEquipment)
+ {
+ if (name1.empty())
+ {
+ // TRANSLATORS: popup menu item
+ name1 = _("Equip");
+ }
+ if (name2.empty())
+ {
+ // TRANSLATORS: popup menu item
+ name2 = _("Unequip");
+ }
+ }
+ else
+ {
+ if (name1.empty())
+ {
+ // TRANSLATORS: popup menu item
+ name1 = _("Use");
+ }
+ if (name2.empty())
+ {
+ // TRANSLATORS: popup menu item
+ name2 = _("Use");
+ }
+ }
+ inventoryMenu.push_back(ItemMenuItem(
+ name1,
+ name2,
+ "useinv 'INVINDEX'",
+ "useinv 'INVINDEX'"));
+ }
+
#define CHECK_PARAM(param) \
if (param.empty()) \
{ \