Mercurial > wow > ouroloot
comparison text_tabs.lua @ 1:822b6ca3ef89
Import of 2.15, moving to wowace svn.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Sat, 16 Apr 2011 06:03:29 +0000 |
| parents | |
| children | 952c3ac0e783 |
comparison
equal
deleted
inserted
replaced
| 0:0f14a1e5364d | 1:822b6ca3ef89 |
|---|---|
| 1 local addon = select(2,...) | |
| 2 | |
| 3 --[[ Generator: | |
| 4 boolean FUNC (ttype, loot, last_printed, generated, cache) | |
| 5 in TTYPE: the registered text type as passed to register_text_generator | |
| 6 in LOOT: pointer to g_loot table | |
| 7 in LAST_PRINTED: index into loot most recently formatted by this routine | |
| 8 in GENERATED.TTYPE: (string) FIFO buffer for text created by this routine; | |
| 9 other parts of the GUI copy and nil out this string. Do not change | |
| 10 this string, only examine it if needed. If the generator is called | |
| 11 more than once between GUI updates, text will build up here. | |
| 12 in/out GENERATED.TTYPE_pos: if non-nil, this is the saved cursor position in | |
| 13 the text window (so that it stays where the user last left it). | |
| 14 Move it if you're doing something strange with the displayed text. | |
| 15 tmp GENERATED.loc_TTYPE_*: Use as needed. | |
| 16 out CACHE: Empty output table. Accumulate generated lines here, one entry | |
| 17 per visible line. Do not terminate with a newline unless you want | |
| 18 an extra blank line there. | |
| 19 | |
| 20 Preconditions: | |
| 21 + LAST_PRINTED < #LOOT | |
| 22 + all "display-relevant" information for the main Loot tab has been filled | |
| 23 out (e.g., LOOT[i].cols[3] might have extra text, etc) | |
| 24 + LOOT.TTYPE is a non-nil string containing all text in the text box (and | |
| 25 if the user has edited the text box, this string will be updated). Do not | |
| 26 change this, but like GENERATED.TTYPE it is available for examination. | |
| 27 | |
| 28 Return true if text was created, false if nothing was done. | |
| 29 ]] | |
| 30 | |
| 31 --[[ Optional special widgets: | |
| 32 FUNC (ttype, editbox, container, mkbutton) | |
| 33 TTYPE: see above | |
| 34 EDITBOX: the MultiLineEditBox widget | |
| 35 CONTAINER: widget container (already has 'Regenerate' button in it) | |
| 36 MKBUTTON: function to create more AceGUI widgets, as follows: | |
| 37 | |
| 38 mkbutton ("WidgetType", 'display key', "Text On Widget", "the mouseover display text") | |
| 39 mkbutton ( [Button] 'display key', "Text On Widget", "the mouseover display text") | |
| 40 mkbutton ( [Button] [text] "Text On Widget", "the mouseover display text") | |
| 41 | |
| 42 The 'display key' parameter will almost certainly be specified as nil for these functions. | |
| 43 ]] | |
| 44 | |
| 45 local forum_warned_heroic | |
| 46 local warning_text | |
| 47 do | |
| 48 local red = '|cffff0505' | |
| 49 local green = addon.quality_hexes[ITEM_QUALITY_UNCOMMON] | |
| 50 warning_text = ([[%sWARNING:|r Heroic items sharing the same name as normal items often display incorrectly on forums that use the item name as the identifier. Recommend you change the %sItem markup|r dropdown in the right-hand side to %s"[item] by ID"|r and regenerate this loot.]]):format(red, green, green) | |
| 51 end | |
| 52 | |
| 53 local function forum (_, loot, last_printed, generated, cache) | |
| 54 local fmt = OuroLootSV_opts.forum[OuroLootSV_opts.forum_current] or "" | |
| 55 -- if it's capable of handling heroic items, consider them warned already | |
| 56 forum_warned_heroic = forum_warned_heroic or fmt:find'%$I' | |
| 57 | |
| 58 for i = last_printed+1, #loot do | |
| 59 local e = loot[i] | |
| 60 | |
| 61 if e.kind == 'loot' then | |
| 62 -- Assuming nobody names a toon "offspec" or "gvault" | |
| 63 -- 16Apr2011: armory finds 20 Gvaults and 77 Offspecs... hulk smash. | |
| 64 local disp = e.disposition or e.person | |
| 65 if disp == 'offspec' then | |
| 66 disp = e.person .. " " .. 'offspec' | |
| 67 elseif disp == 'gvault' then | |
| 68 --disp = "guild vault (".. e.person .. ")" | |
| 69 disp = "guild vault" | |
| 70 end | |
| 71 if e.extratext_byhand then | |
| 72 disp = disp .. " -- " .. e.extratext | |
| 73 end | |
| 74 if e.is_heroic and not forum_warned_heroic then | |
| 75 forum_warned_heroic = true | |
| 76 addon:Print(warning_text) | |
| 77 end | |
| 78 local t = fmt:gsub('%$I', e.id) | |
| 79 :gsub('%$N', e.itemname) | |
| 80 :gsub('%$X', e.count or "") | |
| 81 :gsub('%$T', disp) | |
| 82 cache[#cache+1] = t | |
| 83 | |
| 84 elseif e.kind == 'boss' and e.reason == 'kill' then | |
| 85 -- first boss in an instance gets an instance tag, others get a blank line | |
| 86 if generated.last_instance == e.instance then | |
| 87 cache[#cache+1] = "" | |
| 88 else | |
| 89 cache[#cache+1] = "\n[b]" .. e.instance .. "[/b]" | |
| 90 generated.last_instance = e.instance | |
| 91 end | |
| 92 cache[#cache+1] = "[i]" .. e.bosskill .. "[/i]" | |
| 93 | |
| 94 elseif e.kind == 'time' then | |
| 95 cache[#cache+1] = "[b]" .. e.startday.text .. "[/b]" | |
| 96 | |
| 97 end | |
| 98 end | |
| 99 return true | |
| 100 end | |
| 101 | |
| 102 local function forum_specials (_,_, container, mkbutton) | |
| 103 local map,current = {} | |
| 104 for label,format in pairs(OuroLootSV_opts.forum) do | |
| 105 table.insert(map,label) | |
| 106 if label == OuroLootSV_opts.forum_current then | |
| 107 current = #map | |
| 108 end | |
| 109 end | |
| 110 | |
| 111 local dd, editbox | |
| 112 dd = mkbutton("Dropdown", nil, "", | |
| 113 [[Chose specific formatting of loot items. See Help tab for more. Regenerate to take effect.]]) | |
| 114 dd:SetFullWidth(true) | |
| 115 dd:SetLabel("Item markup") | |
| 116 dd:SetList(map) | |
| 117 dd:SetValue(current) | |
| 118 dd:SetCallback("OnValueChanged", function(_dd,event,choice) | |
| 119 OuroLootSV_opts.forum_current = map[choice] | |
| 120 forum_warned_heroic = nil | |
| 121 editbox:SetDisabled(map[choice] ~= "Custom...") | |
| 122 end) | |
| 123 container:AddChild(dd) | |
| 124 | |
| 125 editbox = mkbutton("EditBox", nil, OuroLootSV_opts.forum["Custom..."], | |
| 126 [[Format described in Help tab (Generated Text -> Forum Markup).]]) | |
| 127 editbox:SetFullWidth(true) | |
| 128 editbox:SetLabel("Custom:") | |
| 129 editbox:SetCallback("OnEnterPressed", function(_e,event,value) | |
| 130 OuroLootSV_opts.forum["Custom..."] = value | |
| 131 _e.editbox:ClearFocus() | |
| 132 end) | |
| 133 editbox:SetDisabled(OuroLootSV_opts.forum_current ~= "Custom...") | |
| 134 container:AddChild(editbox) | |
| 135 end | |
| 136 | |
| 137 addon:register_text_generator ("forum", [[Forum Markup]], [[BBcode ready for Ouroboros forums]], forum, forum_specials) | |
| 138 | |
| 139 | |
| 140 local function att (_, loot, last_printed, _, cache) | |
| 141 for i = last_printed+1, #loot do | |
| 142 local e = loot[i] | |
| 143 | |
| 144 if e.kind == 'boss' and e.reason == 'kill' then | |
| 145 cache[#cache+1] = ("\n%s -- %s\n%s"):format(e.instance, e.bosskill, e.raiderlist or '<none recorded>') | |
| 146 | |
| 147 elseif e.kind == 'time' then | |
| 148 cache[#cache+1] = e.startday.text | |
| 149 | |
| 150 end | |
| 151 end | |
| 152 return true | |
| 153 end | |
| 154 | |
| 155 local function att_specials (_, editbox, container, mkbutton) | |
| 156 local w = mkbutton("Take Attendance", | |
| 157 [[Take attendance now (will continue to take attendance on each boss kill).]]) | |
| 158 w:SetFullWidth(true) | |
| 159 w:SetCallback("OnClick", function(_w) | |
| 160 local raiders = {} | |
| 161 for i = 1, GetNumRaidMembers() do | |
| 162 table.insert(raiders, (GetRaidRosterInfo(i))) | |
| 163 end | |
| 164 table.sort(raiders) | |
| 165 local h, m = GetGameTime() | |
| 166 local additional = ("Attendance at %s:%s:\n%s"):format(h,m,table.concat(raiders, ", ")) | |
| 167 editbox:SetText(editbox:GetText() .. '\n' .. additional) | |
| 168 end) | |
| 169 container:AddChild(w) | |
| 170 end | |
| 171 | |
| 172 addon:register_text_generator ("attend", [[Attendance]], [[Attendance list for each kill]], att, att_specials) | |
| 173 | |
| 174 -- vim:noet |
