mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-22 15:46:56 +00:00
map: rework some parts of the map initialization
* make use of internal pfUI api functions * create coord text string only once * add frame to UISpecialFrames only once * use a fixed anchor in SetPoint * cache scale and alpha settings
This commit is contained in:
+46
-56
@@ -1,20 +1,19 @@
|
||||
pfUI:RegisterModule("map", 20400, function ()
|
||||
table.insert(UISpecialFrames, "WorldMapFrame")
|
||||
|
||||
function _G.ToggleWorldMap()
|
||||
if WorldMapFrame:IsShown() then
|
||||
WorldMapFrame:Hide()
|
||||
else
|
||||
WorldMapFrame:Show()
|
||||
table.insert(UISpecialFrames, "WorldMapFrame")
|
||||
end
|
||||
end
|
||||
|
||||
if not C.position[WorldMapFrame:GetName()] then
|
||||
C.position[WorldMapFrame:GetName()] = { alpha = 1.0, scale = 0.7 }
|
||||
end
|
||||
local c_position = C.position[WorldMapFrame:GetName()]
|
||||
C.position["WorldMapFrame"] = C.position["WorldMapFrame"] or { alpha = 1.0, scale = 0.7 }
|
||||
local alpha = C.position["WorldMapFrame"].alpha
|
||||
local scale = C.position["WorldMapFrame"].scale
|
||||
|
||||
local pfMapLoader = CreateFrame("Frame", nil, UIParent)
|
||||
local pfMapLoader = CreateFrame("Frame")
|
||||
pfMapLoader:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
pfMapLoader:SetScript("OnEvent", function()
|
||||
-- do not load if other map addon is loaded
|
||||
@@ -38,13 +37,13 @@ pfUI:RegisterModule("map", 20400, function ()
|
||||
|
||||
WorldMapFrame:SetScript("OnMouseWheel", function()
|
||||
if IsShiftKeyDown() then
|
||||
c_position.alpha = pfUI.api.clamp(WorldMapFrame:GetAlpha() + arg1/10, 0.1, 1.0)
|
||||
WorldMapFrame:SetAlpha(c_position.alpha)
|
||||
alpha = clamp(WorldMapFrame:GetAlpha() + arg1/10, 0.1, 1.0)
|
||||
WorldMapFrame:SetAlpha(alpha)
|
||||
end
|
||||
|
||||
if IsControlKeyDown() then
|
||||
c_position.scale = pfUI.api.clamp(WorldMapFrame:GetScale() + arg1/10, 0.1, 2.0)
|
||||
WorldMapFrame:SetScale(c_position.scale)
|
||||
scale = clamp(WorldMapFrame:GetScale() + arg1/10, 0.1, 2.0)
|
||||
WorldMapFrame:SetScale(scale)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -57,67 +56,58 @@ pfUI:RegisterModule("map", 20400, function ()
|
||||
SaveMovable(this)
|
||||
end)
|
||||
|
||||
WorldMapFrame:SetAlpha(c_position.alpha)
|
||||
WorldMapFrame:SetScale(c_position.scale)
|
||||
|
||||
WorldMapFrame:ClearAllPoints()
|
||||
WorldMapFrame:SetPoint("CENTER", 0, 0)
|
||||
WorldMapFrame:SetWidth(WorldMapButton:GetWidth() + 15)
|
||||
WorldMapFrame:SetHeight(WorldMapButton:GetHeight() + 55)
|
||||
|
||||
WorldMapFrame:SetMovable(true)
|
||||
WorldMapFrame:EnableMouse(true)
|
||||
|
||||
WorldMapFrame:SetAlpha(alpha)
|
||||
WorldMapFrame:SetScale(scale)
|
||||
|
||||
WorldMapFrame:ClearAllPoints()
|
||||
WorldMapFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
|
||||
WorldMapFrame:SetWidth(WorldMapButton:GetWidth() + 15)
|
||||
WorldMapFrame:SetHeight(WorldMapButton:GetHeight() + 55)
|
||||
LoadMovable(WorldMapFrame)
|
||||
|
||||
-- skin
|
||||
WorldMapFrameCloseButton:SetPoint("TOPRIGHT", WorldMapFrame, "TOPRIGHT", 0, 0)
|
||||
CreateBackdrop(WorldMapFrame)
|
||||
|
||||
BlackoutWorld:Hide()
|
||||
|
||||
for i,v in ipairs({WorldMapFrame:GetRegions()}) do
|
||||
if v.SetTexture then
|
||||
v:SetTexture("")
|
||||
end
|
||||
|
||||
if v.SetText then
|
||||
v:SetText("")
|
||||
end
|
||||
end
|
||||
|
||||
-- coordinates
|
||||
WorldMapButton.coords = WorldMapButton.coords or CreateFrame("Frame", "pfWorldMapButtonCoords", WorldMapButton)
|
||||
WorldMapButton.coords.text = WorldMapButton.coords:CreateFontString(nil, "OVERLAY")
|
||||
WorldMapButton.coords.text:SetPoint("BOTTOMRIGHT", WorldMapButton, "BOTTOMRIGHT", -10, 10)
|
||||
WorldMapButton.coords.text:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
|
||||
WorldMapButton.coords.text:SetTextColor(1, 1, 1)
|
||||
WorldMapButton.coords.text:SetJustifyH("RIGHT")
|
||||
|
||||
WorldMapButton.coords:SetScript("OnUpdate", function()
|
||||
local width = WorldMapButton:GetWidth()
|
||||
local height = WorldMapButton:GetHeight()
|
||||
local mx, my = WorldMapButton:GetCenter()
|
||||
local scale = WorldMapButton:GetEffectiveScale()
|
||||
local x, y = GetCursorPosition()
|
||||
|
||||
mx = (( x / scale ) - ( mx - width / 2)) / width * 100
|
||||
my = (( my + height / 2 ) - ( y / scale )) / height * 100
|
||||
|
||||
if MouseIsOver(WorldMapButton) then
|
||||
WorldMapButton.coords.text:SetText(string.format('%.1f / %.1f', mx, my))
|
||||
else
|
||||
WorldMapButton.coords.text:SetText("")
|
||||
end
|
||||
end)
|
||||
StripTextures(WorldMapFrame)
|
||||
|
||||
SkinButton(WorldMapZoomOutButton)
|
||||
|
||||
SkinCloseButton(WorldMapFrameCloseButton, WorldMapFrame, -3, -3)
|
||||
|
||||
SkinDropDown(WorldMapContinentDropDown)
|
||||
|
||||
SkinDropDown(WorldMapZoneDropDown)
|
||||
local point, anchor, anchorPoint, x, y = WorldMapZoneDropDown:GetPoint()
|
||||
WorldMapZoneDropDown:ClearAllPoints()
|
||||
WorldMapZoneDropDown:SetPoint(point, anchor, anchorPoint, x+8, y)
|
||||
|
||||
-- coordinates
|
||||
if not WorldMapButton.coords then
|
||||
WorldMapButton.coords = CreateFrame("Frame", "pfWorldMapButtonCoords", WorldMapButton)
|
||||
WorldMapButton.coords.text = WorldMapButton.coords:CreateFontString(nil, "OVERLAY")
|
||||
WorldMapButton.coords.text:SetPoint("BOTTOMRIGHT", WorldMapButton, "BOTTOMRIGHT", -10, 10)
|
||||
WorldMapButton.coords.text:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
|
||||
WorldMapButton.coords.text:SetTextColor(1, 1, 1)
|
||||
WorldMapButton.coords.text:SetJustifyH("RIGHT")
|
||||
|
||||
WorldMapButton.coords:SetScript("OnUpdate", function()
|
||||
local width = WorldMapButton:GetWidth()
|
||||
local height = WorldMapButton:GetHeight()
|
||||
local mx, my = WorldMapButton:GetCenter()
|
||||
local scale = WorldMapButton:GetEffectiveScale()
|
||||
local x, y = GetCursorPosition()
|
||||
|
||||
mx = (( x / scale ) - ( mx - width / 2)) / width * 100
|
||||
my = (( my + height / 2 ) - ( y / scale )) / height * 100
|
||||
|
||||
if MouseIsOver(WorldMapButton) then
|
||||
WorldMapButton.coords.text:SetText(string.format('%.1f / %.1f', mx, my))
|
||||
else
|
||||
WorldMapButton.coords.text:SetText("")
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user