2929import eu .midnightdust .midnightcontrols .client .enums .ControllerType ;
3030import eu .midnightdust .midnightcontrols .client .enums .HudSide ;
3131import eu .midnightdust .midnightcontrols .client .enums .VirtualMouseSkin ;
32+ import eu .midnightdust .midnightcontrols .client .gui .MidnightControlsSettingsScreen ;
3233import eu .midnightdust .midnightcontrols .client .gui .RingScreen ;
3334import eu .midnightdust .midnightcontrols .client .enums .TouchMode ;
3435import eu .midnightdust .midnightcontrols .client .gui .config .ControllerBindingButton ;
3536import eu .midnightdust .midnightcontrols .client .gui .config .ControllerSelectionButton ;
37+ import eu .midnightdust .midnightcontrols .client .gui .config .MappingsStringInputWidget ;
3638import eu .midnightdust .midnightcontrols .client .virtualkeyboard .KeyboardLayoutManager ;
3739import net .minecraft .client .MinecraftClient ;
3840import net .minecraft .client .gui .screen .ChatScreen ;
4951import java .util .*;
5052import java .util .regex .Pattern ;
5153
54+ import static eu .midnightdust .midnightcontrols .client .MidnightControlsClient .client ;
5255import static org .lwjgl .glfw .GLFW .*;
5356
5457/**
@@ -62,6 +65,7 @@ public class MidnightControlsConfig extends MidnightConfig {
6265 public static final String VISUAL = "visual" ;
6366 public static final String MISC = "misc" ;
6467 public static final String BUTTONS = "buttons" ;
68+ public static final String MAPPING = "mapping" ;
6569 public static boolean isEditing = false ;
6670 @ Hidden @ Entry public static int configVersion = 2 ;
6771
@@ -186,7 +190,12 @@ public class MidnightControlsConfig extends MidnightConfig {
186190 @ Comment (category = MISC , centered = true , name ="☆ Other Options" ) public static Comment _otherOptions ;
187191 @ Entry (category = MISC , name = "Trigger button fix" ) public static boolean triggerFix = true ;
188192 @ Entry (category = MISC , name = "Excluded Controllers (Name Regex)" ) public static List <String > excludedControllers = Lists .newArrayList (".*(Keyboard)$" , ".*(Touchpad)$" , ".*(Pen)$" , ".*(Finger)$" );
193+
194+ // Init mapping tab (see #onTabInit())
195+ @ Comment (category = MAPPING ) @ Condition (requiredModId = "thisModDoesNotExist" ) public static Comment this_spacer_will_never_be_visible_as_well ;
196+
189197 @ Entry @ Hidden public static Map <String , Map <String , String >> controllerBindingProfiles = new HashMap <>();
198+
190199 private static Map <String , String > currentBindingProfile = new HashMap <>();
191200 private static Controller prevController ;
192201
@@ -236,6 +245,15 @@ public boolean centered() {
236245 list .addButton (List .of (), Text .of ("\uD83C \uDFAE General" ), centeredComment );
237246 ControllerSelectionButton .add (list , screen , false );
238247 ControllerSelectionButton .add (list , screen , true );
248+
249+ ButtonWidget editButton = ButtonWidget .builder (Text .of ("OPEN" ),
250+ button -> {
251+ client .setScreen (new MidnightControlsSettingsScreen (client .currentScreen , false ));
252+ }).dimensions (screen .width - 185 , 0 , 175 , 20 ).build ();
253+ list .addButton (List .of (editButton ), Text .of ("Legacy Config UI" ), new EntryInfo (null , screen .modid ));
254+ }
255+ if (MAPPING .equals (tabName )) {
256+ MappingsStringInputWidget .add (centeredComment , list , screen );
239257 }
240258 }
241259
@@ -507,17 +525,23 @@ public static void reset() {
507525 * @return the controller name matches a type, else empty
508526 */
509527 public static @ NotNull ControllerType matchControllerToType () {
510- String controller = getController ().getName ().toLowerCase ();
511- if (controller . contains ( "xbox 360" )) return ControllerType .XBOX_360 ;
512- else if (controller . contains ( "xbox" ) || controller .contains ("afterglow" )) return ControllerType .XBOX ;
513- else if (controller . contains ( "steam" ) && GLX ._getCpuInfo ().contains ("AMD Custom APU" )) return ControllerType .STEAM_DECK ;
514- else if (controller . contains ( "steam" )) return ControllerType .STEAM_CONTROLLER ;
515- else if (controller . contains ( "dualsense" ) || controller . contains ( "ps5" )) return ControllerType .DUALSENSE ;
516- else if (controller . contains ( "dualshock" ) || controller . contains ( "ps4" ) || controller . contains ( "sony" )) return ControllerType .DUALSHOCK ;
517- else if (controller . contains ( "switch" ) || controller . contains ( "joy-con" ) || controller . contains ( "wii" ) || controller . contains ( "nintendo" )) return ControllerType .SWITCH ;
518- else if (controller . contains ( "ouya" )) return ControllerType .OUYA ;
528+ String name = getController ().getName ().toLowerCase ();
529+ if (containsAny ( name , "xbox 360" )) return ControllerType .XBOX_360 ;
530+ else if (containsAny ( name , "xbox" ) || name .contains ("afterglow" )) return ControllerType .XBOX ;
531+ else if (containsAny ( name , "steam" ) && GLX ._getCpuInfo ().contains ("AMD Custom APU" )) return ControllerType .STEAM_DECK ;
532+ else if (containsAny ( name , "steam" )) return ControllerType .STEAM_CONTROLLER ;
533+ else if (containsAny ( name , "dualsense" , "ps5" )) return ControllerType .DUALSENSE ;
534+ else if (containsAny ( name , "dualshock" , "ps4" , "sony" )) return ControllerType .DUALSHOCK ;
535+ else if (containsAny ( name , "switch" , "joy-con" , "wii" , "nintendo" )) return ControllerType .SWITCH ;
536+ else if (containsAny ( name , "ouya" )) return ControllerType .OUYA ;
519537 else return ControllerType .DEFAULT ;
520538 }
539+
540+ private static boolean containsAny (String controller , String ... substring ) {
541+ for (String s : substring ) if (controller .contains (s )) return true ;
542+ return false ;
543+ }
544+
521545 public static boolean doMixedInput () {
522546 return touchInControllerMode && controlsMode == ControlsMode .CONTROLLER ;
523547 }
0 commit comments