godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

Add NSViewController to macOS platform code #6513

Open Valeryn4 opened 1 year ago

Valeryn4 commented 1 year ago

Describe the project you are working on

I'm trying to implement iCloud and GameCenter.

Godot does not provide an NSViewController. Because of this, the developer does not have access to the API. It is impossible to activate various controllers and monitor their life. We cannot use the full functionality of the billing, game center, control the operation of some windows (request Review).

Providing an NSViewController, just like UIViewController (in the iphone), will solve the problems.

Describe the problem or limitation you are having in your project

I need to provide an NSViewController for GameCenter. Otherwise, it will not work.

Example GameCenter Doc.

Before you can access any Game Center data and use GameKit features, you need to authenticate the local player to ensure the player signs in to Game Center on the device running your game. Set this property to a method that GameKit invokes during the authentication process. If viewController is nil, Game Center authenticates the player and the player can start your game. Otherwise, present the view controller so the player can perform any additional actions to complete authentication.

For more information about the authentication of the local player, see Authenticating a Player.

GKLocalPlayer *player = [GKLocalPlayer localPlayer];
 player.authenticateHandler = (^(NSViewController *controller, NSError *error) {
            NSViewController *root_controller = [[[NSApplication sharedApplication] keyWindow] contentViewController]; 
            if (controller) { 
                [root_controller presentViewControllerAsModalWindow:controller]; /// NEED CONTROLLER
            }

Describe the feature / enhancement and how it helps to overcome the problem or limitation

move NSView from NSWindow to NSViewController. add NSViewController to NSWindow.contentViewController

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

change from

    window_view = [[GodotContentView alloc] init];
    if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_14) {
        [window_view setWantsLayer:TRUE];
    }

    window_size.width = p_desired.width;
    window_size.height = p_desired.height;

    if (displayScale > 1.0) {
        [window_view setWantsBestResolutionOpenGLSurface:YES];
        //if (current_videomode.resizable)
        [window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    } else {
        [window_view setWantsBestResolutionOpenGLSurface:NO];
    }

    [window_object setColorSpace:[NSColorSpace sRGBColorSpace]];

    //[window_object setTitle:[NSString stringWithUTF8String:"GodotEnginies"]];
    [window_object setContentView:window_view];
    [window_object setDelegate:window_delegate];

to

    view = [[GodotContentView alloc] init]; // <<<<<<<
    if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_14) {
        [view setWantsLayer:TRUE];
    }

    window_size.width = p_desired.width;
    window_size.height = p_desired.height;

    if (displayScale > 1.0) {
        [window_view setWantsBestResolutionOpenGLSurface:YES];
        //if (current_videomode.resizable)
        [window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    } else {
        [view setWantsBestResolutionOpenGLSurface:NO];
    }

    [window_object setColorSpace:[NSColorSpace sRGBColorSpace]];

        view_controller = [[GodotViewController alloc] init]; // <<<<<<<<<<<<<<
    view_controller.view = view; // <<<<<<<<<<
    window_object.contentViewController = view_controller; // <<<<<
    [window_object setDelegate:window_delegate];

I don't program in Obj-C. But there is API preparation for the Game Center. That's the kind of decision that came to my mind. But perhaps there is a better approach.

If this enhancement will not be used often, can it be worked around with a few lines of script?

no

Is there a reason why this should be core and not an add-on in the asset library?

platform dependence

Calinou commented 1 year ago

cc @bruvzg