Ejemplo 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);
            }
        }
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation && activationType == ActivationType.AddedToHierarchy)
            {
                _downloadListTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First();

                _tabControl = CustomExtensions.CreateTextSegmentedControl(rectTransform, new Vector2(0f, -9f));
                _tabControl.SetTexts(new string[] { "Players", "Modifiers" });
                _tabControl.didSelectCellEvent += _tabControl_didSelectCellEvent;

                #region Modifiers tab

                _modifiersTab = new GameObject("ModifiersTab", typeof(RectTransform)).GetComponent <RectTransform>();
                _modifiersTab.SetParent(rectTransform, false);
                _modifiersTab.anchorMin        = new Vector2(0f, 0f);
                _modifiersTab.anchorMax        = new Vector2(1f, 1f);
                _modifiersTab.anchoredPosition = new Vector2(0f, 0f);
                _modifiersTab.sizeDelta        = new Vector2(0f, 0f);

                _modifiersPanel = Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifiersPanelController>().First(), rectTransform, false);
                _modifiersPanel.gameObject.SetActive(true);
                _modifiersPanel.transform.SetParent(_modifiersTab, false);
                (_modifiersPanel.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_modifiersPanel.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_modifiersPanel.transform as RectTransform).anchoredPosition = new Vector2(0f, -23f);
                (_modifiersPanel.transform as RectTransform).sizeDelta        = new Vector2(120f, -23f);

                _modifiersPanel.Init(GameplayModifiers.defaultModifiers);
                _modifiersPanel.Awake();

                var modifierToggles = _modifiersPanel.GetPrivateField <GameplayModifierToggle[]>("_gameplayModifierToggles");

                foreach (var item in modifierToggles)
                {
                    item.toggle.onValueChanged.AddListener((enabled) => { gameplayModifiersChanged?.Invoke(); });
                }

                _modifiersPanelBlocker = new GameObject("ModifiersPanelBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid"
                _modifiersPanelBlocker.SetParent(_modifiersTab, false);
                _modifiersPanelBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f);
                _modifiersPanelBlocker.anchorMin        = new Vector2(0f, 0f);
                _modifiersPanelBlocker.anchorMax        = new Vector2(1f, 0f);
                _modifiersPanelBlocker.pivot            = new Vector2(0.5f, 0f);
                _modifiersPanelBlocker.sizeDelta        = new Vector2(-10f, 62f);
                _modifiersPanelBlocker.anchoredPosition = new Vector2(0f, 0f);

                #endregion

                #region Players tab

                _playersTab = new GameObject("PlayersTab", typeof(RectTransform)).GetComponent <RectTransform>();
                _playersTab.SetParent(rectTransform, false);
                _playersTab.anchorMin        = new Vector2(0f, 0f);
                _playersTab.anchorMax        = new Vector2(1f, 1f);
                _playersTab.anchoredPosition = new Vector2(0f, 0f);
                _playersTab.sizeDelta        = new Vector2(0f, 0f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), _playersTab, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -18f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _playersTableView.PageScrollUp();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), _playersTab, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 6f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _playersTableView.PageScrollDown();
                });
                _pageDownButton.interactable = false;

                RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(_playersTab, false);
                container.anchorMin        = new Vector2(0.15f, 0.5f);
                container.anchorMax        = new Vector2(0.85f, 0.5f);
                container.sizeDelta        = new Vector2(0f, 49f);
                container.anchoredPosition = new Vector2(0f, -3f);

                _playersTableView = new GameObject("CustomTableView").AddComponent <TableView>();
                _playersTableView.gameObject.AddComponent <RectMask2D>();
                _playersTableView.transform.SetParent(container, false);

                _playersTableView.SetPrivateField("_isInitialized", false);
                _playersTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _playersTableView.Init();

                (_playersTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0f);
                (_playersTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 1f);
                (_playersTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 0f);
                (_playersTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

                ReflectionUtil.SetPrivateField(_playersTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_playersTableView, "_pageDownButton", _pageDownButton);

                _playersTableView.dataSource = this;
                #endregion

                _pingText           = this.CreateText("PING: 0", new Vector2(75f, 22.5f));
                _pingText.alignment = TextAlignmentOptions.Left;

                _tabControl_didSelectCellEvent(null, 0);
            }

            if (activationType == ActivationType.AddedToHierarchy)
            {
                SetGameplayModifiers(GameplayModifiers.defaultModifiers);
            }
        }
