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>
This commit is contained in:
parent
a1fec557a3
commit
e589a8585e
BIN
bin/controls.config
Normal file
BIN
bin/controls.config
Normal file
Binary file not shown.
@ -126,6 +126,7 @@ public class RabiClone {
|
|||||||
long dt = 0;
|
long dt = 0;
|
||||||
|
|
||||||
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
|
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
|
||||||
|
ConfigureControls.LoadControls();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
dt += System.nanoTime() - lastGameTime;
|
dt += System.nanoTime() - lastGameTime;
|
||||||
@ -254,6 +255,18 @@ public class RabiClone {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!CONTROLLERS[i].poll()) {
|
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];
|
Controller[] newArr = new Controller[CONTROLLERS.length - 1];
|
||||||
for (int j = 0; j < CONTROLLERS.length; j++) {
|
for (int j = 0; j < CONTROLLERS.length; j++) {
|
||||||
if (j != i) {
|
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);
|
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 {
|
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) {
|
while (stream.available()>0) {
|
||||||
Action a = Action.valueOf(readString(stream));
|
Action a = Action.valueOf(readString(stream));
|
||||||
byte port = stream.readByte();
|
byte port = stream.readByte();
|
||||||
|
System.out.println("PI:"+port);
|
||||||
do {
|
do {
|
||||||
if (port==(byte)-1) {
|
if (port==(byte)-1) {
|
||||||
int keycode = stream.readInt();
|
int keycode = stream.readInt();
|
||||||
@ -63,6 +64,7 @@ public class ConfigureControls extends Object{
|
|||||||
appendToKeybind(a,kb);
|
appendToKeybind(a,kb);
|
||||||
} else {
|
} else {
|
||||||
java.lang.String controllerName = readString(stream);
|
java.lang.String controllerName = readString(stream);
|
||||||
|
System.out.println("CONT:"+controllerName);
|
||||||
Controller controller=null;
|
Controller controller=null;
|
||||||
for (int i = 0; i < RabiClone.CONTROLLERS.length; i++) {
|
for (int i = 0; i < RabiClone.CONTROLLERS.length; i++) {
|
||||||
if (RabiClone.CONTROLLERS[i].getType() == Controller.Type.KEYBOARD
|
if (RabiClone.CONTROLLERS[i].getType() == Controller.Type.KEYBOARD
|
||||||
@ -75,11 +77,12 @@ public class ConfigureControls extends Object{
|
|||||||
}
|
}
|
||||||
if (controller==null) {
|
if (controller==null) {
|
||||||
//Discard these bits of data as we didn't find a controller.
|
//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();
|
stream.readFloat();
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
java.lang.String componentName = readString(stream);
|
java.lang.String componentName = readString(stream);
|
||||||
|
System.out.println("COM:"+componentName);
|
||||||
Component c=null;
|
Component c=null;
|
||||||
for (Component cc : controller.getComponents()) {
|
for (Component cc : controller.getComponents()) {
|
||||||
if (cc.getName().equals(componentName)) {
|
if (cc.getName().equals(componentName)) {
|
||||||
@ -97,7 +100,8 @@ public class ConfigureControls extends Object{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
port = stream.readByte();
|
port = stream.readByte();
|
||||||
} while (port!='\0');
|
System.out.println("P:"+port);
|
||||||
|
} while (port!=(byte)-2);
|
||||||
}
|
}
|
||||||
updateHighlightSections();
|
updateHighlightSections();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -130,6 +134,7 @@ public class ConfigureControls extends Object{
|
|||||||
for (Action a : Action.values()) {
|
for (Action a : Action.values()) {
|
||||||
writeString(a.name(),stream);
|
writeString(a.name(),stream);
|
||||||
for (KeyBind k : KeyBind.KEYBINDS.get(a)) {
|
for (KeyBind k : KeyBind.KEYBINDS.get(a)) {
|
||||||
|
if (k.port==-1||k.port<RabiClone.CONTROLLERS.length) {
|
||||||
stream.writeByte(k.port);
|
stream.writeByte(k.port);
|
||||||
if (k.port==(byte)-1) {
|
if (k.port==(byte)-1) {
|
||||||
stream.writeInt(((Key)k.id).getKeyCode());
|
stream.writeInt(((Key)k.id).getKeyCode());
|
||||||
@ -139,7 +144,8 @@ public class ConfigureControls extends Object{
|
|||||||
stream.writeFloat(k.getVal());
|
stream.writeFloat(k.getVal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream.writeByte('\0');
|
}
|
||||||
|
stream.writeByte((byte)-2);
|
||||||
}
|
}
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -152,7 +158,7 @@ public class ConfigureControls extends Object{
|
|||||||
stream.writeChar('\0');
|
stream.writeChar('\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateHighlightSections() {
|
public static void updateHighlightSections() {
|
||||||
for (int i=0;i<Action.values().length;i++) {
|
for (int i=0;i<Action.values().length;i++) {
|
||||||
Action a = Action.values()[i];
|
Action a = Action.values()[i];
|
||||||
actionHighlightSections.add(new ArrayList<Integer>());
|
actionHighlightSections.add(new ArrayList<Integer>());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user