FrameworkZ 4.4.2
Provides a framework for Project Zomboid with various systems.
Loading...
Searching...
No Matches
ToolTipOverride.lua
Go to the documentation of this file.
1require "ISUI/ISToolTipInv"
5FrameworkZ.Overrides.ISToolTipInv_render = ISToolTipInv.render
8 local maxLineLength = 28
9 local lines = {}
10 local line = ""
11 local lineLength = 0
12 local words = {}
14 for word in string.gmatch(text, "%S+") do
15 table.insert(words, word)
16 end
18 for i = 1, #words do
19 local word = words[i]
20 local wordLength = string.len(word)
21
22 if lineLength + wordLength <= maxLineLength then
23 line = line .. " " .. word
24 lineLength = lineLength + wordLength
25 else
26 table.insert(lines, line)
27 line = word
28 lineLength = wordLength
29 end
30 end
31
32 table.insert(lines, line)
33
34 return lines
35end
36
37function FrameworkZ.Overrides.DoTooltip(objTooltip, item, panel)
38 local itemData = item:getModData()["FZ_ITM"]
39
40 objTooltip:render()
41
42 local textureWidth, textureHeight = 64, 64
43 local font = objTooltip:getFont()
44 local lineSpace = objTooltip:getLineSpacing()
45 local yOffset = 5
46
47 if itemData then
48 local itemName = itemData.name
49 local itemDescription = itemData.description
50
51 objTooltip:DrawText(font, itemName, 5.0, yOffset, 1.0, 1.0, 0.8, 1.0)
52 objTooltip:adjustWidth(5, itemName)
53 yOffset = yOffset + lineSpace + 5
54
55 local yTextureOffset = textureHeight + 10
56 objTooltip:DrawTextureScaled(item:getTexture(), panel:getWidth() - textureWidth - 15, 5, textureWidth, textureHeight, 0.75)
57
58 local description = FrameworkZ.Overrides.WordWrapText(itemDescription)
59
60 for k, v in pairs(description) do
61 objTooltip:DrawText(font, v, 5, yOffset, 1, 1, 0.8, 1)
62 objTooltip:adjustWidth(5, v)
63 yOffset = yOffset + lineSpace + 2.5
64 end
65
66 if yTextureOffset > yOffset then
67 yOffset = yTextureOffset
68 end
69
70 panel:drawRect(0, yOffset, panel:getWidth(), 1, panel.borderColor.a, panel.borderColor.r, panel.borderColor.g, panel.borderColor.b)
71
72 yOffset = yOffset + 2.5
73 else
74 objTooltip:DrawText(font, item:getDisplayName(), 5.0, yOffset, 1.0, 1.0, 0.8, 1.0)
75 objTooltip:adjustWidth(5, item:getDisplayName())
76 yOffset = yOffset + lineSpace + 5
77
78 local yTextureOffset = textureHeight + 10
79 objTooltip:DrawTextureScaled(item:getTexture(), panel:getWidth() - textureWidth - 15, 5, textureWidth, textureHeight, 0.75)
80
81 --[[
82 local description = FrameworkZ.Overrides.WordWrapText(item:getDescription())
83
84 for k, v in pairs(description) do
85 objTooltip:DrawText(font, v, 5, yOffset, 1, 1, 0.8, 1)
86 objTooltip:adjustWidth(5, v)
87 yOffset = yOffset + lineSpace + 2.5
88 end
89 --]]
90
91 if yTextureOffset > yOffset then
92 yOffset = yTextureOffset
93 end
94
95 panel:drawRect(0, yOffset, panel:getWidth(), 1, panel.borderColor.a, panel.borderColor.r, panel.borderColor.g, panel.borderColor.b)
96
97 yOffset = yOffset + 2.5
98 end
99
100 local layoutTooltip = objTooltip:beginLayout()
101 layoutTooltip:setMinLabelWidth(128)
102 local layout = nil
103
104 if itemData then
105 local itemInstance = FrameworkZ.Items:GetInstance(itemData.instanceID)
106 local itemCustomFields = itemData.customFields
107
108 for k, v in pairs(itemCustomFields) do
109 layout = layoutTooltip:addItem()
110 layout:setLabel(k .. ":", 1, 1, 0.8, 1)
111
112 if type(v) == "boolean" then
113 if v then
114 layout:setValue("Yes", 1, 1, 1, 1)
115 else
116 layout:setValue("No", 1, 1, 1, 1)
117 end
118 else
119 if v.get then
120 layout:setValue(tostring(v.get(itemInstance)), 1, 1, 1, 1)
121 else
122 layout:setValue(v, 1, 1, 1, 1)
123 end
124 end
125 end
126 end
127
128 local weightEquipped = item:getCleanString(item:getEquippedWeight())
129 local weightUnequipped = item:getUnequippedWeight()
130 layout = layoutTooltip:addItem()
131 layout:setLabel("Weight (Unequipped):", 1, 1, 0.8, 1)
132
133 if weightUnequipped > 0 and weightUnequipped < 0.01 then
134 weightUnequipped = "<0.01"
135 else
136 weightUnequipped = item:getCleanString(weightUnequipped)
137 end
138
139 if not item:isEquipped() then
140 layout:setValue("*" .. tostring(weightUnequipped) .. "*", 1, 1, 1, 1)
141 else
142 layout:setValue(tostring(weightUnequipped), 1, 1, 1, 1)
143 end
144
145 layout = layoutTooltip:addItem()
146 layout:setLabel("Weight (Equipped):", 1, 1, 0.8, 1)
147
148 if item:isEquipped() then
149 layout:setValue("*" .. tostring(weightEquipped) .. "*", 1, 1, 1, 1)
150 else
151 layout:setValue(tostring(weightEquipped), 1, 1, 1, 1)
152 end
153
154 --[[
155 if not item:IsWeapon() and not item:IsClothing() and not item:IsDrainable() and not string.match(item:getFullType(), "Walkie") then
156 local unequippedWeight = item:getUnequippedWeight()
157
158 if unequippedWeight > 0 and unequippedWeight < 0.01 then
159 unequippedWeight = 0.01
160 end
161
162 layout:setValueRightNoPlus(unequippedWeight)
163 elseif item:isEquipped() then
164 local equippedWeight = item:getCleanString(item:getEquippedWeight())
165
166 layout:setValue(equippedWeight .. " (" .. item:getCleanString(item:getUnequippedWeight()) .. " " .. getText("Tooltip_item_Unequipped") .. ")", 1.0, 1.0, 1.0, 1.0)
167 elseif item:getAttachedSlot() > -1 then
168 local hotbarEquippedWeight = item:getCleanString(item:getHotbarEquippedWeight())
169
170 layout:setValue(hotbarEquippedWeight .. " (" .. item:getCleanString(item:getUnequippedWeight()) .. " " .. getText("Tooltip_item_Unequipped") .. ")", 1.0, 1.0, 1.0, 1.0)
171 else
172 local unequippedWeight = item:getCleanString(item:getUnequippedWeight())
173
174 layout:setValue(unequippedWeight .. " (" .. item:getCleanString(item:getEquippedWeight()) .. " " .. getText("Tooltip_item_Equipped") .. ")", 1.0, 1.0, 1.0, 1.0)
175 end
176 --]]
177
178 if item:getTooltip() ~= nil then
179 layout = layoutTooltip:addItem()
180 layout:setLabel(getText(item:getTooltip()), 1, 1, 0.8, 1)
181 end
182
183 yOffset = layoutTooltip:render(5, yOffset, objTooltip)
184 objTooltip:endLayout(layoutTooltip)
185 yOffset = yOffset + 5
186 objTooltip:setHeight(yOffset)
187
188 if objTooltip:getWidth() < 256 then
189 objTooltip:setWidth(256)
190 end
191end
192
193ISToolTipInv.render = function(self)
194 local mx = getMouseX() + 24
195 local my = getMouseY() + 24
196
197 if not self.followMouse then
198 mx = self:getX()
199 my = self:getY()
200 if self.anchorBottomLeft then
201 mx = self.anchorBottomLeft.x
202 my = self.anchorBottomLeft.y
203 end
204 end
205
206 self.tooltip:setX(mx + 11);
207 self.tooltip:setY(my);
208
209 self.tooltip:setWidth(50)
210 self.tooltip:setMeasureOnly(true)
211
212 if self.item ~= nil and self.tooltip ~= nil then
214 else
215 self.item:DoTooltip(self.tooltip);
216 end
217
218 self.tooltip:setMeasureOnly(false)
219
220 -- clampy x, y
221
222 local myCore = getCore();
223 local maxX = myCore:getScreenWidth();
224 local maxY = myCore:getScreenHeight();
225
226 local tw = self.tooltip:getWidth();
227 local th = self.tooltip:getHeight();
228
229 self.tooltip:setX(math.max(0, math.min(mx + 11, maxX - tw - 1)));
230
231 if not self.followMouse and self.anchorBottomLeft then
232 self.tooltip:setY(math.max(0, math.min(my - th, maxY - th - 1)));
233 else
234 self.tooltip:setY(math.max(0, math.min(my, maxY - th - 1)));
235 end
236
237 self:setX(self.tooltip:getX() - 11);
238 self:setY(self.tooltip:getY());
239 self:setWidth(tw + 11);
240 self:setHeight(th);
241
242 if self.followMouse then
243 self:adjustPositionToAvoidOverlap({
244 x = mx - 24 * 2,
245 y = my - 24 * 2,
246 width = 24 * 2,
247 height = 24 * 2
248 })
249 end
250
251 self:drawRect(0, 0, self.width, self.height, self.backgroundColor.a, self.backgroundColor.r, self.backgroundColor.g, self.backgroundColor.b);
252 self:drawRectBorder(0, 0, self.width, self.height, self.borderColor.a, self.borderColor.r, self.borderColor.g, self.borderColor.b);
253
254 if self.item ~= nil and self.tooltip ~= nil then
255 FrameworkZ.Overrides.DoTooltip(self.tooltip, self.item, self);
256 else
257 self.item:DoTooltip(self.tooltip);
258 end
259end
void local y()
void local x()
void local tooltip()
void name()
void local yOffset()
void if self initialFaction and v()
void local height()
void local width
void customFields()
void local instanceID
void type()
void local itemInstance()
void local itemData()
void self createCharacterButton font()
void if not description or description()
void self self
Definition MainMenu.lua:85
void self self nil
Definition MainMenu.lua:91
void processingNotification backgroundColor a()
void local item()
void FrameworkZ Overrides()
void local word()
void local wordLength()
void for i()
void FrameworkZ()
void DoTooltip(objTooltip, item, panel)
FrameworkZ global table.