Skip to content

Commit

Permalink
feat: display tier UI (GameThingUpgradeClassification) (mehah#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokekanon authored Oct 6, 2024
1 parent 3ca46d4 commit 7ff3f41
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 45 deletions.
Binary file added data/images/inventory/tiers-strip-big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/inventory/tiers-strip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 28 additions & 2 deletions data/styles/10-items.otui
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ Item < UIItem

$disabled:
color: #646464

UIWidget
id: tier
size: 10 9
image-source: /images/inventory/tiers-strip
image-clip: 0 0 10 9
image-size: 10 9
anchors.top: parent.top
anchors.right: parent.right
phantom: true
focusable: false
visible: false
image-smooth: true

MainInventoryItem < UIWidget
image-source: /images/inventory/containerslot
image-border: 3
Expand Down Expand Up @@ -180,5 +192,19 @@ MainInventoryItem < UIWidget

Label
id: Duration
anchors.fill: parent
anchors.bottom: parent.bottom
anchors.left: parent.left
phantom: true
UIWidget
id: tier
size: 10 9
image-source: /images/inventory/tiers-strip
image-clip: 0 0 10 9
image-size: 10 9
anchors.top: parent.top
anchors.right: parent.right
phantom: true
focusable: false
visible: false
image-smooth: true

3 changes: 3 additions & 0 deletions modules/game_containers/containers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function refreshContainerItems(container)
for slot = 0, container:getCapacity() - 1 do
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
itemWidget:setItem(container:getItem(slot))
ItemsDatabase.setRarityItem(itemWidget, container:getItem(slot))
ItemsDatabase.setTier(itemWidget, container:getItem(slot))
end

if container:hasPages() then
Expand Down Expand Up @@ -138,6 +140,7 @@ function onContainerOpen(container, previousContainer)
itemWidget:setId('item' .. slot)
itemWidget:setItem(container:getItem(slot))
ItemsDatabase.setRarityItem(itemWidget, container:getItem(slot))
ItemsDatabase.setTier(itemWidget, container:getItem(slot))
itemWidget:setMargin(0)
itemWidget.position = container:getSlotPosition(slot)

Expand Down
2 changes: 1 addition & 1 deletion modules/game_cyclopedia/cyclopedia_widgets.otui
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ CharacterListItem < UIWidget
id: rarity
margin: 1
anchors.fill: ItemBackground
UIItem
Item
id: item
anchors.fill: ItemBackground
Label
Expand Down
36 changes: 13 additions & 23 deletions modules/game_cyclopedia/tab/character/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function showCharacter()
if item then
itemWidget:setStyle("InventoryItemCyclopedia")
itemWidget:setItem(item)
ItemsDatabase.setRarityItem(itemWidget, itemWidget:getItem())
ItemsDatabase.setTier(itemWidget, itemWidget:getItem())
itemWidget:setIcon("")
else
itemWidget:setStyle(Cyclopedia.InventorySlotStyles[i].name)
Expand Down Expand Up @@ -275,28 +277,15 @@ function Cyclopedia.reloadCharacterItems()

if data.visible then
local listItem = g_ui.createWidget("CharacterListItem", UI.CharacterItems.ListBase.list)
-- local frame = g_game.getItemFrame(data.value)
listItem.item:setItemId(itemId)
listItem.name:setText(data.name)
ItemsDatabase.setRarityItem(listItem.item, listItem.item:getItem())
ItemsDatabase.setTier(listItem.item, item.tier)
listItem.amount:setText(data.amount)
listItem:setBackgroundColor(colors[colorIndex])

local gridItem = g_ui.createWidget("CharacterGridItem", UI.CharacterItems.gridBase.grid)
gridItem.item:setItemId(itemId)
gridItem.amount:setText(data.amount)

--[[
if frame > 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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions modules/game_imbuementtracker/imbuementtracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/game_inventory/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions modules/game_playertrade/playertrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion modules/game_playertrade/tradewindow.otui
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TradeWindow < MiniWindow
!text: tr('Trade')
height: 150

UIItem
Item
id: tradeItem
virtual: true
size: 16 16
Expand Down
19 changes: 19 additions & 0 deletions modules/gamelib/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/client/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ struct BosstiarySlotsData
struct ItemSummary
{
uint16_t itemId;
uint8_t classification;
uint8_t tier;
uint32_t amount;
};

Expand Down
3 changes: 3 additions & 0 deletions src/client/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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 };

Expand Down
1 change: 1 addition & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Item>("getId", &Item::getId);
g_lua.bindClassMemberFunction<Item>("getTooltip", &Item::getTooltip);
g_lua.bindClassMemberFunction<Item>("getDurationTime", &Item::getDurationTime);
g_lua.bindClassMemberFunction<Item>("getTier", &Item::getTier);

g_lua.bindClassMemberFunction<Item>("isStackable", &Item::isStackable);
g_lua.bindClassMemberFunction<Item>("isMarketable", &Item::isMarketable);
Expand Down
2 changes: 2 additions & 0 deletions src/client/luavaluecasts_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 7ff3f41

Please sign in to comment.