1
0
Fork 0

Added Joystick Sensitivity Reduction to dialog.

This allows the setting of the <power> tag - which in turn will decreases the sensitivity around the zero position
This commit is contained in:
Richard Harrison 2020-04-09 23:37:17 +02:00
parent 7605fee09f
commit 5f1784937e
2 changed files with 65 additions and 8 deletions

View file

@ -15,6 +15,7 @@ var Axis = {
m.prop = prop; m.prop = prop;
m.invertable = invertable; m.invertable = invertable;
m.inverted = 0; m.inverted = 0;
m.power = 1.0;
return m; return m;
}, },
@ -24,6 +25,7 @@ var Axis = {
m.prop = me.prop; m.prop = me.prop;
m.invertable = me.invertable; m.invertable = me.invertable;
m.inverted = me.inverted; m.inverted = me.inverted;
m.power = me.power;
return m; return m;
}, },
@ -37,12 +39,13 @@ var Axis = {
getName: func() { return me.name; }, getName: func() { return me.name; },
getBinding: func(axis) { return props.Node.new(); }, getBinding: func(axis) { return props.Node.new(); },
isInvertable: func() { return me.invertable; }, isInvertable: func() { return me.invertable; },
isInverted: func() { return me.inverted; }, isInverted: func() { return me.inverted; },
getPower: func() { return me.power; },
setInverted: func(b) { setPower: func(v) { me.power = v; },
if (me.invertable) me.inverted = b; setInverted: func(b) { if (me.invertable) me.inverted = b; },
},
}; };
var CustomAxis = { var CustomAxis = {
@ -100,11 +103,13 @@ var UnboundAxis = {
var PropertyScaleAxis = { var PropertyScaleAxis = {
new: func(name, prop, factor=1, offset=0) { new: func(name, prop, factor=1, offset=0, power=1) {
var m = { parents: [PropertyScaleAxis, Axis.new(name, prop, 1) ] }; var m = { parents: [PropertyScaleAxis, Axis.new(name, prop, 1) ] };
m.prop=prop; m.prop=prop;
m.factor = factor; m.factor = factor;
m.offset = offset; m.offset = offset;
m.power = power;
return m; return m;
}, },
@ -116,6 +121,7 @@ var PropertyScaleAxis = {
m.prop= me.prop; m.prop= me.prop;
m.factor = me.factor; m.factor = me.factor;
m.offset = me.offset; m.offset = me.offset;
m.power = me.power;
return m; return m;
}, },
@ -134,9 +140,11 @@ var PropertyScaleAxis = {
# (value 0 wouldn't be appropriate for a default factor) # (value 0 wouldn't be appropriate for a default factor)
factorNode = bindingNode.getNode("factor", 0); factorNode = bindingNode.getNode("factor", 0);
me.factor = (factorNode != nil) ? factorNode.getValue() : 1.0; me.factor = (factorNode != nil) ? factorNode.getValue() : 1.0;
me.inverted = (me.factor < 0); me.inverted = (me.factor < 0);
me.offset = bindingNode.getNode("offset", 1).getValue(); me.offset = bindingNode.getNode("offset", 1).getValue();
powerNode = bindingNode.getNode("power", 0);
me.power = (powerNode != nil) ? powerNode.getValue() : 1.0;
}, },
getBinding: func(axis) { getBinding: func(axis) {
@ -151,6 +159,7 @@ var PropertyScaleAxis = {
p.getNode("binding", 1).getNode("factor", 1).setValue(me.factor); p.getNode("binding", 1).getNode("factor", 1).setValue(me.factor);
} }
p.getNode("binding", 1).getNode("offset", 1).setValue(me.offset); p.getNode("binding", 1).getNode("offset", 1).setValue(me.offset);
p.getNode("binding", 1).getNode("power",1 ).setValue(me.power);
return p; return p;
}, },
@ -642,6 +651,7 @@ var readConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") {
p.getNode("binding", 1).setValue(binding.getName()); p.getNode("binding", 1).setValue(binding.getName());
p.getNode("invertable", 1).setValue(binding.isInvertable()); p.getNode("invertable", 1).setValue(binding.isInvertable());
p.getNode("inverted", 1).setValue(binding.isInverted()); p.getNode("inverted", 1).setValue(binding.isInverted());
p.getNode("power", 1).setValue(binding.getPower());
} }
} }
@ -650,12 +660,14 @@ var readConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") {
p.getNode("binding", 1).setValue("None"); p.getNode("binding", 1).setValue("None");
p.getNode("invertable", 1).setValue(0); p.getNode("invertable", 1).setValue(0);
p.getNode("inverted", 1).setValue(0); p.getNode("inverted", 1).setValue(0);
p.getNode("power", 1).setValue(1.0);
p.removeChild("original_binding"); p.removeChild("original_binding");
} }
} else { } else {
p.getNode("binding", 1).setValue("None"); p.getNode("binding", 1).setValue("None");
p.getNode("invertable", 1).setValue(0); p.getNode("invertable", 1).setValue(0);
p.getNode("inverted", 1).setValue(0); p.getNode("inverted", 1).setValue(0);
p.getNode("power", 1).setValue(1.0);
p.removeChild("original_binding"); p.removeChild("original_binding");
} }
} }
@ -743,6 +755,7 @@ var writeConfig = func(dialog_root="/sim/gui/dialogs/joystick-config", reset=0)
if (binding.getName() == name) { if (binding.getName() == name) {
var b = binding.clone(); var b = binding.clone();
b.setInverted(getprop(dialog_root ~ "/axis[" ~ axis ~ "]/inverted")); b.setInverted(getprop(dialog_root ~ "/axis[" ~ axis ~ "]/inverted"));
b.setPower(getprop(dialog_root ~ "/axis[" ~ axis ~ "]/power"));
# Generate the axis and binding # Generate the axis and binding
var axisnode = config.getNode("axis[" ~ axis ~ "]", 1); var axisnode = config.getNode("axis[" ~ axis ~ "]", 1);

View file

@ -4,11 +4,16 @@
<nasal> <nasal>
<open><![CDATA[ <open><![CDATA[
var curpower = getprop("/sim/gui/dialogs/joystick-config/axis[" ~ getprop("/sim/gui/dialogs/joystick-config/current-axis") ~ "]/power");
if (curpower == nil)
curpower = 1.0;
setprop("/sim/gui/dialogs/joystick-config/gui-factor",curpower);
var assignAxis = func(cmd) { var assignAxis = func(cmd) {
var i = getprop("/sim/gui/dialogs/joystick-config/current-axis"); var i = getprop("/sim/gui/dialogs/joystick-config/current-axis");
setprop("/sim/gui/dialogs/joystick-config/axis[" ~ i ~ "]/binding", cmd); if (cmd != nil)
setprop("/sim/gui/dialogs/joystick-config/axis[" ~ i ~ "]/binding", cmd);
setprop("/sim/gui/dialogs/joystick-config/axis[" ~ i ~ "]/power", getprop("/sim/gui/dialogs/joystick-config/gui-factor"));
joystick.writeConfig(); joystick.writeConfig();
fgcommand("reinit", props.Node.new({"subsystem": "input"})); fgcommand("reinit", props.Node.new({"subsystem": "input"}));
fgcommand("dialog-close", props.Node.new({"dialog-name": "button-axis-config"})); fgcommand("dialog-close", props.Node.new({"dialog-name": "button-axis-config"}));
@ -437,9 +442,48 @@ var assignAxis = func(cmd) {
</button> </button>
<slider>
<row>11</row>
<col>0</col>
<colspan>1</colspan>
<name>sensitivity</name>
<min>0</min>
<max>5</max>
<step>0.1</step>
<live>true</live>
<property>/sim/gui/dialogs/joystick-config/gui-factor</property>
<binding>
<command>dialog-apply</command>
<object-name>sensitivity</object-name>
</binding>
</slider>
<text>
<row>11</row>
<col>1</col>
<halign>left</halign>
<format>Sensitivity Reduction %2.1f</format>
<label>0</label>
<property>/sim/gui/dialogs/joystick-config/gui-factor</property>
<live>true</live>
</text>
<button>
<row>11</row>
<col>2</col>
<halign>fill</halign>
<legend>Apply sensitivity</legend>
<binding>
<command>nasal</command>
<script>
assignAxis(nil);
</script>
</binding>
</button>
</group> </group>
<group> <group>
<empty> <empty>
<stretch>true</stretch> <stretch>true</stretch>