Skip to content
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
72 changes: 68 additions & 4 deletions Core/MultiBot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1581,11 +1581,59 @@ local function RequestBridgeUnitsRelayout()
end
end

local function ShouldRebuildBridgeUnitFrame(unitFrame, button, combat, normal)
if not unitFrame or not button then
return true
end

if unitFrame._mbBridgeBuilt ~= true then
return true
end

if unitFrame._mbBridgeClass ~= button.class then
return true
end

if unitFrame._mbBridgeCombat ~= combat then
return true
end

if unitFrame._mbBridgeNormal ~= normal then
return true
end

return false
end

local function MarkBridgeUnitFrameBuilt(unitFrame, button, combat, normal)
if not unitFrame or not button then
return
end

unitFrame._mbBridgeBuilt = true
unitFrame._mbBridgeClass = button.class
unitFrame._mbBridgeCombat = combat
unitFrame._mbBridgeNormal = normal
end

local function EnsureBridgeActiveIndex(button, name)
if not button or not button.class or button.class == "" then
return
end

MultiBot.index.classes.actives[button.class] = MultiBot.index.classes.actives[button.class] or {}
InsertBridgeNameUnique(MultiBot.index.classes.actives[button.class], name)
InsertBridgeNameUnique(MultiBot.index.actives, name)
end

function MultiBot.ApplyBridgeBotState(name, combat, normal)
if type(name) ~= "string" or name == "" then
return false
end

combat = combat or ""
normal = normal or ""

if not (MultiBot.frames and MultiBot.frames["MultiBar"]
and MultiBot.frames["MultiBar"].frames
and MultiBot.frames["MultiBar"].frames["Units"]) then
Expand All @@ -1598,6 +1646,9 @@ function MultiBot.ApplyBridgeBotState(name, combat, normal)
return false
end

local existingFrame = units.frames and units.frames[name] or nil
local shouldRebuildFrame = ShouldRebuildBridgeUnitFrame(existingFrame, button, combat, normal)

button.combat = combat or ""
button.normal = normal or ""
button.waitFor = ""
Expand All @@ -1609,6 +1660,17 @@ function MultiBot.ApplyBridgeBotState(name, combat, normal)
return true
end

if not shouldRebuildFrame then
EnsureBridgeActiveIndex(button, name)
if button.setEnable then
button.setEnable()
end

RequestBridgeUnitsRelayout()
return true
end

local wasShown = existingFrame and existingFrame.IsShown and existingFrame:IsShown()
local unitFrame = units.addFrame(name, -34, 2)
if unitFrame and unitFrame.Hide then
unitFrame:Hide()
Expand All @@ -1626,15 +1688,17 @@ function MultiBot.ApplyBridgeBotState(name, combat, normal)
MultiBot.addEvery(unitFrame, button.combat, button.normal)
end

MultiBot.index.classes.actives[button.class] = MultiBot.index.classes.actives[button.class] or {}
InsertBridgeNameUnique(MultiBot.index.classes.actives[button.class], name)
InsertBridgeNameUnique(MultiBot.index.actives, name)
MarkBridgeUnitFrameBuilt(unitFrame, button, button.combat, button.normal)

EnsureBridgeActiveIndex(button, name)

if button.setEnable then
button.setEnable()
end

if unitFrame and unitFrame.Hide then
if wasShown and unitFrame and unitFrame.Show then
unitFrame:Show()
elseif unitFrame and unitFrame.Hide then
unitFrame:Hide()
end

Expand Down
23 changes: 22 additions & 1 deletion Core/MultiBotHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2091,12 +2091,32 @@ function MultiBot.HandleMultiBotEvent(event, ...)
tButton.waitFor = "IGNORE"
tButton.normal = string.sub(arg1, 13)

local tFrame = MultiBot.frames["MultiBar"].frames["Units"].addFrame(arg2, tButton.x - tButton.size - 2, tButton.y + 2)
local tUnitsFrame = MultiBot.frames["MultiBar"].frames["Units"]
local tExistingFrame = tUnitsFrame.frames and tUnitsFrame.frames[arg2] or nil
local tCombat = tButton.combat or ""
local tNormal = tButton.normal or ""

if tExistingFrame
and tExistingFrame._mbLegacyBuilt == true
and tExistingFrame._mbLegacyClass == tButton.class
and tExistingFrame._mbLegacyCombat == tCombat
and tExistingFrame._mbLegacyNormal == tNormal then
tButton.setEnable()
SendChatMessage("ss ?", "WHISPER", nil, arg2)
return
end

local tWasShown = tExistingFrame and tExistingFrame.IsShown and tExistingFrame:IsShown()
local tFrame = tUnitsFrame.addFrame(arg2, tButton.x - tButton.size - 2, tButton.y + 2)
tFrame.class = tButton.class
tFrame.name = tButton.name

