- let menuEnable() consider all <name>s
- always disable tutorial-stop; enable tutorial-start if tutorial available - don't call the tutorial selector "Wizard 1/2". There is only one tutorial selector, the next dialog is already part of the tutorial. Also, the dialogs don't guide you through multi-dialog setup, which is what "wizards" normally stand for. - use tutorial name as dialog title - set button shortcuts (default == return, esc) - make esc go back to select dialog - beautify sliders & some other tweaks
This commit is contained in:
parent
efc1577118
commit
fa37af573c
1 changed files with 62 additions and 60 deletions
122
Nasal/gui.nas
122
Nasal/gui.nas
|
@ -30,14 +30,18 @@ showDialog = func {
|
||||||
##
|
##
|
||||||
# Enable/disable named menu entry
|
# Enable/disable named menu entry
|
||||||
#
|
#
|
||||||
menuEnable = func(name, state) {
|
menuEnable = func(searchname, state) {
|
||||||
foreach (menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
|
foreach (menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
|
||||||
if ((n = menu.getNode("name")) != nil and n.getValue() == name) {
|
foreach (name; menu.getChildren("name")) {
|
||||||
menu.getNode("enabled").setBoolValue(state);
|
if (name.getValue() == searchname) {
|
||||||
|
menu.getNode("enabled").setBoolValue(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
foreach (item; menu.getChildren("item")) {
|
foreach (item; menu.getChildren("item")) {
|
||||||
if ((n = item.getNode("name")) != nil and n.getValue() == name) {
|
foreach (name; item.getChildren("name")) {
|
||||||
item.getNode("enabled").setBoolValue(state);
|
if (name.getValue() == searchname) {
|
||||||
|
item.getNode("enabled").setBoolValue(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +71,8 @@ INIT = func {
|
||||||
# enable/disable menu entries
|
# enable/disable menu entries
|
||||||
menuEnable("fuel-and-payload", getprop("/sim/flight-model") == "yasim");
|
menuEnable("fuel-and-payload", getprop("/sim/flight-model") == "yasim");
|
||||||
menuEnable("autopilot", props.globals.getNode("/autopilot/KAP140/locks") == nil);
|
menuEnable("autopilot", props.globals.getNode("/autopilot/KAP140/locks") == nil);
|
||||||
menuEnable("tutorial", size(props.globals.getNode("/sim").getChildren("tutorial")));
|
menuEnable("tutorial-start", size(props.globals.getNode("/sim").getChildren("tutorial")));
|
||||||
|
menuEnable("tutorial-stop", 0);
|
||||||
|
|
||||||
var fps = props.globals.getNode("/sim/rendering/fps-display", 1);
|
var fps = props.globals.getNode("/sim/rendering/fps-display", 1);
|
||||||
setlistener(fps, fpsDisplay, 1);
|
setlistener(fps, fpsDisplay, 1);
|
||||||
|
@ -158,7 +163,7 @@ dialog = {};
|
||||||
#
|
#
|
||||||
showSelTutDialog = func {
|
showSelTutDialog = func {
|
||||||
name = "selectTutorial";
|
name = "selectTutorial";
|
||||||
title = "Tutorial Wizard - Step 1/2";
|
title = "Select Tutorial";
|
||||||
|
|
||||||
#
|
#
|
||||||
# Immediately stop any tutorials that are running.
|
# Immediately stop any tutorials that are running.
|
||||||
|
@ -187,10 +192,6 @@ showSelTutDialog = func {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ltextarea = dialog[name].addChild("text");
|
|
||||||
ltextarea.set("label", "Please choose a tutorial from the list below");
|
|
||||||
ltextarea.set("halign", "center");
|
|
||||||
|
|
||||||
contentArea = dialog[name].addChild("group");
|
contentArea = dialog[name].addChild("group");
|
||||||
contentArea.set("layout", "hbox");
|
contentArea.set("layout", "hbox");
|
||||||
|
|
||||||
|
@ -204,15 +205,16 @@ showSelTutDialog = func {
|
||||||
|
|
||||||
# Get a list of all tutorials
|
# Get a list of all tutorials
|
||||||
ltutorials = props.globals.getNode("/sim/tutorial").getChildren("tutorial");
|
ltutorials = props.globals.getNode("/sim/tutorial").getChildren("tutorial");
|
||||||
for(i=0; i<size(ltutorials); i+=1)
|
for(i=0; i<size(ltutorials); i+=1) {
|
||||||
{
|
c = ltutorials[i];
|
||||||
c = ltutorials[i];
|
if (c.getChild("name") != nil) {
|
||||||
if (c.getChild("name") != nil)
|
lname = c.getChild("name").getValue();
|
||||||
{
|
lentry = combo.addChild("value");
|
||||||
lname = c.getChild("name").getValue();
|
lentry.prop().setValue(lname);
|
||||||
lentry = combo.addChild("value");
|
if (i == 0) {
|
||||||
lentry.prop().setValue(lname);
|
setprop("/sim/tutorial/current-tutorial", lname);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonBar = dialog[name].addChild("group");
|
buttonBar = dialog[name].addChild("group");
|
||||||
|
@ -221,11 +223,14 @@ showSelTutDialog = func {
|
||||||
|
|
||||||
lcancel = buttonBar.addChild("button");
|
lcancel = buttonBar.addChild("button");
|
||||||
lcancel.set("legend", "Cancel");
|
lcancel.set("legend", "Cancel");
|
||||||
|
lcancel.set("keynum", 27);
|
||||||
|
lcancel.set("equal", 1);
|
||||||
lcancel.prop().getNode("binding[0]/command", 1).setValue("dialog-close");
|
lcancel.prop().getNode("binding[0]/command", 1).setValue("dialog-close");
|
||||||
|
|
||||||
lnext = buttonBar.addChild("button");
|
lnext = buttonBar.addChild("button");
|
||||||
lnext.set("legend", "Next");
|
lnext.set("legend", "Next");
|
||||||
lnext.set("keynum", 27);
|
lnext.set("default", 1);
|
||||||
|
lnext.set("equal", 1);
|
||||||
lnext.prop().getNode("binding[0]/command", 1).setValue("dialog-apply");
|
lnext.prop().getNode("binding[0]/command", 1).setValue("dialog-apply");
|
||||||
lnext.prop().getNode("binding[1]/command", 1).setValue("nasal");
|
lnext.prop().getNode("binding[1]/command", 1).setValue("nasal");
|
||||||
lnext.prop().getNode("binding[1]/script", 1).setValue("gui.showTutorialDialog()");
|
lnext.prop().getNode("binding[1]/script", 1).setValue("gui.showTutorialDialog()");
|
||||||
|
@ -239,7 +244,25 @@ showSelTutDialog = func {
|
||||||
|
|
||||||
showTutorialDialog = func {
|
showTutorialDialog = func {
|
||||||
name = "displayTutorial";
|
name = "displayTutorial";
|
||||||
title = "Tutorial Wizard - Step 2/2";
|
|
||||||
|
# Get tutorial title and description
|
||||||
|
ltutorial = getprop("/sim/tutorial/current-tutorial");
|
||||||
|
|
||||||
|
if (ltutorial == nil) { ltutorial = "<undefined>"; }
|
||||||
|
|
||||||
|
lfound = 0;
|
||||||
|
ldescription = "No description available for this tutorial.";
|
||||||
|
|
||||||
|
foreach(c; props.globals.getNode("/sim/tutorial").getChildren("tutorial")) {
|
||||||
|
if (c.getChild("name").getValue() == ltutorial) {
|
||||||
|
lfound = 1;
|
||||||
|
if (c.getChild("description") != nil) {
|
||||||
|
ldescription = c.getChild("description") .getValue();
|
||||||
|
setprop("/sim/tutorial/description", ldescription);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
title = "Tutorial \"" ~ ltutorial ~ "\"";
|
||||||
|
|
||||||
#
|
#
|
||||||
# General Dialog Structure
|
# General Dialog Structure
|
||||||
|
@ -253,27 +276,6 @@ showTutorialDialog = func {
|
||||||
|
|
||||||
dialog[name].addChild("hrule").set("pref-height", 1);
|
dialog[name].addChild("hrule").set("pref-height", 1);
|
||||||
|
|
||||||
# Get the tutorial description
|
|
||||||
ltutorial = getprop("/sim/tutorial/current-tutorial");
|
|
||||||
|
|
||||||
if (ltutorial == nil) { ltutorial = "<undefined>"; }
|
|
||||||
|
|
||||||
lfound = 0;
|
|
||||||
ldescription = "No description available for this tutorial.";
|
|
||||||
|
|
||||||
foreach(c; props.globals.getNode("/sim/tutorial").getChildren("tutorial"))
|
|
||||||
{
|
|
||||||
if (c.getChild("name").getValue() == ltutorial)
|
|
||||||
{
|
|
||||||
lfound = 1;
|
|
||||||
if (c.getChild("description") != nil)
|
|
||||||
{
|
|
||||||
ldescription = c.getChild("description") .getValue();
|
|
||||||
setprop("/sim/tutorial/description", ldescription);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lfound == 0) {
|
if (lfound == 0) {
|
||||||
msg = dialog[name].addChild("text");
|
msg = dialog[name].addChild("text");
|
||||||
msg.set("label", "Unable to find tutorial " ~ ltutorial);
|
msg.set("label", "Unable to find tutorial " ~ ltutorial);
|
||||||
|
@ -288,36 +290,36 @@ showTutorialDialog = func {
|
||||||
contentArea = dialog[name].addChild("group");
|
contentArea = dialog[name].addChild("group");
|
||||||
contentArea.set("layout", "hbox");
|
contentArea.set("layout", "hbox");
|
||||||
|
|
||||||
label = contentArea.addChild("text");
|
|
||||||
label.set("label", "Tutorial: " ~ ltutorial);
|
|
||||||
label.set("halign", "left");
|
|
||||||
|
|
||||||
textarea = dialog[name].addChild("textbox");
|
textarea = dialog[name].addChild("textbox");
|
||||||
textarea.set("pref-width", "600");
|
textarea.set("pref-width", "600");
|
||||||
textarea.set("pref-height", "400");
|
textarea.set("pref-height", "400");
|
||||||
textarea.set("slider", "12");
|
textarea.set("slider", "20");
|
||||||
textarea.set("live", "true");
|
|
||||||
textarea.set("wrap", "true");
|
textarea.set("wrap", "true");
|
||||||
textarea.set("editable", "false");
|
textarea.set("editable", "false");
|
||||||
textarea.set("valign", "top");
|
textarea.set("valign", "top");
|
||||||
textarea.set("halign", "left");
|
textarea.set("halign", "fill");
|
||||||
textarea.set("property", "/sim/tutorial/description");
|
textarea.set("property", "/sim/tutorial/description");
|
||||||
|
|
||||||
buttonBar = dialog[name].addChild("group");
|
buttonBar = dialog[name].addChild("group");
|
||||||
buttonBar.set("layout", "hbox");
|
buttonBar.set("layout", "hbox");
|
||||||
buttonBar.set("default-padding", 10);
|
buttonBar.set("default-padding", 10);
|
||||||
|
|
||||||
lcancel = buttonBar.addChild("button");
|
lback = buttonBar.addChild("button");
|
||||||
lcancel.set("legend", "Cancel");
|
lback.set("legend", "Back");
|
||||||
lcancel.prop().getNode("binding[0]/command", 1).setValue("dialog-close");
|
lback.set("equal", 1);
|
||||||
|
lback.set("keynum", 27);
|
||||||
|
lback.prop().getNode("binding[0]/command", 1).setValue("nasal");
|
||||||
|
lback.prop().getNode("binding[0]/script", 1).setValue("gui.showSelTutDialog()");
|
||||||
|
lback.prop().getNode("binding[1]/command", 1).setValue("dialog-close");
|
||||||
|
|
||||||
lnext = buttonBar.addChild("button");
|
lnext = buttonBar.addChild("button");
|
||||||
lnext.set("legend", "Start Tutorial");
|
lnext.set("legend", "Start");
|
||||||
lnext.set("keynum", 27);
|
lnext.set("default", 1);
|
||||||
lnext.prop().getNode("binding[0]/command", 1).setValue("dialog-apply");
|
lnext.set("pref-width", 100);
|
||||||
lnext.prop().getNode("binding[1]/command", 1).setValue("nasal");
|
lnext.set("equal", 1);
|
||||||
lnext.prop().getNode("binding[1]/script", 1).setValue("tutorial.startTutorial()");
|
lnext.prop().getNode("binding[0]/command", 1).setValue("nasal");
|
||||||
lnext.prop().getNode("binding[2]/command", 1).setValue("dialog-close");
|
lnext.prop().getNode("binding[0]/script", 1).setValue("tutorial.startTutorial()");
|
||||||
|
lnext.prop().getNode("binding[1]/command", 1).setValue("dialog-close");
|
||||||
|
|
||||||
# All done: pop it up
|
# All done: pop it up
|
||||||
fgcommand("dialog-new", dialog[name].prop());
|
fgcommand("dialog-new", dialog[name].prop());
|
||||||
|
@ -626,7 +628,7 @@ showHelpDialog = func {
|
||||||
}
|
}
|
||||||
|
|
||||||
w = dialog[name].addChild("textbox");
|
w = dialog[name].addChild("textbox");
|
||||||
w.set("halign", "center");
|
w.set("halign", "fill");
|
||||||
w.set("slider", 20);
|
w.set("slider", 20);
|
||||||
w.set("pref-width", width);
|
w.set("pref-width", width);
|
||||||
w.set("pref-height", height);
|
w.set("pref-height", height);
|
||||||
|
|
Loading…
Add table
Reference in a new issue