ResetTimesDialog = class(Turbine.UI.Lotro.Window);
function ResetTimesDialog:Constructor(event)
Turbine.UI.Lotro.Window.Constructor(self);
local prevContext = L:SetContext("/ResetTimesDialog");
self:SetText(L:GetText("Title"));
self:SetVisible(true);
self.event, self.window = event, event.tab.window;
-- If the event is deleted, we should close this window
self.eventDestroyedFunc = function()
self:Close();
end
-- If the window is closed, we should unregister the callback
self.Closing = function()
RemoveCallback(event, "Destroyed", self.eventDestroyedFunc);
self:SetWantsUpdates(false);
end
-- Register the callback now, but first make sure it isn't already registered
self.Closing();
AddCallback(event, "Destroyed", self.eventDestroyedFunc);
-- Make this window prevent access to the main window while it's open
self:SetZOrder(self.window:GetZOrder() + 1);
self.window:WaitForChild(self);
local resetTimeSpec = self.event:GetResetTimes();
local rotationTimeSpec = self.event:GetRotation();
self.resetTimesCtl = ResetTimesControl(resetTimeSpec, true);
AddCallback(self.resetTimesCtl, "SizeChanged", function()
self:DoLayout();
end);
AddCallback(self.resetTimesCtl, "ValidChanged", function()
self.okButton:UpdateEnabled();
end);
self.rotationCtl = RotationTimesControl(rotationTimeSpec);
AddCallback(self.rotationCtl, "SizeChanged", function()
self:DoLayout();
end);
if (rotationTimeSpec) then
self.selectedCtl = self.rotationCtl;
elseif (resetTimeSpec) then
self.selectedCtl = self.resetTimesCtl;
end
self.window = win;
self.id = id;
self.settings = settings;
-- Handle ENTER and ESC keys
EnableEnterEscHandling(self);
L:SetContext(prevContext);
self:DoLayout();
-- Position this window so its center is at the mouse position
local width, height = self:GetSize();
local x, y = Turbine.UI.Display.GetMousePosition();
local left = math.max(0, x - math.floor(width / 2));
local top = math.max(0, y - math.floor(height / 2));
self:SetPosition(left, top);
EnsureOnScreen(self);
-- Handle ENTER and ESC keys
EnableEnterEscHandling(self);
end
function ResetTimesDialog:DoLayout()
local xmargin = 28;
local top = 39;
local width = self:GetWidth();
local label;
self:GetControls():Clear();
collectgarbage();
local function AddLabel(parent, top, text, height)
local label = Turbine.UI.Label();
label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
label:SetFontStyle(Turbine.UI.FontStyle.Outline);
label:SetOutlineColor(Turbine.UI.Color.Black);
label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
label:SetText(text);
label:SetParent(parent);
label:SetPosition(xmargin, top);
label:AutoSize();
return label, top + height + 10;
end
local function AddRadioButton(parent, top, text, selected)
if (selected) then
text = text .. L:GetText("/QuestRepeatedDialog/Colon");
end
local button = Thurallor.UI.RadioButton(parent, text, selected);
button:SetFont(Turbine.UI.Lotro.Font.Verdana14);
button:SetPosition(2 * xmargin, top);
button:SetSize(width, 14);
return button, top + 20;
end
local function AddButton(parent, left, top, width, text)
local button = Turbine.UI.Lotro.Button();
button:SetParent(parent);
button:SetText(text);
button:SetPosition(left, top);
button:SetWidth(width);
return button;
end
label, top = AddLabel(self, top, L:GetText("/ResetTimesDialog/Description"), 14);
width = label:GetWidth() + 2 * xmargin;
if (self.selectedCtl == self.resetTimesCtl) then
self.dailyBtn, top = AddRadioButton(self, top, L:GetText("/ResetTimesDialog/DailyWeekly"), true);
self.resetTimesCtl:SetParent(self);
self.resetTimesCtl:SetPosition(3 * xmargin, top);
width = self.resetTimesCtl:GetWidth() + 4 * xmargin;
top = top + self.resetTimesCtl:GetHeight() + 10; -- skip some space
else
self.dailyBtn, top = AddRadioButton(self, top, L:GetText("/ResetTimesDialog/DailyWeekly"), false);
self.dailyBtn.Clicked = function()
self.selectedCtl = self.resetTimesCtl;
self:DoLayout();
end
end
if (self.selectedCtl == self.rotationCtl) then
self.rotationBtn, top = AddRadioButton(self, top, L:GetText("/ResetTimesDialog/Rotation"), true);
self.rotationCtl:SetParent(self);
self.rotationCtl:SetPosition(3 * xmargin, top);
width = self.rotationCtl:GetWidth() + 4 * xmargin;
top = top + self.rotationCtl:GetHeight() + 10; -- skip some space
else
self.rotationBtn, top = AddRadioButton(self, top, L:GetText("/ResetTimesDialog/Rotation"), false);
self.rotationBtn.Clicked = function()
self.selectedCtl = self.rotationCtl;
self:DoLayout();
end
end
self.disabledBtn, top = AddRadioButton(self, top, L:GetText("/ResetTimesDialog/Disabled"), false);
self.disabledBtn:SetChecked(self.selectedCtl == nil);
self.disabledBtn.Clicked = function()
self.selectedCtl = nil;
self:DoLayout();
end
Thurallor.UI.RadioButton.LinkPeers({ self.dailyBtn, self.rotationBtn, self.disabledBtn });
local buttons = Turbine.UI.Control();
buttons:SetParent(self);
buttons:SetTop(top);
self.okButton = AddButton(buttons, 0, 0, 50, L:GetText("/ExpireTimeDialog/Ok"));
self.okButton.UpdateEnabled = function()
local enable = true;
if ((self.selectedCtl == self.resetTimesCtl) and not self.resetTimesCtl:IsValid()) then
enable = false;
end
-- Lotro.Button can't get mouse events while disabled. Need to superimpose another control.
if (enable and not self.okButton:IsEnabled()) then
self.okMask:SetParent(nil);
self.okMask = nil;
elseif (not enable and self.okButton:IsEnabled()) then
self.okMask = Turbine.UI.Control();
self.okMask:SetParent(self.okButton);
self.okMask:SetSize(self.okButton:GetSize());
Thurallor.UI.Tooltip(L:GetText("/ResetTimesDialog/NotOkTooltip")):Attach(self.okMask);
end
Turbine.UI.Lotro.Button.SetEnabled(self.okButton, enable);
end
self.okButton.UpdateEnabled();
self.okButton.Click = function()
local resetTimeSpec, rotationTimeSpec;
if (self.selectedCtl == self.resetTimesCtl) then
resetTimeSpec = self.resetTimesCtl:GetTimeSpec();
elseif (self.selectedCtl == self.rotationCtl) then
rotationTimeSpec = self.rotationCtl:GetTimeSpec();
end
DoCallbacks(self, "Ok", { resetTimes = resetTimeSpec; rotation = rotationTimeSpec });
self:Close();
end
left = self.okButton:GetWidth() + 4;
self.cancelButton = AddButton(buttons, left, 0, L:GetText("/ExpireTimeDialog/CancelWidth"), L:GetText("/ExpireTimeDialog/Cancel"));
self.cancelButton.Click = function()
self:Close();
end
buttons:SetSize(left + self.cancelButton:GetWidth(), self.cancelButton:GetHeight());
buttons:SetLeft(math.floor(0.5 + (width - buttons:GetWidth()) / 2));
top = top + buttons:GetHeight();
local height = top + 22;
self:SetSize(width, height);
EnsureOnScreen(self, true);
end
function ResetTimesDialog:EnterKeyPressed()
DoCallbacks(self.okButton, "Click");
end
function ResetTimesDialog:EscapeKeyPressed()
self:Close();
end