spacefractal · 25621
//// InputView.h// Jungool//// Created by Ben Baker on 19/11/10.// Copyright 2010 Headsoft. All rights reserved.//#import <Foundation/Foundation.h>#import "ESRenderer.h"#import "GamePadState.h"/* P1 UP ON,OFF = w,e P1 RT ON,OFF = d,c P1 DN ON,OFF = x,z P1 LT ON,OFF = a,q P1 A ON,OFF = y,t P1 B ON,OFF = h,r P1 C ON,OFF = u,f P1 D ON,OFF = j,n P1 E ON,OFF = i,m P1 F ON,OFF = k,p P1 G ON,OFF = o,g P1 H ON,OFF = l,v P2 UP ON,OFF = W,E P2 RT ON,OFF = D,C P2 DN ON,OFF = X,Z P2 LT ON,OFF = A,Q P2 A ON,OFF = Y,T P2 B ON,OFF = H,R P2 C ON,OFF = U,F P2 D ON,OFF = J,N P2 E ON,OFF = I,M P2 F ON,OFF = K,P P2 G ON,OFF = O,G P2 H ON,OFF = L,V */#define APPLE_MAX_JOYCOUNT 4@protocol GamePadEventDelegate <NSObject>@optional- (void)stateChanged:(GamePadState)state;- (void)buttonDown:(GamePadState)button;- (void)buttonUp:(GamePadState)button;@end@interface InputView : UIView <UIKeyInput, UIAccelerometerDelegate, GamePadEventDelegate>{@public; ESRenderer *m_renderer; UIView *m_inputView; GamePadState m_gamePadState; id<GamePadEventDelegate> m_delegate; long long m_inputDown[APPLE_MAX_JOYCOUNT]; struct { bool stateChanged:1; bool buttonDown:1; bool buttonUp:1; } m_delegateFlags;}@property (readwrite, retain) ESRenderer *renderer;@property (nonatomic, assign) GamePadState gamePadState;@property (nonatomic, assign) id<GamePadEventDelegate> delegate;@property (nonatomic, assign) BOOL active;- (void)addObservers;- (void)removeObservers;- (void)didEnterBackground;- (void)didBecomeActive;@end
//// InputView.m// Jungool//// Created by Ben Baker on 19/11/10.// Copyright 2010 Headsoft. All rights reserved.//#import "GameController/GCController.h"#import "InputView.h"#include "Globals.h"static const char *ON_STATES = "wdxayhujikolWDXAYHUJIKOL";static const char *OFF_STATES = "eczqtrfnmpgvECZQTRFNMPGV";@implementation InputView@synthesize renderer = m_renderer;@synthesize active = m_active;@synthesize gamePadState = m_gamePadState;@synthesize delegate = m_delegate;- (id)initWithFrame:(CGRect)frame{ if ((self = [super initWithFrame:frame])) { m_inputView = [[UIView alloc] initWithFrame:CGRectZero]; [self setMultipleTouchEnabled:YES]; [self addObservers]; [self setDelegate:self]; memset(m_inputDown, sizeof(m_inputDown[0]) * APPLE_MAX_JOYCOUNT, 0); // iOS 7 Game Controller if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) [self gameControllerConnect]; } return self;}- (void)dealloc{ [self removeObservers]; [super dealloc];}#pragma mark Touch methods- (CGPoint)rotateTouch:(CGPoint) point{ float tempX = 0; point.x *= g_inputScreen->Scale; point.y *= g_inputScreen->Scale; switch(g_inputScreen->Angle) { case ROTATION_0: break; case ROTATION_90: tempX = point.x; point.x = g_inputScreen->DisplaySize.width - point.y; point.y = tempX; break; case ROTATION_180: point.x = g_inputScreen->DisplaySize.width - point.x; point.y = g_inputScreen->DisplaySize.height - point.y; break; case ROTATION_270: tempX = point.x; point.x = point.y; point.y = g_inputScreen->DisplaySize.height - tempX; break; default: break; } //DEBUGLOG("X:%.2f of %.0f Y:%.2f of %.0f", point.x, g_displaySize.width, point.y, g_displaySize.height); return point;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSArray *touchArray = [touches allObjects]; NSInteger touchCount = [touchArray count]; //NSSet *allTouches = [event allTouches]; for(int i=0; i<touchCount; i++) { UITouch *touch = [touchArray objectAtIndex:i]; int id = (int)touch; for(int j=0; j<TOUCH_MAX; j++) { if(g_touchCurrent[j].Id == 0) { CGPoint point = [self rotateTouch:[touch locationInView:self]]; g_touchCurrent[j].Id = id; g_touchCurrent[j].Type = TOUCH_DOWN; g_touchCurrent[j].Position = Vector2DMake(point.x, point.y); g_touchCurrent[j].PositionNormal = Vector2DMake(point.x / g_inputScreen->DisplaySize.width, point.y / g_inputScreen->DisplaySize.height); g_touchCurrent[j].PositionWorld = Vector2DMake(g_touchCurrent[j].PositionNormal.x * g_inputScreen->ScreenRect.width - g_inputScreen->ScreenRect.width * 0.5f, -(g_touchCurrent[j].PositionNormal.y * g_inputScreen->ScreenRect.height - g_inputScreen->ScreenRect.height * 0.5f)); g_touchCurrent[j].TouchRegion = (g_touchCurrent[j].PositionNormal.x < 0.5f ? REGION_LEFT : (g_touchCurrent[j].PositionNormal.x >= 0.5f ? REGION_RIGHT : 0)); g_touchCurrent[j].TouchRegion |= (g_touchCurrent[j].PositionNormal.y < 0.5f ? REGION_TOP : (g_touchCurrent[j].PositionNormal.y >= 0.5f ? REGION_BOTTOM : 0)); g_touchCurrent[j].TouchDown = &g_touchDown[j]; g_touchCurrent[j].TouchMove = NULL; g_touchCurrent[j].TouchUp = NULL; g_touchCurrent[j].TouchPrevious = NULL; g_touchDown[j] = g_touchCurrent[j]; //DEBUGLOG("TOUCH %d (%3.3f,%3.3f)", j, - g_touchCurrent[j].Position.y + 320.0f, g_touchCurrent[j].Position.x); g_touchAll[i] = &g_touchCurrent[j]; break; } } } if(g_touchAll[0] == NULL) return; [m_renderer touchDown:g_touchAll touchCount:touchCount touches:touches withEvent:event];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSArray *touchArray = [touches allObjects]; NSInteger touchCount = [touchArray count]; //NSSet *allTouches = [event allTouches]; for(int i=0; i<touchCount; i++) { UITouch *touch = [touchArray objectAtIndex:i]; int id = (int)touch; for(int j=0; j<TOUCH_MAX; j++) { if(g_touchCurrent[j].Id == id) { CGPoint point = [self rotateTouch:[touch locationInView:self]]; g_touchPrevious[j] = g_touchCurrent[j]; g_touchCurrent[j].Id = id; g_touchCurrent[j].Type = TOUCH_MOVE; g_touchCurrent[j].Position = Vector2DMake(point.x, point.y); g_touchCurrent[j].PositionNormal = Vector2DMake(point.x / g_inputScreen->DisplaySize.width, point.y / g_inputScreen->DisplaySize.height); g_touchCurrent[j].PositionWorld = Vector2DMake(g_touchCurrent[j].PositionNormal.x * g_inputScreen->ScreenRect.width - g_inputScreen->ScreenRect.width * 0.5f, -(g_touchCurrent[j].PositionNormal.y * g_inputScreen->ScreenRect.height - g_inputScreen->ScreenRect.height * 0.5f)); g_touchCurrent[j].TouchRegion = (g_touchCurrent[j].PositionNormal.x < 0.5f ? REGION_LEFT : (g_touchCurrent[j].PositionNormal.x >= 0.5f ? REGION_RIGHT : 0)); g_touchCurrent[j].TouchRegion |= (g_touchCurrent[j].PositionNormal.y < 0.5f ? REGION_TOP : (g_touchCurrent[j].PositionNormal.y >= 0.5f ? REGION_BOTTOM : 0)); g_touchCurrent[j].TouchDown = &g_touchDown[j]; g_touchCurrent[j].TouchMove = &g_touchMove[j]; g_touchCurrent[j].TouchUp = NULL; g_touchCurrent[j].TouchPrevious = &g_touchPrevious[j]; g_touchMove[j] = g_touchCurrent[j]; //DEBUGLOG("MOVED %d (%3.3f,%3.3f)", j, - g_touchCurrent[j].Position.y + 320.0f, g_touchCurrent[j].Position.x); g_touchAll[i] = &g_touchCurrent[j]; break; } } } if(g_touchAll[0] == NULL) return; [m_renderer touchMove:g_touchAll touchCount:touchCount touches:touches withEvent:event];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSArray *touchArray = [touches allObjects]; NSInteger touchCount = [touchArray count]; //NSSet *allTouches = [event allTouches]; for(int i=0; i<touchCount; i++) { UITouch *touch = [touchArray objectAtIndex:i]; int id = (int)touch; for(int j=0; j<TOUCH_MAX; j++) { if(g_touchCurrent[j].Id == id) { CGPoint point = [self rotateTouch:[touch locationInView:self]]; g_touchPrevious[j] = g_touchCurrent[j]; g_touchCurrent[j].Id = id; g_touchCurrent[j].Type = TOUCH_UP; g_touchCurrent[j].Position = Vector2DMake(point.x, point.y); g_touchCurrent[j].PositionNormal = Vector2DMake(point.x / g_inputScreen->DisplaySize.width, point.y / g_inputScreen->DisplaySize.height); g_touchCurrent[j].PositionWorld = Vector2DMake(g_touchCurrent[j].PositionNormal.x * g_inputScreen->ScreenRect.width - g_inputScreen->ScreenRect.width * 0.5f, -(g_touchCurrent[j].PositionNormal.y * g_inputScreen->ScreenRect.height - g_inputScreen->ScreenRect.height * 0.5f)); g_touchCurrent[j].TouchRegion = (g_touchCurrent[j].PositionNormal.x < 0.5f ? REGION_LEFT : (g_touchCurrent[j].PositionNormal.x >= 0.5f ? REGION_RIGHT : 0)); g_touchCurrent[j].TouchRegion |= (g_touchCurrent[j].PositionNormal.y < 0.5f ? REGION_TOP : (g_touchCurrent[j].PositionNormal.y >= 0.5f ? REGION_BOTTOM : 0)); g_touchCurrent[j].TouchDown = &g_touchDown[j]; g_touchCurrent[j].TouchMove = &g_touchMove[j]; g_touchCurrent[j].TouchUp = &g_touchUp[j]; g_touchCurrent[j].TouchPrevious = &g_touchPrevious[j]; g_touchUp[j] = g_touchCurrent[j]; g_touchAll[i] = &g_touchCurrent[j]; break; } } } if(g_touchAll[0] == NULL) return; [m_renderer touchUp:g_touchAll touchCount:touchCount touches:touches withEvent:event]; for(int i=0; i<touchCount; i++) { for(int j=0; j<TOUCH_MAX; j++) { UITouch *touch = [touchArray objectAtIndex:i]; int id = (int)touch; if(g_touchCurrent[j].Id == id) { g_touchAll[i] = NULL; memset(&g_touchCurrent[j], 0, sizeof(Touch)); memset(&g_touchDown[j], 0, sizeof(Touch)); memset(&g_touchMove[j], 0, sizeof(Touch)); memset(&g_touchUp[j], 0, sizeof(Touch)); memset(&g_touchPrevious[j], 0, sizeof(Touch)); } } }}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ NSArray *touchArray = [touches allObjects]; NSInteger touchCount = [touchArray count]; //NSSet *allTouches = [event allTouches]; for(int i=0; i<touchCount; i++) { for(int j=0; j<TOUCH_MAX; j++) { UITouch *touch = [touchArray objectAtIndex:i]; int id = (int)touch; if(g_touchDown[j].Id == id) { g_touchAll[i] = NULL; memset(&g_touchCurrent[j], 0, sizeof(Touch)); memset(&g_touchDown[j], 0, sizeof(Touch)); memset(&g_touchMove[j], 0, sizeof(Touch)); memset(&g_touchUp[j], 0, sizeof(Touch)); memset(&g_touchPrevious[j], 0, sizeof(Touch)); } } }}- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ [m_renderer motionEnded:motion withEvent:event];}- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration{ [m_renderer accelerometer:accelerometer didAccelerate:acceleration];}- (void)setRotation:(Rotation)rotation{ [m_renderer setRotation:rotation];}- (void)resetRotation{ [m_renderer resetRotation];}- (void)detectRotation{ [m_renderer detectRotation];}- (void)buttonDown:(GamePadState)button{ [m_renderer buttonDown:button];}- (void)buttonUp:(GamePadState)button{ [m_renderer buttonUp:button];}#pragma mark -#pragma mark UIKeyInput Protocol Methods- (BOOL)hasText{ return NO;}- (void)insertText:(NSString *)text{ char ch = [text characterAtIndex:0]; char *pOn = strchr(ON_STATES, ch); char *pOff = strchr(OFF_STATES, ch); bool stateChanged = false; if (pOn) { int index = pOn - ON_STATES; m_gamePadState = (GamePadState) ((int)m_gamePadState | (1 << index)); stateChanged = true; if (m_delegateFlags.buttonDown) { [m_delegate buttonDown:(GamePadState)(1 << index)]; } } else if(pOff) { int index = pOff - OFF_STATES; m_gamePadState = (GamePadState) ((int)m_gamePadState & ~(1 << index)); stateChanged = true; if (m_delegateFlags.buttonUp) { [m_delegate buttonUp:(GamePadState)(1 << index)]; } } if (stateChanged && m_delegateFlags.stateChanged) { [m_delegate stateChanged:m_gamePadState]; } static int cycleResponder = 0; if (++cycleResponder > 20) { // necessary to clear a buffer that accumulates internally cycleResponder = 0; [self resignFirstResponder]; [self becomeFirstResponder]; }}- (void)deleteBackward{ // This space intentionally left blank to complete protocol}#pragma mark -#pragma mark Apple Game Controller- (void)gameControllerDidConnect{ [self gameControllerConnect];}- (void)gameControllerDidDisconnect{ [self gameControllerConnect];}- (void)gameControllerConnect{ int controllerCount = [[GCController controllers] count]; NSLog(@"ControllerCount %d", controllerCount); if(controllerCount > 0) g_inputDown |= DEVICE_APPLE; else g_inputDown &= ~DEVICE_APPLE; [self configureConnectedGameControllers];}- (void) configureConnectedGameControllers{ NSLog(@"configureConnectedGameControllers"); // First deal with the controllers previously set to a player for (GCController *controller in [GCController controllers]) { NSInteger playerIndex = (controller.playerIndex == GCControllerPlayerIndexUnset ? 0 : controller.playerIndex); GCExtendedGamepad *profile = controller.extendedGamepad; controller.controllerPausedHandler = ^(GCController *controller) { // Controller paused // ok, we need this to be used for pause g_inputDown |= INPUT_PAUSE; }; profile.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) { if(element == gamepad.dpad) { float xValue = gamepad.dpad.xAxis.value; float yValue = gamepad.dpad.yAxis.value; float distance = hypotf(xValue, yValue); if(gamepad.dpad.up.isPressed) m_inputDown[playerIndex] |= APPLE_DPAD_UP; else m_inputDown[playerIndex] &= ~APPLE_DPAD_UP; if(gamepad.dpad.down.isPressed) m_inputDown[playerIndex] |= APPLE_DPAD_DOWN; else m_inputDown[playerIndex] &= ~APPLE_DPAD_DOWN; if(gamepad.dpad.left.isPressed) m_inputDown[playerIndex] |= APPLE_DPAD_LEFT; else m_inputDown[playerIndex] &= ~APPLE_DPAD_LEFT; if(gamepad.dpad.right.isPressed) m_inputDown[playerIndex] |= APPLE_DPAD_RIGHT; else m_inputDown[playerIndex] &= ~APPLE_DPAD_RIGHT; if (distance > 0.0f) [m_renderer gameControllerAnalogInput:playerIndex xValue:xValue yValue:yValue]; } else if(element == gamepad.buttonA) { if(gamepad.buttonA.isPressed) m_inputDown[playerIndex] |= APPLE_BUTTON_A; else m_inputDown[playerIndex] &= ~APPLE_BUTTON_A; } else if(element == gamepad.buttonB) { if(gamepad.buttonB.isPressed) m_inputDown[playerIndex] |= APPLE_BUTTON_B; else m_inputDown[playerIndex] &= ~APPLE_BUTTON_B; } else if(element == gamepad.buttonX) { if(gamepad.buttonX.isPressed) m_inputDown[playerIndex] |= APPLE_BUTTON_X; else m_inputDown[playerIndex] &= ~APPLE_BUTTON_X; } else if(element == gamepad.buttonY) { if(gamepad.buttonY.isPressed) m_inputDown[playerIndex] |= APPLE_BUTTON_Y; else m_inputDown[playerIndex] &= ~APPLE_BUTTON_Y; } else if(element == gamepad.leftThumbstick) { NSLog(@"LEFT THUMB"); float xValue = gamepad.leftThumbstick.xAxis.value; float yValue = gamepad.leftThumbstick.yAxis.value; //float distance = hypotf(xValue, yValue); if(gamepad.leftThumbstick.up.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_LEFT_UP; else m_inputDown[playerIndex] &= ~APPLE_THUMB_LEFT_UP; if(gamepad.leftThumbstick.down.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_LEFT_DOWN; else m_inputDown[playerIndex] &= ~APPLE_THUMB_LEFT_DOWN; if(gamepad.leftThumbstick.left.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_LEFT_LEFT; else m_inputDown[playerIndex] &= ~APPLE_THUMB_LEFT_LEFT; if(gamepad.leftThumbstick.right.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_LEFT_RIGHT; else m_inputDown[playerIndex] &= ~APPLE_THUMB_LEFT_RIGHT; // if (distance > 0.0f) [m_renderer gameControllerAnalogInput:playerIndex xValue:xValue yValue:yValue]; } else if(element == gamepad.rightThumbstick) { float xValue = gamepad.rightThumbstick.xAxis.value; float yValue = gamepad.rightThumbstick.yAxis.value; //float distance = hypotf(xValue, yValue); if(gamepad.rightThumbstick.up.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_RIGHT_UP; else m_inputDown[playerIndex] &= ~APPLE_THUMB_RIGHT_UP; if(gamepad.rightThumbstick.down.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_RIGHT_DOWN; else m_inputDown[playerIndex] &= ~APPLE_THUMB_RIGHT_DOWN; if(gamepad.rightThumbstick.left.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_RIGHT_LEFT; else m_inputDown[playerIndex] &= ~APPLE_THUMB_RIGHT_LEFT; if(gamepad.rightThumbstick.right.isPressed) m_inputDown[playerIndex] |= APPLE_THUMB_RIGHT_RIGHT; else m_inputDown[playerIndex] &= ~APPLE_THUMB_RIGHT_RIGHT; //if (distance > 0.0f) [m_renderer gameControllerAnalogInput:playerIndex xValue:xValue yValue:yValue]; } else if(element == gamepad.leftShoulder) { if(gamepad.leftShoulder.isPressed) m_inputDown[playerIndex] |= APPLE_SHOULDER_LEFT; else m_inputDown[playerIndex] &= ~APPLE_SHOULDER_LEFT; } else if(element == gamepad.rightShoulder) { if(gamepad.rightShoulder.isPressed) m_inputDown[playerIndex] |= APPLE_SHOULDER_RIGHT; else m_inputDown[playerIndex] &= ~APPLE_SHOULDER_RIGHT; } else if(element == gamepad.leftTrigger) { if(gamepad.leftTrigger.isPressed) m_inputDown[playerIndex] |= APPLE_TRIGGER_LEFT; else m_inputDown[playerIndex] &= ~APPLE_TRIGGER_LEFT; } else if(element == gamepad.rightTrigger) { if(gamepad.rightTrigger.isPressed) m_inputDown[playerIndex] |= APPLE_TRIGGER_RIGHT; else m_inputDown[playerIndex] &= ~APPLE_TRIGGER_RIGHT; } if (g_joystick != NULL) g_joystick->SetVisible(false); // Turn off joystick // NSLog(@"Calling gameControllerButtonInput"); [m_renderer gameControllerButtonInput:playerIndex inputDown:m_inputDown[playerIndex]]; }; }}#pragma mark -#pragma mark ***************- (void)setDelegate:(id<GamePadEventDelegate>)delegate{ m_delegate = delegate; if (!m_delegate) return; m_delegateFlags.stateChanged = [m_delegate respondsToSelector:@selector(stateChanged:)]; m_delegateFlags.buttonDown = [m_delegate respondsToSelector:@selector(buttonDown:)]; m_delegateFlags.buttonUp = [m_delegate respondsToSelector:@selector(buttonUp:)];}- (UIView *) inputView{ return m_inputView;}- (void)setActive:(BOOL)value{ m_active = value; if (m_active) { [self becomeFirstResponder]; } else { [self resignFirstResponder]; }}- (void)addObservers{ //[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0f / ACCELEROMETER_FREQUENCY)]; //[[UIAccelerometer sharedAccelerometer] setDelegate:self]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectRotation) name:UIDeviceOrientationDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gameControllerDidConnect) name:GCControllerDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gameControllerDidDisconnect) name:GCControllerDidDisconnectNotification object:nil]; }}- (void)removeObservers{ //[[UIAccelerometer sharedAccelerometer] setDelegate:nil]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { [[NSNotificationCenter defaultCenter] removeObserver:self name:GCControllerDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:GCControllerDidDisconnectNotification object:nil]; }}- (void)didEnterBackground{ if (self.active) [self resignFirstResponder];}- (void)didBecomeActive{ if (self.active) [self becomeFirstResponder];}- (BOOL)canBecomeFirstResponder{ return YES;}@end
const char* StoreGetPrice(const char* productid){ NSString *ProductID = [[NSString alloc] initWithUTF8String:productid]; NSDictionary *prices = [[MKStoreManager sharedManager] pricesDictionary]; NSString *upgradePrice = [prices objectForKey:ProductID]; if (upgradePrice) { strcpy(iPrice, [upgradePrice UTF8String]); } return iPrice;}
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gameControllerDidConnect) name:GCControllerDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gameControllerDidDisconnect) name:GCControllerDidDisconnectNotification object:nil];}
profile.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element){ if(gamepad.buttonA.isPressed) // A button pressed};
Im should get one of the controller. Which one did you get?
im do wonder what Lobo is going today.
#import <Foundation/NSObject.h>#import <Foundation/NSString.h>#import <Foundation/NSFileManager.h>#import <Foundation/NSURL.h>#import <Foundation/NSBundle.h>#import <string.h>#import <UIKit/UIKit.h>#import <Social/Social.h>void postToFacebook(const char* text, const char *url, const char *image) { NSString *Stext = [[NSString alloc] initWithUTF8String:text]; NSString *Surl = [[NSString alloc] initWithUTF8String:url]; NSString *Simage = [[NSString alloc] initWithUTF8String:image]; if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; [controller setInitialText:@"First post from my iPhone app"]; [controller addURL:[NSURL URLWithString:@"http://www.appcoda.com"]]; [controller addImage:[UIImage imageNamed:@"socialsharing-facebook-image.jpg"]]; [self presentViewController:controller animated:YES completion:Nil]; }}
//// FacebookPost.h// WinSolitaire//// Created by Ben Baker on 6/10/13.// Copyright (c) 2013 Headsoft. All rights reserved.//#ifndef __FACEBOOKPOST_H__#define __FACEBOOKPOST_H__#ifdef __OBJC__#import <Foundation/Foundation.h>#import <FacebookSDK/FacebookSDK.h>@interface FacebookPost : NSObject{ NSString *m_name;}@property (retain) NSString *message;@property (retain) NSString *name;+ (void)postData:(NSString *)imageUrl message:(NSString *)message;+ (void)postImage:(NSString *)imageUrl message:(NSString *)message;+ (bool)isSessionOpen;+ (void)openSession;+ (void)closeSession;+ (void)postWallImage:(NSString*)imageUrl message:(NSString *)message;@end#elsebool fbIsSessionOpen();void fbOpenSession();void fbCloseSession();#endif#endif
//// FacebookPost.m// WinSolitaire//// Created by Ben Baker on 6/10/13.// Copyright (c) 2013 Headsoft. All rights reserved.//#import "FacebookPost.h"#import <FacebookSDK/FacebookSDK.h>#import "SolitaireAppDelegate.h"#import "GfxManager.h"@implementation FacebookPoststatic NSString *m_name = nil;// Start here https://developers.facebook.com/docs/getting-started/getting-started-with-the-ios-sdk/// Install the Facebook SDK, get it linked up, create an app, and get that setup correctly// in your info.plist, appDelegate, and build settings.+ (void)postData:(NSString *)imageUrl message:(NSString *)message{ DEBUGLOG("postData"); [self postImage:imageUrl message:message];}+ (bool)isSessionOpen{ return [[FBSession activeSession] isOpen];}+ (void)openSession{ [FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObject:@"basic_info"] allowLoginUI:!FBSession.activeSession.isOpen completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }];}+ (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error{ switch (state) { case FBSessionStateOpen: if (error) DEBUGLOG("Facebook: Session Error."); else DEBUGLOG("Facebook: Session Open."); break; case FBSessionStateClosed: DEBUGLOG("FBSessionStateClosed: Facebook: Facebook: Closing Session."); [FacebookPost closeSession]; [FacebookPost openSession]; break; case FBSessionStateClosedLoginFailed: DEBUGLOG("FBSessionStateClosedLoginFailed: Facebook: Closing Session."); [self closeSession]; break; default: break; }}+ (void)closeSession{ [FBSession.activeSession closeAndClearTokenInformation]; [FBSession.activeSession close];// [FBSession setActiveSession:nil]; // This appeared to be causing the crash? V1.5 // Clear Facebook cookies NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"https://facebook.com/"]]; for (NSHTTPCookie* cookie in facebookCookies) [cookies deleteCookie:cookie];}// https://developers.facebook.com/docs/ios/user-data-ios-sdk/+ (void) getFacebookName{ [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) { if (!error) { m_name = user.name; } }];}+ (void)postImage:(NSString *)imageUrl message:(NSString *)message{ DEBUGLOG("postImage"); if ([[FBSession activeSession] isOpen]) { // we defer request for permission to post to the moment of post, then we check for the permission if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) { // if we don't already have the permission, then we request it now [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"] defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) { if (!error) { [self postWallImage:imageUrl message:message]; } else if (error.fberrorCategory != FBErrorCategoryUserCancelled) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied" message:@"Unable to get permission to post" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; } }]; } else { [self postWallImage:imageUrl message:message]; } } else { [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { [self sessionStateChanged:session state:status error:error]; if (!error) { if (FB_ISSESSIONOPENWITHSTATE(status)) { [self postWallImage:imageUrl message:message]; } } else { DEBUGLOG("Error opening Facebook Session: %s", [(NSString *)[error localizedDescription] UTF8String]); } }]; }}+ (void)postWallImage:(NSString *)imageUrl message:(NSString *)message{ DEBUGLOG("postDataWithPhoto"); // *** Example Data *** // photoID: 1387931298109844 // currentSource: https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-ash4/1384079_1387931298109844_1334380320_n.jpg // picture: https://fbcdn-photos-d-a.akamaihd.net/hphotos-ak-ash4/1384079_1387931298109844_1334380320_s.jpg // link: https://www.facebook.com/photo.php?fbid=1387931298109844&set=p.1387931298109844&type=1 NSMutableDictionary *params = [NSMutableDictionary dictionary]; [params setObject:message forKey:@"message"]; [params setObject:imageUrl forKey:@"picture"]; //[params setObject:link forKey:@"link"]; [params setObject:FACEBOOK_LINK_URL forKey:@"link"]; [params setObject:FACEBOOK_LINK_NAME forKey:@"name"]; [params setObject:FACEBOOK_LINK_CAPTION forKey:@"caption"]; [params setObject:FACEBOOK_LINK_DESCRIPTION forKey:@"description"]; //[params setObject:photoID forKey:@"object_attachment"]; [FBRequestConnection startForPostWithGraphPath:@"me/feed" graphObject:(id<FBGraphObject>)[NSDictionary dictionaryWithDictionary:params] completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { /* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Your update has been posted to Facebook!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; */ } else { DEBUGLOG("postWallImage: Error opening Facebook Session: %s", [(NSString *)[error localizedDescription] UTF8String]); /* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Facebook had an error." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; */ } }];}@endbool fbIsSessionOpen(){ return [FacebookPost isSessionOpen];}void fbOpenSession(){ [FacebookPost openSession];}void fbCloseSession(){ [FacebookPost closeSession];}