Skip to content

Commit e8c32b9

Browse files
committed
refactor to use GemSelectControl, dps sort integrated into new imbued control
1 parent 8a03334 commit e8c32b9

4 files changed

Lines changed: 78 additions & 66 deletions

File tree

src/Classes/GemSelectControl.lua

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ local m_max = math.max
1212
local m_floor = math.floor
1313

1414
local toolTipText = "Prefix tag searches with a colon and exclude tags with a dash. e.g. :fire:lightning:-cold:area"
15+
local imbuedTooltipText = "Socketed in must be set in order to add an imbued support. Only one imbued support is allowed per socketed in."
1516
local altQualMap = {
1617
["Default"] = "",
1718
["Alternate1"] = "Anomalous ",
1819
["Alternate2"] = "Divergent ",
1920
["Alternate3"] = "Phantasmal ",
2021
}
2122

22-
local GemSelectClass = newClass("GemSelectControl", "EditControl", function(self, anchor, rect, skillsTab, index, changeFunc, forceTooltip)
23+
local GemSelectClass = newClass("GemSelectControl", "EditControl", function(self, anchor, rect, skillsTab, index, changeFunc, forceTooltip, imbued)
2324
self.EditControl(anchor, rect, nil, nil, "^ %a':-")
2425
self.controls.scrollBar = new("ScrollBarControl", { "TOPRIGHT", self, "TOPRIGHT" }, {-1, 0, 18, 0}, (self.height - 4) * 4)
2526
self.controls.scrollBar.y = function()
@@ -56,6 +57,7 @@ local GemSelectClass = newClass("GemSelectControl", "EditControl", function(self
5657
lifeReservationFlat = "Life",
5758
lifeReservationPercent = "LifePercent",
5859
}
60+
self.imbuedSelect = imbued
5961
end)
6062

6163
function GemSelectClass:CalcOutputWithThisGem(calcFunc, gemData, qualityId, useFullDPS)
@@ -81,7 +83,7 @@ function GemSelectClass:CalcOutputWithThisGem(calcFunc, gemData, qualityId, useF
8183

8284
-- Create gemInstance to represent the hovered gem
8385
local gemInstance = gemList[self.index]
84-
gemInstance.level = self.skillsTab:ProcessGemLevel(gemData)
86+
gemInstance.level = self.skillsTab:ProcessGemLevel(gemData, self.imbuedSelect)
8587
gemInstance.gemData = gemData
8688
gemInstance.displayEffect = nil
8789
if gemInstance.qualityId == nil or gemInstance.qualityId == "" then
@@ -136,6 +138,11 @@ function GemSelectClass:FilterSupport(gemId, gemData)
136138
if gemData.grantedEffect.legacy and not self.skillsTab.showLegacyGems then
137139
return false
138140
end
141+
142+
if self.imbuedSelect then
143+
return (gemData.grantedEffect.support and not (gemData.tagString:match("Exceptional")))
144+
end
145+
139146
return (not gemData.grantedEffect.support
140147
or showSupportTypes == "ALL"
141148
or (showSupportTypes == "NORMAL" and not gemData.grantedEffect.plusVersionOf)
@@ -483,7 +490,7 @@ function GemSelectClass:Draw(viewPort, noTooltip)
483490
local qualityType = self:GetQualityType(self.list[self.hoverSel])
484491
local output= self:CalcOutputWithThisGem(calcFunc, gemData, qualityType, self.skillsTab.sortGemsByDPSField == "FullDPS")
485492
local gemInstance = {
486-
level = self.skillsTab:ProcessGemLevel(gemData),
493+
level = self.skillsTab:ProcessGemLevel(gemData, self.imbuedSelect),
487494
qualityId = qualityType,
488495
quality = self.skillsTab.defaultGemQuality or 0,
489496
count = 1,
@@ -531,7 +538,7 @@ function GemSelectClass:Draw(viewPort, noTooltip)
531538
end
532539
self:AddGemTooltip(gemInstance)
533540
else
534-
self.tooltip:AddLine(16, toolTipText)
541+
self.tooltip:AddLine(16, self.imbuedSelect and imbuedTooltipText or toolTipText)
535542
end
536543

537544
colorS = 0.5
@@ -546,23 +553,25 @@ function GemSelectClass:Draw(viewPort, noTooltip)
546553
self.tooltip:AddLine(16, "Only show Active gems")
547554
end
548555

549-
-- support shortcut
550-
sx = x + width - 16 - 2
551-
SetDrawColor(colorS,colorS,colorS)
552-
DrawImage(nil, sx, y+2, 16, height-4)
553-
SetDrawColor(0,0,0)
554-
DrawImage(nil, sx+1, y+2, 16-2, height-4)
555-
SetDrawColor(colorS,colorS,colorS)
556-
DrawString(sx + 8, y, "CENTER_X", height - 2, "VAR", "S")
557-
558-
-- active shortcut
559-
sx = x + width - (16*2) - (2*2)
560-
SetDrawColor(colorA,colorA,colorA)
561-
DrawImage(nil, sx, y+2, 16, height-4)
562-
SetDrawColor(0,0,0)
563-
DrawImage(nil, sx+1, y+2, 16-2, height-4)
564-
SetDrawColor(colorA,colorA,colorA)
565-
DrawString(sx + 8, y, "CENTER_X", height - 2, "VAR", "A")
556+
if not self.imbuedSelect then
557+
-- support shortcut
558+
sx = x + width - 16 - 2
559+
SetDrawColor(colorS,colorS,colorS)
560+
DrawImage(nil, sx, y+2, 16, height-4)
561+
SetDrawColor(0,0,0)
562+
DrawImage(nil, sx+1, y+2, 16-2, height-4)
563+
SetDrawColor(colorS,colorS,colorS)
564+
DrawString(sx + 8, y, "CENTER_X", height - 2, "VAR", "S")
565+
566+
-- active shortcut
567+
sx = x + width - (16*2) - (2*2)
568+
SetDrawColor(colorA,colorA,colorA)
569+
DrawImage(nil, sx, y+2, 16, height-4)
570+
SetDrawColor(0,0,0)
571+
DrawImage(nil, sx+1, y+2, 16-2, height-4)
572+
SetDrawColor(colorA,colorA,colorA)
573+
DrawString(sx + 8, y, "CENTER_X", height - 2, "VAR", "A")
574+
end
566575

567576
SetDrawLayer(nil, 10)
568577
self.tooltip:Draw(x, y, width, height, viewPort)
@@ -900,4 +909,8 @@ function GemSelectClass:OnKeyUp(key)
900909
end
901910
local newSel = self.EditControl:OnKeyUp(key)
902911
return newSel == self.EditControl and self or newSel
903-
end
912+
end
913+
914+
function GemSelectClass:UpdateIndex(index)
915+
self.index = index
916+
end

src/Classes/ImportTab.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ function ImportTabClass:ImportSocketedItems(item, socketedItems, slotName)
11511151
end
11521152
if socketedItem.builtInSupport then
11531153
socketGroup.imbuedSupport = socketedItem.builtInSupport:gsub("Supported by Level 1 ", "")
1154-
self.build.skillsTab.controls.imbuedSupport.selFunc(nil, socketedItem.builtInSupport:gsub("Supported by Level 1 ", ""), slotName)
1154+
self.build.skillsTab.controls.imbuedSupport.gemChangeFunc(data.gems[data.gemForBaseName[socketGroup.imbuedSupport:lower().." support"]], nil, nil, slotName)
11551155
end
11561156
end
11571157
end

src/Classes/SkillsTab.lua

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont
169169
self.controls.groupSlot = new("DropDownControl", { "TOPLEFT", self.anchorGroupDetail, "TOPLEFT" }, { 85, 28, 130, 20 }, groupSlotDropList, function(index, value)
170170
-- maintain imbued support to new slot
171171
if self.imbuedSupportBySlot[self.displayGroup.slot] and self.displayGroup.imbuedSupport then
172-
if value.label ~= "None" then
172+
if value.label ~= "None" and not self.imbuedSupportBySlot[value.label] then
173173
self.imbuedSupportBySlot[value.label] = copyTable(self.imbuedSupportBySlot[self.displayGroup.slot], true)
174174
else
175-
self.controls.imbuedSupport.selIndex = 1 -- reset dropdown to None if socketedIn switched to None
175+
self.controls.imbuedSupport.gemId = nil
176+
self.controls.imbuedSupport:SetText("")
176177
self.displayGroup.imbuedSupport = nil -- reset saved support to None
177178
end
178179
self.imbuedSupportBySlot[self.displayGroup.slot] = nil
@@ -211,54 +212,38 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont
211212
self.build.buildFlag = true
212213
end)
213214

214-
local imbuedSupportList = { }
215-
local gemColor = "^7"
216-
for _, gem in pairs(data.gems) do
217-
if gem.tagString:match("Support") and not gem.tagString:match("Exceptional") and not gem.name:match("Awakened") then
218-
-- wanted to add color but with sorting by name, it scrambled the gems AND we use value in the code later in CalcSetup and breaks Dropdown:SelByValue so we'd have to scrub it anyways
219-
--if gem.grantedEffect then
220-
-- if gem.grantedEffect.color == 1 then
221-
-- gemColor = colorCodes.STRENGTH
222-
-- elseif gem.grantedEffect.color == 2 then
223-
-- gemColor = colorCodes.DEXTERITY
224-
-- elseif gem.grantedEffect.color == 3 then
225-
-- gemColor = colorCodes.INTELLIGENCE
226-
-- end
227-
--end
228-
t_insert(imbuedSupportList, gem.name)
229-
end
230-
end
231-
t_sort(imbuedSupportList)
232-
t_insert(imbuedSupportList, 1, "None")
233-
234215
self.imbuedSupportBySlot = { }
235216
self.controls.imbuedSupportLabel = new("LabelControl", { "LEFT", self.controls.includeInFullDPS, "RIGHT" }, { 12, 0, 0, 16 }, colorCodes.POSITIVE.."Imbued Support:")
236-
self.controls.imbuedSupport = new("DropDownControl", { "LEFT", self.controls.imbuedSupportLabel, "RIGHT" }, { 8, 0, 250, 20 }, imbuedSupportList, function(_, value, slotName) -- slotName used on Import
237-
local gemName = value:gsub("%^7", "")
238-
if value == "None" then
239-
self.imbuedSupportBySlot[slotName or self.displayGroup.slot] = nil
217+
self.controls.imbuedSupport = new("GemSelectControl", { "LEFT", self.controls.imbuedSupportLabel, "RIGHT" }, { 8, 0, 250, 20 }, self, 1, function(gemData, _, _, slotName) -- slotName used on Import
218+
if gemData and (type(gemData) == "string" or gemData.id) then
219+
self.imbuedSupportBySlot[slotName or self.displayGroup.slot] = data.gems[gemData.id or gemData].grantedEffect
220+
if self.displayGroup then
221+
self.displayGroup.imbuedSupport = data.gems[gemData.id or gemData].name
222+
end
223+
self.build.buildFlag = true
240224
else
241-
self.imbuedSupportBySlot[slotName or self.displayGroup.slot] = data.gems[data.gemForBaseName[gemName:lower().." support"]].grantedEffect
242-
end
243-
244-
if self.displayGroup then
245-
self.displayGroup.imbuedSupport = gemName
225+
self.imbuedSupportBySlot[slotName or self.displayGroup.slot] = nil
246226
end
247-
self.build.buildFlag = true
248-
end)
227+
end, nil, true)
249228
self.controls.imbuedSupport.enabled = function()
250229
-- socketedIn must be set and the displayGroup must have an imbued, otherwise disable the imbued dropdown
251-
if self.displayGroup.slot and ((self.imbuedSupportBySlot[self.displayGroup.slot] and (self.displayGroup.imbuedSupport and self.displayGroup.imbuedSupport ~= "None") or not self.imbuedSupportBySlot[self.displayGroup.slot])) then
252-
self.controls.imbuedSupport.tooltipText = nil
230+
if self.displayGroup.slot and ((self.imbuedSupportBySlot[self.displayGroup.slot] and self.displayGroup.imbuedSupport) or not self.imbuedSupportBySlot[self.displayGroup.slot]) then
253231
return true
254232
else
255-
self.controls.imbuedSupport.tooltipText = "Imbued supports must be socketed in an item."
256233
return false
257234
end
258235
end
259236
self.controls.imbuedSupportLabel.shown = function() -- don't show imbued for skills from items
260237
return not self.displayGroup.source
261238
end
239+
self.controls.imbuedSupportClear = new("ButtonControl", { "LEFT", self.controls.imbuedSupportLabel, "RIGHT" }, { 264, 0, 80, 20}, "Clear", function()
240+
self.controls.imbuedSupport.gemId = nil
241+
self.controls.imbuedSupport:SetText("")
242+
self.displayGroup.imbuedSupport = nil
243+
self.imbuedSupportBySlot[self.displayGroup.slot] = nil
244+
245+
self.build.buildFlag = true
246+
end)
262247

263248
self.controls.groupCountLabel = new("LabelControl", { "LEFT", self.controls.includeInFullDPS, "RIGHT" }, { 16, 0, 0, 16 }, "Count:")
264249
self.controls.groupCountLabel.shown = function()
@@ -346,7 +331,7 @@ function SkillsTabClass:LoadSkill(node, skillSetId)
346331
socketGroup.gemList = { }
347332
if node.attrib.imbuedSupport and node.attrib.slot then
348333
socketGroup.imbuedSupport = node.attrib.imbuedSupport
349-
self.controls.imbuedSupport.selFunc(nil, socketGroup.imbuedSupport, socketGroup.slot)
334+
self.controls.imbuedSupport.gemChangeFunc(data.gems[data.gemForBaseName[socketGroup.imbuedSupport:lower().." support"]], nil, nil, socketGroup.slot)
350335
end
351336

352337
for _, child in ipairs(node) do
@@ -630,6 +615,12 @@ function SkillsTabClass:PasteSocketGroup(testInput)
630615
end
631616
end
632617

618+
local function updateImbuedSupportIndex(control, gemListCount)
619+
if gemListCount > 0 then
620+
control.index = gemListCount + 1
621+
end
622+
end
623+
633624
-- Create the controls for editing the gem at a given index
634625
function SkillsTabClass:CreateGemSlot(index)
635626
local slot = { }
@@ -649,6 +640,7 @@ function SkillsTabClass:CreateGemSlot(index)
649640
self.gemSlots[index2].enableGlobal2.state = gemInstance.enableGlobal2
650641
self.gemSlots[index2].count:SetText(gemInstance.count or 1)
651642
end
643+
updateImbuedSupportIndex(self.controls.imbuedSupport, #self.displayGroup.gemList)
652644
self:AddUndoState()
653645
self.build.buildFlag = true
654646
end)
@@ -952,10 +944,12 @@ function SkillsTabClass:FindSkillGem(nameSpec)
952944
return "Unrecognised gem name '" .. nameSpec .. "'"
953945
end
954946

955-
function SkillsTabClass:ProcessGemLevel(gemData)
947+
function SkillsTabClass:ProcessGemLevel(gemData, imbued)
956948
local grantedEffect = gemData.grantedEffect
957949
local naturalMaxLevel = gemData.naturalMaxLevel
958-
if self.defaultGemLevel == "awakenedMaximum" then
950+
if imbued or self.defaultGemLevel == "levelOne" then
951+
return 1
952+
elseif self.defaultGemLevel == "awakenedMaximum" then
959953
return naturalMaxLevel + 1
960954
elseif self.defaultGemLevel == "corruptedMaximum" then
961955
if grantedEffect.plusVersionOf then
@@ -965,8 +959,6 @@ function SkillsTabClass:ProcessGemLevel(gemData)
965959
end
966960
elseif self.defaultGemLevel == "normalMaximum" then
967961
return naturalMaxLevel
968-
elseif self.defaultGemLevel == "levelOne" then
969-
return 1
970962
else -- self.defaultGemLevel == "characterLevel"
971963
local maxGemLevel = naturalMaxLevel
972964
if not grantedEffect.levels[maxGemLevel] then
@@ -1056,6 +1048,7 @@ function SkillsTabClass:ProcessSocketGroup(socketGroup)
10561048
end
10571049
end
10581050
end
1051+
updateImbuedSupportIndex(self.controls.imbuedSupport, #socketGroup.gemList)
10591052
end
10601053

10611054
-- Set the skill to be displayed/edited
@@ -1070,7 +1063,13 @@ function SkillsTabClass:SetDisplayGroup(socketGroup)
10701063
self.controls.groupEnabled.state = socketGroup.enabled
10711064
self.controls.includeInFullDPS.state = socketGroup.includeInFullDPS and socketGroup.enabled
10721065
self.controls.groupCount:SetText(socketGroup.groupCount or 1)
1073-
self.controls.imbuedSupport:SelByValue(socketGroup.imbuedSupport or "None")
1066+
if socketGroup.imbuedSupport then
1067+
self.controls.imbuedSupport.gemId = data.gems[data.gemForBaseName[socketGroup.imbuedSupport:lower().." support"]]
1068+
self.controls.imbuedSupport:SetText(socketGroup.imbuedSupport)
1069+
else
1070+
self.controls.imbuedSupport.gemId = nil
1071+
self.controls.imbuedSupport:SetText("")
1072+
end
10741073

10751074
-- Update the gem slot controls
10761075
self:UpdateGemSlots()

src/Modules/CalcSetup.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ function calcs.initEnv(build, mode, override, specEnv)
14951495
end
14961496
end
14971497
-- if the slot has an imbued support, add it as an ExtraSupport
1498-
if build.skillsTab.imbuedSupportBySlot and build.skillsTab.imbuedSupportBySlot[slotName] and (group.imbuedSupport and group.imbuedSupport ~= "None") then
1498+
if build.skillsTab.imbuedSupportBySlot and build.skillsTab.imbuedSupportBySlot[slotName] and group.imbuedSupport then
14991499
addExtraSupports(nil, build.skillsTab.imbuedSupportBySlot[slotName], 1)
15001500
end
15011501

0 commit comments

Comments
 (0)