MultiBot["add" .. tButton.class](tFrame, tButton.combat, tButton.normal)
MultiBot.addEvery(tFrame, tButton.combat, tButton.normal)
tFrame._mbLegacyBuilt = true
tFrame._mbLegacyClass = tButton.class
tFrame._mbLegacyCombat = tCombat
tFrame._mbLegacyNormal = tNormal

if(MultiBot.index.classes.actives[tButton.class] == nil) then MultiBot.index.classes.actives[tButton.class] = {} end
if(MultiBot.isActive(tButton.name) == false) then
Expand All @@ -2105,6 +2125,7 @@ function MultiBot.HandleMultiBotEvent(event, ...)
end

tButton.setEnable()
if tWasShown and tFrame.Show then tFrame:Show() end
SendChatMessage("ss ?", "WHISPER", nil, arg2)
return
end
Expand Down
86 changes: 80 additions & 6 deletions UI/MultiBotUnitsRootUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,55 @@ local function getDisplayableUnits(unitsFrame, sourceTable)
return display
end

local function addRefreshTarget(targets, seen, unitsFrame, name)
if type(name) ~= "string" or name == "" or name == UnitName("player") then
return
end

if seen[name] or not (unitsFrame and unitsFrame.buttons and unitsFrame.buttons[name]) then
return
end

seen[name] = true
table.insert(targets, name)
end

local function getVisibleRefreshTargets(unitsButton, unitsFrame)
local targets = {}
local seen = {}

if not unitsButton or not unitsFrame then
return targets
end

local visibleNames = unitsButton._visibleNames
if type(visibleNames) == "table" and #visibleNames > 0 then
for index = 1, #visibleNames do
addRefreshTarget(targets, seen, unitsFrame, visibleNames[index])
end

return targets
end

local sourceTable = getUnitsSourceTable(unitsButton)
local display = getDisplayableUnits(unitsFrame, sourceTable)
local fromIndex = tonumber(unitsButton.from) or 1
local toIndex = tonumber(unitsButton.to) or math.min(#display, UNITS_PAGE_SIZE)

if fromIndex < 1 then
fromIndex = 1
end
if toIndex < fromIndex then
toIndex = math.min(#display, UNITS_PAGE_SIZE)
end

for index = fromIndex, math.min(toIndex, #display) do
addRefreshTarget(targets, seen, unitsFrame, display[index])
end

return targets
end

local function hideTrackedVisibleUnits(unitsButton, unitsFrame)
local visibleNames = unitsButton and unitsButton._visibleNames
if type(visibleNames) ~= "table" then
Expand Down Expand Up @@ -292,7 +341,7 @@ local function refreshUnitsDisplay(unitsButton, requestedRoster, requestedFilter
relayoutUnitsDisplay(unitsButton, unitsFrame)

if refreshStrategiesForActiveBots then
refreshStrategiesForActiveBots()
refreshStrategiesForActiveBots(unitsButton)
end
end

Expand Down Expand Up @@ -448,7 +497,14 @@ local function rebuildGuildAndFriendIndexes(button)
return isGuildRetry
end

refreshStrategiesForActiveBots = function()
refreshStrategiesForActiveBots = function(unitsButton)
local unitsFrame = MultiBot.frames
and MultiBot.frames["MultiBar"]
and MultiBot.frames["MultiBar"].frames
and MultiBot.frames["MultiBar"].frames[UNITS_FRAME_NAME]
local scopedToDisplayedUnits = unitsButton ~= nil
local targetNames = scopedToDisplayedUnits and getVisibleRefreshTargets(unitsButton, unitsFrame) or nil

if MultiBot.bridge and MultiBot.Comm and MultiBot.Comm.RequestStates then
if not MultiBot.bridge.connected then
return
Expand All @@ -459,16 +515,24 @@ refreshStrategiesForActiveBots = function()
return
end

local unitsFrame = MultiBot.frames
and MultiBot.frames["MultiBar"]
and MultiBot.frames["MultiBar"].frames
and MultiBot.frames["MultiBar"].frames[UNITS_FRAME_NAME]
local button = unitsFrame and unitsFrame.buttons and unitsFrame.buttons[name]
if button then
button.waitFor = "BRIDGE_STATE"
end
end

if scopedToDisplayedUnits then
if targetNames and #targetNames > 0 and MultiBot.Comm.RequestState then
for index = 1, #targetNames do
local name = targetNames[index]
markBridgeStateWait(name)
MultiBot.Comm.RequestState(name)
end
end

return
end

if IsInRaid() then
for index = 1, GetNumGroupMembers() do
markBridgeStateWait(UnitName("raid" .. index))
Expand Down Expand Up @@ -527,6 +591,16 @@ refreshStrategiesForActiveBots = function()
SendChatMessage("co ?", "WHISPER", nil, name)
end

if scopedToDisplayedUnits then
if targetNames and #targetNames > 0 then
for index = 1, #targetNames do
refreshStrategiesFor(targetNames[index])
end
end

return
end

if IsInRaid() then
for index = 1, GetNumGroupMembers() do
refreshStrategiesFor(UnitName("raid" .. index))
Expand Down
Loading