Files
pfUI/modules/farmmode.lua
T
Brues 4616c2bc5f Toggle visibility with SetShown instead of Show/Hide branches
Each if/else that only showed one object in one branch and hid it in the other is now ClassicAPI's SetShown, which shows on any truthy value. 21 sites across 10 modules.
2026-10-30 19:49:43 -05:00

141 lines
4.1 KiB
Lua

pfUI:RegisterModule("farmmode", function ()
local function ToggleFarmMode()
pfUI.farmmap:SetShown(not pfUI.farmmap:IsShown())
end
local function MoveNodes(layer)
-- pfMap entries (pfQuest / pfDB)
if pfMap and pfMap.drawlayer then
pfMap.drawlayer = layer
for id, pin in pairs(pfMap.mpins) do
pin:SetParent(layer)
end
pfMap:UpdateMinimap()
end
end
local function UpdateMinimap()
-- haven't found anything better to
-- force update the map textures
Minimap_ZoomIn()
Minimap_ZoomOut()
end
pfUI.api.RegisterSlashCommand("PFFARMMAP", { "/farm", "/farmmode" }, ToggleFarmMode, true)
pfUI.farmmap = CreateFrame("Minimap", "pfFarmMap", UIParent)
pfUI.farmmap:Hide()
pfUI.farmmap:SetFrameStrata("LOW")
pfUI.farmmap:SetWidth(300)
pfUI.farmmap:SetHeight(300)
pfUI.farmmap:SetClampedToScreen(1)
pfUI.farmmap:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 200, -200)
pfUI.farmmap:SetAlpha(.8)
pfUI.farmmap:SetMovable(1)
pfUI.farmmap:EnableMouse(1)
pfUI.farmmap:EnableMouseWheel(1)
pfUI.farmmap:RegisterForDrag("LeftButton")
pfUI.farmmap:SetScript("OnMouseWheel", function()
if IsControlKeyDown() then
local adjust = (arg1 > 0 and 10 or -10)
local width, height = this:GetSize()
this:SetSize(width + adjust, height + adjust)
Minimap_ZoomIn()
Minimap_ZoomOut()
elseif IsShiftKeyDown() then
this:SetAlpha(this:GetAlpha() + (arg1 > 0 and 0.1 or (this:GetAlpha() > 0.1 and -0.1 or 0)))
SaveMovable(this)
else
if(arg1 > 0) then Minimap_ZoomIn() else Minimap_ZoomOut() end
end
end)
pfUI.farmmap:SetScript("OnDragStart", function()
this:StartMoving()
end)
pfUI.farmmap:SetScript("OnDragStop", function()
this:StopMovingOrSizing()
SaveMovable(this)
end)
pfUI.farmmap:SetScript("OnUpdate", function()
if not Minimap:IsShown() then return end
Minimap:Hide()
-- move existing nodes to new minimap
MoveNodes(pfUI.farmmap)
-- move tracking frame
if pfUI.tracking then
pfUI.tracking:ClearAllPoints()
pfUI.tracking:SetPoint("TOPLEFT", pfUI.farmmap, -10, -10)
end
-- move pvp icon
if pfUI.minimap and pfUI.minimap.pvpicon then
pfUI.minimap.pvpicon:ClearAllPoints()
pfUI.minimap.pvpicon:SetPoint("BOTTOMRIGHT", pfUI.farmmap, "BOTTOMRIGHT", -5, 5)
end
-- save old minimap height
if pfUI.minimap then
this.mmoldsize = pfUI.minimap:GetHeight()
pfUI.minimap:SetHeight(16)
pfUI.minimap:SetAlpha(1)
pfUI.farmmap.button:Show()
end
-- refresh minimap content
UpdateMinimap()
end)
pfUI.farmmap:SetScript("OnHide", function()
ShowUIPanel(Minimap)
-- move existing nodes to new minimap
MoveNodes(Minimap)
-- move tracking frame
if pfUI.tracking then
pfUI.tracking:ClearAllPoints()
pfUI.tracking:SetPoint("TOPLEFT", pfUI.minimap or Minimap, -10, -10)
UpdateMovable(pfUI.tracking)
end
-- move pvp icon
if pfUI.minimap and pfUI.minimap.pvpicon then
pfUI.minimap.pvpicon:ClearAllPoints()
pfUI.minimap.pvpicon:SetPoint("BOTTOMRIGHT", pfUI.minimap, "BOTTOMRIGHT", -5, 5)
end
-- save old minimap height
if pfUI.minimap then
pfUI.minimap:SetHeight(this.mmoldsize)
pfUI.minimap:SetAlpha(1)
pfUI.farmmap.button:Hide()
end
-- refresh minimap content
UpdateMinimap()
end)
if pfUI.minimap then
pfUI.farmmap.button = CreateFrame("Button", "pfFarmMapButton", pfUI.minimap)
pfUI.farmmap.button:Hide()
pfUI.farmmap.button:SetPoint("TOPLEFT", pfUI.minimap, "TOPLEFT", 0, 0)
pfUI.farmmap.button:SetPoint("BOTTOMRIGHT", pfUI.minimap, "BOTTOMRIGHT", 0, 0)
pfUI.farmmap.button:SetFrameStrata("MEDIUM")
pfUI.farmmap.button:SetScript("OnClick", ToggleFarmMode)
pfUI.farmmap.button.txt = pfUI.farmmap.button:CreateFontString("pfFarmMapText", "LOW", "GameFontWhite")
pfUI.farmmap.button.txt:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
pfUI.farmmap.button.txt:SetPoint("CENTER", 0, 0)
pfUI.farmmap.button.txt:SetText("|cff33ffcc " .. T["FARM MODE"])
end
CreateBackdrop(pfUI.farmmap)
LoadMovable(pfUI.farmmap)
end)