forked from ArtOfShred/LuiExtended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.lua
224 lines (174 loc) · 6.79 KB
/
UI.lua
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
--[[
LuiExtended
License: The MIT License (MIT)
--]]
-- UI namespace
LUIE.UI = {}
local UI = LUIE.UI
local windowManager = WINDOW_MANAGER
-- A handy chaining function for quickly setting up UI elements
-- Allows us to reference methods to set properties without calling the specific object
function UI.Chain(object)
-- Setup the metatable
local T = {}
setmetatable(T , { __index = function( self , func)
-- Know when to stop chaining
if func == "__END" then return object end
-- Otherwise, add the method to the parent object
return function(self , ...)
assert(object[func] , func .. " missing in object")
object[func](object , ...)
return self
end
end })
-- Return the metatable
return T
end
-- Creates empty CT_TOPLEVELCONTROL window
function UI.TopLevel(anchors, dims)
local tlw = windowManager:CreateTopLevelWindow()
tlw:SetClampedToScreen(true)
tlw:SetMouseEnabled(false)
tlw:SetMovable(false)
tlw:SetHidden(true)
if anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
tlw:SetAnchor(anchors[1], anchors[5] or GuiRoot, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims ~= nil and #dims == 2 then
tlw:SetDimensions(dims[1], dims[2])
end
return tlw
end
-- Creates plain CT_CONTROL UI control element
function UI.Control(parent, anchors, dims, hidden, name)
if not parent then return end
local name = name or nil
local c = windowManager:CreateControl(name, parent, CT_CONTROL)
c:SetHidden(hidden)
if anchors == "fill" then
c:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
c:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
c:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
c:SetDimensions(dims[1], dims[2])
end
return c
end
-- Creates CT_TEXTURE UI control element
function UI.Texture(parent, anchors, dims, texture, drawlayer, hidden)
if not parent then return end
local t = windowManager:CreateControl(nil, parent, CT_TEXTURE)
t:SetHidden(hidden)
if anchors == "fill" then
t:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
t:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
t:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
t:SetDimensions(dims[1], dims[2])
end
if texture then
t:SetTexture(texture)
end
if drawlayer then
t:SetDrawLayer(drawlayer)
end
return t
end
-- Creates CT_BACKDROP UI control element
function UI.Backdrop(parent, anchors, dims, center, edge, hidden)
if not parent then return end
local center = (center ~= nil and #center == 4) and center or { 0,0,0,0.4 }
local edge = (edge ~= nil and #edge == 4) and edge or { 0,0,0,0.6 }
local bg = windowManager:CreateControl(nil, parent, CT_BACKDROP)
bg:SetCenterColor(center[1], center[2], center[3], center[4])
bg:SetEdgeColor(edge[1], edge[2], edge[3], edge[4])
bg:SetEdgeTexture("", 8, 1, 0)
bg:SetDrawLayer(DL_BACKGROUND)
bg:SetHidden(hidden)
if anchors == "fill" then
bg:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
bg:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
bg:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
bg:SetDimensions(dims[1], dims[2])
end
return bg
end
-- Creates CT_BACKDROP UI control element with Chat Window background style
function UI.ChatBackdrop(parent, anchors, dims, color, edge_size, hidden)
if not parent then return end
local color = (color ~= nil and #color == 4) and color or { 0,0,0,1 }
local edge_size = (edge_size ~= nil and edge_size > 0) and edge_size or 16
local bg = windowManager:CreateControl(nil, parent, CT_BACKDROP)
bg:SetCenterColor(color[1], color[2], color[3], color[4])
bg:SetEdgeColor(color[1], color[2], color[3], color[4])
bg:SetCenterTexture("/esoui/art/chatwindow/chat_bg_center.dds")
bg:SetEdgeTexture("/esoui/art/chatwindow/chat_bg_edge.dds", 256, 256, edge_size)
bg:SetInsets(edge_size, edge_size, -edge_size, -edge_size)
bg:SetDrawLayer(DL_BACKGROUND)
bg:SetHidden(hidden)
if anchors == "fill" then
bg:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
bg:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
bg:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
bg:SetDimensions(dims[1], dims[2])
end
return bg
end
-- Creates CT_STATUSBAR UI control element
function UI.StatusBar(parent, anchors, dims, color, hidden)
if not parent then return end
local sb = windowManager:CreateControl(nil, parent, CT_STATUSBAR)
sb:SetHidden(hidden)
if anchors == "fill" then
sb:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
sb:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
sb:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
sb:SetDimensions(dims[1], dims[2])
end
if color ~= nil and (#color == 3 or #color == 4) then
sb:SetColor(unpack(color))
end
return sb
end
-- Creates CT_STATUSBAR UI control element
function UI.Label(parent, anchors, dims, align, font, text, hidden, name)
if not parent then return end
local align = (align ~= nil and #align == 2) and align or { TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER }
local name = name or nil
local label = windowManager:CreateControl(name, parent, CT_LABEL)
label:SetFont(font or 'ZoFontGame')
label:SetHorizontalAlignment(align[1])
label:SetVerticalAlignment(align[2])
label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
label:SetHidden(hidden)
if anchors == "fill" then
label:SetAnchorFill()
elseif anchors ~= nil and #anchors >= 2 and #anchors <= 5 then
label:SetAnchor(anchors[1], anchors[5] or parent, anchors[2], anchors[3] or 0, anchors[4] or 0)
end
if dims == "inherit" then
label:SetDimensions(parent:GetWidth(), parent:GetHeight())
elseif dims ~= nil and #dims == 2 then
label:SetDimensions(dims[1], dims[2])
end
if text then label:SetText(text) end
return label
end