Repository navigation
Expand file tree
/
Copy pathExample.lua
More file actions
executable file
·163 lines (143 loc) · 6.07 KB
/
Copy pathExample.lua
File metadata and controls
executable file
·163 lines (143 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
--[[ ------------------------------------------------------------------------
Title: Example.lua
Author: mrbryo
Create Date : 07/11/2026
Description: Just a way to view a frame with UI elements.
-----------------------------------------------------------------------------]]
local addonName, ns = ...
-- for all example code
ns.example = {
objects = {},
const = {
template = "ExampleTemplateType",
frameType = "ExampleFrameType",
note = "ExampleNote",
padding = 10,
-- colors
colors = {
white = "|cffffffff",
yellow = "|cffffff00",
green = "|cff00ff00",
blue = "|cff0000ff",
purple = "|cffff00ff",
red = "|cffff0000",
orange = "|cffff7f00",
gray = "|cff7f7f7f",
label = "|cffffd100",
ending = "|r",
},
},
ui = {
frames = {}
}
}
-- properly get frame attribute to check for nil or attribute which doesn't exist
function ns:GetAttribute(uiobject, attribute)
if uiobject == nil then
return ns.L["NIL Object"]
else
local attrValue = uiobject:GetAttribute(attribute)
if attrValue == nil then
return ns.L["Missing Attribute"]
else
return attrValue
end
end
end
function ns:ExampleFrame(parentFrame, object)
-- standard variables
local padding = ns.example.const.padding
-- content frame
local groupFrame = CreateFrame("Frame", nil, parentFrame, "InsetFrameTemplate")
groupFrame:SetFrameStrata("MEDIUM")
local bg = groupFrame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(groupFrame)
bg:SetColorTexture(0, 0, 0, 0.7) -- Black, 80% opaque
-- get object attributes
local frameType = ns:GetAttribute(object, ns.example.const.frameType)
local frameTemplate = ns:GetAttribute(object, ns.example.const.template)
-- add text about object
local frameLabel = groupFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
frameLabel:SetText(("%s%s%s %s"):format(ns.example.const.colors.white, ns.L["Frame Type:"], ns.example.const.colors.ending, frameType))
frameLabel:SetJustifyH("LEFT")
frameLabel:SetWordWrap(true)
frameLabel:SetPoint("TOPLEFT", groupFrame, "TOPLEFT", padding, -padding)
frameLabel:SetPoint("TOPRIGHT", groupFrame, "TOPRIGHT", -padding, -padding)
local templateLabel = groupFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
templateLabel:SetText(("%s%s%s %s"):format(ns.example.const.colors.white, ns.L["Frame Template:"], ns.example.const.colors.ending, frameTemplate))
templateLabel:SetJustifyH("LEFT")
templateLabel:SetWordWrap(true)
templateLabel:SetPoint("TOPLEFT", frameLabel, "BOTTOMLEFT", 0, -padding)
templateLabel:SetPoint("TOPRIGHT", frameLabel, "BOTTOMRIGHT", 0, -padding)
local rowHeight = frameLabel:GetStringHeight() + templateLabel:GetStringHeight() + (padding * 2)
-- set the top left corder to the previous object
if object ~= nil then
object:SetPoint("TOPLEFT", templateLabel, "BOTTOMLEFT", 0, -padding)
object:SetPoint("TOPRIGHT", templateLabel, "BOTTOMRIGHT", 0, -padding)
-- place note if the attribute exists
local note = object:GetAttribute(ns.example.const.note)
if note ~= nil then
local noteString = groupFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
noteString:SetText(("%s%s%s %s"):format(ns.example.const.colors.white, "Note:", ns.example.const.colors.ending, note))
noteString:SetJustifyH("LEFT")
noteString:SetJustifyV("TOP")
if object ~= nil then
noteString:SetPoint("TOPLEFT", object, "BOTTOMLEFT", 0, -padding)
noteString:SetPoint("TOPRIGHT", object, "BOTTOMRIGHT", 0, -padding)
noteString:SetPoint("BOTTOMLEFT", groupFrame, "BOTTOMLEFT", 0, padding)
else
noteString:SetPoint("TOPLEFT", templateLabel, "BOTTOMLEFT", 0, -padding)
noteString:SetPoint("TOPRIGHT", templateLabel, "BOTTOMRIGHT", 0, -padding)
noteString:SetPoint("BOTTOMLEFT", groupFrame, "BOTTOMLEFT", 0, padding)
end
-- include note height
rowHeight = rowHeight + noteString:GetStringHeight()
end
-- add height
rowHeight = rowHeight + object:GetHeight() + (padding * 1)
end
-- set height
groupFrame:SetHeight(rowHeight)
-- return the frame
return groupFrame
end
function ns:ShowUI()
local frameName = "MainFrame"
-- if the MainFrame is not nil then exit early as the UI is already built
if ns.example.ui.frames.MainFrame ~= nil then
if ns.example.ui.frames.MainFrame:IsVisible() == false then
ns.example.ui.frames.MainFrame:Show()
end
return
end
-- only create if frame is nil
local mainFrame = CreateFrame("Frame", nil, UIParent, "BasicFrameTemplate")
frameWidth = 800
frameHeight = 600
mainFrame:SetSize(frameWidth, frameHeight)
mainFrame:SetAttribute("ExampleFrameName", frameName)
ns.framePosn:RestoreFramePosition(mainFrame, mainFrame:GetAttribute("ExampleFrameName"), frameWidth, frameHeight)
mainFrame:SetMovable(true)
mainFrame:EnableMouse(true)
mainFrame:RegisterForDrag("LeftButton")
mainFrame:SetScript("OnDragStart", mainFrame.StartMoving)
mainFrame:SetScript("OnDragStop", function(thisframe)
-- must be self; since this is a frame function
thisframe:StopMovingOrSizing()
-- save location and size
ns.framePosn:StoreFramePosition(mainFrame, frameName)
end)
mainFrame:SetFrameStrata("MEDIUM")
mainFrame:SetFrameLevel(1)
-- instantiate the tabs
ns.tabDropdown:SetupTabDropdowns(mainFrame)
ns.tabButton:SetupTabButtons(mainFrame)
ns.tabFrame:SetupTabFrames(mainFrame)
-- draw the tabs
ns.tabs:ProcessTabSystem(mainFrame)
-- show the frame
ns.example.ui.frames.MainFrame = mainFrame
if mainFrame:IsVisible() == false then
ns.example.ui.frames.MainFrame:Show()
end
end