Posted by Primer 2010-03-07 14:02:41.105742   (Wrap: None 80 100 120)
001 | if select(6, GetAddOnInfo("PitBull4_" .. (debugstack():match("[o%.][d%.][u%.]les\\(.-)\\") or ""))) ~= "MISSING" then return end local PitBull4 = _G.PitBull4 if not PitBull4 then error("PitBull4_DirectionIcon requires PitBull4") end local L = PitBull4.L local PitBull4_DirectionIcon = PitBull4:NewModule("DirectionIcon", "AceEvent-3.0") PitBull4_DirectionIcon:SetModuleType("custom") PitBull4_DirectionIcon:SetName(L["Direction icon"]) PitBull4_DirectionIcon:SetDescription(L["Shows an arrow indicating the direction of the player."]) PitBull4_DirectionIcon:SetDefaults({ attach_to = "root", location = "edge_top", position = 1, while_target = false, while_hover = true, }) local t, f = nil, nil local current_frame = nil local playerGuid = nil local s2 = sqrt(2) local cos, sin, rad, atan2 = math.cos, math.sin, math.rad, math.atan2 local function CalculateCorner(r) return 0.5 + cos(r) / s2, 0.5 + sin(r) / s2; end local function RotateTexture(texture, angle) local LRx, LRy = CalculateCorner(angle + 0.785398163); local LLx, LLy = CalculateCorner(angle + 2.35619449); local ULx, ULy = CalculateCorner(angle + 3.92699082); local URx, URy = CalculateCorner(angle - 0.785398163); texture:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy); end local function GetBearing (unit) DEFAULT_CHAT_FRAME:AddMessage ("Get Bearing for unit: " .. unit) tx, ty = GetPlayerMapPosition(unit) if tx == 0 and ty == 0 then return 999 end px, py = GetPlayerMapPosition("player") return -GetPlayerFacing() - atan2 (tx - px, py - ty) end local function ShouldShow (frame) local bearing = GetBearing (frame.unit) if bearing == 999 then return false end return true end local function OnUpdate (self, elapsed) self.elapsed = self.elapsed + elapsed DEFAULT_CHAT_FRAME:AddMessage ("OnUpdate GUID: " .. current_frame.guid .. ", unit: " .. current_frame.unit) if (self.elapsed > 0) then self.elapsed = 0 local bearing = GetBearing (current_frame.unit) DEFAULT_CHAT_FRAME:AddMessage ("OnUpdate frame. GUID: " .. current_frame.guid .. ", unit: " .. current_frame.unit .. ", Bearing: " .. bearing) if bearing == 999 then f:Hide() return end f:SetPoint("CENTER", current_frame) f:SetScale(current_frame:GetScale()) RotateTexture (t, bearing) end end f = CreateFrame("Button", nil, UIParent) f:SetPoint("CENTER") f:SetAllPoints() f:EnableMouse(false) f:SetFrameLevel(10) f:SetWidth(32) f:SetHeight(32) f:SetAlpha(1) f:Hide() f.elapsed = 0 f:SetScript("OnUpdate", OnUpdate) t = f:CreateTexture("OVERLAY") f.texture = t t:SetTexture([[Interface\Minimap\MinimapArrow]]) t:SetBlendMode("BLEND") t:SetAlpha(1) t:SetAllPoints(f) function PitBull4_DirectionIcon:OnEnable() playerGuid = UnitGUID("player") self:AddFrameScriptHook("OnEnter") self:AddFrameScriptHook("OnLeave") end function PitBull4_DirectionIcon:OnDisable() self:RemoveFrameScriptHook("OnEnter") self:RemoveFrameScriptHook("OnLeave") end function PitBull4_DirectionIcon:OnEnter(frame) DEFAULT_CHAT_FRAME:AddMessage ("Entered frame") if frame.guid == playerGuid then return end if ShouldShow (frame) then DEFAULT_CHAT_FRAME:AddMessage (" should show!") current_frame = frame f:Show() end end function PitBull4_DirectionIcon:OnLeave(frame) DEFAULT_CHAT_FRAME:AddMessage ("Left frame") current_frame = nil f:Hide() end PitBull4_DirectionIcon:SetLayoutOptionsFunction(function(self) return 'while_target', { type = 'toggle', name = L["When targeted"], desc = L["Show the direction to this player when it's also your target."], get = function(info) return PitBull4.Options.GetLayoutDB(self).while_target end, set = function(info, value) PitBull4.Options.GetLayoutDB(self).while_target = value end, }, 'while_hover', { type = 'toggle', name = L["On mouse hover"], desc = L["Show the direction to this player while the mouse hovers over it."], get = function(info) return PitBull4.Options.GetLayoutDB(self).while_hover end, set = function(info, value) PitBull4.Options.GetLayoutDB(self).while_hover = value end, } end) |
Submit a correction or amendment below. (click here to make a fresh posting)
Hint: if you have the wonderful curl program installed, use the following commands (script) to send a file directly:
curl -F "code=</path/to/file" -F poster=YourNick http://ceregatti.org/p/
or the output from a program directly:
program | curl -F "code=<-" -F poster=YourNick http://ceregatti.org/p/