initial commit
This commit is contained in:
4
Modules/Maps/Load_Maps.xml
Normal file
4
Modules/Maps/Load_Maps.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns='http://www.blizzard.com/wow/ui/'>
|
||||
<Script file='Minimap.lua'/>
|
||||
<Script file='Worldmap.lua'/>
|
||||
</Ui>
|
||||
428
Modules/Maps/Minimap.lua
Normal file
428
Modules/Maps/Minimap.lua
Normal file
@@ -0,0 +1,428 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local M = E:GetModule('Minimap')
|
||||
local LSM = E.Libs.LSM
|
||||
|
||||
local _G = _G
|
||||
local pairs = pairs
|
||||
local tinsert = tinsert
|
||||
local utf8sub = string.utf8sub
|
||||
|
||||
local CloseAllWindows = CloseAllWindows
|
||||
local CloseMenus = CloseMenus
|
||||
local PlaySound = PlaySound
|
||||
local CreateFrame = CreateFrame
|
||||
local GarrisonLandingPageMinimapButton_OnClick = GarrisonLandingPageMinimapButton_OnClick
|
||||
local GetMinimapZoneText = GetMinimapZoneText
|
||||
local GetZonePVPInfo = GetZonePVPInfo
|
||||
local InCombatLockdown = InCombatLockdown
|
||||
local IsAddOnLoaded = IsAddOnLoaded
|
||||
local IsShiftKeyDown = IsShiftKeyDown
|
||||
local MainMenuMicroButton_SetNormal = MainMenuMicroButton_SetNormal
|
||||
local ShowUIPanel, HideUIPanel = ShowUIPanel, HideUIPanel
|
||||
local ToggleAchievementFrame = ToggleAchievementFrame
|
||||
local ToggleCharacter = ToggleCharacter
|
||||
local ToggleCollectionsJournal = ToggleCollectionsJournal
|
||||
local ToggleFrame = ToggleFrame
|
||||
local ToggleFriendsFrame = ToggleFriendsFrame
|
||||
local ToggleGuildFrame = ToggleGuildFrame
|
||||
local ToggleHelpFrame = ToggleHelpFrame
|
||||
local ToggleLFDParentFrame = ToggleLFDParentFrame
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
local Minimap = _G.Minimap
|
||||
|
||||
-- GLOBALS: GetMinimapShape
|
||||
|
||||
--Create the new minimap tracking dropdown frame and initialize it
|
||||
local ElvUIMiniMapTrackingDropDown = CreateFrame('Frame', 'ElvUIMiniMapTrackingDropDown', _G.UIParent, 'UIDropDownMenuTemplate')
|
||||
ElvUIMiniMapTrackingDropDown:SetID(1)
|
||||
ElvUIMiniMapTrackingDropDown:SetClampedToScreen(true)
|
||||
ElvUIMiniMapTrackingDropDown:Hide()
|
||||
_G.UIDropDownMenu_Initialize(ElvUIMiniMapTrackingDropDown, _G.MiniMapTrackingDropDown_Initialize, 'MENU')
|
||||
ElvUIMiniMapTrackingDropDown.noResize = true
|
||||
|
||||
--Create the minimap micro menu
|
||||
local menuFrame = CreateFrame('Frame', 'MinimapRightClickMenu', E.UIParent, 'BackdropTemplate')
|
||||
local menuList = {
|
||||
{text = _G.CHARACTER_BUTTON,
|
||||
func = function() ToggleCharacter('PaperDollFrame') end},
|
||||
{text = _G.SPELLBOOK_ABILITIES_BUTTON,
|
||||
func = function()
|
||||
if not _G.SpellBookFrame:IsShown() then
|
||||
ShowUIPanel(_G.SpellBookFrame)
|
||||
else
|
||||
HideUIPanel(_G.SpellBookFrame)
|
||||
end
|
||||
end},
|
||||
{text = _G.TALENTS_BUTTON,
|
||||
func = function()
|
||||
if not _G.PlayerTalentFrame then
|
||||
_G.TalentFrame_LoadUI()
|
||||
end
|
||||
|
||||
local PlayerTalentFrame = _G.PlayerTalentFrame
|
||||
if not PlayerTalentFrame:IsShown() then
|
||||
ShowUIPanel(PlayerTalentFrame)
|
||||
else
|
||||
HideUIPanel(PlayerTalentFrame)
|
||||
end
|
||||
end},
|
||||
{text = _G.COLLECTIONS,
|
||||
func = ToggleCollectionsJournal},
|
||||
{text = _G.CHAT_CHANNELS,
|
||||
func = _G.ToggleChannelFrame},
|
||||
{text = _G.TIMEMANAGER_TITLE,
|
||||
func = function() ToggleFrame(_G.TimeManagerFrame) end},
|
||||
{text = _G.ACHIEVEMENT_BUTTON,
|
||||
func = ToggleAchievementFrame},
|
||||
{text = _G.SOCIAL_BUTTON,
|
||||
func = ToggleFriendsFrame},
|
||||
{text = L["Calendar"],
|
||||
func = function() _G.GameTimeFrame:Click() end},
|
||||
{text = _G.GARRISON_TYPE_8_0_LANDING_PAGE_TITLE,
|
||||
func = function() GarrisonLandingPageMinimapButton_OnClick(_G.GarrisonLandingPageMinimapButton) end},
|
||||
{text = _G.ACHIEVEMENTS_GUILD_TAB,
|
||||
func = ToggleGuildFrame},
|
||||
{text = _G.LFG_TITLE,
|
||||
func = ToggleLFDParentFrame},
|
||||
{text = _G.ENCOUNTER_JOURNAL,
|
||||
func = function()
|
||||
if not IsAddOnLoaded('Blizzard_EncounterJournal') then
|
||||
_G.EncounterJournal_LoadUI()
|
||||
end
|
||||
|
||||
ToggleFrame(_G.EncounterJournal)
|
||||
end},
|
||||
{text = _G.MAINMENU_BUTTON,
|
||||
func = function()
|
||||
if not _G.GameMenuFrame:IsShown() then
|
||||
if _G.VideoOptionsFrame:IsShown() then
|
||||
_G.VideoOptionsFrameCancel:Click()
|
||||
elseif _G.AudioOptionsFrame:IsShown() then
|
||||
_G.AudioOptionsFrameCancel:Click()
|
||||
elseif _G.InterfaceOptionsFrame:IsShown() then
|
||||
_G.InterfaceOptionsFrameCancel:Click()
|
||||
end
|
||||
|
||||
CloseMenus()
|
||||
CloseAllWindows()
|
||||
PlaySound(850) --IG_MAINMENU_OPEN
|
||||
ShowUIPanel(_G.GameMenuFrame)
|
||||
else
|
||||
PlaySound(854) --IG_MAINMENU_QUIT
|
||||
HideUIPanel(_G.GameMenuFrame)
|
||||
MainMenuMicroButton_SetNormal()
|
||||
end
|
||||
end}
|
||||
}
|
||||
|
||||
tinsert(menuList, {text = _G.BLIZZARD_STORE, func = function() _G.StoreMicroButton:Click() end})
|
||||
tinsert(menuList, {text = _G.HELP_BUTTON, func = ToggleHelpFrame})
|
||||
|
||||
function M:HandleGarrisonButton()
|
||||
local button = _G.GarrisonLandingPageMinimapButton
|
||||
if button then
|
||||
local db = E.db.general.minimap.icons.classHall
|
||||
local scale, pos = db.scale or 1, db.position or 'BOTTOMLEFT'
|
||||
button:ClearAllPoints()
|
||||
button:Point(pos, Minimap, pos, db.xOffset or 0, db.yOffset or 0)
|
||||
button:SetScale(scale)
|
||||
|
||||
local box = _G.GarrisonLandingPageTutorialBox
|
||||
if box then
|
||||
box:SetScale(1/scale)
|
||||
box:SetClampedToScreen(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M:GetLocTextColor()
|
||||
local pvpType = GetZonePVPInfo()
|
||||
if pvpType == 'arena' then
|
||||
return 0.84, 0.03, 0.03
|
||||
elseif pvpType == 'friendly' then
|
||||
return 0.05, 0.85, 0.03
|
||||
elseif pvpType == 'contested' then
|
||||
return 0.9, 0.85, 0.05
|
||||
elseif pvpType == 'hostile' then
|
||||
return 0.84, 0.03, 0.03
|
||||
elseif pvpType == 'sanctuary' then
|
||||
return 0.035, 0.58, 0.84
|
||||
elseif pvpType == 'combat' then
|
||||
return 0.84, 0.03, 0.03
|
||||
else
|
||||
return 0.9, 0.85, 0.05
|
||||
end
|
||||
end
|
||||
|
||||
function M:SetupHybridMinimap()
|
||||
local MapCanvas = _G.HybridMinimap.MapCanvas
|
||||
MapCanvas:SetMaskTexture(E.Media.Textures.White8x8)
|
||||
MapCanvas:SetScript('OnMouseWheel', M.Minimap_OnMouseWheel)
|
||||
MapCanvas:SetScript('OnMouseDown', M.MapCanvas_OnMouseDown)
|
||||
MapCanvas:SetScript('OnMouseUp', E.noop)
|
||||
end
|
||||
|
||||
function M:ADDON_LOADED(_, addon)
|
||||
if addon == 'Blizzard_TimeManager' then
|
||||
_G.TimeManagerClockButton:Kill()
|
||||
elseif addon == 'Blizzard_FeedbackUI' then
|
||||
_G.FeedbackUIButton:Kill()
|
||||
elseif addon == 'Blizzard_HybridMinimap' then
|
||||
M:SetupHybridMinimap()
|
||||
end
|
||||
end
|
||||
|
||||
function M:Minimap_OnMouseDown(btn)
|
||||
_G.HideDropDownMenu(1, nil, ElvUIMiniMapTrackingDropDown)
|
||||
menuFrame:Hide()
|
||||
|
||||
local position = self:GetPoint()
|
||||
if btn == 'MiddleButton' or (btn == 'RightButton' and IsShiftKeyDown()) then
|
||||
if InCombatLockdown() then _G.UIErrorsFrame:AddMessage(E.InfoColor.._G.ERR_NOT_IN_COMBAT) return end
|
||||
if position:match('LEFT') then
|
||||
E:DropDown(menuList, menuFrame)
|
||||
else
|
||||
E:DropDown(menuList, menuFrame, -160, 0)
|
||||
end
|
||||
elseif btn == 'RightButton' then
|
||||
_G.ToggleDropDownMenu(1, nil, ElvUIMiniMapTrackingDropDown, 'cursor')
|
||||
else
|
||||
_G.Minimap_OnClick(self)
|
||||
end
|
||||
end
|
||||
|
||||
function M:MapCanvas_OnMouseDown(btn)
|
||||
_G.HideDropDownMenu(1, nil, ElvUIMiniMapTrackingDropDown)
|
||||
menuFrame:Hide()
|
||||
|
||||
local position = self:GetPoint()
|
||||
if btn == 'MiddleButton' or (btn == 'RightButton' and IsShiftKeyDown()) then
|
||||
if InCombatLockdown() then _G.UIErrorsFrame:AddMessage(E.InfoColor.._G.ERR_NOT_IN_COMBAT) return end
|
||||
if position:match('LEFT') then
|
||||
E:DropDown(menuList, menuFrame)
|
||||
else
|
||||
E:DropDown(menuList, menuFrame, -160, 0)
|
||||
end
|
||||
elseif btn == 'RightButton' then
|
||||
_G.ToggleDropDownMenu(1, nil, ElvUIMiniMapTrackingDropDown, 'cursor')
|
||||
end
|
||||
end
|
||||
|
||||
function M:Minimap_OnMouseWheel(d)
|
||||
if d > 0 then
|
||||
_G.MinimapZoomIn:Click()
|
||||
elseif d < 0 then
|
||||
_G.MinimapZoomOut:Click()
|
||||
end
|
||||
end
|
||||
|
||||
function M:Update_ZoneText()
|
||||
if E.db.general.minimap.locationText == 'HIDE' then return end
|
||||
Minimap.location:FontTemplate(LSM:Fetch('font', E.db.general.minimap.locationFont), E.db.general.minimap.locationFontSize, E.db.general.minimap.locationFontOutline)
|
||||
Minimap.location:SetText(utf8sub(GetMinimapZoneText(), 1, 46))
|
||||
Minimap.location:SetTextColor(M:GetLocTextColor())
|
||||
end
|
||||
|
||||
do
|
||||
local isResetting
|
||||
local function ResetZoom()
|
||||
Minimap:SetZoom(0)
|
||||
_G.MinimapZoomIn:Enable(); --Reset enabled state of buttons
|
||||
_G.MinimapZoomOut:Disable()
|
||||
isResetting = false
|
||||
end
|
||||
|
||||
local function SetupZoomReset()
|
||||
if E.db.general.minimap.resetZoom.enable and not isResetting then
|
||||
isResetting = true
|
||||
E:Delay(E.db.general.minimap.resetZoom.time, ResetZoom)
|
||||
end
|
||||
end
|
||||
hooksecurefunc(Minimap, 'SetZoom', SetupZoomReset)
|
||||
end
|
||||
|
||||
function M:UpdateSettings()
|
||||
if not E.private.general.minimap.enable then return end
|
||||
|
||||
E.MinimapSize = E.db.general.minimap.size or Minimap:GetWidth()
|
||||
|
||||
local MinimapPanel, MMHolder = _G.MinimapPanel, _G.MMHolder
|
||||
MinimapPanel:SetShown(E.db.datatexts.panels.MinimapPanel.enable)
|
||||
|
||||
local borderWidth, borderHeight = E.PixelMode and 2 or 6, E.PixelMode and 2 or 8
|
||||
local panelSize, joinPanel = (MinimapPanel:IsShown() and MinimapPanel:GetHeight()) or (E.PixelMode and 1 or -1), 1
|
||||
local height, width = E.MinimapSize + (panelSize - joinPanel), E.MinimapSize
|
||||
MMHolder:Size(width + borderWidth, height + borderHeight)
|
||||
_G.MinimapMover:Size(width + borderWidth, height + borderHeight)
|
||||
|
||||
local mmOffset = E.PixelMode and 1 or 3
|
||||
Minimap:ClearAllPoints()
|
||||
Minimap:Point('TOPRIGHT', MMHolder, 'TOPRIGHT', -mmOffset, -mmOffset)
|
||||
Minimap:Size(E.MinimapSize, E.MinimapSize)
|
||||
|
||||
Minimap.location:Width(E.MinimapSize)
|
||||
if E.db.general.minimap.locationText ~= 'SHOW' then
|
||||
Minimap.location:Hide()
|
||||
else
|
||||
Minimap.location:Show()
|
||||
end
|
||||
|
||||
M.HandleGarrisonButton()
|
||||
|
||||
local GameTimeFrame = _G.GameTimeFrame
|
||||
if GameTimeFrame then
|
||||
if E.private.general.minimap.hideCalendar then
|
||||
GameTimeFrame:Hide()
|
||||
else
|
||||
local pos = E.db.general.minimap.icons.calendar.position or 'TOPRIGHT'
|
||||
local scale = E.db.general.minimap.icons.calendar.scale or 1
|
||||
GameTimeFrame:ClearAllPoints()
|
||||
GameTimeFrame:Point(pos, Minimap, pos, E.db.general.minimap.icons.calendar.xOffset or 0, E.db.general.minimap.icons.calendar.yOffset or 0)
|
||||
GameTimeFrame:SetScale(scale)
|
||||
GameTimeFrame:Show()
|
||||
end
|
||||
end
|
||||
|
||||
local MiniMapMailFrame = _G.MiniMapMailFrame
|
||||
if MiniMapMailFrame then
|
||||
local pos = E.db.general.minimap.icons.mail.position or 'TOPRIGHT'
|
||||
local scale = E.db.general.minimap.icons.mail.scale or 1
|
||||
MiniMapMailFrame:ClearAllPoints()
|
||||
MiniMapMailFrame:Point(pos, Minimap, pos, E.db.general.minimap.icons.mail.xOffset or 3, E.db.general.minimap.icons.mail.yOffset or 4)
|
||||
MiniMapMailFrame:SetScale(scale)
|
||||
end
|
||||
|
||||
local QueueStatusMinimapButton = _G.QueueStatusMinimapButton
|
||||
if QueueStatusMinimapButton then
|
||||
local pos = E.db.general.minimap.icons.lfgEye.position or 'BOTTOMRIGHT'
|
||||
local scale = E.db.general.minimap.icons.lfgEye.scale or 1
|
||||
QueueStatusMinimapButton:ClearAllPoints()
|
||||
QueueStatusMinimapButton:Point(pos, Minimap, pos, E.db.general.minimap.icons.lfgEye.xOffset or 3, E.db.general.minimap.icons.lfgEye.yOffset or 0)
|
||||
QueueStatusMinimapButton:SetScale(scale)
|
||||
_G.QueueStatusFrame:SetScale(scale)
|
||||
end
|
||||
|
||||
local MiniMapInstanceDifficulty = _G.MiniMapInstanceDifficulty
|
||||
local GuildInstanceDifficulty = _G.GuildInstanceDifficulty
|
||||
if MiniMapInstanceDifficulty and GuildInstanceDifficulty then
|
||||
local pos = E.db.general.minimap.icons.difficulty.position or 'TOPLEFT'
|
||||
local scale = E.db.general.minimap.icons.difficulty.scale or 1
|
||||
local x = E.db.general.minimap.icons.difficulty.xOffset or 0
|
||||
local y = E.db.general.minimap.icons.difficulty.yOffset or 0
|
||||
MiniMapInstanceDifficulty:ClearAllPoints()
|
||||
MiniMapInstanceDifficulty:Point(pos, Minimap, pos, x, y)
|
||||
MiniMapInstanceDifficulty:SetScale(scale)
|
||||
GuildInstanceDifficulty:ClearAllPoints()
|
||||
GuildInstanceDifficulty:Point(pos, Minimap, pos, x, y)
|
||||
GuildInstanceDifficulty:SetScale(scale)
|
||||
end
|
||||
|
||||
local MiniMapChallengeMode = _G.MiniMapChallengeMode
|
||||
if MiniMapChallengeMode then
|
||||
local pos = E.db.general.minimap.icons.challengeMode.position or 'TOPLEFT'
|
||||
local scale = E.db.general.minimap.icons.challengeMode.scale or 1
|
||||
MiniMapChallengeMode:ClearAllPoints()
|
||||
MiniMapChallengeMode:Point(pos, Minimap, pos, E.db.general.minimap.icons.challengeMode.xOffset or 8, E.db.general.minimap.icons.challengeMode.yOffset or -8)
|
||||
MiniMapChallengeMode:SetScale(scale)
|
||||
end
|
||||
end
|
||||
|
||||
local function MinimapPostDrag()
|
||||
_G.MinimapBackdrop:ClearAllPoints()
|
||||
_G.MinimapBackdrop:SetAllPoints(_G.Minimap)
|
||||
end
|
||||
|
||||
function M:GetMinimapShape()
|
||||
return 'SQUARE'
|
||||
end
|
||||
|
||||
function M:SetGetMinimapShape()
|
||||
GetMinimapShape = M.GetMinimapShape --This is just to support for other mods
|
||||
Minimap:Size(E.db.general.minimap.size, E.db.general.minimap.size)
|
||||
end
|
||||
|
||||
function M:Initialize()
|
||||
if not E.private.general.minimap.enable then return end
|
||||
self.Initialized = true
|
||||
|
||||
menuFrame:SetTemplate('Transparent')
|
||||
|
||||
local mmholder = CreateFrame('Frame', 'MMHolder', Minimap)
|
||||
mmholder:Point('TOPRIGHT', E.UIParent, 'TOPRIGHT', -3, -3)
|
||||
mmholder:Size(Minimap:GetSize())
|
||||
|
||||
Minimap:SetQuestBlobRingAlpha(0)
|
||||
Minimap:SetArchBlobRingAlpha(0)
|
||||
Minimap:CreateBackdrop()
|
||||
Minimap:SetFrameLevel(Minimap:GetFrameLevel() + 2)
|
||||
Minimap:ClearAllPoints()
|
||||
Minimap:Point('TOPRIGHT', mmholder, 'TOPRIGHT', -E.Border, -E.Border)
|
||||
Minimap:HookScript('OnEnter', function(mm) if E.db.general.minimap.locationText == 'MOUSEOVER' then mm.location:Show() end end)
|
||||
Minimap:HookScript('OnLeave', function(mm) if E.db.general.minimap.locationText == 'MOUSEOVER' then mm.location:Hide() end end)
|
||||
|
||||
Minimap.location = Minimap:CreateFontString(nil, 'OVERLAY')
|
||||
Minimap.location:FontTemplate(nil, nil, 'OUTLINE')
|
||||
Minimap.location:Point('TOP', Minimap, 'TOP', 0, -2)
|
||||
Minimap.location:SetJustifyH('CENTER')
|
||||
Minimap.location:SetJustifyV('MIDDLE')
|
||||
if E.db.general.minimap.locationText ~= 'SHOW' then
|
||||
Minimap.location:Hide()
|
||||
end
|
||||
|
||||
local frames = {
|
||||
_G.MinimapBorder,
|
||||
_G.MinimapBorderTop,
|
||||
_G.MinimapZoomIn,
|
||||
_G.MinimapZoomOut,
|
||||
_G.MinimapNorthTag,
|
||||
_G.MinimapZoneTextButton,
|
||||
_G.MiniMapTracking,
|
||||
_G.MiniMapMailBorder
|
||||
}
|
||||
|
||||
for _, frame in pairs(frames) do
|
||||
frame:Kill()
|
||||
end
|
||||
|
||||
_G.MiniMapMailIcon:SetTexture(E.Media.Textures.Mail)
|
||||
|
||||
-- Every GarrisonLandingPageMinimapButton_UpdateIcon() call reanchor the button
|
||||
hooksecurefunc('GarrisonLandingPageMinimapButton_UpdateIcon', M.HandleGarrisonButton)
|
||||
|
||||
--Hide the BlopRing on Minimap
|
||||
Minimap:SetArchBlobRingScalar(0)
|
||||
Minimap:SetQuestBlobRingScalar(0)
|
||||
|
||||
if E.private.general.minimap.hideClassHallReport then
|
||||
_G.GarrisonLandingPageMinimapButton:Kill()
|
||||
_G.GarrisonLandingPageMinimapButton.IsShown = function() return true end
|
||||
end
|
||||
|
||||
_G.QueueStatusMinimapButtonBorder:Hide()
|
||||
_G.QueueStatusFrame:SetClampedToScreen(true)
|
||||
_G.MiniMapWorldMapButton:Hide()
|
||||
_G.MiniMapInstanceDifficulty:SetParent(Minimap)
|
||||
_G.GuildInstanceDifficulty:SetParent(Minimap)
|
||||
_G.MiniMapChallengeMode:SetParent(Minimap)
|
||||
|
||||
if _G.TimeManagerClockButton then _G.TimeManagerClockButton:Kill() end
|
||||
if _G.FeedbackUIButton then _G.FeedbackUIButton:Kill() end
|
||||
if _G.HybridMinimap then M:SetupHybridMinimap() end
|
||||
|
||||
E:CreateMover(_G.MMHolder, 'MinimapMover', L["Minimap"], nil, nil, MinimapPostDrag, nil, nil, 'maps,minimap')
|
||||
|
||||
_G.MinimapCluster:EnableMouse(false)
|
||||
Minimap:EnableMouseWheel(true)
|
||||
Minimap:SetScript('OnMouseWheel', M.Minimap_OnMouseWheel)
|
||||
Minimap:SetScript('OnMouseDown', M.Minimap_OnMouseDown)
|
||||
Minimap:SetScript('OnMouseUp', E.noop)
|
||||
|
||||
self:RegisterEvent('PLAYER_ENTERING_WORLD', 'Update_ZoneText')
|
||||
self:RegisterEvent('ZONE_CHANGED_NEW_AREA', 'Update_ZoneText')
|
||||
self:RegisterEvent('ZONE_CHANGED_INDOORS', 'Update_ZoneText')
|
||||
self:RegisterEvent('ZONE_CHANGED', 'Update_ZoneText')
|
||||
self:RegisterEvent('ADDON_LOADED')
|
||||
self:UpdateSettings()
|
||||
end
|
||||
|
||||
E:RegisterModule(M:GetName())
|
||||
264
Modules/Maps/Worldmap.lua
Normal file
264
Modules/Maps/Worldmap.lua
Normal file
@@ -0,0 +1,264 @@
|
||||
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
|
||||
local M = E:GetModule('WorldMap')
|
||||
|
||||
local _G = _G
|
||||
local strfind = strfind
|
||||
local CreateFrame = CreateFrame
|
||||
local SetUIPanelAttribute = SetUIPanelAttribute
|
||||
local MOUSE_LABEL = MOUSE_LABEL:gsub('|[TA].-|[ta]','')
|
||||
local PLAYER = PLAYER
|
||||
local hooksecurefunc = hooksecurefunc
|
||||
local IsPlayerMoving = IsPlayerMoving
|
||||
local PlayerMovementFrameFader = PlayerMovementFrameFader
|
||||
-- GLOBALS: CoordsHolder
|
||||
|
||||
local INVERTED_POINTS = {
|
||||
TOPLEFT = 'BOTTOMLEFT',
|
||||
TOPRIGHT = 'BOTTOMRIGHT',
|
||||
BOTTOMLEFT = 'TOPLEFT',
|
||||
BOTTOMRIGHT = 'TOPRIGHT',
|
||||
TOP = 'BOTTOM',
|
||||
BOTTOM = 'TOP',
|
||||
}
|
||||
|
||||
-- this will be updated later
|
||||
local smallerMapScale = 0.8
|
||||
|
||||
function M:SetLargeWorldMap()
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
WorldMapFrame:SetParent(E.UIParent)
|
||||
WorldMapFrame:SetScale(1)
|
||||
WorldMapFrame.ScrollContainer.Child:SetScale(smallerMapScale)
|
||||
|
||||
if WorldMapFrame:GetAttribute('UIPanelLayout-area') ~= 'center' then
|
||||
SetUIPanelAttribute(WorldMapFrame, 'area', 'center');
|
||||
end
|
||||
|
||||
if WorldMapFrame:GetAttribute('UIPanelLayout-allowOtherPanels') ~= true then
|
||||
SetUIPanelAttribute(WorldMapFrame, 'allowOtherPanels', true)
|
||||
end
|
||||
|
||||
WorldMapFrame:OnFrameSizeChanged()
|
||||
if WorldMapFrame:GetMapID() then
|
||||
WorldMapFrame.NavBar:Refresh()
|
||||
end
|
||||
end
|
||||
|
||||
function M:UpdateMaximizedSize()
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
local width, height = WorldMapFrame:GetSize()
|
||||
local magicNumber = (1 - smallerMapScale) * 100
|
||||
WorldMapFrame:Size((width * smallerMapScale) - (magicNumber + 2), (height * smallerMapScale) - 2)
|
||||
end
|
||||
|
||||
function M:SynchronizeDisplayState()
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
if WorldMapFrame:IsMaximized() then
|
||||
WorldMapFrame:ClearAllPoints()
|
||||
WorldMapFrame:Point('CENTER', E.UIParent)
|
||||
end
|
||||
end
|
||||
|
||||
function M:SetSmallWorldMap()
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
if not WorldMapFrame:IsMaximized() then
|
||||
WorldMapFrame:ClearAllPoints()
|
||||
WorldMapFrame:Point('TOPLEFT', E.UIParent, 'TOPLEFT', 16, -94)
|
||||
end
|
||||
end
|
||||
|
||||
local inRestrictedArea = false
|
||||
function M:UpdateRestrictedArea()
|
||||
if E.MapInfo.x and E.MapInfo.y then
|
||||
inRestrictedArea = false
|
||||
else
|
||||
inRestrictedArea = true
|
||||
CoordsHolder.playerCoords:SetFormattedText('%s: %s', PLAYER, 'N/A')
|
||||
end
|
||||
end
|
||||
|
||||
function M:UpdateCoords(OnShow)
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
if not WorldMapFrame:IsShown() then return end
|
||||
|
||||
if WorldMapFrame.ScrollContainer:IsMouseOver() then
|
||||
local x, y = WorldMapFrame.ScrollContainer:GetNormalizedCursorPosition()
|
||||
if x and y and x >= 0 and y >= 0 then
|
||||
CoordsHolder.mouseCoords:SetFormattedText('%s: %.2f, %.2f', MOUSE_LABEL, x * 100, y * 100)
|
||||
else
|
||||
CoordsHolder.mouseCoords:SetText('')
|
||||
end
|
||||
else
|
||||
CoordsHolder.mouseCoords:SetText('')
|
||||
end
|
||||
|
||||
if not inRestrictedArea and (OnShow or E.MapInfo.coordsWatching) then
|
||||
if E.MapInfo.x and E.MapInfo.y then
|
||||
CoordsHolder.playerCoords:SetFormattedText('%s: %.2f, %.2f', PLAYER, (E.MapInfo.xText or 0), (E.MapInfo.yText or 0))
|
||||
else
|
||||
CoordsHolder.playerCoords:SetFormattedText('%s: %s', PLAYER, 'N/A')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M:PositionCoords()
|
||||
local db = E.global.general.WorldMapCoordinates
|
||||
local position = db.position
|
||||
local xOffset = db.xOffset
|
||||
local yOffset = db.yOffset
|
||||
|
||||
local x, y = 5, 5
|
||||
if strfind(position, 'RIGHT') then x = -5 end
|
||||
if strfind(position, 'TOP') then y = -5 end
|
||||
|
||||
CoordsHolder.playerCoords:ClearAllPoints()
|
||||
CoordsHolder.playerCoords:Point(position, _G.WorldMapFrame.BorderFrame, position, x + xOffset, y + yOffset)
|
||||
CoordsHolder.mouseCoords:ClearAllPoints()
|
||||
CoordsHolder.mouseCoords:Point(position, CoordsHolder.playerCoords, INVERTED_POINTS[position], 0, y)
|
||||
end
|
||||
|
||||
function M:MapShouldFade()
|
||||
-- normally we would check GetCVarBool('mapFade') here instead of the setting
|
||||
return E.global.general.fadeMapWhenMoving and not _G.WorldMapFrame:IsMouseOver()
|
||||
end
|
||||
|
||||
function M:MapFadeOnUpdate(elapsed)
|
||||
self.elapsed = (self.elapsed or 0) + elapsed
|
||||
if self.elapsed > 0.1 then
|
||||
self.elapsed = 0
|
||||
|
||||
local object = self.FadeObject
|
||||
local settings = object and object.FadeSettings
|
||||
if not settings then return end
|
||||
|
||||
local fadeOut = IsPlayerMoving() and (not settings.fadePredicate or settings.fadePredicate())
|
||||
local endAlpha = (fadeOut and (settings.minAlpha or 0.5)) or settings.maxAlpha or 1
|
||||
local startAlpha = _G.WorldMapFrame:GetAlpha()
|
||||
|
||||
object.timeToFade = settings.durationSec or 0.5
|
||||
object.startAlpha = startAlpha
|
||||
object.endAlpha = endAlpha
|
||||
object.diffAlpha = endAlpha - startAlpha
|
||||
|
||||
if object.fadeTimer then
|
||||
object.fadeTimer = nil
|
||||
end
|
||||
|
||||
E:UIFrameFade(_G.WorldMapFrame, object)
|
||||
end
|
||||
end
|
||||
|
||||
local fadeFrame
|
||||
function M:StopMapFromFading()
|
||||
if fadeFrame then
|
||||
fadeFrame:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
function M:EnableMapFading(frame)
|
||||
if not fadeFrame then
|
||||
fadeFrame = CreateFrame('FRAME')
|
||||
fadeFrame:SetScript('OnUpdate', M.MapFadeOnUpdate)
|
||||
frame:HookScript('OnHide', M.StopMapFromFading)
|
||||
end
|
||||
|
||||
if not fadeFrame.FadeObject then fadeFrame.FadeObject = {} end
|
||||
if not fadeFrame.FadeObject.FadeSettings then fadeFrame.FadeObject.FadeSettings = {} end
|
||||
|
||||
local settings = fadeFrame.FadeObject.FadeSettings
|
||||
settings.fadePredicate = M.MapShouldFade
|
||||
settings.durationSec = E.global.general.fadeMapDuration
|
||||
settings.minAlpha = E.global.general.mapAlphaWhenMoving
|
||||
settings.maxAlpha = 1
|
||||
|
||||
fadeFrame:Show()
|
||||
end
|
||||
|
||||
function M:UpdateMapFade(minAlpha, maxAlpha, durationSec, fadePredicate) -- self is frame
|
||||
if self:IsShown() and (self == _G.WorldMapFrame and fadePredicate ~= M.MapShouldFade) then
|
||||
-- blizzard spams code in OnUpdate and doesnt finish their functions, so we shut their fader down :L
|
||||
PlayerMovementFrameFader.RemoveFrame(self)
|
||||
|
||||
-- replacement function which is complete :3
|
||||
if E.global.general.fadeMapWhenMoving then
|
||||
M:EnableMapFading(self)
|
||||
end
|
||||
|
||||
-- we can't use the blizzard function because `durationSec` was never finished being implimented?
|
||||
-- PlayerMovementFrameFader.AddDeferredFrame(self, E.global.general.mapAlphaWhenMoving, 1, E.global.general.fadeMapDuration, M.MapShouldFade)
|
||||
end
|
||||
end
|
||||
|
||||
function M:Initialize()
|
||||
self.Initialized = true
|
||||
|
||||
if not E.private.general.worldMap then
|
||||
return
|
||||
end
|
||||
|
||||
local WorldMapFrame = _G.WorldMapFrame
|
||||
if E.global.general.WorldMapCoordinates.enable then
|
||||
local CoordsHolder = CreateFrame('Frame', 'CoordsHolder', WorldMapFrame)
|
||||
CoordsHolder:SetFrameLevel(WorldMapFrame.BorderFrame:GetFrameLevel() + 10)
|
||||
CoordsHolder:SetFrameStrata(WorldMapFrame.BorderFrame:GetFrameStrata())
|
||||
CoordsHolder.playerCoords = CoordsHolder:CreateFontString(nil, 'OVERLAY')
|
||||
CoordsHolder.mouseCoords = CoordsHolder:CreateFontString(nil, 'OVERLAY')
|
||||
CoordsHolder.playerCoords:SetTextColor(1, 1 ,0)
|
||||
CoordsHolder.mouseCoords:SetTextColor(1, 1 ,0)
|
||||
CoordsHolder.playerCoords:SetFontObject(_G.NumberFontNormal)
|
||||
CoordsHolder.mouseCoords:SetFontObject(_G.NumberFontNormal)
|
||||
CoordsHolder.playerCoords:SetText(PLAYER..': 0, 0')
|
||||
CoordsHolder.mouseCoords:SetText(MOUSE_LABEL..': 0, 0')
|
||||
|
||||
WorldMapFrame:HookScript('OnShow', function()
|
||||
if not M.CoordsTimer then
|
||||
M:UpdateCoords(true)
|
||||
M.CoordsTimer = M:ScheduleRepeatingTimer('UpdateCoords', 0.1)
|
||||
end
|
||||
end)
|
||||
WorldMapFrame:HookScript('OnHide', function()
|
||||
M:CancelTimer(M.CoordsTimer)
|
||||
M.CoordsTimer = nil
|
||||
end)
|
||||
|
||||
M:PositionCoords()
|
||||
|
||||
E:RegisterEventForObject('LOADING_SCREEN_DISABLED', E.MapInfo, M.UpdateRestrictedArea)
|
||||
E:RegisterEventForObject('ZONE_CHANGED_NEW_AREA', E.MapInfo, M.UpdateRestrictedArea)
|
||||
E:RegisterEventForObject('ZONE_CHANGED_INDOORS', E.MapInfo, M.UpdateRestrictedArea)
|
||||
E:RegisterEventForObject('ZONE_CHANGED', E.MapInfo, M.UpdateRestrictedArea)
|
||||
end
|
||||
|
||||
if E.global.general.smallerWorldMap then
|
||||
smallerMapScale = E.global.general.smallerWorldMapScale
|
||||
|
||||
WorldMapFrame.BlackoutFrame.Blackout:SetTexture()
|
||||
WorldMapFrame.BlackoutFrame:EnableMouse(false)
|
||||
|
||||
self:SecureHook(WorldMapFrame, 'Maximize', 'SetLargeWorldMap')
|
||||
self:SecureHook(WorldMapFrame, 'Minimize', 'SetSmallWorldMap')
|
||||
self:SecureHook(WorldMapFrame, 'SynchronizeDisplayState')
|
||||
self:SecureHook(WorldMapFrame, 'UpdateMaximizedSize')
|
||||
|
||||
self:SecureHookScript(WorldMapFrame, 'OnShow', function()
|
||||
if WorldMapFrame:IsMaximized() then
|
||||
WorldMapFrame:UpdateMaximizedSize()
|
||||
self:SetLargeWorldMap()
|
||||
else
|
||||
self:SetSmallWorldMap()
|
||||
end
|
||||
|
||||
M:Unhook(WorldMapFrame, 'OnShow', nil)
|
||||
end)
|
||||
end
|
||||
|
||||
-- This lets us control the maps fading function
|
||||
hooksecurefunc(PlayerMovementFrameFader, 'AddDeferredFrame', M.UpdateMapFade)
|
||||
|
||||
-- Enable/Disable map fading when moving
|
||||
-- currently we dont need to touch this cvar because we have our own control for this currently
|
||||
-- see the comment in `M:UpdateMapFade` about `durationSec` for more information
|
||||
-- SetCVar('mapFade', E.global.general.fadeMapWhenMoving and 1 or 0)
|
||||
end
|
||||
|
||||
E:RegisterInitialModule(M:GetName())
|
||||
Reference in New Issue
Block a user