Esempio n. 1
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                //Set up UI
                title          = "Room Screen";
                showBackButton = true;

                _playerDataModel             = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First();
                _menuLightsManager           = Resources.FindObjectsOfTypeAll <MenuLightsManager>().First();
                _soloFreePlayFlowCoordinator = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
                _campaignFlowCoordinator     = Resources.FindObjectsOfTypeAll <CampaignFlowCoordinator>().First();
                _resultsViewController       = Resources.FindObjectsOfTypeAll <ResultsViewController>().First();
                _scoreLights   = _soloFreePlayFlowCoordinator.GetField <MenuLightsPresetSO>("_resultsLightsPreset");
                _redLights     = _campaignFlowCoordinator.GetField <MenuLightsPresetSO>("_newObjectiveLightsPreset");
                _defaultLights = _soloFreePlayFlowCoordinator.GetField <MenuLightsPresetSO>("_defaultLightsPreset");

                _songSelection = BeatSaberUI.CreateViewController <SongSelection>();
                _songSelection.SongSelected += songSelection_SongSelected;

                _splashScreen = BeatSaberUI.CreateViewController <SplashScreen>();

                _songDetail              = BeatSaberUI.CreateViewController <SongDetail>();
                _songDetail.PlayPressed += songDetail_didPressPlayButtonEvent;
                _songDetail.DifficultyBeatmapChanged += songDetail_didChangeDifficultyBeatmapEvent;

                _playerList = BeatSaberUI.CreateViewController <PlayerList>();
            }
            if (activationType == ActivationType.AddedToHierarchy)
            {
                tournamentMode = Match == null;
                if (tournamentMode)
                {
                    _splashScreen.StatusText = $"Connecting to \"{Host.Name}\"...";
                    ProvideInitialViewControllers(_splashScreen);
                }
                else
                {
                    //If we're not in tournament mode, then a client connection has already been made
                    //by the room selection screen, so we can just assume Plugin.client isn't null
                    //NOTE: This is *such* a hack. Oh my god.
                    isHost = Match.Leader == Plugin.client.Self;
                    _songSelection.SetSongs(SongUtils.masterLevelList);
                    _playerList.Players      = Match.Players;
                    _splashScreen.StatusText = "Waiting for the host to select a song...";

                    if (isHost)
                    {
                        ProvideInitialViewControllers(_songSelection, _playerList);
                    }
                    else
                    {
                        ProvideInitialViewControllers(_splashScreen, _playerList);
                    }
                }
            }

            //The ancestor sets up the server event listeners
            //It would be possible to recieve an event that does a ui update after this call
            //and before the rest of the ui is set up, if we did this at the top.
            //So, we do it last
            base.DidActivate(firstActivation, activationType);
        }
Esempio n. 2
0
        private void SongFinished(StandardLevelScenesTransitionSetupDataSO standardLevelScenesTransitionSetupData, LevelCompletionResults results)
        {
            standardLevelScenesTransitionSetupData.didFinishEvent -= SongFinished;

            var map          = _communityLeaderboard.selectedSong.Beatmap;
            var localPlayer  = _playerDataModel.playerData;
            var localResults = localPlayer.GetPlayerLevelStatsData(map.level.levelID, map.difficulty, map.parentDifficultyBeatmapSet.beatmapCharacteristic);
            var highScore    = localResults.highScore < results.modifiedScore;

            var scoreLights   = _soloFreePlayFlowCoordinator.GetField <MenuLightsPresetSO>("_resultsLightsPreset");
            var redLights     = _campaignFlowCoordinator.GetField <MenuLightsPresetSO>("_newObjectiveLightsPreset");
            var defaultLights = _soloFreePlayFlowCoordinator.GetField <MenuLightsPresetSO>("_defaultLightsPreset");

            if (results.levelEndAction == LevelCompletionResults.LevelEndAction.Restart)
            {
                PlaySong(_communityLeaderboard.selectedSong);
            }
            else
            {
                if (results.levelEndStateType == LevelCompletionResults.LevelEndStateType.Cleared) //Didn't quit and didn't die
                {
                    //If bs_utils disables score submission, we do too
                    if (BSUtilsScoreDisabled())
                    {
                        return;
                    }

                    IBeatmapLevel level    = _communityLeaderboard.selectedSong.Beatmap.level;
                    string        songHash = SongUtils.GetHashFromLevelId(level.levelID);

                    //Community leaderboards
                    var    song   = _communityLeaderboard.selectedSong;
                    string signed = RSA.SignScore(Plugin.UserId, song.Hash, (int)_communityLeaderboard.selectedSong.Beatmap.difficulty, _communityLeaderboard.selectedSong.Characteristic, results.fullCombo, results.rawScore, (int)song.PlayerOptions, (int)song.GameOptions);

                    Action <bool> scoreUpdateComplete = (b) =>
                    {
                        Logger.Success($"Score upload {(b ? "compete" : "failed")}!");
                        if (b && _communityLeaderboard)
                        {
                            UnityMainThreadDispatcher.Instance().Enqueue(() =>
                            {
                                _communityLeaderboard.Refresh();
                            });
                        }
                    };
                    Client.SubmitScore(Plugin.UserId, song.Hash, (int)_communityLeaderboard.selectedSong.Beatmap.difficulty, _communityLeaderboard.selectedSong.Characteristic, results.fullCombo, results.rawScore, signed, (int)song.PlayerOptions, (int)song.GameOptions, scoreUpdateComplete);

                    Action <ResultsViewController> resultsContinuePressed = null;
                    resultsContinuePressed = (e) =>
                    {
                        _resultsViewController.continueButtonPressedEvent -= resultsContinuePressed;
                        _menuLightsManager.SetColorPreset(defaultLights, true);
                        DismissViewController(_resultsViewController);
                    };

                    _menuLightsManager.SetColorPreset(scoreLights, true);
                    _resultsViewController.Init(results, map, false, highScore);
                    _resultsViewController.continueButtonPressedEvent += resultsContinuePressed;
                    PresentViewController(_resultsViewController, null, true);
                }
            }
        }