vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 PetFeederPlayerButtonBar_Vars = { FoodLink = nil, FoodText = "", LoyaltyLevel = 0, LoyaltyText = "", XPCurrent = 0, XPNextLevel = 0 }
2 PetFeederPlayerButtonBar_Config = {Show = 1, Scale = 1}
3  
4 Orig_PetFeeder_UpdateQuantities = nil;
5 Orig_PetFeeder_PopulateFoods = nil
6 PetFeederButtonBar_PetName = nil;
7  
8 local MAX_LEVEL = 60
9  
10 function PetFeederButtonBar_OnLoad()
11 if ( UnitClass("player") ~= PETFEEDER_HUNTER ) then
12  
13 return;
14 end
15 PetFeederButtonBar:RegisterEvent("UNIT_HAPPINESS");
16 PetFeederButtonBar:RegisterEvent("PLAYER_ENTERING_WORLD");
17 PetFeederButtonBar:RegisterEvent("BAG_UPDATE");
18 PetFeederButtonBar:RegisterEvent("VARIABLES_LOADED");
19 PetFeederButtonBar:RegisterEvent("PLAYER_PET_CHANGED");
20 PetFeederButtonBar:RegisterEvent("PET_BAR_UPDATE");
21 PetFeederButtonBar:RegisterEvent("LOCALPLAYER_PET_RENAMED");
22 PetFeederButtonBar:RegisterEvent("UNIT_PET");
23 PetFeederButtonBar:RegisterEvent("UNIT_NAME_UPDATE");
24 PetFeederButtonBar:RegisterEvent("UNIT_PET_EXPERIENCE");
25 if ( PeetFeederPlayer_Config.BarEnabled ) then
26 this:Show();
27 end
28 Orig_PetFeeder_UpdateQuantities = PetFeeder_UpdateQuantities;
29 PetFeeder_UpdateQuantities = PetFeederButtonBar_UpdateQuan;
30 Orig_PetFeeder_PopulateFoods = PetFeeder_PopulateFoods;
31 PetFeeder_PopulateFoods = PetFeederButtonBar_PopulateFoods;
32  
33  
34 end
35  
36  
37 function PetFeederButtonBar_OnEvent()
38 if (event == "PLAYER_ENTERING_WORLD" or event == "VARIABLES_LOADED" ) then
39 local _ , playerClass = UnitClass("player");
40 if ( playerClass ~= "HUNTER" ) then
41 PetFeederButtonBar:Hide();
42 else
43 if ( PeetFeederPlayer_Config.BarEnabled and PeetFeederPlayer_Config.Enabled ) then
44 PetFeederButtonBar:Show();
45 end
46  
47 end
48 elseif ( event == "BAG_UPDATE" ) then
49  
50 PetFeederButtonBar_GetNextFood();
51  
52 elseif ( event == "UNIT_HAPPINESS" ) then
53  
54 PetFeederButtonBar_SetHappiness();
55 elseif ( event == "PET_BAR_UPDATE" or event == "PLAYER_PET_CHANGED" or event == "UNIT_PET" ) then
56 if ( not UnitExists("pet") ) then
57 PetFeederButtonBar:Hide();
58 else
59 PetFeederButtonBar_ShowActions()
60 end
61 elseif ( event == "LOCALPLAYER_PET_RENAMED" or "UNIT_NAME_UPDATE" ) then
62  
63 if ( not PetFeeder_HasPet() ) then
64 return;
65 end
66 if ( PetFeederButtonBar_PetName ~= UnitName("pet") ) then
67 PetFeederButtonBar_PetName = UnitName("pet");
68 else
69 return;
70 end
71 PetFeederButtonBar_ShowActions()
72 elseif ( event == "UNIT_PET_EXPERIENCE" ) then
73 PetFeederButtonBar_SetXPBar();
74 end
75  
76  
77 end
78  
79 function PetFeederButtonBar_ShowActions()
80 if ( PeetFeederPlayer_Config.BarEnabled ) then
81 PetFeederButtonBar:Show();
82 PetFeederButtonBar_SetHappiness();
83 PetFeederButtonBar_GetNextFood();
84 else
85 PetFeederButtonBar:Hide();
86 PetFeederButton_Food:Hide();
87 PetFeederButton_Icon:Hide();
88 PetFeederButton_Happiness:Hide();
89 PetFeederButton_XPBar:Hide();
90 PetFeederButton_LoyaltyBar:Hide();
91 end
92 end
93  
94 function PetFeederButtonBar_OnClick()
95 if (arg1 == "LeftButton") then
96 if ( IsShiftKeyDown() ) then
97 PetFeeder_Feed();
98 end
99 else
100 if (not IsControlKeyDown()) then
101 togglePetFeeder(nil);
102 end
103  
104 end
105 end
106  
107 function PetFeederButtonBar_UpdateQuan()
108 Orig_PetFeeder_UpdateQuantities();
109 PetFeederButtonBar_GetNextFood();
110 end
111  
112 function PetFeederButtonBar_PopulateFoods()
113 Orig_PetFeeder_PopulateFoods();
114 PetFeederButtonBar_GetNextFood();
115 end
116 function PetFeederButtonBar_GetNextFood()
117 if ( not PetFeeder_HasPet() or not PeetFeederPlayer_Config.BarEnabled ) then
118 PetFeederButton_Food:Hide();
119  
120 return;
121 end
122 if ( not PetFeederPlayer_Foods[PetFeeder_PetName] ) then return; end
123  
124 PetFeederButtonBar:Show();
125 PetFeederButton_Food:Show();
126 local count = 0;
127 local found = false;
128 for index, value in PetFeederPlayer_Foods[PetFeeder_PetName] do
129  
130 if ( value.quantity and value.quantity > 0 ) then
131 if ( PeetFeederPlayer_Config.RequireApproval == 1 and value.foodlikedstate == PETFEEDER_FL_UNKNOWN ) or ( (PeetFeederPlayer_Config.FeedOnlyApproved == 1 and value.foodlikedstate == PETFEEDER_FL_APPROVED) or ( PeetFeederPlayer_Config.FeedOnlyApproved == 0 and value.foodlikedstate > 0 ) )then
132 if ( not found ) then
133 local tex = getglobal("PetFeederButton_Food_NormalTexture");
134 tex:SetTexture(value.texture);
135 found = true;
136 PetFeederPlayerButtonBar_Vars.FoodText = value.text;
137 PetFeederPlayerButtonBar_Vars.FoodLink = value.id;
138 end
139 count = count + value.quantity;
140  
141 end
142 end
143 end
144 if ( count == 0 ) then
145 PetFeederButton_Food_NormalTexture:SetTexture("");
146 PetFeederPlayerButtonBar_Vars.FoodText = "";
147 PetFeederPlayerButtonBar_Vars.FoodLink = nil;
148 PetFeederButton_FoodText:SetText("");
149 else
150 PetFeederButton_FoodText:SetText(count);
151 end
152  
153 end
154  
155  
156  
157 function PetFeederButtonBar_SetHappiness()
158 local happiness, damagePercentage, loyaltyRate = GetPetHappiness();
159 -- DEFAULT_CHAT_FRAME:AddMessage("PetFeederButtonBar_SetHappiness");
160 local hasPetUI, isHunterPet = HasPetUI();
161 if ( not happiness or not isHunterPet or not PeetFeederPlayer_Config.BarEnabled ) then
162 PetFeederButton_Happiness:Hide();
163 PetFeederButton_XPBar:Hide();
164 PetFeederButton_LoyaltyBar:Hide();
165 return;
166 end
167 -- DEFAULT_CHAT_FRAME:AddMessage("PetFeederButtonBar_SetHappiness Show");
168 PetFeederButton_Happiness:Show();
169 PetFeederButton_LoyaltyBar:Show();
170 if ( happiness == 1 ) then
171 PetFeederButton_Happiness_NormalTexture:SetTexCoord(0.375, 0.5625, 0, 0.359375);
172 elseif ( happiness == 2 ) then
173 PetFeederButton_Happiness_NormalTexture:SetTexCoord(0.1875, 0.375, 0, 0.359375);
174 elseif ( happiness == 3 ) then
175 PetFeederButton_Happiness_NormalTexture:SetTexCoord(0, 0.1875, 0, 0.359375);
176 end
177 PetFeederButton_Happiness.tooltip = getglobal("PET_HAPPINESS"..happiness);
178 PetFeederButton_Happiness.tooltipDamage = format(PET_DAMAGE_PERCENTAGE, damagePercentage);
179 if ( loyaltyRate < 0 ) then
180 PetFeederButton_Happiness.tooltipLoyalty = getglobal("LOSING_LOYALTY");
181 elseif ( loyaltyRate > 0 ) then
182 PetFeederButton_Happiness.tooltipLoyalty = getglobal("GAINING_LOYALTY");
183 else
184 PetFeederButton_Happiness.tooltipLoyalty = nil;
185 UIErrorsFrame:AddMessage(PETFEEDER_PETHUNGERY, 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
186 end
187  
188  
189 PetFeederButton_Icon_NormalTexture:SetTexture(GetPetIcon());
190 PetFeederButton_IconText:SetText(PetFeederButtonBar_GetLevel());
191 PetFeederButton_Icon:Show();
192 PetFeederButtonBar_SetXPBar();
193 PetFeederButtonBar_SetLoyaltyBar();
194 end
195  
196 function PetFeederButtonBar_GetLevel()
197 local lvl = UnitLevel("pet");
198 return ( lvl == MAX_LEVEL ) and "" or lvl;
199 end
200  
201 function PetFeederButtonBar_SetXPBar()
202 if ( UnitLevel("pet") < MAX_LEVEL and PetFeederButton_Happiness:IsVisible() ) then
203 local currXP, nextXP = GetPetExperience();
204 PetFeederButton_XPBar:SetMinMaxValues(min(0, currXP),nextXP);
205 PetFeederButton_XPBar:SetValue(currXP);
206 PetFeederButton_XPBar:Show();
207 else
208 PetFeederButton_XPBar:Hide();
209 end
210  
211 end
212  
213 function PetFeederButtonBar_SetLoyaltyBar()
214 local loyalty = GetPetLoyalty();
215 if ( loyalty ) then
216 PetFeederPlayerButtonBar_Vars.LoyaltyText = loyalty;
217 local _,_,llvl = string.find(loyalty, "(%d)");
218 if ( tonumber(llvl) < 6 ) then
219 local currXP, nextXP = GetPetExperience();
220 PetFeederButton_LoyaltyBar:SetMinMaxValues(0,6);
221 PetFeederButton_LoyaltyBar:SetValue(tonumber(llvl));
222 PetFeederButton_LoyaltyBar:Show();
223 else
224  
225 PetFeederButton_LoyaltyBar:Hide();
226 end
227 else
228 PetFeederPlayerButtonBar_Vars.LoyaltyText = nil;
229 end
230  
231 end
232  
233 function PetFeederButtonBar_FoodToolTip()
234 if ( PetFeederPlayerButtonBar_Vars.FoodLink ) then
235 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
236 GameTooltip:SetHyperlink("item:"..PetFeederPlayerButtonBar_Vars.FoodLink);
237 GameTooltip:AddLine(" ");
238 GameTooltip:AddLine("("..PETFEEDER_CLICKFEEDPET..")",0,1,0);
239 GameTooltip:Show();
240 end
241 end
242  
243 function PetFeederButtonBar_HappinessToolTip()
244 if ( this.tooltip ) then
245 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
246 GameTooltip:SetText(this.tooltip);
247 if ( this.tooltipDamage ) then
248 GameTooltip:AddLine(this.tooltipDamage, "", 1, 1, 1);
249 end
250 if ( this.tooltipLoyalty ) then
251 GameTooltip:AddLine(this.tooltipLoyalty, "", 1, 1, 1);
252 end
253 GameTooltip:AddLine(PetFeederPlayerButtonBar_Vars.LoyaltyText,0,1,1)
254 GameTooltip:AddLine(" ");
255 GameTooltip:AddLine("("..PETFEEDER_CLICKOPENOPTIONS..")",0,1,0);
256 GameTooltip:Show();
257 end
258 end
259  
260  
261  
262 function PetFeederButtonBar_IconToolTip()
263 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
264 GameTooltip:SetUnit("pet");
265 if ( UnitLevel("pet") < MAX_LEVEL ) then
266 local currXP, nextXP = GetPetExperience();
267 GameTooltip:AddDoubleLine("Current XP:",currXP,0,1,1,1,1,1)
268 GameTooltip:AddDoubleLine("Next Level XP:",nextXP,0,1,1,1,1,1)
269 end
270 GameTooltip:AddLine(" ");
271 GameTooltip:AddLine("("..PETFEEDER_CLICKMOVEBAR..")",0,1,0);
272 GameTooltip:Show();
273 end
274  
275 function PetFeeder_PFB_Enabled_CheckBt_Update(whatValue)
276 PeetFeederPlayer_Config.BarEnabled = whatValue;
277 PetFeederButtonBar_ShowActions();
278 end