local KhioHud = LibStub("AceAddon-3.0"):NewAddon("KhioHud", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("KhioHud")
KhioHud.minimapOverlay = _G["KhioHud"].minimapOverlay
KhioHud.toggleButton = _G["KhioHud"].toggleButton
local MinimapCluster = _G["MinimapCluster"]
local Minimap = _G["Minimap"]
function KhioHud:OnInitialize()
self:InitializeSettings()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
function KhioHud:OnEnable()
self:AddToBlizOptions()
if (not KhioHud.minimapOverlay:IsVisible()) then
KhioHud.restorePosition = KhioHud:GetMinimapPosition()
end
--ElvUI dirty fix
if (IsAddOnLoaded("ElvUI")) then
MinimapCluster:ClearAllPoints()
Minimap:ClearAllPoints()
Minimap:SetPoint("TOPLEFT", MinimapCluster)
end
--ElvUI dirty fix
local button = KhioHud.toggleButton
button:RegisterForClicks("LeftButtonDown", "RightButtonDown")
button:SetScript("OnEnter", function(self, motion)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine(L["Left Click: Toggle Khio Hud"])
GameTooltip:AddLine(L["Right Click: Show options"])
GameTooltip:AddLine(L["SHIFT + Drag: Move minimap"])
GameTooltip:Show()
end)
button:SetScript("OnLeave", function(self, motion)
GameTooltip:Hide()
end)
button:SetScript("OnClick", function(self, button, down)
if (button == "LeftButton" and down and not IsShiftKeyDown()) then
KhioHud:Toggle(not KhioHud.minimapOverlay:IsVisible())
elseif (button == "RightButton" and down) then
InterfaceOptionsFrame_OpenToCategory("Khio Hud")
InterfaceOptionsFrame_OpenToCategory("Khio Hud")
end
end)
button:SetScript("OnMouseDown", function(self, button)
if (button == "LeftButton" and IsShiftKeyDown() and not self.isMoving) then
MinimapCluster:SetMovable(true)
MinimapCluster:StartMoving()
self.isMoving = true
end
end)
button:SetScript("OnMouseUp", function(self, button)
if (button == "LeftButton" and self.isMoving) then
MinimapCluster:StopMovingOrSizing()
MinimapCluster:SetMovable(false)
self.isMoving = false
KhioHudDB.minimap = KhioHud:GetMinimapPosition()
KhioHud:Toggle(true)
end
end)
end
function KhioHud:OnDisable()
end
function KhioHud:PLAYER_ENTERING_WORLD()
local inInstance, instanceType = IsInInstance()
if (inInstance and KhioHudDB.autoToggle.inside) then
KhioHud:Toggle(true)
elseif(not inInstance and KhioHudDB.autoToggle.outside) then
KhioHud:Toggle(false)
end
end
function KhioHud:Toggle(visible)
if (visible) then
Minimap:SetZoom(5)
Minimap:EnableMouse(false)
Minimap:EnableMouseWheel(false)
MinimapCluster:SetAlpha(0)
SetCVar("rotateMinimap", true)
KhioHud:SetMinimapPosition(KhioHudDB.minimap.x, KhioHudDB.minimap.y)
KhioHud.minimapOverlay:Show()
else
Minimap:SetZoom(1)
Minimap:EnableMouse(true)
Minimap:EnableMouseWheel(true)
MinimapCluster:SetAlpha(1)
SetCVar("rotateMinimap", false)
KhioHud:SetMinimapPosition(KhioHud.restorePosition.x, KhioHud.restorePosition.y)
KhioHud.minimapOverlay:Hide()
end
end
function KhioHud:GetMinimapPosition()
local s = MinimapCluster:GetEffectiveScale()
return { x = MinimapCluster:GetLeft() * s, y = MinimapCluster:GetTop() * s }
end
function KhioHud:SetMinimapPosition(x, y)
if (x ~= nil and y ~= nil) then
local s = MinimapCluster:GetEffectiveScale()
MinimapCluster:ClearAllPoints()
MinimapCluster:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x / s, y / s)
end
end