vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 TITAN_ITEMBONUSES_ID = "ItemBonuses";
2  
3 TitanItemBonuses_bonuses = {};
4 TitanItemBonuses_active = nil;
5  
6 function TitanPanelItemBonusesButton_OnLoad()
7 this.registry = {
8 id = TITAN_ITEMBONUSES_ID,
9 builtIn = 1,
10 version = "0.9.1800",
11 menuText = TITAN_ITEMBONUSES_TEXT,
12 buttonTextFunction = "TitanPanelItemBonusesButton_GetButtonText",
13 tooltipTitle = TITAN_ITEMBONUSES_TEXT,
14 tooltipTextFunction = "TitanPanelItemBonusesButton_GetTooltipText",
15 icon = "Interface\\Icons\\Spell_Nature_EnchantArmor.blp";
16 iconWidth = 16,
17 savedVariables = {
18 ShowLabelText = 1,
19 ShowColoredText = 0,
20 ShowIcon = 1,
21 shortdisplay = 0,
22 displaybonuses = {},
23 }
24 };
25  
26 this:RegisterEvent("PLAYER_ENTERING_WORLD");
27 this:RegisterEvent("UNIT_INVENTORY_CHANGED");
28 end
29  
30 function TitanPanelItemBonusesButton_FormatShortText(short,val)
31 local color = 'FFFFFF';
32 local text = string.sub(short,2);
33 local colorcode = string.sub(short,1,1);
34 if(TitanItemBonuses_colors[colorcode]) then
35 color = TitanItemBonuses_colors[colorcode];
36 end;
37 if(val) then
38 return '|cff'.. color .. val .. FONT_COLOR_CODE_CLOSE
39 else
40 return '|cff'.. color .. text .. FONT_COLOR_CODE_CLOSE
41 end;
42 end
43  
44  
45 function TitanPanelItemBonusesButton_GetButtonText(id)
46 local title = TITAN_ITEMBONUSES_TEXT;
47 local text = "";
48 local disp = TitanGetVar(TITAN_ITEMBONUSES_ID, "displaybonuses");
49 -- preventing getting inaccessible due to no display at all
50 if( (not disp or (table.getn(disp) == 0))
51 and not TitanGetVar(TITAN_ITEMBONUSES_ID, "ShowLabelText")
52 and not TitanGetVar(TITAN_ITEMBONUSES_ID, "ShowIcon")) then
53 TitanSetVar(TITAN_ITEMBONUSES_ID, "ShowLabelText", 1);
54 TitanPanelButton_UpdateButton(TITAN_ITEMBONUSES_ID);
55 end;
56  
57 local i,d,e;
58 local liste = {};
59 for i,d in disp do
60 e = TITAN_ITEMBONUSES_EFFECTS[d];
61 if(TitanGetVar(TITAN_ITEMBONUSES_ID, "shortdisplay")) then
62 title = TitanPanelItemBonusesButton_FormatShortText(e.short);
63 else
64 title = e.name..": ";
65 end
66 if(TitanItemBonuses_bonuses[e.effect]) then
67 val = TitanItemBonuses_bonuses[e.effect];
68 else
69 val = 0;
70 end
71 text = format(e.format,val);
72 if(TitanGetVar(TITAN_ITEMBONUSES_ID, "ShowColoredText")) then
73 text = TitanPanelItemBonusesButton_FormatShortText(e.short,text);
74 end;
75 table.insert(liste,title);
76 table.insert(liste,TitanUtils_GetHighlightText(text));
77 end;
78  
79 if(table.getn(liste) == 0) then
80 return TITAN_ITEMBONUSES_TEXT,"";
81 end
82 return unpack(liste);
83 end
84  
85 function TitanPanelItemBonusesButton_isdisp(val)
86 local disp = TitanGetVar(TITAN_ITEMBONUSES_ID, "displaybonuses");
87 local i,d;
88 for i,d in disp do
89 if(d==val) then
90 return 1;
91 end
92 end
93 return nil;
94 end
95  
96 function TitanPanelItemBonusesButton_hasdisp()
97 local disp = TitanGetVar(TITAN_ITEMBONUSES_ID, "displaybonuses");
98 if(not disp) then
99 return nil;
100 end
101 return table.getn(disp) > 0;
102 end
103  
104  
105 function TitanPanelItemBonusesButton_GetTooltipText()
106 local retstr,cat,val = "","","","";
107 local i;
108  
109 for i,e in TITAN_ITEMBONUSES_EFFECTS do
110  
111 if(TitanItemBonuses_bonuses[e.effect]) then
112 if(e.format) then
113 val = format(e.format,TitanItemBonuses_bonuses[e.effect]);
114 else
115 val = TitanItemBonuses_bonuses[e.effect];
116 end;
117 if(e.cat ~= cat) then
118 cat = e.cat;
119 if(retstr ~= "") then
120 retstr = retstr .. "\n"
121 end
122 retstr = retstr .. "\n" .. TitanUtils_GetGreenText(getglobal('TITAN_ITEMBONUSES_CAT_'..cat)..":");
123 end
124  
125 retstr = retstr.. "\n".. e.name..":\t".. TitanUtils_GetHighlightText(val);
126 end
127 end
128 return retstr;
129 end
130  
131 function TitanPanelItemBonusesButton_OnEvent()
132 if (event == "PLAYER_ENTERING_WORLD") then
133 TitanItemBonuses_active = 1;
134 end
135 if (((event == "PLAYER_ENTERING_WORLD") or (event == "UNIT_INVENTORY_CHANGED")) and TitanItemBonuses_active) then
136 TitanPanelItemBonuses_CalcValues();
137 TitanPanelButton_UpdateButton(TITAN_ITEMBONUSES_ID);
138 end
139 end
140  
141 function TitanPanelRightClickMenu_PrepareItemBonusesMenu()
142 local id = "ItemBonuses";
143 local info = {};
144 local i,cat,disp,val;
145  
146 if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then
147 for i,e in TITAN_ITEMBONUSES_EFFECTS do
148 if(e.cat == this.value) then
149 info = {};
150 info.text = '[' .. TitanPanelItemBonusesButton_FormatShortText(e.short) .. '] ' .. e.name;
151 if(TitanItemBonuses_bonuses[e.effect]) then
152 val = TitanItemBonuses_bonuses[e.effect];
153 info.text = info.text .. " (".. format(e.format,val).. ")";
154 end
155 info.value = i;
156 info.func = TitanPanelItemBonuses_SetDisplay;
157 info.checked = TitanPanelItemBonusesButton_isdisp(i);
158 info.keepShownOnClick = 1;
159 UIDropDownMenu_AddButton(info,UIDROPDOWNMENU_MENU_LEVEL);
160 end
161 end
162 else
163 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_ITEMBONUSES_ID].menuText);
164 TitanPanelRightClickMenu_AddSpacer(UIDROPDOWNMENU_MENU_LEVEL);
165  
166 info = {};
167 info.text = TITAN_ITEMBONUSES_DISPLAY_NONE;
168 info.value = 0;
169 info.func = TitanPanelItemBonuses_SetDisplay;
170 disp = TitanGetVar(TITAN_ITEMBONUSES_ID, "displaybonuses");
171 info.checked = not TitanPanelItemBonusesButton_hasdisp();
172 UIDropDownMenu_AddButton(info);
173  
174 for i,cat in TITAN_ITEMBONUSES_CATEGORIES do
175 info = {};
176 info.text = getglobal('TITAN_ITEMBONUSES_CAT_'..cat);
177 info.hasArrow = 1;
178 info.value = cat;
179 UIDropDownMenu_AddButton(info);
180 end;
181  
182 TitanPanelRightClickMenu_AddSpacer(UIDROPDOWNMENU_MENU_LEVEL);
183  
184 TitanPanelRightClickMenu_AddToggleIcon(TITAN_ITEMBONUSES_ID);
185 TitanPanelRightClickMenu_AddToggleVar(TITAN_ITEMBONUSES_SHORTDISPLAY, TITAN_ITEMBONUSES_ID,'shortdisplay');
186 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_ITEMBONUSES_ID);
187 TitanPanelRightClickMenu_AddToggleColoredText(TITAN_ITEMBONUSES_ID);
188 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, id, TITAN_PANEL_MENU_FUNC_HIDE);
189 end
190 end
191  
192 function TitanPanelItemBonuses_SetDisplay()
193 local db = TitanGetVar(TITAN_ITEMBONUSES_ID, "displaybonuses");
194 local i,d,found;
195 if(this.value == 0) then
196 TitanSetVar(TITAN_ITEMBONUSES_ID, "displaybonuses", {});
197 else
198 found = 0;
199 for i,d in db do
200 if(d == this.value)then
201 found = i;
202 end
203 end
204 if(found > 0) then
205 table.remove(db,found)
206 else
207 while(table.getn(db)>3) do
208 table.remove(db);
209 end;
210 table.insert(db,this.value);
211 end
212 TitanSetVar(TITAN_ITEMBONUSES_ID, "displaybonuses", db);
213 end;
214 TitanPanelButton_UpdateButton(TITAN_ITEMBONUSES_ID);
215 end
216  
217  
218 function TitanPanelItemBonuses_CalcValues()
219  
220 BonusScanner_ScanAll();
221 TitanItemBonuses_bonuses = BonusScanner_bonuses;
222 end
223