add setViewByIndex to view.nas
This commit is contained in:
parent
3738d84d7b
commit
aaa7888f6b
1 changed files with 14 additions and 1 deletions
|
@ -3,6 +3,10 @@
|
||||||
##
|
##
|
||||||
## Nasal code for implementing view-specific functionality.
|
## Nasal code for implementing view-specific functionality.
|
||||||
|
|
||||||
|
# ATTENTION:
|
||||||
|
# /sim/current-view/view-number is in the range 0..viewCount, it is NOT
|
||||||
|
# the index used in aircraft XML files (e.g. <view n="100">)
|
||||||
|
|
||||||
# For debugging. Returns string containing description of <x>.
|
# For debugging. Returns string containing description of <x>.
|
||||||
#
|
#
|
||||||
var str = func(x, prefix='') {
|
var str = func(x, prefix='') {
|
||||||
|
@ -25,10 +29,17 @@ var str = func(x, prefix='') {
|
||||||
}
|
}
|
||||||
|
|
||||||
var index = nil; # current view index
|
var index = nil; # current view index
|
||||||
|
var indices = {}; # view_index -> number
|
||||||
var views = nil; # list of all view branches (/sim/view[n]) as props.Node
|
var views = nil; # list of all view branches (/sim/view[n]) as props.Node
|
||||||
var current = nil; # current view branch (e.g. /sim/view[1]) as props.Node
|
var current = nil; # current view branch (e.g. /sim/view[1]) as props.Node
|
||||||
var fovProp = nil;
|
var fovProp = nil;
|
||||||
|
|
||||||
|
# activate view by index number used in XML definition (e.g. >100)
|
||||||
|
var setViewByIndex = func(i) {
|
||||||
|
if (indices[i] != nil)
|
||||||
|
setprop("/sim/current-view/view-number", indices[i]);
|
||||||
|
}
|
||||||
|
|
||||||
var hasmember = func(class, member) {
|
var hasmember = func(class, member) {
|
||||||
if (contains(class, member))
|
if (contains(class, member))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -261,6 +272,7 @@ var manager = {
|
||||||
set_default(helicopter_view, "config/target-z-offset-m", viewnode);
|
set_default(helicopter_view, "config/target-z-offset-m", viewnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# see comment at begin of file
|
||||||
setlistener("/sim/current-view/view-number", func(n) {
|
setlistener("/sim/current-view/view-number", func(n) {
|
||||||
manager.set_view(n.getValue());
|
manager.set_view(n.getValue());
|
||||||
}, 1);
|
}, 1);
|
||||||
|
@ -835,7 +847,7 @@ _setlistener("/sim/startup/ysize", func {
|
||||||
|
|
||||||
|
|
||||||
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
||||||
removelistener(fdm_init_listener); # uninstall, so we're only called once
|
removelistener(fdm_init_listener); # uninstall, so we are only called once
|
||||||
var zoffset = nil;
|
var zoffset = nil;
|
||||||
foreach (var v; views) {
|
foreach (var v; views) {
|
||||||
var index = v.getIndex();
|
var index = v.getIndex();
|
||||||
|
@ -855,6 +867,7 @@ var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
||||||
}
|
}
|
||||||
|
|
||||||
forindex (var i; views) {
|
forindex (var i; views) {
|
||||||
|
indices[views[i].getIndex()] = i;
|
||||||
var limits = views[i].getNode("config/limits/enabled");
|
var limits = views[i].getNode("config/limits/enabled");
|
||||||
if (limits != nil) {
|
if (limits != nil) {
|
||||||
func (i) {
|
func (i) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue