1 |
177 |
Thurallor-7095 |
HotkeyAssignWindow = class(Turbine.UI.Lotro.Window); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
function HotkeyAssignWindow:Constructor() |
4 |
|
Thurallor-7095 |
Turbine.UI.Lotro.Window.Constructor(self); |
5 |
|
Thurallor-7095 |
self:SetVisible(true); |
6 |
|
Thurallor-7095 |
local intructionLines = L:GetNumber("/HotkeyAssignWindow/instrLines"); |
7 |
|
Thurallor-7095 |
self:SetSize(450, 165 + intructionLines * 14); |
8 |
|
Thurallor-7095 |
CenterWindow(self); |
9 |
|
Thurallor-7095 |
|
10 |
|
Thurallor-7095 |
self.actions = {}; |
11 |
|
Thurallor-7095 |
for name, value in pairs(Turbine.UI.Lotro.Action) do |
12 |
|
Thurallor-7095 |
name = name:gsub("_", " "); |
13 |
|
Thurallor-7095 |
self.actions[value] = name; |
14 |
|
Thurallor-7095 |
end |
15 |
|
Thurallor-7095 |
|
16 |
|
Thurallor-7095 |
self:SetText(L:GetText("/HotkeyAssignWindow/Title")); |
17 |
|
Thurallor-7095 |
|
18 |
|
Thurallor-7095 |
local label = Turbine.UI.Label(); |
19 |
|
Thurallor-7095 |
label:SetFont(Turbine.UI.Lotro.Font.Verdana14); |
20 |
|
Thurallor-7095 |
label:SetForeColor(Turbine.UI.Color.Silver); |
21 |
|
Thurallor-7095 |
label:SetText(L:GetText("/HotkeyAssignWindow/Instructions")); |
22 |
|
Thurallor-7095 |
label:SetSelectable(true); |
23 |
|
Thurallor-7095 |
label:SetParent(self); |
24 |
|
Thurallor-7095 |
label:SetPosition(20, 40); |
25 |
|
Thurallor-7095 |
label:SetSize(410, 14 * intructionLines); |
26 |
|
Thurallor-7095 |
self.instructions = label; |
27 |
|
Thurallor-7095 |
|
28 |
|
Thurallor-7095 |
local listbox = Turbine.UI.ListBox(); |
29 |
|
Thurallor-7095 |
local top = label:GetTop() + label:GetHeight() + 14; |
30 |
|
Thurallor-7095 |
listbox:SetParent(self); |
31 |
|
Thurallor-7095 |
--listbox:SetBackColor(Turbine.UI.Color(1, 0, 0.11, 0.20)); |
32 |
|
Thurallor-7095 |
listbox:SetPosition(70, top); |
33 |
|
Thurallor-7095 |
listbox:SetSize(300, 87); |
34 |
|
Thurallor-7095 |
listbox.SelectedIndexChanged = function(_, args) |
35 |
|
Thurallor-7095 |
local ctl = (listbox:GetSelectedItem()).textbox; |
36 |
|
Thurallor-7095 |
DoCallbacks(self, "KeySelected", { Event = ctl.event; Action = ctl.action; Text = ctl:GetText() }); |
37 |
|
Thurallor-7095 |
self.keySelected = true; |
38 |
|
Thurallor-7095 |
self:Close(); |
39 |
|
Thurallor-7095 |
end |
40 |
|
Thurallor-7095 |
self.listbox = listbox; |
41 |
|
Thurallor-7095 |
|
42 |
|
Thurallor-7095 |
local scrollBar = Turbine.UI.Lotro.ScrollBar(); |
43 |
|
Thurallor-7095 |
scrollBar:SetOrientation(Turbine.UI.Orientation.Vertical); |
44 |
|
Thurallor-7095 |
scrollBar:SetParent(self); |
45 |
|
Thurallor-7095 |
scrollBar:SetSize(10, 87); |
46 |
|
Thurallor-7095 |
scrollBar:SetPosition(370, top); |
47 |
|
Thurallor-7095 |
listbox:SetVerticalScrollBar(scrollBar); |
48 |
|
Thurallor-7095 |
|
49 |
|
Thurallor-7095 |
self:SetWantsKeyEvents(true); |
50 |
|
Thurallor-7095 |
end |
51 |
|
Thurallor-7095 |
|
52 |
|
Thurallor-7095 |
function HotkeyAssignWindow:AddKeypress(text, event, action) |
53 |
|
Thurallor-7095 |
local wrapper = Turbine.UI.Control(); |
54 |
|
Thurallor-7095 |
wrapper:SetSize(300, 30); |
55 |
|
Thurallor-7095 |
|
56 |
|
Thurallor-7095 |
local textbox = Turbine.UI.Lotro.TextBox(); |
57 |
|
Thurallor-7095 |
textbox.event = event; |
58 |
|
Thurallor-7095 |
textbox.action = action; |
59 |
|
Thurallor-7095 |
textbox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter); |
60 |
|
Thurallor-7095 |
textbox:SetMultiline(false); |
61 |
|
Thurallor-7095 |
textbox:SetFont(Turbine.UI.Lotro.Font.Verdana14); |
62 |
|
Thurallor-7095 |
textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.19, 0.33)); |
63 |
|
Thurallor-7095 |
textbox:SetText(text); |
64 |
|
Thurallor-7095 |
textbox:SetReadOnly(true); |
65 |
|
Thurallor-7095 |
textbox:SetParent(wrapper); |
66 |
|
Thurallor-7095 |
textbox:SetSize(298, 28); |
67 |
|
Thurallor-7095 |
textbox:SetPosition(1, 1); |
68 |
|
Thurallor-7095 |
textbox:SetMouseVisible(false); |
69 |
|
Thurallor-7095 |
wrapper.textbox = textbox; |
70 |
|
Thurallor-7095 |
|
71 |
|
Thurallor-7095 |
wrapper.MouseEnter = function(ctl) |
72 |
|
Thurallor-7095 |
ctl.textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.57, 1)); |
73 |
|
Thurallor-7095 |
end |
74 |
|
Thurallor-7095 |
wrapper.MouseLeave = function(ctl) |
75 |
|
Thurallor-7095 |
ctl.textbox:SetBackColor(Turbine.UI.Color(1, 0, 0.19, 0.33)); |
76 |
|
Thurallor-7095 |
end |
77 |
|
Thurallor-7095 |
|
78 |
|
Thurallor-7095 |
self.listbox:AddItem(wrapper); |
79 |
|
Thurallor-7095 |
self.listbox:EnsureVisible(self.listbox:GetItemCount()); |
80 |
|
Thurallor-7095 |
end |
81 |
|
Thurallor-7095 |
|
82 |
|
Thurallor-7095 |
function HotkeyAssignWindow:KeyDown(args) |
83 |
|
Thurallor-7095 |
local action = self.actions[args.Action] or "unknown action " .. args.Action; |
84 |
|
Thurallor-7095 |
self:AddKeypress(action .. L:GetText("/HotkeyAssignWindow/KeyDown"), "KeyDown", args.Action); |
85 |
|
Thurallor-7095 |
end |
86 |
|
Thurallor-7095 |
|
87 |
|
Thurallor-7095 |
function HotkeyAssignWindow:KeyUp(args) |
88 |
|
Thurallor-7095 |
local action = self.actions[args.Action] or "unknown action " .. args.Action; |
89 |
|
Thurallor-7095 |
self:AddKeypress(action .. L:GetText("/HotkeyAssignWindow/KeyUp"), "KeyUp", args.Action); |
90 |
|
Thurallor-7095 |
end |
91 |
|
Thurallor-7095 |
|
92 |
|
Thurallor-7095 |
function HotkeyAssignWindow:Closing() |
93 |
|
Thurallor-7095 |
if (not self.keySelected) then |
94 |
|
Thurallor-7095 |
DoCallbacks(self, "Canceled"); |
95 |
|
Thurallor-7095 |
end |
96 |
|
Thurallor-7095 |
end |