vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | TITAN_BAG_ID = "Bag"; |
2 | TITAN_BAG_THRESHOLD_TABLE = { |
||
3 | Values = { 0.5, 0.75 }, |
||
4 | Colors = { GREEN_FONT_COLOR, NORMAL_FONT_COLOR, RED_FONT_COLOR }, |
||
5 | } |
||
6 | |||
7 | function TitanPanelBagButton_OnLoad() |
||
8 | this.registry = { |
||
9 | id = TITAN_BAG_ID, |
||
10 | builtIn = 1, |
||
11 | version = TITAN_VERSION, |
||
12 | menuText = TITAN_BAG_MENU_TEXT, |
||
13 | buttonTextFunction = "TitanPanelBagButton_GetButtonText", |
||
14 | tooltipTitle = TITAN_BAG_TOOLTIP, |
||
15 | tooltipTextFunction = "TitanPanelBagButton_GetTooltipText", |
||
16 | icon = TITAN_ARTWORK_PATH.."TitanBag", |
||
17 | iconWidth = 16, |
||
18 | savedVariables = { |
||
19 | ShowUsedSlots = 1, |
||
20 | CountAmmoPouchSlots = TITAN_NIL, |
||
21 | CountShardBagSlots = TITAN_NIL, |
||
22 | CountProfBagSlots = TITAN_NIL, |
||
23 | ShowIcon = 1, |
||
24 | ShowLabelText = 1, |
||
25 | ShowColoredText = 1, |
||
26 | } |
||
27 | }; |
||
28 | |||
29 | this:RegisterEvent("PLAYER_LEAVING_WORLD"); |
||
30 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
31 | end |
||
32 | |||
33 | function TitanPanelBagButton_OnEvent() |
||
34 | if (event == "PLAYER_LEAVING_WORLD") then |
||
35 | this:UnregisterEvent("BAG_UPDATE"); |
||
36 | this:UnregisterEvent("ITEM_LOCK_CHANGED"); |
||
37 | this:UnregisterEvent("UNIT_MODEL_CHANGED"); |
||
38 | end |
||
39 | |||
40 | if (event == "PLAYER_ENTERING_WORLD") then |
||
41 | this:RegisterEvent("BAG_UPDATE"); |
||
42 | this:RegisterEvent("ITEM_LOCK_CHANGED"); |
||
43 | this:RegisterEvent("UNIT_MODEL_CHANGED"); |
||
44 | end |
||
45 | |||
46 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
47 | end |
||
48 | |||
49 | function TitanPanelBagButton_OnClick(button) |
||
50 | if (button == "LeftButton") then |
||
51 | OpenAllBags(); |
||
52 | end |
||
53 | end |
||
54 | |||
55 | function TitanPanelBagButton_GetButtonText(id) |
||
56 | local button, id = TitanUtils_GetButton(id, true); |
||
57 | local totalSlots, usedSlosts, availableSlots; |
||
58 | local useme; |
||
59 | |||
60 | totalSlots = 0; |
||
61 | usedSlots = 0; |
||
62 | for bag = 0, 4 do |
||
63 | if TitanGetVar(TITAN_BAG_ID, "CountAmmoPouchSlots") and TitanBag_IsAmmoPouch(GetBagName(bag)) then |
||
64 | useme = 1; |
||
65 | elseif TitanGetVar(TITAN_BAG_ID, "CountShardBagSlots") and TitanBag_IsShardBag(GetBagName(bag)) then |
||
66 | useme = 1; |
||
67 | elseif TitanGetVar(TITAN_BAG_ID, "CountProfBagSlots") and TitanBag_IsProfBag(GetBagName(bag)) then |
||
68 | useme = 1; |
||
69 | elseif not TitanBag_IsAmmoPouch(GetBagName(bag)) and not TitanBag_IsShardBag(GetBagName(bag)) and not TitanBag_IsProfBag(GetBagName(bag)) then |
||
70 | useme = 1; |
||
71 | else |
||
72 | useme = 0; |
||
73 | end |
||
74 | |||
75 | if useme == 1 then |
||
76 | local size = GetContainerNumSlots(bag); |
||
77 | if (size and size > 0) then |
||
78 | totalSlots = totalSlots + size; |
||
79 | for slot = 1, size do |
||
80 | if (GetContainerItemInfo(bag, slot)) then |
||
81 | usedSlots = usedSlots + 1; |
||
82 | end |
||
83 | end |
||
84 | end |
||
85 | end |
||
86 | end |
||
87 | availableSlots = totalSlots - usedSlots; |
||
88 | |||
89 | local bagText, bagRichText, color; |
||
90 | if (TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")) then |
||
91 | bagText = format(TITAN_BAG_FORMAT, usedSlots, totalSlots); |
||
92 | else |
||
93 | bagText = format(TITAN_BAG_FORMAT, availableSlots, totalSlots); |
||
94 | end |
||
95 | |||
96 | if ( TitanGetVar(TITAN_BAG_ID, "ShowColoredText") ) then |
||
97 | color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, usedSlots / totalSlots); |
||
98 | bagRichText = TitanUtils_GetColoredText(bagText, color); |
||
99 | else |
||
100 | bagRichText = TitanUtils_GetHighlightText(bagText); |
||
101 | end |
||
102 | |||
103 | return TITAN_BAG_BUTTON_LABEL, bagRichText; |
||
104 | end |
||
105 | |||
106 | function TitanPanelBagButton_GetTooltipText() |
||
107 | return TitanUtils_GetGreenText(TITAN_BAG_TOOLTIP_HINTS); |
||
108 | end |
||
109 | |||
110 | function TitanPanelRightClickMenu_PrepareBagMenu() |
||
111 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_BAG_ID].menuText); |
||
112 | |||
113 | local info = {}; |
||
114 | info.text = TITAN_BAG_MENU_SHOW_USED_SLOTS; |
||
115 | info.func = TitanPanelBagButton_ShowUsedSlots; |
||
116 | info.checked = TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots"); |
||
117 | UIDropDownMenu_AddButton(info); |
||
118 | |||
119 | info = {}; |
||
120 | info.text = TITAN_BAG_MENU_SHOW_AVAILABLE_SLOTS; |
||
121 | info.func = TitanPanelBagButton_ShowAvailableSlots; |
||
122 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")); |
||
123 | UIDropDownMenu_AddButton(info); |
||
124 | |||
125 | TitanPanelRightClickMenu_AddSpacer(); |
||
126 | |||
127 | info = {}; |
||
128 | info.text = TITAN_BAG_MENU_IGNORE_AMMO_POUCH_SLOTS; |
||
129 | info.func = TitanPanelBagButton_ToggleIgnoreAmmoPouchSlots; |
||
130 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "CountAmmoPouchSlots")); |
||
131 | UIDropDownMenu_AddButton(info); |
||
132 | |||
133 | info = {}; |
||
134 | info.text = TITAN_BAG_MENU_IGNORE_SHARD_BAGS_SLOTS; |
||
135 | info.func = TitanPanelBagButton_ToggleIgnoreShardBagSlots; |
||
136 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "CountShardBagSlots")); |
||
137 | UIDropDownMenu_AddButton(info); |
||
138 | |||
139 | info = {}; |
||
140 | info.text = TITAN_BAG_MENU_IGNORE_PROF_BAGS_SLOTS; |
||
141 | info.func = TitanPanelBagButton_ToggleIgnoreProfBagSlots; |
||
142 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "CountProfBagSlots")); |
||
143 | UIDropDownMenu_AddButton(info); |
||
144 | |||
145 | TitanPanelRightClickMenu_AddSpacer(); |
||
146 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_BAG_ID); |
||
147 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_BAG_ID); |
||
148 | TitanPanelRightClickMenu_AddToggleColoredText(TITAN_BAG_ID); |
||
149 | |||
150 | TitanPanelRightClickMenu_AddSpacer(); |
||
151 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_BAG_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
152 | end |
||
153 | |||
154 | function TitanPanelBagButton_ShowUsedSlots() |
||
155 | TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", 1); |
||
156 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
157 | end |
||
158 | |||
159 | function TitanPanelBagButton_ShowAvailableSlots() |
||
160 | TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", nil); |
||
161 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
162 | end |
||
163 | |||
164 | function TitanPanelBagButton_ToggleIgnoreAmmoPouchSlots() |
||
165 | TitanToggleVar(TITAN_BAG_ID, "CountAmmoPouchSlots"); |
||
166 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
167 | end |
||
168 | |||
169 | function TitanPanelBagButton_ToggleIgnoreShardBagSlots() |
||
170 | TitanToggleVar(TITAN_BAG_ID, "CountShardBagSlots"); |
||
171 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
172 | end |
||
173 | |||
174 | function TitanPanelBagButton_ToggleIgnoreProfdBagSlots() |
||
175 | TitanToggleVar(TITAN_BAG_ID, "CountProfBagSlots"); |
||
176 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
177 | end |
||
178 | |||
179 | function TitanBag_IsAmmoPouch(name) |
||
180 | if (name) then |
||
181 | for index, value in TITAN_BAG_AMMO_POUCH_NAMES do |
||
182 | if (string.find(name, value)) then |
||
183 | return true; |
||
184 | end |
||
185 | end |
||
186 | end |
||
187 | return false; |
||
188 | end |
||
189 | |||
190 | function TitanBag_IsShardBag(name) |
||
191 | if (name) then |
||
192 | for index, value in TITAN_BAG_SHARD_BAG_NAMES do |
||
193 | if (string.find(name, value)) then |
||
194 | return true; |
||
195 | end |
||
196 | end |
||
197 | end |
||
198 | return false; |
||
199 | end |
||
200 | |||
201 | function TitanBag_IsProfBag(name) |
||
202 | if (name) then |
||
203 | for index, value in TITAN_BAG_PROF_BAG_NAMES do |
||
204 | if (string.find(name, value)) then |
||
205 | return true; |
||
206 | end |
||
207 | end |
||
208 | end |
||
209 | return false; |
||
210 | end |