Avoid showing filters that don't work on a given platform

(cough Windows cough)
This commit is contained in:
Ash 2017-04-12 21:44:42 +10:00
parent 725d23de72
commit 3917dbbb0c
2 changed files with 19 additions and 8 deletions

View File

@ -108,6 +108,7 @@ public class GuiOptionsWindow extends JPanel {
cFilterList = new ControllerFilteringList(); cFilterList = new ControllerFilteringList();
for (Settings.ControllerFiltering.Type type : Settings.ControllerFiltering.Type.values()) { for (Settings.ControllerFiltering.Type type : Settings.ControllerFiltering.Type.values()) {
if (!type.isSupportedOnPlatform()) continue;
ControllerFilteringListItem item = new ControllerFilteringListItem(type); ControllerFilteringListItem item = new ControllerFilteringListItem(type);
cFilterList.add(item); cFilterList.add(item);
} }

View File

@ -192,26 +192,36 @@ public final class Settings {
} else if (os.contains("Mac OS X")) { } else if (os.contains("Mac OS X")) {
return Platform.MAC_OS_X; return Platform.MAC_OS_X;
} }
return null; return Platform.UNKNOWN;
} }
public enum Platform { public enum Platform {
LINUX, WINDOWS, MAC_OS_X, UNKNOWN LINUX (0x1), WINDOWS (0x2), MAC_OS_X (0x4), UNKNOWN (0x8);
private int mask;
private Platform(int mask) {
this.mask = mask;
}
} }
//TODO rename this to something less nonsensical //TODO rename this to something less nonsensical
public static class ControllerFiltering { public static class ControllerFiltering {
public static enum Type { public static enum Type {
HIDGAMEPAD (0, "HID Gamepads"), HIDGAMEPAD (0, "HID Gamepads", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask),
HIDKEYBOARD (1, "HID Keyboards"), HIDKEYBOARD (1, "HID Keyboards", Platform.LINUX.mask | Platform.MAC_OS_X.mask),
HIDMOUSE (2, "HID Mice"), HIDMOUSE (2, "HID Mice", Platform.LINUX.mask | Platform.MAC_OS_X.mask),
HIDOTHER (3, "Other HIDs"); HIDOTHER (3, "Other HIDs", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask);
private int index; private int index;
@Getter private String name; @Getter private String name;
private Type(int index, String name) { private int platforms;
private Type(int index, String name, int platforms) {
this.index = index; this.index = index;
this.name = name; this.name = name;
this.platforms = platforms;
}
public boolean isSupportedOnPlatform() {
return (platforms & getPlattform().mask) != 0;
} }
} }
@ -234,7 +244,7 @@ public final class Settings {
filterStates[filter.index] = state; filterStates[filter.index] = state;
} }
public static boolean getFilterState(Type filter) { public static boolean getFilterState(Type filter) {
return filterStates[filter.index]; return filterStates[filter.index] || !filter.isSupportedOnPlatform();
} }
public static void setDefaultFilterStates() { public static void setDefaultFilterStates() {
filterStates[Type.HIDGAMEPAD.index] = true; filterStates[Type.HIDGAMEPAD.index] = true;