objc2-game-kit 0.3.2

Bindings to the GameKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkmatchmakingmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKMatchmakingMode(pub NSInteger);
impl GKMatchmakingMode {
    #[doc(alias = "GKMatchmakingModeDefault")]
    pub const Default: Self = Self(0);
    #[doc(alias = "GKMatchmakingModeNearbyOnly")]
    pub const NearbyOnly: Self = Self(1);
    #[doc(alias = "GKMatchmakingModeAutomatchOnly")]
    pub const AutomatchOnly: Self = Self(2);
    #[doc(alias = "GKMatchmakingModeInviteOnly")]
    pub const InviteOnly: Self = Self(3);
}

unsafe impl Encode for GKMatchmakingMode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GKMatchmakingMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkmatchmakerviewcontroller?language=objc)
    #[unsafe(super(NSViewController, NSResponder, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "objc2-app-kit")]
    #[cfg(target_os = "macos")]
    pub struct GKMatchmakerViewController;
);

#[cfg(all(feature = "GKDialogController", feature = "objc2-app-kit"))]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl GKViewController for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSCoding for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSEditor for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSObjectProtocol for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSSeguePerforming for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
extern_conformance!(
    unsafe impl NSUserInterfaceItemIdentification for GKMatchmakerViewController {}
);

#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
impl GKMatchmakerViewController {
    extern_methods!(
        #[unsafe(method(matchmakerDelegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn matchmakerDelegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn GKMatchmakerViewControllerDelegate>>>;

        /// Setter for [`matchmakerDelegate`][Self::matchmakerDelegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setMatchmakerDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMatchmakerDelegate(
            &self,
            matchmaker_delegate: Option<&ProtocolObject<dyn GKMatchmakerViewControllerDelegate>>,
        );

        #[cfg(feature = "GKMatchmaker")]
        #[unsafe(method(matchRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn matchRequest(&self) -> Retained<GKMatchRequest>;

        /// set to YES to receive hosted (eg. not peer-to-peer) match results. Will cause the controller to return an array of players instead of a match.
        #[unsafe(method(isHosted))]
        #[unsafe(method_family = none)]
        pub unsafe fn isHosted(&self) -> bool;

        /// Setter for [`isHosted`][Self::isHosted].
        #[unsafe(method(setHosted:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHosted(&self, hosted: bool);

        /// this controls which mode of matchmaking to support in the UI (all, nearby only, automatch only, invite only).  Throws an exeption if you can not set to the desired mode (due to restrictions)
        #[unsafe(method(matchmakingMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn matchmakingMode(&self) -> GKMatchmakingMode;

        /// Setter for [`matchmakingMode`][Self::matchmakingMode].
        #[unsafe(method(setMatchmakingMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMatchmakingMode(&self, matchmaking_mode: GKMatchmakingMode);

        /// A BOOL value to allow the GKMatchMakerViewController to return control to the game once the minimum number of players are connected.
        /// By default the value is NO, and the multiplayer match can only proceed after all players are connected.
        /// If the value is set to YES, then once the number of connected players is greater than or equal to minPlayers of the match request, matchmakerViewController:didFindMatch: will be called and the game can get the match instance, and update the game scene accordingly. The remaining players wil continue to connect.
        #[unsafe(method(canStartWithMinimumPlayers))]
        #[unsafe(method_family = none)]
        pub unsafe fn canStartWithMinimumPlayers(&self) -> bool;

        /// Setter for [`canStartWithMinimumPlayers`][Self::canStartWithMinimumPlayers].
        #[unsafe(method(setCanStartWithMinimumPlayers:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCanStartWithMinimumPlayers(&self, can_start_with_minimum_players: bool);

        #[cfg(feature = "GKMatchmaker")]
        /// Initialize with a matchmaking request, allowing the user to send invites and/or start matchmaking
        #[unsafe(method(initWithMatchRequest:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithMatchRequest(
            this: Allocated<Self>,
            request: &GKMatchRequest,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "GKMatchmaker")]
        /// Initialize with an accepted invite, allowing the user to see the status of other invited players and get notified when the game starts
        #[unsafe(method(initWithInvite:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithInvite(
            this: Allocated<Self>,
            invite: &GKInvite,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "GKMatch")]
        /// Add additional players (not currently connected) to an existing peer-to-peer match.
        /// Apps should elect a single device to do this, otherwise conflicts could arise resulting in unexpected connection errors.
        #[unsafe(method(addPlayersToMatch:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addPlayersToMatch(&self, r#match: &GKMatch);

        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
        #[unsafe(method(setHostedPlayer:didConnect:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHostedPlayer_didConnect(&self, player: &GKPlayer, connected: bool);

        /// deprecated, set the message on the match request instead
        #[deprecated = "No longer supported."]
        #[unsafe(method(defaultInvitationMessage))]
        #[unsafe(method_family = none)]
        pub unsafe fn defaultInvitationMessage(&self) -> Option<Retained<NSString>>;

        /// Setter for [`defaultInvitationMessage`][Self::defaultInvitationMessage].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[deprecated = "No longer supported."]
        #[unsafe(method(setDefaultInvitationMessage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDefaultInvitationMessage(
            &self,
            default_invitation_message: Option<&NSString>,
        );
    );
}

