comparison options.lua @ 99:966d06c8d9c9

- Brought plugin handling code up to date. SVs are kept in DB namespaces like they should have been. - Removed/commented all datarev code, until it becomes necessary after MoP. - Textgen special blocks for plugins do not automatically get a "reset&reload" button anymore. - New method to register option pages on the main tab. No sub-entry pages supported yet. Titles and reset&reload added here instead.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 29 Jul 2012 23:12:18 +0000
parents b5a55c69ef67
children a57133ee3c9b
comparison
equal deleted inserted replaced
98:b5a55c69ef67 99:966d06c8d9c9
21 -- [49426] = true, -- Emblem of Frost 21 -- [49426] = true, -- Emblem of Frost
22 } 22 }
23 23
24 -- Mark these as straight to guild vault: 24 -- Mark these as straight to guild vault:
25 addon.default_itemvault = { 25 addon.default_itemvault = {
26 [52078] = true, -- Chaos Orb 26 [52078] = true, -- Chaos Orb (Cata heroics)
27 [69237] = true, -- Living Ember 27 [69237] = true, -- Living Ember (Cata Firelands)
28 [71998] = true, -- Essence of Destruction 28 [71998] = true, -- Essence of Destruction (Cata Dragon Soul)
29 } 29 }
30 30
31 local options_tree = { 31 local options_tree = {
32 { 32 {
33 value = "pong", 33 value = "pong",
34 text = "Pongs", 34 text = "Pongs",
35 }, 35 },
36 { 36 {
37 value = "basic", 37 value = "basic",
38 text = "Options", 38 text = "Main Options",
39 children = { 39 children = {
40 { 40 {
41 value = "filter", 41 value = "filter",
42 text = "Item Filters", 42 text = "Item Filters",
43 }, 43 },
45 value = "profiles", 45 value = "profiles",
46 text = "Profiles", 46 text = "Profiles",
47 }, 47 },
48 }, 48 },
49 }, 49 },
50 'NEW INSERTIONS HERE', -- commenting this puts them all at the bottom
50 { 51 {
51 value = "adv", 52 value = "adv",
52 text = "Advanced/Debugging", 53 text = "Advanced/Debugging",
53 }, 54 },
54 } 55 }
62 local mkbutton = addon.gui_state_pointer.mkbutton 63 local mkbutton = addon.gui_state_pointer.mkbutton
63 local gui = addon.gui_state_pointer 64 local gui = addon.gui_state_pointer
64 local AceGUI = LibStub("AceGUI-3.0") 65 local AceGUI = LibStub("AceGUI-3.0")
65 local flib = LibStub("LibFarmbuyer") 66 local flib = LibStub("LibFarmbuyer")
66 local opts 67 local opts
68
69 local error, assert = addon.error, addon.assert
67 70
68 local function mktoggle (opt, label, width, desc, opt_func) 71 local function mktoggle (opt, label, width, desc, opt_func)
69 local w = mkbutton("CheckBoxSmallLabel", nil, "", desc) 72 local w = mkbutton("CheckBoxSmallLabel", nil, "", desc)
70 w:SetRelativeWidth(width) 73 w:SetRelativeWidth(width)
71 w:SetType("checkbox") 74 w:SetType("checkbox")
681 --------------- 684 ---------------
682 -- Tab 6: Options 685 -- Tab 6: Options
683 do 686 do
684 local funkified = {} 687 local funkified = {}
685 for key,f in pairs(controls) do 688 for key,f in pairs(controls) do
686 -- this is how TreeGroup makes unique keys 689 -- this is how TreeGroup makes unique keys out of nested entries
687 local funkykey = key:gsub('_','\001') 690 local funkykey = key:gsub('_','\001')
688 funkified[funkykey] = { f } 691 funkified[funkykey] = { f }
689 end 692 end
690 controls = funkified 693 controls = funkified
691 end 694 end
699 for id in pairs(opts.itemfilter) do GetItemInfo(id) end 702 for id in pairs(opts.itemfilter) do GetItemInfo(id) end
700 for id in pairs(opts.itemvault) do GetItemInfo(id) end 703 for id in pairs(opts.itemvault) do GetItemInfo(id) end
701 preload = nil 704 preload = nil
702 end 705 end
703 706
704 -- Clicking an entry on the left tree column. 707 local aceconfig_list = {}
708
709 -- Selecting an entry on the left tree column.
705 local opt_OnGroupSelected_func = function (treeg,event,category) 710 local opt_OnGroupSelected_func = function (treeg,event,category)
706 opts = addon.db.profile 711 opts = addon.db.profile
707 local catfuncs = controls[category] 712 local catfuncs = controls[category]
708 if not catfuncs then 713 if not catfuncs then
709 addon:horrible_horrible_error(("Category '%s' has no handler function!"):format(category:gsub('\001','_'))) 714 addon:horrible_horrible_error(("Category '%s' has no handler function!"):format(category:gsub('\001','_')))
710 end 715 end
711 treeg:ReleaseChildren() 716 treeg:ReleaseChildren()
712 local sf = AceGUI:Create("ScrollFrame") 717 if aceconfig_list[category] then
713 sf:SetStatusTable(status_for_scroll) 718 -- aceconfigdialog makes too many assumptions about scrolling
714 sf:SetLayout("Flow") 719 for _,func in ipairs(catfuncs) do
715 -- This forces the scrolling area to be bigger than the visible area; else 720 if func(treeg,category) then break end
716 -- some of the text gets cut off without ever triggering the scrollbar. 721 end
717 sf.content:SetHeight(700)
718 for _,func in ipairs(catfuncs) do
719 if func(sf) then break end
720 end
721 treeg:AddChild(sf)
722 if treeg:GetUserData("options restore scroll") then
723 if status_for_scroll.scrollvalue then
724 sf:SetScroll(status_for_scroll.scrollvalue)
725 end
726 treeg:SetUserData("options restore scroll", false)
727 else 722 else
728 sf:SetScroll(0) 723 local sf = AceGUI:Create("ScrollFrame")
724 sf:SetStatusTable(status_for_scroll)
725 sf:SetLayout("Flow")
726 -- This forces the scrolling area to be bigger than the visible area; else
727 -- some of the text gets cut off without ever triggering the scrollbar.
728 sf.content:SetHeight(700)
729 for _,func in ipairs(catfuncs) do
730 if func(sf,category) then break end
731 end
732 treeg:AddChild(sf)
733 if treeg:GetUserData("options restore scroll") then
734 if status_for_scroll.scrollvalue then
735 sf:SetScroll(status_for_scroll.scrollvalue)
736 end
737 treeg:SetUserData("options restore scroll", false)
738 else
739 sf:SetScroll(0)
740 end
729 end 741 end
730 end 742 end
731 743
732 -- Clicking the Options tab as a whole (tabs_OnGroupSelected["opt"]). 744 -- Clicking the Options tab as a whole (tabs_OnGroupSelected["opt"]).
733 local tabs_OGS = function (container, specials) 745 local tabs_OGS = function (container, specials)
773 end 785 end
774 786
775 addon:register_tab_control_AT_END ("opt", [[Options]], 787 addon:register_tab_control_AT_END ("opt", [[Options]],
776 [[Options for fine-tuning behavior]], tabs_OGS) 788 [[Options for fine-tuning behavior]], tabs_OGS)
777 789
790
791 ---------------
792 -- Registering new options entries
793 local insertion_index = #options_tree
794 for i = #options_tree, 1, -1 do
795 if options_tree[i] == 'NEW INSERTIONS HERE' then
796 insertion_index = i
797 break
798 end
799 end
800 if insertion_index then
801 table.remove (options_tree, insertion_index)
802 else
803 insertion_index = #options_tree + 1
804 end
805
806
807 --[[
808 PLUGIN is the module table itself.
809 PARENT is nil to register in the tree list directly.
810 TEXT is either the text to display in the tree list, or nil to use the
811 moduleName field out of PLUGIN (not :GetName()).
812 OPTIONS is either
813 I) a function to call directly
814 II) an aceconfig-style options table
815
816 (I) Will augment options.args.name with coloring/sizing, if it exists.
817 (Set options.args.name.name before registering.) Will create it if not
818 present.
819
820 (II) Title added unconditionally. Callback is
821 options (scrollframe_container, plugin, unique_code)
822 where UNIQUE_CODE is what's used by the TreeGroup widget in identifying
823 the "button" clicked in the lefthand tree list.
824
825 Will append a reset button IFF an options database has been registered already.
826 ]]
827 function addon:register_options_entry (plugin, parent, text, options)
828 -- if this changes at all, fix up plugin_reset_button accordingly
829 local code = plugin:GetName()
830 --if parent
831
832 text = text or plugin.moduleName
833
834 local handler
835 local pdb = self.db:GetNamespace (plugin.moduleName, --[[silent=]]true)
836 if type(options) == 'table' then
837 -- AceConfig-style options table
838 aceconfig_list[code] = true
839 if not options.args.name then
840 options.args.name = {
841 name = plugin.moduleName,
842 type = 'description',
843 }
844 end
845 options.args.name.name = '|cff30adff' .. options.args.name.name .. '|r'
846 options.args.name.fontSize = 'large'
847 options.args.name.width = 'full'
848 options.args.name.cmdHidden = true
849 options.args.name.order = 1
850 if pdb then
851 options.args.INSERTED_SPACER = {
852 name = '',
853 type = 'description',
854 cmdHidden = true,
855 width = 'full',
856 order = 9000,
857 }
858 options.args.RESET = {
859 name = "Reset",
860 desc = ([[Reset settings for <%s> plugin back to defaults. Shift-click to also trigger a UI reload.]]):format(plugin:GetName()),
861 type = 'execute',
862 func = function()
863 pdb:ResetProfile()
864 if IsShiftKeyDown() then ReloadUI() end
865 end,
866 order = 9001,
867 }
868 end
869 LibStub("AceConfig-3.0"):RegisterOptionsTable(plugin:GetName(), options)
870 handler = function (sf)
871 LibStub("AceConfigDialog-3.0"):Open (plugin:GetName(), sf)
872 end
873
874 elseif type(options) == 'function' then
875 -- AceGUI callback
876 if pdb then
877 handler = function (sf)
878 sf:AddChildren(mktitle(text))
879 local ret = options (sf, plugin, code)
880 local w = mkbutton("Reset",
881 ([[Reset settings for <%s> plugin back to defaults. Shift-click to also trigger a UI reload.]]):format(text))
882 w:SetRelativeWidth(0.3)
883 w:SetCallback("OnClick", function(_w)
884 pdb:ResetProfile()
885 if IsShiftKeyDown() then ReloadUI() end
886 end)
887 sf:AddChildren(spacer(10),w)
888 return ret
889 end
890 else
891 handler = function (sf)
892 sf:AddChildren(mktitle(text))
893 return options (sf, plugin, code)
894 end
895 end
896
897 else
898 error(("Error: 'options' parameter for plugin '%s' is neither table nor function"):format(plugin:GetName()))
899 end
900
901 if not controls[code] then
902 controls[code] = {}
903 end
904 table.insert (controls[code], handler)
905
906 table.insert (options_tree, insertion_index, {
907 value = code,
908 text = text, -- maybe call markup on this?
909 })
910 insertion_index = insertion_index + 1
911 -- The treegroup will rescan options_tree (via RefreshTree) several times
912 -- before the player actually sees anything; no more work needs doing.
913 return -- something that can be used as 'parent'
914 end
915
916
778 -- vim:noet 917 -- vim:noet