297 lines
15 KiB
Lua
297 lines
15 KiB
Lua
local _, P = ...
|
||
local letters = {"Q","W","R","T","A","G","H","Z","X","C","V","B"}
|
||
local numbers = {"1","2","3","4","5","6","7","8","9","0","-","="}
|
||
-- Plain numbers control pets; the corresponding utility slots use Ctrl.
|
||
local keys = {{"MultiBarLeft", "CTRL-", "MULTIACTIONBAR4BUTTON"},
|
||
{"MultiBarRight", "SHIFT-", "MULTIACTIONBAR3BUTTON"},
|
||
{"MultiBar5", "ALT-", "MULTIACTIONBAR5BUTTON"},
|
||
{"MultiBar6", "ALT-", "MULTIACTIONBAR6BUTTON"},
|
||
{"MultiBar7", "CTRL-SHIFT-", "MULTIACTIONBAR7BUTTON"}}
|
||
|
||
local function uiEdge(f, method)
|
||
local v=f and f[method] and f[method](f)
|
||
return v and v*f:GetEffectiveScale()/UIParent:GetEffectiveScale()
|
||
end
|
||
|
||
local function leftRows()
|
||
-- Two compact 6x2 blocks at every resolution, matching the right utility
|
||
-- bars. Wider monitors must not stretch these into distracting long strips.
|
||
return 2
|
||
end
|
||
|
||
local function leftDock(edge, rows, saved)
|
||
local x=edge(ChatFrame1,"GetLeft") or 20
|
||
-- Keep the shelf on the layout margin, not the text inset introduced by
|
||
-- native chat clamping. Those extra 12 units matter to a compact raid grid.
|
||
local chatOrigin=P.DefaultChatOrigin()
|
||
x=math.max(P.layoutPolicy.gap,x-math.max(0,chatOrigin-20))
|
||
local width=(rows or leftRows())==1 and 495 or 252
|
||
local y=P.SocialNotificationSpace(edge).top+12
|
||
-- During first installation Blizzard's player frame may still be at the
|
||
-- top-left. It must not push the new shelf off screen before Ruen is active.
|
||
if saved and not P.IsOurLayout(EditModeManagerFrame:GetActiveLayoutInfo()) then return x,y end
|
||
-- On narrow screens the wider shelf reaches under the player/pet HUD.
|
||
-- Use the whole unit footprint, including its normal combat visibility.
|
||
for _,name in ipairs({"PlayerFrame","PetFrame","PlayerCastingBarFrame","StanceBar","PetActionBar","MultiCastActionBarFrame","PossessActionBar","MainMenuBarVehicleLeaveButton","ExtraAbilityContainer"}) do
|
||
local f=_G[name]
|
||
if f and (name=="PlayerFrame" or f:IsShown()) then
|
||
local l,r,t=edge(f,"GetLeft"),edge(f,"GetRight"),edge(f,"GetTop")
|
||
if l and r and t and x<r+12 and x+width>l-12 then y=math.max(y,t+12) end
|
||
end
|
||
end
|
||
return x,y
|
||
end
|
||
|
||
function P.ConfigureLeftBarSystems(layout)
|
||
local A=Enum.EditModeActionBarSetting
|
||
local rows=leftRows()
|
||
local height=rows==1 and 36 or 74
|
||
local x,y=leftDock(uiEdge,rows,true)
|
||
local function set(s,k,v)
|
||
for _,e in ipairs(s.settings) do if e.setting==k then e.value=v;return end end
|
||
s.settings[#s.settings+1]={setting=k,value=v}
|
||
end
|
||
for _,s in ipairs(layout.systems or {}) do
|
||
if s.system==Enum.EditModeSystem.ActionBar and (s.systemIndex==7 or s.systemIndex==8) then
|
||
set(s,A.NumRows,rows);set(s,A.Orientation,Enum.ActionBarOrientation.Horizontal)
|
||
s.isInDefaultPosition=false
|
||
s.anchorInfo={point="BOTTOMLEFT",relativeTo="UIParent",relativePoint="BOTTOMLEFT",
|
||
offsetX=x,offsetY=y+(s.systemIndex-7)*(height+6)}
|
||
elseif s.system==Enum.EditModeSystem.UnitFrame and (s.systemIndex==Enum.EditModeUnitFrameSystemIndices.Party
|
||
or s.systemIndex==Enum.EditModeUnitFrameSystemIndices.Raid) then
|
||
if s.systemIndex==Enum.EditModeUnitFrameSystemIndices.Raid then
|
||
set(s,Enum.EditModeUnitFrameSetting.RowSize,8) -- compact five-column grid at 40 players
|
||
end
|
||
s.isInDefaultPosition=false
|
||
s.anchorInfo={point="BOTTOMLEFT",relativeTo="UIParent",relativePoint="BOTTOMLEFT",offsetX=x,offsetY=y+height*2+38}
|
||
end
|
||
end
|
||
end
|
||
|
||
function P.MigrateLeftBars()
|
||
if InCombatLockdown() or RuenUIDB.disabled then return end
|
||
local m=EditModeManagerFrame
|
||
if not m or m:IsShown() or m.overrideLayoutInfo or not P.IsOurLayout(m:GetActiveLayoutInfo()) then return end
|
||
local rows=leftRows()
|
||
if RuenUIDB.leftBarsVersion==3 and RuenUIDB.leftBarRows==rows then return end
|
||
local data=P.CopyEditModeLayouts()
|
||
for _,layout in ipairs(data.layouts or {}) do
|
||
if P.IsOurLayout(layout) then
|
||
RuenUIDB.beforeLeftBars=RuenUIDB.beforeLeftBars or C_EditMode.ConvertLayoutInfoToString(layout)
|
||
P.ConfigureLeftBarSystems(layout)
|
||
end
|
||
end
|
||
P.SaveEditModeLayouts(data)
|
||
RuenUIDB.leftBarsVersion=3
|
||
RuenUIDB.leftBarRows=rows
|
||
end
|
||
|
||
function P.ConfigureExtraBars(layout)
|
||
local A = Enum.EditModeActionBarSetting
|
||
local function set(s,k,v)
|
||
if not k then return end
|
||
for _,e in ipairs(s.settings) do if e.setting==k then e.value=v; return end end
|
||
s.settings[#s.settings+1]={setting=k,value=v}
|
||
end
|
||
for _,s in ipairs(layout.systems or {}) do
|
||
local U,I=Enum.EditModeUnitFrameSetting,Enum.EditModeUnitFrameSystemIndices
|
||
if s.system==Enum.EditModeSystem.UnitFrame and (s.systemIndex==I.Party or s.systemIndex==I.Raid) then
|
||
s.anchorInfo={point="BOTTOMLEFT",relativeTo="UIParent",relativePoint="BOTTOMLEFT",offsetX=20,offsetY=407}
|
||
s.isInDefaultPosition=false
|
||
if s.systemIndex==I.Raid then
|
||
set(s,U.FrameWidth,0);set(s,U.FrameHeight,0)
|
||
set(s,U.RaidGroupDisplayType,Enum.RaidGroupDisplayType.CombineGroupsVertical)
|
||
set(s,U.RowSize,8) -- 40 players: five columns, eight rows; native minimum is 72x36
|
||
end
|
||
end
|
||
if s.system==Enum.EditModeSystem.ActionBar and s.systemIndex>=4 and s.systemIndex<=8 then
|
||
set(s,A.NumIcons,12); set(s,A.NumRows,s.systemIndex==6 and 1 or 2); set(s,A.IconPadding,2); set(s,A.IconSize,4)
|
||
set(s,A.Orientation,Enum.ActionBarOrientation.Horizontal)
|
||
set(s,A.VisibleSetting,Enum.ActionBarVisibleSetting.Always)
|
||
set(s,A.AlwaysShowButtons,s.systemIndex==6 and 1 or (C_CVar.GetCVar("lockActionBars")=="1" and 0 or 1))
|
||
local left=s.systemIndex>=7
|
||
s.anchorInfo={point=left and "BOTTOMLEFT" or "BOTTOMRIGHT",relativeTo="UIParent",
|
||
relativePoint=left and "BOTTOMLEFT" or "BOTTOMRIGHT", offsetX=left and 20 or -22,
|
||
offsetY=left and (215+(s.systemIndex-7)*82) or (s.systemIndex==5 and 100 or s.systemIndex==4 and 182 or 264)}
|
||
if s.systemIndex==6 then
|
||
s.anchorInfo={point="BOTTOM",relativeTo="UIParent",relativePoint="BOTTOM",offsetX=0,offsetY=174}
|
||
end
|
||
s.isInDefaultPosition=false
|
||
end
|
||
end
|
||
P.ConfigureLeftBarSystems(layout)
|
||
end
|
||
|
||
function P.MigrateExtraBars(force)
|
||
if InCombatLockdown() or RuenUIDB.disabled then return end
|
||
local m=EditModeManagerFrame
|
||
if not m or m:IsShown() or m.overrideLayoutInfo or not P.IsOurLayout(m:GetActiveLayoutInfo()) then return end
|
||
-- Layout geometry is shared, but enableMultiActionBars is per character.
|
||
-- Older alts need their own visibility upgrade even after another character
|
||
-- migrated the account layout. Do this once, preserving later manual choices.
|
||
if RuenUICharacter.extraBarsVisibilityVersion~=1 then
|
||
local bars={GetActionBarToggles()}
|
||
RuenUICharacter.oldBars=RuenUICharacter.oldBars or CopyTable(bars)
|
||
for i=2,8 do
|
||
if not bars[i-1] then Settings.SetValue("PROXY_SHOW_ACTIONBAR_"..i,true) end
|
||
end
|
||
MultiActionBar_Update()
|
||
RuenUICharacter.extraBarsVisibilityVersion=1
|
||
end
|
||
if not force and RuenUIDB.extraBarsVersion==1 then P.MigrateLeftBars();return end
|
||
local data=P.CopyEditModeLayouts()
|
||
for _,layout in ipairs(data.layouts or {}) do
|
||
if P.IsOurLayout(layout) then
|
||
if force and RuenUIDB.extraBarsVersion==1 then
|
||
for _,s in ipairs(layout.systems or {}) do
|
||
if s.system==Enum.EditModeSystem.ActionBar and s.systemIndex>=4 and s.systemIndex<=8 and s.systemIndex~=6 then
|
||
for _,e in ipairs(s.settings or {}) do
|
||
if e.setting==Enum.EditModeActionBarSetting.AlwaysShowButtons then
|
||
e.value=C_CVar.GetCVar("lockActionBars")=="1" and 0 or 1
|
||
end
|
||
end
|
||
end
|
||
end
|
||
else P.ConfigureExtraBars(layout) end
|
||
P.ConfigureLeftBarSystems(layout)
|
||
end
|
||
end
|
||
P.SaveEditModeLayouts(data)
|
||
MultiActionBar_Update()
|
||
RuenUIDB.extraBarsVersion=1
|
||
RuenUIDB.leftBarsVersion=3
|
||
RuenUIDB.leftBarRows=leftRows()
|
||
end
|
||
|
||
function P.ApplyPetBindings(force)
|
||
if InCombatLockdown() or RuenUIDB.disabled then return end
|
||
P.ApplyCharacterBindings(force)
|
||
-- The caller may also have changed ordinary row bindings. Profile bindings
|
||
-- themselves are session-local and never written into the account set.
|
||
if force then SaveBindings(GetCurrentBindingSet()) end
|
||
end
|
||
|
||
function P.ApplyExtraBindings(force)
|
||
if InCombatLockdown() then return end
|
||
local scope=GetCurrentBindingSet()==1 and RuenUIDB or RuenUICharacter
|
||
if scope.extraBindingsVersion==1 and not force then
|
||
P.ApplyPetBindings(false)
|
||
return
|
||
end
|
||
local changes=RuenUICharacter.bindingChanges or {}
|
||
RuenUICharacter.bindingChanges=changes
|
||
local function bind(key,action)
|
||
local old=GetBindingAction(key)
|
||
if old==(action or "") then return end
|
||
if not SetBinding(key,action) then error("Could not bind "..key) end
|
||
changes[key]=changes[key] or {before=old}
|
||
changes[key].applied=action or ""
|
||
end
|
||
for _,row in ipairs(keys) do
|
||
for i,key in ipairs(row[1]=="MultiBar5" and letters or numbers) do
|
||
local action=row[3]..i
|
||
for _,old in ipairs({GetBindingKey(action)}) do bind(old,nil) end
|
||
bind(row[2]..key,action)
|
||
end
|
||
end
|
||
for _,key in ipairs({"E","D","S","F"}) do
|
||
local action=({E="MOVEFORWARD",D="MOVEBACKWARD",S="STRAFELEFT",F="STRAFERIGHT"})[key]
|
||
bind("ALT-"..key,action)
|
||
end
|
||
bind("ALT-BUTTON3","JUMP");bind("ALT-BUTTON4","TARGETPREVIOUSENEMY");bind("ALT-BUTTON5","TARGETNEARESTENEMY")
|
||
bind("CTRL-SHIFT-F11","TOGGLEUI")
|
||
-- Alt is an action-row modifier now, so it must not also force friendly
|
||
-- spells onto the player. Automatic self-cast and F1 targeting stay available.
|
||
if GetModifiedClick and SetModifiedClick then
|
||
RuenUIDB.oldSelfCast=RuenUIDB.oldSelfCast or GetModifiedClick("SELFCAST")
|
||
if Settings.GetSetting("SELFCAST") then Settings.SetValue("SELFCAST","NONE")
|
||
else SetModifiedClick("SELFCAST","NONE") end
|
||
RuenUIDB.original.autoSelfCast=RuenUIDB.original.autoSelfCast or C_CVar.GetCVar("autoSelfCast")
|
||
C_CVar.SetCVar("autoSelfCast","1")
|
||
end
|
||
P.ApplyPetBindings(true) -- also saves the bindings changed above
|
||
scope.extraBindingsVersion=1
|
||
end
|
||
|
||
function P.UtilityTop()
|
||
return MultiBarRight or MultiBarLeft
|
||
end
|
||
|
||
function P.PositionExtraBars(place,edge)
|
||
place(MultiBarRight,"BOTTOMRIGHT",MultiBarLeft,"TOPRIGHT",0,P.layoutPolicy.utilityRowGap)
|
||
place(MultiBar5,"BOTTOMLEFT",MultiBarBottomRight,"TOPLEFT",0,P.layoutPolicy.actionRowGap)
|
||
end
|
||
|
||
function P.PositionLeftBars(place,edge)
|
||
local x,y=leftDock(edge)
|
||
place(MultiBar6,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",x,y)
|
||
place(MultiBar7,"BOTTOMLEFT",MultiBar6,"TOPLEFT",0,P.layoutPolicy.utilityRowGap)
|
||
end
|
||
|
||
local groupScales={}
|
||
function P.PositionGroupFrames(place,edge)
|
||
local top=math.max((edge(MultiBar7,"GetTop") or 375)+32,(edge(PlayerFrame,"GetTop") or 397)+16)
|
||
local obstacles={}
|
||
for _,r in ipairs(P.OverlayObstacles(false)) do
|
||
if r.name~="PartyFrame" and r.name~="CompactRaidFrameContainer" and not (r.name or ""):match("^DamageMeter")
|
||
and not (r.name or ""):find("CooldownViewer") then obstacles[#obstacles+1]=r end
|
||
end
|
||
-- Preserve a useful central sightline/tooltip lane on short viewports.
|
||
-- Large battleground objective widgets already reserve that area and may
|
||
-- require the group to use the clear space underneath them instead.
|
||
local instanceType
|
||
if IsInInstance then local inside;inside,instanceType=IsInInstance() end
|
||
if instanceType~="pvp" and not (FocusFrame and FocusFrame:IsShown()) then
|
||
obstacles[#obstacles+1]={left=UIParent:GetWidth()/2-150,right=UIParent:GetWidth()/2+150,
|
||
bottom=(edge(PlayerFrame,"GetTop") or 400)+12,top=UIParent:GetHeight(),name="Central sightline"}
|
||
end
|
||
P.groupLayoutIssues={}
|
||
for _,name in ipairs({"PartyFrame","CompactRaidFrameContainer"}) do
|
||
local f=_G[name]
|
||
if f then
|
||
groupScales[f]=groupScales[f] or f:GetScale()
|
||
local base=groupScales[f]
|
||
local ratio=f:GetEffectiveScale()/UIParent:GetEffectiveScale()*base/f:GetScale()
|
||
local width,height=f:GetWidth()*ratio,f:GetHeight()*ratio
|
||
local x=edge(ChatFrame1,"GetLeft") or 20
|
||
if width>8 and height>8 and f:IsShown() then
|
||
local target,fit,score
|
||
-- Try relocating the complete group before reducing readability.
|
||
-- Never turn a 40-player raid into half-size health bars.
|
||
for step=0,5 do
|
||
local candidateFit=1-step*.05
|
||
local candidate=P.FindOverlayPosition(width*candidateFit,height*candidateFit,x,top,obstacles,UIParent:GetWidth(),UIParent:GetHeight())
|
||
if candidate then
|
||
-- A modest size reduction at the left edge is preferable
|
||
-- to a large raid grid spreading across the play field.
|
||
local cost=(candidate.left-x)^2+(candidate.bottom-top)^2+((1-candidateFit)*600)^2
|
||
if not score or cost<score then target,fit,score=candidate,candidateFit,cost end
|
||
if cost==0 then break end
|
||
end
|
||
end
|
||
if target then
|
||
local scale=base*fit
|
||
if math.abs(f:GetScale()-scale)>.001 then (f.SetScaleBase or f.SetScale)(f,scale) end
|
||
place(f,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",target.left,target.bottom)
|
||
target.name=name;obstacles[#obstacles+1]=target
|
||
else
|
||
P.groupLayoutIssues[#P.groupLayoutIssues+1]=name.." cannot fit at readable scale"
|
||
end
|
||
else
|
||
-- Empty native containers grow on GROUP_ROSTER_UPDATE/OnShow.
|
||
if math.abs(f:GetScale()-base)>.001 then (f.SetScaleBase or f.SetScale)(f,base) end
|
||
place(f,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",x,top)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
function P.BarHelp()
|
||
local pet = P.NumberProfile() == "pet"
|
||
local mapping = pet and P.Localized("1–= pets; Ctrl+1–= right utility.", "1–= — питомец; Ctrl+1–= — нижняя правая панель.")
|
||
or P.Localized("1–= right utility; Ctrl+1–= pets.", "1–= — нижняя правая панель; Ctrl+1–= — питомец.")
|
||
return P.Localized("96 slots: 48 ESDF combat (base/Shift/Ctrl/Alt). ", "96 ячеек: 48 боевых ESDF (без модификатора/Shift/Ctrl/Alt). ")
|
||
..mapping..P.Localized(" Upper right: Shift+numbers; left: Alt+numbers, Ctrl+Shift+numbers. /ruen keys auto|pet|utility; /ruen lock | unlock. Custom bindings are preserved.",
|
||
" Верхняя правая: Shift+цифры; слева: Alt+цифры, Ctrl+Shift+цифры. /ruen keys auto|pet|utility; /ruen lock | unlock. Свои назначения сохраняются.")
|
||
end
|