1 |
2 |
Thurallor-7095 |
CaptionEditor = class(Turbine.UI.Lotro.Window); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
function CaptionEditor:Constructor(title, target, startingWidth, startingHeight, startingText) |
4 |
|
Thurallor-7095 |
Turbine.UI.Lotro.Window.Constructor(self); |
5 |
|
Thurallor-7095 |
|
6 |
|
Thurallor-7095 |
self.target = target; |
7 |
|
Thurallor-7095 |
self:SetText(L:GetText("/CaptionEditor/Title/" .. title)); |
8 |
|
Thurallor-7095 |
self:SetZOrder(2147483647 - 5); |
9 |
|
Thurallor-7095 |
self:SetVisible(true); |
10 |
|
Thurallor-7095 |
|
11 |
|
Thurallor-7095 |
local minimumWidth, minimumHeight = 250, 130; |
12 |
|
Thurallor-7095 |
local minCaptionWidth, minCaptionHeight = 32, 32; |
13 |
|
Thurallor-7095 |
self.xMargin = minimumWidth - minCaptionWidth; |
14 |
|
Thurallor-7095 |
self.yMargin = minimumHeight - minCaptionHeight; |
15 |
|
Thurallor-7095 |
self:SetMinimumWidth(minimumWidth); |
16 |
|
Thurallor-7095 |
self:SetMinimumHeight(minimumHeight); |
17 |
|
Thurallor-7095 |
self:SetWidth(startingWidth + self.xMargin); |
18 |
|
Thurallor-7095 |
self:SetHeight(startingHeight + self.yMargin); |
19 |
|
Thurallor-7095 |
self:SetLeft(Turbine.UI.Display.GetMouseX() - math.floor(self:GetWidth() / 2)); |
20 |
|
Thurallor-7095 |
self:SetTop(Turbine.UI.Display.GetMouseY() - math.floor(self:GetHeight() / 2)); |
21 |
|
Thurallor-7095 |
self:SetResizable(true); |
22 |
|
Thurallor-7095 |
|
23 |
|
Thurallor-7095 |
self.textBoxBorder = Turbine.UI.Lotro.TextBox(); |
24 |
|
Thurallor-7095 |
self.textBoxBorder:SetPosition(math.floor(self.xMargin / 2) - 3, math.floor(self.yMargin / 2) - 3); |
25 |
|
Thurallor-7095 |
self.textBoxBorder:SetParent(self); |
26 |
|
Thurallor-7095 |
self.textBoxBorder:SetEnabled(false); |
27 |
|
Thurallor-7095 |
|
28 |
|
Thurallor-7095 |
self.textBox = Turbine.UI.TextBox(); |
29 |
|
Thurallor-7095 |
self.textBox:SetPosition(math.floor(self.xMargin / 2), math.floor(self.yMargin / 2)); |
30 |
|
Thurallor-7095 |
self.textBox:SetParent(self); |
31 |
|
Thurallor-7095 |
self.textBox:SetSelectable(true); |
32 |
|
Thurallor-7095 |
self.textBox:SetText(startingText); |
33 |
|
Thurallor-7095 |
self.textBox.TextChanged = function(sender, args) |
34 |
5 |
Thurallor-7095 |
local text = sender:GetText(); |
35 |
|
Thurallor-7095 |
-- Remove carriage returns |
36 |
|
Thurallor-7095 |
local stripped = string.gsub(text, "\n", ""); |
37 |
|
Thurallor-7095 |
if (stripped ~= text) then |
38 |
|
Thurallor-7095 |
sender:SetText(stripped); |
39 |
|
Thurallor-7095 |
text = stripped; |
40 |
|
Thurallor-7095 |
else |
41 |
|
Thurallor-7095 |
stripped = nil; |
42 |
|
Thurallor-7095 |
end |
43 |
2 |
Thurallor-7095 |
self.avoidRecursion = true; |
44 |
5 |
Thurallor-7095 |
target:SetName(text); |
45 |
2 |
Thurallor-7095 |
self.avoidRecursion = false; |
46 |
5 |
Thurallor-7095 |
if (stripped) then |
47 |
|
Thurallor-7095 |
self:Close(); |
48 |
|
Thurallor-7095 |
end |
49 |
2 |
Thurallor-7095 |
end |
50 |
|
Thurallor-7095 |
|
51 |
|
Thurallor-7095 |
local prevContext = L:SetContext("/CaptionEditor"); |
52 |
|
Thurallor-7095 |
|
53 |
|
Thurallor-7095 |
self.buttonWidth = 90; |
54 |
|
Thurallor-7095 |
self.buttonSpacingX, self.buttonSpacingY = 10, 20 |
55 |
|
Thurallor-7095 |
self.fontButton = Turbine.UI.Lotro.Button(); |
56 |
|
Thurallor-7095 |
self.fontButton:SetParent(self); |
57 |
|
Thurallor-7095 |
self.fontButton:SetFont(Turbine.UI.Lotro.Font.TrajanPro13); |
58 |
|
Thurallor-7095 |
self.fontButton:SetText(L:GetText("Font")); |
59 |
|
Thurallor-7095 |
self.fontButton:SetWidth(self.buttonWidth); |
60 |
|
Thurallor-7095 |
self.fontButton:SetEnabled(target.SetCaptionFont ~= nil); |
61 |
|
Thurallor-7095 |
self.fontButton.Click = function(sender, args) |
62 |
|
Thurallor-7095 |
self:ShowFontMenu(); |
63 |
|
Thurallor-7095 |
end |
64 |
|
Thurallor-7095 |
|
65 |
|
Thurallor-7095 |
self.colorButton = Turbine.UI.Lotro.Button(); |
66 |
|
Thurallor-7095 |
self.colorButton:SetParent(self); |
67 |
|
Thurallor-7095 |
self.colorButton:SetFont(Turbine.UI.Lotro.Font.TrajanPro13); |
68 |
|
Thurallor-7095 |
self.colorButton:SetText(L:GetText("Color")); |
69 |
|
Thurallor-7095 |
self.colorButton:SetWidth(self.buttonWidth); |
70 |
|
Thurallor-7095 |
self.colorButton.Click = function(sender, args) |
71 |
|
Thurallor-7095 |
self.target:EditColor(); |
72 |
|
Thurallor-7095 |
end |
73 |
|
Thurallor-7095 |
|
74 |
18 |
Thurallor-7095 |
AddCallback(self, "SizeChanged", function(sender, args) |
75 |
2 |
Thurallor-7095 |
local width = self:GetWidth(); |
76 |
|
Thurallor-7095 |
local height = self:GetHeight(); |
77 |
|
Thurallor-7095 |
self.target:SetCaptionSize(width - self.xMargin, height - self.yMargin); |
78 |
|
Thurallor-7095 |
self.fontButton:SetLeft(math.floor(width / 2 + self.buttonSpacingX / 2)); |
79 |
|
Thurallor-7095 |
self.colorButton:SetLeft(math.floor(width / 2 - self.buttonSpacingX / 2 - self.buttonWidth)); |
80 |
|
Thurallor-7095 |
local top = height - self.buttonSpacingY - self.fontButton:GetHeight(); |
81 |
|
Thurallor-7095 |
self.fontButton:SetTop(top); |
82 |
|
Thurallor-7095 |
self.colorButton:SetTop(top); |
83 |
18 |
Thurallor-7095 |
end); |
84 |
|
Thurallor-7095 |
DoCallbacks(self, "SizeChanged"); |
85 |
2 |
Thurallor-7095 |
self.textBox:SelectAll(); |
86 |
|
Thurallor-7095 |
end |
87 |
|
Thurallor-7095 |
|
88 |
|
Thurallor-7095 |
function CaptionEditor:WantsCaptionUpdates() |
89 |
|
Thurallor-7095 |
return (not self.avoidRecursion); |
90 |
|
Thurallor-7095 |
end |
91 |
|
Thurallor-7095 |
|
92 |
|
Thurallor-7095 |
function CaptionEditor:GetTextBox() |
93 |
|
Thurallor-7095 |
return self.textBox; |
94 |
|
Thurallor-7095 |
end |
95 |
|
Thurallor-7095 |
|
96 |
|
Thurallor-7095 |
function CaptionEditor:Redraw() |
97 |
|
Thurallor-7095 |
self.textBoxBorder:SetWidth(self.textBox:GetWidth() + 6); |
98 |
|
Thurallor-7095 |
self.textBoxBorder:SetHeight(self.textBox:GetHeight() + 6); |
99 |
|
Thurallor-7095 |
end |
100 |
|
Thurallor-7095 |
|
101 |
|
Thurallor-7095 |
function CaptionEditor:ShowFontMenu() |
102 |
|
Thurallor-7095 |
self.fontMenu = Turbine.UI.ContextMenu(); |
103 |
|
Thurallor-7095 |
|
104 |
|
Thurallor-7095 |
local selectedFont = self.textBox:GetFont(); |
105 |
|
Thurallor-7095 |
local fontNames = { }; |
106 |
|
Thurallor-7095 |
local fontSizes = { }; |
107 |
|
Thurallor-7095 |
for fontName, font in pairs(Turbine.UI.Lotro.Font) do |
108 |
20 |
Thurallor-7095 |
if ((type(font) == "number") and (fontName ~= "Undefined") and (string.sub(fontName, 1, 1) ~= "_")) then |
109 |
2 |
Thurallor-7095 |
local typeFace, size = string.match(fontName, "^([^0-9]+)([0-9]+)$"); |
110 |
|
Thurallor-7095 |
if (fontSizes[typeFace] == nil) then |
111 |
|
Thurallor-7095 |
fontSizes[typeFace] = { }; |
112 |
|
Thurallor-7095 |
table.insert(fontNames, typeFace); |
113 |
|
Thurallor-7095 |
end |
114 |
|
Thurallor-7095 |
table.insert(fontSizes[typeFace], size); |
115 |
|
Thurallor-7095 |
end |
116 |
|
Thurallor-7095 |
end |
117 |
|
Thurallor-7095 |
table.sort(fontNames); |
118 |
|
Thurallor-7095 |
for f = 1, #fontNames, 1 do |
119 |
|
Thurallor-7095 |
local fontName = fontNames[f]; |
120 |
|
Thurallor-7095 |
local item = Turbine.UI.MenuItem(fontName, true, false); |
121 |
|
Thurallor-7095 |
self.fontMenu:GetItems():Add(item); |
122 |
|
Thurallor-7095 |
local sizes = fontSizes[fontName]; |
123 |
|
Thurallor-7095 |
table.sort(sizes); |
124 |
|
Thurallor-7095 |
for s = 1, #sizes, 1 do |
125 |
|
Thurallor-7095 |
local fontSize = sizes[s]; |
126 |
|
Thurallor-7095 |
local font = Turbine.UI.Lotro.Font[fontName .. fontSize]; |
127 |
|
Thurallor-7095 |
local subItem = Turbine.UI.MenuItem(fontSize, true, font == selectedFont); |
128 |
|
Thurallor-7095 |
item:GetItems():Add(subItem); |
129 |
|
Thurallor-7095 |
subItem.Click = function(sender, args) |
130 |
|
Thurallor-7095 |
self.target:SetCaptionFont(font); |
131 |
|
Thurallor-7095 |
end |
132 |
|
Thurallor-7095 |
end |
133 |
|
Thurallor-7095 |
end |
134 |
|
Thurallor-7095 |
|
135 |
|
Thurallor-7095 |
self.fontMenu:ShowMenu(); |
136 |
|
Thurallor-7095 |
end |