- make modelmgr a singleton class
- add selected_models() function - fix help screen
This commit is contained in:
parent
95a652be17
commit
205675455c
2 changed files with 65 additions and 71 deletions
|
@ -167,7 +167,7 @@
|
||||||
<line>  ~/.fgfs/ufo-model-export.xml (Unix)</line>
|
<line>  ~/.fgfs/ufo-model-export.xml (Unix)</line>
|
||||||
<line>  %APPDATA%\flightgear.org\ufo-model-export.xml (Microsoft Windows)</line>
|
<line>  %APPDATA%\flightgear.org\ufo-model-export.xml (Microsoft Windows)</line>
|
||||||
<line/>
|
<line/>
|
||||||
<line>In the adjustment dialog (SPACE-key) holding the Ctrl or Shift key down</line>
|
<line>In the adjustment dialog (TAB-key) holding the Ctrl or Shift key down</line>
|
||||||
<line>makes slider effects coarser/finer.</line>
|
<line>makes slider effects coarser/finer.</line>
|
||||||
</help>
|
</help>
|
||||||
</sim>
|
</sim>
|
||||||
|
|
|
@ -51,8 +51,8 @@ setlistener("/sim/signals/screenshot", func(n) {
|
||||||
if (n.getBoolValue()) {
|
if (n.getBoolValue()) {
|
||||||
status_restore = status_dialog.is_open();
|
status_restore = status_dialog.is_open();
|
||||||
status_dialog.close();
|
status_dialog.close();
|
||||||
} else {
|
} elsif (status_restore) {
|
||||||
status_restore and status_dialog.open();
|
status_dialog.open();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,29 +92,29 @@ mouse.loop = func {
|
||||||
return settimer(mouse.loop, 0);
|
return settimer(mouse.loop, 0);
|
||||||
|
|
||||||
var dx = mouse.x - mouse.centerx;
|
var dx = mouse.x - mouse.centerx;
|
||||||
var dy = mouse.y - mouse.centery;
|
var dy = -mouse.y + mouse.centery;
|
||||||
if (!dx and !dy)
|
if (!dx and !dy)
|
||||||
return settimer(mouse.loop, 0);
|
return settimer(mouse.loop, 0);
|
||||||
|
|
||||||
var speed = KbdShift.getValue() ? 1 : 0.1;
|
var speed = KbdShift.getValue() ? 1 : 0.1;
|
||||||
var progress = 1.7;
|
var progress = 1.7;
|
||||||
var powx = npow(dx, progress) * speed;
|
var powx = npow(dx, progress) * speed;
|
||||||
var powy = -npow(dy, progress) * speed;
|
var powy = npow(dy, progress) * speed;
|
||||||
var option = mouse.lmb or gear_key_down;
|
var option = mouse.lmb or gear_key_down;
|
||||||
|
|
||||||
if (KbdCtrl.getValue()) { # operation
|
if (KbdCtrl.getValue()) { # operation
|
||||||
if (dx) {
|
if (dx) {
|
||||||
if (option)
|
if (option)
|
||||||
modelmgr.adjust("bearing", dx * 0.05, 1);
|
modelmgr.adjust("bearing", dx * 0.03, 1);
|
||||||
else
|
else
|
||||||
modelmgr.adjust("transversal", powx * 0.05, 1);
|
modelmgr.adjust("transversal", powx * 0.03, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dy) {
|
if (dy) {
|
||||||
if (option)
|
if (option)
|
||||||
modelmgr.adjust("altitude", powy * 0.05, 1);
|
modelmgr.adjust("altitude", powy * 0.03, 1);
|
||||||
else
|
else
|
||||||
modelmgr.adjust("longitudinal", powy * 0.05, 1);
|
modelmgr.adjust("longitudinal", powy * 0.03, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { # navigation
|
} else { # navigation
|
||||||
|
@ -297,13 +297,11 @@ var Model = {
|
||||||
m.hdg = ModelValue.new(m.node, "heading-deg", hdg);
|
m.hdg = ModelValue.new(m.node, "heading-deg", hdg);
|
||||||
m.pitch = ModelValue.new(m.node, "pitch-deg", pitch);
|
m.pitch = ModelValue.new(m.node, "pitch-deg", pitch);
|
||||||
m.roll = ModelValue.new(m.node, "roll-deg", roll);
|
m.roll = ModelValue.new(m.node, "roll-deg", roll);
|
||||||
|
m.node.getNode("load", 1).remove();
|
||||||
m.node.getNode("load", 1).setValue(1);
|
|
||||||
m.node.removeChildren("load");
|
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
remove : func {
|
remove : func {
|
||||||
props.globals.getNode("/models", 1).removeChild("model", me.node.getIndex());
|
me.node.remove();
|
||||||
},
|
},
|
||||||
clone : func(path) {
|
clone : func(path) {
|
||||||
Model.new(path, geo.Coord.new(me.pos), me.node);
|
Model.new(path, geo.Coord.new(me.pos), me.node);
|
||||||
|
@ -414,25 +412,22 @@ var Model = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var ModelMgr = {
|
var modelmgr = {
|
||||||
new : func(path) {
|
init : func(path) {
|
||||||
var m = { parents: [ModelMgr] };
|
me.active = nil;
|
||||||
m.active = nil;
|
me.models = [];
|
||||||
m.models = [];
|
me.legendN = props.globals.getNode("/sim/gui/dialogs/ufo-status/input", 1);
|
||||||
m.legendN = props.globals.getNode("/sim/gui/dialogs/ufo-status/input", 1);
|
me.legendN.setValue("");
|
||||||
m.legendN.setValue("");
|
me.mouse_coord = geo.aircraft_position();
|
||||||
m.mouse_coord = geo.aircraft_position();
|
me.import();
|
||||||
m.import();
|
me.marker = Model.new("Aircraft/ufo/Models/marker.ac", geo.Coord.new().set_xyz(0, 0, 0));
|
||||||
m.marker = Model.new("Aircraft/ufo/Models/marker.ac", geo.Coord.new().set_xyz(0, 0, 0));
|
me.marker.hide();
|
||||||
m.marker.hide();
|
me.modelpath = path;
|
||||||
m.modelpath = path;
|
if (me.active != nil)
|
||||||
if (m.active != nil)
|
me.marker.move(me.active.pos);
|
||||||
m.marker.move(m.active.pos);
|
|
||||||
|
|
||||||
if (path != "Aircraft/ufo/Models/cursor.ac")
|
if (path != "Aircraft/ufo/Models/cursor.ac")
|
||||||
status_dialog.open();
|
status_dialog.open();
|
||||||
|
|
||||||
return m;
|
|
||||||
},
|
},
|
||||||
click : func(mouse_coord) {
|
click : func(mouse_coord) {
|
||||||
if (gear_key_down)
|
if (gear_key_down)
|
||||||
|
@ -500,6 +495,13 @@ var ModelMgr = {
|
||||||
|
|
||||||
me.display_status(me.modelpath = me.active.path);
|
me.display_status(me.modelpath = me.active.path);
|
||||||
},
|
},
|
||||||
|
selected_models : func {
|
||||||
|
var models = [];
|
||||||
|
foreach (var m; me.models)
|
||||||
|
if (m.selected)
|
||||||
|
append(models, m);
|
||||||
|
return models;
|
||||||
|
},
|
||||||
deselect_all : func {
|
deselect_all : func {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.models)
|
||||||
m.flash(m.selected = 0);
|
m.flash(m.selected = 0);
|
||||||
|
@ -558,9 +560,9 @@ var ModelMgr = {
|
||||||
},
|
},
|
||||||
sticky_data : func {
|
sticky_data : func {
|
||||||
var n = props.Node.new();
|
var n = props.Node.new();
|
||||||
if (me.active == nil) {
|
if (me.active == nil)
|
||||||
return n;
|
return n;
|
||||||
}
|
|
||||||
var hdg = n.getNode("heading-deg", 1);
|
var hdg = n.getNode("heading-deg", 1);
|
||||||
var pitch = n.getNode("pitch-deg", 1);
|
var pitch = n.getNode("pitch-deg", 1);
|
||||||
var roll = n.getNode("roll-deg", 1);
|
var roll = n.getNode("roll-deg", 1);
|
||||||
|
@ -579,17 +581,14 @@ var ModelMgr = {
|
||||||
return n;
|
return n;
|
||||||
},
|
},
|
||||||
reset_heading : func {
|
reset_heading : func {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
if (m.selected)
|
|
||||||
m.hdg.set(0);
|
m.hdg.set(0);
|
||||||
},
|
},
|
||||||
reset_orientation : func {
|
reset_orientation : func {
|
||||||
foreach (var m; me.models) {
|
foreach (var m; me.selected_models()) {
|
||||||
if (m.selected) {
|
|
||||||
m.pitch.set(0);
|
m.pitch.set(0);
|
||||||
m.roll.set(0);
|
m.roll.set(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
import : func {
|
import : func {
|
||||||
me.active = nil;
|
me.active = nil;
|
||||||
|
@ -619,33 +618,32 @@ var ModelMgr = {
|
||||||
var dist = scale ? ufo.distance_to(me.active.pos) * 0.05 : 1;
|
var dist = scale ? ufo.distance_to(me.active.pos) * 0.05 : 1;
|
||||||
if (name == "longitudinal") {
|
if (name == "longitudinal") {
|
||||||
var dir = ufo.course_to(me.active.pos);
|
var dir = ufo.course_to(me.active.pos);
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.apply_course_distance(dir, value * dist);
|
m.apply_course_distance(dir, value * dist);
|
||||||
|
|
||||||
} elsif (name == "transversal") {
|
} elsif (name == "transversal") {
|
||||||
var dir = ufo.course_to(me.active.pos) + 90;
|
var dir = ufo.course_to(me.active.pos) + 90;
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.apply_course_distance(dir, value * dist);
|
m.apply_course_distance(dir, value * dist);
|
||||||
|
|
||||||
} elsif (name == "altitude") {
|
} elsif (name == "altitude") {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.raise(value * dist * 0.4);
|
m.raise(value * dist * 0.4);
|
||||||
|
|
||||||
} elsif (name == "heading") {
|
} elsif (name == "heading") {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.hdg.set(m.hdg.get() + value * 4);
|
m.hdg.set(m.hdg.get() + value * 4);
|
||||||
|
|
||||||
} elsif (name == "pitch") {
|
} elsif (name == "pitch") {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.pitch.set(m.pitch.get() + value * 6);
|
m.pitch.set(m.pitch.get() + value * 6);
|
||||||
|
|
||||||
} elsif (name == "roll") {
|
} elsif (name == "roll") {
|
||||||
foreach (var m; me.models)
|
foreach (var m; me.selected_models())
|
||||||
m.selected and m.roll.set(m.roll.get() + value * 6);
|
m.roll.set(m.roll.get() + value * 6);
|
||||||
|
|
||||||
} elsif (name == "bearing") {
|
} elsif (name == "bearing") {
|
||||||
foreach (var m; me.models) {
|
foreach (var m; me.selected_models()) {
|
||||||
if (m.selected) {
|
|
||||||
var course = me.active.pos.course_to(m.pos);
|
var course = me.active.pos.course_to(m.pos);
|
||||||
var dist = me.active.pos.distance_to(m.pos);
|
var dist = me.active.pos.distance_to(m.pos);
|
||||||
m.apply_course_distance(course, -dist);
|
m.apply_course_distance(course, -dist);
|
||||||
|
@ -653,7 +651,6 @@ var ModelMgr = {
|
||||||
m.hdg.set(m.hdg.get() + value * 4);
|
m.hdg.set(m.hdg.get() + value * 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
me.marker.move(me.active.pos);
|
me.marker.move(me.active.pos);
|
||||||
},
|
},
|
||||||
toggle_marker : func {
|
toggle_marker : func {
|
||||||
|
@ -661,19 +658,16 @@ var ModelMgr = {
|
||||||
},
|
},
|
||||||
clone_selected : func {
|
clone_selected : func {
|
||||||
var clones = [];
|
var clones = [];
|
||||||
foreach (var m; me.models) {
|
foreach (var m; me.selected_models()) {
|
||||||
if (m.selected) {
|
|
||||||
m.selected = 0;
|
m.selected = 0;
|
||||||
var c = m.clone(m.path);
|
var c = m.clone(m.path);
|
||||||
|
#c.selected = 1;
|
||||||
append(clones, c);
|
append(clones, c);
|
||||||
if (m == me.active)
|
if (m == me.active)
|
||||||
me.active = c;
|
me.active = c;
|
||||||
}
|
}
|
||||||
}
|
foreach (var m; clones)
|
||||||
foreach (var m; clones) {
|
|
||||||
m.selected = 1;
|
|
||||||
append(me.models, m);
|
append(me.models, m);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -854,7 +848,7 @@ var KbdCtrl = props.globals.getNode("/devices/status/keyboard/ctrl");
|
||||||
var KbdAlt = props.globals.getNode("/devices/status/keyboard/alt");
|
var KbdAlt = props.globals.getNode("/devices/status/keyboard/alt");
|
||||||
|
|
||||||
var modellist = scan_dirs(getprop("/source"));
|
var modellist = scan_dirs(getprop("/source"));
|
||||||
var modelmgr = ModelMgr.new(getprop("/cursor"));
|
modelmgr.init(getprop("/cursor"));
|
||||||
|
|
||||||
setlistener("/sim/signals/click", func {
|
setlistener("/sim/signals/click", func {
|
||||||
if (!mouse.mmb)
|
if (!mouse.mmb)
|
||||||
|
|
Loading…
Add table
Reference in a new issue