Allow controls to be loaded and saved. Controller configurations are also remembered.

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent a1fec557a3
commit e589a8585e
  1. BIN
      bin/controls.config
  2. 13
      src/sig/RabiClone.java
  3. 3
      src/sig/engine/KeyBind.java
  4. 30
      src/sig/objects/ConfigureControls.java

Binary file not shown.

@ -126,6 +126,7 @@ public class RabiClone {
long dt = 0;
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
ConfigureControls.LoadControls();
while (true) {
dt += System.nanoTime() - lastGameTime;
@ -254,6 +255,18 @@ public class RabiClone {
continue;
}
if (!CONTROLLERS[i].poll()) {
if (control_settings_menu!=null) {
for (Action a : Action.values()) {
List<KeyBind> binds = KeyBind.KEYBINDS.get(a);
for (int j=0;j<binds.size();j++) {
if (binds.get(j).port==i) {
binds.remove(j--);
}
}
KeyBind.KEYBINDS.put(a,binds);
ConfigureControls.updateHighlightSections();
}
}
Controller[] newArr = new Controller[CONTROLLERS.length - 1];
for (int j = 0; j < CONTROLLERS.length; j++) {
if (j != i) {

@ -65,7 +65,8 @@ public class KeyBind {
return Math.abs(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())>=RabiClone.CONTROLLERS[port].getComponent(id).getDeadZone()&&Math.signum(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())==Math.signum(val);
}
else {
throw new UnsupportedOperationException("Could not find proper recognition for component "+id.getName());
return false;
//throw new UnsupportedOperationException("Could not find proper recognition for component "+id.getName());
}
}

@ -56,6 +56,7 @@ public class ConfigureControls extends Object{
while (stream.available()>0) {
Action a = Action.valueOf(readString(stream));
byte port = stream.readByte();
System.out.println("PI:"+port);
do {
if (port==(byte)-1) {
int keycode = stream.readInt();
@ -63,6 +64,7 @@ public class ConfigureControls extends Object{
appendToKeybind(a,kb);
} else {
java.lang.String controllerName = readString(stream);
System.out.println("CONT:"+controllerName);
Controller controller=null;
for (int i = 0; i < RabiClone.CONTROLLERS.length; i++) {
if (RabiClone.CONTROLLERS[i].getType() == Controller.Type.KEYBOARD
@ -75,11 +77,12 @@ public class ConfigureControls extends Object{
}
if (controller==null) {
//Discard these bits of data as we didn't find a controller.
readString(stream);
java.lang.String comName = readString(stream);
System.out.println("NULL:"+comName);
stream.readFloat();
continue;
} else {
java.lang.String componentName = readString(stream);
System.out.println("COM:"+componentName);
Component c=null;
for (Component cc : controller.getComponents()) {
if (cc.getName().equals(componentName)) {
@ -97,7 +100,8 @@ public class ConfigureControls extends Object{
}
}
port = stream.readByte();
} while (port!='\0');
System.out.println("P:"+port);
} while (port!=(byte)-2);
}
updateHighlightSections();
} catch (IOException e) {
@ -130,16 +134,18 @@ public class ConfigureControls extends Object{
for (Action a : Action.values()) {
writeString(a.name(),stream);
for (KeyBind k : KeyBind.KEYBINDS.get(a)) {
stream.writeByte(k.port);
if (k.port==(byte)-1) {
stream.writeInt(((Key)k.id).getKeyCode());
} else {
writeString(RabiClone.CONTROLLERS[k.port].getName(),stream);
writeString(RabiClone.CONTROLLERS[k.port].getComponent(k.id).getName(),stream);
stream.writeFloat(k.getVal());
if (k.port==-1||k.port<RabiClone.CONTROLLERS.length) {
stream.writeByte(k.port);
if (k.port==(byte)-1) {
stream.writeInt(((Key)k.id).getKeyCode());
} else {
writeString(RabiClone.CONTROLLERS[k.port].getName(),stream);
writeString(RabiClone.CONTROLLERS[k.port].getComponent(k.id).getName(),stream);
stream.writeFloat(k.getVal());
}
}
}
stream.writeByte('\0');
stream.writeByte((byte)-2);
}
stream.close();
} catch (IOException e) {
@ -152,7 +158,7 @@ public class ConfigureControls extends Object{
stream.writeChar('\0');
}
private static void updateHighlightSections() {
public static void updateHighlightSections() {
for (int i=0;i<Action.values().length;i++) {
Action a = Action.values()[i];
actionHighlightSections.add(new ArrayList<Integer>());

Loading…
Cancel
Save