HotkeyAssignWindow = class(Turbine.UI.Lotro.Window);
function HotkeyAssignWindow:Constructor()
Turbine.UI.Lotro.Window.Constructor(self);
self:SetVisible(true);
local intructionLines = L:GetNumber("/HotkeyAssignWindow/instrLines");
self:SetSize(450, 165 + intructionLines * 14);
CenterWindow(self);
self.actions = {};
for name, value in pairs(Turbine.UI.Lotro.Action) do
name = name:gsub("_", " ");
self.actions[value] = name;
end
self:SetText(L:GetText("/HotkeyAssignWindow/Title"));
local label = Turbine.UI.Label();
label:SetFont(Turbine.UI.Lotro.Font.Verdana14);
label:SetForeColor(Turbine.UI.Color.Silver);
label:SetText(L:GetText("/HotkeyAssignWindow/Instructions"));
label:SetSelectable(true);
label:SetParent(self);
label:SetPosition(20, 40);
label:SetSize(410, 14 * intructionLines);
self.instructions = label;
local listbox = Turbine.UI.ListBox();
local top = label:GetTop() + label:GetHeight() + 14;
listbox:SetParent(self);
--listbox:SetBackColor(Turbine.UI.Color(1, 0, 0.11, 0.20));
listbox:SetPosition(70, top);
listbox:SetSize(300, 87);
listbox.SelectedIndexChanged = function(_, args)
local ctl = (listbox:GetSelectedItem()).textbox;
DoCallbacks(self, "KeySelected", { Event = ctl.event; Action = ctl.action; Text = ctl:GetText() });
self.keySelected = true;
self:Close();
end
self.listbox = listbox;
local scrollBar = Turbine.UI.Lotro.ScrollBar();
scrollBar:SetOrientation(Turbine.UI.Orientation.Vertical);
scrollBar:SetParent(self);
scrollBar:SetSize(10, 87);
scrollBar:SetPosition(370, top);
listbox:SetVerticalScrollBar(scrollBar);
self:SetWantsKeyEvents(true);
end
function HotkeyAssignWindow:AddKeypress(text, event, action)
local wrapper = Turbine.UI.Control();
wrapper:SetSize(300, 30);
local textbox = Turbine.UI.Lotro.TextBox();
textbox.event = event;
textbox.action = action;
textbox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
textbox:SetMultiline(false);
textbox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.19, 0.33));
textbox:SetText(text);
textbox:SetReadOnly(true);
textbox:SetParent(wrapper);
textbox:SetSize(298, 28);
textbox:SetPosition(1, 1);
textbox:SetMouseVisible(false);
wrapper.textbox = textbox;
wrapper.MouseEnter = function(ctl)
ctl.textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.57, 1));
end
wrapper.MouseLeave = function(ctl)
ctl.textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.19, 0.33));
end
self.listbox:AddItem(wrapper);
self.listbox:EnsureVisible(self.listbox:GetItemCount());
end
function HotkeyAssignWindow:KeyDown(args)
local action = self.actions[args.Action] or "unknown action " .. args.Action;
self:AddKeypress(action .. L:GetText("/HotkeyAssignWindow/KeyDown"), "KeyDown", args.Action);
end
function HotkeyAssignWindow:KeyUp(args)
local action = self.actions[args.Action] or "unknown action " .. args.Action;
self:AddKeypress(action .. L:GetText("/HotkeyAssignWindow/KeyUp"), "KeyUp", args.Action);
end
function HotkeyAssignWindow:Closing()
if (not self.keySelected) then
DoCallbacks(self, "Canceled");
end
end