-
Notifications
You must be signed in to change notification settings - Fork 24
/
OutfitterMinimapButton.lua
272 lines (214 loc) · 7.81 KB
/
OutfitterMinimapButton.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
Outfitter._MinimapButton = {}
function Outfitter._MinimapButton:Construct()
self:RegisterForDrag("LeftButton")
self.CurrentOutfitTexture = self:CreateTexture(nil, "BACKGROUND")
self.CurrentOutfitTexture:SetWidth(22)
self.CurrentOutfitTexture:SetHeight(22)
self.CurrentOutfitTexture:SetPoint("TOPLEFT", self, "TOPLEFT", 5, -4)
SetPortraitToTexture(self.CurrentOutfitTexture, "Interface\\Icons\\INV_Chest_Cloth_21")
end
function Outfitter._MinimapButton:MouseDown()
-- Remember where the cursor was in case the user drags
local vCursorX, vCursorY = GetCursorPosition()
vCursorX = vCursorX / self:GetEffectiveScale()
vCursorY = vCursorY / self:GetEffectiveScale()
OutfitterMinimapButton.CursorStartX = vCursorX
OutfitterMinimapButton.CursorStartY = vCursorY
local vCenterX, vCenterY = OutfitterMinimapButton:GetCenter()
local vMinimapCenterX, vMinimapCenterY = Minimap:GetCenter()
OutfitterMinimapButton.CenterStartX = vCenterX - vMinimapCenterX
OutfitterMinimapButton.CenterStartY = vCenterY - vMinimapCenterY
OutfitterMinimapButton.EnableFreeDrag = IsModifierKeyDown()
end
function Outfitter._MinimapButton:DragStart()
Outfitter.SchedulerLib:ScheduleUniqueRepeatingTask(0, self.UpdateDragPosition, self)
end
function Outfitter._MinimapButton:DragEnd()
Outfitter.SchedulerLib:UnscheduleTask(self.UpdateDragPosition, self)
end
function Outfitter._MinimapButton:UpdateDragPosition()
-- Remember where the cursor was in case the user drags
local vCursorX, vCursorY = GetCursorPosition()
vCursorX = vCursorX / self:GetEffectiveScale()
vCursorY = vCursorY / self:GetEffectiveScale()
local vCursorDeltaX = vCursorX - OutfitterMinimapButton.CursorStartX
local vCursorDeltaY = vCursorY - OutfitterMinimapButton.CursorStartY
--
local vCenterX = OutfitterMinimapButton.CenterStartX + vCursorDeltaX
local vCenterY = OutfitterMinimapButton.CenterStartY + vCursorDeltaY
if OutfitterMinimapButton.EnableFreeDrag then
self:SetPosition(vCenterX, vCenterY)
else
-- Calculate the angle and set the new position
local vAngle = math.atan2(vCenterX, vCenterY)
self:SetPositionAngle(vAngle)
end
end
function Outfitter:RestrictAngle(pAngle, pRestrictStart, pRestrictEnd)
if pAngle <= pRestrictStart
or pAngle >= pRestrictEnd then
return pAngle
end
local vDistance = (pAngle - pRestrictStart) / (pRestrictEnd - pRestrictStart)
if vDistance > 0.5 then
return pRestrictEnd
else
return pRestrictStart
end
end
function Outfitter._MinimapButton:SetPosition(pX, pY)
gOutfitter_Settings.Options.MinimapButtonAngle = nil
gOutfitter_Settings.Options.MinimapButtonX = pX
gOutfitter_Settings.Options.MinimapButtonY = pY
OutfitterMinimapButton:SetPoint("CENTER", Minimap, "CENTER", pX, pY)
end
function Outfitter._MinimapButton:SetPositionAngle(pAngle)
local vAngle = pAngle
-- Restrict the angle from going over the date/time icon or the zoom in/out icons
--[[
local vRestrictedStartAngle = nil
local vRestrictedEndAngle = nil
if GameTimeFrame:IsVisible() then
if MinimapZoomIn:IsVisible()
or MinimapZoomOut:IsVisible() then
vAngle = Outfitter:RestrictAngle(vAngle, 0.4302272732931596, 2.930420793963121)
else
vAngle = Outfitter:RestrictAngle(vAngle, 0.4302272732931596, 1.720531504573905)
end
elseif MinimapZoomIn:IsVisible()
or MinimapZoomOut:IsVisible() then
vAngle = Outfitter:RestrictAngle(vAngle, 1.720531504573905, 2.930420793963121)
end
-- Restrict it from the tracking icon area
vAngle = Outfitter:RestrictAngle(vAngle, -1.290357134304173, -0.4918423429923585)
]]--
--
local vRadius = 80
local vCenterX = math.sin(vAngle) * vRadius
local vCenterY = math.cos(vAngle) * vRadius
OutfitterMinimapButton:SetPoint("CENTER", Minimap, "CENTER", vCenterX - 1, vCenterY - 1)
gOutfitter_Settings.Options.MinimapButtonAngle = vAngle
end
function Outfitter:GetMinimapDropdownItems(items)
-- Just return if not initialized yet
if not self.Initialized then
return
end
-- Add controls for the addon
items:AddCategoryTitle(self.cTitleVersion)
items:AddFunction(self.cOpenOutfitter, function ()
self:OpenUI()
end)
items:AddToggle(self.cAutoSwitch,
function ()
return self.Settings.Options.DisableAutoSwitch
end, function (menu, value)
self:SetAutoSwitch(self.Settings.Options.DisableAutoSwitch)
end)
-- Add the outfits
self:GetMinimapOutfitItems(items)
end
function Outfitter:GetMinimapOutfitItems(items)
-- Just return if not initialized yet
if not self.Initialized then
return
end
--
local inventoryCache = self:GetInventoryCache()
local categoryOrder = self:GetCategoryOrder()
for _, categoryID in ipairs(categoryOrder) do
local categoryName = self["c"..categoryID.."Outfits"]
local outfits = self:GetOutfitsByCategoryID(categoryID)
if self:HasVisibleOutfits(outfits) then
items:AddCategoryTitle(categoryName)
for vIndex, outfit in ipairs(outfits) do
if self:OutfitIsVisible(outfit) then
local wearingOutfit = Outfitter:WearingOutfit(outfit)
local missingItems, bankedItems = inventoryCache:GetMissingItems(outfit)
local itemColor = nil
if missingItems then
itemColor = RED_FONT_COLOR
elseif bankedItems then
itemColor = Outfitter.BANKED_FONT_COLOR
end
items:AddToggleWithIcon(outfit:GetName(), self.OutfitBar:GetOutfitTexture(outfit), itemColor,
function ()
return wearingOutfit
end, function (menu, value)
local categoryID = outfit.CategoryID
local doToggle = categoryID ~= "Complete"
if IsModifierKeyDown() then
self:AskSetCurrent(outfit)
elseif doToggle
and self:WearingOutfit(outfit) then
self:RemoveOutfit(outfit)
else
self:WearOutfit(outfit)
end
end)
--[[
Outfitter:AddMenuItem(
pFrame,
outfit:GetName(),
{CategoryID = categoryID, Index = vIndex},
wearingOutfit, -- Checked
nil, -- Level
itemColor, -- Color
nil, -- Disabled
{icon = Outfitter.OutfitBar:GetOutfitTexture(outfit)})
]]
end
end
end
end
end
function Outfitter._MinimapButton:HideMenu()
if not self.dropDownMenu then
return
end
self.dropDownMenu:Hide()
self.dropDownMenu = nil
end
function Outfitter._MinimapButton:ShowMenu()
assert(not self.dropDownMenu, "can't show the minimap menu while it's already up")
-- Create the items
local items = Outfitter:New(Outfitter.UIElementsLib._DropDownMenuItems, function ()
-- Close the menu after a short delay when a menu item is selected
Outfitter.SchedulerLib:ScheduleTask(0.1, function ()
self:HideMenu()
end)
end)
-- Get the items
Outfitter:GetMinimapDropdownItems(items)
-- Show the menu
self.dropDownMenu = Outfitter:New(Outfitter.UIElementsLib._DropDownMenu)
self.dropDownMenu:Show(items, "TOPRIGHT", self, "TOPRIGHT", -20, -20)
self.dropDownMenu.cleanup = function ()
self.dropDownMenu = nil
end
end
function Outfitter._MinimapButton:ToggleMenu()
-- Play a sound
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
-- Hide the menu if it's showing
if self.dropDownMenu then
self.dropDownMenu:Hide()
return
end
-- Get the items
items = Outfitter:New(Outfitter.UIElementsLib._DropDownMenuItems, function ()
Outfitter.SchedulerLib:ScheduleTask(0.1, function ()
if not self.dropDownMenu then
return
end
self.dropDownMenu:Hide()
end)
end)
Outfitter:GetMinimapDropdownItems(items)
-- Show the menu
self.dropDownMenu = Outfitter:New(Outfitter.UIElementsLib._DropDownMenu)
self.dropDownMenu:Show(items, "TOPRIGHT", self, "TOPRIGHT", -20, -20)
self.dropDownMenu.cleanup = function ()
self.dropDownMenu = nil
end
end