comparison core.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
107 107
108 108
109 ------ Constants 109 ------ Constants
110 local RAID_ROSTER_UPDATE_EVENT = 110 local RAID_ROSTER_UPDATE_EVENT =
111 (select(4,GetBuildInfo()) >= 50000) and 'GROUP_ROSTER_UPDATE' or 'RAID_ROSTER_UPDATE' 111 (select(4,GetBuildInfo()) >= 50000) and 'GROUP_ROSTER_UPDATE' or 'RAID_ROSTER_UPDATE'
112 local option_defaults = { 112 local option_defaults = { profile = {
113 ['datarev'] = 20, -- cheating, this isn't actually an option 113 --['datarev'] = 20, -- cheating, this isn't actually an option
114 ['popup_on_join'] = true, 114 ['popup_on_join'] = true,
115 ['register_slash_synonyms'] = false, 115 ['register_slash_synonyms'] = false,
116 ['slash_synonyms'] = '/ol,/oloot', 116 ['slash_synonyms'] = '/ol,/oloot',
117 ['scroll_to_bottom'] = true, 117 ['scroll_to_bottom'] = true,
118 ['gui_noob'] = true, 118 ['gui_noob'] = true,
135 ['precache_history_uniques'] = false, 135 ['precache_history_uniques'] = false,
136 ['chatty_on_remote_changes'] = false, 136 ['chatty_on_remote_changes'] = false,
137 ['chatty_on_remote_changes_frame'] = 1, 137 ['chatty_on_remote_changes_frame'] = 1,
138 ['itemfilter'] = {}, 138 ['itemfilter'] = {},
139 ['itemvault'] = {}, 139 ['itemvault'] = {},
140 } 140 } }
141 local virgin = "First time loaded? Hi! Use the /ouroloot command" 141 local virgin = "First time loaded? Hi! Use the /ouroloot command"
142 .." to show the main display. You should probably browse the instructions" 142 .." to show the main display. You should probably browse the instructions"
143 .." if you've never used this before; %s to display the help window. This" 143 .." if you've never used this before; %s to display the help window. This"
144 .." welcome message will not intrude again." 144 .." welcome message will not intrude again."
145 local newer_warning = "A newer version has been released. You can %s to display" 145 local newer_warning = "A newer version has been released. You can %s to display"
152 ..[[ will not display a window until this situation is corrected. ]] 152 ..[[ will not display a window until this situation is corrected. ]]
153 ..[[ You can try typing|n|cff00ff40/ouroloot fix ?|n]] 153 ..[[ You can try typing|n|cff00ff40/ouroloot fix ?|n]]
154 ..[[|cffffff00to see what can be done by software alone. You may still]] 154 ..[[|cffffff00to see what can be done by software alone. You may still]]
155 ..[[ need to do a "/reload" afterwards, or even restart the game client.]] 155 ..[[ need to do a "/reload" afterwards, or even restart the game client.]]
156 local unique_collision = "Item '%s' was carrying unique tag <%s>, but that was already in use; tried to generate a new tag and failed!|n|nRemote sender was '%s', previous cache entry was <%s/%s>.|n|nThis may require a live human to figure out; the loot in question has not been stored." 156 local unique_collision = "Item '%s' was carrying unique tag <%s>, but that was already in use; tried to generate a new tag and failed!|n|nRemote sender was '%s', previous cache entry was <%s/%s>.|n|nThis may require a live human to figure out; the loot in question has not been stored."
157 local new_profile_warning = [[Be aware that profiles only store addon & plugin settings from the <Options> tab; loot and generated text is account-wide data, unrelated to your current profile.]]
157 local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s to %s" 158 local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s to %s"
158 local qualnames = { 159 local qualnames = {
159 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, 160 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0,
160 ['white'] = 1, ['common'] = 1, 161 ['white'] = 1, ['common'] = 1,
161 ['green'] = 2, ['uncommon'] = 2, 162 ['green'] = 2, ['uncommon'] = 2,
728 virgin = nil 729 virgin = nil
729 end,10,self) 730 end,10,self)
730 else 731 else
731 virgin = nil 732 virgin = nil
732 end 733 end
733 self.db = _G.LibStub("AceDB-3.0"):New("OuroLootOptsDB", 734 self.db = _G.LibStub("AceDB-3.0"):New("OuroLootOptsDB", option_defaults , --[[Default=]]true)
734 { profile = option_defaults } , --[[Default=]]true) 735 self.db.RegisterCallback (self, "OnNewProfile", function()
736 self:Print(new_profile_warning)
737 end)
735 self.db.RegisterCallback (self, "OnProfileChanged", "DBProfileRefresh") 738 self.db.RegisterCallback (self, "OnProfileChanged", "DBProfileRefresh")
736 self.db.RegisterCallback (self, "OnProfileCopied", "DBProfileRefresh") 739 self.db.RegisterCallback (self, "OnProfileCopied", "DBProfileRefresh")
737 self.db.RegisterCallback (self, "OnProfileReset", "DBProfileRefresh") 740 self.db.RegisterCallback (self, "OnProfileReset", "DBProfileRefresh")
738 self:DBProfileRefresh() 741 self:DBProfileRefresh()
739 742
952 if self.debug.flow then self:Print"is in control-flow debug mode." end 955 if self.debug.flow then self:Print"is in control-flow debug mode." end
953 end 956 end
954 --function addon:OnDisable() end 957 --function addon:OnDisable() end
955 958
956 do 959 do
960 --[[
961 Module support (aka plugins). Field names with special meanings:
962 - option_defaults: (IN) Standard AceDB-style table. Use a profiles key!
963 - db: (OUT) AceDB object, set during init.
964 - opts: (OUT) Pointer to plugin's "db.profile" subtable.
965
966 OnInitialize, [default_]OnEnable, register_text_generator, register_tab_control
967 are all inherited.
968 ]]
957 local prototype = {} 969 local prototype = {}
958 local registry 970 local registry
959 971
960 -- By default, no plugins. First one in sets up code for any after. 972 -- By default, no plugins. First one in sets up code for any after.
961 addon.get_plugin = flib.nullfunc 973 addon.get_plugin = flib.nullfunc
974 return addon:register_tab_control(t,...) 986 return addon:register_tab_control(t,...)
975 end 987 end
976 end 988 end
977 end 989 end
978 990
991 local function module_OnInit (plugin)
992 if plugin.option_defaults then
993 plugin.db = addon.db:RegisterNamespace (plugin.moduleName, plugin.option_defaults)
994 plugin.opts = plugin.db.profile
995 --plugin:SetEnabledState(plugin.db.profile.enabled) if that flag is needed later
996 end
997 end
998
979 local function module_OnEnable (plugin) 999 local function module_OnEnable (plugin)
980 if plugin.option_defaults then 1000 end
981 local SVname = 'OuroLoot'..plugin:GetName()..'_opts' 1001
982 if not _G[SVname] then 1002 local function module_GetOption (plugin, info)
983 _G[SVname] = {} 1003 local name = info[#info]
984 if type(plugin.OnFirstTime) == 'function' then 1004 return plugin.db.profile[name]
985 plugin:OnFirstTime() 1005 end
986 end 1006 local function module_SetOption (plugin, info, value)
987 end 1007 local name = info[#info]
988 plugin.opts = _G[SVname] 1008 plugin.db.profile[name] = value
989 for option,default in pairs(plugin.option_defaults) do 1009 local arg = info.arg
990 if plugin.opts[option] == nil then 1010 if type(arg) == 'function' then
991 plugin.opts[option] = default 1011 plugin[arg](plugin,info)
992 end 1012 end
993 end 1013 end
994 plugin.option_defaults = nil 1014
995 end 1015 prototype.OnInitialize = module_OnInit
996 end
997
998 prototype.OnEnable = module_OnEnable 1016 prototype.OnEnable = module_OnEnable
999 prototype.default_OnEnable = module_OnEnable 1017 prototype.default_OnEnable = module_OnEnable
1018 prototype.GetOption = module_GetOption
1019 prototype.SetOption = module_SetOption
1000 1020
1001 addon:SetDefaultModuleLibraries("AceConsole-3.0") 1021 addon:SetDefaultModuleLibraries("AceConsole-3.0")
1002 addon:SetDefaultModulePrototype(prototype) 1022 addon:SetDefaultModulePrototype(prototype)
1003 1023
1004 local err = [[Module '%s' cannot register itself because it failed a required condition: '%s']] 1024 local err = [[Module '%s' cannot register itself because it failed a required condition: '%s']]
1012 if mincomm and tonumber(mincomm) > tonumber(self.commrev) then 1032 if mincomm and tonumber(mincomm) > tonumber(self.commrev) then
1013 self:Print(err,modname, 1033 self:Print(err,modname,
1014 "commrev "..self.commrev.." older than minimum "..mincomm) 1034 "commrev "..self.commrev.." older than minimum "..mincomm)
1015 return false 1035 return false
1016 end 1036 end
1017 if mindata and tonumber(mindata) > opts.datarev then 1037 --[[if mindata and tonumber(mindata) > opts.datarev then
1018 self:Print(err,modname, 1038 self:Print(err,modname,
1019 "datarev "..opts.datarev.." older than minimum "..mindata) 1039 "datarev "..opts.datarev.." older than minimum "..mindata)
1020 return false 1040 return false
1021 end 1041 end]]
1022 end 1042 end
1023 return self:NewModule(modname) 1043 return self:NewModule(modname)
1024 end 1044 end
1025 end 1045 end
1026 1046