vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- Minimap Button Handling |
2 | |||
3 | lrmm = {} |
||
4 | |||
5 | function lrmm.OnLoad() |
||
6 | local junk, englishClass = UnitClass("player") |
||
7 | if (englishClass ~= "ROGUE") then |
||
8 | return |
||
9 | end |
||
10 | this:SetFrameLevel(this:GetFrameLevel()+1) |
||
11 | this:RegisterForClicks("LeftButtonDown", "RightButtonDown") |
||
12 | this:RegisterEvent("VARIABLES_LOADED") |
||
13 | end |
||
14 | |||
15 | function lrmm.OnClick(button) |
||
16 | if (button == "LeftButton") then |
||
17 | -- Toggle menu |
||
18 | local menu = getglobal("LazyRogueMinimapMenu") |
||
19 | menu.point = "TOPRIGHT" |
||
20 | menu.relativePoint = "CENTER" |
||
21 | ToggleDropDownMenu(1, nil, menu, "LazyRogueMinimapButton", -120, 0) |
||
22 | end |
||
23 | end |
||
24 | |||
25 | function lrmm.OnEvent() |
||
26 | lrmm.UpdateMinimap() |
||
27 | if (lrConf.mmIsVisible) then |
||
28 | this:Show() |
||
29 | LazyRogueMinimapButton:Show() |
||
30 | else |
||
31 | this:Hide() |
||
32 | LazyRogueMinimapButton:Hide() |
||
33 | end |
||
34 | end |
||
35 | |||
36 | function lrmm.OnEnter() |
||
37 | GameTooltip:SetOwner(this, "ANCHOR_LEFT") |
||
38 | -- TBD: localization |
||
39 | GameTooltip:SetText("LazyRogue") |
||
40 | GameTooltip:AddLine("Left-click to choose your form.") |
||
41 | GameTooltip:AddLine("Right-click and drag to move this button.") |
||
42 | GameTooltip:Show() |
||
43 | end |
||
44 | |||
45 | function lrmm.UpdateMinimap() |
||
46 | lrmm.MoveButton() |
||
47 | if (Minimap:IsVisible()) then |
||
48 | LazyRogueMinimapButton:EnableMouse(true) |
||
49 | LazyRogueMinimapButton:Show() |
||
50 | LazyRogueMinimapFrame:Show() |
||
51 | else |
||
52 | LazyRogueMinimapButton:EnableMouse(false) |
||
53 | LazyRogueMinimapButton:Hide() |
||
54 | LazyRogueMinimapFrame:Hide() |
||
55 | end |
||
56 | end |
||
57 | |||
58 | function lrmm.Menu_Initialize() |
||
59 | if (UIDROPDOWNMENU_MENU_LEVEL == 1) then |
||
60 | |||
61 | local formNames = {} |
||
62 | for form, actions in lrConf.forms do |
||
63 | table.insert(formNames, form) |
||
64 | end |
||
65 | |||
66 | table.sort(formNames) |
||
67 | |||
68 | local info = {} |
||
69 | info.isTitle = 1 |
||
70 | info.text = "LazyRogue" |
||
71 | UIDropDownMenu_AddButton(info) |
||
72 | |||
73 | for idx, formName in formNames do |
||
74 | local actions = lrConf.forms[formName] |
||
75 | local info = {} |
||
76 | info.text = formName |
||
77 | info.value = formName |
||
78 | info.func = lrmm.Menu_ClickFunc(formName) |
||
79 | info.checked = (lrConf.defaultForm and lrConf.defaultForm == formName) |
||
80 | info.keepShownOnClick = 1 |
||
81 | info.hasArrow = 1 |
||
82 | info.tooltipTitle = formName |
||
83 | info.tooltipText = table.concat(actions, "\n") |
||
84 | UIDropDownMenu_AddButton(info) |
||
85 | end |
||
86 | |||
87 | info = {} |
||
88 | info.text = "< Create new form >" |
||
89 | info.func = lrmm.Menu_ClickSubFunction("New") |
||
90 | UIDropDownMenu_AddButton(info) |
||
91 | |||
92 | elseif (UIDROPDOWNMENU_MENU_LEVEL == 2) then |
||
93 | for idx, op in {"Edit", "Copy", "Delete"} do |
||
94 | local info = {} |
||
95 | info.text = op |
||
96 | info.func = lrmm.Menu_ClickSubFunction(op, UIDROPDOWNMENU_MENU_VALUE) |
||
97 | UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL) |
||
98 | end |
||
99 | end |
||
100 | end |
||
101 | |||
102 | function lrmm.Menu_ClickFunc(form) |
||
103 | return function() |
||
104 | lr.SlashCommand("default "..form) |
||
105 | CloseDropDownMenus() |
||
106 | LazyRogueMinimapButton:Click() |
||
107 | -- This is a total hack to deal with the code in UIDropDownMenu.lua. |
||
108 | -- This makes it so if a button was already checked, it remains checked, |
||
109 | -- which is what I want. |
||
110 | if (this.checked) then |
||
111 | this.checked = nil |
||
112 | end |
||
113 | end |
||
114 | end |
||
115 | |||
116 | function lrmm.Menu_ClickSubFunction(op, form) |
||
117 | return function() |
||
118 | if (not form) then |
||
119 | form = "" |
||
120 | end |
||
121 | if (op == "New" or op == "Edit") then |
||
122 | lr.SlashCommand("edit "..form) |
||
123 | elseif (op == "Copy") then |
||
124 | local newName |
||
125 | for i = 1, 10 do |
||
126 | newName = form.."-"..i |
||
127 | if (not lrConf.forms[newName]) then |
||
128 | lr.SlashCommand("copy "..form.." "..newName) |
||
129 | break |
||
130 | end |
||
131 | end |
||
132 | elseif (op == "Delete") then |
||
133 | lr.SlashCommand("clear "..form) |
||
134 | end |
||
135 | CloseDropDownMenus() |
||
136 | LazyRogueMinimapButton:Click() |
||
137 | end |
||
138 | end |
||
139 | |||
140 | -- Thanks to Yatlas for this code |
||
141 | function lrmm.Button_BeingDragged() |
||
142 | -- Thanks to Gello for this code |
||
143 | local xpos,ypos = GetCursorPosition() |
||
144 | local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom() |
||
145 | |||
146 | xpos = xmin-xpos/UIParent:GetScale()+70 |
||
147 | ypos = ypos/UIParent:GetScale()-ymin-70 |
||
148 | |||
149 | lrmm.Button_SetPosition(math.deg(math.atan2(ypos,xpos))) |
||
150 | end |
||
151 | |||
152 | function lrmm.Button_SetPosition(v) |
||
153 | if(v < 0) then |
||
154 | v = v + 360 |
||
155 | end |
||
156 | |||
157 | lrConf.minimapButtonPos = v |
||
158 | lrmm.MoveButton() |
||
159 | end |
||
160 | |||
161 | function lrmm.MoveButton() |
||
162 | local where = lrConf.minimapButtonPos |
||
163 | LazyRogueMinimapFrame:ClearAllPoints() |
||
164 | LazyRogueMinimapFrame:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", |
||
165 | 52 - (80 * cos(where)), |
||
166 | (80 * sin(where)) - 52) |
||
167 | end |
||
168 |