vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Guild Event Manager by Kiki of European Cho'gall
3 Events list - By Kiki
4 ]]
5  
6 local selectChanItem = nil;
7 local GEM_Conf_ChanList = {};
8  
9 function GEMOptions_Click_Validate()
10 -- Save options
11 local newdf = GEMOptions_DateFormat:GetText();
12 if(newdf == "")
13 then
14 newdf = GEM_DATE_FORMAT;
15 end
16 GEM_Events.DateFormat = newdf;
17  
18 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannel = GEMOptions_ChannelBip:GetChecked();
19 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue = GEMOptions_ChannelBipValue:GetText();
20 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].FilterEvents = GEMOptions_FilterEvents:GetChecked();
21 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].UseServerTime = GEMOptions_DateUseServer:GetChecked();
22  
23 if(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].comment ~= comment)
24 then
25 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].comment = comment;
26 GEM_COM_PlayerInfos();
27 end
28  
29 GEMList_Notify(GEM_NOTIFY_MY_SUBSCRIPTION,""); -- Force update of the list
30 GEM_Toggle();
31 end
32  
33 function GEMOptions_SetBipBoxState()
34 if(GEMOptions_ChannelBip:GetChecked())
35 then
36 GEMOptions_ChannelBipValue:EnableKeyboard(1);
37 GEMOptions_ChannelBipValue:EnableMouse(1);
38 GEMOptions_ChannelBipValue:SetTextColor(1,1,1);
39 else
40 GEMOptions_ChannelBipValue:EnableKeyboard(0);
41 GEMOptions_ChannelBipValue:EnableMouse(0);
42 GEMOptions_ChannelBipValue:SetTextColor(0.5,0.5,0.5);
43 end
44 if(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue)
45 then
46 GEMOptions_ChannelBipValue:SetText(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue);
47 else
48 GEMOptions_ChannelBipValue:SetText("");
49 end
50 end
51  
52 function GEMOptions_OnShow()
53 if(GEM_COM_Channels == nil)
54 then
55 GEMOptionsFrame:Hide();
56 return;
57 end
58  
59 -- Change all that channel part by Add/Remove buttons
60 if(GEM_DefaultSendChannel and GEM_COM_Channels[GEM_DefaultSendChannel]) -- Reset password that might have been lost
61 then
62 GEM_COM_Channels[GEM_DefaultSendChannel].password = GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels[1].password;
63 end
64 -- End of future change
65  
66 if(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName] and GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].comment)
67 then
68 GEMOptions_Comment:SetText(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].comment);
69 else
70 GEMOptions_Comment:SetText("");
71 end
72 GEM_MinimapArcSlider:SetValue(GEM_Events.MinimapArcOffset);
73 GEM_MinimapRadiusSlider:SetValue(GEM_Events.MinimapRadiusOffset);
74 GEMOptions_DateFormat:SetText(GEM_Events.DateFormat);
75 GEMOptions_ChannelBip:SetChecked(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannel);
76 if(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue == nil)
77 then
78 GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue = GEM_PlayerName;
79 end
80 GEMOptions_SetBipBoxState();
81 GEMOptions_FilterEvents:SetChecked(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].FilterEvents);
82 GEMOptions_DateUseServer:SetChecked(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].UseServerTime);
83  
84 GEMOptionsFrameChannelsListAddChannel:SetText("");
85 GEMOptionsFrameChannelsListAddPassword:SetText("");
86 GEMOptionsFrameChannelsListAddAlias:SetText("");
87 GEMOptionsFrameChannelsListAddSlash:SetText("");
88 selectChanItem = nil;
89 GEM_Config_Channels_UpdateList();
90 end
91  
92 --------------------------------------------
93 function GEMOptions_LoadChannelsConfig(pl_name)
94 GEM_COM_Channels = {};
95  
96 if(GEM_Events.realms[GEM_Realm].my_names[pl_name].channels == nil) -- Never init channels
97 then
98 GEM_Events.realms[GEM_Realm].my_names[pl_name].channels = {};
99 GEMOptions_AddChannel(GEM_DEFAULT_CHANNEL,GEM_DEFAULT_PASSWORD,GEM_DEFAULT_ALIAS,GEM_DEFAULT_SLASH);
100 end
101  
102 GEM_DefaultSendChannel = nil;
103 for i,chantab in GEM_Events.realms[GEM_Realm].my_names[pl_name].channels
104 do
105 local channame = chantab.name;
106 GEM_COM_Channels[channame] = {};
107 GEM_COM_Channels[channame].id = 0;
108 if(i == 1)
109 then
110 GEM_COM_Channels[channame].default = true;
111 GEM_DefaultSendChannel = channame;
112 end
113 GEM_COM_Channels[channame].password = chantab.password;
114 GEM_COM_Channels[channame].alias = chantab.alias;
115 GEM_COM_Channels[channame].slash = chantab.slash;
116 GEM_COM_Channels[channame].notify = chantab.notify;
117 GEM_COM_Channels[channame].retries = 0;
118 end
119 end
120  
121 function GEMOptions_AddChannel(channel,password,alias,slash)
122 channel = strlower(channel);
123 if(GEM_COM_Channels[channel] == nil) -- If channel is not in my list, init it
124 then
125 -- Add to saved config
126 table.insert(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels,{ name=channel, password=password, alias=alias, slash=slash });
127  
128 -- Add to running config
129 GEM_COM_Channels[channel] = {};
130 GEM_COM_Channels[channel].id = 0;
131 GEM_COM_Channels[channel].retries = 0;
132 GEM_COM_Channels[channel].password = password;
133 GEM_COM_Channels[channel].alias = alias;
134 GEM_COM_Channels[channel].slash = slash;
135  
136 if(GEM_DefaultSendChannel == nil) -- Only channel we join ?
137 then
138 GEM_DefaultSendChannel = channel;
139 end
140  
141 -- Create Players struct
142 if(GEM_Players[GEM_Realm] == nil) -- First time in this realm
143 then
144 GEM_Players[GEM_Realm] = {};
145 GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEMOptions_AddChannel : First time in Realm "..GEM_Realm..", creating GEM_Players struct");
146 end
147 if(GEM_Players[GEM_Realm][channel] == nil) -- First time in this channel
148 then
149 GEM_Players[GEM_Realm][channel] = {};
150 GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEMOptions_AddChannel : First time in channel "..channel.." for Realm "..GEM_Realm..", creating GEM_Players struct for this channel");
151 end
152 -- Join new channel
153 GEM_InitChannels(false);
154 GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEMOptions_AddChannel : Added new channel : "..channel);
155 end
156 end
157  
158 function GEMOptions_RemoveChannel(channel)
159 if(GEM_COM_Channels[channel]) -- If channel is in my list, remove it
160 then
161 -- Unalias channel
162 GEM_COM_UnAliasChannel(channel,GEM_COM_Channels[channel].alias,GEM_COM_Channels[channel].slash);
163 -- Leave channel
164 GEM_COM_LeaveChannel(channel);
165 --[[while(GetChannelName(channel) ~= 0)
166 do
167 GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEMOptions_RemoveChannel : Waiting for channel "..channel.." leave notification...");
168 end]]
169  
170 -- Remove from running config
171 GEM_COM_Channels[channel] = nil;
172  
173 -- Remove from saved config
174 for i,chantab in GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels
175 do
176 if(chantab.name == channel)
177 then
178 table.remove(GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels,i);
179 break;
180 end
181 end
182  
183 -- Change default channel
184 if(GEM_DefaultSendChannel == channel)
185 then
186 GEM_DefaultSendChannel = nil;
187 for i,chantab in GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels
188 do
189 GEM_DefaultSendChannel = chantab.name;
190 break;
191 end
192 end
193  
194 -- Clear all events from that channel
195 for ev_id,event in GEM_Events.realms[GEM_Realm].events
196 do
197 GEM_CheckEventHasChannel(event);
198 if(not GEM_IsChannelInList(event.channel))
199 then
200 if(not GEM_IsMyReroll(event.leader))
201 then
202 GEM_EVT_ClearEvent(ev_id,"Left channel",true);
203 end
204 end
205 end
206  
207 -- Clear buffered send queue
208 GEM_COM_PurgeQueueMessageForChannel(channel);
209  
210 GEM_ChatDebug(GEM_DEBUG_CHANNEL,"GEMOptions_RemoveChannel : Removed channel : "..channel);
211 end
212 end
213  
214 function GEMOptions_GetComment(pl_name)
215 return "";
216 end
217  
218 function GEMOptions_MustBip(str)
219 local match = GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannelValue;
220 if(not GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].BipOnChannel or match == nil or match == "")
221 then
222 return false;
223 end
224 if(string.find(str,match)) -- Try something like "(^match^) | (^match[%s]) | ([%s]match^) | ([%s]match[%s])"
225 then
226 return true;
227 else
228 return false;
229 end
230 end
231  
232 function GEM_Config_Channels_GetList()
233 GEM_Conf_ChanList = {};
234 for channame, tab in GEM_COM_Channels
235 do
236 local def = false;
237 if(channame == GEM_DefaultSendChannel)
238 then
239 def = true;
240 end
241 tinsert(GEM_Conf_ChanList, { Name = channame; Pwd = tab.password; Slash = tab.slash; Alias = tab.alias; Default = def; Notify = tab.notify } );
242 end
243 return GEM_Conf_ChanList;
244 end
245  
246 local GEM_CHANS_MAX_LIST_ITEMS = 4;
247  
248 function GEM_Config_Channels_UpdateList()
249 if(not GEMOptionsFrame:IsVisible()) then
250 return;
251 end
252 local list = GEM_Config_Channels_GetList();
253 local size = table.getn(list);
254 local enableButtons = false;
255  
256 local offset = FauxScrollFrame_GetOffset(GEMOptionsFrameChannelsListScrollFrame);
257 numButtons = GEM_CHANS_MAX_LIST_ITEMS;
258 i = 1;
259 GEMOptionsFrameChannelsListUpdateButton:Disable();
260 GEMOptionsFrameChannelsListRemoveButton:Disable();
261  
262 while (i <= numButtons) do
263 local j = i + offset
264 local prefix = "GEMOptionsFrameChannelsListItem"..i;
265 local button = getglobal(prefix);
266  
267 if (j <= size) then
268 button.Name = list[j].Name;
269 button.Pwd = list[j].Pwd;
270 button.Alias = list[j].Alias;
271 button.Slash = list[j].Slash;
272 getglobal(prefix.."Name"):SetText(list[j].Name);
273 getglobal(prefix.."Pwd"):SetText(list[j].Pwd);
274 getglobal(prefix.."Alias"):SetText(list[j].Alias);
275 getglobal(prefix.."Slash"):SetText(list[j].Slash);
276 getglobal(prefix.."Notify"):SetChecked(list[j].Notify);
277 button:Show();
278  
279 -- selected
280 if (selectChanItem == list[j].Name) then
281 button:LockHighlight();
282 enableButtons = true;
283 else
284 button:UnlockHighlight();
285 end
286 else
287 button.Name = nil;
288 button:Hide();
289 end
290  
291 i = i + 1;
292 end
293  
294 if(enableButtons)
295 then
296 GEMOptionsFrameChannelsListUpdateButton:Enable();
297 if(table.getn(GEM_Conf_ChanList) > 1)
298 then
299 GEMOptionsFrameChannelsListRemoveButton:Enable();
300 end
301 end
302 FauxScrollFrame_Update(GEMOptionsFrameChannelsListScrollFrame, size, GEM_CHANS_MAX_LIST_ITEMS, 10);
303 end
304  
305 function GEM_Config_UpdateNotify(name,state)
306 for i,infos in GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels
307 do
308 if(infos.name == name)
309 then
310 infos.notify = state;
311 return;
312 end
313 end
314 end
315  
316 function GEM_Config_OnClickNotify(button)
317 local channel = getglobal(button:GetParent():GetName()).Name;
318 if(GEM_COM_Channels[channel])
319 then
320 if(button:GetChecked())
321 then
322 GEM_COM_Channels[channel].notify = true;
323 else
324 GEM_COM_Channels[channel].notify = false;
325 end
326 GEM_Config_UpdateNotify(channel,GEM_COM_Channels[channel].notify);
327 end
328 end
329  
330 function GEM_Config_OnChanSelected(item)
331 selectChanItem = item.Name;
332 GEM_Config_Channels_UpdateList();
333 GEMOptionsFrameChannelsListAddChannel:SetText(item.Name);
334 GEMOptionsFrameChannelsListAddPassword:SetText(item.Pwd);
335 GEMOptionsFrameChannelsListAddAlias:SetText(item.Alias);
336 GEMOptionsFrameChannelsListAddSlash:SetText(item.Slash);
337 end
338  
339 function GEM_Conf_Click_AddChannel()
340 local name = GEMOptionsFrameChannelsListAddChannel:GetText();
341 local pwd = GEMOptionsFrameChannelsListAddPassword:GetText();
342 local alias = GEMOptionsFrameChannelsListAddAlias:GetText();
343 local slash = GEMOptionsFrameChannelsListAddSlash:GetText();
344 if(name == nil or name == "")
345 then
346 GEM_ChatPrint(GEM_TEXT_ERR_NEED_CHANNEL);
347 GEMOptionsFrameChannelsListAddChannel:SetFocus();
348 return;
349 end
350 if(GEM_COM_Channels[name])
351 then
352 GEM_ChatPrint("Already a channel with that name, use the 'Update' button to modify channel configuration.");
353 GEMOptionsFrameChannelsListAddChannel:SetFocus();
354 return;
355 end
356 if(pwd == nil) then pwd = ""; end
357 if(alias == nil) then alias = ""; end
358 if(slash == nil) then slash = ""; end
359 if((alias == "" and slash ~= "") or (alias ~= "" and slash == ""))
360 then
361 if(alias == "")
362 then
363 GEMOptionsFrameChannelsListAddAlias:SetFocus();
364 else
365 GEMOptionsFrameChannelsListAddSlash:SetFocus();
366 end
367 GEM_ChatPrint(GEM_TEXT_ERR_NEED_ALIAS);
368 return;
369 end;
370  
371 GEMOptions_AddChannel(name,pwd,alias,slash);
372 GEM_Config_Channels_UpdateList();
373 end
374  
375 function GEM_Conf_Click_UpdateChannel()
376 local name = GEMOptionsFrameChannelsListAddChannel:GetText();
377 local pwd = GEMOptionsFrameChannelsListAddPassword:GetText();
378 local alias = GEMOptionsFrameChannelsListAddAlias:GetText();
379 local slash = GEMOptionsFrameChannelsListAddSlash:GetText();
380 if(name == nil or name == "")
381 then
382 GEM_ChatPrint(GEM_TEXT_ERR_NEED_CHANNEL);
383 GEMOptionsFrameChannelsListAddChannel:SetFocus();
384 return;
385 end
386 if(name ~= selectChanItem)
387 then
388 GEM_ChatPrint("You must use the 'Add' button to create a new GEM channel");
389 return;
390 end
391 if(pwd == nil) then pwd = ""; end
392 if(alias == nil) then alias = ""; end
393 if(slash == nil) then slash = ""; end
394  
395 if((alias == "" and slash ~= "") or (alias ~= "" and slash == ""))
396 then
397 if(alias == "")
398 then
399 GEMOptionsFrameChannelsListAddAlias:SetFocus();
400 else
401 GEMOptionsFrameChannelsListAddSlash:SetFocus();
402 end
403 GEM_ChatPrint(GEM_TEXT_ERR_NEED_ALIAS);
404 return;
405 end;
406  
407 local GEMchannelName = selectChanItem;
408 local GEMchannelPassword = "";
409 local GEMchannelAlias = "";
410 local GEMchannelSlashCmd = "";
411  
412 if(GEM_COM_Channels[selectChanItem].password) then GEMchannelPassword = GEM_COM_Channels[selectChanItem].password; end
413 if(GEM_COM_Channels[selectChanItem].alias) then GEMchannelAlias = GEM_COM_Channels[selectChanItem].alias; end
414 if(GEM_COM_Channels[selectChanItem].slash) then GEMchannelSlashCmd = GEM_COM_Channels[selectChanItem].slash; end
415  
416 if(name ~= GEMchannelName or pwd ~= GEMchannelPassword or alias ~= GEMchannelAlias or slash ~= GEMchannelSlashCmd)
417 then
418 if(name == GEMchannelName and pwd == GEMchannelPassword) -- Don't remove chan if it is the same (but changing the alias)
419 then
420 for i,chantab in GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].channels
421 do
422 if(chantab.name == name)
423 then
424 chantab.alias = alias;
425 chantab.slash = slash;
426 break;
427 end
428 end
429 if(alias == "") -- No alias anymore
430 then
431 GEM_COM_UnAliasChannel(name,GEM_COM_Channels[name].alias,GEM_COM_Channels[name].slash);
432 GEM_COM_Channels[name].alias = "";
433 GEM_COM_Channels[name].slash = "";
434 else
435 GEM_COM_Channels[name].alias = alias;
436 GEM_COM_Channels[name].slash = slash;
437 GEM_COM_AliasChannel(name,GEM_COM_Channels[name].alias,GEM_COM_Channels[name].slash);
438 end
439 else -- Not the same channel, remove and add new one
440 GEMOptions_RemoveChannel(GEMchannelName);
441 GEMOptions_AddChannel(name,pwd,alias,slash);
442 end
443  
444 -- Force reroll lists to be re-init
445 getglobal("GEMListFrameRerollDropDown").name = nil;
446 getglobal("GEMNewRerollDropDown").name = nil;
447 end
448 GEM_Config_Channels_UpdateList();
449 end
450  
451 function GEM_Conf_Click_DelChannel()
452 if(selectChanItem and selectChanItem ~= "")
453 then
454 GEMOptions_RemoveChannel(selectChanItem);
455 GEM_Config_Channels_UpdateList();
456 end
457 end
458