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 | ShowIcon = 1, |
||
22 | ShowLabelText = 1, |
||
23 | ShowColoredText = 1, |
||
24 | } |
||
25 | }; |
||
26 | |||
27 | this:RegisterEvent("BAG_UPDATE"); |
||
28 | this:RegisterEvent("ITEM_LOCK_CHANGED"); |
||
29 | this:RegisterEvent("UNIT_MODEL_CHANGED"); |
||
30 | end |
||
31 | |||
32 | function TitanPanelBagButton_OnEvent() |
||
33 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
34 | end |
||
35 | |||
36 | function TitanPanelBagButton_OnClick(button) |
||
37 | if (button == "LeftButton") then |
||
38 | OpenAllBags(); |
||
39 | end |
||
40 | end |
||
41 | |||
42 | function TitanPanelBagButton_GetButtonText(id) |
||
43 | local button, id = TitanUtils_GetButton(id, true); |
||
44 | local totalSlots, usedSlosts, availableSlots; |
||
45 | |||
46 | totalSlots = 0; |
||
47 | usedSlots = 0; |
||
48 | for bag = 0, 4 do |
||
49 | if (TitanGetVar(TITAN_BAG_ID, "CountAmmoPouchSlots") |
||
50 | or not TitanBag_IsAmmoPouch(GetBagName(bag))) then |
||
51 | local size = GetContainerNumSlots(bag); |
||
52 | if (size and size > 0) then |
||
53 | totalSlots = totalSlots + size; |
||
54 | for slot = 1, size do |
||
55 | if (GetContainerItemInfo(bag, slot)) then |
||
56 | usedSlots = usedSlots + 1; |
||
57 | end |
||
58 | end |
||
59 | end |
||
60 | end |
||
61 | end |
||
62 | availableSlots = totalSlots - usedSlots; |
||
63 | |||
64 | local bagText, bagRichText, color; |
||
65 | if (TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")) then |
||
66 | bagText = format(TITAN_BAG_FORMAT, usedSlots, totalSlots); |
||
67 | else |
||
68 | bagText = format(TITAN_BAG_FORMAT, availableSlots, totalSlots); |
||
69 | end |
||
70 | |||
71 | if ( TitanGetVar(TITAN_BAG_ID, "ShowColoredText") ) then |
||
72 | color = TitanUtils_GetThresholdColor(TITAN_BAG_THRESHOLD_TABLE, usedSlots / totalSlots); |
||
73 | bagRichText = TitanUtils_GetColoredText(bagText, color); |
||
74 | else |
||
75 | bagRichText = TitanUtils_GetHighlightText(bagText); |
||
76 | end |
||
77 | |||
78 | return TITAN_BAG_BUTTON_LABEL, bagRichText; |
||
79 | end |
||
80 | |||
81 | function TitanPanelBagButton_GetTooltipText() |
||
82 | return TitanUtils_GetGreenText(TITAN_BAG_TOOLTIP_HINTS); |
||
83 | end |
||
84 | |||
85 | function TitanPanelRightClickMenu_PrepareBagMenu() |
||
86 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_BAG_ID].menuText); |
||
87 | |||
88 | local info = {}; |
||
89 | info.text = TITAN_BAG_MENU_SHOW_USED_SLOTS; |
||
90 | info.func = TitanPanelBagButton_ShowUsedSlots; |
||
91 | info.checked = TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots"); |
||
92 | UIDropDownMenu_AddButton(info); |
||
93 | |||
94 | info = {}; |
||
95 | info.text = TITAN_BAG_MENU_SHOW_AVAILABLE_SLOTS; |
||
96 | info.func = TitanPanelBagButton_ShowAvailableSlots; |
||
97 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "ShowUsedSlots")); |
||
98 | UIDropDownMenu_AddButton(info); |
||
99 | |||
100 | TitanPanelRightClickMenu_AddSpacer(); |
||
101 | |||
102 | info = {}; |
||
103 | info.text = TITAN_BAG_MENU_IGNORE_AMMO_POUCH_SLOTS; |
||
104 | info.func = TitanPanelBagButton_ToggleIgnoreAmmoPouchSlots; |
||
105 | info.checked = TitanUtils_Toggle(TitanGetVar(TITAN_BAG_ID, "CountAmmoPouchSlots")); |
||
106 | UIDropDownMenu_AddButton(info); |
||
107 | |||
108 | TitanPanelRightClickMenu_AddSpacer(); |
||
109 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_BAG_ID); |
||
110 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_BAG_ID); |
||
111 | TitanPanelRightClickMenu_AddToggleColoredText(TITAN_BAG_ID); |
||
112 | |||
113 | TitanPanelRightClickMenu_AddSpacer(); |
||
114 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_BAG_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
115 | end |
||
116 | |||
117 | function TitanPanelBagButton_ShowUsedSlots() |
||
118 | TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", 1); |
||
119 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
120 | end |
||
121 | |||
122 | function TitanPanelBagButton_ShowAvailableSlots() |
||
123 | TitanSetVar(TITAN_BAG_ID, "ShowUsedSlots", nil); |
||
124 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
125 | end |
||
126 | |||
127 | function TitanPanelBagButton_ToggleIgnoreAmmoPouchSlots() |
||
128 | TitanToggleVar(TITAN_BAG_ID, "CountAmmoPouchSlots"); |
||
129 | TitanPanelButton_UpdateButton(TITAN_BAG_ID); |
||
130 | end |
||
131 | |||
132 | function TitanBag_IsAmmoPouch(name) |
||
133 | if (name) then |
||
134 | for index, value in TITAN_BAG_AMMO_POUCH_NAMES do |
||
135 | if (string.find(name, value)) then |
||
136 | return true; |
||
137 | end |
||
138 | end |
||
139 | end |
||
140 | return false; |
||
141 | end |