1 |
2 |
Thurallor-7095 |
ExportWindow = class(); |
2 |
|
Thurallor-7095 |
|
3 |
|
Thurallor-7095 |
function ExportWindow:Constructor(title, exportData) |
4 |
|
Thurallor-7095 |
local prevContext = L:SetContext("/ExportWindow"); |
5 |
|
Thurallor-7095 |
self.uncompressedData = PrettyPrint(exportData, ""); |
6 |
|
Thurallor-7095 |
self.compactData = Serialize(exportData); |
7 |
|
Thurallor-7095 |
|
8 |
|
Thurallor-7095 |
self.ok = L:GetText("OK"); |
9 |
|
Thurallor-7095 |
self.window = Alert(title, "", self.ok); |
10 |
|
Thurallor-7095 |
self.window:SetSize(423, 300); |
11 |
|
Thurallor-7095 |
self.window:SetMinimumSize(423, 300); |
12 |
|
Thurallor-7095 |
CenterWindow(self.window); |
13 |
|
Thurallor-7095 |
self.window:SetZOrder(2147483647); |
14 |
|
Thurallor-7095 |
self.okButton = self.window.buttons[self.ok]; |
15 |
|
Thurallor-7095 |
self.okButton:SetEnabled(false); |
16 |
20 |
Thurallor-7095 |
self.okButton.Click = function() |
17 |
2 |
Thurallor-7095 |
self.window:Close(); |
18 |
|
Thurallor-7095 |
end |
19 |
|
Thurallor-7095 |
|
20 |
|
Thurallor-7095 |
self.compressed = Turbine.UI.Lotro.CheckBox(); |
21 |
|
Thurallor-7095 |
self.compressed:SetParent(self.window); |
22 |
|
Thurallor-7095 |
self.compressed:SetSize(100, 20); |
23 |
|
Thurallor-7095 |
self.compressed:SetFont(Turbine.UI.Lotro.Font.TrajanPro14); |
24 |
|
Thurallor-7095 |
self.compressed:SetText(L:GetText("Compressed")); |
25 |
|
Thurallor-7095 |
self.compressed:SetEnabled(false); |
26 |
|
Thurallor-7095 |
self.compressed.CheckedChanged = function(control) |
27 |
|
Thurallor-7095 |
if (control:IsChecked()) then |
28 |
|
Thurallor-7095 |
self.window.label:SetText(self.compressedData); |
29 |
|
Thurallor-7095 |
else |
30 |
|
Thurallor-7095 |
if (#self.uncompressedData > 65535) then |
31 |
6 |
Thurallor-7095 |
Puts(L:GetText("/ExportWindow/UncompressedDataTooBig")); |
32 |
2 |
Thurallor-7095 |
control:SetChecked(true); |
33 |
|
Thurallor-7095 |
else |
34 |
|
Thurallor-7095 |
self.window.label:SetText(self.uncompressedData); |
35 |
|
Thurallor-7095 |
end |
36 |
|
Thurallor-7095 |
end |
37 |
|
Thurallor-7095 |
end |
38 |
|
Thurallor-7095 |
|
39 |
|
Thurallor-7095 |
-- Compress the data in the next Update cycle. |
40 |
|
Thurallor-7095 |
self.window:SetWantsUpdates(true); |
41 |
|
Thurallor-7095 |
self.window.updateCount = 0; |
42 |
|
Thurallor-7095 |
self.window.Update = function(w) |
43 |
|
Thurallor-7095 |
w.updateCount = w.updateCount + 1; |
44 |
|
Thurallor-7095 |
if (w.updateCount == 1) then |
45 |
|
Thurallor-7095 |
w.label:SetText(L:GetText("/ExportWindow/Compressing")); |
46 |
6 |
Thurallor-7095 |
Puts(L:GetText("/ExportWindow/Compressing")); |
47 |
2 |
Thurallor-7095 |
elseif (w.updateCount == 3) then |
48 |
|
Thurallor-7095 |
w.compressor = Thurallor.Utils.LibCompress(); |
49 |
|
Thurallor-7095 |
elseif (w.updateCount == 4) then |
50 |
|
Thurallor-7095 |
self.compressedData = w.compressor:Compress(self.compactData); |
51 |
|
Thurallor-7095 |
elseif (w.updateCount == 5) then |
52 |
|
Thurallor-7095 |
w.label:SetText(w.label:GetText() .. "\n" .. L:GetText("/ExportWindow/Encoding")); |
53 |
6 |
Thurallor-7095 |
Puts(L:GetText("/ExportWindow/Encoding")); |
54 |
2 |
Thurallor-7095 |
elseif (w.updateCount == 7) then |
55 |
|
Thurallor-7095 |
self.compressedData = Bin2Text(self.compressedData); |
56 |
6 |
Thurallor-7095 |
--local ratio = (1 - #self.compressedData / #self.uncompressedData) * 100; |
57 |
|
Thurallor-7095 |
--Puts("Compressed " .. tostring(#self.uncompressedData) .. " bytes by " .. string.format("%.0f%%", ratio) .. " to " .. tostring(#self.compressedData) .. " bytes."); |
58 |
2 |
Thurallor-7095 |
if (#self.compressedData > 65535) then |
59 |
6 |
Thurallor-7095 |
Puts(L:GetText("/ExportWindow/ExportFailedTooBig")); |
60 |
2 |
Thurallor-7095 |
w:Close(); |
61 |
|
Thurallor-7095 |
end |
62 |
|
Thurallor-7095 |
elseif (w.updateCount == 8) then |
63 |
|
Thurallor-7095 |
self.compressed:SetChecked(true); |
64 |
|
Thurallor-7095 |
elseif (w.updateCount == 9) then |
65 |
|
Thurallor-7095 |
w.compressor = nil; |
66 |
|
Thurallor-7095 |
self.compressed:SetEnabled(true); |
67 |
|
Thurallor-7095 |
self.okButton:SetEnabled(true); |
68 |
7 |
Thurallor-7095 |
self.window:Activate(); |
69 |
|
Thurallor-7095 |
self.window.label:SelectAll(); |
70 |
|
Thurallor-7095 |
self.window.label:Focus(); |
71 |
2 |
Thurallor-7095 |
w:SetWantsUpdates(false); |
72 |
|
Thurallor-7095 |
end |
73 |
|
Thurallor-7095 |
end |
74 |
|
Thurallor-7095 |
|
75 |
|
Thurallor-7095 |
AddCallback(self.window, "Closing", function() |
76 |
|
Thurallor-7095 |
if (self.Closing) then |
77 |
|
Thurallor-7095 |
self:Closing(); |
78 |
|
Thurallor-7095 |
end |
79 |
|
Thurallor-7095 |
end); |
80 |
|
Thurallor-7095 |
|
81 |
|
Thurallor-7095 |
AddCallback(self.window, "SizeChanged", function() |
82 |
|
Thurallor-7095 |
self:SizeChanged(); |
83 |
|
Thurallor-7095 |
end); |
84 |
|
Thurallor-7095 |
self:SizeChanged(); |
85 |
|
Thurallor-7095 |
|
86 |
|
Thurallor-7095 |
L:SetContext(prevContext); |
87 |
|
Thurallor-7095 |
end |
88 |
|
Thurallor-7095 |
|
89 |
|
Thurallor-7095 |
function ExportWindow:SizeChanged() |
90 |
|
Thurallor-7095 |
local left, top = self.window.buttons[self.ok]:GetPosition(); |
91 |
|
Thurallor-7095 |
self.compressed:SetPosition(left - 120, top); |
92 |
|
Thurallor-7095 |
end |
93 |
|
Thurallor-7095 |
|
94 |
|
Thurallor-7095 |
function ExportWindow:Close() |
95 |
|
Thurallor-7095 |
self.window:Close(); |
96 |
|
Thurallor-7095 |
end |