Refactor whole addon to follow best practices
This commit is contained in:
parent
43fc252902
commit
414aef6924
31 changed files with 7843 additions and 29579 deletions
147
Addon/Code/QuestFrame.lua
Executable file
147
Addon/Code/QuestFrame.lua
Executable file
|
@ -0,0 +1,147 @@
|
|||
local _, addon = ...
|
||||
|
||||
local QuestFrame = CreateFrame("Frame", "CzechQuestsQuestFrame", UIParent, "BackdropTemplate")
|
||||
QuestFrame:Hide()
|
||||
|
||||
addon.QuestFrame = QuestFrame
|
||||
|
||||
function QuestFrame:CreateHeader()
|
||||
local font = addon.API.CreateCzechFont(
|
||||
self,
|
||||
CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME,
|
||||
CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE
|
||||
)
|
||||
font:SetWidth(self:GetWidth() - 20)
|
||||
return font;
|
||||
end
|
||||
|
||||
function QuestFrame:CreateText()
|
||||
local font = addon.API.CreateCzechFont(
|
||||
self,
|
||||
CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME,
|
||||
CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE
|
||||
)
|
||||
font:SetWidth(self:GetWidth() - 20)
|
||||
return font;
|
||||
end
|
||||
|
||||
function QuestFrame:Init()
|
||||
-- Default style
|
||||
self:SetSize(300, 200)
|
||||
self:SetBackdrop({ edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 8 })
|
||||
|
||||
-- Background Parchment texture
|
||||
self.Texture = self:CreateTexture(nil, "BACKGROUND", nil, -1);
|
||||
self.Texture:SetAllPoints(true)
|
||||
self.Texture:SetHorizTile(true)
|
||||
|
||||
-- Load settings
|
||||
self:UpdateSettings()
|
||||
end
|
||||
|
||||
function QuestFrame:UpdateSettings()
|
||||
self.Title = self:CreateHeader()
|
||||
self.Text1 = self:CreateText()
|
||||
self.Header = self:CreateHeader()
|
||||
self.Text2 = self:CreateText()
|
||||
|
||||
self:ApplyTheme()
|
||||
|
||||
if not CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING then
|
||||
self.Texture:SetAlpha(CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA / 100)
|
||||
end
|
||||
end
|
||||
|
||||
function QuestFrame:ResetText()
|
||||
self.Title:SetText("")
|
||||
self.Header:SetText("")
|
||||
self.Text1:SetText("")
|
||||
self.Text2:SetText("")
|
||||
end
|
||||
|
||||
function QuestFrame:SetTextColor(r, g, b, a)
|
||||
self.Title:SetTextColor(r, g, b, a)
|
||||
self.Header:SetTextColor(r, g, b, a)
|
||||
self.Text1:SetTextColor(r, g, b, a)
|
||||
self.Text2:SetTextColor(r, g, b, a)
|
||||
end
|
||||
|
||||
function QuestFrame:ApplyTheme()
|
||||
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
|
||||
self.Texture:SetTexture("Interface/QUESTFRAME/QuestBG");
|
||||
self.Texture:SetTexCoord(0, .58, 0.005, 0.66)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
if not CzechQuestsAddon_Store.config.QUEST_DARK_MODE then
|
||||
self:SetBackdropColor(0, 0, 0, 1)
|
||||
self.Texture:SetColorTexture(0, 0, 0, 1)
|
||||
self:SetTextColor(255, 255, 255, 1)
|
||||
end
|
||||
else
|
||||
self.Texture:SetTexture("Interface/QUESTFRAME/QuestBackgroundParchment");
|
||||
self.Texture:SetTexCoord(0, .01, 0, 0.4)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
local questTextContrast = C_CVar.GetCVar("questTextContrast")
|
||||
if questTextContrast == "1" then -- Brown
|
||||
self.Texture:SetTexCoord(0, .01, .4, .8)
|
||||
elseif questTextContrast == "2" or questTextContrast == "3" then -- Gray
|
||||
self.Texture:SetColorTexture(255, 255, 255, 1)
|
||||
elseif questTextContrast == "4" then -- Black
|
||||
self.Texture:SetColorTexture(0, 0, 0, 1)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function QuestFrame:CalculateHeight()
|
||||
local height = 0;
|
||||
local heights = {
|
||||
self.Title:GetHeight() ,
|
||||
self.Text1:GetHeight(),
|
||||
self.Header:GetHeight(),
|
||||
self.Text2:GetHeight(),
|
||||
10
|
||||
}
|
||||
for _, value in ipairs(heights) do
|
||||
height = height + value + 10
|
||||
end
|
||||
self:SetHeight(height)
|
||||
end
|
||||
|
||||
function QuestFrame:SetData(name, text1, header, text2, parentFrame, yOffset, xOffset)
|
||||
-- Reset previously values
|
||||
self:ResetText()
|
||||
|
||||
-- Set parent
|
||||
self:SetParent(parentFrame)
|
||||
|
||||
-- set text to labels
|
||||
self.Title:SetText(name)
|
||||
self.Text1:SetText(text1)
|
||||
self.Header:SetText(header)
|
||||
self.Text2:SetText(text2)
|
||||
|
||||
-- apply text positions
|
||||
self.Title:SetPoint("TOPLEFT", self, "TOPLEFT", 10, -10)
|
||||
self.Text1:SetPoint("TOPLEFT", self.Title, "BOTTOMLEFT", 0, -5)
|
||||
self.Header:SetPoint("TOPLEFT", self.Text1, "BOTTOMLEFT", 0, -20)
|
||||
self.Text2:SetPoint("TOPLEFT", self.Header, "BOTTOMLEFT", 0, -5)
|
||||
|
||||
-- apply frame position
|
||||
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
|
||||
self:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", xOffset, yOffset)
|
||||
else
|
||||
self:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", xOffset, yOffset)
|
||||
end
|
||||
|
||||
self:Show()
|
||||
|
||||
-- wait for font render before calculate height
|
||||
local height = self.Title:GetStringHeight()
|
||||
if height == 0 then
|
||||
C_Timer.After(0.5, function()
|
||||
self:CalculateHeight()
|
||||
end)
|
||||
else
|
||||
self:CalculateHeight()
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue