vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Guild Event Manager by Kiki of European Cho'gall (Alliance) |
||
3 | Calendar module - By Kiki |
||
4 | ]] |
||
5 | |||
6 | --------------- Local variables --------------- |
||
7 | local GEM_CALENDAR_CBFunc = nil; |
||
8 | local GEM_CALENDAR_UserData = nil; |
||
9 | |||
10 | local GEM_EVENT_CALENDAR_INSTANCE_NONE = 0; |
||
11 | local GEM_EVENT_CALENDAR_INSTANCE_ONYXIA = 1; |
||
12 | local GEM_EVENT_CALENDAR_INSTANCE_MC = 2; |
||
13 | local GEM_EVENT_CALENDAR_INSTANCE_BWL = 3; |
||
14 | local GEM_EVENT_CALENDAR_INSTANCE_ZG = 4; |
||
15 | local GEM_EVENT_CALENDAR_INSTANCE_AQ20 = 5; |
||
16 | local GEM_EVENT_CALENDAR_INSTANCE_AQ40 = 6; |
||
17 | |||
18 | GEM_EVENT_CALENDAR_Resets = { |
||
19 | [GEM_EVENT_CALENDAR_INSTANCE_NONE] = { name=GEM_EVENT_CALENDAR_INSTANCE_NONE_NAME; }; |
||
20 | [GEM_EVENT_CALENDAR_INSTANCE_ONYXIA] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_1; delay=24*60*60* 5; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\onx"; name=GEM_EVENT_CALENDAR_INSTANCE_ONYXIA_NAME; }; |
||
21 | [GEM_EVENT_CALENDAR_INSTANCE_MC] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_2; delay=24*60*60* 7; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\mc"; name=GEM_EVENT_CALENDAR_INSTANCE_MC_NAME; }; |
||
22 | [GEM_EVENT_CALENDAR_INSTANCE_BWL] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_2; delay=24*60*60* 7; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\bwl"; name=GEM_EVENT_CALENDAR_INSTANCE_BWL_NAME; }; |
||
23 | [GEM_EVENT_CALENDAR_INSTANCE_ZG] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_3; delay=24*60*60* 3; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\zg"; name=GEM_EVENT_CALENDAR_INSTANCE_ZG_NAME; }; |
||
24 | [GEM_EVENT_CALENDAR_INSTANCE_AQ20] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_3; delay=24*60*60* 3; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\aq20"; name=GEM_EVENT_CALENDAR_INSTANCE_AQ20_NAME; }; |
||
25 | [GEM_EVENT_CALENDAR_INSTANCE_AQ40] = { start=GEM_EVENT_CALENDAR_INSTANCE_FIRST_RESET_TIME_2; delay=24*60*60* 7; texture="Interface\\AddOns\\GuildEventManager2\\images\\"..GEM_EVENT_CALENDAR_INSTANCE_IMAGES_DIR.."\\aq40"; name=GEM_EVENT_CALENDAR_INSTANCE_AQ40_NAME; }; |
||
26 | }; |
||
27 | |||
28 | |||
29 | --------------- Internal functions --------------- |
||
30 | |||
31 | local function GEMEventCalendar_DrawTexture(parent,line,row,start_tim,ShowReset) |
||
32 | if(ShowReset ~= 0) -- Draw reset days |
||
33 | then |
||
34 | local diff = start_tim - GEM_EVENT_CALENDAR_Resets[ShowReset].start; |
||
35 | local result = math.mod(diff,GEM_EVENT_CALENDAR_Resets[ShowReset].delay); |
||
36 | if(result < 24*60*60) |
||
37 | then |
||
38 | getglobal(parent:GetName().."Day"..line..row.."Texture"):SetTexture(GEM_EVENT_CALENDAR_Resets[ShowReset].texture); |
||
39 | return; |
||
40 | end |
||
41 | end |
||
42 | end |
||
43 | |||
44 | function GEMEventCalendar_DrawDays(parent,tim,ShowReset) |
||
45 | local today = date("*t"); |
||
46 | |||
47 | -- Clear all days |
||
48 | for i=1,6 do |
||
49 | for j=1,7 do |
||
50 | getglobal(parent:GetName().."Day"..i..j.."Text"):SetText(""); |
||
51 | getglobal(parent:GetName().."Day"..i..j.."Texture"):SetTexture(""); |
||
52 | getglobal(parent:GetName().."Day"..i..j):Hide(); |
||
53 | end |
||
54 | end |
||
55 | |||
56 | -- Compute starting month day |
||
57 | local tab = date("*t",tim); |
||
58 | local day = 1; |
||
59 | local line = 1; |
||
60 | local row = 1; |
||
61 | local current_month = tab.month; |
||
62 | tab.hour = 12; |
||
63 | tab.min = 1; |
||
64 | tab.sec = 1; |
||
65 | tim = time(tab); |
||
66 | local start_tim = tim - ((tab.day-1) * 60*60*24); -- Rewind (tab.day - 1) days |
||
67 | tab = date("*t",start_tim); |
||
68 | |||
69 | -- Display all valid days |
||
70 | while tab.month == current_month |
||
71 | do |
||
72 | if(tab.wday < row) -- Changed line |
||
73 | then |
||
74 | line = line + 1; |
||
75 | end |
||
76 | row = tab.wday; |
||
77 | getglobal(parent:GetName().."Day"..line..row.."Text"):SetText(day); |
||
78 | getglobal(parent:GetName().."Day"..line..row):Show(); |
||
79 | getglobal(parent:GetName().."Day"..line..row).time = start_tim; |
||
80 | if(today.year == tab.year and today.yday == tab.yday) |
||
81 | then |
||
82 | getglobal(parent:GetName().."Day"..line..row.."Text"):SetTextColor(0.1,0.8,0.1); |
||
83 | else |
||
84 | getglobal(parent:GetName().."Day"..line..row.."Text"):SetTextColor(1.0,0.7,0.15); |
||
85 | end |
||
86 | GEMEventCalendar_DrawTexture(parent,line,row,start_tim,ShowReset); |
||
87 | day = day + 1; |
||
88 | start_tim = start_tim + 60*60*24; -- Increment day |
||
89 | tab = date("*t",start_tim); |
||
90 | end |
||
91 | end |
||
92 | |||
93 | local function GEMCalendar_DrawDays(tim) |
||
94 | local today = date("*t"); |
||
95 | |||
96 | -- Clear all days |
||
97 | for i=1,6 do |
||
98 | for j=1,7 do |
||
99 | getglobal("GEMCalendarDay"..i..j):SetText(""); |
||
100 | getglobal("GEMCalendarDay"..i..j):Hide(); |
||
101 | end |
||
102 | end |
||
103 | |||
104 | -- Compute starting month day |
||
105 | local tab = date("*t",tim); |
||
106 | local day = 1; |
||
107 | local line = 1; |
||
108 | local row = 1; |
||
109 | local current_month = tab.month; |
||
110 | tab.hour = 12; |
||
111 | tab.min = 1; |
||
112 | tab.sec = 1; |
||
113 | tim = time(tab); |
||
114 | local start_tim = tim - ((tab.day-1) * 60*60*24); -- Rewind (tab.day - 1) days |
||
115 | tab = date("*t",start_tim); |
||
116 | |||
117 | -- Display all valid days |
||
118 | while tab.month == current_month |
||
119 | do |
||
120 | if(tab.wday < row) -- Changed line |
||
121 | then |
||
122 | line = line + 1; |
||
123 | end |
||
124 | row = tab.wday; |
||
125 | getglobal("GEMCalendarDay"..line..row):SetText(day); |
||
126 | getglobal("GEMCalendarDay"..line..row):Show(); |
||
127 | getglobal("GEMCalendarDay"..line..row).time = start_tim; |
||
128 | if(today.year == tab.year and today.yday == tab.yday) |
||
129 | then |
||
130 | getglobal("GEMCalendarDay"..line..row.."Text"):SetTextColor(0.1,0.8,0.1); |
||
131 | else |
||
132 | getglobal("GEMCalendarDay"..line..row.."Text"):SetTextColor(1.0,0.7,0.15); |
||
133 | end |
||
134 | day = day + 1; |
||
135 | start_tim = start_tim + 60*60*24; -- Increment day |
||
136 | tab = date("*t",start_tim); |
||
137 | end |
||
138 | end |
||
139 | |||
140 | |||
141 | --------------- From XML functions --------------- |
||
142 | --[[ |
||
143 | function GEMCalendar_EventOnHover() |
||
144 | GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT"); |
||
145 | GameTooltip:AddLine("Coucou "..this:GetID()); |
||
146 | GameTooltip:Show(); |
||
147 | end |
||
148 | ]] |
||
149 | |||
150 | function GEMCalendar_OnClick() |
||
151 | local tab = date("*t",this.time); |
||
152 | tab.hour = getglobal("GEMCalendarHourDropDown").hour; |
||
153 | tab.min = getglobal("GEMCalendarMinuteDropDown").min; |
||
154 | tab.sec = 0; |
||
155 | if(GEM_CALENDAR_CBFunc) |
||
156 | then |
||
157 | GEM_CALENDAR_CBFunc(time(tab),GEM_CALENDAR_UserData); |
||
158 | end |
||
159 | GEMCalendarFrame:Hide(); |
||
160 | end |
||
161 | |||
162 | function GEMCalendar_OnShow() |
||
163 | GEMCalendar_DrawDays(time()); |
||
164 | end |
||
165 | |||
166 | function GEMCalendarMonthDropDown_OnShow() |
||
167 | local tab = date("*t"); |
||
168 | getglobal("GEMCalendarMonthDropDown").month = tab.month; |
||
169 | UIDropDownMenu_Initialize(GEMCalendarMonthDropDown, GEMCalendarMonthDropDown_Init); |
||
170 | UIDropDownMenu_SetText(GEMCalendar_Month[tab.month], GEMCalendarMonthDropDown); |
||
171 | UIDropDownMenu_SetWidth(70, GEMCalendarMonthDropDown); |
||
172 | end |
||
173 | |||
174 | function GEMCalendarMonthDropDown_OnClick() |
||
175 | local tab = date("*t"); |
||
176 | getglobal("GEMCalendarMonthDropDown").month = this.value; |
||
177 | tab.day = 1; |
||
178 | tab.month = getglobal("GEMCalendarMonthDropDown").month; |
||
179 | tab.year = getglobal("GEMCalendarYearDropDown").year; |
||
180 | GEMCalendar_DrawDays(time(tab)); |
||
181 | UIDropDownMenu_SetText(GEMCalendar_Month[this.value], GEMCalendarMonthDropDown); |
||
182 | end |
||
183 | |||
184 | function GEMCalendarMonthDropDown_Init() |
||
185 | for i,month in GEMCalendar_Month do |
||
186 | local info = { }; |
||
187 | info.text = month; |
||
188 | info.value = i; |
||
189 | info.func = GEMCalendarMonthDropDown_OnClick; |
||
190 | UIDropDownMenu_AddButton(info); |
||
191 | end |
||
192 | end |
||
193 | -- |
||
194 | function GEMCalendarYearDropDown_OnShow() |
||
195 | local tab = date("*t"); |
||
196 | getglobal("GEMCalendarYearDropDown").year = tab.year; |
||
197 | UIDropDownMenu_Initialize(GEMCalendarYearDropDown, GEMCalendarYearDropDown_Init); |
||
198 | UIDropDownMenu_SetText(tab.year, GEMCalendarYearDropDown); |
||
199 | UIDropDownMenu_SetWidth(58, GEMCalendarYearDropDown); |
||
200 | end |
||
201 | |||
202 | function GEMCalendarYearDropDown_OnClick() |
||
203 | local tab = date("*t"); |
||
204 | getglobal("GEMCalendarYearDropDown").year = this.value; |
||
205 | tab.day = 1; |
||
206 | tab.month = getglobal("GEMCalendarMonthDropDown").month; |
||
207 | tab.year = getglobal("GEMCalendarYearDropDown").year; |
||
208 | GEMCalendar_DrawDays(time(tab)); |
||
209 | UIDropDownMenu_SetText(this.value,GEMCalendarYearDropDown); |
||
210 | end |
||
211 | |||
212 | function GEMCalendarYearDropDown_Init() |
||
213 | for i=2005,2008 do |
||
214 | local info = { }; |
||
215 | info.text = i; |
||
216 | info.value = i; |
||
217 | info.func = GEMCalendarYearDropDown_OnClick; |
||
218 | UIDropDownMenu_AddButton(info); |
||
219 | end |
||
220 | end |
||
221 | -- |
||
222 | function GEMCalendarHourDropDown_OnShow() |
||
223 | getglobal("GEMCalendarHourDropDown").hour = 20; |
||
224 | UIDropDownMenu_Initialize(GEMCalendarHourDropDown, GEMCalendarHourDropDown_Init); |
||
225 | UIDropDownMenu_SetText("20h", GEMCalendarHourDropDown); |
||
226 | UIDropDownMenu_SetWidth(48, GEMCalendarHourDropDown); |
||
227 | end |
||
228 | |||
229 | function GEMCalendarHourDropDown_OnClick() |
||
230 | getglobal("GEMCalendarHourDropDown").hour = this.value; |
||
231 | if(this.value < 10) |
||
232 | then |
||
233 | UIDropDownMenu_SetText("0"..this.value.."h",GEMCalendarHourDropDown); |
||
234 | else |
||
235 | UIDropDownMenu_SetText(this.value.."h",GEMCalendarHourDropDown); |
||
236 | end |
||
237 | end |
||
238 | |||
239 | function GEMCalendarHourDropDown_Init() |
||
240 | for i=0,23 do |
||
241 | local info = { }; |
||
242 | if(i < 10) |
||
243 | then |
||
244 | info.text = "0"..i.."h"; |
||
245 | else |
||
246 | info.text = i.."h"; |
||
247 | end |
||
248 | info.value = i; |
||
249 | info.func = GEMCalendarHourDropDown_OnClick; |
||
250 | UIDropDownMenu_AddButton(info); |
||
251 | end |
||
252 | end |
||
253 | -- |
||
254 | function GEMCalendarMinuteDropDown_OnShow() |
||
255 | getglobal("GEMCalendarMinuteDropDown").min = 0; |
||
256 | UIDropDownMenu_Initialize(GEMCalendarMinuteDropDown, GEMCalendarMinuteDropDown_Init); |
||
257 | UIDropDownMenu_SetText("00", GEMCalendarMinuteDropDown); |
||
258 | UIDropDownMenu_SetWidth(40, GEMCalendarMinuteDropDown); |
||
259 | end |
||
260 | |||
261 | function GEMCalendarMinuteDropDown_OnClick() |
||
262 | getglobal("GEMCalendarMinuteDropDown").min = this.value; |
||
263 | if(this.value < 10) |
||
264 | then |
||
265 | UIDropDownMenu_SetText("0"..this.value,GEMCalendarMinuteDropDown); |
||
266 | else |
||
267 | UIDropDownMenu_SetText(this.value,GEMCalendarMinuteDropDown); |
||
268 | end |
||
269 | end |
||
270 | |||
271 | function GEMCalendarMinuteDropDown_Init() |
||
272 | for i=0,45,15 do |
||
273 | local info = { }; |
||
274 | if(i < 10) |
||
275 | then |
||
276 | info.text = "0"..i; |
||
277 | else |
||
278 | info.text = i; |
||
279 | end |
||
280 | info.value = i; |
||
281 | info.func = GEMCalendarMinuteDropDown_OnClick; |
||
282 | UIDropDownMenu_AddButton(info); |
||
283 | end |
||
284 | end |
||
285 | |||
286 | |||
287 | --------------- GUI Exported functions --------------- |
||
288 | |||
289 | --[[ |
||
290 | function GEMCalendar_PickupDate : |
||
291 | Opens the calendar |
||
292 | CBFunc : Function -- The CB function : void (*func)(sel_date,user_data) -- Called with the selected date (hour/minute undefined) |
||
293 | user_data : any -- User data returned in the callback |
||
294 | -- |
||
295 | Returns false if Calendar is already open, True otherwise |
||
296 | ]] |
||
297 | function GEMCalendar_PickupDate(CBFunc,user_data) |
||
298 | if(GEMCalendarFrame:IsVisible()) |
||
299 | then |
||
300 | return false; |
||
301 | end |
||
302 | GEM_CALENDAR_CBFunc = CBFunc; |
||
303 | GEM_CALENDAR_UserData = user_data; |
||
304 | GEMCalendarFrame:Show(); |
||
305 | return true; |
||
306 | end |
||
307 | |||
308 | -- /script GEMCalendar_PickupDate(nil) |