Esempio n. 1
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                _settingsSegments = CustomExtensions.CreateTextSegmentedControl(rectTransform, new Vector2(0f, -9f));

                _settingsSegments.SetTexts(new string[] { "General", "Voice" });
                _settingsSegments.didSelectCellEvent += SettingsCellSelected;

                #region General Settings
                int generalSettingsIndex = 0;

                var avatarsInGame = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Show Avatars In Game", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                avatarsInGame.ValueChanged += (value) => { Config.Instance.ShowAvatarsInGame = value; };
                avatarsInGame.Value         = Config.Instance.ShowAvatarsInGame;
                _generalSettings.Add(avatarsInGame.gameObject);

                var blocksInGame = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Show Other Players Blocks", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                blocksInGame.ValueChanged += (value) => { Config.Instance.ShowOtherPlayersBlocks = value; };
                blocksInGame.Value         = Config.Instance.ShowOtherPlayersBlocks;
                _generalSettings.Add(blocksInGame.gameObject);

                var avatarsInRoom = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Show Avatars In Room", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                avatarsInRoom.ValueChanged += (value) => { Config.Instance.ShowAvatarsInRoom = value; };
                avatarsInRoom.Value         = Config.Instance.ShowAvatarsInRoom;
                _generalSettings.Add(avatarsInRoom.gameObject);

                var downloadAvatars = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Download Other Players Avatars", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                downloadAvatars.ValueChanged += (value) => { Config.Instance.DownloadAvatars = value; };
                downloadAvatars.Value         = Config.Instance.DownloadAvatars;
                _generalSettings.Add(downloadAvatars.gameObject);

                var separateAvatar = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Separate Avatar For Multiplayer", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                separateAvatar.ValueChanged += (value) => { InGameOnlineController.Instance.SetSeparatePublicAvatarState(value); };
                separateAvatar.Value         = Config.Instance.SeparateAvatarForMultiplayer;
                _generalSettings.Add(separateAvatar.gameObject);

                _publicAvatarOption = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Public Avatar", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                _publicAvatarOption.OnEnable();
                _publicAvatarOption.ValueChanged += (e) => { InGameOnlineController.Instance.SetSeparatePublicAvatarHash(ModelSaberAPI.cachedAvatars.FirstOrDefault(x => x.Value == CustomAvatar.Plugin.Instance.AvatarLoader.Avatars[e]).Key); };
                _publicAvatarOption.maxValue      = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.Count - 1;
                _publicAvatarOption.textForValues = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.Select(x => (string.IsNullOrEmpty(x.Name) ? "" : x.Name)).ToArray();

                if (ModelSaberAPI.cachedAvatars.TryGetValue(Config.Instance.PublicAvatarHash, out CustomAvatar.CustomAvatar avatar))
                {
                    _publicAvatarOption.Value = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.ToList().IndexOf(avatar);
                }
                else
                {
                    if (ModelSaberAPI.isCalculatingHashes)
                    {
                        ModelSaberAPI.hashesCalculated -= UpdateSelectedAvatar;
                        ModelSaberAPI.hashesCalculated += UpdateSelectedAvatar;
                    }
                    _publicAvatarOption.Value = 0;
                }

                _publicAvatarOption.UpdateText();
                _generalSettings.Add(_publicAvatarOption.gameObject);

                var spectatorMode = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Spectator Mode", new Vector2(0f, 22.5f + -8f * generalSettingsIndex++));
                spectatorMode.Value         = Config.Instance.SpectatorMode;
                spectatorMode.ValueChanged += (value) => { Config.Instance.SpectatorMode = value; };
                _generalSettings.Add(spectatorMode.gameObject);

                #endregion

                #region Voice Settings
                int voiceSettingsIndex = 0;

                var voiceEnabled = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Enable Voice Chat", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                voiceEnabled.ValueChanged += (value) => { InGameOnlineController.Instance.ToggleVoiceChat(value); };
                voiceEnabled.Value         = Config.Instance.EnableVoiceChat;
                _voiceSettings.Add(voiceEnabled.gameObject);

                var voiceVolume = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Voice Chat Volume", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                voiceVolume.Value         = (int)(Config.Instance.VoiceChatVolume * 20f);
                voiceVolume.ValueChanged += delegate(int value) { Config.Instance.VoiceChatVolume = value / 20f; InGameOnlineController.Instance.VoiceChatVolumeChanged(value / 20f); };
                voiceVolume.maxValue      = 20;
                _voiceSettings.Add(voiceVolume.gameObject);

                var micEnabled = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Enable Microphone", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                micEnabled.Value         = Config.Instance.MicEnabled;
                micEnabled.ValueChanged += delegate(bool value) { Config.Instance.MicEnabled = value; };
                _voiceSettings.Add(micEnabled.gameObject);

                var spatialAudio = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Spatial Audio", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                spatialAudio.Value         = Config.Instance.SpatialAudio;
                spatialAudio.ValueChanged += delegate(bool value) { Config.Instance.SpatialAudio = value; InGameOnlineController.Instance.VoiceChatSpatialAudioChanged(value); };
                _voiceSettings.Add(spatialAudio.gameObject);

                var pushToTalk = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Push to Talk", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                pushToTalk.Value         = Config.Instance.PushToTalk;
                pushToTalk.ValueChanged += delegate(bool value) { Config.Instance.PushToTalk = value; };
                _voiceSettings.Add(pushToTalk.gameObject);

                var pushToTalkButton = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Push to Talk Button", new Vector2(0f, 22.5f + -8f * voiceSettingsIndex++));
                pushToTalkButton.OnEnable();
                pushToTalkButton.ValueChanged += (e) => { Config.Instance.PushToTalkButton = e; };
                pushToTalkButton.maxValue      = 7;
                pushToTalkButton.textForValues = new string[] { "L Grip", "R Grip", "L Trigger", "R Trigger", "L+R Grip", "L+R Trigger", "Any Grip", "Any Trigger" };
                pushToTalkButton.Value         = Config.Instance.PushToTalkButton;
                pushToTalkButton.UpdateText();
                _voiceSettings.Add(pushToTalkButton.gameObject);

                #endregion

                SettingsCellSelected(null, 0);
            }
        }
