1 |
177 |
Thurallor-7095 |
ChatTriggerWindow = class(Turbine.UI.Lotro.Window); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
local function AddLabel(parent, left, top, text) |
4 |
|
Thurallor-7095 |
local label = Turbine.UI.Label(); |
5 |
|
Thurallor-7095 |
label:SetFont(Turbine.UI.Lotro.Font.Verdana14); |
6 |
|
Thurallor-7095 |
label:SetForeColor(Turbine.UI.Color.Silver); |
7 |
|
Thurallor-7095 |
label:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleRight); |
8 |
|
Thurallor-7095 |
label:SetText(text); |
9 |
|
Thurallor-7095 |
label:SetSize(100, 14); |
10 |
|
Thurallor-7095 |
label:SetParent(parent); |
11 |
|
Thurallor-7095 |
label:SetPosition(left, top); |
12 |
|
Thurallor-7095 |
return label, left + label:GetWidth(), top + label:GetHeight(); |
13 |
|
Thurallor-7095 |
end |
14 |
|
Thurallor-7095 |
|
15 |
|
Thurallor-7095 |
local function AddTextBox(parent, left, top, text) |
16 |
|
Thurallor-7095 |
local textbox = Turbine.UI.Lotro.TextBox(); |
17 |
|
Thurallor-7095 |
textbox:SetFont(Turbine.UI.Lotro.Font.Verdana14); |
18 |
|
Thurallor-7095 |
textbox:SetForeColor(Turbine.UI.Color.White); |
19 |
|
Thurallor-7095 |
textbox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft); |
20 |
|
Thurallor-7095 |
textbox:SetText(text); |
21 |
|
Thurallor-7095 |
textbox:SetSize(270, 24); |
22 |
|
Thurallor-7095 |
textbox:SetParent(parent); |
23 |
|
Thurallor-7095 |
textbox:SetPosition(left, top); |
24 |
|
Thurallor-7095 |
return textbox, left + textbox:GetWidth(), top + textbox:GetHeight(); |
25 |
|
Thurallor-7095 |
end |
26 |
|
Thurallor-7095 |
|
27 |
|
Thurallor-7095 |
function ChatTriggerWindow:Constructor(channel, pattern) |
28 |
|
Thurallor-7095 |
Turbine.UI.Lotro.Window.Constructor(self); |
29 |
|
Thurallor-7095 |
self:SetVisible(true); |
30 |
|
Thurallor-7095 |
self:SetSize(450, 150); |
31 |
|
Thurallor-7095 |
CenterWindow(self); |
32 |
|
Thurallor-7095 |
|
33 |
|
Thurallor-7095 |
self.localChatNames, self.localChatNameToChatType, self.chatTypeToLocalChatName = {}, {}, {}; |
34 |
|
Thurallor-7095 |
local prevContext = L:SetContext("/Turbine/ChatType"); |
35 |
|
Thurallor-7095 |
for _, name in pairs(L:GetItems("/Turbine/ChatType")) do |
36 |
|
Thurallor-7095 |
local chatType = Turbine.ChatType[name]; |
37 |
|
Thurallor-7095 |
local localChatName = L:GetText(name); |
38 |
|
Thurallor-7095 |
table.insert(self.localChatNames, localChatName); |
39 |
|
Thurallor-7095 |
self.localChatNameToChatType[localChatName] = chatType |
40 |
|
Thurallor-7095 |
self.chatTypeToLocalChatName[chatType] = localChatName; |
41 |
|
Thurallor-7095 |
end |
42 |
|
Thurallor-7095 |
table.sort(self.localChatNames); |
43 |
|
Thurallor-7095 |
|
44 |
|
Thurallor-7095 |
L:SetContext("/ChatTriggerWindow"); |
45 |
|
Thurallor-7095 |
self:SetText(L:GetText("Title")); |
46 |
|
Thurallor-7095 |
|
47 |
|
Thurallor-7095 |
local left, top = 20, 48; |
48 |
|
Thurallor-7095 |
local label, left = AddLabel(self, left, top, L:GetText("Channel")); |
49 |
|
Thurallor-7095 |
|
50 |
|
Thurallor-7095 |
self.selectedChannel = channel or Turbine.ChatType.PlayerCombat; |
51 |
|
Thurallor-7095 |
local dropDown = Thurallor.UI.DropDown(self.localChatNames, self.chatTypeToLocalChatName[self.selectedChannel]); |
52 |
|
Thurallor-7095 |
dropDown:SetParent(self); |
53 |
|
Thurallor-7095 |
dropDown:SetPosition(left + 6, top - 1); |
54 |
|
Thurallor-7095 |
dropDown:SetWidth(170); |
55 |
|
Thurallor-7095 |
AddCallback(dropDown, "SelectionChanged", function(_, args) |
56 |
|
Thurallor-7095 |
self.selectedChannel = self.localChatNameToChatType[args.Item]; |
57 |
|
Thurallor-7095 |
end); |
58 |
|
Thurallor-7095 |
self.channelDropDown = dropDown; |
59 |
|
Thurallor-7095 |
|
60 |
|
Thurallor-7095 |
left, top = 20, top + 26; |
61 |
|
Thurallor-7095 |
local label, left = AddLabel(self, left, top, L:GetText("Pattern")); |
62 |
|
Thurallor-7095 |
|
63 |
|
Thurallor-7095 |
self.pattern = pattern or ""; |
64 |
|
Thurallor-7095 |
self.patternTextBox = AddTextBox(self, left + 6, top - 5, self.pattern); |
65 |
|
Thurallor-7095 |
AddCallback(self.patternTextBox, "TextChanged", function(ctl) |
66 |
|
Thurallor-7095 |
self.pattern = ctl:GetText(); |
67 |
|
Thurallor-7095 |
end); |
68 |
|
Thurallor-7095 |
AddCallback(self.patternTextBox, "KeyDown", function(ctl, args) |
69 |
|
Thurallor-7095 |
self:KeyDown(args); |
70 |
|
Thurallor-7095 |
end); |
71 |
|
Thurallor-7095 |
self:Activate(); |
72 |
|
Thurallor-7095 |
self.patternTextBox:Focus(); |
73 |
|
Thurallor-7095 |
|
74 |
|
Thurallor-7095 |
local button = Turbine.UI.Lotro.Button(); |
75 |
|
Thurallor-7095 |
button:SetText(L:GetText("Ok")); |
76 |
|
Thurallor-7095 |
button:SetParent(self); |
77 |
|
Thurallor-7095 |
button:SetPosition(200, 108); |
78 |
|
Thurallor-7095 |
AddCallback(button, "Click", function() |
79 |
|
Thurallor-7095 |
self:Accept(); |
80 |
|
Thurallor-7095 |
end); |
81 |
|
Thurallor-7095 |
self.okButton = button; |
82 |
|
Thurallor-7095 |
|
83 |
|
Thurallor-7095 |
L:SetContext(prevContext); |
84 |
|
Thurallor-7095 |
end |
85 |
|
Thurallor-7095 |
|
86 |
|
Thurallor-7095 |
function ChatTriggerWindow:KeyDown(args) |
87 |
|
Thurallor-7095 |
if (args.Action == Turbine.UI.Lotro.Action.EnterKey) then |
88 |
|
Thurallor-7095 |
self:Accept(); |
89 |
|
Thurallor-7095 |
elseif (args.Action == Turbine.UI.Lotro.Action.Escape) then |
90 |
|
Thurallor-7095 |
self:Close(); |
91 |
|
Thurallor-7095 |
end |
92 |
|
Thurallor-7095 |
end |
93 |
|
Thurallor-7095 |
|
94 |
|
Thurallor-7095 |
function ChatTriggerWindow:Accept() |
95 |
|
Thurallor-7095 |
self.pattern = self.pattern:gsub("\n", ""); |
96 |
|
Thurallor-7095 |
local text = "[" .. self.chatTypeToLocalChatName[self.selectedChannel] .. "] " .. self.pattern; |
97 |
|
Thurallor-7095 |
DoCallbacks(self, "Accepted", { ChatType = self.selectedChannel; Pattern = self.pattern; Text = text }); |
98 |
|
Thurallor-7095 |
self.accepted = true; |
99 |
|
Thurallor-7095 |
self:Close(); |
100 |
|
Thurallor-7095 |
end |
101 |
|
Thurallor-7095 |
|
102 |
|
Thurallor-7095 |
function ChatTriggerWindow:Closing() |
103 |
|
Thurallor-7095 |
if (not self.accepted) then |
104 |
|
Thurallor-7095 |
DoCallbacks(self, "Canceled"); |
105 |
|
Thurallor-7095 |
end |
106 |
|
Thurallor-7095 |
end |