2014-06-10 16:47:13 +00:00
|
|
|
var AircraftCenter = {
|
|
|
|
show: func
|
|
|
|
{
|
2014-06-13 17:17:40 +00:00
|
|
|
var dlg = canvas.Window.new([600,500], "dialog")
|
2014-06-10 16:47:13 +00:00
|
|
|
.set("title", "Aircraft Center")
|
|
|
|
.set("resize", 1);
|
|
|
|
dlg.getCanvas(1)
|
|
|
|
.set("background", canvas.style.getColor("bg_color"));
|
|
|
|
var root = dlg.getCanvas().createGroup();
|
|
|
|
|
|
|
|
var vbox = VBoxLayout.new();
|
|
|
|
dlg.setLayout(vbox);
|
|
|
|
|
2014-06-11 22:49:18 +00:00
|
|
|
var packages = pkg.root.search({
|
|
|
|
'rating-FDM': 2,
|
|
|
|
'rating-cockpit': 2,
|
|
|
|
'rating-model': 2,
|
|
|
|
'rating-systems': 1
|
|
|
|
});
|
|
|
|
|
|
|
|
var info_text =
|
2014-06-13 17:17:40 +00:00
|
|
|
"Install/remove aircraft (Showing " ~ size(packages) ~ " aircraft)";
|
2014-06-11 22:49:18 +00:00
|
|
|
|
2014-06-10 16:47:13 +00:00
|
|
|
vbox.addItem(
|
2014-06-12 22:32:40 +00:00
|
|
|
gui.widgets.Label.new(root, style, {wordWrap: 1})
|
2014-06-11 22:49:18 +00:00
|
|
|
.setText(info_text)
|
2014-06-10 16:47:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
var scroll = gui.widgets.ScrollArea.new(root, style, {size: [96, 128]})
|
|
|
|
.move(20, 100);
|
|
|
|
vbox.addItem(scroll, 1);
|
|
|
|
|
|
|
|
var content = scroll.getContent()
|
|
|
|
.set("font", "LiberationFonts/LiberationSans-Bold.ttf")
|
|
|
|
.set("character-size", 16)
|
|
|
|
.set("alignment", "left-center");
|
|
|
|
|
|
|
|
var list = VBoxLayout.new();
|
|
|
|
scroll.setLayout(list);
|
|
|
|
|
2014-06-11 22:49:18 +00:00
|
|
|
foreach(var package; packages)
|
2014-06-10 16:47:13 +00:00
|
|
|
{
|
2014-06-11 22:49:18 +00:00
|
|
|
var row = HBoxLayout.new();
|
|
|
|
list.addItem(row);
|
|
|
|
|
|
|
|
var image_label = gui.widgets.Label.new(content, style, {});
|
|
|
|
image_label.setFixedSize(171, 128);
|
|
|
|
row.addItem(image_label);
|
|
|
|
|
|
|
|
var thumbs = package.thumbnails;
|
|
|
|
if( size(thumbs) > 0 )
|
|
|
|
image_label.setImage(thumbs[0]);
|
|
|
|
else
|
|
|
|
image_label.setText("No thumbnail available");
|
|
|
|
|
|
|
|
var detail_box = VBoxLayout.new();
|
|
|
|
row.addItem(detail_box);
|
2014-06-12 22:32:40 +00:00
|
|
|
row.addSpacing(5);
|
2014-06-11 22:49:18 +00:00
|
|
|
|
|
|
|
var title_box = HBoxLayout.new();
|
|
|
|
detail_box.addItem(title_box);
|
|
|
|
|
|
|
|
title_box.addItem(
|
|
|
|
gui.widgets.Label.new(content, style, {})
|
|
|
|
.setText(package.name)
|
|
|
|
);
|
|
|
|
title_box.addStretch(1);
|
|
|
|
(func {
|
|
|
|
var p = package;
|
|
|
|
var b = gui.widgets.Button.new(content, style, {});
|
|
|
|
var installed = p.installed;
|
2014-06-12 22:32:40 +00:00
|
|
|
var install_text = sprintf("Install (%.1fMB)", p.fileSize/1024/1024);
|
2014-06-11 22:49:18 +00:00
|
|
|
|
|
|
|
if( installed )
|
|
|
|
b.setText("Remove");
|
|
|
|
else
|
2014-06-12 22:32:40 +00:00
|
|
|
b.setText(install_text);
|
2014-06-10 22:38:56 +00:00
|
|
|
|
2014-06-11 22:49:18 +00:00
|
|
|
b.listen("clicked", func
|
|
|
|
{
|
2014-06-10 22:38:56 +00:00
|
|
|
if( installed )
|
2014-06-11 22:49:18 +00:00
|
|
|
{
|
|
|
|
p.uninstall();
|
|
|
|
installed = 0;
|
2014-06-12 22:32:40 +00:00
|
|
|
b.setText(install_text);
|
2014-06-11 22:49:18 +00:00
|
|
|
}
|
|
|
|
else
|
2014-06-10 22:38:56 +00:00
|
|
|
{
|
2014-06-11 22:49:18 +00:00
|
|
|
b.setEnabled(0)
|
|
|
|
.setText("Wait...");
|
|
|
|
p.install()
|
|
|
|
.progress(func(i, cur, total)
|
|
|
|
b.setText(sprintf("%.1f%%", (cur / total) * 100))
|
|
|
|
)
|
|
|
|
.fail(func b.setText('Failed'))
|
|
|
|
.done(func {
|
|
|
|
installed = 1;
|
|
|
|
b.setText("Remove")
|
|
|
|
.setEnabled(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-11 22:49:18 +00:00
|
|
|
title_box.addItem(b);
|
|
|
|
})();
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-13 17:17:40 +00:00
|
|
|
var description = parse_markdown(package.description);
|
2014-06-12 22:32:40 +00:00
|
|
|
if( size(description) <= 0 )
|
2014-06-11 22:49:18 +00:00
|
|
|
{
|
2014-06-12 22:32:40 +00:00
|
|
|
foreach(var cat; ["FDM", "systems", "cockpit", "model"])
|
|
|
|
description ~= cat ~ ": " ~ package.lprop("rating/" ~ cat) ~ "\n";
|
2014-06-10 16:47:13 +00:00
|
|
|
}
|
2014-06-11 22:49:18 +00:00
|
|
|
|
2014-06-12 22:32:40 +00:00
|
|
|
detail_box.addItem(
|
|
|
|
gui.widgets.Label.new(content, style, {wordWrap: 1})
|
|
|
|
.setText(description)
|
|
|
|
);
|
|
|
|
|
|
|
|
detail_box.addStretch(1);
|
2014-06-10 16:47:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AircraftCenter.show();
|