Esempio n. 2
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation)
            {
                _backButton = BeatSaberUI.CreateBackButton(rectTransform);
                _backButton.onClick.AddListener(delegate() { didFinishEvent?.Invoke(); });

                _nameKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _nameKeyboard.enterButtonPressed += NameEntered;
                _nameKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_nameKeyboard); };

                _passwordKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _passwordKeyboard.allowEmptyInput     = true;
                _passwordKeyboard.enterButtonPressed += PasswordEntered;
                _passwordKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_passwordKeyboard); };

                _presetNameKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _presetNameKeyboard.enterButtonPressed += PresetNameEntered;
                _presetNameKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_presetNameKeyboard); };

                _usePasswordToggle = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Use Password", new Vector2(0f, 11f));
                _usePasswordToggle.ValueChanged += UsePasswordToggle_ValueChanged;
                _usePasswordToggle.Value         = _usePassword;

                _songSelectionList = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Song Selection", new Vector2(0f, 3f));
                _songSelectionList.ValueChanged += SongSelection_ValueChanged;
                _songSelectionList.maxValue      = 1;
                _songSelectionList.Value         = (int)_songSelectionType;
                _songSelectionList.textForValues = new string[] { "Manual", "Random" };
                _songSelectionList.UpdateText();

                _maxPlayersList = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Max Players", new Vector2(0f, -5f));
                _maxPlayersList.ValueChanged += MaxPlayers_ValueChanged;
                _maxPlayersList.Value         = _maxPlayers;
                _maxPlayersList.maxValue      = 16;
                _maxPlayersList.textForValues = new string[] { "No limit" };
                _maxPlayersList.UpdateText();

                _resultsShowTimeList = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Results Show Time", new Vector2(0f, -13f));
                _resultsShowTimeList.ValueChanged += ResultsShowTime_ValueChanged;
                _resultsShowTimeList.minValue      = 5;
                _resultsShowTimeList.maxValue      = 45;
                _resultsShowTimeList.Value         = _resultsShowTime;

                _perPlayerDifficultyToggle = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Per player difficulty", new Vector2(0f, -21f));
                _perPlayerDifficultyToggle.ValueChanged += PerPlayerDifficultyToggle_ValueChanged;
                _perPlayerDifficultyToggle.Value         = _allowPerPlayerDifficulty;

                _roomName          = $"{GetUserInfo.GetUserName()}'s room".ToUpper();
                _nameText          = BeatSaberUI.CreateText(rectTransform, _roomName, new Vector2(-22.5f, 30f));
                _nameText.fontSize = 5f;

                _editNameButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton");
                _editNameButton.SetButtonText("EDIT NAME");
                (_editNameButton.transform as RectTransform).sizeDelta        = new Vector2(34f, 8f);
                (_editNameButton.transform as RectTransform).anchoredPosition = new Vector2(34f, 32f);
                _editNameButton.onClick.RemoveAllListeners();
                _editNameButton.onClick.AddListener(delegate()
                {
                    _nameKeyboard.inputString = _roomName;
                    presentKeyboardEvent?.Invoke(_nameKeyboard);
                });

                _roomPassword          = "";
                _passwordText          = BeatSaberUI.CreateText(rectTransform, "ENTER PASSWORD", new Vector2(-22.5f, 20f));
                _passwordText.fontSize = 5f;

                _editPasswordButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton");
                _editPasswordButton.SetButtonText("EDIT PASS");
                (_editPasswordButton.transform as RectTransform).sizeDelta        = new Vector2(34f, 8f);
                (_editPasswordButton.transform as RectTransform).anchoredPosition = new Vector2(34f, 22f);
                _editPasswordButton.onClick.RemoveAllListeners();
                _editPasswordButton.onClick.AddListener(delegate()
                {
                    _passwordKeyboard.inputString = _roomPassword;
                    presentKeyboardEvent?.Invoke(_passwordKeyboard);
                });

                _createRoomButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton");
                _createRoomButton.SetButtonText("Create Room");
                (_createRoomButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_createRoomButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -32.5f);
                _createRoomButton.onClick.RemoveAllListeners();
                _createRoomButton.onClick.AddListener(delegate() {
                    CreatedRoom?.Invoke(new RoomSettings()
                    {
                        Name = _roomName, UsePassword = _usePassword, Password = _roomPassword, PerPlayerDifficulty = _allowPerPlayerDifficulty, MaxPlayers = _maxPlayers, SelectionType = _songSelectionType, ResultsShowTime = _resultsShowTime
                    });
                });
                _createRoomButton.interactable = PluginUI.instance.roomCreationFlowCoordinator.CheckRequirements();

                _savePresetButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton");
                _savePresetButton.SetButtonText("Save Preset");
                (_savePresetButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_savePresetButton.transform as RectTransform).anchoredPosition = new Vector2(-32f, -32.5f);
                _savePresetButton.onClick.RemoveAllListeners();
                _savePresetButton.onClick.AddListener(delegate() {
                    _presetNameKeyboard.inputString = "NEW PRESET";
                    presentKeyboardEvent?.Invoke(_presetNameKeyboard);
                });

                _loadPresetButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton");
                _loadPresetButton.SetButtonText("Load Preset");
                (_loadPresetButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_loadPresetButton.transform as RectTransform).anchoredPosition = new Vector2(32f, -32.5f);
                _loadPresetButton.onClick.RemoveAllListeners();
                _loadPresetButton.onClick.AddListener(delegate() {
                    LoadPresetPressed?.Invoke();
                });
            }
            else
            {
                _songSelectionList.textForValues = new string[] { "Manual", "Random" };
                _songSelectionList.UpdateText();
                _maxPlayersList.textForValues = new string[] { "No limit" };
                _maxPlayersList.UpdateText();
                _createRoomButton.interactable = PluginUI.instance.roomCreationFlowCoordinator.CheckRequirements();
            }
        }
