# HG changeset patch # User John@Yosemite-PC # Date 1330745532 18000 # Node ID 21c58930f74e6090b8056e4c0efb6a6ce9745c25 # Parent 47fac96968e150a433fa2d6a3bdae068e87f0793 Refactoring diff -r 47fac96968e1 -r 21c58930f74e Core.lua --- a/Core.lua Fri Mar 02 00:15:09 2012 -0500 +++ b/Core.lua Fri Mar 02 22:32:12 2012 -0500 @@ -3,8 +3,9 @@ -- order of implementation --- ( ) lists fully functional (/script interface) --- ( ) lists single-user functional via command line interface +-- (_) lists fully functional (/script interface) +-- (_) lists single-user functional via command line interface +-- ( ) all actions should reference the player list -- ( ) single user + admin gui (manual suicides) -- ( ) single user + admin gui (master loot) -- ( ) communication and list trimming @@ -15,7 +16,8 @@ -- ( ) reserves -- important things to remember: --- 1) ipairs iterates from 1 until the first missing int index -> no gaps +-- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int +-- indexing -- 2) a.x === a["x"] -- 3) a["1"] =/= a[1] @@ -33,10 +35,10 @@ self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk") self:RegisterChatCommand("bsk", "HandleCommand") - bsk:CreateWorkingStateFromChanges() end function bsk:OnEnable() + bsk:CreateWorkingStateFromChanges() --self:HandleCommand() end @@ -65,12 +67,12 @@ return end if param[2] == "player" then - --if param[3] == "all" then - -- bsk:Pop - --else + if param[3] == "all" then + bsk:AddMissingPlayers() + else local player = FixPlayerName(param[3]) bsk:AddPlayer(player) - --end + end elseif param[2] == "list" then bsk:CreateList(param[3]) end @@ -90,11 +92,6 @@ bsk:PrintLists(param[2]) end - -- TODO: add options - -- - -- for now: launch GUI - -- - --if self.frame == nil then --self:CreateGUI() --self:ShowGUI() @@ -103,76 +100,6 @@ --end end ---MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)" ---function GetNamePattern(name) --- local u = name:match(MULTIBYTE_FIRST_CHAR):upper() - --- if not u or u:len() == 0 then Prat.Print("GetNamePattern: name error", name) return end --- local l = u:lower() --- local namepat --- if u == l then --- namepat = name:lower() --- elseif u:len() == 1 then --- namepat = "["..u..l.."]"..name:sub(2):lower() --- elseif u:len() > 1 then --- namepat = "" --- for i=1,u:len() do --- namepat = namepat .. "[" .. u:sub(i,i)..l:sub(i,i).."]" --- end --- namepat = namepat .. name:sub(u:len()+1) --- end --- return "%f[%a\192-\255]"..namepat.."%f[^%a\128-\255]" ---end ---AnyNamePattern = "%f[%a\192-\255]([%a\192-\255]+)%f[^%a\128-\255]" - - -function bsk:CreateGUI() - - -- Create a container frame - self.frame = AceGUI:Create("Frame") - self.frame:SetCallback("OnClose",function(widget) AceGUI:Release(widget) end) - self.frame:SetTitle("BSK") - self.frame:SetLayout("Flow") - self.frame:SetHeight(700) - self.frame:SetWidth(350) - local tab = AceGUI:Create("TabGroup") - tab:SetLayout("Flow") - tab:SetTabs( - { - { - text="Tab 1", - value="tab1" - }, - - { - text="Tab 2", - value="tab2" - }, - { - text="Tab 3", - value="tab3" - }, - { - text="Tab 4", - value="tab4" - } - } - ) - tab.width = "fill" - tab.height = "fill" - - tab:SetCallback("OnGroupSelected",ChangeTab) - tab:SelectTab("tab1") - self.frame:AddChild(tab) - - -- Create a button - --local btn = AceGUI:Create("Button") - --btn:SetWidth(170) - --btn:SetText("Button !") - --btn:SetCallback("OnClick", function() print("Click!") end) - -- Add the button to the container - --self.frame:AddChild(btn) -end bsk.defaults = { profile = { @@ -182,367 +109,4 @@ } } -bsk.options = { - name= 'bsk', - type = 'group', - args = - { - version = - { - type = "execute", - name = "Version query", - desc = "Check others' versions", - func = function(self) self:Print("TODO") end - } - } -} -function ChangeTab(container, event, group) - container:ReleaseChildren() - if group == "tab2" then - local desc = AceGUI:Create("Label") - desc:SetText("This is Tab 1") - desc:SetFullWidth(true) - container:AddChild(desc) - local button = AceGUI:Create("Button") - button:SetText("Tab 1 Button") - button:SetWidth(200) - container:AddChild(button) - elseif group == "tab1" then - local item2 = {string="item2!", color = {r=1,g=0,b=0.5} } - local itemList = {"Item1", item2, "Item3", "Item4"} - - local myMultiSelect = AceGUI:Create("MultiSelect") - myMultiSelect:SetLabel("My Multi Select") - myMultiSelect:SetWidth(200) - myMultiSelect:SetHeight(400) - myMultiSelect:SetItemList(itemList) - myMultiSelect:SetMultiSelect(false) - container:AddChild(myMultiSelect) - end -end - - - - - - - - - - - ---[[---------------------------------- --- MultiSelect widget for AceGUI-3.0 --- Written by Shirokuma ---]]---------------------------------- - - ---[[----------------- --- AceGUI ---]]----------------- ---local AceGUI = LibStub("AceGUI-3.0") - ---[[----------------- --- Lua APIs ---]]----------------- -local format, pairs, tostring = string.format, pairs, tostring - ---[[----------------- --- WoW APIs ---]]----------------- -local CreateFrame, UIParent = CreateFrame, UIParent - ---[[----------------- --- Frame Elements ---]]----------------- -local FrameBackdrop = { - bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - tile = true, tileSize = 16, edgeSize = 16, - insets = { left = 3, right = 3, top = 3, bottom = 3 } -} - - ---[[----------------- --- Widget Info ---]]----------------- -local widgetType = "MultiSelect" -local widgetVersion = 1 - - ---[[----------------- --- Event Code ---]]----------------- -local function Label_OnEnter(label) - local self = label.obj - local value = label - self:Fire("OnLabelEnter", value) -end - -local function Label_OnLeave(label) - local self = label.obj - local value = label - self:Fire("OnLabelEnter", value) -end - -local function Label_OnClick(label) - local self = label.obj - local value = label - self:Fire("OnLabelClick", value) - AceGUI:ClearFocus() -end - - ---[[----------------- --- MultiSelect Code ---]]----------------- -do - local function OnAcquire(self) -- set up the default size - self:SetWidth(200) - self:SetHeight(400) - end - - local function SetWidth(self, w) -- override the SetWidth function to include the labelframe - self.frame:SetWidth(w) - self.labelframe:SetWidth(w-33) - end - - local function SetLabel(self, text) -- sets the multiselect label text - self.label:SetText(text) - end - - local function SetMultiSelect(self, value) -- set if multiple values can be selected simultaneously - self.multiselect = value - end - - local function AddItem(self, str, color) -- add an item (create a new item label object) - local color = color - local label = CreateFrame("Button", nil, self.labelframe) - label.selected = false - label.obj = self - label:SetHeight(18) - label:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, -(getn(self.labels) * 18)) - label:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0, -(getn(self.labels) * 18)) - self.labels[getn(self.labels) + 1] = label - self.labelframe:SetHeight(getn(self.labels) * 18) - - local text = label:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") - text:SetJustifyH("LEFT") - text:SetPoint("TOPLEFT",label,"TOPLEFT",5,0) - text:SetPoint("BOTTOMRIGHT",label,"BOTTOMRIGHT",-5,0) - if color ~= nil then - text:SetTextColor(color.r,color.g,color.b) - end - text:SetText(str) - label.text = text - - local highlight = label:CreateTexture(nil, "OVERLAY") - highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") - highlight:SetBlendMode("ADD") - highlight:SetHeight(14) - highlight:ClearAllPoints() - highlight:SetPoint("RIGHT",label,"RIGHT",0,0) - highlight:SetPoint("LEFT",label,"LEFT",0,0) - highlight:Hide() - label.highlight = highlight - - label:SetScript("OnEnter", function(this) - this.highlight:Show() - Label_OnEnter(this) - end) - label:SetScript("OnLeave", function(this) - if not this.selected then - this.highlight:Hide() - end - end) - label:SetScript("OnClick", function(this) - if not this.selected then - this.selected = true - if not self.multiselect then - for index, items in pairs(self.labels) do - if self.labels[index] ~= this and self.labels[index].selected then - self.labels[index].selected = false - self.labels[index].highlight:Hide() - end - end - end - else - this.selected = false - end - Label_OnClick(this) - end) - end - - local function GetItem(self, text) -- find an object based on the text parameter - for _, value in pairs(self.labels) do - if value.text:GetText() == text then - return value - end - end - return nil - end - - local function GetText(self, value) -- get the text of a label object - for _,item in pairs(self.labels) do - if value == item then - return item.text:GetText() - end - end - return nil - end - - local function SetText(self, value, text) -- set the text of a label object - for _, item in pairs(self.labels) do - if value == item then - value.text:SetText(text) - end - end - end - - local function IsSelected(self, value) -- return if the label object is currently selected - for _, item in pairs(self.labels) do - if value == item then - return item.selected - end - end - return nil - end - - local function GetSelected(self) -- return a table of the currently selected label objects - local selectedList = {} - for _, item in pairs(self.labels) do - if item.selected then - table.insert(selectedList, item) - end - end - return selectedList - end - - local function SetItemList(self, list) -- create new labels from a list of strings - for _,item in pairs(self.labels) do - item:Hide() - item:ClearAllPoints() - end - - self.labels = {} - - if list then - for _,item in pairs(list) do - if type(item) == "string" then - self:AddItem(item) - elseif type(item) == "table" then - if item.string ~= nil and type(item.string) == "string" then - if item.color ~= nil then - if type(item.color) == "table" and item.color.r ~= nil and item.color.g ~= nil and item.color.b ~= nil then - self:AddItem(item.string, item.color) - else - assert(false and "setitemlist: item.color is set, but nonsense") - end - else - self:AddItem(item.string) - end - else - assert( false and "setitemlist: item is table without .string member") - end - else - assert(false and "SetItemList: nonsense list entry") - end - end - end - end - - local function RemoveItem(self, item) -- delete an item - local function RedrawFrame() - for index,value in pairs(self.labels) do - value:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, (-(index-1) * 18)) - value:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0,(-(index-1) * 18)) - end - end - - for index, value in pairs(self.labels) do - if value == item then - table.remove(self.labels, index) - item:Hide() - item:ClearAllPoints() - RedrawFrame() - end - end - end - - local function SetSelected(self, item, value) - if value then - if not self.multiselect then -- test - for _, value in pairs(self.labels) do - value.selected = false - value.highlight:Hide() - end - end - item.selected = true - item.highlight:Show() - else - item.selected = false - item.highlight:Hide() - end - end - - local function Constructor() -- widget constructor - local frame = CreateFrame("Frame", nil, UIParent) - local backdrop = CreateFrame("Frame", nil, frame) - local self = {} - local labels = {} - - self.type = widgetType - self.frame = frame - self.backdrop = backdrop - self.labels = {} - self.multiselect = true - frame.obj = self - - local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") - label:SetJustifyH("LEFT") - label:SetPoint("TOPLEFT", 5, 0) - label:SetPoint("TOPRIGHT", -5, 0) - label:SetHeight(14) - label:SetText("MultiSelect") - self.label = label - - backdrop:SetBackdrop(FrameBackdrop) - backdrop:SetBackdropColor(0, 0, 0) - backdrop:SetBackdropBorderColor(0.4, 0.4, 0.4) - backdrop:SetPoint("TOPLEFT", frame, "TOPLEFT", 5, -14) - backdrop:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -5, 0) - - local scrollframe = CreateFrame("ScrollFrame", format("%s@%s@%s", widgetType, "ScrollFrame", tostring(self)), frame, "UIPanelScrollFrameTemplate") - scrollframe:SetPoint("TOPLEFT", backdrop, "TOPLEFT", 5, -6) - scrollframe:SetPoint("BOTTOMRIGHT", backdrop, "BOTTOMRIGHT", -28, 6) - scrollframe.obj = self - self.scrollframe = scrollframe - - local labelframe = CreateFrame("Frame", nil, scrollframe) - labelframe:SetAllPoints() - labelframe.obj = self - scrollframe:SetScrollChild(labelframe) - self.labelframe = labelframe - - -- method listing - self.OnAcquire = OnAcquire - self.SetLabel = SetLabel - self.AddItem = AddItem - self.SetWidth = SetWidth - self.SetMultiSelect = SetMultiSelect - self.SetItemList = SetItemList - self.GetItem = GetItem - self.RemoveItem = RemoveItem - self.GetText = GetText - self.SetText = SetText - self.IsSelected = IsSelected - self.GetSelected = GetSelected - self.SetSelected = SetSelected - - AceGUI:RegisterAsWidget(self) - return self - end - AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) -end - diff -r 47fac96968e1 -r 21c58930f74e Gui.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Gui.lua Fri Mar 02 22:32:12 2012 -0500 @@ -0,0 +1,76 @@ + +local ChangeTab = function(container, event, group) + container:ReleaseChildren() + if group == "tab2" then + local desc = AceGUI:Create("Label") + desc:SetText("This is Tab 1") + desc:SetFullWidth(true) + container:AddChild(desc) + + local button = AceGUI:Create("Button") + button:SetText("Tab 1 Button") + button:SetWidth(200) + container:AddChild(button) + elseif group == "tab1" then + local item2 = {string="item2!", color = {r=1,g=0,b=0.5} } + local itemList = {"Item1", item2, "Item3", "Item4"} + + local myMultiSelect = AceGUI:Create("MultiSelect") + myMultiSelect:SetLabel("My Multi Select") + myMultiSelect:SetWidth(200) + myMultiSelect:SetHeight(400) + myMultiSelect:SetItemList(itemList) + myMultiSelect:SetMultiSelect(false) + container:AddChild(myMultiSelect) + end +end + +function bsk:CreateGUI() + + -- Create a container frame + self.frame = AceGUI:Create("Frame") + self.frame:SetCallback("OnClose",function(widget) AceGUI:Release(widget) end) + self.frame:SetTitle("BSK") + self.frame:SetLayout("Flow") + self.frame:SetHeight(700) + self.frame:SetWidth(350) + local tab = AceGUI:Create("TabGroup") + tab:SetLayout("Flow") + tab:SetTabs( + { + { + text="Tab 1", + value="tab1" + }, + + { + text="Tab 2", + value="tab2" + }, + { + text="Tab 3", + value="tab3" + }, + { + text="Tab 4", + value="tab4" + } + } + ) + tab.width = "fill" + tab.height = "fill" + + tab:SetCallback("OnGroupSelected",ChangeTab) + tab:SelectTab("tab1") + self.frame:AddChild(tab) + + -- Create a button + --local btn = AceGUI:Create("Button") + --btn:SetWidth(170) + --btn:SetText("Button !") + --btn:SetCallback("OnClick", function() print("Click!") end) + -- Add the button to the container + --self.frame:AddChild(btn) +end + + diff -r 47fac96968e1 -r 21c58930f74e Lists.lua --- a/Lists.lua Fri Mar 02 00:15:09 2012 -0500 +++ b/Lists.lua Fri Mar 02 22:32:12 2012 -0500 @@ -38,6 +38,16 @@ return setmetatable(u, getmetatable(t)) end +-- Debugging {{{ +function bsk:PrintLists() + bsk:PrintTable(bsk.lists) +end +function bsk:PrintChanges() + bsk:PrintTable(bsk.db.profile.changes) +end +function bsk:PrintPlayers() + bsk:PrintTable(bsk.players) +end function bsk:PrintTable(table, depth) depth = depth or "" if not table then return end @@ -57,16 +67,6 @@ end end --- Debugging {{{ -function bsk:PrintLists() - bsk:PrintTable(bsk.lists) -end -function bsk:PrintChanges() - bsk:PrintTable(bsk.db.profile.changes) -end -function bsk:PrintPlayers() - bsk:PrintTable(bsk.players) -end --}}} function bsk:CreateWorkingStateFromChanges() @@ -159,7 +159,7 @@ end end - +-- Action and DoAction defs {{{ -- -- The actual actions for changes start here -- @@ -214,10 +214,6 @@ end end -function bsk:CreateFakeLists() - -- testing only -end - function bsk:DoCreateList(change) -- TODO: this segment will probably be useful as bsk:SearchForListByName local lists = bsk.lists @@ -276,27 +272,6 @@ -- from both players and lists end -function bsk:GetSuicideList(name,list) - --self:Print("Calculating changeset for "..name.." from list -") - --self:PrintTable(list) - local t = {} - local ret = {} - local pushing = false - for i = 1, #list do - if list[i] == name then - pushing = true - end - if pushing and (RaidList[list[i]] or ReserveList[list[i]]) then - tinsert(ret,list[i]) - end - end - return ret -end - -function bsk:GetActiveList() - return bsk.lists[1] -- todo! -end - function bsk:DoSuicidePlayer(change) local listIndex = change.arg.listIndex local list = bsk.lists[listIndex] @@ -324,16 +299,52 @@ function bsk:SuicidePlayer(name,list) -- require admin - local l=bsk:GetActiveList() bsk:PopulateRaidList() - local slist=bsk:GetSuicideList(name,l) local listIndex = bsk:GetListIndex(list) + local slist=bsk:GetSuicideList(name,bsk.lists[listIndex]) local change = {action="SuicidePlayer",arg={names=names,list=slist,listIndex=listIndex}} bsk:StartChange(change) if bsk:DoSuicidePlayer(change) then bsk:CommitChange(change) end end +--}}} +-- Higher order actions (ie calls other Doers){{{ +function bsk:AddMissingPlayers() + bsk:PopulateRaidList() + local t = {} + for i,v in pairs(bsk.players) do + t[v] = true + end + for i,v in pairs(RaidList) do + if t[v] == nil then + bsk:Print(sformat("Player % is missing from the players list - adding",v)) + bsk:AddPlayer(v) + end + end + -- TODO: batch into a single op - no need to spam 25 messages in a row +end +--}}} + +-- "Soft" actions- ie things that cause nonpermanent state {{{ + +-- reserves +function bsk:AddReserve(name) + ReserveList[name]=true + -- TODO: communicate to others. don't store this in any way. +end + +function bsk:RemoveReserve(name) + ReserveList[name]=false + -- TODO: communicate to others. don't store this in any way. +end + + +--function bsk:GetActiveList() +-- return bsk.lists[1] -- todo! +--end + +--}}} -- The following code is from Xinhuan (wowace forum member) -- Pre-create the unitID strings we will use @@ -375,25 +386,23 @@ -- prevent proper undo, such as add/delete player or add/delete list - - --- reserves -function bsk:AddReserve(name) - ReserveList[name]=true - -- TODO: communicate to others. don't store this in any way. +function bsk:GetSuicideList(name,list) + --self:Print("Calculating changeset for "..name.." from list -") + --self:PrintTable(list) + local t = {} + local ret = {} + local pushing = false + for i = 1, #list do + if list[i] == name then + pushing = true + end + if pushing and (RaidList[list[i]] or ReserveList[list[i]]) then + tinsert(ret,list[i]) + end + end + return ret end -function bsk:RemoveReserve(name) - ReserveList[name]=false - -- TODO: communicate to others. don't store this in any way. -end - - - - - - - -- Support functions @@ -406,3 +415,4 @@ end assert(false) end + diff -r 47fac96968e1 -r 21c58930f74e MultiSelectWidget.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MultiSelectWidget.lua Fri Mar 02 22:32:12 2012 -0500 @@ -0,0 +1,316 @@ + + +--[[---------------------------------- +-- MultiSelect widget for AceGUI-3.0 +-- Written by Shirokuma +--]]---------------------------------- + + +--[[----------------- +-- AceGUI +--]]----------------- +local AceGUI = LibStub("AceGUI-3.0") + +--[[----------------- +-- Lua APIs +--]]----------------- +local format, pairs, tostring = string.format, pairs, tostring + +--[[----------------- +-- WoW APIs +--]]----------------- +local CreateFrame, UIParent = CreateFrame, UIParent + +--[[----------------- +-- Frame Elements +--]]----------------- +local FrameBackdrop = { + bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + tile = true, tileSize = 16, edgeSize = 16, + insets = { left = 3, right = 3, top = 3, bottom = 3 } +} + + +--[[----------------- +-- Widget Info +--]]----------------- +local widgetType = "MultiSelect" +local widgetVersion = 1 + + +--[[----------------- +-- Event Code +--]]----------------- +local function Label_OnEnter(label) + local self = label.obj + local value = label + self:Fire("OnLabelEnter", value) +end + +local function Label_OnLeave(label) + local self = label.obj + local value = label + self:Fire("OnLabelEnter", value) +end + +local function Label_OnClick(label) + local self = label.obj + local value = label + self:Fire("OnLabelClick", value) + AceGUI:ClearFocus() +end + + +--[[----------------- +-- MultiSelect Code +--]]----------------- +do + local function OnAcquire(self) -- set up the default size + self:SetWidth(200) + self:SetHeight(400) + end + + local function SetWidth(self, w) -- override the SetWidth function to include the labelframe + self.frame:SetWidth(w) + self.labelframe:SetWidth(w-33) + end + + local function SetLabel(self, text) -- sets the multiselect label text + self.label:SetText(text) + end + + local function SetMultiSelect(self, value) -- set if multiple values can be selected simultaneously + self.multiselect = value + end + + local function AddItem(self, str, color) -- add an item (create a new item label object) + local color = color + local label = CreateFrame("Button", nil, self.labelframe) + label.selected = false + label.obj = self + label:SetHeight(18) + label:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, -(getn(self.labels) * 18)) + label:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0, -(getn(self.labels) * 18)) + self.labels[getn(self.labels) + 1] = label + self.labelframe:SetHeight(getn(self.labels) * 18) + + local text = label:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") + text:SetJustifyH("LEFT") + text:SetPoint("TOPLEFT",label,"TOPLEFT",5,0) + text:SetPoint("BOTTOMRIGHT",label,"BOTTOMRIGHT",-5,0) + if color ~= nil then + text:SetTextColor(color.r,color.g,color.b) + end + text:SetText(str) + label.text = text + + local highlight = label:CreateTexture(nil, "OVERLAY") + highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") + highlight:SetBlendMode("ADD") + highlight:SetHeight(14) + highlight:ClearAllPoints() + highlight:SetPoint("RIGHT",label,"RIGHT",0,0) + highlight:SetPoint("LEFT",label,"LEFT",0,0) + highlight:Hide() + label.highlight = highlight + + label:SetScript("OnEnter", function(this) + this.highlight:Show() + Label_OnEnter(this) + end) + label:SetScript("OnLeave", function(this) + if not this.selected then + this.highlight:Hide() + end + end) + label:SetScript("OnClick", function(this) + if not this.selected then + this.selected = true + if not self.multiselect then + for index, items in pairs(self.labels) do + if self.labels[index] ~= this and self.labels[index].selected then + self.labels[index].selected = false + self.labels[index].highlight:Hide() + end + end + end + else + this.selected = false + end + Label_OnClick(this) + end) + end + + local function GetItem(self, text) -- find an object based on the text parameter + for _, value in pairs(self.labels) do + if value.text:GetText() == text then + return value + end + end + return nil + end + + local function GetText(self, value) -- get the text of a label object + for _,item in pairs(self.labels) do + if value == item then + return item.text:GetText() + end + end + return nil + end + + local function SetText(self, value, text) -- set the text of a label object + for _, item in pairs(self.labels) do + if value == item then + value.text:SetText(text) + end + end + end + + local function IsSelected(self, value) -- return if the label object is currently selected + for _, item in pairs(self.labels) do + if value == item then + return item.selected + end + end + return nil + end + + local function GetSelected(self) -- return a table of the currently selected label objects + local selectedList = {} + for _, item in pairs(self.labels) do + if item.selected then + table.insert(selectedList, item) + end + end + return selectedList + end + + local function SetItemList(self, list) -- create new labels from a list of strings + for _,item in pairs(self.labels) do + item:Hide() + item:ClearAllPoints() + end + + self.labels = {} + + if list then + for _,item in pairs(list) do + if type(item) == "string" then + self:AddItem(item) + elseif type(item) == "table" then + if item.string ~= nil and type(item.string) == "string" then + if item.color ~= nil then + if type(item.color) == "table" and item.color.r ~= nil and item.color.g ~= nil and item.color.b ~= nil then + self:AddItem(item.string, item.color) + else + assert(false and "setitemlist: item.color is set, but nonsense") + end + else + self:AddItem(item.string) + end + else + assert( false and "setitemlist: item is table without .string member") + end + else + assert(false and "SetItemList: nonsense list entry") + end + end + end + end + + local function RemoveItem(self, item) -- delete an item + local function RedrawFrame() + for index,value in pairs(self.labels) do + value:SetPoint("TOPLEFT", self.labelframe, "TOPLEFT", 0, (-(index-1) * 18)) + value:SetPoint("TOPRIGHT", self.labelframe, "TOPRIGHT", 0,(-(index-1) * 18)) + end + end + + for index, value in pairs(self.labels) do + if value == item then + table.remove(self.labels, index) + item:Hide() + item:ClearAllPoints() + RedrawFrame() + end + end + end + + local function SetSelected(self, item, value) + if value then + if not self.multiselect then -- test + for _, value in pairs(self.labels) do + value.selected = false + value.highlight:Hide() + end + end + item.selected = true + item.highlight:Show() + else + item.selected = false + item.highlight:Hide() + end + end + + local function Constructor() -- widget constructor + local frame = CreateFrame("Frame", nil, UIParent) + local backdrop = CreateFrame("Frame", nil, frame) + local self = {} + local labels = {} + + self.type = widgetType + self.frame = frame + self.backdrop = backdrop + self.labels = {} + self.multiselect = true + frame.obj = self + + local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") + label:SetJustifyH("LEFT") + label:SetPoint("TOPLEFT", 5, 0) + label:SetPoint("TOPRIGHT", -5, 0) + label:SetHeight(14) + label:SetText("MultiSelect") + self.label = label + + backdrop:SetBackdrop(FrameBackdrop) + backdrop:SetBackdropColor(0, 0, 0) + backdrop:SetBackdropBorderColor(0.4, 0.4, 0.4) + backdrop:SetPoint("TOPLEFT", frame, "TOPLEFT", 5, -14) + backdrop:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -5, 0) + + local scrollframe = CreateFrame("ScrollFrame", format("%s@%s@%s", widgetType, "ScrollFrame", tostring(self)), frame, "UIPanelScrollFrameTemplate") + scrollframe:SetPoint("TOPLEFT", backdrop, "TOPLEFT", 5, -6) + scrollframe:SetPoint("BOTTOMRIGHT", backdrop, "BOTTOMRIGHT", -28, 6) + scrollframe.obj = self + self.scrollframe = scrollframe + + local labelframe = CreateFrame("Frame", nil, scrollframe) + labelframe:SetAllPoints() + labelframe.obj = self + scrollframe:SetScrollChild(labelframe) + self.labelframe = labelframe + + -- method listing + self.OnAcquire = OnAcquire + self.SetLabel = SetLabel + self.AddItem = AddItem + self.SetWidth = SetWidth + self.SetMultiSelect = SetMultiSelect + self.SetItemList = SetItemList + self.GetItem = GetItem + self.RemoveItem = RemoveItem + self.GetText = GetText + self.SetText = SetText + self.IsSelected = IsSelected + self.GetSelected = GetSelected + self.SetSelected = SetSelected + + AceGUI:RegisterAsWidget(self) + return self + end + AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) +end + diff -r 47fac96968e1 -r 21c58930f74e Options.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options.lua Fri Mar 02 22:32:12 2012 -0500 @@ -0,0 +1,15 @@ + +bsk.options = { + name= 'bsk', + type = 'group', + args = + { + version = + { + type = "execute", + name = "Version query", + desc = "Check others' versions", + func = function(self) self:Print("TODO") end + } + } +} diff -r 47fac96968e1 -r 21c58930f74e breuesk.toc --- a/breuesk.toc Fri Mar 02 00:15:09 2012 -0500 +++ b/breuesk.toc Fri Mar 02 22:32:12 2012 -0500 @@ -22,4 +22,6 @@ Localization\enUS.lua Core.lua Lists.lua - +Gui.lua +MultiSelectWidget.lua +Options.lua