2021-03-23 08:47:50 +00:00
|
|
|
local addonName, addon = ...
|
|
|
|
local childName = addon['childName']
|
|
|
|
local child = addon[childName]
|
|
|
|
local events = child['events']
|
|
|
|
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
|
|
|
|
local db
|
|
|
|
local delayOnUpdate = .5
|
|
|
|
LibStub("zzHelper"):Embed(child)
|
|
|
|
local function prepareDB()
|
|
|
|
db = addon['db']['profile'][childName]
|
|
|
|
child['db'] = db
|
|
|
|
addon['callbacks']:Fire(format("Init%s", childName))
|
|
|
|
child:ZoneEvent()
|
|
|
|
end
|
|
|
|
local function setPlayerCoords()
|
|
|
|
local playerCoords = "-, -"
|
|
|
|
local mapID = C_Map.GetBestMapForUnit("player")
|
|
|
|
if(mapID) then
|
|
|
|
local pmp = C_Map.GetPlayerMapPosition(mapID,"player")
|
|
|
|
if(pmp) then
|
|
|
|
local x,y = pmp:GetXY()
|
|
|
|
if(x and y) then
|
|
|
|
playerCoords = format("%.1f, %.1f", x*100, y*100)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
child['playerCoords'] = playerCoords
|
|
|
|
end
|
|
|
|
local colorlist = {
|
2022-12-08 20:48:12 +00:00
|
|
|
['arena'] = "ff1919",
|
|
|
|
['combat'] = "ff1919",
|
|
|
|
['hostile'] = "ff1919",
|
|
|
|
['friendly'] = "19ff19",
|
|
|
|
['sanctuary'] = "68ccef",
|
|
|
|
['contested'] = "ffb200",
|
2021-03-23 08:47:50 +00:00
|
|
|
}
|
|
|
|
local function pvpColor(txt)
|
2022-12-09 16:04:08 +00:00
|
|
|
local pvpType = GetZonePVPInfo()
|
2021-03-23 08:47:50 +00:00
|
|
|
if(colorlist[pvpType]) then
|
2022-12-09 16:04:08 +00:00
|
|
|
return child:colorize(txt, colorlist[pvpType])
|
2021-03-23 08:47:50 +00:00
|
|
|
end
|
2022-12-09 16:04:08 +00:00
|
|
|
return txt
|
2021-03-23 08:47:50 +00:00
|
|
|
end
|
|
|
|
local function OnDataUpdate()
|
|
|
|
setPlayerCoords()
|
|
|
|
if(child['zoneText'] and child['zoneText']~="") then
|
|
|
|
local coordsline = db['hideLDBCoords'] and "%s" or "%s (%s)"
|
|
|
|
child:OnText(childName, format(coordsline,(db['colorLDB'] and pvpColor(child['zoneText']) or child['zoneText']) or "", child['playerCoords'] or ""))
|
|
|
|
else
|
|
|
|
if(db['hideLDBCoords']) then
|
|
|
|
child:OnText(childName, "")
|
|
|
|
else
|
|
|
|
child:OnText(childName, child['playerCoords'] or "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if(child['moving']) then
|
|
|
|
C_Timer.After(delayOnUpdate, OnDataUpdate)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-02 10:48:54 +00:00
|
|
|
local function zzCoords_MinimapToggle()
|
2021-03-23 08:47:50 +00:00
|
|
|
if(MinimapCluster:IsVisible()) then
|
|
|
|
MinimapCluster:Hide()
|
|
|
|
else
|
|
|
|
MinimapCluster:Show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function limitLength(info, maxlength)
|
|
|
|
if(info and maxlength) then
|
|
|
|
if(maxlength > 0 and info:len() > maxlength) then
|
|
|
|
info = format("%s~",info:sub(1,maxlength))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
function child:ZoneEvent()
|
|
|
|
local zoneText = db['ShowZone'] and GetRealZoneText() or ""
|
|
|
|
if(db['ShowSubZone']) then
|
|
|
|
if(GetSubZoneText() and GetSubZoneText()~="") then
|
|
|
|
if(db['ShowZone']) then
|
|
|
|
zoneText = zoneText ~= GetSubZoneText() and format("%s, %s",zoneText,GetSubZoneText()) or zoneText
|
|
|
|
else
|
|
|
|
zoneText = GetSubZoneText()
|
|
|
|
end
|
|
|
|
elseif(not db['ShowZone']) then
|
|
|
|
zoneText = GetRealZoneText()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
child['zoneText'] = limitLength(zoneText, db['maxLength'])
|
|
|
|
if(not db['hideMapCoords']) then
|
2021-03-27 22:24:19 +00:00
|
|
|
child['mapframe']:Show()
|
2021-03-23 08:47:50 +00:00
|
|
|
else
|
2021-03-27 22:24:19 +00:00
|
|
|
child['mapframe']:Hide()
|
2021-03-23 08:47:50 +00:00
|
|
|
end
|
|
|
|
OnDataUpdate()
|
|
|
|
end
|
|
|
|
|
|
|
|
function child:MoveEvent(lib, event)
|
|
|
|
child['moving'] = event == "PLAYER_STARTED_MOVING" and true or nil
|
|
|
|
OnDataUpdate()
|
|
|
|
end
|
|
|
|
child['specs'] = {
|
|
|
|
['name'] = childName,
|
|
|
|
['sv'] = true,
|
|
|
|
['cfg'] = true,
|
|
|
|
['cfgReset'] = prepareDB,
|
|
|
|
['ldb'] = child['ldb'],
|
|
|
|
['defaults'] = {
|
|
|
|
['profile'] = {
|
|
|
|
[childName] = {
|
|
|
|
["colorLDB"] = true,
|
|
|
|
["ShowZone"] = false,
|
|
|
|
["ShowSubZone"] = true,
|
|
|
|
["ShowTooltip"] = false,
|
|
|
|
["windowX"] = 10,
|
|
|
|
["windowY"] = 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function events:PLAYER_ENTERING_WORLD(event)
|
|
|
|
child:UnregisterEvent('PLAYER_ENTERING_WORLD')
|
2021-05-02 10:48:54 +00:00
|
|
|
local m = CreateFrame("BUTTON", "zzCoords_MinimapToggleFrame")
|
|
|
|
m:SetScript("OnClick", zzCoords_MinimapToggle)
|
|
|
|
if(db['toggleMap'] and db['toggleMap'] ~= '') then
|
|
|
|
SetBinding(db['toggleMap'], "CLICK zzCoords_MinimapToggleFrame:LeftButton")
|
|
|
|
end
|
2021-03-23 08:47:50 +00:00
|
|
|
child:RegisterEvent({"ZONE_CHANGED_NEW_AREA","ZONE_CHANGED","ZONE_CHANGED_INDOORS","NEW_WMO_CHUNK"}, child.ZoneEvent)
|
|
|
|
child:RegisterEvent({"PLAYER_STARTED_MOVING", "PLAYER_STOPPED_MOVING"}, child.MoveEvent)
|
|
|
|
end
|
|
|
|
child:NewAddOn(...)
|