Mercurial > wow > ouroloot
comparison gui.lua @ 57:81d5449621f8
Fix some sloppy indentation. Correct handling of delayed-load plugins registering multiple tabs in arbitrary order. Add option to not display tabs for disabled plugins (would normally allow enabling of them).
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Tue, 17 Apr 2012 04:57:06 +0000 |
| parents | fcc0d0ff5832 |
| children | 59718ec80610 |
comparison
equal
deleted
inserted
replaced
| 56:fcc0d0ff5832 | 57:81d5449621f8 |
|---|---|
| 93 | 93 |
| 94 | 94 |
| 95 ------ Behind the scenes routines | 95 ------ Behind the scenes routines |
| 96 -- Text generation | 96 -- Text generation |
| 97 do | 97 do |
| 98 local next_insertion_position = 2 -- position in _taborder | |
| 99 local text_gen_funcs, specials_gen_funcs = {}, {} | 98 local text_gen_funcs, specials_gen_funcs = {}, {} |
| 100 local accumulator = {} | 99 local accumulator = {} |
| 101 | 100 |
| 102 -- Can do clever things by passing other halting points as zero | 101 -- Can do clever things by passing other halting points as zero |
| 103 function addon:zero_printed_fenceposts(zero) | 102 function addon:zero_printed_fenceposts(zero) |
| 114 function addon:register_text_generator (text_type, title, description, generator, opt_specgen) | 113 function addon:register_text_generator (text_type, title, description, generator, opt_specgen) |
| 115 if type(generator) ~= 'function' then | 114 if type(generator) ~= 'function' then |
| 116 error(("Generator for text type '%s' must be a function!"):format(text_type)) | 115 error(("Generator for text type '%s' must be a function!"):format(text_type)) |
| 117 end | 116 end |
| 118 _tabtexts[text_type] = { title=title, desc=description } | 117 _tabtexts[text_type] = { title=title, desc=description } |
| 119 tinsert (_taborder, next_insertion_position, text_type) | 118 self:tabposition_insert (text_type) |
| 120 next_insertion_position = next_insertion_position + 1 | |
| 121 text_gen_funcs[text_type] = generator | 119 text_gen_funcs[text_type] = generator |
| 122 specials_gen_funcs[text_type] = opt_specgen | 120 specials_gen_funcs[text_type] = opt_specgen |
| 123 dirty_tabs = true | 121 dirty_tabs = true |
| 124 end | 122 end |
| 125 | 123 |
| 157 -- LOD tab has been clicked on. | 155 -- LOD tab has been clicked on. |
| 158 local function _handle_LOD (tabs_container,specials,tabtitle) | 156 local function _handle_LOD (tabs_container,specials,tabtitle) |
| 159 -- "tabtitle" here is the name in _taborder, not the colorized string | 157 -- "tabtitle" here is the name in _taborder, not the colorized string |
| 160 local what = _tabtexts[tabtitle] | 158 local what = _tabtexts[tabtitle] |
| 161 local addon_index = what.LOD | 159 local addon_index = what.LOD |
| 162 local loaded_at = what.loaded_at | |
| 163 local real_nip = next_insertion_position | |
| 164 local function LOAD() | 160 local function LOAD() |
| 165 _tabtexts[tabtitle] = nil | 161 _tabtexts[tabtitle] = nil |
| 166 tremove (_taborder, loaded_at) | 162 addon:tabposition_remove_and_remember (tabtitle) |
| 167 next_insertion_position = loaded_at | |
| 168 local saved_next_insertion_position = loaded_at | |
| 169 local loaded, whynot = LoadAddOn(addon_index) | 163 local loaded, whynot = LoadAddOn(addon_index) |
| 164 local tabdelta = addon:tabposition_restore() | |
| 170 if loaded then | 165 if loaded then |
| 171 addon:Print("%s loaded. %d |4tab:tabs; added.", tabtitle, | 166 addon:Print("%s loaded, %d |4tab:tabs; added.", tabtitle, tabdelta) |
| 172 next_insertion_position - saved_next_insertion_position) | |
| 173 else | 167 else |
| 174 what.disabled = true | 168 what.disabled = true |
| 175 _tabtexts[tabtitle] = what -- restore this for mouseovers | 169 _tabtexts[tabtitle] = what -- restore this for mouseovers |
| 176 addon:Print("%s could not load (game client reason was '%s').", tabtitle, whynot) | 170 addon:Print("%s could not load (game client reason was '%s').", tabtitle, whynot) |
| 177 DisableAddOn(addon_index) | 171 DisableAddOn(addon_index) |
| 178 end | 172 end |
| 179 next_insertion_position = real_nip | |
| 180 dirty_tabs = true | 173 dirty_tabs = true |
| 181 return addon:OpenMainDisplayToTab(tabtitle) or addon:BuildMainDisplay() | 174 return addon:OpenMainDisplayToTab(tabtitle) or addon:BuildMainDisplay() |
| 182 end | 175 end |
| 183 addon.display:Hide() | 176 addon.display:Hide() |
| 184 if what.LOD_enabled then | 177 if what.LOD_enabled then |
| 185 -- totally loadable, go for it | 178 -- totally loadable, go for it |
| 186 LOAD() | 179 LOAD() |
| 187 else | 180 else |
| 188 -- was disabled at addons menu | 181 -- was disabled at addons menu |
| 189 StaticPopupDialogs["OUROL_LOD_DISABLED"] = flib.StaticPopup{ | 182 StaticPopupDialogs["OUROL_LOD_DISABLED"] = flib.StaticPopup{ |
| 190 text = tabtitle.." was disabled at the character loading screen. Do you want to enable it?", | 183 text = tabtitle.." was disabled at the character selection screen. Do you want to enable it?", |
| 191 button1 = YES, | 184 button1 = YES, |
| 192 button2 = NO, | 185 button2 = NO, |
| 193 OnAccept = function() | 186 OnAccept = function() |
| 194 EnableAddOn(addon_index) | 187 EnableAddOn(addon_index) |
| 195 LOAD() | 188 LOAD() |
| 209 -- already been called, we flag the dirty bit and let the main building | 202 -- already been called, we flag the dirty bit and let the main building |
| 210 -- routine handle it like any other plugin. | 203 -- routine handle it like any other plugin. |
| 211 function addon:_gui_add_LOD_tab (tabtitle, folder, addon_index, enabled_p, why_not) | 204 function addon:_gui_add_LOD_tab (tabtitle, folder, addon_index, enabled_p, why_not) |
| 212 _tabtexts[tabtitle] = { | 205 _tabtexts[tabtitle] = { |
| 213 title = ("|cffff0000(%s)|r"):format(tabtitle), | 206 title = ("|cffff0000(%s)|r"):format(tabtitle), |
| 214 desc = ("'|cffff0000%s|r' is not loaded yet. Click the tab to load it now."):format(folder), | 207 desc = ("Plugin '|cffff0000%s|r' is not loaded yet. Click the tab to load it now."):format(folder), |
| 215 LOD = addon_index, | 208 LOD = addon_index, |
| 216 LOD_enabled = enabled_p, | 209 LOD_enabled = enabled_p, |
| 217 LOD_why_not = why_not, | 210 LOD_why_not = why_not, |
| 218 loaded_at = next_insertion_position, | |
| 219 } | 211 } |
| 220 tabs_OnGroupSelected[tabtitle] = _handle_LOD | 212 tabs_OnGroupSelected[tabtitle] = _handle_LOD |
| 221 tinsert (_taborder, next_insertion_position, tabtitle) | 213 self:tabposition_insert (tabtitle) |
| 222 next_insertion_position = next_insertion_position + 1 | |
| 223 dirty_tabs = true | 214 dirty_tabs = true |
| 224 end | 215 end |
| 225 end | 216 end |
| 226 | 217 |
| 227 --[[ | 218 --[[ |
| 415 local tabgroup_tabs | 406 local tabgroup_tabs |
| 416 | 407 |
| 417 --[[ | 408 --[[ |
| 418 Controls for the tabs on the left side of the main display. | 409 Controls for the tabs on the left side of the main display. |
| 419 ]] | 410 ]] |
| 411 | |
| 412 -- The _tabtexts and _taborder tables have distressingly wide visibility. | |
| 413 -- They are used to build the tabgroup_tabs array fed to TabGroup, and for the | |
| 414 -- official source of mouseover tab titles, etc. Not completely encapsulated | |
| 415 -- because we need to reach in and fiddle too often to be worth it. | |
| 420 _tabtexts = { | 416 _tabtexts = { |
| 421 ["eoi"] = {title=[[Loot]], desc=[[Observed loot, plus boss kills and other events of interest]]}, | 417 ["eoi"] = {title=[[Loot]], desc=[[Observed loot, plus boss kills and other events of interest]]}, |
| 422 ["hist"] = {title=[[History]], desc=[[A short semi-permanent record]]}, | 418 ["hist"] = {title=[[History]], desc=[[A short semi-permanent record]]}, |
| 423 ["help"] = {title=[[Help]], desc=[[Instructions, reminders, and tips for non-obvious features]]}, | 419 ["help"] = {title=[[Help]], desc=[[Instructions, reminders, and tips for non-obvious features]]}, |
| 424 ["opt"] = {title=[[Options]], desc=[[Options for fine-tuning behavior]]}, | 420 ["opt"] = {title=[[Options]], desc=[[Options for fine-tuning behavior]]}, |
| 426 } | 422 } |
| 427 --if addon.author_debug then | 423 --if addon.author_debug then |
| 428 _taborder = { "eoi", "hist", "help", "opt" } | 424 _taborder = { "eoi", "hist", "help", "opt" } |
| 429 --else _taborder = { "eoi", "help", "opt" } end | 425 --else _taborder = { "eoi", "help", "opt" } end |
| 430 | 426 |
| 427 do | |
| 428 local next_insertion_position = 2 -- position in _taborder | |
| 429 local removed, saved_offset | |
| 430 | |
| 431 function addon:tabposition_insert (tabcode) | |
| 432 tinsert (_taborder, next_insertion_position, tabcode) | |
| 433 next_insertion_position = next_insertion_position + 1 | |
| 434 end | |
| 435 | |
| 436 -- These two functions are push/pop pairs, sort of. The first removes | |
| 437 -- a tab and prepares to insert more tab(s) in its place. The second | |
| 438 -- returns the "next tab goes here" marker back to the proper end. (And | |
| 439 -- doing all 3 adjustments below at once is amazingly hard to read.) | |
| 440 function addon:tabposition_remove_and_remember (tabcode) | |
| 441 assert(not removed) -- enforce stack-ish discipline | |
| 442 for i = 2, #_taborder do | |
| 443 if _taborder[i] == tabcode then | |
| 444 tremove (_taborder, i) | |
| 445 saved_offset = next_insertion_position - i - 1 | |
| 446 removed, next_insertion_position = i, i | |
| 447 return | |
| 448 end | |
| 449 end | |
| 450 error(("'%s' not used as a tab-text code"):format(tabcode)) | |
| 451 end | |
| 452 function addon:tabposition_restore() | |
| 453 assert(removed) | |
| 454 local count = next_insertion_position - removed | |
| 455 next_insertion_position = next_insertion_position + saved_offset | |
| 456 removed, saved_offset = nil, nil | |
| 457 return count | |
| 458 end | |
| 459 end | |
| 460 | |
| 461 | |
| 462 -- Done at startup, and whenever we've changed the population of tabs. | |
| 431 function addon:gui_init (loot_pointer) | 463 function addon:gui_init (loot_pointer) |
| 432 g_loot = loot_pointer | 464 g_loot = loot_pointer |
| 433 g_generated = nil | 465 g_generated = nil |
| 434 tabgroup_tabs = {} | 466 tabgroup_tabs = {} |
| 435 window_title = "Ouro Loot " .. self.revision | 467 window_title = "Ouro Loot " .. self.revision |
| 1688 -- cutesy abbrevs | 1720 -- cutesy abbrevs |
| 1689 w = mkoption('snarky_boss', "Use snarky boss names", 0.49, | 1721 w = mkoption('snarky_boss', "Use snarky boss names", 0.49, |
| 1690 [[Irreverent replacement names for boss events.]]) | 1722 [[Irreverent replacement names for boss events.]]) |
| 1691 grp:AddChild(w) | 1723 grp:AddChild(w) |
| 1692 | 1724 |
| 1725 -- LOD plugins in all cases | |
| 1726 w = mkoption('display_disabled_LODs', "Include disabled plugins", 0.49, | |
| 1727 [[Show loadable plugins even if they've been disabled (and offer to enable them). Relog to take effect.]]) | |
| 1728 grp:AddChild(w) | |
| 1729 | |
| 1693 -- possible keybindings | 1730 -- possible keybindings |
| 1694 do | 1731 do |
| 1695 local pair = GUI:Create("SimpleGroup") | 1732 local pair = GUI:Create("SimpleGroup") |
| 1696 pair:SetLayout("Flow") | 1733 pair:SetLayout("Flow") |
| 1697 pair:SetRelativeWidth(0.95) | 1734 pair:SetRelativeWidth(0.95) |
