Files
2026-11-15 17:40:50 +01:00

206 lines
9.1 KiB
Lua

---
--- QuestUI.lua - Atlas quest UI frame and component creation
---
--- This file contains the quest UI frame creation and management for Atlas-CFM.
--- It handles quest window interface, quest display components, frame layout,
--- and provides the visual foundation for the Atlas quest browser system.
---
--- Features:
--- - Quest frame creation and styling
--- - Quest display components
--- - UI element initialization
--- - Frame positioning and layout
--- - Quest interface management
---
--- @compatible World of Warcraft 1.12
---
local _G = getfenv()
AtlasCFM = _G.AtlasCFM
local L = (AtlasCFM.Localization and AtlasCFM.Localization.UI) or {}
-- Constants
local FRAME_WIDTH = 220
local FRAME_HEIGHT = 570
local FRAME_POINT = { "TOP", "AtlasCFMFrame", -556, -30 }
-- Main Frame
local frame = CreateFrame("Frame", "", AtlasCFMFrame)
frame:SetWidth(FRAME_WIDTH)
frame:SetHeight(FRAME_HEIGHT)
frame:SetPoint(unpack(FRAME_POINT))
--frame:SetMovable(false)
frame:EnableMouse(true)
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 5, right = 5, top = 5, bottom = 5 }
})
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function()
AtlasCFM.StartMoving()
end)
frame:SetScript("OnDragStop", function()
AtlasCFMFrame:StopMovingOrSizing()
AtlasCFMFrame.isMoving = false
end)
frame:SetScript("OnMouseUp", function()
AtlasCFMFrame:StopMovingOrSizing()
AtlasCFMFrame.isMoving = false
end)
frame:Hide()
-- UI Elements Table
local UI_Main = { Frame = frame }
---
--- Helper function to create UI elements with common properties
--- @param type string The frame type to create (e.g., "Button", "Frame")
--- @param name string The name for the frame (can be empty string)
--- @param parent table The parent frame object
--- @param template string The template to use for the frame (optional)
--- @param width number The width of the element in pixels
--- @param height number The height of the element in pixels
--- @param point table The positioning point as {anchor, x, y} or {anchor, relativeTo, relativeAnchor, x, y}
--- @param text string Optional text to set on the element
--- @return table The created UI element
--- @usage local button = CreateElement("Button", "", parent, "UIPanelButtonTemplate", 100, 30, {"CENTER", 0, 0}, "Click Me")
---
local function CreateElement(type, name, parent, template, width, height, point, text)
local element = CreateFrame(type, name, parent, template)
element:SetWidth(width)
element:SetHeight(height)
element:SetPoint(unpack(point))
if text then element:SetText(text) end
return element
end
---
--- Helper function to create FontString objects with common properties
--- @param name string The name for the FontString (can be empty string)
--- @param parent table The parent frame object
--- @param font string The font template to use (e.g., "GameFontNormal")
--- @param point table The positioning point as {anchor, x, y} or {anchor, relativeTo, relativeAnchor, x, y}
--- @param width number The width of the text area in pixels
--- @param height number The height of the text area in pixels
--- @param justifyH string Horizontal justification ("LEFT", "CENTER", "RIGHT"), defaults to "CENTER"
--- @param justifyV string Vertical justification ("TOP", "MIDDLE", "BOTTOM"), defaults to "MIDDLE"
--- @return table The created FontString object
--- @usage local label = CreateText("", parent, "GameFontNormal", {"TOP", 0, -10}, 200, 20, "LEFT", "TOP")
---
local function CreateText(name, parent, font, point, width, height, justifyH, justifyV)
local text = parent:CreateFontString(name, "ARTWORK", font)
text:SetWidth(width)
text:SetHeight(height)
text:SetPoint(unpack(point))
text:SetJustifyH(justifyH or "CENTER")
text:SetJustifyV(justifyV or "MIDDLE")
return text
end
---
--- Sets the frame level relative to parent when frame is shown
--- Ensures this frame appears above its parent frame in the UI stack
--- @usage frame:SetScript("OnShow", setFrameLevelOnShow)
---
local function setFrameLevelOnShow()
this:SetFrameLevel(this:GetParent():GetFrameLevel() + 1)
end
-- Close Button
UI_Main.CloseButton = CreateElement("Button", "", frame, "UIPanelCloseButton", 27, 27, { "TOPLEFT", 10, -10 })
UI_Main.CloseButton:SetScript("OnClick", function() AtlasCFM.Quest.CloseQuestFrame() end)
UI_Main.CloseButton:SetScript("OnShow", setFrameLevelOnShow)
-- Story Button
UI_Main.StoryButton = CreateElement("Button", "", frame, "OptionsButtonTemplate", 70, 20, { "TOP", 0, -13 }, L["Story"])
UI_Main.StoryButton:SetScript("OnClick", function() AtlasCFM.Quest.OnStoryClick() end)
UI_Main.StoryButton:SetScript("OnShow", setFrameLevelOnShow)
-- Faction Buttons
UI_Main.AllianceButton = CreateElement("Button", "", frame, nil, 30, 30, { "TOPLEFT", 25, -25 })
UI_Main.AllianceButton:SetNormalTexture("Interface\\TargetingFrame\\UI-PVP-Alliance")
UI_Main.AllianceButton:GetNormalTexture():SetWidth(50)
UI_Main.AllianceButton:GetNormalTexture():SetHeight(50)
UI_Main.AllianceButton:GetNormalTexture():ClearAllPoints()
UI_Main.AllianceButton:GetNormalTexture():SetPoint("CENTER", 8, -9)
UI_Main.AllianceButton:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
UI_Main.AllianceButton:SetScript("OnClick", function() AtlasCFM.Quest.OnAllianceClick() end)
UI_Main.AllianceButton:SetScript("OnShow", setFrameLevelOnShow)
UI_Main.HordeButton = CreateElement("Button", "", frame, nil, 30, 30, { "TOPRIGHT", -25, -25 })
UI_Main.HordeButton:SetNormalTexture("Interface\\TargetingFrame\\UI-PVP-Horde")
UI_Main.HordeButton:GetNormalTexture():SetWidth(50)
UI_Main.HordeButton:GetNormalTexture():SetHeight(50)
UI_Main.HordeButton:GetNormalTexture():ClearAllPoints()
UI_Main.HordeButton:GetNormalTexture():SetPoint("CENTER", 8, -9)
UI_Main.HordeButton:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD")
UI_Main.HordeButton:SetScript("OnClick", function() AtlasCFM.Quest.OnHordeClick() end)
UI_Main.HordeButton:SetScript("OnShow", setFrameLevelOnShow)
-- Quest Counter Text
UI_Main.QuestCounter = CreateText("", frame, "GameFontNormal", { "TOP", 0, -25 }, 60, 40)
-- Quest Buttons, Arrows, and Texts
UI_Main.QuestButtons = {}
for i = 1, AtlasCFM.QMAXQUESTS do
local index = i
local yOffset = -60 - (i - 1) * 20
local button = CreateElement("Button", "", frame, nil, 165, 20, { "TOPLEFT", 15, yOffset })
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:SetScript("OnClick", function() AtlasCFM.Quest.OnQuestClick(this:GetID(), arg1) end)
button:SetScript("OnShow", setFrameLevelOnShow)
local arrow = frame:CreateTexture("", "OVERLAY")
arrow:SetWidth(15)
arrow:SetHeight(15)
arrow:SetPoint("TOPLEFT", button, 1, -2.5)
arrow:SetTexture("Interface\\Glues\\Login\\UI-BackArrow")
local text = CreateText("", button, "GameFontNormalSmall", { "TOPLEFT", 15, 0 }, 150, 20, "LEFT")
UI_Main.QuestButtons[i] = { Button = button, Arrow = arrow, Text = text }
end
-- Register Events
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("CHAT_MSG_SYSTEM")
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:SetBackdropBorderColor(0.80, 0.60, 0.25, 1)
frame:SetScript("OnEvent", function()
-- Debug print to verify script handler execution
-- if DEFAULT_CHAT_FRAME then DEFAULT_CHAT_FRAME:AddMessage("Atlas-CFM: Frame OnEvent Triggered: " .. (event or "nil")) end
AtlasCFM.Quest.OnEvent(event, arg1, arg2, arg3)
end)
frame:SetScript("OnShow", function() AtlasCFM.Quest.OnQuestFrameShow() end)
-- Check Completed Quests Button
-- Use the segmented panel button artwork for this wide footer control.
-- The single-piece OptionsButtonTemplate stretches its texture at wide widths;
-- UIPanelButtonTemplate2 keeps fixed caps and stretches only the middle section.
--
-- Keep this control inside the usable interior of the 220px quest frame instead
-- of placing it over the dialog-frame border. The backdrop uses a 32px edge, so
-- a 20px horizontal inset and 20px bottom inset give the footer clear breathing
-- room while preserving enough width for the localized label.
--
-- Template2 resolves $parentLeft/Middle/Right through the global frame name, so
-- the button must be named rather than anonymous.
local QUEST_FOOTER_BUTTON_WIDTH = FRAME_WIDTH - 40
local QUEST_FOOTER_BOTTOM_INSET = 20
UI_Main.CheckCompletedQuestsButton = CreateElement("Button", "AtlasCFMQuestCheckCompletedQuestsButton", frame, "UIPanelButtonTemplate2", QUEST_FOOTER_BUTTON_WIDTH, 20,
{ "BOTTOM", 0, QUEST_FOOTER_BOTTOM_INSET }, L["Check Completed Quests"])
UI_Main.CheckCompletedQuestsButton:SetScript("OnClick", function()
SendChatMessage(".queststatus")
this:Hide()
end)
UI_Main.CheckCompletedQuestsButton:SetScript("OnShow", setFrameLevelOnShow)
-- Assign UI table to the global namespace
AtlasCFM.Quest.UI_Main = UI_Main