/// Methods declared on superclass `NSViewController`.
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
impl GKMatchmakerViewController {
    extern_methods!(
        #[unsafe(method(initWithNibName:bundle:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithNibName_bundle(
            this: Allocated<Self>,
            nib_name_or_nil: Option<&NSNibName>,
            nib_bundle_or_nil: Option<&NSBundle>,
        ) -> Retained<Self>;

        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;
    );
}

/// Methods declared on superclass `NSResponder`.
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
impl GKMatchmakerViewController {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
impl GKMatchmakerViewController {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

/// Obsoleted.
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
impl GKMatchmakerViewController {
    extern_methods!(
        /// * This method is obsolete. It will never be invoked and its implementation does nothing**
        #[deprecated]
        #[unsafe(method(setHostedPlayer:connected:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHostedPlayer_connected(&self, player_id: &NSString, connected: bool);

        /// * This method is obsolete. It will never be invoked and its implementation does nothing**
        #[deprecated]
        #[unsafe(method(setHostedPlayerReady:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHostedPlayerReady(&self, player_id: &NSString);
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkmatchmakerviewcontrollerdelegate?language=objc)
    pub unsafe trait GKMatchmakerViewControllerDelegate: NSObjectProtocol {
        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        /// The user has cancelled matchmaking
        #[unsafe(method(matchmakerViewControllerWasCancelled:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewControllerWasCancelled(
            &self,
            view_controller: &GKMatchmakerViewController,
        );

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        /// Matchmaking has failed with an error
        #[unsafe(method(matchmakerViewController:didFailWithError:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_didFailWithError(
            &self,
            view_controller: &GKMatchmakerViewController,
            error: &NSError,
        );

        #[cfg(all(feature = "GKMatch", feature = "objc2-app-kit"))]
        #[cfg(target_os = "macos")]
        /// A peer-to-peer match has been found, the game should start
        #[optional]
        #[unsafe(method(matchmakerViewController:didFindMatch:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_didFindMatch(
            &self,
            view_controller: &GKMatchmakerViewController,
            r#match: &GKMatch,
        );

        #[cfg(all(
            feature = "GKBasePlayer",
            feature = "GKPlayer",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        /// Players have been found for a server-hosted game, the game should start
        #[optional]
        #[unsafe(method(matchmakerViewController:didFindHostedPlayers:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_didFindHostedPlayers(
            &self,
            view_controller: &GKMatchmakerViewController,
            players: &NSArray<GKPlayer>,
        );

        #[cfg(all(
            feature = "GKBasePlayer",
            feature = "GKPlayer",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        /// An invited player has accepted a hosted invite.  Apps should connect through the hosting server and then update the player's connected state (using setConnected:forHostedPlayer:)
        #[optional]
        #[unsafe(method(matchmakerViewController:hostedPlayerDidAccept:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_hostedPlayerDidAccept(
            &self,
            view_controller: &GKMatchmakerViewController,
            player: &GKPlayer,
        );

        #[cfg(all(
            feature = "GKBasePlayer",
            feature = "GKDefines",
            feature = "GKPlayer",
            feature = "block2",
            feature = "objc2-app-kit"
        ))]
        #[cfg(target_os = "macos")]
        /// The game should provide `GKMatchProperties` for the `GKPlayer` that has been invited.
        /// If implemented, this function must call `completionHandler`: failing to do so will hang matchmaking.
        #[optional]
        #[unsafe(method(matchmakerViewController:getMatchPropertiesForRecipient:withCompletionHandler:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_getMatchPropertiesForRecipient_withCompletionHandler(
            &self,
            view_controller: &GKMatchmakerViewController,
            recipient: &GKPlayer,
            completion_handler: &block2::DynBlock<dyn Fn(NonNull<GKMatchProperties>)>,
        );

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        /// * These protocol methods are obsoleted. They will never be invoked and their implementation does nothing**
        #[deprecated]
        #[optional]
        #[unsafe(method(matchmakerViewController:didFindPlayers:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_didFindPlayers(
            &self,
            view_controller: &GKMatchmakerViewController,
            player_i_ds: &NSArray<NSString>,
        );

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        #[deprecated]
        #[optional]
        #[unsafe(method(matchmakerViewController:didReceiveAcceptFromHostedPlayer:))]
        #[unsafe(method_family = none)]
        unsafe fn matchmakerViewController_didReceiveAcceptFromHostedPlayer(
            &self,
            view_controller: &GKMatchmakerViewController,
            player_id: &NSString,
        );
    }
);