-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUltMenu.lua
155 lines (144 loc) · 3.81 KB
/
UltMenu.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
local collectgarbage = collectgarbage
local GetUnitName = GetUnitName
local BOTTOMRIGHT = BOTTOMRIGHT
local LAMCreateControl = LAMCreateControl
setfenv(1, POC)
local Settings, Swimlanes, Ult, watch
_ = ''
local LAM = LibAddonMenu2
UltMenu = {}
UltMenu.__index = UltMenu
local okimg = 'POC/icons/ok.dds'
local ok1img = 'POC/icons/ok1.dds'
local nook1img = 'POC/icons/nook1.dds'
local lams = {}
local container
local dropdown
local curapid
local showicons
local switch
local myults
local ultix = GetUnitName("player")
-- Select ultimate group menu
--
local function set_ult(iconstr)
dropdown:SetHidden(true)
if iconstr == switch then
Ult.SetSavedId()
elseif iconstr == okimg then
Ult.SetSavedId(curapid, 1)
elseif iconstr == ok1img then
Ult.SetSavedId(curapid, 2)
elseif iconstr == nook1img then
Ult.SetSavedId('MIA', 2)
else
Swimlanes.SetLaneUlt(curapid, Ult.UltApidFromIcon(iconstr))
end
Swimlanes.Sched()
collectgarbage("collect")
end
local function get_ult()
local ult = Ult.ByPing(curapid)
return ult.Icon
end
local iconPicker
function UltMenu.IsActive()
local res = iconPicker and not iconPicker:IsHidden()
watch("UltMenu.IsActive", 'returning', res, "ishidden", iconPicker and iconPicker:IsHidden())
return res
end
-- Show an appropriate "menu" for selecting ultimates
-- 1 = On non-selected: Show primary/secondary
-- 2 = On primary: Show secondary with "switch note"
-- 3 = On secondary: Show secondary with red circle
function UltMenu.Show(parent, apid)
watch("UltMenu.Show", apid)
curapid = apid
if parent.data == nil then
parent.data = {}
end
local n
if apid ~= myults[1] and apid ~= myults[2] then
n = 1
elseif apid == myults[1] then
n = 2
elseif myults[2] == 'MIA' then
n = 3
else
n = 4
end
if lams[n] == nil then
local icons = {}
local tooltips = {}
local switch
if n == 1 then
icons[#icons + 1] = okimg
tooltips[#tooltips + 1] = 'Make this your primary ultimate'
icons[#icons + 1] = ok1img
tooltips[#tooltips + 1] = 'Make this your secondary ultimate'
elseif n == 2 then
icons[#icons + 1] = ok1img
tooltips[#tooltips + 1] = 'Switch primary and secondary ultimates'
switch = ok1img
elseif n == 3 then
-- nothing extra
elseif n == 4 then
icons[#icons + 1] = okimg
tooltips[#tooltips + 1] = 'Switch primary and secondary ultimates'
icons[#icons + 1] = nook1img
tooltips[#tooltips + 1] = 'Deselect as your secondary ultimate'
switch = okimg
end
for i, x in ipairs(Ult.Icons()) do
icons[#icons + 1] = x
end
for i, x in ipairs(Ult.Descriptions()) do
tooltips[#tooltips + 1] = x
end
local lam = LAMCreateControl.iconpicker(parent, {
type = "iconpicker",
tooltip = "Select ultimate",
choices = icons,
choicesTooltips = tooltips,
getFunc = get_ult,
setFunc = set_ult,
maxColumns = 7,
visibleRows = 5,
iconSize = 48,
})
lams[n] = {
[1] = lam,
[2] = lam.container,
[3] = lam.dropdown,
[4] = lam.dropdown:GetHandler("OnMouseUp"),
[5] = switch
}
if not iconPicker then
iconPicker = LAM.util.GetIconPickerMenu().control
local onhide = iconPicker:GetHandler("OnEffectivelyHidden");
iconPicker:SetHandler("OnEffectivelyHidden", function (self)
Swimlanes.Redo()
if onhide then
self:onhide()
end
end)
end
end
local lam
lam, container, dropdown, showicons, switch = unpack(lams[n])
dropdown:SetParent(parent)
dropdown:ClearAnchors()
container:SetAnchor(BOTTOMRIGHT, parent, BOTTOMRIGHT, 4, -4)
dropdown:SetHidden(true)
lam:UpdateChoices()
showicons()
end
-- Initialize UltMenu
--
function UltMenu.Initialize(_saved)
myults = _saved.MyUltId[ultix]
Settings = POC.Settings
Swimlanes = POC.Swimlanes
Ult = POC.Ult
watch = POC.watch
end