ItineraryDialog = class(Turbine.UI.Lotro.Window);
function ItineraryDialog:Constructor(win)
Turbine.UI.Lotro.Window.Constructor(self);
local instructions = Turbine.UI.Label();
instructions:SetFont(Turbine.UI.Lotro.Font.Verdana14);
local prevContext = L:SetContext("/ItineraryDialog");
self:SetText(L:GetText("Title"));
self:SetVisible(true);
self.window = win;
self:SetZOrder(win:GetZOrder() + 1);
self:SetSize(500, 500);
local label, textBox;
local xmargin = 28;
local width = self:GetWidth() - 2 * xmargin;
local top = 44;
local font = Turbine.UI.Lotro.Font.Verdana14;
local instructions = Turbine.UI.Label();
instructions:SetParent(self);
instructions:SetFont(font);
instructions:SetFontStyle(Turbine.UI.FontStyle.Outline);
instructions:SetOutlineColor(Turbine.UI.Color.Black);
instructions:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
instructions:SetText(L:GetText("Instructions"));
instructions:SetPosition(xmargin, top);
instructions:SetSize(width, 14 * 3);
top = top + instructions:GetHeight() + 10;
local textBox = Turbine.UI.Lotro.TextBox();
self.textBox = textBox;
textBox:SetParent(self);
textBox:SetFont(font);
textBox:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
textBox:SetTextAlignment(Turbine.UI.ContentAlignment.TopLeft);
textBox:SetSelectable(true);
textBox:SetMultiline(true);
textBox:SetPosition(xmargin, top);
textBox:SetSize(width - 10, 14 * 10);
textBox.TextChanged = function()
self:SetWantsUpdates(true);
end
local vScrollBar = Turbine.UI.Lotro.ScrollBar();
vScrollBar:SetParent(self);
vScrollBar:SetOrientation(Turbine.UI.Orientation.Vertical);
vScrollBar:SetSize(10, textBox:GetHeight());
vScrollBar:SetPosition(textBox:GetLeft() + textBox:GetWidth(), textBox:GetTop());
textBox:SetVerticalScrollBar(vScrollBar);
top = top + vScrollBar:GetHeight() + 10;
local results = Turbine.UI.Label();
self.results = results;
results:SetParent(self);
results:SetFont(font);
results:SetFontStyle(Turbine.UI.FontStyle.Outline);
results:SetOutlineColor(Turbine.UI.Color.Black);
results:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
results:SetPosition(xmargin, top);
results:SetSize(width, 14);
top = top + results:GetHeight() + 10;
local okButton = Turbine.UI.Lotro.Button();
self.okButton = okButton;
okButton:SetParent(self);
okButton:SetFont(font);
okButton:SetText(L:GetText("CreateButton"));
okButton:SetWidth(L:GetText("CreateButtonWidth"));
okButton:SetPosition(math.floor(0.5 + (self:GetWidth() - okButton:GetWidth()) / 2), top);
okButton.Click = function()
win:CreateNewItinerary(self.locations);
self:Close();
end
okButton:SetEnabled(false);
top = top + okButton:GetHeight() + 20;
L:SetContext(prevContext);
self:SetHeight(top);
end
function ItineraryDialog:Update()
local text = self.textBox:GetText();
local leftBracket = "[%(%[]*";
local xcoord = "(%d+%.?%d*) *([EWOewo])";
local ycoord = "(%d+%.?%d*) *([NSns])";
local fluff = "[,;%- ]*";
local rightBracket = "[%)%]]*";
local regexp1 = "(" .. fluff .. leftBracket .. fluff .. ycoord .. fluff .. xcoord .. fluff .. rightBracket .. fluff .. ")";
local regexp2 = "(" .. fluff .. leftBracket .. fluff .. xcoord .. fluff .. ycoord .. fluff .. rightBracket .. fluff .. ")";
self.locations = {};
for line in string.gmatch(text, "([^\n]+)") do
local coords, y, yDir, x, xDir = string.match(line, regexp1);
if (not coords) then
coords, x, xDir, y, yDir = string.match(line, regexp2);
end
if (coords) then
local prefix, suffix = string.find(line, coords, 1, true);
coords = string.upper(y .. yDir .. ", " .. x .. xDir);
prefix = string.sub(line, 1, prefix - 1);
suffix = string.sub(line, suffix + 1, -1);
local desc;
if ((prefix ~= "") and (suffix == "")) then
desc = prefix;
elseif ((prefix == "") and (suffix ~= "")) then
desc = suffix;
else
desc = line;
end
table.insert(self.locations, { desc = desc; location = coords });
end
end
local results = L:GetText("/ItineraryDialog/FoundLocations");
results = string.gsub(results, "<num>", #self.locations);
self.results:SetText(results);
if (#self.locations > 0) then
self.results:SetForeColor(Turbine.UI.Color(0, 1, 0));
self.okButton:SetEnabled(true);
else
self.results:SetForeColor(Turbine.UI.Color(1, 0, 0));
self.okButton:SetEnabled(false);
end
self:SetWantsUpdates(false);
end