-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventsCalendar.lua
More file actions
274 lines (227 loc) · 9.06 KB
/
EventsCalendar.lua
File metadata and controls
274 lines (227 loc) · 9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
-----------------------------------------------------------------------------------------------
-- Calendar Package for NCSoft's Wildstar.
-- Generates procedural calendars without relying on days of the month tables typically used in
-- lua calendars. Copyright.Thoughtcrime[AllRightsReserved] == true
-- if you use this package, you must include this header.
-- usage: local calendar = Apollo.GetPackage("TC:WSCalendar-1.0").tPackage
-----------------------------------------------------------------------------------------------
local MAJOR, MINOR = "TC:WSCalendar-1.0",1
local APkg = Apollo.GetPackage(MAJOR)
if APkg and (APkg.nVersion or 0) >= MINOR then
return -- no upgrade is needed
end
local LibCalendar = APkg and APkg.tPackage or {}
require "Window"
-----------------------------------------------------------------------------------------------
-- LibCalendar Module Definition
-----------------------------------------------------------------------------------------------
local LibCalendar = {}
local usermonth
local oldcolumn = 1
local monthdayscount
local deaddays = {}
local CalArray = {value = 1, epochtime = 0, GridType = ""}
local CalDisplay = {}
local calcmonth
local column
local row
local ndisplay
local leadingdays
local epochtime
local newepoch
local leadingcolumns
local correction
local tCurrentDay ={}
local trailingdays
local ViewingMonth = {}
local tDisplayedMonth = {}
-----------------------------------------------------------------------------------------------
-- Constants
-----------------------------------------------------------------------------------------------
-- e.g. local kiExampleVariableMax = 999
local kcrSelectedText = ApolloColor.new("UI_BtnTextHoloPressedFlyby")
local kcrNormalText = ApolloColor.new("UI_BtnTextHoloNormal")
local kcrDeadDaysText = ApolloColor.new("darkgray")
-----------------------------------------------------------------------------------------------
-- Init functions
-----------------------------------------------------------------------------------------------
function LibCalendar:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
-- initialize variables here
o.tItems = {} -- keep track of all the list items
o.wndSelectedListItem = nil -- keep track of which list item is currently selected
return o
end
function LibCalendar:Init()
local bHasConfigureFunction = false
local strConfigureButtonText = ""
local tDependencies = {
-- "UnitOrPackageName",
}
Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
end
-----------------------------------------------------------------------------------------------
-- LibCalendar Functions
-----------------------------------------------------------------------------------------------
function LibCalendar:BuildCalendarTable(tDisplayedMonth)
--SendVarToRover("Displayed Month",tDisplayedMonth)
usermonth = tDisplayedMonth.month
oldcolumn = 1
monthdayscount = 1
deaddays = {}
CalArray = {
}
CalDisplay = {}
newepoch = 0
trailingdays = 0
usermonth = tDisplayedMonth.month
column = tonumber(os.date("%w",os.time({year = tDisplayedMonth.year, month = usermonth, day = 1})) + 1)
epochtime = os.time({year = tDisplayedMonth.year, month = usermonth, day = 1})
if column > 1 then
leadingcolumns = column - 1
newepoch = epochtime
for k = leadingcolumns, 1, -1 do
newepoch = epochtime
newepoch = newepoch - 86400*(leadingcolumns)
correction = os.date("%d",newepoch)
print(correction)
table.insert(CalArray, {value = correction, epoch = newepoch, GridType = "Inactive"})
if leadingcolumns > 1 then
leadingcolumns = leadingcolumns - 1
end
end
end
for j = 1, 32, 1 do
calcmonth = tonumber(os.date("%m", os.time({year = tDisplayedMonth.year, month = usermonth, day = j})))
if not calcmonth then return
else
if calcmonth == usermonth then
monthdayscount = monthdayscount + 1
end
end
end
for i = 1, monthdayscount-1, 1 do
column = tonumber(os.date("%w",os.time({year = tDisplayedMonth.year, month = usermonth, day = i})) + 1)
epochtime = os.time({year = tDisplayedMonth.year, month = usermonth, day = i})
ndisplay = i
print(ndisplay)
if i < monthdayscount then
table.insert(CalArray,{value = ndisplay, epoch = epochtime, GridType = "Active"})
end
--Print(tonumber(column))
end
if column < 7 then
trailingdays = 7-column
--Print(trailingdays)
newepoch = epochtime
for m = 1, trailingdays, 1 do
newepoch = newepoch + (86400)
correction = os.date("%d", newepoch)
table.insert(CalArray, {value = correction, epoch = newepoch, GridType = "Inactive"})
end
end
return CalArray
end
--[[ to use the Calendar, you would include something like the following to create your
Calendar Grid.
-----------------------------------------------------------------------------------------------
-- ItemList Functions
-----------------------------------------------------------------------------------------------
-- populate item list
function LibCalendar:ConstructCalendarGrid(list)
-- make sure the item list is empty to start with
-- make sure the item list is empty to start with
self.wndItemList:DestroyChildren()
self.wndSelectedListItem = nil
if list == nil then return
else
for i = 1,#CalArray do
self:AddCalendarItem(i)
end
-- now all the item are added, call ArrangeChildrenVert to list out the list items vertically
self.wndItemList:ArrangeChildrenTiles()
self.wndMain:FindChild("MonthYearDisplay"):SetText(ViewingMonth.strMonth..", "..ViewingMonth.nYear)
end
end
function LibCalendar:AddCalendarItem(i)
-- load the window item for the list item
local wnd = Apollo.LoadForm(self.xmlDoc, "CalendarItem", self.wndItemList, self)
local wndSelectedItemHighlight = wnd:FindChild("SelectedDayHighlight"):Show(false)
-- keep track of the window item created
--self.CalendarItems[i] = wnd
-- give it a piece of data to refer to
local wndDateText = wnd:FindChild("Text")
if wndDateText then -- make sure the text wnd exist
wndDateText:SetText(CalArray[i].value) -- set the item wnd's text to "item i"
if CalArray[i].GridType == "Active" then
wndDateText:SetTextColor(kcrNormalText)
else
wndDateText:SetTextColor(kcrDeadDaysText)
wnd:FindChild("SelectedDayHighlight"):Show(false)
end
wnd:SetData(CalArray[i])
end
end
-- when a list item is selected
function LibCalendar:OnListItemSelected(wndHandler, wndControl)
--SendVarToRover("selected list item",self.wndSelectedListItem)
-- make sure the wndControl is valid
if wndHandler ~= wndControl then
return
end
-- change the old item's text color back to normal color
local wndDateText
if self.wndSelectedListItem ~= nil then
wndDateText = self.wndSelectedListItem:FindChild("Text")
local wndSelectedDay = self.wndSelectedListItem:FindChild("SelectedDayHighlight")
if self.wndSelectedListItem:GetData().GridType == "Active" then
wndDateText:SetTextColor(kcrNormalText)
elseif self.wndSelectedListItem:GetData().GridType == "Inactive" then
wndDateText:SetTextColor(kcrDeadDaysText)
end
wndSelectedDay:Show(false)
end
-- wndControl is the item selected - change its color to selected
self.wndSelectedListItem = wndControl
wndDateText = self.wndSelectedListItem:FindChild("Text")
wndDateText:SetTextColor(kcrSelectedText)
local wndSelectedDay = self.wndSelectedListItem:FindChild("SelectedDayHighlight")
wndSelectedDay:Show(true)
Print( os.date("%x",self.wndSelectedListItem:GetData().epoch) .. " is selected.")
end
-----------------------------------------------------------------------------------------------
-- Button Functions
-----------------------------------------------------------------------------------------------
function LibCalendar:OnNextMonthButton(wndHandler,wndControl, eMouseButton)
local month = tDisplayedMonth.month
month = month + 1
if month > 12 then
month = month - 12
tDisplayedMonth.year = tDisplayedMonth.year + 1
end
tDisplayedMonth.month = month
ViewingMonth = {strMonth = os.date("%B", os.time(tDisplayedMonth)), nYear = os.date("%Y", os.time(tDisplayedMonth))}
self:BuildCalendarTable(tDisplayedMonth)
self:ConstructCalendarGrid(CalArray)
end
function LibCalendar:OnLastMonthButton(wndHandler,wndControl, eMouseButton)
local month = tDisplayedMonth.month
month = month - 1
if month < 1 then
month = month + 12
tDisplayedMonth.year = tDisplayedMonth.year - 1
end
tDisplayedMonth.month = month
ViewingMonth = {strMonth = os.date("%B", os.time(tDisplayedMonth)), nYear = os.date("%Y", os.time(tDisplayedMonth))}
self:BuildCalendarTable(tDisplayedMonth)
self:ConstructCalendarGrid(CalArray)
end
]]--
-----------------------------------------------------------------------------------------------
-- LibCalendar Instance
-----------------------------------------------------------------------------------------------
local LibCalendarInst = LibCalendar:new()
LibCalendarInst:Init()
Apollo.RegisterPackage(LibCalendar, MAJOR, MINOR, {})