Mercurial > wow > whichrankdoeswhat
comparison main.lua @ 1:17a4945d14eb
Initial functioning checkin.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Fri, 14 Jan 2011 00:48:17 +0000 |
| parents | |
| children | 78ff21480511 |
comparison
equal
deleted
inserted
replaced
| 0:de6232dda772 | 1:17a4945d14eb |
|---|---|
| 1 local nametag, addon = ... | |
| 2 | |
| 3 addon.defaults = { | |
| 4 profile = { | |
| 5 enable = true, | |
| 6 guildcontrol = true, | |
| 7 }, | |
| 8 } | |
| 9 | |
| 10 | |
| 11 addon.options = { | |
| 12 name = "", | |
| 13 type = 'group', | |
| 14 childGroups = 'tab', | |
| 15 handler = addon, -- functions listed as strings called as addon:func | |
| 16 get = "GetOption", | |
| 17 set = "SetOption", | |
| 18 args = { | |
| 19 general = { | |
| 20 name = "General", | |
| 21 desc = "General options", | |
| 22 type = 'group', | |
| 23 order = 10, | |
| 24 args = { | |
| 25 version = { | |
| 26 --name = filled in during OnInit | |
| 27 type = 'description', | |
| 28 fontSize = "large", | |
| 29 cmdHidden = true, | |
| 30 width = 'full', | |
| 31 order = 1, | |
| 32 }, | |
| 33 enable = { | |
| 34 name = "Enable", | |
| 35 desc = "Use this addon", | |
| 36 type = 'toggle', | |
| 37 arg = "ToggleEnable", | |
| 38 order = 5, | |
| 39 }, | |
| 40 guildcontrol = { | |
| 41 name = "Guild Control for non-GMs", | |
| 42 desc = [[Make the grayed-out Guild Control button activate this addon instead.]], | |
| 43 type = 'toggle', | |
| 44 order = 10, | |
| 45 }, | |
| 46 break1 = { | |
| 47 name = '', | |
| 48 type = 'description', | |
| 49 cmdHidden = true, | |
| 50 width = 'full', | |
| 51 order = 14, | |
| 52 }, | |
| 53 popup = { | |
| 54 name = "/wrdw", | |
| 55 desc = "Toggle WRDW window", | |
| 56 type = 'execute', | |
| 57 func = function() | |
| 58 InterfaceOptionsFrameCancel:Click() | |
| 59 HideUIPanel(GameMenuFrame) | |
| 60 addon:BuildWindow() | |
| 61 end, | |
| 62 order = 15, | |
| 63 }, | |
| 64 }, | |
| 65 }, | |
| 66 --profiles = filled in OnInit | |
| 67 }, | |
| 68 } | |
| 69 | |
| 70 | |
| 71 ----------------------------------------------------------------------------- | |
| 72 -- other locals | |
| 73 local AceGUI = LibStub("AceGUI-3.0") | |
| 74 local st_rowheight = 25 | |
| 75 local st_displayed_rows = 15 --math.floor(366/st_rowheight) | |
| 76 local sidetabs | |
| 77 local incomplete | |
| 78 | |
| 79 -- Remove children widgets without explicitly Release()'ing them. | |
| 80 local function DisownChildren (container) | |
| 81 for i,v in ipairs(container.children) do | |
| 82 container.children[i] = nil | |
| 83 v.frame:Hide() | |
| 84 v.frame:ClearAllPoints() | |
| 85 end | |
| 86 end | |
| 87 | |
| 88 | |
| 89 ----------------------------------------------------------------------------- | |
| 90 addon = LibStub("AceAddon-3.0"):NewAddon(addon, nametag, | |
| 91 "AceConsole-3.0", "AceEvent-3.0") | |
| 92 | |
| 93 -- Thanks to jerry for the nifty arg idea. | |
| 94 function addon:SetOption (info, value) | |
| 95 local name = info[#info] | |
| 96 self.db.profile[name] = value | |
| 97 local arg = info.arg | |
| 98 if arg then self[arg](self) end | |
| 99 end | |
| 100 | |
| 101 function addon:GetOption (info) | |
| 102 local name = info[#info] | |
| 103 return self.db.profile[name] | |
| 104 end | |
| 105 | |
| 106 function addon:OnInitialize() | |
| 107 self.db = LibStub("AceDB-3.0"):New("wrdwDB", self.defaults, --[[Default=]]true) | |
| 108 | |
| 109 local AceDBOptions = LibStub("AceDBOptions-3.0", true) | |
| 110 if AceDBOptions then | |
| 111 self.options.args.profiles = AceDBOptions:GetOptionsTable(self.db) | |
| 112 self.options.args.profiles.order = 200 | |
| 113 end | |
| 114 | |
| 115 self.options.args.general.args.version.name = | |
| 116 "|cff30adffVersion " .. (GetAddOnMetadata(nametag, "Version") or "?") .. "|r" | |
| 117 LibStub("AceConfig-3.0"):RegisterOptionsTable(nametag, self.options) | |
| 118 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(nametag, "WhichRankDoesWhat") | |
| 119 --self.optionsFrame.okay = function() pattern_editing_safe = false end | |
| 120 --self.optionsFrame.refresh = self.optionsFrame.okay | |
| 121 --self.optionsFrame.cancel = self.optionsFrame.okay | |
| 122 | |
| 123 self:SetEnabledState(self.db.profile.enable) | |
| 124 self.OnInitialize = nil | |
| 125 end | |
| 126 | |
| 127 | |
| 128 function addon:OnEnable() | |
| 129 self:RegisterEvent("GUILD_RANKS_UPDATE") | |
| 130 self:RegisterChatCommand("wrdw", "OnChatCommand") | |
| 131 | |
| 132 if (not IsGuildLeader()) and self.db.profile.guildcontrol then | |
| 133 local function onclick() addon:BuildWindow() end | |
| 134 local function onenter(this) GameTooltip_AddNewbieTip(this, GUILDCONTROL, 1.0, 1.0, 1.0, "/wrdw", 1) end | |
| 135 GuildFrame_LoadUI() | |
| 136 hooksecurefunc("GuildFrame_CheckPermissions", function() | |
| 137 GuildControlButton:Enable() | |
| 138 GuildControlButton:SetScript("OnClick", onclick) | |
| 139 GuildControlButton:SetScript("OnEnter", onenter) | |
| 140 end) | |
| 141 end | |
| 142 end | |
| 143 | |
| 144 function addon:OnDisable() | |
| 145 self:Print([[You will need to relog or /reload to fully disable this addon.]]) | |
| 146 end | |
| 147 | |
| 148 function addon:ToggleEnable() | |
| 149 if self.db.profile.enable then | |
| 150 self:Enable() | |
| 151 else | |
| 152 self:Disable() | |
| 153 end | |
| 154 end | |
| 155 | |
| 156 function addon:OnChatCommand (input) | |
| 157 if not input or input:trim() == "" then | |
| 158 if self.display and self.display:IsShown() then | |
| 159 self.display:Hide() | |
| 160 else | |
| 161 self:BuildWindow() | |
| 162 end | |
| 163 else | |
| 164 --LibStub("AceConfigCmd-3.0").HandleCommand(self, "wrdw", nametag, input) | |
| 165 LibStub("AceConfigDialog-3.0"):Open(nametag) | |
| 166 end | |
| 167 end | |
| 168 | |
| 169 | |
| 170 -- Something somewhere has changed, redo the cache | |
| 171 function addon:GUILD_RANKS_UPDATE() | |
| 172 self.perms = nil | |
| 173 if (not incomplete) and self.display and self.display:IsVisible() then | |
| 174 self.display:SetStatusText([[|cffff1010Guild flags have changed!|r You must close and reopen this window to display the changes.]]) | |
| 175 end | |
| 176 end | |
| 177 | |
| 178 | |
| 179 function addon:BuildPerms() | |
| 180 assert(UIParentLoadAddOn("Blizzard_GuildControlUI")) | |
| 181 local check = "|TInterface\\Buttons\\UI-CheckBox-Check:"..(st_rowheight-2).."|t" | |
| 182 | |
| 183 -- http://www.wowace.com/addons/lib-st/pages/set-data/minimal-dataset-format/ | |
| 184 local p,v = {}, {} | |
| 185 for r = 1, GuildControlGetNumRanks() do | |
| 186 GuildControlSetRank(r) | |
| 187 | |
| 188 -- permissions | |
| 189 local flags = { GuildControlGetRankFlags() } | |
| 190 local row = { GuildControlGetRankName(r) } | |
| 191 for c = 1, NUM_RANK_FLAGS do if c ~= 14 then | |
| 192 local newcol = #row + 1 | |
| 193 if c == 15 or c == 16 then | |
| 194 local val = GetGuildBankWithdrawGoldLimit() | |
| 195 row[newcol] = flags[c] and ((val == -1) and check or val) or "" | |
| 196 else | |
| 197 row[newcol] = flags[c] and check or "" | |
| 198 end | |
| 199 end end | |
| 200 p[r] = row | |
| 201 | |
| 202 -- guild vault | |
| 203 local banktabs = {} | |
| 204 for t = 1, GetNumGuildBankTabs() do | |
| 205 -- isViewable, canDeposit, editText, numWithdrawals | |
| 206 banktabs[t] = { row[1], GetGuildBankTabPermissions(t) } | |
| 207 banktabs[t][2] = banktabs[t][2] and check or "" | |
| 208 banktabs[t][3] = banktabs[t][3] and check or "" | |
| 209 banktabs[t][4] = banktabs[t][4] and check or "" | |
| 210 local withdraw = banktabs[t][5] | |
| 211 banktabs[t][5] = (withdraw == -1) and check or (withdraw == 0) and "" or withdraw | |
| 212 end | |
| 213 v[r] = banktabs | |
| 214 end | |
| 215 self.perms = p | |
| 216 -- This one needs to be turned inside-out to match the data requirements | |
| 217 self.vault = {} | |
| 218 for t = 1, GetNumGuildBankTabs() do | |
| 219 self.vault[t] = {} | |
| 220 for r = 1, #v do | |
| 221 self.vault[t][r] = v[r][t] | |
| 222 end | |
| 223 end | |
| 224 end | |
| 225 | |
| 226 | |
| 227 local function setstatus(txt) addon.display:SetStatusText(txt) end | |
| 228 | |
| 229 local make_sidetab | |
| 230 do | |
| 231 local lastclicked | |
| 232 local function OnClick (thistab) | |
| 233 if thistab == lastclicked then return end | |
| 234 for i = 1, #sidetabs do | |
| 235 sidetabs[i]:SetChecked(false) | |
| 236 end | |
| 237 thistab:SetChecked(true) -- should be redundant, but just in case | |
| 238 lastclicked = thistab | |
| 239 if thistab.callback then | |
| 240 thistab:callback(thistab:GetID()) | |
| 241 end | |
| 242 end | |
| 243 | |
| 244 -- Some magic numbers here wrt the index | |
| 245 function make_sidetab (index, callback) | |
| 246 if not sidetabs then | |
| 247 sidetabs = {} | |
| 248 end | |
| 249 | |
| 250 local tab = CreateFrame("CheckButton", "WRDWTab"..index, addon.display.frame, "SpellBookSkillLineTabTemplate", index) | |
| 251 if index > 1 then | |
| 252 tab:SetPoint("TOPLEFT", sidetabs[index-1], "BOTTOMLEFT", 0, -17) | |
| 253 else | |
| 254 tab:SetNormalTexture("Interface\\SpellBook\\GuildSpellbooktabBG") | |
| 255 tab.TabardEmblem:Show() | |
| 256 tab.TabardIconFrame:Show() | |
| 257 SetLargeGuildTabardTextures("player", tab.TabardEmblem, tab:GetNormalTexture(), tab.TabardIconFrame) | |
| 258 tab:SetPoint("TOPLEFT", addon.display.frame, "TOPRIGHT", 0, -17) | |
| 259 end | |
| 260 tab:SetScript("OnClick", OnClick) | |
| 261 --tab:SetChecked(false) -- is default | |
| 262 tab:Show() | |
| 263 tab.callback = callback | |
| 264 sidetabs[index] = tab | |
| 265 return tab | |
| 266 end | |
| 267 | |
| 268 function addon:BuildVaultTabs() | |
| 269 incomplete = nil | |
| 270 local offset = 1 -- number of tabs already made | |
| 271 local function pick_a_tab (tab, id) | |
| 272 DisownChildren(self.display) | |
| 273 self.display:AddChild(self.vault_sts[id-offset]) | |
| 274 end | |
| 275 for t = 1, GetNumGuildBankTabs() do | |
| 276 local name, icon = GetGuildBankTabInfo(t) | |
| 277 incomplete = incomplete or icon == [[Interface\Icons\INV_Misc_QuestionMark]] | |
| 278 local tab = make_sidetab(t+offset, pick_a_tab) | |
| 279 tab:SetNormalTexture(icon) | |
| 280 tab.tooltip = name | |
| 281 end | |
| 282 if incomplete then | |
| 283 setstatus[[Guild vault information is incomplete. Be closer to a vault, and give it some time. You may need to relog and/or open the guild roster/vault to force a client update.]] | |
| 284 end | |
| 285 end | |
| 286 end | |
| 287 | |
| 288 | |
| 289 local function st_OnEnter (rowFrame, cellFrame, data, cols, row, realrow, column, sttable, button, ...) | |
| 290 if (row == nil) or (realrow == nil) then -- mouseover column header | |
| 291 setstatus(cellFrame:GetText():gsub('\n',' ')) | |
| 292 return true | |
| 293 end | |
| 294 return false -- continue with default highlighting behavior | |
| 295 end | |
| 296 local function st_OnLeave (rowFrame, cellFrame, data, cols, row, realrow, column, sttable, button, ...) | |
| 297 setstatus("") | |
| 298 return false -- continue with default un-highlighting behavior | |
| 299 end | |
| 300 local function st_OnClick (rowFrame, cellFrame, data, cols, row, realrow, column, sttable, button, ...) | |
| 301 if (row == nil) or (realrow == nil) then return true end -- click column header, suppress reordering | |
| 302 -- more here? | |
| 303 return true -- do not do anything further | |
| 304 end | |
| 305 | |
| 306 | |
| 307 function addon:BuildMainST (permissions, parent_frame) | |
| 308 -- if this language uses a trailing colon, strip it | |
| 309 local tmp = GUILDCONTROL_RANKLABEL:gsub(":$","") | |
| 310 local cols = {{ | |
| 311 name = tmp, | |
| 312 width = 10 * #tmp, | |
| 313 }} | |
| 314 for i = 1, NUM_RANK_FLAGS do if i ~= 14 then | |
| 315 table.insert(cols,{ | |
| 316 name = _G['GUILDCONTROL_OPTION'..i], | |
| 317 width = 62, | |
| 318 }) | |
| 319 end end | |
| 320 | |
| 321 local ST = LibStub("ScrollingTable"):CreateST (cols, st_displayed_rows, st_rowheight, nil, parent_frame) | |
| 322 ST:Hide() | |
| 323 | |
| 324 ST:SetData(permissions, --[[minimal format=]]true) | |
| 325 ST:RegisterEvents{ | |
| 326 OnEnter = st_OnEnter, | |
| 327 OnLeave = st_OnLeave, | |
| 328 OnClick = st_OnClick, | |
| 329 OnDoubleClick = st_OnClick, | |
| 330 } | |
| 331 | |
| 332 return ST | |
| 333 end | |
| 334 | |
| 335 function addon:BuildVaultSTs (permissions, parent_frame) | |
| 336 self.vault_sts = {} | |
| 337 local cols = { | |
| 338 self.main_st.st.cols[1], | |
| 339 { name = GUILDCONTROL_VIEW_TAB, width = 80 }, | |
| 340 { name = GUILDCONTROL_DEPOSIT_ITEMS, width = 80 }, | |
| 341 { name = GUILDCONTROL_UPDATE_TEXT, width = 80 }, | |
| 342 { name = GUILDCONTROL_WITHDRAW_ITEMS, width = 150 }, | |
| 343 } | |
| 344 | |
| 345 for tab = 1, #permissions do | |
| 346 local ST = LibStub("ScrollingTable"):CreateST (cols, st_displayed_rows, st_rowheight, nil, parent_frame) | |
| 347 ST:Hide() | |
| 348 ST:SetData(permissions[tab], --[[minimal format=]]true) | |
| 349 ST:RegisterEvents{ | |
| 350 OnEnter = st_OnEnter, | |
| 351 OnLeave = st_OnLeave, | |
| 352 OnClick = st_OnClick, | |
| 353 OnDoubleClick = st_OnClick, | |
| 354 } | |
| 355 self.vault_sts[tab] = ST | |
| 356 end | |
| 357 end | |
| 358 | |
| 359 | |
| 360 function addon:BuildWindow() | |
| 361 local need_tabs | |
| 362 if self.display then | |
| 363 self.display:Hide() | |
| 364 else | |
| 365 self.display = AceGUI:Create("Frame") | |
| 366 self.display:SetTitle("Which Rank Does What") | |
| 367 self.display:SetLayout("Fill") | |
| 368 self.display:SetStatusTable{ | |
| 369 width = 1225, | |
| 370 height = 500, | |
| 371 } | |
| 372 self.display:ApplyStatus() | |
| 373 self.display:SetCallback("OnClose", function(_d) | |
| 374 if incomplete or (not self.perms) then | |
| 375 -- stuff changed while open | |
| 376 self.perms = nil | |
| 377 self.display = nil | |
| 378 sidetabs = nil | |
| 379 AceGUI:Release(_d) | |
| 380 end | |
| 381 end) | |
| 382 if self.display.EnableResize then | |
| 383 self.display:EnableResize(false) | |
| 384 end | |
| 385 need_tabs = true | |
| 386 end | |
| 387 | |
| 388 if not self.perms then | |
| 389 need_tabs = true | |
| 390 self:BuildPerms() -- creates self.perms and self.vault | |
| 391 DisownChildren(self.display) | |
| 392 -- Could be new rows, fewer rows, changed tickboxes... ugh, trying to | |
| 393 -- update the scrolltable is a pain. Throw it out and start over. | |
| 394 if self.main_st and self.main_st.st then | |
| 395 self.main_st:Release() | |
| 396 end | |
| 397 if self.vault_sts then for i = 1, #self.vault_sts do | |
| 398 if self.vault_sts[i] and self.vault_sts[i].st then | |
| 399 self.vault_sts[i]:Release() | |
| 400 end | |
| 401 end end | |
| 402 self.main_st = nil | |
| 403 self.vault_sts = nil | |
| 404 end | |
| 405 if not self.main_st then | |
| 406 local st = self:BuildMainST (self.perms, self.display.content) | |
| 407 self.main_st = AceGUI:Create("lib-st"):WrapST(st) | |
| 408 self.main_st.head_offset = 20 | |
| 409 --st_widget.tail_offset = 5 | |
| 410 self.display:AddChild(self.main_st) | |
| 411 | |
| 412 self:BuildVaultSTs (self.vault, self.display.content) | |
| 413 for i,st in ipairs(self.vault_sts) do | |
| 414 self.vault_sts[i] = AceGUI:Create("lib-st"):WrapST(st) | |
| 415 self.vault_sts[i].head_offset = 20 | |
| 416 end | |
| 417 end | |
| 418 | |
| 419 if need_tabs or incomplete then | |
| 420 local maintab = make_sidetab(1, function (this, id) | |
| 421 DisownChildren(self.display) | |
| 422 self.display:AddChild(self.main_st) | |
| 423 end) | |
| 424 maintab.tooltip = [[Rank permissions]] | |
| 425 maintab:SetChecked(true) | |
| 426 self:BuildVaultTabs() | |
| 427 end | |
| 428 | |
| 429 self.display:Show() | |
| 430 return self.display | |
| 431 end | |
| 432 | |
| 433 -- vim:noet |
