Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Commit 69f27e5

Browse files
committed
Extract Minimap to own file
1 parent 2c5d802 commit 69f27e5

4 files changed

Lines changed: 163 additions & 135 deletions

File tree

Core/MultiBotInit.lua

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,141 +5,7 @@
55
MultiBot.MB_PAGE_DEFAULT = string.format("%d/%d", 0, 0)
66
--local MB_TAB_TITLE_DEFAULT = UNKNOWN or ""
77

8-
-- =====================================================================
9-
-- MINIMAP BUTTON
10-
-- =====================================================================
11-
do
12-
local BTN_NAME = "MultiBot_MinimapButton"
13-
local RADIUS = 80 -- rayon d’ancrage au bord de la minimap
14-
15-
local function deg2rad(d) return d * math.pi / 180 end
16-
17-
local function UpdatePosition(self, angle)
18-
local minimap = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
19-
angle = angle or (minimap and minimap.angle) or 220
20-
if not Minimap or not Minimap:GetCenter() then return end
21-
local mx, my = Minimap:GetCenter()
22-
local sx, sy = GetScreenWidth(), GetScreenHeight()
23-
if not mx or not my or not sx or not sy then return end
24-
local r = RADIUS * (Minimap:GetEffectiveScale() / UIParent:GetEffectiveScale())
25-
local x = math.cos(deg2rad(angle)) * r
26-
local y = math.sin(deg2rad(angle)) * r
27-
self:ClearAllPoints()
28-
self:SetPoint("CENTER", Minimap, "CENTER", x, y)
29-
end
30-
31-
local function SaveAngleFromCursor(self)
32-
local mx, my = Minimap:GetCenter()
33-
local cx, cy = GetCursorPosition()
34-
local scale = UIParent:GetEffectiveScale()
35-
cx, cy = cx/scale, cy/scale
36-
local dx, dy = cx - mx, cy - my
37-
local angle = math.deg(math.atan2(dy, dx))
38-
if angle < 0 then angle = angle + 360 end
39-
if MultiBot.SetMinimapConfig then
40-
MultiBot.SetMinimapConfig("angle", angle)
41-
end
42-
UpdatePosition(self, angle)
43-
end
44-
45-
function MultiBot.Minimap_Create()
46-
if _G[BTN_NAME] then
47-
MultiBot.Minimap_Refresh()
48-
return _G[BTN_NAME]
49-
end
50-
-- Respecter l’éventuel “hide”
51-
local minimap = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
52-
if minimap and minimap.hide then return nil end
53-
54-
local b = CreateFrame("Button", BTN_NAME, Minimap)
55-
b:SetSize(31, 31)
56-
b:SetFrameStrata("MEDIUM")
57-
b:SetFrameLevel(8)
58-
b:SetMovable(true)
59-
b:SetClampedToScreen(true)
60-
b:RegisterForDrag("LeftButton")
61-
b:RegisterForClicks("AnyUp")
62-
63-
-- Anneau/bord standard de la minimap
64-
local overlay = b:CreateTexture(nil, "OVERLAY")
65-
overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
66-
overlay:SetSize(56, 56)
67-
overlay:SetPoint("TOPLEFT")
68-
69-
-- Icône (prends un pictogramme existant du pack)
70-
local icon = b:CreateTexture(nil, "ARTWORK")
71-
icon:SetTexture("Interface\\AddOns\\MultiBot\\Icons\\browse.blp")
72-
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
73-
icon:SetSize(20, 20)
74-
icon:SetPoint("CENTER", 0, 0)
75-
b.icon = icon
76-
77-
local hl = b:CreateTexture(nil, "HIGHLIGHT")
78-
hl:SetTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
79-
hl:SetBlendMode("ADD")
80-
hl:SetAllPoints(b)
81-
82-
b:SetScript("OnDragStart", function(self)
83-
self:SetScript("OnUpdate", SaveAngleFromCursor)
84-
end)
85-
b:SetScript("OnDragStop", function(self)
86-
self:SetScript("OnUpdate", nil)
87-
SaveAngleFromCursor(self)
88-
end)
89-
90-
b:SetScript("OnEnter", function(self)
91-
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
92-
GameTooltip:ClearLines()
93-
GameTooltip:AddLine(MultiBot.L("info.butttitle"), 1, 1, 1)
94-
GameTooltip:AddLine(MultiBot.L("info.buttontoggle"), 0.9, 0.9, 0.9)
95-
GameTooltip:AddLine(MultiBot.L("info.buttonoptions"), 0.9, 0.9, 0.9)
96-
GameTooltip:Show()
97-
end)
98-
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
99-
100-
b:SetScript("OnClick", function(self, btn)
101-
if btn == "RightButton" then
102-
if MultiBot.ToggleOptionsPanel then
103-
MultiBot.ToggleOptionsPanel()
104-
elseif InterfaceOptionsFrame_OpenToCategory and MultiBot.BuildOptionsPanel then
105-
MultiBot.BuildOptionsPanel()
106-
InterfaceOptionsFrame_OpenToCategory("MultiBot")
107-
InterfaceOptionsFrame_OpenToCategory("MultiBot")
108-
end
109-
else
110-
-- Clic gauche: même effet que /mb
111-
if SlashCmdList and SlashCmdList["MULTIBOT"] then
112-
SlashCmdList["MULTIBOT"]()
113-
else
114-
-- Fallback local if slash commands are unavailable.
115-
if MultiBot.ToggleMainUIVisibility then
116-
MultiBot.ToggleMainUIVisibility()
117-
end
118-
end
119-
end
120-
end)
121-
122-
UpdatePosition(b)
123-
b:Show()
124-
MultiBot.MinimapButton = b
125-
return b
126-
end
127-
128-
function MultiBot.Minimap_Refresh()
129-
local minimap = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
130-
131-
local b = _G[BTN_NAME] or MultiBot.MinimapButton
132-
if minimap and minimap.hide then
133-
if b then b:Hide() end
134-
return
135-
end
136-
if not b then b = MultiBot.Minimap_Create() end
137-
if b then
138-
UpdatePosition(b)
139-
b:Show()
140-
end
141-
end
142-
end
8+
-- Minimap config and button logic moved to UI/MultiBotMinimap.lua.
1439

