From a772960ccc6bc5cbe22f0dd599aa749cfab368a7 Mon Sep 17 00:00:00 2001 From: Geraud Date: Fri, 30 Sep 2011 11:38:26 +0200 Subject: [PATCH 1/2] The iCadeReaderView now supports long hold. Mainly handy for the joystick. The Demo now supports diagonal directions: UpRight, ... --- iCadeTest.xcodeproj/project.pbxproj | 7 ++++++ iCadeTest/iCade/iCadeReaderView.h | 2 ++ iCadeTest/iCade/iCadeReaderView.m | 35 ++++++++++++++++++++++++++- iCadeTest/iCadeTest-Info.plist | 2 +- iCadeTest/iCadeTestViewController.m | 37 ++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/iCadeTest.xcodeproj/project.pbxproj b/iCadeTest.xcodeproj/project.pbxproj index 6743f47..a78a137 100644 --- a/iCadeTest.xcodeproj/project.pbxproj +++ b/iCadeTest.xcodeproj/project.pbxproj @@ -294,12 +294,15 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "iCadeTest/iCadeTest-Prefix.pch"; INFOPLIST_FILE = "iCadeTest/iCadeTest-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.2; PRODUCT_NAME = "$(TARGET_NAME)"; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; WRAPPER_EXTENSION = app; }; name = Debug; @@ -308,11 +311,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "iCadeTest/iCadeTest-Prefix.pch"; INFOPLIST_FILE = "iCadeTest/iCadeTest-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 4.2; PRODUCT_NAME = "$(TARGET_NAME)"; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; VALIDATE_PRODUCT = YES; WRAPPER_EXTENSION = app; }; @@ -337,6 +343,7 @@ 05059CA213AB035F00A09408 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/iCadeTest/iCade/iCadeReaderView.h b/iCadeTest/iCade/iCadeReaderView.h index 2f39a3d..a737059 100644 --- a/iCadeTest/iCade/iCadeReaderView.h +++ b/iCadeTest/iCade/iCadeReaderView.h @@ -51,6 +51,7 @@ UIView *inputView; iCadeState _iCadeState; id _delegate; + NSTimer *_actionLoop; struct { bool stateChanged:1; @@ -62,5 +63,6 @@ @property (nonatomic, assign) iCadeState iCadeState; @property (nonatomic, assign) id delegate; @property (nonatomic, assign) BOOL active; +@property (nonatomic, retain) NSTimer *actionLoop; @end diff --git a/iCadeTest/iCade/iCadeReaderView.m b/iCadeTest/iCade/iCadeReaderView.m index 2437276..9202d56 100644 --- a/iCadeTest/iCade/iCadeReaderView.m +++ b/iCadeTest/iCade/iCadeReaderView.m @@ -24,6 +24,10 @@ of this software and associated documentation files (the "Software"), to deal static const char *ON_STATES = "wdxayhujikol"; static const char *OFF_STATES = "eczqtrfnmpgv"; +static const iCadeState ICADE_STATES[] = {iCadeJoystickDownLeft, iCadeJoystickDownRight, iCadeJoystickUpLeft,iCadeJoystickUpRight, + iCadeJoystickUp, iCadeJoystickDown, iCadeJoystickLeft, iCadeJoystickRight, + iCadeButtonA, iCadeButtonB, iCadeButtonC, iCadeButtonD, + iCadeButtonE, iCadeButtonF, iCadeButtonG, iCadeButtonH}; @interface iCadeReaderView() @@ -34,7 +38,7 @@ - (void)didBecomeActive; @implementation iCadeReaderView -@synthesize iCadeState=_iCadeState, delegate=_delegate, active; +@synthesize iCadeState=_iCadeState, delegate=_delegate, active, actionLoop = _actionLoop; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -42,6 +46,7 @@ - (id)initWithFrame:(CGRect)frame { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; + self.actionLoop = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(checkCurrentState:) userInfo:nil repeats:YES]; return self; } @@ -134,6 +139,34 @@ - (void)insertText:(NSString *)text { } } +//We check if the current state contains a specific state. +//In this case, we remove the State and we notify the delegate +- (void)compareState:(iCadeState *)currentState withState:(iCadeState)testState { + if ((testState & *currentState) == testState) { + NSLog(@"This is the currentState: %i and the testState: %i", *currentState, testState); + *currentState &= ~testState; + if (_delegateFlags.stateChanged) { + [_delegate stateChanged:testState]; + } else { + if (_delegateFlags.buttonDown) { + [_delegate buttonDown:testState]; + } + } + } +} + +- (void)checkCurrentState:(NSTimer*)theTimer { + iCadeState currentState = _iCadeState; + NSLog(@" \n\n\n\n\n\nThis is the currentState: %i", currentState); + + //We begin with the composition (UpRight). + //Else, we would have sent 2 separate actions instead of the composition + for (int i = 0; i<16; i++) { + [self compareState:¤tState withState:ICADE_STATES[i]]; + } + +} + - (void)deleteBackward { // This space intentionally left blank to complete protocol } diff --git a/iCadeTest/iCadeTest-Info.plist b/iCadeTest/iCadeTest-Info.plist index 70ae644..750d10e 100644 --- a/iCadeTest/iCadeTest-Info.plist +++ b/iCadeTest/iCadeTest-Info.plist @@ -17,7 +17,7 @@ Icon.png CFBundleIdentifier - com.manomio.${PRODUCT_NAME:rfc1034identifier} + com.creatives.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/iCadeTest/iCadeTestViewController.m b/iCadeTest/iCadeTestViewController.m index e83e4bf..4f6adf7 100644 --- a/iCadeTest/iCadeTestViewController.m +++ b/iCadeTest/iCadeTestViewController.m @@ -144,7 +144,42 @@ - (void)setState:(BOOL)state forButton:(iCadeState)button { center.x += offset; } break; - + case iCadeJoystickDownLeft: + if (state) { + center.x -= offset; + center.y += offset; + } else { + center.x += offset; + center.y -= offset; + } + break; + case iCadeJoystickDownRight: + if (state) { + center.x += offset; + center.y += offset; + } else { + center.x -= offset; + center.y -= offset; + } + break; + case iCadeJoystickUpLeft: + if (state) { + center.x -= offset; + center.y -= offset; + } else { + center.x += offset; + center.y += offset; + } + break; + case iCadeJoystickUpRight: + if (state) { + center.x += offset; + center.y -= offset; + } else { + center.x -= offset; + center.y += offset; + } + break; default: break; } From 075bcabe117c8b40980bde2b416dfa34936a8c84 Mon Sep 17 00:00:00 2001 From: Geraud Date: Fri, 30 Sep 2011 11:42:07 +0200 Subject: [PATCH 2/2] The iCadeReaderView now supports long hold. Mainly handy for the joystick. The Demo now supports diagonal directions: UpRight, ... --- iCadeTest/iCadeTest-Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iCadeTest/iCadeTest-Info.plist b/iCadeTest/iCadeTest-Info.plist index 750d10e..70ae644 100644 --- a/iCadeTest/iCadeTest-Info.plist +++ b/iCadeTest/iCadeTest-Info.plist @@ -17,7 +17,7 @@ Icon.png CFBundleIdentifier - com.creatives.${PRODUCT_NAME:rfc1034identifier} + com.manomio.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName