f8bbc32d68
Only show max 50 aircraft by default and provide a "Show More" button. This prevents locking the GUI for up to nearly 15 seconds with showing the list of all aircraft.
266 lines
6.9 KiB
Text
266 lines
6.9 KiB
Text
var AircraftCenter = {
|
|
new: func
|
|
{
|
|
var m = {
|
|
parents: [AircraftCenter],
|
|
_dlg: canvas.Window.new([600,500], "dialog")
|
|
.set("title", "Aircraft Center")
|
|
.set("resize", 1),
|
|
_active_button: nil,
|
|
_show_more: nil
|
|
};
|
|
|
|
m._dlg.getCanvas(1)
|
|
.set("background", canvas.style.getColor("bg_color"));
|
|
m._root = m._dlg.getCanvas().createGroup();
|
|
|
|
var vbox = VBoxLayout.new();
|
|
m._dlg.setLayout(vbox);
|
|
|
|
m._tab_bar = HBoxLayout.new();
|
|
vbox.addItem(m._tab_bar);
|
|
|
|
m._tab_bar.addStretch(1);
|
|
m._tab_bar.addStretch(1);
|
|
|
|
var scroll = gui.widgets.ScrollArea.new(m._root, style, {size: [96, 128]})
|
|
.move(20, 100);
|
|
vbox.addItem(scroll, 1);
|
|
|
|
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();
|
|
me._show_more = nil;
|
|
|
|
settimer(func me.fillList(pkg.root.search(filter)), 0);
|
|
});
|
|
|
|
if( me._active_button == nil )
|
|
b.setChecked(1);
|
|
|
|
return me;
|
|
},
|
|
fillList: func(packages)
|
|
{
|
|
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 )
|
|
{
|
|
me._list.removeItem(me._show_more);
|
|
me._show_more = nil;
|
|
}
|
|
|
|
for(var i = begin; i < end; i += 1)
|
|
{
|
|
var package = packages[i];
|
|
var row = HBoxLayout.new();
|
|
me._list.addItem(row);
|
|
|
|
var image_label = gui.widgets.Label.new(me._scroll_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);
|
|
row.addSpacing(5);
|
|
|
|
var title_box = HBoxLayout.new();
|
|
detail_box.addItem(title_box);
|
|
|
|
title_box.addItem(
|
|
gui.widgets.Label.new(me._scroll_content, style, {})
|
|
.setText(package.name)
|
|
);
|
|
title_box.addStretch(1);
|
|
(func {
|
|
var p = package;
|
|
var b = gui.widgets.Button.new(me._scroll_content, style, {});
|
|
var installed = p.installed;
|
|
var install_text = sprintf("Install (%.1fMB)", p.fileSize/1024/1024);
|
|
|
|
if( installed )
|
|
b.setText("Remove");
|
|
else
|
|
b.setText(install_text);
|
|
|
|
b.listen("clicked", func
|
|
{
|
|
if( installed )
|
|
{
|
|
p.uninstall();
|
|
installed = 0;
|
|
b.setText(install_text);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
});
|
|
}
|
|
});
|
|
|
|
title_box.addItem(b);
|
|
})();
|
|
|
|
var description = parse_markdown(package.description);
|
|
if( size(description) <= 0 )
|
|
{
|
|
foreach(var cat; ["FDM", "systems", "cockpit", "model"])
|
|
description ~= cat ~ ": " ~ package.lprop("rating/" ~ cat) ~ "\n";
|
|
}
|
|
|
|
detail_box.addItem(
|
|
gui.widgets.Label.new(me._scroll_content, style, {wordWrap: 1})
|
|
.setText(description)
|
|
);
|
|
|
|
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);
|
|
}
|
|
|
|
detail_box.addStretch(1);
|
|
}
|
|
|
|
# get rid of references to widgets of last package
|
|
row = nil;
|
|
image_label = nil;
|
|
detail_box = nil;
|
|
title_box = nil;
|
|
launch_bar = nil;
|
|
|
|
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));
|
|
|
|
me._show_more = VBoxLayout.new();
|
|
me._list.addItem(me._show_more);
|
|
|
|
me._show_more.addSpacing(3);
|
|
var hbox = HBoxLayout.new();
|
|
me._show_more.addItem(hbox);
|
|
me._show_more.addSpacing(5);
|
|
|
|
hbox.addStretch(1);
|
|
hbox.addItem(
|
|
gui.widgets.Button.new(me._scroll_content, style, {})
|
|
.setText("Show more...")
|
|
.listen("clicked", func
|
|
me._addPackageEntries(packages, start, end)
|
|
)
|
|
);
|
|
hbox.addStretch(1);
|
|
|
|
hbox = nil;
|
|
}
|
|
|
|
# Add some stretch in case the scroll area is larger than the list
|
|
me._list.addStretch(1);
|
|
|
|
me._info_label.setText(
|
|
"Install/remove aircraft (Showing " ~ num_info ~ " aircraft)"
|
|
);
|
|
me._dlg.getCanvas().update();
|
|
}
|
|
};
|
|
|
|
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
|
|
);
|