comparison UI.lua @ 35:3304455a3f45

code organizing; UI stuff is in the UI script, Devian prime just deals with config and print corner menu elements placed and hooked, still needs follow-up code
author Nenue
date Sun, 27 Dec 2015 03:51:17 -0500
parents
children bec37163b7fe
comparison
equal deleted inserted replaced
34:7441f3bce940 35:3304455a3f45
1 --- ${PACKAGE_NAME}
2 -- @file-author@
3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@
5 -- Created: 12/27/2015 3:01 AM
6
7
8 if not LibStub then
9 print('Something has happened...')
10 end
11 local D = LibStub("AceAddon-3.0"):GetAddon("Devian")
12
13
14
15 local DEVIAN_FRAME = 'DevianConsole'
16 local DEVIAN_DOCK_FRAME = 'DevianDockFrame'
17 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
18
19
20 local function Console_MinMax(self)
21 if self.minimized then
22 self:Maximize()
23 else
24 self:Minimize()
25 end
26 end
27
28 local function Console_Minimize(self)
29 self:SetHeight(20)
30 self:SetMaxResize(GetScreenWidth(),20)
31 self.minimized = true
32 self.out:Hide()
33 self:Save()
34 end
35
36 local function Console_Maximize(self)
37 local db = D.channels[self.index]
38 self:SetHeight(db.height)
39 self:SetMaxResize(GetScreenWidth(),GetScreenHeight())
40 self.minimized = nil
41 self.out:Show()
42 self:Save()
43 end
44
45
46 local function Console_Save(self)
47 local db = D.channels[self.index]
48 if self.x then
49 db.x = self.x
50 else
51 db.x = self:GetLeft()
52 end
53
54 if self.y then
55 db.y = self.y
56 else
57 db.y = (self:GetTop() - GetScreenHeight())
58 end
59
60 if self.width then
61 db.width = self.width
62 else
63 db.width = self:GetWidth()
64 end
65
66 if not self.minimized then
67 if self.height then
68 db.height = self.height
69 else
70 db.height = self:GetHeight()
71 end
72 self:SetHeight(db.height)
73 end
74
75 db.dockedTo = self.dockedTo
76 db.docked = self.docked
77
78 db.minimized = self.minimized and true or nil
79 db.enabled = self:IsVisible() and true or nil
80 db.active = self.active and true or nil
81 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width)
82 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y)
83 self:SetWidth(db.width)
84 end
85
86 -- Console frame toggler
87 -- @paramsig [...]
88 -- @param ... one or more space-seperated channel keys
89 local function Console_Toggle(input)
90 local db = D.db
91 if db.workspace == 1 then
92 return D:Print(MSG_NEED_DEV_MODE)
93 end
94 local search = {}
95 local n = 0
96 if D:GetArgs(input,1) then
97 repeat
98 key, n = D:GetArgs(input,1,n)
99 if D.sig[key] then
100 table.insert(search, D.sig[key])
101 elseif D.console[key] then
102 table.insert(search, D.console[key])
103 end
104 until n == 1e9
105 else
106 search = D.console
107 end
108
109 db.enabled = (not db.enabled) and true or nil
110 for i, c in ipairs(search) do
111 --print(i,c.index)
112 if db.enabled then
113 c.enabled = true
114 c:Show()
115 if db.current_channel == c.index then
116 c:ToFront()
117 end
118 c:Save()
119 else
120 c:Hide()
121 end
122 end
123
124 if db.enabled then
125 D:Print('toggled on?')
126 else
127 D:Print('toggled off?')
128 end
129 end
130
131 --- Brings the console to the front.
132 -- Frame method used to bring a console frame to the front of the display stack.
133 local function Console_ToFront(c)
134 local db = D.db
135 --print(D.raise_ct, 'Raising', c.signature)
136 --print(unpack(db.frontdrop))
137 --print(unpack(db.frontgrad))
138 --print(db.frontblend)
139 -- D.raise_ct = D.raise_ct + 1
140 c:Raise()
141 c:SetAlpha(db.frontalpha)
142 c.out.backdrop:SetTexture(unpack(db.frontdrop))
143 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
144 c.out.backdrop:SetBlendMode(db.frontblend)
145 db.current_channel = c.index
146
147 for _, part in pairs(c.border) do
148 part:SetTexture(unpack(db.frontborder))
149 end
150
151 for id, bc in pairs(D.console) do
152 if id ~= c.index then
153 --print(D.raise_ct, 'Lowering', bc.signature)
154 --print(unpack(db.backdrop))
155 --print(unpack(db.backgrad))
156 --print(db.backblend)
157 bc:SetAlpha(db.backalpha)
158 bc.out.backdrop:SetTexture(unpack(db.backdrop))
159 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
160 bc.out.backdrop:SetBlendMode(db.backblend)
161
162 for _, part in pairs(bc.border) do
163 part:SetTexture(unpack(db.backborder))
164 end
165 end
166 end
167 end
168
169 local function Console_MouseDown(self, button, up)
170 if button == 'LeftButton' then
171 if up then
172 self:StopMovingOrSizing()
173 self:ToFront()
174 self.x = nil
175 self.y = nil
176 self.width = nil
177 self.height = nil
178 self:Save()
179 elseif self.out.grip:IsMouseOver() then
180 self:StartSizing()
181 else
182 self:StartMoving()
183 end
184 else
185 if up then
186 self:MinMax()
187 end
188 end
189 end
190 local function Console_MouseUp(self, button)
191 return Console_MouseDown(self, button, true)
192 end
193 print('load check')
194
195
196 --- Constructs the frame object for a console channel
197 -- Initializes the console channel at a specified index.
198 -- Configuration data can be overridden by passing a desired settings table.
199 -- @param i Numeric index of the channel as it manifests in db.channels
200 -- @param vars Optional settings table to be used.
201 local function CreateConsole(i, vars)
202 local db = D.db
203 if tonumber(i) == nil or math.floor(i) ~= i then
204 error('Non-integer index value.')
205 end
206 if not vars then
207 vars = D.channels[i] and D.channels[i] or D.channels[db.primary_channel]
208 end
209 local f
210 if vars.docked then
211 f = CreateFrame('Frame','DevianDockFrame' .. i, DEVIAN_DOCK_FRAME)
212 else
213 f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME)
214 end
215 --@debug@
216 --print(f:GetName())
217
218 --print('create(2)')
219 for k,v in pairs(vars) do
220 f[k] = v
221 --@debug@
222 print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v))
223 end
224
225 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y)
226 f:SetSize(vars.width, vars.height)
227 f:Lower()
228 f.out:SetFont(db.font, db.fontsize, db.fontoutline)
229 if (db.current_channel == i) then
230 f.out.backdrop:SetTexture(unpack(db.frontdrop))
231 else
232 f.out.backdrop:SetTexture(unpack(db.backdrop))
233 end
234
235
236
237 f.Save = Console_Save
238 f.Minimize = Console_Minimize
239 f.Maximize = Console_Maximize
240 f.MinMax = Console_MinMax
241 f.ToFront = Console_ToFront
242 f.Toggle = D.Console_Toggle
243 f:SetScript('OnMouseDown', Console_MouseDown)
244 f:SetScript('OnMouseUp', Console_MouseUp)
245
246 if vars.minimized then
247 f:Minimize()
248 else
249 f:Maximize()
250 end
251 if db.enabled and f.enabled then
252 f:Show()
253 end
254
255 return f
256 end
257
258
259 --- Updates console information and returns the handle of the channel object that was worked on.
260 -- When key is nil or not a valid handle, a new channel is created using whatever signature can be found in cinfo.
261 -- The signature can be passed as a string, or as a table entry under the key 'signature'
262 -- If the signature of a new channel is also a tag, the channel will be added to that tag
263 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel
264 -- @param key string signature or index number of channel to operate on
265 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel
266 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4
267 function D:SetChannel(cinfo, key)
268 local db = self.db
269 local t_info = {}
270 local channel, isNew, id, sig, t_id
271 -- obtain source data
272 if tonumber(key) ~= nil and db.channels[key] then
273 id = tonumber(key)
274 elseif D.sigID[tostring(key)] then
275 id = D.sigID[tostring(key)]
276 else
277 id = db.primary_channel
278 isNew = true
279 end
280 local dbvars = db.channels[id]
281 t_id = id -- overridden later if new
282 t_info.index = t_id --
283 --@debug@
284 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@
285
286
287 -- obtain config info
288 if type(cinfo) == 'string' then
289 sig = cinfo
290 cinfo = {signature = sig}
291 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed
292 error('Expecting table of string as arg1')
293 elseif cinfo.signature then -- new sig
294 sig = cinfo.signature
295 elseif isNew then -- new channel sig
296 sig = 'Ch'
297 else -- old sig
298 sig = db.channels[id].signature
299 end
300 t_info.signature = sig
301 --@debug@
302 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@
303
304 for k,v in pairs(cinfo) do -- allow all cinfo to pass
305 t_info[k] = v
306 end
307
308 local blocked = { -- ignore these vars:
309 ['docked'] = true, -- table
310 ['dockedTo'] = true, -- table-related
311 ['signature'] = true} -- already determined
312 for k,v in pairs(dbvars) do
313 if not t_info[k] and not blocked[k] then -- already set or blocked?
314 t_info[k] = v
315 end
316 end
317 -- new channel overrides
318 if isNew then
319 if D.sigID[sig]then -- find a non-clashing signature
320 local result, i = sig, 1
321 while D.sigID[result] do
322 result = sig .. i
323 i = i + 1
324 end
325 t_info.signature = result
326 end
327 t_id = db.max_channel + 1
328 t_info.index = t_id
329 --@debug@
330 --print('setchan(3a) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@
331 else
332 --@debug@
333 --print('setchan(3b) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@
334 end
335
336 local channel
337 if not self.console[t_id] then -- create a frame
338 if isNew then -- position the channel frame
339 t_info.x = t_info.x + 20
340 t_info.y = t_info.y - 20
341 db.channels[t_id] = t_info
342 --@debug@
343 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@
344 end
345 channel = CreateConsole(t_id, t_info)
346 self.console[t_id] = channel
347 self.sig[t_info.signature] = channel
348 self.sigID[t_info.signature] = t_id
349 self.IDsig[t_id] = t_info.signature
350
351 end
352 channel = self.console[t_id]
353 if channel.minimized then
354 channel:Minimize()
355 else
356 channel:Maximize()
357 end
358
359 if channel.enabled and db.enabled then -- hide or show last since Min/Max mess with visibility
360 print('setchan(5a) enable')
361 channel:Show()
362 else
363 print('setchan(5a) disable')
364 channel:Hide()
365 end
366 --@debug@
367 --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@
368 return channel
369 end