From 7ff3f418b0d83e3e825e06e699b5e3185c8630ed Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Sun, 6 Oct 2024 02:10:12 -0300 Subject: [PATCH] feat: display tier UI (GameThingUpgradeClassification) (#895) --- data/images/inventory/tiers-strip-big.png | Bin 0 -> 315 bytes data/images/inventory/tiers-strip.png | Bin 0 -> 265 bytes data/styles/10-items.otui | 30 ++++++++++++++- modules/game_containers/containers.lua | 3 ++ .../game_cyclopedia/cyclopedia_widgets.otui | 2 +- .../tab/character/character.lua | 36 +++++++----------- .../imbuementtracker.lua | 1 + modules/game_inventory/inventory.lua | 2 +- modules/game_playertrade/playertrade.lua | 1 + modules/game_playertrade/tradewindow.otui | 2 +- modules/gamelib/items.lua | 19 +++++++++ src/client/game.h | 2 +- src/client/item.h | 3 ++ src/client/luafunctions.cpp | 1 + src/client/luavaluecasts_client.cpp | 2 + src/client/protocolgameparse.cpp | 32 ++++++++-------- 16 files changed, 91 insertions(+), 45 deletions(-) create mode 100644 data/images/inventory/tiers-strip-big.png create mode 100644 data/images/inventory/tiers-strip.png diff --git a/data/images/inventory/tiers-strip-big.png b/data/images/inventory/tiers-strip-big.png new file mode 100644 index 0000000000000000000000000000000000000000..8352a13b97e6c0a85623be30a86b9a8358d0ed57 GIT binary patch literal 315 zcmV-B0mS}^P)ME#3=8c7-~#}!+X)tq z*C(VS9dDf-gcyi@?v3aB8vyXQ9I74^+6TOKta-(8c<0qyJnX#UcB$)fXfc;Vr$&A$ zxg%^VomP2mHACd~3oD+|IITLV_~Z8Rxg1)|<TPXc?cY?t)Xt=} z{af2!4lU-~<>v(E1)w9VH@Bu99BUH1>5-?@r4K;Gq!Oe1OR{E540HO4KGv2 zgw)M(+0~cEWpBb*UQwggtCfz|E4A)&n+yQ!)SqlzmoPbAT45G*&Bdehq-intCa+U} zUPEqSIR#ox_IS0NM9nWY#Tp*XOVbZ12yc^OV%9d(68HL8Uf!B49dAze=xP$vzM}O! z=V 0 then - listItem.rarity:setImageSource("/images/ui/frames") - listItem.rarity:setImageClip(torect(g_game.getRectFrame(frame))) - gridItem.rarity:setImageSource("/images/ui/frames") - gridItem.rarity:setImageClip(torect(g_game.getRectFrame(frame))) - else - listItem.rarity:setImageSource("") - gridItem.rarity:setImageSource("") - end - ]]-- - colorIndex = 3 - colorIndex end end @@ -324,14 +313,18 @@ function Cyclopedia.loadCharacterItems(data) name = name, amount = data.amount, type = type - -- value = thing:getResultingValue() } - local insertedItem = Cyclopedia.Character.Items[data.itemId] + local itemKey = data.itemId .. "-" .. (data.tier or "no_tier") + local insertedItem = Cyclopedia.Character.Items[itemKey] if insertedItem then insertedItem.amount = insertedItem.amount + data.amount else - Cyclopedia.Character.Items[data.itemId] = data_t + Cyclopedia.Character.Items[itemKey] = { + itemId = data.itemId, + tier = data.tier, + data = data_t + } end end @@ -352,11 +345,8 @@ function Cyclopedia.loadCharacterItems(data) local sortedItems = {} - for itemId, data in pairs(Cyclopedia.Character.Items) do - table.insert(sortedItems, { - itemId = itemId, - data = data - }) + for _, itemData in pairs(Cyclopedia.Character.Items) do + table.insert(sortedItems, itemData) end local function compareByName(a, b) diff --git a/modules/game_imbuementtracker/imbuementtracker.lua b/modules/game_imbuementtracker/imbuementtracker.lua index 8ba716be2b..af2fceef68 100644 --- a/modules/game_imbuementtracker/imbuementtracker.lua +++ b/modules/game_imbuementtracker/imbuementtracker.lua @@ -153,6 +153,7 @@ end local function addTrackedItem(item) local trackedItem = g_ui.createWidget('InventoryItem') trackedItem.item:setItem(item['item']) + ItemsDatabase.setTier(trackedItem.item, trackedItem.item:getItem()) trackedItem.item:setVirtual(true) local maxDuration = 0 for _, imbuementSlot in ipairs(item['slots']) do diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index 548f2149b3..9855c20697 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -124,7 +124,7 @@ local function inventoryEvent(player, slot, item, oldItem) end end end - + ItemsDatabase.setTier(slotPanel.item, item) end local function onSoulChange(localPlayer, soul) diff --git a/modules/game_playertrade/playertrade.lua b/modules/game_playertrade/playertrade.lua index c3fbd34d5e..ea9a9a76f6 100644 --- a/modules/game_playertrade/playertrade.lua +++ b/modules/game_playertrade/playertrade.lua @@ -57,6 +57,7 @@ function fillTrade(name, items, counter) for index, item in ipairs(items) do local itemWidget = g_ui.createWidget('Item', tradeContainer) itemWidget:setItem(item) + ItemsDatabase.setTier(itemWidget, item) itemWidget:setVirtual(true) itemWidget:setMargin(0) itemWidget.onClick = function() diff --git a/modules/game_playertrade/tradewindow.otui b/modules/game_playertrade/tradewindow.otui index 15708d1479..dd23050796 100644 --- a/modules/game_playertrade/tradewindow.otui +++ b/modules/game_playertrade/tradewindow.otui @@ -2,7 +2,7 @@ TradeWindow < MiniWindow !text: tr('Trade') height: 150 - UIItem + Item id: tradeItem virtual: true size: 16 16 diff --git a/modules/gamelib/items.lua b/modules/gamelib/items.lua index 1fe02c28fa..1e409d9b1f 100644 --- a/modules/gamelib/items.lua +++ b/modules/gamelib/items.lua @@ -5002,3 +5002,22 @@ function ItemsDatabase.getSellValueAndColor(clientID) end return 0, "" end + +function ItemsDatabase.setTier(widget, item) + if not g_game.getFeature(GameThingUpgradeClassification) or not widget then + return + end + local tier = type(item) == "number" and item or (item and item:getTier()) or 0 + if tier and tier > 0 then + local xOffset = (math.min(math.max(tier, 1), 10) - 1) * 9 + widget.tier:setImageClip({ + x = xOffset, + y = 0, + width = 10, + height = 9 + }) + widget.tier:setVisible(true) + else + widget.tier:setVisible(false) + end +end diff --git a/src/client/game.h b/src/client/game.h index ff0c9055d1..43746be8f0 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -330,7 +330,7 @@ struct BosstiarySlotsData struct ItemSummary { uint16_t itemId; - uint8_t classification; + uint8_t tier; uint32_t amount; }; diff --git a/src/client/item.h b/src/client/item.h index 3c305742d6..10f1f40a22 100644 --- a/src/client/item.h +++ b/src/client/item.h @@ -88,12 +88,14 @@ class Item : public Thing void setPosition(const Position& position, uint8_t stackPos = 0, bool hasElevation = false) override; void setTooltip(const std::string& str) { m_tooltip = str; } void setDurationTime(const uint32_t durationTime) { m_durationTime = durationTime; } + void setTier(const uint8_t tier) { m_tier = tier; } int getCountOrSubType() { return m_countOrSubType; } int getSubType(); int getCount() { return isStackable() ? m_countOrSubType : 1; } std::string getTooltip() { return m_tooltip; } uint32_t getDurationTime() { return m_durationTime; } + uint8_t getTier() { return m_tier; } bool isValid() { return getThingType() != nullptr; } @@ -160,6 +162,7 @@ class Item : public Thing uint16_t m_countOrSubType{ 0 }; uint32_t m_durationTime{ 0 }; + uint8_t m_tier{ 0 }; Color m_color{ Color::white }; diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 58676788aa..e2466be8f5 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -702,6 +702,7 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("getId", &Item::getId); g_lua.bindClassMemberFunction("getTooltip", &Item::getTooltip); g_lua.bindClassMemberFunction("getDurationTime", &Item::getDurationTime); + g_lua.bindClassMemberFunction("getTier", &Item::getTier); g_lua.bindClassMemberFunction("isStackable", &Item::isStackable); g_lua.bindClassMemberFunction("isMarketable", &Item::isMarketable); diff --git a/src/client/luavaluecasts_client.cpp b/src/client/luavaluecasts_client.cpp index 3d9e051415..8dcb3c29e7 100644 --- a/src/client/luavaluecasts_client.cpp +++ b/src/client/luavaluecasts_client.cpp @@ -929,6 +929,8 @@ int push_luavalue(const ItemSummary& item) { g_lua.createTable(0, 2); g_lua.pushInteger(item.itemId); g_lua.setField("itemId"); + g_lua.pushInteger(item.tier); + g_lua.setField("tier"); g_lua.pushInteger(item.amount); g_lua.setField("amount"); return 1; diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index f7ee89f218..bbdc4371b1 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -3605,7 +3605,7 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id) if (g_game.getFeature(Otc::GameThingUpgradeClassification)) { if (item->getClassification()) { - msg->getU8(); // Item tier + item->setTier(msg->getU8()); } } @@ -4199,13 +4199,13 @@ void ProtocolGame::parseCyclopediaCharacterInfo(const InputMessagePtr& msg) const auto& itemCreated = Item::create(itemId); const uint16_t classification = itemCreated->getClassification(); - uint8_t itemClass = 0; + uint8_t itemTier = 0; if (classification > 0) { - itemClass = msg->getU8(); + itemTier = msg->getU8(); } item.itemId = itemId; - item.classification = itemClass; + item.tier = itemTier; item.amount = msg->getU32(); data.inventory.emplace_back(item); } @@ -4217,13 +4217,13 @@ void ProtocolGame::parseCyclopediaCharacterInfo(const InputMessagePtr& msg) const auto& itemCreated = Item::create(itemId); const uint16_t classification = itemCreated->getClassification(); - uint8_t itemClass = 0; + uint8_t itemTier = 0; if (classification > 0) { - itemClass = msg->getU8(); + itemTier = msg->getU8(); } item.itemId = itemId; - item.classification = itemClass; + item.tier = itemTier; item.amount = msg->getU32(); data.store.emplace_back(item); } @@ -4235,13 +4235,13 @@ void ProtocolGame::parseCyclopediaCharacterInfo(const InputMessagePtr& msg) const auto& itemCreated = Item::create(itemId); const uint16_t classification = itemCreated->getClassification(); - uint8_t itemClass = 0; + uint8_t itemTier = 0; if (classification > 0) { - itemClass = msg->getU8(); + itemTier = msg->getU8(); } item.itemId = itemId; - item.classification = itemClass; + item.tier = itemTier; item.amount = msg->getU32(); data.stash.emplace_back(item); } @@ -4253,13 +4253,13 @@ void ProtocolGame::parseCyclopediaCharacterInfo(const InputMessagePtr& msg) const auto& itemCreated = Item::create(itemId); const uint16_t classification = itemCreated->getClassification(); - uint8_t itemClass = 0; + uint8_t itemTier = 0; if (classification > 0) { - itemClass = msg->getU8(); + itemTier = msg->getU8(); } item.itemId = itemId; - item.classification = itemClass; + item.tier = itemTier; item.amount = msg->getU32(); data.depot.emplace_back(item); } @@ -4271,13 +4271,13 @@ void ProtocolGame::parseCyclopediaCharacterInfo(const InputMessagePtr& msg) const auto& itemCreated = Item::create(itemId); const uint16_t classification = itemCreated->getClassification(); - uint8_t itemClass = 0; + uint8_t itemTier = 0; if (classification > 0) { - itemClass = msg->getU8(); + itemTier = msg->getU8(); } item.itemId = itemId; - item.classification = itemClass; + item.tier = itemTier; item.amount = msg->getU32(); data.inbox.emplace_back(item); }