Skip to content

Commit 6626c24

Browse files
committed
Refactoring
1 parent fd45e29 commit 6626c24

1 file changed

Lines changed: 68 additions & 51 deletions

File tree

addons/tooltiphelper/tooltiphelper.lua

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -372,55 +372,40 @@ function RECIPE_ADD_CUSTOM_TOOLTIP_TEXT(invItem)
372372
return table.concat(partOfRecipe, "{nl}")
373373
end
374374

375-
function CUSTOM_TOOLTIP_PROPS(tooltipFrame, mainFrameName, invItem, strArg, useSubFrame)
376-
local gBox = GET_CHILD(tooltipFrame, mainFrameName,'ui::CGroupBox');
377-
378-
local yPos = gBox:GetY() + gBox:GetHeight();
379-
380-
local ctrl = gBox:CreateOrGetControl("richtext", 'text', 0, yPos, 410, 30);
381-
tolua.cast(ctrl, "ui::CRichText");
382-
383-
local stringBuffer = {};
384-
local text = ""
385-
386-
--Show trade count when trade window is visible
387-
if ui.GetFrame('exchange'):IsVisible() == 1 then
388-
local tradeCount = GetMyAccountObj().TradeCount
389-
if tradeCount > 0 then
390-
text = toIMCTemplate(tradeCount .. " trades left!", completeColor)
391-
table.insert(stringBuffer, text)
392-
end
393-
end
394-
395-
--Reroll price
396-
if invItem.GroupName == "Drug" then
375+
function RENDER_CUBE_REROLL_PRICE(tooltipFrame, buffer, invItem)
376+
if invItem.GroupName == "Drug" then
397377
local item = GetObjectByGuid(tooltipFrame:GetTooltipIESID());
398378
local itemName = dictionary.ReplaceDicIDInCompStr(item.Name)
399379
if string.find(itemName, 'Cube') then
400380
local rerollPrice = TryGet(item, "NumberArg1")
401381
if rerollPrice > 0 then
402-
table.insert(stringBuffer, addIcon("", invItem.Icon) .. toIMCTemplate("Reroll Price: " .. GetCommaedText(rerollPrice), labelColor))
382+
table.insert(buffer, addIcon("", invItem.Icon) .. toIMCTemplate("Reroll Price: " .. GetCommaedText(rerollPrice), labelColor))
403383
end
404384
end
405385
end
406-
407-
--Journal stats
408-
local journalStatsLabel = ""
409-
if TooltipHelper.config.showJournalStats then
386+
end
387+
388+
function RENDER_JOURNAL_STATS(tooltipFrame, invItem)
389+
local journalStatsLabel = ""
390+
if TooltipHelper.config.showJournalStats then
410391
journalStatsLabel = JOURNAL_STATS_CUSTOM_TOOLTIP_TEXT(invItem)
411392
end
412-
413-
--iLvl
414-
local itemLevelLabel = ""
415-
if TooltipHelper.config.showItemLevel then
393+
return journalStatsLabel
394+
end
395+
396+
function RENDER_ITEM_LEVEL(tooltipFrame, invItem)
397+
local itemLevelLabel = ""
398+
if TooltipHelper.config.showItemLevel then
416399
if invItem.ItemType == "Equip" then
417400
itemLevelLabel = toIMCTemplate("Item Level: ", labelColor) .. toIMCTemplate(invItem.ItemLv .. " ", acutil.getItemRarityColor(invItem))
418401
end
419402
end
420-
421-
--Repair Recommendation
422-
local repairRecommendationLabel = ""
423-
if TooltipHelper.config.showRepairRecommendation then
403+
return itemLevelLabel
404+
end
405+
406+
function RENDER_REPAIR_RECOMMENDATION(tooltipFrame, invItem)
407+
local repairRecommendationLabel = ""
408+
if TooltipHelper.config.showRepairRecommendation then
424409
if invItem.ItemType == "Equip" and invItem.Reinforce_Type == 'Moru' then
425410
local _, squireResult = ITEMBUFF_NEEDITEM_Squire_Repair(nil, invItem)
426411
if invItem.Dur < invItem.MaxDur then
@@ -432,39 +417,71 @@ function CUSTOM_TOOLTIP_PROPS(tooltipFrame, mainFrameName, invItem, strArg, useS
432417
end
433418
end
434419
end
435-
436-
local headText = journalStatsLabel .. itemLevelLabel .. repairRecommendationLabel
437-
table.insert(stringBuffer,headText);
438-
439-
--Collection
440-
if TooltipHelper.config.showCollectionCustomTooltips then
420+
return repairRecommendationLabel
421+
end
422+
423+
function RENDER_COLLECTION_DETAILS(tooltipFrame, buffer, invItem, text)
424+
if TooltipHelper.config.showCollectionCustomTooltips then
441425
text = COLLECTION_ADD_CUSTOM_TOOLTIP_TEXT(invItem);
442426
if text ~= "" then
443-
table.insert(stringBuffer,text)
427+
table.insert(buffer,text)
444428
end
445429
end
446-
447-
--Recipe
448-
if TooltipHelper.config.showRecipeCustomTooltips then
430+
end
431+
432+
function RENDER_RECIPE_DETAILS(tooltipFrame, buffer, invItem, text)
433+
if TooltipHelper.config.showRecipeCustomTooltips then
449434
text = RECIPE_ADD_CUSTOM_TOOLTIP_TEXT(invItem)
450435
if text ~= "" then
451-
table.insert(stringBuffer,text)
436+
table.insert(buffer,text)
452437
end
453438
end
439+
end
440+
441+
function CUSTOM_TOOLTIP_PROPS(tooltipFrame, mainFrameName, invItem, strArg, useSubFrame)
442+
local gBox = GET_CHILD(tooltipFrame, mainFrameName,'ui::CGroupBox');
443+
444+
local yPos = gBox:GetY() + gBox:GetHeight();
445+
446+
local ctrl = gBox:CreateOrGetControl("richtext", 'text', 0, yPos, 410, 30);
447+
tolua.cast(ctrl, "ui::CRichText");
448+
449+
local buffer = {};
450+
local text = ""
454451

455-
if #stringBuffer == 1 and invItem.ItemType == "Equip" then
452+
--Reroll Price
453+
RENDER_CUBE_REROLL_PRICE(tooltipFrame, buffer, invItem);
454+
455+
--Journal stats
456+
local journalStatsLabel = RENDER_JOURNAL_STATS(tooltipFrame, invItem);
457+
458+
--iLvl
459+
local itemLevelLabel = RENDER_ITEM_LEVEL(tooltipFrame, invItem);
460+
461+
--Repair Recommendation
462+
local repairRecommendationLabel = RENDER_REPAIR_RECOMMENDATION(tooltipFrame, invItem);
463+
464+
local headText = journalStatsLabel .. itemLevelLabel .. repairRecommendationLabel;
465+
table.insert(buffer,headText);
466+
467+
--Collection
468+
RENDER_COLLECTION_DETAILS(tooltipFrame, buffer, invItem, text)
469+
470+
--Recipe
471+
RENDER_RECIPE_DETAILS(tooltipFrame, buffer, invItem, text)
472+
473+
if #buffer == 1 and invItem.ItemType == "Equip" then
456474
text = journalStatsLabel .. itemLevelLabel .. repairRecommendationLabel
457475
else
458-
text = table.concat(stringBuffer,"{nl}")
476+
text = table.concat(buffer,"{nl}")
459477
end
460-
461-
478+
462479
ctrl:SetText(text);
463480
ctrl:SetMargin(20,gBox:GetHeight() - 10,0,0)
464481

465482
gBox:Resize(gBox:GetWidth(),gBox:GetHeight() + ctrl:GetHeight())
466483

467-
stringBuffer = {}
484+
buffer = {}
468485
text = ""
469486
return ctrl:GetHeight() + ctrl:GetY();
470487
end

0 commit comments

Comments
 (0)