Esempio n. 3
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation && activationType == ActivationType.AddedToHierarchy)
            {
                _backButton = BeatSaberUI.CreateBackButton(rectTransform);
                _backButton.onClick.AddListener(delegate() { didFinishEvent?.Invoke(); });

                _nameKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _nameKeyboard.enterButtonPressed += NameEntered;
                _nameKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_nameKeyboard); };
                _passwordKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _passwordKeyboard.enterButtonPressed += PasswordEntered;
                _passwordKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_passwordKeyboard); };
                _presetNameKeyboard = BeatSaberUI.CreateViewController <CustomKeyboardViewController>();
                _presetNameKeyboard.enterButtonPressed += PresetNameEntered;
                _presetNameKeyboard.backButtonPressed  += () => { keyboardDidFinishEvent?.Invoke(_presetNameKeyboard); };

                _usePasswordToggle = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "Use Password");
                (_usePasswordToggle.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_usePasswordToggle.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_usePasswordToggle.transform as RectTransform).anchoredPosition = new Vector2(0f, 10f);
                _usePasswordToggle.ValueChanged += UsePasswordToggle_ValueChanged;
                _usePasswordToggle.Value         = _usePassword;

                _songSelectionList = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Song Selection");
                (_songSelectionList.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_songSelectionList.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_songSelectionList.transform as RectTransform).anchoredPosition = new Vector2(0f, 0f);
                _songSelectionList.ValueChanged += SongSelection_ValueChanged;
                _songSelectionList.maxValue      = 2;
                _songSelectionList.Value         = (int)_songSelectionType;
                _songSelectionList.textForValues = new string[] { "Manual", "Random", "Voting" };
                _songSelectionList.UpdateText();

                _maxPlayersList = CustomSettingsHelper.AddListSetting <MultiplayerListViewController>(rectTransform, "Max Players");
                (_maxPlayersList.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_maxPlayersList.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_maxPlayersList.transform as RectTransform).anchoredPosition = new Vector2(0f, -10f);
                _maxPlayersList.ValueChanged += MaxPlayers_ValueChanged;
                _maxPlayersList.Value         = _maxPlayers;
                _maxPlayersList.maxValue      = 16;

                _noFailToggle = CustomSettingsHelper.AddToggleSetting <OnOffViewController>(rectTransform, "No Fail Mode");
                (_noFailToggle.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_noFailToggle.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_noFailToggle.transform as RectTransform).anchoredPosition = new Vector2(0f, -20f);
                _noFailToggle.ValueChanged += NoFailToggle_ValueChanged;
                _noFailToggle.Value         = _noFailMode;

                _roomName          = $"{GetUserInfo.GetUserName()}'s room".ToUpper();
                _nameText          = BeatSaberUI.CreateText(rectTransform, _roomName, new Vector2(-22.5f, 25f));
                _nameText.fontSize = 5f;

                _editNameButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                _editNameButton.SetButtonText("EDIT NAME");
                (_editNameButton.transform as RectTransform).sizeDelta        = new Vector2(34f, 8f);
                (_editNameButton.transform as RectTransform).anchoredPosition = new Vector2(34f, 25f);
                _editNameButton.onClick.RemoveAllListeners();
                _editNameButton.onClick.AddListener(delegate()
                {
                    _nameKeyboard.inputString = _roomName;
                    PluginUI.instance.roomCreationFlowCoordinator.PresentKeyboard(_nameKeyboard);
                });

                _roomPassword          = "";
                _passwordText          = BeatSaberUI.CreateText(rectTransform, "ENTER PASSWORD", new Vector2(-22.5f, 15f));
                _passwordText.fontSize = 5f;

                _editPasswordButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                _editPasswordButton.SetButtonText("EDIT PASS");
                (_editPasswordButton.transform as RectTransform).sizeDelta        = new Vector2(34f, 8f);
                (_editPasswordButton.transform as RectTransform).anchoredPosition = new Vector2(34f, 15f);
                _editPasswordButton.onClick.RemoveAllListeners();
                _editPasswordButton.onClick.AddListener(delegate()
                {
                    _passwordKeyboard.inputString = _roomPassword;
                    PluginUI.instance.roomCreationFlowCoordinator.PresentKeyboard(_passwordKeyboard);
                });

                _createRoomButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                _createRoomButton.SetButtonText("Create Room");
                (_createRoomButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_createRoomButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -32.5f);
                _createRoomButton.onClick.RemoveAllListeners();
                _createRoomButton.onClick.AddListener(delegate() {
                    CreatedRoom?.Invoke(new RoomSettings()
                    {
                        Name = _roomName, UsePassword = _usePassword, Password = _roomPassword, NoFail = _noFailMode, MaxPlayers = _maxPlayers, SelectionType = _songSelectionType
                    });
                });
                _createRoomButton.interactable = PluginUI.instance.roomCreationFlowCoordinator.CheckRequirements();

                _savePresetButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                _savePresetButton.SetButtonText("Save Preset");
                (_savePresetButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_savePresetButton.transform as RectTransform).anchoredPosition = new Vector2(-32f, -32.5f);
                _savePresetButton.onClick.RemoveAllListeners();
                _savePresetButton.onClick.AddListener(delegate() {
                    _presetNameKeyboard.inputString = "NEW PRESET";
                    PluginUI.instance.roomCreationFlowCoordinator.PresentKeyboard(_presetNameKeyboard);
                });

                _loadPresetButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                _loadPresetButton.SetButtonText("Load Preset");
                (_loadPresetButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_loadPresetButton.transform as RectTransform).anchoredPosition = new Vector2(32f, -32.5f);
                _loadPresetButton.onClick.RemoveAllListeners();
                _loadPresetButton.onClick.AddListener(delegate() {
                    LoadPresetPressed?.Invoke();
                });
            }
            else
            {
                _songSelectionList.textForValues = new string[] { "Manual", "Random", "Voting" };
                _songSelectionList.UpdateText();
                _createRoomButton.interactable = PluginUI.instance.roomCreationFlowCoordinator.CheckRequirements();
            }
        }