Gives the calibrator the option of rendering unused buttons useless.
This prevents them from accidentally interfering with buttons we want.
This commit is contained in:
@@ -19,7 +19,6 @@ import com.jme3.input.event.KeyInputEvent;
|
|||||||
import com.jme3.input.event.MouseButtonEvent;
|
import com.jme3.input.event.MouseButtonEvent;
|
||||||
import com.jme3.input.event.MouseMotionEvent;
|
import com.jme3.input.event.MouseMotionEvent;
|
||||||
import com.jme3.input.event.TouchEvent;
|
import com.jme3.input.event.TouchEvent;
|
||||||
import com.jme3.math.ColorRGBA;
|
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
|
|
||||||
@@ -27,6 +26,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -118,6 +118,8 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
private Node skipButton;
|
private Node skipButton;
|
||||||
private Node cancelButton;
|
private Node cancelButton;
|
||||||
private Node restartButton;
|
private Node restartButton;
|
||||||
|
private Node yesButton;
|
||||||
|
private Node noButton;
|
||||||
private JoystickPreviewScreen.GamepadView gamepad;
|
private JoystickPreviewScreen.GamepadView gamepad;
|
||||||
|
|
||||||
private BitmapText currentJoystick;
|
private BitmapText currentJoystick;
|
||||||
@@ -145,6 +147,8 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
|
|
||||||
private HashMap<Object, Float> defaultValues = new HashMap<>();
|
private HashMap<Object, Float> defaultValues = new HashMap<>();
|
||||||
|
|
||||||
|
private boolean clear;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a screen for calibrating and remapping a game controller.
|
* Creates a screen for calibrating and remapping a game controller.
|
||||||
* @param calibrationFile - The file to store the results in.
|
* @param calibrationFile - The file to store the results in.
|
||||||
@@ -181,8 +185,9 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
this.introCont.attachChild(text);
|
this.introCont.attachChild(text);
|
||||||
|
|
||||||
this.startButton =
|
this.startButton =
|
||||||
GUIUtils.createButton(app.getAssetManager(), this.guiFont, app.getContext().getTouchInput() != null,
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
"start", "Start");
|
app.getContext().getTouchInput() != null, "start",
|
||||||
|
"Start");
|
||||||
// this.startButton.addClickCommands(this);
|
// this.startButton.addClickCommands(this);
|
||||||
this.introCont.attachChild(this.startButton);
|
this.introCont.attachChild(this.startButton);
|
||||||
|
|
||||||
@@ -193,17 +198,28 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
"on the controller you want to calibrate."));
|
"on the controller you want to calibrate."));
|
||||||
|
|
||||||
this.skipButton =
|
this.skipButton =
|
||||||
GUIUtils.createButton(app.getAssetManager(), this.guiFont, app.getContext().getTouchInput() != null,
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
"skip", "Skip");
|
app.getContext().getTouchInput() != null, "skip",
|
||||||
|
"Skip");
|
||||||
|
|
||||||
this.cancelButton =
|
this.cancelButton =
|
||||||
GUIUtils.createButton(app.getAssetManager(), this.guiFont, app.getContext().getTouchInput() != null,
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
"cancel", "Cancel");
|
app.getContext().getTouchInput() != null, "cancel",
|
||||||
|
"Cancel");
|
||||||
this.introCont.attachChild(this.cancelButton);
|
this.introCont.attachChild(this.cancelButton);
|
||||||
|
|
||||||
this.restartButton =
|
this.restartButton =
|
||||||
GUIUtils.createButton(app.getAssetManager(), this.guiFont, app.getContext().getTouchInput() != null,
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
"close", "Close Application");
|
app.getContext().getTouchInput() != null, "close",
|
||||||
|
"Close Application");
|
||||||
|
this.yesButton =
|
||||||
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
|
app.getContext().getTouchInput() != null, "yes",
|
||||||
|
"Yes");
|
||||||
|
this.noButton =
|
||||||
|
GUIUtils.createButton(app.getAssetManager(), this.guiFont,
|
||||||
|
app.getContext().getTouchInput() != null, "no",
|
||||||
|
"No");
|
||||||
|
|
||||||
this.gui.attachChild(this.introCont);
|
this.gui.attachChild(this.introCont);
|
||||||
|
|
||||||
@@ -420,6 +436,12 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
case "close":
|
case "close":
|
||||||
this.getApplication().stop();
|
this.getApplication().stop();
|
||||||
break;
|
break;
|
||||||
|
case "yes":
|
||||||
|
this.clearUnused();
|
||||||
|
break;
|
||||||
|
case "no":
|
||||||
|
this.recordFile();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -626,10 +648,34 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.recordFile();
|
this.promptClearUnused();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void promptClearUnused()
|
||||||
|
{
|
||||||
|
this.currentStage = null;
|
||||||
|
this.mainOptions.removeFromParent();
|
||||||
|
this.gamepad.removeFromParent();
|
||||||
|
|
||||||
|
this.introCont.detachAllChildren();
|
||||||
|
this.introCont.attachChild(this.guiFont.createLabel(
|
||||||
|
"Do you wish to set all buttons and axes not used to not " +
|
||||||
|
"trigger?\nThis has the benefit of ensuring unused " +
|
||||||
|
"buttons don't interfere with\n" +
|
||||||
|
"anything else."));
|
||||||
|
this.introCont.attachChild(this.yesButton);
|
||||||
|
this.introCont.attachChild(this.noButton);
|
||||||
|
this.gui.attachChild(this.introCont);
|
||||||
|
this.resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearUnused()
|
||||||
|
{
|
||||||
|
this.clear = true;
|
||||||
|
this.recordFile();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the calibration settings to the file and prompts for an
|
* Saves the calibration settings to the file and prompts for an
|
||||||
* application restart.
|
* application restart.
|
||||||
@@ -639,14 +685,12 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
/*
|
/*
|
||||||
* Enable this in JME 3.4.
|
* Enable this in JME 3.4.
|
||||||
*/
|
*/
|
||||||
boolean perComponentEnabled = false;
|
boolean perComponentEnabled = true;
|
||||||
JoystickAxis axis;
|
JoystickAxis axis;
|
||||||
JoystickButton button;
|
JoystickButton button;
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
|
||||||
this.currentStage = null;
|
this.introCont.removeFromParent();
|
||||||
this.mainOptions.removeFromParent();
|
|
||||||
this.gamepad.removeFromParent();
|
|
||||||
|
|
||||||
if (!calibrationFile.exists())
|
if (!calibrationFile.exists())
|
||||||
{
|
{
|
||||||
@@ -681,13 +725,16 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
ArrayList<Object> elements = new ArrayList<>();
|
||||||
|
elements.addAll(this.joystick.getAxes());
|
||||||
|
elements.addAll(this.joystick.getButtons());
|
||||||
for (Map.Entry<String, Object> calibrationEntry : this.maps
|
for (Map.Entry<String, Object> calibrationEntry : this.maps
|
||||||
.entrySet())
|
.entrySet())
|
||||||
{
|
{
|
||||||
if (calibrationEntry.getValue() instanceof JoystickButton)
|
if (calibrationEntry.getValue() instanceof JoystickButton)
|
||||||
{
|
{
|
||||||
button = (JoystickButton) calibrationEntry.getValue();
|
button = (JoystickButton) calibrationEntry.getValue();
|
||||||
if (!button.getName().equals(calibrationEntry.getKey()))
|
if (!button.getName().equals(calibrationEntry.getKey()) || clear)
|
||||||
{
|
{
|
||||||
props.put((perComponentEnabled ? "button." : "") +
|
props.put((perComponentEnabled ? "button." : "") +
|
||||||
this.joystick.getName() + "." +
|
this.joystick.getName() + "." +
|
||||||
@@ -697,13 +744,34 @@ public class CalibrateInputScreen extends BaseAppState
|
|||||||
else if (calibrationEntry.getValue() instanceof JoystickAxis)
|
else if (calibrationEntry.getValue() instanceof JoystickAxis)
|
||||||
{
|
{
|
||||||
axis = (JoystickAxis) calibrationEntry.getValue();
|
axis = (JoystickAxis) calibrationEntry.getValue();
|
||||||
if (!axis.getName().equals(calibrationEntry.getKey()))
|
if (!axis.getName().equals(calibrationEntry.getKey()) || clear)
|
||||||
{
|
{
|
||||||
props.put((perComponentEnabled ? "axis." : "") +
|
props.put((perComponentEnabled ? "axis." : "") +
|
||||||
this.joystick.getName() + "." + axis.getName(),
|
this.joystick.getName() + "." + axis.getName(),
|
||||||
calibrationEntry.getKey());
|
calibrationEntry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elements.remove(calibrationEntry.getValue());
|
||||||
|
}
|
||||||
|
if (this.clear)
|
||||||
|
{
|
||||||
|
for (Object element : elements)
|
||||||
|
{
|
||||||
|
if (element instanceof JoystickButton)
|
||||||
|
{
|
||||||
|
button = (JoystickButton) element;
|
||||||
|
props.put((perComponentEnabled ? "button." : "") +
|
||||||
|
this.joystick.getName() + "." +
|
||||||
|
button.getName(), "null");
|
||||||
|
}
|
||||||
|
else if (element instanceof JoystickAxis)
|
||||||
|
{
|
||||||
|
axis = (JoystickAxis) element;
|
||||||
|
props.put((perComponentEnabled ? "axis." : "") +
|
||||||
|
this.joystick.getName() + "." + axis.getName(),
|
||||||
|
"null");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try (FileOutputStream output = new FileOutputStream(
|
try (FileOutputStream output = new FileOutputStream(
|
||||||
calibrationFile))
|
calibrationFile))
|
||||||
|
|||||||
Reference in New Issue
Block a user