Mercurial > wow > breuesk
comparison Core.lua @ 1:21c58930f74e
Refactoring
author | John@Yosemite-PC |
---|---|
date | Fri, 02 Mar 2012 22:32:12 -0500 |
parents | 47fac96968e1 |
children | 431ddc8bdb4a |
comparison
equal
deleted
inserted
replaced
0:47fac96968e1 | 1:21c58930f74e |
---|---|
1 -- ideas: last attended data and/or remove people who haven't attended in X days | 1 -- ideas: last attended data and/or remove people who haven't attended in X days |
2 -- and/or just a "remove from all lists" option | 2 -- and/or just a "remove from all lists" option |
3 | 3 |
4 | 4 |
5 -- order of implementation | 5 -- order of implementation |
6 -- ( ) lists fully functional (/script interface) | 6 -- (_) lists fully functional (/script interface) |
7 -- ( ) lists single-user functional via command line interface | 7 -- (_) lists single-user functional via command line interface |
8 -- ( ) all actions should reference the player list | |
8 -- ( ) single user + admin gui (manual suicides) | 9 -- ( ) single user + admin gui (manual suicides) |
9 -- ( ) single user + admin gui (master loot) | 10 -- ( ) single user + admin gui (master loot) |
10 -- ( ) communication and list trimming | 11 -- ( ) communication and list trimming |
11 -- ( ) admins | 12 -- ( ) admins |
12 -- ( ) players gui | 13 -- ( ) players gui |
13 -- ( ) crypto / protection against tampering | 14 -- ( ) crypto / protection against tampering |
14 -- ( ) alt tracking | 15 -- ( ) alt tracking |
15 -- ( ) reserves | 16 -- ( ) reserves |
16 | 17 |
17 -- important things to remember: | 18 -- important things to remember: |
18 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps | 19 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int |
20 -- indexing | |
19 -- 2) a.x === a["x"] | 21 -- 2) a.x === a["x"] |
20 -- 3) a["1"] =/= a[1] | 22 -- 3) a["1"] =/= a[1] |
21 | 23 |
22 bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0", "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0") | 24 bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0", "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0") |
23 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false) | 25 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false) |
31 self.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) | 33 self.options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) |
32 LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", self.options) | 34 LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", self.options) |
33 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk") | 35 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk") |
34 | 36 |
35 self:RegisterChatCommand("bsk", "HandleCommand") | 37 self:RegisterChatCommand("bsk", "HandleCommand") |
36 bsk:CreateWorkingStateFromChanges() | |
37 end | 38 end |
38 | 39 |
39 function bsk:OnEnable() | 40 function bsk:OnEnable() |
41 bsk:CreateWorkingStateFromChanges() | |
40 --self:HandleCommand() | 42 --self:HandleCommand() |
41 end | 43 end |
42 | 44 |
43 function bsk:HandleCommand(paramIn) | 45 function bsk:HandleCommand(paramIn) |
44 local param = { strsplit(" ", paramIn) } | 46 local param = { strsplit(" ", paramIn) } |
63 if param[3] == nil or param[3] == "" then | 65 if param[3] == nil or param[3] == "" then |
64 bsk:PrintTable(param) | 66 bsk:PrintTable(param) |
65 return | 67 return |
66 end | 68 end |
67 if param[2] == "player" then | 69 if param[2] == "player" then |
68 --if param[3] == "all" then | 70 if param[3] == "all" then |
69 -- bsk:Pop | 71 bsk:AddMissingPlayers() |
70 --else | 72 else |
71 local player = FixPlayerName(param[3]) | 73 local player = FixPlayerName(param[3]) |
72 bsk:AddPlayer(player) | 74 bsk:AddPlayer(player) |
73 --end | 75 end |
74 elseif param[2] == "list" then | 76 elseif param[2] == "list" then |
75 bsk:CreateList(param[3]) | 77 bsk:CreateList(param[3]) |
76 end | 78 end |
77 elseif param[1] == "suicide" then | 79 elseif param[1] == "suicide" then |
78 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then | 80 if param[2] == nil or param[2] == "" or param[3] == nil or param[3] == "" then |
88 return | 90 return |
89 end | 91 end |
90 bsk:PrintLists(param[2]) | 92 bsk:PrintLists(param[2]) |
91 end | 93 end |
92 | 94 |
93 -- TODO: add options | |
94 -- | |
95 -- for now: launch GUI | |
96 -- | |
97 | |
98 --if self.frame == nil then | 95 --if self.frame == nil then |
99 --self:CreateGUI() | 96 --self:CreateGUI() |
100 --self:ShowGUI() | 97 --self:ShowGUI() |
101 --else | 98 --else |
102 --self:ShowGUI() | 99 --self:ShowGUI() |
103 --end | 100 --end |
104 | 101 |
105 end | |
106 --MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)" | |
107 --function GetNamePattern(name) | |
108 -- local u = name:match(MULTIBYTE_FIRST_CHAR):upper() | |
109 | |
110 -- if not u or u:len() == 0 then Prat.Print("GetNamePattern: name error", name) return end | |
111 -- local l = u:lower() | |
112 -- local namepat | |
113 -- if u == l then | |
114 -- namepat = name:lower() | |
115 -- elseif u:len() == 1 then | |
116 -- namepat = "["..u..l.."]"..name:sub(2):lower() | |
117 -- elseif u:len() > 1 then | |
118 -- namepat = "" | |
119 -- for i=1,u:len() do | |
120 -- namepat = namepat .. "[" .. u:sub(i,i)..l:sub(i,i).."]" | |
121 -- end | |
122 -- namepat = namepat .. name:sub(u:len()+1) | |
123 -- end | |
124 -- return "%f[%a\192-\255]"..namepat.."%f[^%a\128-\255]" | |
125 --end | |
126 --AnyNamePattern = "%f[%a\192-\255]([%a\192-\255]+)%f[^%a\128-\255]" | |
127 | |
128 | |
129 function bsk:CreateGUI() | |
130 | |
131 -- Create a container frame | |
132 self.frame = AceGUI:Create("Frame") | |
133 self.frame:SetCallback("OnClose",function(widget) AceGUI:Release(widget) end) | |
134 self.frame:SetTitle("BSK") | |
135 self.frame:SetLayout("Flow") | |
136 self.frame:SetHeight(700) | |
137 self.frame:SetWidth(350) | |
138 local tab = AceGUI:Create("TabGroup") | |
139 tab:SetLayout("Flow") | |
140 tab:SetTabs( | |
141 { | |
142 { | |
143 text="Tab 1", | |
144 value="tab1" | |
145 }, | |
146 | |
147 { | |
148 text="Tab 2", | |
149 value="tab2" | |
150 }, | |
151 { | |
152 text="Tab 3", | |
153 value="tab3" | |
154 }, | |
155 { | |
156 text="Tab 4", | |
157 value="tab4" | |
158 } | |
159 } | |
160 ) | |
161 tab.width = "fill" | |
162 tab.height = "fill" | |
163 | |
164 tab:SetCallback("OnGroupSelected",ChangeTab) | |
165 tab:SelectTab("tab1") | |
166 self.frame:AddChild(tab) | |
167 | |
168 -- Create a button | |
169 --local btn = AceGUI:Create("Button") | |
170 --btn:SetWidth(170) | |
171 --btn:SetText("Button !") | |
172 --btn:SetCallback("OnClick", function() print("Click!") end) | |
173 -- Add the button to the container | |
174 --self.frame:AddChild(btn) | |
175 end | 102 end |
176 | 103 |
177 bsk.defaults = { | 104 bsk.defaults = { |
178 profile = { | 105 profile = { |
179 players = {}, | 106 players = {}, |
180 changes = {}, | 107 changes = {}, |
181 listBase = {} | 108 listBase = {} |
182 } | 109 } |
183 } | 110 } |
184 | 111 |
185 bsk.options = { | |
186 name= 'bsk', | |
187 type = 'group', | |
188 args = | |
189 { | |
190 version = | |
191 { | |
192 type = "execute", | |
193 name = "Version query", | |
194 desc = "Check others' versions", | |
195 func = function(self) self:Print("TODO") end | |
196 } | |
197 } | |
198 } | |
199 function ChangeTab(container, event, group) | |
200 container:ReleaseChildren() | |
201 if group == "tab2" then | |
202 local desc = AceGUI:Create("Label") | |
203 desc:SetText("This is Tab 1") | |
204 desc:SetFullWidth(true) | |
205 container:AddChild(desc) | |
206 | 112 |
207 local button = AceGUI:Create("Button") | |
208 button:SetText("Tab 1 Button") | |
209 button:SetWidth(200) | |
210 container:AddChild(button) | |
211 elseif group == "tab1" then | |
212 local item2 = {string="item2!", color = {r=1,g=0,b=0.5} } | |
213 local itemList = {"Item1", item2, "Item3", "Item4"} | |
214 | |
215 local myMultiSelect = AceGUI:Create("MultiSelect") | |
216 myMultiSelect:SetLabel("My Multi Select") | |
217 myMultiSelect:SetWidth(200) | |
218 myMultiSelect:SetHeight(400) | |
219 myMultiSelect:SetItemList(itemList) | |
220 myMultiSelect:SetMultiSelect(false) | |
221 container:AddChild(myMultiSelect) | |
222 end | |
223 end | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 --[[---------------------------------- | |
236 -- MultiSelect widget for AceGUI-3.0 | |
237 -- Written by Shirokuma | |
238 --]]---------------------------------- | |
239 | |
240 | |
241 --[[----------------- | |
242 -- AceGUI | |
243 --]]----------------- | |
244 --local AceGUI = LibStub("AceGUI-3.0") | |
245 | |
246 --[[----------------- | |
247 -- Lua APIs | |
248 --]]----------------- | |
249 local format, pairs, tostring = string.format, pairs, tostring | |
250 | |
251 --[[----------------- | |
252 -- WoW APIs | |
253 --]]----------------- | |
254 local CreateFrame, UIParent = CreateFrame, UIParent | |
255 | |
256 --[[----------------- | |
257 -- Frame Elements | |
258 --]]----------------- | |
259 local FrameBackdrop = { | |
260 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", | |
261 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", | |
262 tile = true, tileSize = 16, edgeSize = 16, | |
263 insets = { left = 3, right = 3, top = 3, bottom = 3 } | |
264 } | |
265 | |
266 | |
267 --[[----------------- | |
268 -- Widget Info | |
269 --]]----------------- | |
270 local widgetType = "MultiSelect" | |
271 local widgetVersion = 1 | |
272 | |
273 | |
274 --[[----------------- | |
275 -- Event Code | |
276 --]]----------------- | |
277 local function Label_OnEnter(label) | |
278 local self = label.obj | |
279 local value = label | |
280 self:Fire("OnLabelEnter", value) | |
281 end | |
282 | |
283 local function Label_OnLeave(label) | |
284 local self = label.obj | |
285 local value = label | |
286 self:Fire("OnLabelEnter", value) | |
287 end | |
288 | |
289 local function Label_OnClick(label) | |
290 local self = label.obj | |
291 local value = label | |
292 self:Fire("OnLabelClick", value) | |
293 AceGUI:ClearFocus() | |
294 end | |
295 | |
296 | |
297 --[[----------------- | |
298 -- MultiSelect Code | |
299 --]]----------------- | |
300 do | |
301 local function OnAcquire(self) -- set up the default size | |
302 self:SetWidth(200) | |
303 self:SetHeight(400) | |
304 end | |
305 | |
306 local function SetWidth(self, w) -- override the SetWidth function to include the labelframe | |
307 self.frame:SetWidth(w) | |
308 self.labelframe:SetWidth(w-33) | |
309 end | |
310 | |
311 local function SetLabel(self, text) -- sets the multiselect label text | |
312 self.label:SetText(text) | |
313 end | |
314 | |
315 local function SetMultiSelect(self, value) -- set if multiple values can be selected simultaneously | |
316 self.multiselect = value | |
317 end | |
318 | |
319 local function AddItem(self, str, color) -- add an item (create a new item label object) | |
320 local color = color | |
321 local label = CreateFrame("Button", nil, self.labelframe) | |
322 label.selected = false | |
323 label.obj = self | |
324 label:SetHeight(18) | |
325 label:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, -(getn(self.labels) * 18)) | |
326 label:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0, -(getn(self.labels) * 18)) | |
327 self.labels[getn(self.labels) + 1] = label | |
328 self.labelframe:SetHeight(getn(self.labels) * 18) | |
329 | |
330 local text = label:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") | |
331 text:SetJustifyH("LEFT") | |
332 text:SetPoint("TOPLEFT",label,"TOPLEFT",5,0) | |
333 text:SetPoint("BOTTOMRIGHT",label,"BOTTOMRIGHT",-5,0) | |
334 if color ~= nil then | |
335 text:SetTextColor(color.r,color.g,color.b) | |
336 end | |
337 text:SetText(str) | |
338 label.text = text | |
339 | |
340 local highlight = label:CreateTexture(nil, "OVERLAY") | |
341 highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") | |
342 highlight:SetBlendMode("ADD") | |
343 highlight:SetHeight(14) | |
344 highlight:ClearAllPoints() | |
345 highlight:SetPoint("RIGHT",label,"RIGHT",0,0) | |
346 highlight:SetPoint("LEFT",label,"LEFT",0,0) | |
347 highlight:Hide() | |
348 label.highlight = highlight | |
349 | |
350 label:SetScript("OnEnter", function(this) | |
351 this.highlight:Show() | |
352 Label_OnEnter(this) | |
353 end) | |
354 label:SetScript("OnLeave", function(this) | |
355 if not this.selected then | |
356 this.highlight:Hide() | |
357 end | |
358 end) | |
359 label:SetScript("OnClick", function(this) | |
360 if not this.selected then | |
361 this.selected = true | |
362 if not self.multiselect then | |
363 for index, items in pairs(self.labels) do | |
364 if self.labels[index] ~= this and self.labels[index].selected then | |
365 self.labels[index].selected = false | |
366 self.labels[index].highlight:Hide() | |
367 end | |
368 end | |
369 end | |
370 else | |
371 this.selected = false | |
372 end | |
373 Label_OnClick(this) | |
374 end) | |
375 end | |
376 | |
377 local function GetItem(self, text) -- find an object based on the text parameter | |
378 for _, value in pairs(self.labels) do | |
379 if value.text:GetText() == text then | |
380 return value | |
381 end | |
382 end | |
383 return nil | |
384 end | |
385 | |
386 local function GetText(self, value) -- get the text of a label object | |
387 for _,item in pairs(self.labels) do | |
388 if value == item then | |
389 return item.text:GetText() | |
390 end | |
391 end | |
392 return nil | |
393 end | |
394 | |
395 local function SetText(self, value, text) -- set the text of a label object | |
396 for _, item in pairs(self.labels) do | |
397 if value == item then | |
398 value.text:SetText(text) | |
399 end | |
400 end | |
401 end | |
402 | |
403 local function IsSelected(self, value) -- return if the label object is currently selected | |
404 for _, item in pairs(self.labels) do | |
405 if value == item then | |
406 return item.selected | |
407 end | |
408 end | |
409 return nil | |
410 end | |
411 | |
412 local function GetSelected(self) -- return a table of the currently selected label objects | |
413 local selectedList = {} | |
414 for _, item in pairs(self.labels) do | |
415 if item.selected then | |
416 table.insert(selectedList, item) | |
417 end | |
418 end | |
419 return selectedList | |
420 end | |
421 | |
422 local function SetItemList(self, list) -- create new labels from a list of strings | |
423 for _,item in pairs(self.labels) do | |
424 item:Hide() | |
425 item:ClearAllPoints() | |
426 end | |
427 | |
428 self.labels = {} | |
429 | |
430 if list then | |
431 for _,item in pairs(list) do | |
432 if type(item) == "string" then | |
433 self:AddItem(item) | |
434 elseif type(item) == "table" then | |
435 if item.string ~= nil and type(item.string) == "string" then | |
436 if item.color ~= nil then | |
437 if type(item.color) == "table" and item.color.r ~= nil and item.color.g ~= nil and item.color.b ~= nil then | |
438 self:AddItem(item.string, item.color) | |
439 else | |
440 assert(false and "setitemlist: item.color is set, but nonsense") | |
441 end | |
442 else | |
443 self:AddItem(item.string) | |
444 end | |
445 else | |
446 assert( false and "setitemlist: item is table without .string member") | |
447 end | |
448 else | |
449 assert(false and "SetItemList: nonsense list entry") | |
450 end | |
451 end | |
452 end | |
453 end | |
454 | |
455 local function RemoveItem(self, item) -- delete an item | |
456 local function RedrawFrame() | |
457 for index,value in pairs(self.labels) do | |
458 value:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, (-(index-1) * 18)) | |
459 value:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0,(-(index-1) * 18)) | |
460 end | |
461 end | |
462 | |
463 for index, value in pairs(self.labels) do | |
464 if value == item then | |
465 table.remove(self.labels, index) | |
466 item:Hide() | |
467 item:ClearAllPoints() | |
468 RedrawFrame() | |
469 end | |
470 end | |
471 end | |
472 | |
473 local function SetSelected(self, item, value) | |
474 if value then | |
475 if not self.multiselect then -- test | |
476 for _, value in pairs(self.labels) do | |
477 value.selected = false | |
478 value.highlight:Hide() | |
479 end | |
480 end | |
481 item.selected = true | |
482 item.highlight:Show() | |
483 else | |
484 item.selected = false | |
485 item.highlight:Hide() | |
486 end | |
487 end | |
488 | |
489 local function Constructor() -- widget constructor | |
490 local frame = CreateFrame("Frame", nil, UIParent) | |
491 local backdrop = CreateFrame("Frame", nil, frame) | |
492 local self = {} | |
493 local labels = {} | |
494 | |
495 self.type = widgetType | |
496 self.frame = frame | |
497 self.backdrop = backdrop | |
498 self.labels = {} | |
499 self.multiselect = true | |
500 frame.obj = self | |
501 | |
502 local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") | |
503 label:SetJustifyH("LEFT") | |
504 label:SetPoint("TOPLEFT", 5, 0) | |
505 label:SetPoint("TOPRIGHT", -5, 0) | |
506 label:SetHeight(14) | |
507 label:SetText("MultiSelect") | |
508 self.label = label | |
509 | |
510 backdrop:SetBackdrop(FrameBackdrop) | |
511 backdrop:SetBackdropColor(0, 0, 0) | |
512 backdrop:SetBackdropBorderColor(0.4, 0.4, 0.4) | |
513 backdrop:SetPoint("TOPLEFT", frame, "TOPLEFT", 5, -14) | |
514 backdrop:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -5, 0) | |
515 | |
516 local scrollframe = CreateFrame("ScrollFrame", format("%s@%s@%s", widgetType, "ScrollFrame", tostring(self)), frame, "UIPanelScrollFrameTemplate") | |
517 scrollframe:SetPoint("TOPLEFT", backdrop, "TOPLEFT", 5, -6) | |
518 scrollframe:SetPoint("BOTTOMRIGHT", backdrop, "BOTTOMRIGHT", -28, 6) | |
519 scrollframe.obj = self | |
520 self.scrollframe = scrollframe | |
521 | |
522 local labelframe = CreateFrame("Frame", nil, scrollframe) | |
523 labelframe:SetAllPoints() | |
524 labelframe.obj = self | |
525 scrollframe:SetScrollChild(labelframe) | |
526 self.labelframe = labelframe | |
527 | |
528 -- method listing | |
529 self.OnAcquire = OnAcquire | |
530 self.SetLabel = SetLabel | |
531 self.AddItem = AddItem | |
532 self.SetWidth = SetWidth | |
533 self.SetMultiSelect = SetMultiSelect | |
534 self.SetItemList = SetItemList | |
535 self.GetItem = GetItem | |
536 self.RemoveItem = RemoveItem | |
537 self.GetText = GetText | |
538 self.SetText = SetText | |
539 self.IsSelected = IsSelected | |
540 self.GetSelected = GetSelected | |
541 self.SetSelected = SetSelected | |
542 | |
543 AceGUI:RegisterAsWidget(self) | |
544 return self | |
545 end | |
546 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) | |
547 end | |
548 |