2014-06-10 16:47:13 +00:00
|
|
|
var AircraftCenter = {
|
2014-06-16 19:55:35 +00:00
|
|
|
new: func
|
2014-06-10 16:47:13 +00:00
|
|
|
{
|
2014-06-16 19:55:35 +00:00
|
|
|
var m = {
|
|
|
|
parents: [AircraftCenter],
|
|
|
|
_dlg: canvas.Window.new([600,500], "dialog")
|
|
|
|
.set("title", "Aircraft Center")
|
|
|
|
.set("resize", 1),
|
|
|
|
_active_button: nil
|
|
|
|
};
|
|
|
|
|
|
|
|
m._dlg.getCanvas(1)
|
|
|
|
.set("background", canvas.style.getColor("bg_color"));
|
|
|
|
m._root = m._dlg.getCanvas().createGroup();
|
2014-06-10 16:47:13 +00:00
|
|
|
|
|
|
|
var vbox = VBoxLayout.new();
|
2014-06-16 19:55:35 +00:00
|
|
|
m._dlg.setLayout(vbox);
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
m._tab_bar = HBoxLayout.new();
|
|
|
|
vbox.addItem(m._tab_bar);
|
2014-06-11 22:49:18 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
m._tab_bar.addStretch(1);
|
|
|
|
m._tab_bar.addStretch(1);
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
var scroll = gui.widgets.ScrollArea.new(m._root, style, {size: [96, 128]})
|
2014-06-10 16:47:13 +00:00
|
|
|
.move(20, 100);
|
|
|
|
vbox.addItem(scroll, 1);
|
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
m._scroll_content =
|
|
|
|
scroll.getContent()
|
|
|
|
.set("font", "LiberationFonts/LiberationSans-Bold.ttf")
|
|
|
|
.set("character-size", 16)
|
|
|
|
.set("alignment", "left-center");
|
|
|
|
|
|
|
|
m._list = VBoxLayout.new();
|
|
|
|
scroll.setLayout(m._list);
|
|
|
|
|
|
|
|
m._info_label = gui.widgets.Label.new(m._root, style, {wordWrap: 1});
|
|
|
|
vbox.addItem(m._info_label);
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
addPage: func(name, filter)
|
|
|
|
{
|
|
|
|
var b = gui.widgets.Button.new(me._root, style, {})
|
|
|
|
.setText(name)
|
|
|
|
.setCheckable(1);
|
|
|
|
me._tab_bar.insertItem(me._tab_bar.count() - 1, b);
|
|
|
|
|
|
|
|
b.listen("toggled", func(e)
|
|
|
|
{
|
|
|
|
if( !e.detail.checked )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( me._active_button != nil )
|
|
|
|
me._active_button.setChecked(0);
|
|
|
|
me._active_button = b;
|
|
|
|
|
|
|
|
me._list.clear();
|
|
|
|
settimer(func me.fillList(pkg.root.search(filter)), 0);
|
|
|
|
});
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
if( me._active_button == nil )
|
|
|
|
b.setChecked(1);
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
return me;
|
|
|
|
},
|
|
|
|
fillList: func(packages)
|
|
|
|
{
|
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();
|
2014-06-16 19:55:35 +00:00
|
|
|
me._list.addItem(row);
|
2014-06-11 22:49:18 +00:00
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
var image_label = gui.widgets.Label.new(me._scroll_content, style, {});
|
2014-06-11 22:49:18 +00:00
|
|
|
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(
|
2014-06-16 19:55:35 +00:00
|
|
|
gui.widgets.Label.new(me._scroll_content, style, {})
|
2014-06-11 22:49:18 +00:00
|
|
|
.setText(package.name)
|
|
|
|
);
|
|
|
|
title_box.addStretch(1);
|
|
|
|
(func {
|
|
|
|
var p = package;
|
2014-06-16 19:55:35 +00:00
|
|
|
var b = gui.widgets.Button.new(me._scroll_content, style, {});
|
2014-06-11 22:49:18 +00:00
|
|
|
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(
|
2014-06-16 19:55:35 +00:00
|
|
|
gui.widgets.Label.new(me._scroll_content, style, {wordWrap: 1})
|
2014-06-12 22:32:40 +00:00
|
|
|
.setText(description)
|
|
|
|
);
|
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
if( package.installed )
|
|
|
|
{
|
|
|
|
var launch_bar = HBoxLayout.new();
|
|
|
|
detail_box.addItem(launch_bar);
|
|
|
|
|
|
|
|
var variants = keys(package.variants);
|
|
|
|
foreach(var variant; variants)
|
|
|
|
{(func{
|
|
|
|
var b = gui.widgets.Button.new(me._scroll_content, style, {})
|
|
|
|
.setText(package.variants[variant]);
|
|
|
|
var acft_id = variant;
|
|
|
|
b.listen("clicked", func
|
|
|
|
{
|
|
|
|
print("launch " ~ acft_id ~ '(' ~ package.variants[variant] ~ ')');
|
|
|
|
fgcommand("switch-aircraft", props.Node.new({"aircraft": acft_id}));
|
|
|
|
});
|
|
|
|
launch_bar.addItem(b);
|
|
|
|
})();}
|
|
|
|
launch_bar.addStretch(1);
|
|
|
|
}
|
|
|
|
|
2014-06-12 22:32:40 +00:00
|
|
|
detail_box.addStretch(1);
|
2014-06-10 16:47:13 +00:00
|
|
|
}
|
2014-06-16 19:55:35 +00:00
|
|
|
|
|
|
|
# get rid of references to widgets of last package
|
|
|
|
row = nil;
|
|
|
|
image_label = nil;
|
|
|
|
detail_box = nil;
|
|
|
|
title_box = nil;
|
|
|
|
launch_bar = nil;
|
|
|
|
|
|
|
|
me._info_label.setText(
|
|
|
|
"Install/remove aircraft (Showing " ~ size(packages) ~ " aircraft)"
|
|
|
|
);
|
|
|
|
|
|
|
|
me._dlg.getCanvas().update();
|
2014-06-10 16:47:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-18 15:25:15 +00:00
|
|
|
MessageBox.warning(
|
|
|
|
"Experimental Feature...",
|
|
|
|
"The Aircraft Center is only a preview and not yet in a stable state!",
|
|
|
|
func(sel)
|
|
|
|
{
|
|
|
|
if( sel != MessageBox.Ok )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var ac = AircraftCenter.new();
|
|
|
|
ac.addPage("Rated", {
|
|
|
|
'rating-FDM': 2,
|
|
|
|
'rating-cockpit': 2,
|
|
|
|
'rating-model': 2,
|
|
|
|
'rating-systems': 1
|
|
|
|
});
|
|
|
|
ac.addPage("Installed", {
|
|
|
|
'installed': 1
|
|
|
|
});
|
|
|
|
ac.addPage("All", {});
|
|
|
|
},
|
|
|
|
MessageBox.Ok | MessageBox.Cancel | MessageBox.DontShowAgain
|
|
|
|
);
|