Ejemplo n.º 3
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (firstActivation && activationType == ActivationType.AddedToHierarchy)
            {
                _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>();
                _standardCharacteristic = _beatmapCharacteristics.First(x => x.characteristicName == "Standard");

                bool isHost = Client.Instance.isHost;

                _selectedSongCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform, false);
                (_selectedSongCell.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 7.5f);
                _selectedSongCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]);
                _selectedSongCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]);
                _selectedSongCell.SetPrivateField("_bought", true);
                foreach (var icon in _selectedSongCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
                {
                    Destroy(icon.gameObject);
                }

                _playersReadyText = BeatSaberUI.CreateText(rectTransform, "0/0 players ready", new Vector2(0f, 5f));
                _playersReadyText.rectTransform.anchorMin = new Vector2(0.5f, 0f);
                _playersReadyText.rectTransform.anchorMax = new Vector2(0.5f, 0f);
                _playersReadyText.alignment = TextAlignmentOptions.Center;
                _playersReadyText.fontSize  = 5.5f;

                _cancelButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                (_cancelButton.transform as RectTransform).anchoredPosition = new Vector2(-30f, -25f);
                (_cancelButton.transform as RectTransform).sizeDelta        = new Vector2(28f, 12f);
                _cancelButton.SetButtonText("CANCEL");
                _cancelButton.ToggleWordWrapping(false);
                _cancelButton.SetButtonTextSize(5.5f);
                _cancelButton.onClick.AddListener(delegate() { discardPressed?.Invoke(); });
                _cancelButton.gameObject.SetActive(isHost);

                _playButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton");
                (_playButton.transform as RectTransform).anchoredPosition = new Vector2(30f, -25f);
                (_playButton.transform as RectTransform).sizeDelta        = new Vector2(28f, 12f);
                _playButton.SetButtonText("PLAY");
                _playButton.ToggleWordWrapping(false);
                _playButton.SetButtonTextSize(5.5f);
                _playButton.onClick.AddListener(delegate() { playPressed?.Invoke(_selectedSong, selectedCharacteristic, selectedDifficulty); });
                _playButton.gameObject.SetActive(isHost);

                _characteristicControl = CustomExtensions.CreateTextSegmentedControl(rectTransform, new Vector2(0f, -6f), new Vector2(-30f, 7f));

                _characteristicControl.SetTexts(new string[] { "Standard", "No Arrows", "One Saber" });
                _characteristicControl.didSelectCellEvent += _characteristicControl_didSelectCellEvent;

                _characteristicControlBlocker = new GameObject("CharacteristicControlBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid"
                _characteristicControlBlocker.SetParent(rectTransform, false);
                _characteristicControlBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f);
                _characteristicControlBlocker.anchorMin        = new Vector2(0f, 1f);
                _characteristicControlBlocker.anchorMax        = new Vector2(1f, 1f);
                _characteristicControlBlocker.sizeDelta        = new Vector2(-30f, 7f);
                _characteristicControlBlocker.anchoredPosition = new Vector2(0f, -6f);

                _difficultyControl = CustomExtensions.CreateTextSegmentedControl(rectTransform, new Vector2(0f, -16f), new Vector2(-30f, 7f));

                _difficultyControl.SetTexts(new string[] { "Easy", "Normal", "Hard", "Expert", "Expert+" });
                _difficultyControl.didSelectCellEvent += _difficultyControl_didSelectCellEvent;

                _difficultyControlBlocker = new GameObject("DifficultyControlBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid"
                _difficultyControlBlocker.SetParent(rectTransform, false);
                _difficultyControlBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f);
                _difficultyControlBlocker.anchorMin        = new Vector2(0f, 1f);
                _difficultyControlBlocker.anchorMax        = new Vector2(1f, 1f);
                _difficultyControlBlocker.sizeDelta        = new Vector2(-30f, 7f);
                _difficultyControlBlocker.anchoredPosition = new Vector2(0f, -16f);

                _progressBarRect = new GameObject("ProgressBar", typeof(RectTransform)).GetComponent <RectTransform>();

                _progressBarRect.SetParent(rectTransform, false);
                _progressBarRect.anchorMin        = new Vector2(0.5f, 0.5f);
                _progressBarRect.anchorMax        = new Vector2(0.5f, 0.5f);
                _progressBarRect.anchoredPosition = new Vector2(0f, -7.5f);
                _progressBarRect.sizeDelta        = new Vector2(46f, 5f);

                _progressBackground = new GameObject("Background", typeof(RectTransform), typeof(UnityEngine.UI.Image)).GetComponent <UnityEngine.UI.Image>();
                _progressBackground.rectTransform.SetParent(_progressBarRect, false);
                _progressBackground.rectTransform.anchorMin        = new Vector2(0f, 0f);
                _progressBackground.rectTransform.anchorMax        = new Vector2(1f, 1f);
                _progressBackground.rectTransform.anchoredPosition = new Vector2(0f, 0f);
                _progressBackground.rectTransform.sizeDelta        = new Vector2(0f, 0f);

                _progressBackground.sprite   = Sprites.whitePixel;
                _progressBackground.material = Sprites.NoGlowMat;
                _progressBackground.color    = new Color(1f, 1f, 1f, 0.075f);

                _progressBarImage = new GameObject("ProgressImage", typeof(RectTransform), typeof(UnityEngine.UI.Image)).GetComponent <UnityEngine.UI.Image>();
                _progressBarImage.rectTransform.SetParent(_progressBarRect, false);
                _progressBarImage.rectTransform.anchorMin        = new Vector2(0f, 0f);
                _progressBarImage.rectTransform.anchorMax        = new Vector2(1f, 1f);
                _progressBarImage.rectTransform.anchoredPosition = new Vector2(0f, 0f);
                _progressBarImage.rectTransform.sizeDelta        = new Vector2(0f, 0f);

                _progressBarImage.sprite     = Sprites.whitePixel;
                _progressBarImage.material   = Sprites.NoGlowMat;
                _progressBarImage.type       = UnityEngine.UI.Image.Type.Filled;
                _progressBarImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal;
                _progressBarImage.fillAmount = 0.5f;

                _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(55f, -10f));
                _progressText.rectTransform.SetParent(_progressBarRect, true);
            }
            _playButton.interactable = false;
            _progressBarRect.gameObject.SetActive(false);
        }