fixed ability to cancel key bindings, added option to reset to defaults, cleaned up keyboard layout
This commit is contained in:
parent
bc40435e41
commit
e5252168bf
|
@ -14,6 +14,7 @@
|
|||
@property (nonatomic, strong) IBOutlet UIView *keyboardContainerView;
|
||||
@property (nonatomic, strong) IBOutlet UIButton *saveButton;
|
||||
@property (nonatomic, strong) IBOutlet UIButton *cancelButton;
|
||||
@property (nonatomic, strong) IBOutlet UIButton *defaultsButton;
|
||||
@property (nonatomic, strong) KeyMapper *keyMapper;
|
||||
|
||||
@property(nonatomic, copy) void (^onDismissal)();
|
||||
|
|
|
@ -31,15 +31,14 @@ struct KeyCap {
|
|||
|
||||
struct KeyCap keyCapDefinitions[] = {
|
||||
{ 1.2,"caps",KEY_CAPS,0 },
|
||||
{ 1.0,"🍎",KEY_OPTION,0 },
|
||||
{ 1.0,"",KEY_APPLE,0 },
|
||||
{ 1.5,"opt",KEY_APPLE,0 },
|
||||
{ 1.0,"",KEY_OPTION,0 },
|
||||
{ 1.0,"`",KEY_TILDE,0 },
|
||||
{ 5.8," ",KEY_SPACE,0 },
|
||||
{ 1.0,"x",KEY_DOWN_CURSOR,0 },
|
||||
{ 1.0,"->",KEY_RIGHT_CURSOR,0 },
|
||||
{ 1.0,"<-",KEY_LEFT_CURSOR,0 },
|
||||
{ 1.0,"^",KEY_UP_CURSOR,0 },
|
||||
{ 1.0,"v",KEY_DOWN_CURSOR,0 },
|
||||
{ 6.3," ",KEY_SPACE,0 },
|
||||
{ 1.0,"←",KEY_LEFT_CURSOR,0 },
|
||||
{ 1.0,"→",KEY_RIGHT_CURSOR,0 },
|
||||
{ 1.0,"↑",KEY_UP_CURSOR,0 },
|
||||
{ 1.0,"↓",KEY_DOWN_CURSOR,0 },
|
||||
{ -1,0,0,0 },
|
||||
{ 2.5,"shift",KEY_SHIFT,0 },
|
||||
{ 1.0,"Z",KEY_Z,0 },
|
||||
|
@ -102,6 +101,7 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
@interface GameControllerKeyRemapController () <UIAlertViewDelegate>
|
||||
@property (nonatomic, strong) NSMutableArray *keyCapViews;
|
||||
@property (nonatomic, strong) UIAlertView *alertView;
|
||||
@property (nonatomic, strong) KeyMapper *keyMapperWorkingCopy;
|
||||
@end
|
||||
|
||||
@implementation GameControllerKeyRemapController
|
||||
|
@ -109,10 +109,13 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.keyCapViews = [NSMutableArray array];
|
||||
self.keyMapperWorkingCopy = [self.keyMapper copy];
|
||||
self.saveButton.layer.borderWidth = 1.0f;
|
||||
self.saveButton.layer.borderColor = [self.view.tintColor CGColor];
|
||||
self.cancelButton.layer.borderWidth = 1.0f;
|
||||
self.cancelButton.layer.borderColor = [self.view.tintColor CGColor];
|
||||
self.cancelButton.layer.borderColor = [[UIColor redColor] CGColor];
|
||||
self.defaultsButton.layer.borderWidth = 1.0f;
|
||||
self.defaultsButton.layer.borderColor = [self.view.tintColor CGColor];
|
||||
[self constructKeyboard];
|
||||
}
|
||||
|
||||
|
@ -166,7 +169,7 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
keyCapView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
keyCapView.layer.borderWidth = 1.0f;
|
||||
keyCapView.layer.borderColor = [[UIColor blackColor] CGColor];
|
||||
[keyCapView setupWithKeyMapper:self.keyMapper];
|
||||
[keyCapView setupWithKeyMapper:self.keyMapperWorkingCopy];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onKeyTap:)];
|
||||
[keyCapView addGestureRecognizer:tap];
|
||||
[self.keyCapViews addObject:keyCapView];
|
||||
|
@ -218,7 +221,7 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
|
||||
- (void) refreshAllKeyCapViews {
|
||||
for (KeyCapView *view in self.keyCapViews) {
|
||||
[view setupWithKeyMapper:self.keyMapper];
|
||||
[view setupWithKeyMapper:self.keyMapperWorkingCopy];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,62 +244,62 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
if ( controller.extendedGamepad ) {
|
||||
controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) {
|
||||
if ( gamepad.buttonA.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_A];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_A];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonB.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_B];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_B];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonX.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_X];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_X];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonY.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_Y];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_Y];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.leftShoulder.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_LS];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_LS];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.rightShoulder.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_RS];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_RS];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.xAxis.value > 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_RIGHT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_RIGHT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.xAxis.value < 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_LEFT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_LEFT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.yAxis.value > 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_UP];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_UP];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.yAxis.value < 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_DOWN];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_DOWN];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.rightTrigger.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_RT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_RT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.leftTrigger.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_LT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_LT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
|
@ -304,52 +307,52 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
} else {
|
||||
controller.gamepad.valueChangedHandler = ^(GCGamepad *gamepad, GCControllerElement *element) {
|
||||
if ( gamepad.buttonA.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_A];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_A];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonB.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_B];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_B];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonX.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_X];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_X];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.buttonY.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_Y];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_Y];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];;
|
||||
return;
|
||||
}
|
||||
if ( gamepad.leftShoulder.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_LS];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_LS];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.rightShoulder.pressed ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_BUTTON_RS];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_BUTTON_RS];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.xAxis.value > 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_RIGHT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_RIGHT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.xAxis.value < 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_LEFT];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_LEFT];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.yAxis.value > 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_UP];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_UP];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
if ( gamepad.dpad.yAxis.value < 0.0f ) {
|
||||
[self.keyMapper mapKey:keyboardKey ToControl:MFI_DPAD_DOWN];
|
||||
[self.keyMapperWorkingCopy mapKey:keyboardKey ToControl:MFI_DPAD_DOWN];
|
||||
[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
|
||||
return;
|
||||
}
|
||||
|
@ -370,18 +373,26 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
}
|
||||
|
||||
-(IBAction)saveButtonTapped:(id)sender {
|
||||
self.keyMapper = [self.keyMapperWorkingCopy copy];
|
||||
[self.keyMapper saveKeyMapping];
|
||||
self.keyMapperWorkingCopy = nil;
|
||||
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
|
||||
self.onDismissal();
|
||||
}];
|
||||
}
|
||||
|
||||
-(IBAction)cancelButtonTapped:(id)sender {
|
||||
self.keyMapperWorkingCopy = nil;
|
||||
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
|
||||
self.onDismissal();
|
||||
}];
|
||||
}
|
||||
|
||||
-(IBAction) defaultsButtonTapped:(id)sender {
|
||||
[self.keyMapperWorkingCopy resetToDefaults];
|
||||
[self refreshAllKeyCapViews];
|
||||
}
|
||||
|
||||
#
|
||||
# pragma mark - UIAlertViewDelegate
|
||||
#
|
||||
|
@ -390,7 +401,7 @@ struct KeyCap keyCapDefinitions[] = {
|
|||
[self stopRemappingControls];
|
||||
if ( buttonIndex == 1 ) {
|
||||
AppleKeyboardKey mappedKey = alertView.tag;
|
||||
[self.keyMapper unmapKey:mappedKey];
|
||||
[self.keyMapperWorkingCopy unmapKey:mappedKey];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="GameControllerKeyRemapController">
|
||||
<connections>
|
||||
<outlet property="cancelButton" destination="zAx-JO-gDf" id="i1M-NV-0UN"/>
|
||||
<outlet property="defaultsButton" destination="Ih9-iG-ECT" id="Ho3-g5-rOQ"/>
|
||||
<outlet property="keyboardContainerView" destination="PbL-95-ilz" id="UPI-70-2J7"/>
|
||||
<outlet property="saveButton" destination="Ihv-aC-sb7" id="Byt-Gy-MVK"/>
|
||||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
|
||||
|
@ -20,11 +21,14 @@
|
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PbL-95-ilz" userLabel="Keyboard Container View">
|
||||
<rect key="frame" x="0.0" y="360" width="600" height="240"/>
|
||||
<rect key="frame" x="0.0" y="380" width="600" height="220"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="220" id="QNq-rB-Zxd"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ihv-aC-sb7">
|
||||
<rect key="frame" x="96" y="203" width="107" height="44"/>
|
||||
<rect key="frame" x="88.5" y="158" width="107" height="44"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="107" id="82d-Qy-Xfg"/>
|
||||
<constraint firstAttribute="height" constant="44" id="bOc-8m-OXA"/>
|
||||
|
@ -35,8 +39,10 @@
|
|||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zAx-JO-gDf">
|
||||
<rect key="frame" x="396.5" y="203" width="107" height="44"/>
|
||||
<state key="normal" title="Cancel"/>
|
||||
<rect key="frame" x="404.5" y="158" width="107" height="44"/>
|
||||
<state key="normal" title="Cancel">
|
||||
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="cancelButtonTapped:" destination="-1" eventType="touchUpInside" id="byq-hr-jDY"/>
|
||||
</connections>
|
||||
|
@ -47,6 +53,23 @@
|
|||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ih9-iG-ECT">
|
||||
<rect key="frame" x="247" y="158" width="107" height="44"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="107" id="8aa-Yx-81a"/>
|
||||
<constraint firstAttribute="height" constant="44" id="qBN-1t-J0B"/>
|
||||
</constraints>
|
||||
<state key="normal" title="Defaults"/>
|
||||
<variation key="default">
|
||||
<mask key="constraints">
|
||||
<exclude reference="8aa-Yx-81a"/>
|
||||
<exclude reference="qBN-1t-J0B"/>
|
||||
</mask>
|
||||
</variation>
|
||||
<connections>
|
||||
<action selector="defaultsButtonTapped:" destination="-1" eventType="touchUpInside" id="reT-vk-ZW4"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
|
@ -55,17 +78,22 @@
|
|||
<constraint firstItem="PbL-95-ilz" firstAttribute="height" secondItem="i5M-Pr-FkT" secondAttribute="height" multiplier="0.4" id="7Tq-sc-r5F"/>
|
||||
<constraint firstItem="PbL-95-ilz" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="ALZ-jN-EW8"/>
|
||||
<constraint firstItem="zAx-JO-gDf" firstAttribute="height" secondItem="Ihv-aC-sb7" secondAttribute="height" id="HFd-QQ-Vpx"/>
|
||||
<constraint firstItem="zAx-JO-gDf" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" multiplier="1.5" id="Kdj-w0-y90"/>
|
||||
<constraint firstItem="zAx-JO-gDf" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" multiplier="1.5" constant="8" id="Kdj-w0-y90"/>
|
||||
<constraint firstItem="Ih9-iG-ECT" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="Mgp-p2-fmB"/>
|
||||
<constraint firstItem="Ih9-iG-ECT" firstAttribute="width" secondItem="Ihv-aC-sb7" secondAttribute="width" id="R6y-RO-5t1"/>
|
||||
<constraint firstItem="Ih9-iG-ECT" firstAttribute="top" secondItem="Ihv-aC-sb7" secondAttribute="top" id="XbU-xP-HYw"/>
|
||||
<constraint firstItem="x2H-qm-EGT" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="ZTO-dh-bwz"/>
|
||||
<constraint firstItem="zAx-JO-gDf" firstAttribute="centerX" secondItem="Ihv-aC-sb7" secondAttribute="centerX" multiplier="2" id="hJc-6p-crb"/>
|
||||
<constraint firstAttribute="bottom" secondItem="PbL-95-ilz" secondAttribute="bottom" id="kCc-QA-uYA"/>
|
||||
<constraint firstItem="zAx-JO-gDf" firstAttribute="width" secondItem="Ihv-aC-sb7" secondAttribute="width" id="mPI-1j-gTO"/>
|
||||
<constraint firstItem="Ihv-aC-sb7" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" multiplier="0.5" id="niB-eU-bnx"/>
|
||||
<constraint firstItem="Ihv-aC-sb7" firstAttribute="centerY" secondItem="i5M-Pr-FkT" secondAttribute="centerY" multiplier="0.75" id="vLe-Gk-22l"/>
|
||||
<constraint firstItem="Ihv-aC-sb7" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" multiplier="0.5" constant="-8" id="niB-eU-bnx"/>
|
||||
<constraint firstItem="Ihv-aC-sb7" firstAttribute="centerY" secondItem="i5M-Pr-FkT" secondAttribute="centerY" multiplier="0.6" id="vLe-Gk-22l"/>
|
||||
<constraint firstAttribute="trailing" secondItem="PbL-95-ilz" secondAttribute="trailing" id="zbm-Dr-7Jd"/>
|
||||
<constraint firstItem="Ih9-iG-ECT" firstAttribute="height" secondItem="Ihv-aC-sb7" secondAttribute="height" id="zd1-zF-ZZI"/>
|
||||
</constraints>
|
||||
<variation key="default">
|
||||
<mask key="constraints">
|
||||
<exclude reference="7Tq-sc-r5F"/>
|
||||
<exclude reference="hJc-6p-crb"/>
|
||||
</mask>
|
||||
</variation>
|
||||
|
|
|
@ -570,6 +570,7 @@ extern int findCode(const char* _s);
|
|||
[self setMenuBarVisibility:TRUE]; // So First time users are not lost!
|
||||
|
||||
self.keyMapper = [[KeyMapper alloc] init];
|
||||
[self.keyMapper loadFromDefaults];
|
||||
|
||||
self.mfiControllerHandler = [[MfiGameControllerHandler alloc] init];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
@ -678,13 +679,13 @@ extern int findCode(const char* _s);
|
|||
};
|
||||
}
|
||||
|
||||
__block AppleKeyboardKey mappedKeyRS = [self.keyMapper getMappedKeyForControl:MFI_BUTTON_RS];
|
||||
if ( mappedKeyRS != NSNotFound ) {
|
||||
mappedKey = [self.keyMapper getMappedKeyForControl:MFI_BUTTON_RS];
|
||||
if ( mappedKey != NSNotFound ) {
|
||||
buttonRS.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
if ( pressed ) {
|
||||
add_event_key((int)mappedKeyRS, 0);
|
||||
add_event_key((int)mappedKey, 0);
|
||||
} else {
|
||||
add_event_key((int)mappedKeyRS, 1);
|
||||
add_event_key((int)mappedKey, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1107,6 +1108,7 @@ extern int x_frame_rate ;
|
|||
GameControllerKeyRemapController *remapController = [[GameControllerKeyRemapController alloc] initWithNibName:@"GameControllerKeyRemapController" bundle:nil];
|
||||
remapController.keyMapper = self.keyMapper;
|
||||
remapController.onDismissal = ^{
|
||||
[self.keyMapper loadFromDefaults];
|
||||
[self setupMfiController:[[GCController controllers] firstObject]];
|
||||
r_sim65816.resume();
|
||||
};
|
||||
|
@ -1214,6 +1216,15 @@ extern int x_frame_rate ;
|
|||
l+=LINEHEIGHT;
|
||||
l += 2.0;
|
||||
|
||||
UILabel* remapControlsLabel = [[UILabel alloc] initWithFrame:CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT)];
|
||||
remapControlsLabel.text = @"Key Bindings";
|
||||
remapControlsLabel.textAlignment = NSTextAlignmentCenter;
|
||||
remapControlsLabel.font = [UIFont systemFontOfSize:12*res];
|
||||
remapControlsLabel.backgroundColor = [UIColor clearColor];
|
||||
[self.runtimeControlsOptions addSubview:remapControlsLabel];
|
||||
l += LINEHEIGHT;
|
||||
|
||||
l += 2.0;
|
||||
UIButton *remapControlsButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
remapControlsButton.frame = CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT);
|
||||
[remapControlsButton setTitle:@"Remap Controls" forState:UIControlStateNormal];
|
||||
|
|
|
@ -16,8 +16,8 @@ typedef NS_ENUM(NSInteger, AppleKeyboardKey) {
|
|||
KEY_SPACE = 0x31,
|
||||
KEY_RIGHT_CURSOR = 0x3C,
|
||||
KEY_LEFT_CURSOR = 0x3B,
|
||||
KEY_UP_CURSOR = 0x5B,
|
||||
KEY_DOWN_CURSOR = 0x13,
|
||||
KEY_UP_CURSOR = 0x3E,
|
||||
KEY_DOWN_CURSOR = 0x3D,
|
||||
KEY_SHIFT = 0x38,
|
||||
KEY_Z = 0x06,
|
||||
KEY_X = 0x07,
|
||||
|
@ -105,8 +105,10 @@ typedef NS_ENUM(NSInteger, KeyCapIndex) {
|
|||
KeyCapIndexShiftedKey = 3
|
||||
};
|
||||
|
||||
@interface KeyMapper : NSObject
|
||||
@interface KeyMapper : NSObject<NSCopying>
|
||||
|
||||
-(void)loadFromDefaults;
|
||||
-(void) resetToDefaults;
|
||||
-(void) saveKeyMapping;
|
||||
-(void) mapKey:(AppleKeyboardKey)keyboardKey ToControl:(KeyMapMappableButton)button;
|
||||
-(void) unmapKey:(AppleKeyboardKey)keyboardKey;
|
||||
|
|
|
@ -14,17 +14,30 @@
|
|||
|
||||
@implementation KeyMapper
|
||||
|
||||
-(instancetype) init {
|
||||
if ( self = [super init] ) {
|
||||
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"keyMapping"];
|
||||
if ( data == nil || ![data isKindOfClass:[NSData class]] ) {
|
||||
self.keyMapping = [NSMutableDictionary dictionary];
|
||||
} else {
|
||||
NSDictionary *fetchedDict = [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
||||
self.keyMapping = [fetchedDict mutableCopy];
|
||||
}
|
||||
-(void)loadFromDefaults {
|
||||
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"keyMapping"];
|
||||
if ( data == nil || ![data isKindOfClass:[NSData class]] ) {
|
||||
self.keyMapping = [self defaultMapping];
|
||||
} else {
|
||||
NSDictionary *fetchedDict = [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
||||
self.keyMapping = [fetchedDict mutableCopy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
KeyMapper *copy = [[[self class] alloc] init];
|
||||
copy.keyMapping = [self.keyMapping mutableCopy];
|
||||
return copy;
|
||||
}
|
||||
|
||||
-(NSMutableDictionary*) defaultMapping {
|
||||
return [@{ [NSNumber numberWithInteger:MFI_BUTTON_X] : [NSNumber numberWithInteger:KEY_OPTION],
|
||||
[NSNumber numberWithInteger:MFI_BUTTON_A] : [NSNumber numberWithInteger:KEY_APPLE]
|
||||
} mutableCopy];
|
||||
}
|
||||
|
||||
-(void) resetToDefaults {
|
||||
self.keyMapping = [self defaultMapping];
|
||||
}
|
||||
|
||||
-(void) saveKeyMapping {
|
||||
|
|
Loading…
Reference in New Issue