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),
|
2014-06-28 11:12:38 +00:00
|
|
|
_active_button: nil,
|
|
|
|
_show_more: nil
|
2014-06-16 19:55:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
2014-06-28 11:12:38 +00:00
|
|
|
me._show_more = nil;
|
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
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-28 11:12:38 +00:00
|
|
|
var num_packages = size(packages);
|
|
|
|
var end = num_packages;
|
|
|
|
|
|
|
|
if( num_packages > 55 )
|
|
|
|
end = 50;
|
|
|
|
|
|
|
|
me._addPackageEntries(packages, 0, end);
|
|
|
|
},
|
|
|
|
# @param packages
|
|
|
|
# @param begin index of first package
|
|
|
|
# @param end index after last package
|
|
|
|
_addPackageEntries: func(packages, begin, end)
|
|
|
|
{
|
|
|
|
# remove stretch at end of list
|
|
|
|
me._list.takeAt(-1);
|
|
|
|
|
|
|
|
if( me._show_more != nil )
|
2014-06-10 16:47:13 +00:00
|
|
|
{
|
2014-06-28 11:12:38 +00:00
|
|
|
me._list.removeItem(me._show_more);
|
|
|
|
me._show_more = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i = begin; i < end; i += 1)
|
|
|
|
{
|
|
|
|
var package = packages[i];
|
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-12 22:32:40 +00:00
|
|
|
var install_text = sprintf("Install (%.1fMB)", p.fileSize/1024/1024);
|
2014-06-11 22:49:18 +00:00
|
|
|
|
2014-06-30 16:16:22 +00:00
|
|
|
if( p.installed )
|
2014-06-11 22:49:18 +00:00
|
|
|
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-30 16:16:22 +00:00
|
|
|
if( p.installed )
|
2014-06-11 22:49:18 +00:00
|
|
|
{
|
|
|
|
p.uninstall();
|
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-30 16:16:22 +00:00
|
|
|
b.setText("Wait...").setEnabled(0);
|
|
|
|
p.install();
|
2014-06-11 22:49:18 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-10 16:47:13 +00:00
|
|
|
|
2014-06-30 16:16:22 +00:00
|
|
|
p.existingInstall(func(pkg, ins) {
|
|
|
|
ins.progress(func(i, cur, total)
|
|
|
|
b.setText(sprintf("%.1f%%", (cur / total) * 100))
|
|
|
|
);
|
|
|
|
ins.fail(func b.setText('Failed'));
|
|
|
|
ins.done(func b.setText("Remove").setEnabled(1));
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
{
|
2014-07-12 15:56:25 +00:00
|
|
|
printlog("warn", "Switching to aircraft '" ~ acft_id ~ "'");
|
2014-06-16 19:55:35 +00:00
|
|
|
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;
|
|
|
|
|
2014-06-28 11:12:38 +00:00
|
|
|
var num_info = size(packages);
|
|
|
|
|
|
|
|
if( end < size(packages) )
|
|
|
|
{
|
|
|
|
num_info = end ~ " of " ~ num_info;
|
|
|
|
|
|
|
|
# range of next "page"
|
|
|
|
start = end;
|
|
|
|
end = math.min(end + 50, size(packages));
|
|
|
|
|
2014-08-04 22:22:14 +00:00
|
|
|
me._show_more =
|
2014-06-28 11:12:38 +00:00
|
|
|
gui.widgets.Button.new(me._scroll_content, style, {})
|
|
|
|
.setText("Show more...")
|
|
|
|
.listen("clicked", func
|
|
|
|
me._addPackageEntries(packages, start, end)
|
2014-08-04 22:22:14 +00:00
|
|
|
);
|
|
|
|
me._show_more.setContentsMargin(5);
|
|
|
|
me._list.addItem(me._show_more, 0, canvas.AlignHCenter);
|
2014-06-28 11:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add some stretch in case the scroll area is larger than the list
|
|
|
|
me._list.addStretch(1);
|
|
|
|
|
2014-06-16 19:55:35 +00:00
|
|
|
me._info_label.setText(
|
2014-06-28 11:12:38 +00:00
|
|
|
"Install/remove aircraft (Showing " ~ num_info ~ " aircraft)"
|
2014-06-16 19:55:35 +00:00
|
|
|
);
|
|
|
|
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
|
|
|
|
);
|