Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ToolstipsV8 for inventory items #740

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions modules/game_interface/widgets/uiitem.lua
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ function UIItem:onHoverChange(hovered)
draggingWidget.hoveredWho = nil
end
end

if g_game.getFeature(GameItemTooltipV8) then
local tooltip = ""
local function splitTextIntoLines(text, maxLineLength)
local words = {}
for word in text:gmatch("%S+") do
table.insert(words, word)
end

local lines = {}
local currentLine = words[1]
for i = 2, #words do
if currentLine:len() + 1 + words[i]:len() > maxLineLength then
table.insert(lines, currentLine)
currentLine = words[i]
else
currentLine = currentLine .. " " .. words[i]
end
end
table.insert(lines, currentLine)

return table.concat(lines, "\n")
end

if self:getItem() and self:getItem():getTooltip():len() > 0 then
tooltip = splitTextIntoLines(self:getItem():getTooltip(), 80)
if tooltip then
self:setTooltip(tooltip)
end
end
end

end

function UIItem:onMouseRelease(mousePosition, mouseButton)
Expand Down
1 change: 1 addition & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ GameContainerFilter = 113
GameEnterGameShowAppearance = 114
GameSmoothWalkElevation = 115
GameNegativeOffset = 116
GameItemTooltipV8 = 117

TextColors = {
red = '#f55e5e', -- '#c83200'
Expand Down
3 changes: 2 additions & 1 deletion src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ namespace Otc
GameEnterGameShowAppearance = 114,
GameSmoothWalkElevation = 115,
GameNegativeOffset = 116,
LastGameFeature = 117
GameItemTooltipV8 = 117,
LastGameFeature = 118
};

enum MagicEffectsType_t : uint8_t
Expand Down
3 changes: 3 additions & 0 deletions src/client/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ class Item : public Thing
void setSubType(int subType) { m_countOrSubType = subType; updatePatterns(); }
void setColor(const Color& c) { if (m_color != c) m_color = c; }
void setPosition(const Position& position, uint8_t stackPos = 0, bool hasElevation = false) override;
void setTooltip(const std::string& str) { m_tooltip = str; }

int getCountOrSubType() { return m_countOrSubType; }
int getSubType();
int getCount() { return isStackable() ? m_countOrSubType : 1; }
std::string getTooltip() { return m_tooltip; }

bool isValid() { return getThingType() != nullptr; }

Expand Down Expand Up @@ -158,6 +160,7 @@ class Item : public Thing
ticks_t m_lastPhase{ 0 };

bool m_async{ true };
std::string m_tooltip;

#ifdef FRAMEWORK_EDITOR
uint16_t m_serverId{ 0 };
Expand Down
3 changes: 3 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,13 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Item>("clone", &Item::clone);

g_lua.bindClassMemberFunction<Item>("setCount", &Item::setCount);
g_lua.bindClassMemberFunction<Item>("setTooltip", &Item::setTooltip);

g_lua.bindClassMemberFunction<Item>("getCount", &Item::getCount);
g_lua.bindClassMemberFunction<Item>("getSubType", &Item::getSubType);
g_lua.bindClassMemberFunction<Item>("getCountOrSubType", &Item::getCountOrSubType);
g_lua.bindClassMemberFunction<Item>("getId", &Item::getId);
g_lua.bindClassMemberFunction<Item>("getTooltip", &Item::getTooltip);

g_lua.bindClassMemberFunction<Item>("isStackable", &Item::isStackable);
g_lua.bindClassMemberFunction<Item>("isMarketable", &Item::isMarketable);
Expand Down
4 changes: 4 additions & 0 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,10 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id)
item->setShader(msg->getString());
}

if (g_game.getFeature(Otc::GameItemTooltipV8)) {
item->setTooltip(msg->getString());
}

return item;
}

Expand Down
Loading