From 3917dbbb0c9b676ad373ae2be5829709b1c20e11 Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 12 Apr 2017 21:44:42 +1000 Subject: [PATCH] Avoid showing filters that don't work on a given platform (cough Windows cough) --- .../gui/GuiOptionsWindow.java | 1 + .../HIDToVPADNetworkClient/util/Settings.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/net/ash/HIDToVPADNetworkClient/gui/GuiOptionsWindow.java b/src/net/ash/HIDToVPADNetworkClient/gui/GuiOptionsWindow.java index cddbff5..a3efaf6 100644 --- a/src/net/ash/HIDToVPADNetworkClient/gui/GuiOptionsWindow.java +++ b/src/net/ash/HIDToVPADNetworkClient/gui/GuiOptionsWindow.java @@ -108,6 +108,7 @@ public class GuiOptionsWindow extends JPanel { cFilterList = new ControllerFilteringList(); for (Settings.ControllerFiltering.Type type : Settings.ControllerFiltering.Type.values()) { + if (!type.isSupportedOnPlatform()) continue; ControllerFilteringListItem item = new ControllerFilteringListItem(type); cFilterList.add(item); } diff --git a/src/net/ash/HIDToVPADNetworkClient/util/Settings.java b/src/net/ash/HIDToVPADNetworkClient/util/Settings.java index 2e09137..fe74dfd 100644 --- a/src/net/ash/HIDToVPADNetworkClient/util/Settings.java +++ b/src/net/ash/HIDToVPADNetworkClient/util/Settings.java @@ -192,26 +192,36 @@ public final class Settings { } else if (os.contains("Mac OS X")) { return Platform.MAC_OS_X; } - return null; + return Platform.UNKNOWN; } 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 public static class ControllerFiltering { public static enum Type { - HIDGAMEPAD (0, "HID Gamepads"), - HIDKEYBOARD (1, "HID Keyboards"), - HIDMOUSE (2, "HID Mice"), - HIDOTHER (3, "Other HIDs"); + HIDGAMEPAD (0, "HID Gamepads", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask), + HIDKEYBOARD (1, "HID Keyboards", Platform.LINUX.mask | Platform.MAC_OS_X.mask), + HIDMOUSE (2, "HID Mice", Platform.LINUX.mask | Platform.MAC_OS_X.mask), + HIDOTHER (3, "Other HIDs", Platform.LINUX.mask | Platform.WINDOWS.mask | Platform.MAC_OS_X.mask); private int index; @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.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; } public static boolean getFilterState(Type filter) { - return filterStates[filter.index]; + return filterStates[filter.index] || !filter.isSupportedOnPlatform(); } public static void setDefaultFilterStates() { filterStates[Type.HIDGAMEPAD.index] = true;