vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[ simpleMinimap ]]--
2  
3 local smmVersion,smmSubversion = "14","b"
4 local smmInside = true
5 local smmSkins = {
6 { square = false,
7 texture = "Interface\\Minimap\\UI-Minimap-Border",
8 mask = "textures\\MinimapMask",
9 },
10 { square = false,
11 texture = nil,
12 mask = "textures\\MinimapMask",
13 },
14 { square = true,
15 texture = "Interface\\AddOns\\simpleMinimap\\skins\\SquareMinimapBorder",
16 mask = "Interface\\AddOns\\simpleMinimap\\skins\\SquareMinimapMask",
17 },
18 { square = true,
19 texture = nil,
20 mask = "Interface\\AddOns\\simpleMinimap\\skins\\SquareMinimapMask",
21 },
22 { square = true,
23 texture = "Interface\\AddOns\\simpleMinimap\\skins\\dLxBorder",
24 mask = "Interface\\AddOns\\simpleMinimap\\skins\\dLxMask",
25 },
26 { square = true,
27 texture = nil,
28 mask = "Interface\\AddOns\\simpleMinimap\\skins\\dLxMask",
29 },
30 }
31 local smmConst = {
32 frames = {
33 map = MinimapCluster,
34 quest = QuestWatchFrame,
35 doll = DurabilityFrame,
36 timer = QuestTimerFrame,
37 },
38 frameDef = {
39 map = { anchor = "UIParent", point = "TOPRIGHT", rpoint = "TOPRIGHT", x = 0, y = 0 },
40 quest = { anchor = "MinimapCluster", point = "TOPRIGHT", rpoint = "BOTTOMRIGHT", x = 0, y = 10 },
41 doll = { anchor = "MinimapCluster", point = "TOPRIGHT", rpoint = "BOTTOMRIGHT", x = 40, y = 15 },
42 timer = { anchor = "MinimapCluster", point = "TOPRIGHT", rpoint = "BOTTOMRIGHT", x = 10, y = 0 },
43 },
44 buttons = {
45 bgs = MiniMapBattlefieldFrame,
46 meet = MiniMapMeetingStoneFrame,
47 mail = MiniMapMailFrame,
48 time = GameTimeFrame,
49 track = MiniMapTrackingFrame,
50 zoomin = MinimapZoomIn,
51 zoomout = MinimapZoomOut,
52 },
53 }
54  
55 --[[ initialize ]]--
56 --
57 -- debug / info messages
58 function smm_debug(text)
59 if(ChatFrame2) then ChatFrame2:AddMessage(text,0,0.8,1.0) end
60 end
61 --
62 -- default settings
63 local function smm_setDefaults()
64 smmConf = nil
65 smmConf = {
66 version = smmVersion,
67 alpha = 1,
68 scale = 1,
69 lock = false,
70 skin = 1,
71 showPings = true,
72 framePos = {
73 map = false,
74 quest = false,
75 doll = false,
76 timer = false,
77 },
78 buttonPos = {
79 bgs = 302,
80 meet = 189,
81 mail = 169,
82 time = 137,
83 track = 38,
84 zoomin = 209,
85 zoomout = 235,
86 },
87 hide = {
88 location = false,
89 time = false,
90 zoom = false,
91 },
92 }
93 end
94 --
95 -- init & feedback for the XML load
96 function smm_onLoad()
97 SLASH_SIMPMM1 = "/smm"
98 SlashCmdList["SIMPMM"] = smm_slash
99 this:RegisterEvent("PLAYER_ENTERING_WORLD")
100 this:RegisterEvent("MINIMAP_PING")
101 this:RegisterEvent("MINIMAP_UPDATE_ZOOM")
102 smm_debug(":: simpleMinimap version "..smmVersion..smmSubversion.." loaded ::")
103 end
104 --
105 -- on event
106 function smm_onEvent()
107 if(event=="MINIMAP_PING") then
108 return(smm_minimapPing(arg1))
109 elseif(event=="MINIMAP_UPDATE_ZOOM") then
110 local z = Minimap:GetZoom()
111 if (GetCVar("minimapZoom") == GetCVar("minimapInsideZoom")) then
112 if (z < 3) then
113 Minimap:SetZoom(z + 1)
114 else
115 Minimap:SetZoom(z - 1)
116 end
117 else
118 z = nil
119 end
120 if (tonumber(GetCVar("minimapInsideZoom")) == Minimap:GetZoom()) then
121 smmInside = true
122 MinimapCluster:SetAlpha(1)
123 else
124 smmInside = false
125 MinimapCluster:SetAlpha(smmConf.alpha)
126 end
127 if(z) then Minimap:SetZoom(z) end
128 elseif(event=="PLAYER_ENTERING_WORLD") then
129 if(not smmConf or smmConf.version~=smmVersion) then
130 smm_debug("smm :: configuration not present or outdated -- resetting")
131 smm_setDefaults()
132 end
133 MinimapCluster:SetMovable(true)
134 Minimap:RegisterForDrag("LeftButton")
135 Minimap:SetScript("OnDragStart",function() smm_frameDrag(true,"map") end)
136 Minimap:SetScript("OnDragStop",function() smm_frameDrag(false,"map") end)
137 MinimapZoneTextButton:RegisterForDrag("LeftButton")
138 MinimapZoneTextButton:SetScript("OnDragStart",function() smm_frameDrag(true,"map") end)
139 MinimapZoneTextButton:SetScript("OnDragStop",function() smm_frameDrag(false,"map") end)
140 for _,f in pairs(smmConst.buttons) do
141 f:SetMovable(true)
142 f:RegisterForDrag("LeftButton")
143 f:SetScript("OnDragStart",function() smm_buttonDrag(true) end)
144 f:SetScript("OnDragStop",function() smm_buttonDrag(false) end)
145 end
146 smm_update()
147 end
148 end
149  
150  
151 --[[ frame events ]]--
152 --
153 -- minimap zoom
154 function smm_minimapZoom(x)
155 if(IsShiftKeyDown()) then
156 if(not smmInside) then
157 local z=MinimapCluster:GetAlpha()
158 if(x > 0) then
159 if(z < 1) then smmConf.alpha = z + 0.05 else return end
160 else
161 if(z > 0) then smmConf.alpha = z - 0.05 else return end
162 end
163 MinimapCluster:SetAlpha(smmConf.alpha)
164 end
165 else
166 local z=Minimap:GetZoom()
167 if(x > 0) then
168 if(z < Minimap:GetZoomLevels()) then z = z + 1 end
169 else
170 if(z > 0) then z = z - 1 end
171 end
172 Minimap:SetZoom(z)
173 end
174 end
175 --
176 -- minimap ping
177 function smm_minimapPing(x)
178 if(smmConf.showPings) then
179 if(UnitName(x)==UnitName("player")) then
180 MiniMapPing:EnableMouse(false)
181 else
182 MiniMapPing:EnableMouse(true)
183 MiniMapPing:SetScript("OnEnter",function() GameTooltip:SetOwner(this,"ANCHOR_CURSOR") GameTooltip:SetText("ping by |cFFFFFFCC"..UnitName(x)) GameTooltip:Show() end)
184 MiniMapPing:SetScript("OnLeave",function() GameTooltip:Hide() end)
185 end
186 end
187 end
188 --
189 -- frame drag
190 function smm_frameDrag(x,y)
191 if(not y) then y = "map" end
192 local z = smmConst.frames[y]
193 if(x and not smmConf.lock) then
194 z.moving = true
195 z:StartMoving()
196 elseif(z.moving) then
197 z.moving = false
198 z:StopMovingOrSizing()
199 smmConf.framePos[y] = {}
200 smmConf.framePos[y].x,smmConf.framePos[y].y = z:GetCenter()
201 smm_update()
202 end
203 end
204 --
205 -- button drag
206 function smm_buttonDrag(x)
207 local function getPos()
208 local cx,cy = GetCursorPosition("UIParent")
209 local mx,my = Minimap:GetLeft(),Minimap:GetBottom()
210 local z = Minimap:GetEffectiveScale()
211 return(math.deg(math.atan2(cy/z-my-70,mx-cx/z+70)))
212 end
213 if(x and not smmConf.lock) then
214 this.moving = true
215 this:SetScript("OnUpdate",function()
216 local x,y,z = 0,0,getPos()
217 this:ClearAllPoints()
218 if(smmSkins[smmConf.skin]["square"]) then
219 x = math.max(-81,math.min(110*cos(z),81))
220 y = math.max(-81,math.min(110*sin(z),81))
221 else
222 x = 81*cos(z)
223 y = 81*sin(z)
224 end
225 this:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-x,y-54)
226 end)
227 this:StartMoving()
228 elseif(this.moving) then
229 this.moving = false
230 this:StopMovingOrSizing()
231 this:SetScript("OnUpdate",nil)
232 for n,f in pairs(smmConst.buttons) do
233 if(f==this) then smmConf.buttonPos[n] = getPos() end
234 end
235 end
236 end
237 --
238 -- minimap update
239 function smm_update()
240 MinimapBorder:SetTexture(smmSkins[smmConf.skin]["texture"])
241 Minimap:SetMaskTexture(smmSkins[smmConf.skin]["mask"])
242 for n,f in pairs(smmConst.frames) do
243 if(smmConf.framePos[n]) then
244 if(not f.smmTouched) then
245 f.smm_ClearAllPoints = f.ClearAllPoints
246 f.smm_SetAllPoints = f.SetAllPoints
247 f.smm_SetPoint = f.SetPoint
248 f.ClearAllPoints = function() end
249 f.SetAllPoints = function() end
250 f.SetPoint = function() end
251 f.smmTouched = true
252 end
253 f:smm_ClearAllPoints()
254 f:smm_SetPoint("CENTER","UIParent","BOTTOMLEFT",smmConf.framePos[n].x,smmConf.framePos[n].y)
255 else
256 if(f.smmTouched) then
257 f.ClearAllPoints = f.smm_ClearAllPoints
258 f.SetAllPoints = f.smm_SetAllPoints
259 f.SetPoint = f.smm_SetPoint
260 f.smm_ClearAllPoints = nil
261 f.smm_SetAllPoints = nil
262 f.smm_SetPoint = nil
263 f.smmTouched = nil
264 end
265 f:ClearAllPoints()
266 f:SetPoint(smmConst.frameDef[n].point,smmConst.frameDef[n].anchor,smmConst.frameDef[n].rpoint,smmConst.frameDef[n].x,smmConst.frameDef[n].y)
267 end
268 end
269 for n,f in pairs(smmConst.buttons) do
270 if(smmConf.buttonPos[n]) then
271 local x,y = 0,0
272 if(smmSkins[smmConf.skin]["square"]) then
273 x = math.max(-81,math.min(110*cos(smmConf.buttonPos[n]),81))
274 y = math.max(-81,math.min(110*sin(smmConf.buttonPos[n]),81))
275 else
276 x = 81*cos(smmConf.buttonPos[n])
277 y = 81*sin(smmConf.buttonPos[n])
278 end
279 f:ClearAllPoints()
280 f:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-x,y-54)
281 end
282 end
283 MinimapCluster:SetScale(smmConf.scale)
284 if(smmConf.hide.location) then
285 MinimapZoneTextButton:Disable()
286 MinimapToggleButton:Disable()
287 MinimapZoneTextButton:Hide()
288 MinimapToggleButton:Hide()
289 MinimapBorderTop:Hide()
290 else
291 MinimapZoneTextButton:Show()
292 MinimapToggleButton:Show()
293 MinimapBorderTop:Show()
294 MinimapZoneTextButton:Enable()
295 MinimapToggleButton:Enable()
296 end
297 if(smmConf.hide.time) then
298 GameTimeFrame:Hide()
299 else
300 GameTimeFrame:Show()
301 end
302 if(smmConf.hide.zoom) then
303 MinimapZoomIn:Disable()
304 MinimapZoomOut:Disable()
305 MinimapZoomIn:Hide()
306 MinimapZoomOut:Hide()
307 else
308 MinimapZoomIn:Show()
309 MinimapZoomOut:Show()
310 MinimapZoomIn:Enable()
311 MinimapZoomOut:Enable()
312 end
313 if(smmInside) then
314 MinimapCluster:SetAlpha(1)
315 else
316 MinimapCluster:SetAlpha(smmConf.alpha)
317 end
318 if(smmConf.lock) then
319 smm_questMover:Hide()
320 smm_dollMover:Hide()
321 smm_timerMover:Hide()
322 else
323 smm_questMover:Show()
324 smm_dollMover:Show()
325 smm_timerMover:Show()
326 end
327 end
328  
329  
330 --[[ slash command handler ]]--
331 --
332 function smm_slash(x)
333 local _,_,y,z = string.find(x,"(%w+)%s*(.*)")
334 if(y=="hide" and smmConf.hide[z]==false) then
335 smmConf.hide[z]=true
336 smm_debug("smm :: hiding minimap "..z)
337 elseif(y=="show" and smmConf.hide[z]) then
338 smmConf.hide[z]=false
339 smm_debug("smm :: showing minimap "..z)
340 elseif(y=="alpha" and tonumber(z)) then
341 z=tonumber(z)
342 if (z<0) then z=0 elseif(z>1) then z=1 end
343 smmConf.alpha = z
344 smm_debug("smm :: setting minimap alpha ("..z..")")
345 elseif(y=="scale" and tonumber(z)>0) then
346 z=tonumber(z)
347 if(smmConf.framePos.map) then
348 smmConf.framePos.map.x = (smmConf.scale / z) * smmConf.framePos.map.x
349 smmConf.framePos.map.y = (smmConf.scale / z) * smmConf.framePos.map.y
350 end
351 smmConf.scale = z
352 smm_debug("smm :: setting minimap scale ("..z..")")
353 elseif(y=="lock") then
354 if(smmConf.lock) then
355 smmConf.lock = false
356 smm_debug("smm :: unlocking minimap")
357 else
358 smmConf.lock = true
359 smm_debug("smm :: locking minimap")
360 end
361 elseif(y=="skin") then
362 smmConf.skin = smmConf.skin + 1
363 if(not smmSkins[smmConf.skin]) then smmConf.skin = 1 end
364 smm_debug("smm :: changing the minimap skin ("..smmConf.skin..")")
365 elseif(y=="ping") then
366 if(smmConf.showPings) then
367 smmConf.showPings = false
368 smm_debug("smm :: turning ping tooltips off")
369 else
370 smmConf.showPings = true
371 smm_debug("smm :: turning ping tooltips on")
372 end
373 elseif(y=="reset") then
374 smm_setDefaults()
375 smm_debug("smm :: resetting minimap")
376 else
377 for _,t in pairs(sm_HELP) do
378 DEFAULT_CHAT_FRAME:AddMessage(t,0.9,0.8,0)
379 end
380 return
381 end
382 smm_update()
383 end