DayOfWeekControl = class(Turbine.UI.Control);
function DayOfWeekControl:Constructor(numDays, selection)
Turbine.UI.Control.Constructor(self);
self.selection = selection or 1;
self:SetNumDays(numDays or 1);
end
function DayOfWeekControl:SetNumDays(numDays)
self:GetControls():Clear();
if (numDays > 14) then
return error("TBI");
end
if (self.selection > numDays) then
self.selection = numDays;
end
local prevContext = L:SetContext("/Time/DayOfWeek");
local font = Turbine.UI.Lotro.Font.Verdana14;
local function AddPulldown(left, top, width, options, value)
local dropDown = Thurallor.UI.DropDown(options, value);
dropDown:SetAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
dropDown:SetParent(self);
dropDown:SetFont(font);
dropDown:SetZOrder(1);
dropDown:SetPosition(left, top);
dropDown:SetWidth(width);
return dropDown, left + width, top + dropDown:GetHeight();
end
-- Create localized strings for pulldown menu.
local dateInfo = Turbine.Engine.GetDate();
local dayOfWeek = dateInfo.DayOfWeek;
local label = Turbine.UI.Label();
label:SetFont(font);
self.pulldownWidth = 0;
self.weekdays = {};
local dayNames = {};
for d, dayName in ipairs({ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }) do
table.insert(dayNames, L:GetText("/Time/DayOfWeek/" .. dayName));
end
for day = dayOfWeek, dayOfWeek + numDays - 1 do
local text = "<weekday>";
if (day == dayOfWeek) then
text = L:GetText("/Time/DayOfWeek/Today");
elseif (day == dayOfWeek + 1) then
text = L:GetText("/Time/DayOfWeek/Tomorrow");
elseif (day >= dayOfWeek + 7) then
text = L:GetText("/Time/DayOfWeek/Next");
end
local dayNum = (day - 1) % 7 + 1;
text = string.gsub(text, "<weekday>", dayNames[dayNum]);
table.insert(self.weekdays, text);
label:SetText(text);
label:AutoSize();
self.pulldownWidth = math.max(self.pulldownWidth, label:GetWidth() + 8);
end
self.numValidSelections = #self.weekdays;
if (self.selection == 0) then
table.insert(self.weekdays, "...");
self.selection = #self.weekdays;
end
local top, left = 0, 0;
self.pulldown, left, top = AddPulldown(left, top, self.pulldownWidth, self.weekdays, self.weekdays[self.selection]);
AddCallback(self.pulldown, "MouseClick", function(_, args)
DoCallbacks(self, "MouseClick", args);
end);
self.pulldown.ItemChanged = function(_, args)
local newSelection = args.Index;
if (newSelection <= self.numValidSelections) then
self.selection = newSelection;
DoCallbacks(self, "SelectionChanged", args.Index);
end
end
self:SetSize(left, top);
L:SetContext(prevContext);
end
function DayOfWeekControl:GetSelection()
return self.selection;
end