more gamepad changes

- now have a menu bar to access settings
- now handle user input to assign mappings
- fixed some typos
- now properly shutdown controller threads on exit
- renamed GamepadSettings to GamepadMapping
- created a lock to ensure we do not add/remove gamepads from the list while we are handling their events
- fixed settings directory booch
This commit is contained in:
Diego Waxemberg
2013-12-20 13:00:30 -05:00
parent 43df4cf93e
commit ba0b84f9e5
10 changed files with 184 additions and 80 deletions

View File

@@ -8,20 +8,21 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.limelight.input.GamepadSettings;
import com.limelight.input.GamepadMapping;
public class GamepadSettingsManager {
private static GamepadSettings cachedSettings;
private static GamepadMapping cachedSettings;
public static GamepadSettings getSettings() {
public static GamepadMapping getSettings() {
if (cachedSettings == null) {
System.out.println("Reading Gamepad Settings");
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(gamepadFile));
GamepadSettings savedSettings = (GamepadSettings)ois.readObject();
GamepadMapping savedSettings = (GamepadMapping)ois.readObject();
cachedSettings = savedSettings;
} catch (ClassNotFoundException e) {
@@ -47,13 +48,20 @@ public class GamepadSettingsManager {
}
}
}
if (cachedSettings == null) {
System.out.println("Unable to get gamepad settings. Using an empty mapping instead.");
cachedSettings = new GamepadMapping();
writeSettings(cachedSettings);
}
return cachedSettings;
}
public static void writeSettings(GamepadSettings settings) {
public static void writeSettings(GamepadMapping settings) {
cachedSettings = settings;
System.out.println("Writing Gamepad Settings");
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
ObjectOutputStream ous = null;
try {