14410
-- MULTIBAR --
14511
local tMultiBar = MultiBot.addFrame("MultiBar", -322, 144, 36)

MultiBot.toc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ UI\MultiBotQuestAllFrame.lua
8181
UI\MultiBotGameObjectCopyFrame.lua
8282
UI\MultiBotGameObjectResultsFrame.lua
8383
UI\MultiBotQuestsMenu.lua
84+
UI\MultiBotMinimap.lua
8485
UI\MultiBotGroupActionsUI.lua
8586
UI\MultiBotAttackUI.lua
8687
UI\MultiBotFleeUI.lua

UI/MultiBotMinimap.lua

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
if not MultiBot then return end
2+
3+
-- Minimap config is resolved through MultiBot.GetMinimapConfig().
4+
5+
do
6+
local BTN_NAME = "MultiBot_MinimapButton"
7+
local RADIUS = 80 -- rayon d’ancrage au bord de la minimap
8+
9+
local function deg2rad(degrees)
10+
return degrees * math.pi / 180
11+
end
12+
13+
local function updatePosition(button, angle)
14+
local minimapConfig = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
15+
local resolvedAngle = angle or (minimapConfig and minimapConfig.angle) or 220
16+
17+
if not Minimap or not Minimap:GetCenter() then
18+
return
19+
end
20+
21+
local minimapX, minimapY = Minimap:GetCenter()
22+
local screenWidth, screenHeight = GetScreenWidth(), GetScreenHeight()
23+
if not minimapX or not minimapY or not screenWidth or not screenHeight then
24+
return
25+
end
26+
27+
local radius = RADIUS * (Minimap:GetEffectiveScale() / UIParent:GetEffectiveScale())
28+
local xOffset = math.cos(deg2rad(resolvedAngle)) * radius
29+
local yOffset = math.sin(deg2rad(resolvedAngle)) * radius
30+
31+
button:ClearAllPoints()
32+
button:SetPoint("CENTER", Minimap, "CENTER", xOffset, yOffset)
33+
end
34+
35+
local function saveAngleFromCursor(button)
36+
local minimapX, minimapY = Minimap:GetCenter()
37+
local cursorX, cursorY = GetCursorPosition()
38+
local scale = UIParent:GetEffectiveScale()
39+
40+
cursorX, cursorY = cursorX / scale, cursorY / scale
41+
42+
local deltaX, deltaY = cursorX - minimapX, cursorY - minimapY
43+
local angle = math.deg(math.atan2(deltaY, deltaX))
44+
if angle < 0 then
45+
angle = angle + 360
46+
end
47+
48+
if MultiBot.SetMinimapConfig then
49+
MultiBot.SetMinimapConfig("angle", angle)
50+
end
51+
52+
updatePosition(button, angle)
53+
end
54+
55+
function MultiBot.Minimap_Create()
56+
if _G[BTN_NAME] then
57+
MultiBot.Minimap_Refresh()
58+
return _G[BTN_NAME]
59+
end
60+
61+
local minimapConfig = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
62+
if minimapConfig and minimapConfig.hide then
63+
return nil
64+
end
65+
66+
local button = CreateFrame("Button", BTN_NAME, Minimap)
67+
button:SetSize(31, 31)
68+
button:SetFrameStrata("MEDIUM")
69+
button:SetFrameLevel(8)
70+
button:SetMovable(true)
71+
button:SetClampedToScreen(true)
72+
button:RegisterForDrag("LeftButton")
73+
button:RegisterForClicks("AnyUp")
74+
75+
local overlay = button:CreateTexture(nil, "OVERLAY")
76+
overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
77+
overlay:SetSize(56, 56)
78+
overlay:SetPoint("TOPLEFT")
79+
80+
local icon = button:CreateTexture(nil, "ARTWORK")
81+
icon:SetTexture("Interface\\AddOns\\MultiBot\\Icons\\browse.blp")
82+
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
83+
icon:SetSize(20, 20)
84+
icon:SetPoint("CENTER", 0, 0)
85+
button.icon = icon
86+
87+
local highlight = button:CreateTexture(nil, "HIGHLIGHT")
88+
highlight:SetTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
89+
highlight:SetBlendMode("ADD")
90+
highlight:SetAllPoints(button)
91+
92+
button:SetScript("OnDragStart", function(self)
93+
self:SetScript("OnUpdate", saveAngleFromCursor)
94+
end)
95+
96+
button:SetScript("OnDragStop", function(self)
97+
self:SetScript("OnUpdate", nil)
98+
saveAngleFromCursor(self)
99+
end)
100+
101+
button:SetScript("OnEnter", function(self)
102+
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
103+
GameTooltip:ClearLines()
104+
GameTooltip:AddLine(MultiBot.L("info.butttitle"), 1, 1, 1)
105+
GameTooltip:AddLine(MultiBot.L("info.buttontoggle"), 0.9, 0.9, 0.9)
106+
GameTooltip:AddLine(MultiBot.L("info.buttonoptions"), 0.9, 0.9, 0.9)
107+
GameTooltip:Show()
108+
end)
109+
110+
button:SetScript("OnLeave", function()
111+
GameTooltip:Hide()
112+
end)
113+
114+
button:SetScript("OnClick", function(_, mouseButton)
115+
if mouseButton == "RightButton" then
116+
if MultiBot.ToggleOptionsPanel then
117+
MultiBot.ToggleOptionsPanel()
118+
elseif InterfaceOptionsFrame_OpenToCategory and MultiBot.BuildOptionsPanel then
119+
MultiBot.BuildOptionsPanel()
120+
InterfaceOptionsFrame_OpenToCategory("MultiBot")
121+
InterfaceOptionsFrame_OpenToCategory("MultiBot")
122+
end
123+
return
124+
end
125+
126+
if SlashCmdList and SlashCmdList["MULTIBOT"] then
127+
SlashCmdList["MULTIBOT"]()
128+
elseif MultiBot.ToggleMainUIVisibility then
129+
MultiBot.ToggleMainUIVisibility()
130+
end
131+
end)
132+
133+
updatePosition(button)
134+
button:Show()
135+
136+
MultiBot.MinimapButton = button
137+
return button
138+
end
139+
140+
function MultiBot.Minimap_Refresh()
141+
local minimapConfig = MultiBot.GetMinimapConfig and MultiBot.GetMinimapConfig() or nil
142+
local button = _G[BTN_NAME] or MultiBot.MinimapButton
143+
144+
if minimapConfig and minimapConfig.hide then
145+
if button then
146+
button:Hide()
147+
end
148+
return
149+
end
150+
151+
if not button then
152+
button = MultiBot.Minimap_Create()
153+
end
154+
155+
if button then
156+
updatePosition(button)
157+
button:Show()
158+
end
159+
end
160+
end

docs/ace3-multibotinit-cleanup-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ Le nettoyage pourra être considéré comme réussi quand :
272272
- [x] Extraire `Beast`
273273
- [x] Extraire `Creator`
274274
- [x] Extraire `BuildGmUI`
275+
- [x] Extraire `Minimap_Create` / `Minimap_Refresh`
275276
- [x] Extraire `ShowDeleteSVPrompt`
276277
- [x] Extraire `Main`
277278
- [x] Extraire `RTSC`

0 commit comments

Comments
 (0)