|
@@ -28,15 +28,16 @@
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|
|
|
|
-#ifdef GAME_CENTER_ENABLED
|
|
|
|
-
|
|
|
|
#include "game_center.h"
|
|
#include "game_center.h"
|
|
|
|
|
|
-#import "app_delegate.h"
|
|
|
|
-#import "view_controller.h"
|
|
|
|
|
|
+#import "game_center_delegate.h"
|
|
|
|
+#import "platform/iphone/app_delegate.h"
|
|
|
|
+#import "platform/iphone/view_controller.h"
|
|
|
|
+
|
|
#import <GameKit/GameKit.h>
|
|
#import <GameKit/GameKit.h>
|
|
|
|
|
|
GameCenter *GameCenter::instance = NULL;
|
|
GameCenter *GameCenter::instance = NULL;
|
|
|
|
+GodotGameCenterDelegate *gameCenterDelegate = nil;
|
|
|
|
|
|
void GameCenter::_bind_methods() {
|
|
void GameCenter::_bind_methods() {
|
|
ClassDB::bind_method(D_METHOD("authenticate"), &GameCenter::authenticate);
|
|
ClassDB::bind_method(D_METHOD("authenticate"), &GameCenter::authenticate);
|
|
@@ -64,7 +65,7 @@ Error GameCenter::authenticate() {
|
|
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
|
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
|
ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE);
|
|
ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE);
|
|
|
|
|
|
- ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
|
|
|
|
|
+ UIViewController *root_controller = [[UIApplication sharedApplication] delegate].window.rootViewController;
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
|
|
|
|
|
// This handler is called several times. First when the view needs to be shown, then again
|
|
// This handler is called several times. First when the view needs to be shown, then again
|
|
@@ -298,10 +299,10 @@ Error GameCenter::show_game_center(Variant p_params) {
|
|
GKGameCenterViewController *controller = [[GKGameCenterViewController alloc] init];
|
|
GKGameCenterViewController *controller = [[GKGameCenterViewController alloc] init];
|
|
ERR_FAIL_COND_V(!controller, FAILED);
|
|
ERR_FAIL_COND_V(!controller, FAILED);
|
|
|
|
|
|
- ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
|
|
|
|
|
+ UIViewController *root_controller = [[UIApplication sharedApplication] delegate].window.rootViewController;
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
|
|
|
|
|
- controller.gameCenterDelegate = root_controller;
|
|
|
|
|
|
+ controller.gameCenterDelegate = gameCenterDelegate;
|
|
controller.viewState = view_state;
|
|
controller.viewState = view_state;
|
|
if (view_state == GKGameCenterViewControllerStateLeaderboards) {
|
|
if (view_state == GKGameCenterViewControllerStateLeaderboards) {
|
|
controller.leaderboardIdentifier = nil;
|
|
controller.leaderboardIdentifier = nil;
|
|
@@ -373,8 +374,12 @@ GameCenter::GameCenter() {
|
|
ERR_FAIL_COND(instance != NULL);
|
|
ERR_FAIL_COND(instance != NULL);
|
|
instance = this;
|
|
instance = this;
|
|
authenticated = false;
|
|
authenticated = false;
|
|
-};
|
|
|
|
|
|
|
|
-GameCenter::~GameCenter(){};
|
|
|
|
|
|
+ gameCenterDelegate = [[GodotGameCenterDelegate alloc] init];
|
|
|
|
+};
|
|
|
|
|
|
-#endif
|
|
|
|
|
|
+GameCenter::~GameCenter() {
|
|
|
|
+ if (gameCenterDelegate) {
|
|
|
|
+ gameCenterDelegate = nil;
|
|
|
|
+ }
|
|
|
|
+}
|