comparison options.lua @ 125:a9cf9b2fbf9b

- Fix interactions with AddonLoader. - Plugins get a :Print with a clickable prefix, with overrideable behaviors. - 'Deactivate' event gets a [wrapper around] current raiders table. - Fix sorting bug in player history data. - Smarter status line text when viewing unfiltered history. - Do not disable history regeneration button when current history is empty. - :BuildMainDisplay can handle the CLI args now.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 19 Aug 2012 21:08:59 -0400
parents ccca3d8d2b22
children 47b149f9a5d7
comparison
equal deleted inserted replaced
124:1a248faf1a3b 125:a9cf9b2fbf9b
748 controls = funkified 748 controls = funkified
749 end 749 end
750 750
751 -- widget container status tables (will have things magically appear 751 -- widget container status tables (will have things magically appear
752 -- inside them that we wish to preserve) 752 -- inside them that we wish to preserve)
753 local options_treegroup -- careful, this is deliberately not preserved
753 local status_for_scroll = {} 754 local status_for_scroll = {}
754 local status_for_select = { treewidth = 160 } 755 local status_for_select = { treewidth = 160 }
755 756
756 local function preload() 757 local function preload()
757 for id in pairs(opts.itemfilter) do GetItemInfo(id) end 758 for id in pairs(opts.itemfilter) do GetItemInfo(id) end
798 799
799 -- Clicking the Options tab as a whole (tabs_OnGroupSelected["opt"]). 800 -- Clicking the Options tab as a whole (tabs_OnGroupSelected["opt"]).
800 local tabs_OGS = function (container, specials) 801 local tabs_OGS = function (container, specials)
801 container:SetLayout("Fill") 802 container:SetLayout("Fill")
802 local left = AceGUI:Create("TreeGroup") 803 local left = AceGUI:Create("TreeGroup")
804 options_treegroup = left
803 left:SetStatusTable(status_for_select) 805 left:SetStatusTable(status_for_select)
804 left:SetLayout("Fill") 806 left:SetLayout("Fill")
805 left:SetFullWidth(true) 807 left:SetFullWidth(true)
806 left:SetFullHeight(true) 808 left:SetFullHeight(true)
807 left:EnableButtonTooltips(false) 809 left:EnableButtonTooltips(false)
844 end 846 end
845 847
846 if preload then preload() end 848 if preload then preload() end
847 end 849 end
848 850
851 local tabs_cli = function (unique)
852 if not controls[unique] then return end
853 options_treegroup:SetSelected(unique)
854 options_treegroup:SetUserData("options restore scroll", false)
855 end
856
849 addon:register_tab_control_AT_END ("opt", [[Options]], 857 addon:register_tab_control_AT_END ("opt", [[Options]],
850 [[Options for fine-tuning behavior]], tabs_OGS, [[ 858 [[Options for fine-tuning behavior]], tabs_OGS, [[
851 The "be chatty" options can be noisy, but they make the 859 The "be chatty" options can be noisy, but they make the
852 |cffff8000[Ouro Loot]|r link much more useful. See 860 |cffff8000[Ouro Loot]|r link much more useful. See
853 <Help -- Handy Tips> for details! 861 <Help -- Handy Tips> for details!
854 ]]) 862 ]], tabs_cli)
855 863
856 864
857 --------------- 865 ---------------
858 -- Registering new options entries 866 -- Registering new options entries
859 local insertion_index = #options_tree 867 local insertion_index = #options_tree
871 879
872 880
873 --[[ 881 --[[
874 PLUGIN is the module table itself. (This does not actually have to be 882 PLUGIN is the module table itself. (This does not actually have to be
875 a plugin created with :[Constrained]NewModule, as long as it has a 883 a plugin created with :[Constrained]NewModule, as long as it has a
876 GetName method and 884 'name' field and
877 - TEXT is passed 885 - TEXT is passed
878 - if OPTIONS is a table, then OPTIONS.args.name exists 886 - if OPTIONS is a table, then OPTIONS.args.name exists
879 PARENT is nil to register in the tree list directly. 887 UNIQUE and PARENT control placement in the tree list. UNIQUE is a unique
880 TEXT is either the text to display in the tree list, or nil to use the 888 string, or nil to use the module's unique name (this can only be used once
881 moduleName field out of PLUGIN (not :GetName()). 889 obviously, or it's not "unique"). PARENT is nil to display at the main
890 level of options, or a previously-registered return value to display as a
891 child of that option.
892 TEXT is either the text to display in the tree list, or nil to use
893 PLUGIN:GetName().
882 OPTIONS is either 894 OPTIONS is either
883 I) an aceconfig-style options table 895 I) an aceconfig-style options table (uses PLUGIN:GetName())
884 II) a function to call directly 896 II) a function to call directly
885 897
886 (I) Will augment options.args.name with coloring/sizing, if it exists. 898 (I) Will augment options.args.name with coloring/sizing, if it exists.
887 (Set options.args.name.name before registering.) Will create it if not 899 (Set options.args.name.name before registering.) Will create it if not
888 present. 900 present.
891 options (scrollframe_container, plugin, unique_code) 903 options (scrollframe_container, plugin, unique_code)
892 where UNIQUE_CODE is what's used by the TreeGroup widget in identifying 904 where UNIQUE_CODE is what's used by the TreeGroup widget in identifying
893 the "button" clicked in the lefthand tree list. 905 the "button" clicked in the lefthand tree list.
894 906
895 Will append a reset button IFF an options database has been registered already. 907 Will append a reset button IFF an options database has been registered already.
908
909 XXX - the PARENT functionality hasn't been implmented yet cuz I'm lazy
896 ]] 910 ]]
897 function addon:register_options_entry (plugin, parent, text, options) 911 function addon:register_options_entry (plugin, unique, parent, text, options)
898 -- if this changes at all, fix up plugin_reset_button accordingly 912 unique = (unique and tostring(unique))
899 local code = plugin:GetName() 913 or assert(plugin.name, "plugin has no 'name' field")
914
900 --if parent 915 --if parent
901 916
902 text = text or plugin.moduleName 917 text = text or plugin:GetName()
903 918
904 local handler 919 local handler
905 local pdb = plugin.moduleName and 920 local pdb = plugin.moduleName and
906 self.db:GetNamespace (plugin.moduleName, --[[silent=]]true) 921 self.db:GetNamespace (plugin.moduleName, --[[silent=]]true)
907 922
908 if type(options) == 'table' then 923 if type(options) == 'table' then
909 -- AceConfig-style options table 924 -- AceConfig-style options table
910 aceconfig_list[code] = true 925 aceconfig_list[unique] = true
911 if not options.args.name then 926 if not options.args.name then
912 options.args.name = { 927 options.args.name = {
913 name = plugin.moduleName, 928 name = plugin:GetName(),
914 type = 'description', 929 type = 'description',
915 } 930 }
916 end 931 end
917 options.args.name.name = '|cff30adff' .. options.args.name.name .. '|r' 932 options.args.name.name = '|cff30adff' .. options.args.name.name .. '|r'
918 options.args.name.fontSize = 'large' 933 options.args.name.fontSize = 'large'
946 elseif type(options) == 'function' then 961 elseif type(options) == 'function' then
947 -- AceGUI callback 962 -- AceGUI callback
948 if pdb then 963 if pdb then
949 handler = function (sf) 964 handler = function (sf)
950 sf:AddChildren(mktitle(text)) 965 sf:AddChildren(mktitle(text))
951 local ret = options (sf, plugin, code) 966 local ret = options (sf, plugin, unique)
952 local w = mkbutton("Reset", 967 local w = mkbutton("Reset",
953 ([[Reset settings for <%s> plugin back to defaults. Shift-click to also trigger a UI reload.]]):format(text)) 968 ([[Reset settings for <%s> plugin back to defaults. Shift-click to also trigger a UI reload.]]):format(text))
954 w:SetRelativeWidth(0.3) 969 w:SetRelativeWidth(0.3)
955 w:SetCallback("OnClick", function(_w) 970 w:SetCallback("OnClick", function(_w)
956 pdb:ResetProfile() 971 pdb:ResetProfile()
960 return ret 975 return ret
961 end 976 end
962 else 977 else
963 handler = function (sf) 978 handler = function (sf)
964 sf:AddChildren(mktitle(text)) 979 sf:AddChildren(mktitle(text))
965 return options (sf, plugin, code) 980 return options (sf, plugin, unique)
966 end 981 end
967 end 982 end
968 983
969 else 984 else
970 error(("Error: 'options' parameter for plugin '%s' is neither table nor function"):format(plugin:GetName())) 985 error(("Error: 'options' parameter for plugin '%s' is neither table nor function"):format(plugin:GetName()))
971 end 986 end
972 987
973 if not controls[code] then 988 if not controls[unique] then
974 controls[code] = {} 989 controls[unique] = {}
975 end 990 end
976 table.insert (controls[code], handler) 991 table.insert (controls[unique], handler)
977 992
978 table.insert (options_tree, insertion_index, { 993 table.insert (options_tree, insertion_index, {
979 value = code, 994 value = unique,
980 text = text, -- maybe call markup on this? 995 text = '++ '..text, -- maybe call markup on this?
981 }) 996 })
982 insertion_index = insertion_index + 1 997 insertion_index = insertion_index + 1
983 -- The treegroup will rescan options_tree (via RefreshTree) several times 998 -- The treegroup will rescan options_tree (via RefreshTree) several times
984 -- before the player actually sees anything; no more work needs doing. 999 -- before the player actually sees anything; no more work needs doing.
985 return -- something that can be used as 'parent' 1000 return unique -- something that can be used as 'parent'?
986 end 1001 end
987 1002
988 1003
989 addon.FILES_LOADED = addon.FILES_LOADED + 1 1004 addon.FILES_LOADED = addon.FILES_LOADED + 1
990 -- vim:noet 1005 -- vim:noet