Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Radar = {}
- HolyNovaIcon = {};
- local currentMap = {}
- currentMap.height = 500
- currentMap.width = 500
- -- Colors Initialization
- local Colors = {}
- Colors.green = {}
- Colors.green.r = 0.309803922
- Colors.green.g = 0.674509804
- Colors.green.b = 0.043137255
- Colors.yellow = {}
- Colors.yellow.r = 0.674509804
- Colors.yellow.g = 0.592156863
- Colors.yellow.b = 0.043137255
- Colors.orange = {}
- Colors.orange.r = 0.674509804
- Colors.orange.g = 0.325490196
- Colors.orange.b = 0.043137255
- Colors.red = {}
- Colors.red.r = 0.674509804
- Colors.red.g = 0.145098039
- Colors.red.b = 0.043137255
- Colors.BAD = {}
- Colors.BAD.r = 0.674509804
- Colors.BAD.g = 0.145098039
- Colors.BAD.b = 0.043137255
- Colors.GOOD = {}
- Colors.GOOD.r = 0.309803922
- Colors.GOOD.g = 0.674509804
- Colors.GOOD.b = 0.043137255
- Colors.radar = {}
- Colors.radar.r = 0.0
- Colors.radar.g = 1.0
- Colors.radar.b = 0.0
- -- Values that will be set in a configuration file/menu
- local rotateRadar = false -- true = radar will rotate (like DBM one), false = radar will stay static (like the minimap)
- local RadarSize = 300 -- Square radar Height and Width
- local RadarAlpha = 1 -- Radar Circle transparency, 0 = transparent, 1 = opaque
- local HolyNovaOverhealCoheficient = 0.9 -- 1 = No overheal is allowed, 0 = Full overheal is allowed
- -- Constants
- local HolyNovaRadius = 12
- local MapErrorFactor = 1.1
- local pi = math.pi
- -- This Global will keep all dots frames, so change them to update the radar
- local dots = {}
- SLASH_HOLYSONAR1 = '/hn'
- function SlashCmdList.HOLYSONAR(msg, editbox) -- 4.
- if msg == "radar" then
- -- Toggles Radar Visibility on /hn radar
- if Radar:IsVisible() then
- Radar:Hide()
- else
- Radar:Show()
- end
- elseif msg == "icon" then
- -- Toggles Icon Visibility on /hn icon
- if HolyNovaIcon:IsVisible() then
- HolyNovaIcon:Hide()
- else
- HolyNovaIcon:Show()
- end
- else
- -- Toggles Icon Visibility on both
- if HolyNovaIcon:IsVisible() then
- HolyNovaIcon:Hide()
- Radar:Hide()
- else
- HolyNovaIcon:Show()
- Radar:Show()
- end
- end
- end
- -- Holy Nova Icon With text initialization!
- local function newHNIcon()
- -- Create the main frame
- local IconFrame = CreateFrame("Frame", "HolyNovaTargets", UIParent)
- IconFrame:SetFrameStrata("DIALOG")
- IconFrame:SetPoint("CENTER", 400, 182)
- IconFrame:SetSize(64,64)
- IconFrame:EnableMouse(false)
- -- Set Holy Nova Icon Texture
- local iconTexture = IconFrame:CreateTexture(nil,"BACKGROUND")
- iconTexture:SetAllPoints(IconFrame)
- iconTexture:SetTexture("Interface\\Icons\\Spell_Holy_HolyNova.blp")
- -- Overlay on the icon to display a "Good/Bad" effect
- local overlay = IconFrame:CreateTexture("ARTWORK")
- overlay:SetAllPoints()
- -- Start with BAD Color
- overlay:SetTexture(Colors.BAD.r, Colors.BAD.g, Colors.BAD.b)
- overlay:SetAlpha(0.2)
- overlay:Show()
- IconFrame.overlay = overlay
- -- Text to display amount if people around
- local iconText = IconFrame:CreateFontString();
- iconText:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE, MONOCHROME")
- iconText:SetText("0")
- iconText:SetTextColor(1,1,1)
- iconText:SetPoint("CENTER",IconFrame,"CENTER",0,0)
- IconFrame.text = iconText
- IconFrame:Show()
- return IconFrame
- end
- -- Radar Frame initialization code!
- local function newRadar()
- local radarFrame = CreateFrame("Frame", "LifeRadar", UIParent)
- radarFrame:SetFrameStrata("DIALOG")
- radarFrame:SetPoint("CENTER", 400, 0)
- radarFrame:SetHeight(RadarSize)
- radarFrame:SetWidth(RadarSize)
- radarFrame:EnableMouse(false) -- Click through
- radarFrame:SetToplevel(true)
- -- Transparent Black background
- local bg = radarFrame:CreateTexture(nil, "BACKGROUND")
- bg:SetAllPoints(radarFrame)
- bg:SetBlendMode("BLEND")
- bg:SetTexture(0, 0, 0, 0)
- radarFrame.background = bg
- -- I've used DBM circle, it looks pretty
- -- You can create another one and import it
- local circle = radarFrame:CreateTexture(nil, "ARTWORK")
- circle:SetSize(RadarSize, RadarSize)
- circle:SetPoint("CENTER")
- circle:SetTexture("Interface\\AddOns\\DBM-Core\\textures\\radar_circle.blp")
- circle:SetBlendMode("ADD")
- circle:SetVertexColor(Colors.radar.r, Colors.radar.g, Colors.radar.b,RadarAlpha)
- -- Store the background circle on the variable, so we can change it's color
- radarFrame.circle = circle
- -- Player arrow, not needed, but looks good for reference
- local player = radarFrame:CreateTexture(nil, "OVERLAY")
- player:SetSize(32, 32)
- player:SetTexture("Interface\\Minimap\\MinimapArrow.blp")
- player:SetBlendMode("ADD")
- player:SetPoint("CENTER")
- -- Max Raid size is 40, so 40 frames (Dots) created should be enough
- for i = 1, 40 do
- local dot = radarFrame:CreateTexture(nil, "OVERLAY")
- dot:SetSize(20, 20)
- -- X,Y coords, You can start them on 0
- -- TOPLEFT is the "Anchor", so x and y are 'how maby pixels of distance the frame is from the anchor'
- dot:SetPoint("TOPLEFT", i*5, i*-5)
- -- PartyRaidBlips is a 'big' image containing a lot of textures, that include class icons, markeers, etc.
- dot:SetTexture("Interface\\Minimap\\PartyRaidBlips")
- -- You have to remap the texture in order to "zoom" on a specific texture
- -- Here I zoomed on the Priest one (just a white dot), just to get a nice looking circle without having to make a new texture
- dot:SetTexCoord(0.5, 0.625, 0, 0.25)
- -- Here you can set the dot color using RGBA, so the icon original color is irrelevant
- -- It'll desaturate it and colorize
- -- Randomized for fun
- dot:SetVertexColor(math.random(),math.random(),math.random(),1)
- -- All dots start hidden, so you can dot:Show() them after
- dot:Hide()
- dots[i] = dot
- end
- -- Frame starts hidden
- radarFrame:Show()
- return radarFrame
- end
- -- Map methods
- local function getUnitMapPosition(unit)
- local relative_x, relative_y = GetPlayerMapPosition(unit)
- -- Only call SetMatpToCurrentZone if something went wrong
- if relative_x == 0 and relative_y == 0 then
- SetMapToCurrentZone()
- relative_x, relative_y = GetPlayerMapPosition(unit)
- end
- return currentMap.width*relative_x, currentMap.height*relative_y
- end
- -- Straight line distance from 2 coordinates
- local function getDistance(x1, y1, x2, y2)
- local xx = x2 - x1
- local yy = y2 - y1
- return sqrt(xx*xx + yy*yy)
- end
- -- Unit HP Function, all in One
- local function UnitHP(unit)
- local maxHp = UnitHealthMax(unit)
- local currentHp = UnitHealth(unit)
- if maxHp == 0 then
- maxHp = 1
- end
- if currentHp == 0 then
- currentHp = 1
- end
- local pctHp = currentHp/maxHp
- return pctHp, maxHp-currentHp
- end
- -- Deficit color
- -- Maybe add the possibility for a player to create various ranges?
- -- No need, I think. Changing colors should be enoguh, maybe only percentages fix
- local function getDeficitColor(HP)
- if(HP >= 0.95) then
- return Colors.green
- elseif(HP < 0.95 and HP >= 0.75) then
- return Colors.yellow
- elseif(HP < 0.75 and HP >= 0.50) then
- return Colors.orange
- elseif(HP < 0.50) then
- return Colors.red
- end
- end
- -- Holy Nova Math!
- local function calculateHolyNova()
- return 5000
- end
- local rotation = 0
- local function UpdatePinMap()
- -- Holy Nova Heal amount - TBD
- local HolyNovaAmount = calculateHolyNova()
- local playersInRange = 0
- local playerX, playerY = getUnitMapPosition("player")
- local numMembers = GetNumGroupMembers()
- local prefix = "raid"
- -- If the player is in a party, he's not on the Unit ID list
- if not IsInRaid() then
- prefix = "party"
- numMembers = numMembers - 1
- end
- local last = 1
- rotation = GetPlayerFacing()*57.2957795
- for i=1, numMembers do
- -- String.Format is faster than concatenating strings - Or is it?
- --local unit = prefix..i
- local unit = format("%s%d", prefix, i)
- --print(unit)
- -- Don't consider units that are Dead or disconnected
- -- Also, don't include the player here, he'll be taken in account after this for iteration
- if UnitExists(unit) and not UnitIsDeadOrGhost(unit) and not UnitIsUnit(unit,"player") then
- local pctHp, difHp = UnitHP(unit)
- local unitX, unitY = getUnitMapPosition(unit)
- -- All in Yards! (Hopefully)
- local distance = getDistance(playerX,playerY,unitX,unitY)
- -- Check if the HP Deficit is bigger than what we're looking to heal!
- if difHp > HolyNovaAmount*HolyNovaOverhealCoheficient then
- if distance <= HolyNovaRadius*MapErrorFactor then
- playersInRange = playersInRange + 1
- end
- end
- -- Get a dot
- local dot = dots[i]
- -- Get dot color based on player Health percent
- local color = getDeficitColor(pctHp)
- dot:SetVertexColor(color.r,color.g,color.b,1)
- local dist_x = unitX - playerX
- local dist_y = unitY - playerY
- -- Normalize it to pixels
- -- How much does 1 yard is in pixels for our radar size? RadarRadius/Measuring radius
- local yardInPixel = (RadarSize/(HolyNovaRadius*2))
- -- Multiply it so we get the values in pixel
- -- Also factor in the player rotation!
- local radar_x = 0
- local radar_y = 0
- if rotateRadar then
- radar_x = ((dist_x * cos(rotation)) - (-dist_y * sin(rotation))) * yardInPixel
- radar_y = ((dist_x * sin(rotation)) + (-dist_y * cos(rotation))) * yardInPixel
- else
- radar_x = dist_x * yardInPixel
- radar_y = dist_y * yardInPixel
- end
- radar_y = -radar_y
- --print(unit..": ( "..unitX..","..unitY..") ("..radar_x..","..radar_y..")")
- -- Since we considered the player is in the center, we set the anchor to the center of the radar
- -- and place our offsets for x and y as calculated
- -- Need to clear point always
- dot:ClearAllPoints();
- dot:SetPoint("CENTER", Radar, "CENTER", radar_x, radar_y)
- if distance <= HolyNovaRadius then
- dot:Show()
- else
- dot:Hide()
- end
- end
- -- If this is the last, then everything beyond should be hidden (see below)
- last = i + 1
- end
- -- Account the player on the "players in range" count
- local _,difHp = UnitHP("player")
- if difHp > HolyNovaAmount*HolyNovaOverhealCoheficient then
- playersInRange = playersInRange + 1
- end
- -- Hide all unused dots
- for i=last, 40 do
- dots[i]:Hide()
- end
- -- Set the amount on the icon
- HolyNovaIcon.text:SetText(playersInRange)
- -- Set the overlay based on the number of players in range
- local overlay = HolyNovaIcon.overlay
- if playersInRange > 4 then
- overlay:SetTexture(Colors.GOOD.r, Colors.GOOD.g, Colors.GOOD.b)
- else
- overlay:SetTexture(Colors.BAD.r, Colors.BAD.g, Colors.BAD.b)
- end
- end
- local tickTime_Data = 0.01 -- Interval to update Player Info & Radar
- local targetTime_Data = 0
- local total_Data = 0
- local function onUpdate(self,elapsed)
- total_Data = total_Data + elapsed
- if total_Data >= tickTime_Data then
- UpdatePinMap()
- total_Data = 0
- targetTime_Data = tickTime_Data
- end
- --print(currentMap.height.."x"..currentMap.width)
- end
- -- Map changed, better update values!
- local function mapChanged(event,map,floor,w,h)
- currentMap.width = w
- currentMap.height = h
- -- Just in case LibMapData doesn't have data about the map, get blizzard data
- if(currentMap.width == 0 or currentMap.height == 0) then
- local zoneIndex, a, b, c, d = GetCurrentMapZone()
- if not (a and b and c and d) then
- -- All hope is lost, no map data whatsoever
- print("No map data found!")
- currentMap.height = 0
- currentMap.width = 0
- return
- end
- currentMap.height = abs(d-b)
- currentMap.width = abs(c-a)
- end
- end
- -- Handle Events
- --function eventHandler(self, event, ...)
- --if event == "ZONE_CHANGED" or event == "ZONE_CHANGED_INDOORS" or event == "ZONE_CHANGED_NEW_AREA" then
- --updateCurrentMap()
- --end
- --end
- --updateCurrentMap()
- Radar = newRadar()
- HolyNovaIcon = newHNIcon()
- Radar:SetScript("OnUpdate", onUpdate)
- --Radar:SetScript("OnEvent", eventHandler);
- mapfiles = LibStub("LibMapData-1.0")
- mapfiles:RegisterCallback("MapChanged",mapChanged)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement