public void NodeEditor_EndEdit(string nodeText) { CMInputCallbackInstaller.ClearDisabledActionMaps(new[] { typeof(CMInput.INodeEditorActions) }); try { if (!isEditing || !IsActive || SelectionController.SelectedObjects.Count != 1) { return; } JSONNode newNode = JSON.Parse(nodeText); //Parse JSON, and do some basic checks. if (string.IsNullOrEmpty(newNode.ToString())) //Damn you Jackz { throw new Exception("Invalid JSON!\n\nCheck to make sure the node is not empty."); } if (string.IsNullOrEmpty(newNode["_time"])) { throw new Exception("Invalid JSON!\n\nEvery object needs a \"_time\" value!"); } //From this point on, its the mappers fault for whatever shit happens from JSON. BeatmapObject original = BeatmapObject.GenerateCopy(editingContainer.objectData); editingContainer.objectData = Activator.CreateInstance(editingContainer.objectData.GetType(), new object[] { newNode }) as BeatmapObject; BeatmapActionContainer.AddAction(new NodeEditorUpdatedNodeAction(editingContainer, editingContainer.objectData, original)); UpdateAppearance(editingContainer); isEditing = false; } catch (Exception e) { PersistentUI.Instance.ShowDialogBox(e.Message, null, PersistentUI.DialogBoxPresetType.Ok); } }
public void SetParams(string message, Action <int> result, string[] buttonText, TMP_FontAsset[] buttonAsset) { if (IsEnabled) { throw new Exception("Dialog box is already enabled! Please wait until this Dialog Box has been disabled."); } CMInputCallbackInstaller.DisableActionMaps(typeof(CM_DialogBox), disabledActionMaps); UpdateGroup(true); CameraController.ClearCameraMovement(); // Ignore yes/no colours for the dark theme and just use the default (no-outline) font UIMessage.text = message; resultAction = result; for (int i = 0; i < buttonText.Length; i++) { SetupButton( i, buttonText[i], Settings.Instance.DarkTheme || buttonAsset == null ? defaultFont : buttonAsset[i], buttonText.Length > 3 ? 80 : 100 ); } // Make sure any extra buttons are hidden for (int i = buttonText.Length; i < TempButtons.Count + 1; i++) { SetupButton(i, null, null); } }
public void NodeEditor_StartEdit(string _) { if (IsActive) { CMInputCallbackInstaller.DisableActionMaps(actionMapsDisabled); CMInputCallbackInstaller.DisableActionMaps(new[] { typeof(CMInput.INodeEditorActions) }); } }
private IEnumerator CloseOptions() { yield return(StartCoroutine(Close(2, optionsCanvasGroup))); CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(OptionsController), typeof(CMInput).GetNestedTypes().Where(x => x.IsInterface)); IsActive = false; yield return(SceneManager.UnloadSceneAsync(SceneManager.GetSceneByName("04_Options"))); }
//Unsubscrbe from events here. private void OnDisable() { instance = null; input.Disable(); ClearAllEvents(); SceneManager.sceneLoaded -= SceneLoaded; Application.wantsToQuit -= WantsToQuit; }
public void SendResult(int buttonID) { CMInputCallbackInstaller.ClearDisabledActionMaps(disabledActionMaps); UpdateGroup(false); string res = (string.IsNullOrEmpty(InputField.text) || string.IsNullOrWhiteSpace(InputField.text)) ? "" : InputField.text; resultAction?.Invoke(buttonID == 0 ? res : null); }
// Subscribe to events here. private void OnEnable() { instance = this; input = new CMInput(); input.Enable(); InputInstance = input; SceneManager.sceneLoaded += SceneLoaded; Application.wantsToQuit += WantsToQuit; }
public void SendResult(int buttonID) { CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(CM_InputBox), disabledActionMaps); UpdateGroup(false); string res = string.IsNullOrWhiteSpace(InputField.text) ? "" : InputField.text; resultAction?.Invoke(buttonID == 0 ? res : null); resultAction = null; }
private void Start() { CMInputCallbackInstaller.PersistentObject(transform); LocalizationSettings.SelectedLocale = Locale.CreateLocale(Settings.Instance.Language); UpdateDSPBufferSize(); AudioListener.volume = Settings.Instance.Volume; centerDisplay.host = this; bottomDisplay.host = this; }
public static void ShowOptions(int loadGroup = 0) { if (IsActive) { return; } SceneManager.LoadScene("04_Options", LoadSceneMode.Additive); CMInputCallbackInstaller.DisableActionMaps(typeof(OptionsController), typeof(CMInput).GetNestedTypes().Where(x => x.IsInterface)); OptionsLoadedEvent?.Invoke(); IsActive = true; }
public void BrowseForImage() { var extensions = new[] { new ExtensionFilter("Image Files", "png", "jpg", "jpeg"), new ExtensionFilter("All Files", "*"), }; string songDir = BeatSaberSongContainer.Instance.song.directory; CMInputCallbackInstaller.DisableActionMaps(typeof(ContributorListItem), new[] { typeof(CMInput.IMenusExtendedActions) }); var paths = StandaloneFileBrowser.OpenFilePanel("Open File", songDir, extensions, false); StartCoroutine(ClearDisabledActionMaps()); if (paths.Length > 0) { DirectoryInfo directory = new DirectoryInfo(songDir); FileInfo file = new FileInfo(paths[0]); string fullDirectory = directory.FullName; string fullFile = file.FullName; #if UNITY_STANDALONE_WIN bool ignoreCase = true; #else bool ignoreCase = false; #endif if (!fullFile.StartsWith(fullDirectory, ignoreCase, CultureInfo.InvariantCulture)) { if (FileExistsAlready(songDir, file.Name)) { return; } PersistentUI.Instance.ShowDialogBox("SongEditMenu", "files.badpath", result => { if (FileExistsAlready(songDir, file.Name)) { return; } if (result == 0) { File.Copy(fullFile, Path.Combine(songDir, file.Name)); SetImageLocation(file.Name); } }, PersistentUI.DialogBoxPresetType.YesNo); } else { SetImageLocation(fullFile.Substring(fullDirectory.Length + 1)); } } }
public void SetParams(string message, Action <string> result, string defaultText = "") { if (IsEnabled) { throw new Exception("Input box is already enabled! Please wait until this Input Box has been disabled."); } CMInputCallbackInstaller.DisableActionMaps(disabledActionMaps); UpdateGroup(true); UIMessage.text = message; InputField.text = defaultText; resultAction = result; }
public void NodeEditor_EndEdit(string nodeText) { CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(NodeEditorController), new[] { typeof(CMInput.INodeEditorActions) }); CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(NodeEditorController), actionMapsDisabled); try { if (!isEditing || !IsActive) { return; } JSONNode newNode = JSON.Parse(nodeText); //Parse JSON, and do some basic checks. if (string.IsNullOrEmpty(newNode.ToString())) //Damn you Jackz { throw new Exception("Node cannot be empty."); } // Super sneaky clone, maybe not needed var dict = editingObjects.ToDictionary(it => it, it => it.ConvertToJSON().Clone()); ApplyJSON(editingNode.AsObject, newNode.AsObject, dict); var beatmapActions = dict.Select(entry => new BeatmapObjectModifiedAction( Activator.CreateInstance(entry.Key.GetType(), new object[] { entry.Value }) as BeatmapObject, entry.Key, entry.Key, $"Edited a {entry.Key.beatmapType} with Node Editor.", true) ).ToList(); BeatmapActionContainer.AddAction(new ActionCollectionAction(beatmapActions, true, true, $"Edited ({editingObjects.Count()}) objects with Node Editor."), true); UpdateJSON(); } catch (Exception e) { string message = e.Message; switch (e) { case JSONParseException jsonParse: // Error parsing input JSON; tell them what's wrong! message = jsonParse.ToUIFriendlyString(); break; case TargetInvocationException invocationException: // Error when converting JSON to an object; tell them what's wrong! message = invocationException.InnerException.Message; break; default: //Log the full error to the console Debug.LogError(e); break; } PersistentUI.Instance.ShowDialogBox(message, null, PersistentUI.DialogBoxPresetType.Ok); } }
public void OnReplaceBPMinExistingBPMChangeClick(InputAction.CallbackContext context) { if (context.performed && modifierPressed) { RaycastFirstObject(out containerToEdit); if (containerToEdit != null) { CMInputCallbackInstaller.DisableActionMaps(actionMapsDisabled); PersistentUI.Instance.ShowInputBox("Please enter the new BPM for this BPM change.", AttemptPlaceBPMChange, containerToEdit.bpmData._BPM.ToString()); } } }
public void NodeEditor_StartEdit(string content) { if (IsActive) { if (!CMInputCallbackInstaller.IsActionMapDisabled(actionMapsDisabled[0])) { CMInputCallbackInstaller.DisableActionMaps(typeof(NodeEditorController), new[] { typeof(CMInput.INodeEditorActions) }); CMInputCallbackInstaller.DisableActionMaps(typeof(NodeEditorController), actionMapsDisabled); } } oldInputText = content; oldCaretPosition = nodeEditorInputField.caretPosition; }
public void OnToggleNodeEditor(InputAction.CallbackContext context) { if (Settings.Instance.NodeEditor_UseKeybind && AdvancedSetting && context.performed && !PersistentUI.Instance.InputBox_IsEnabled) { StopAllCoroutines(); if (IsActive) { CMInputCallbackInstaller.ClearDisabledActionMaps(new[] { typeof(CMInput.INodeEditorActions) }); CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); } else { CMInputCallbackInstaller.DisableActionMaps(actionMapsDisabled); } StartCoroutine(UpdateGroup(!IsActive, transform as RectTransform)); } }
internal override void ApplyToMap() { if (objectContainerCollection.LoadedContainers.Count >= BPMChangesContainer.ShaderArrayMaxSize) { if (!PersistentUI.Instance.DialogBox_IsEnabled) { PersistentUI.Instance.ShowDialogBox( "Due to Unity shader restrictions, the maximum amount of BPM Changes you can have is " + (BPMChangesContainer.ShaderArrayMaxSize - 1) + ".", null, PersistentUI.DialogBoxPresetType.Ok); } return; } CMInputCallbackInstaller.DisableActionMaps(actionMapsDisabled); PersistentUI.Instance.ShowInputBox("Please enter the BPM for this new BPM change.", AttemptPlaceBPMChange, BeatSaberSongContainer.Instance.song.beatsPerMinute.ToString()); }
public void TogglePause() { IsPaused = !IsPaused; if (IsPaused) { CMInputCallbackInstaller.DisableActionMaps(typeof(PauseManager), disabledActionMaps); previousUIModeType = uiMode.selectedMode; uiMode.SetUIMode(UIModeType.NORMAL, false); foreach (LightsManager e in platform.gameObject.GetComponentsInChildren <LightsManager>()) { e.ChangeAlpha(0, 1, e.ControllingLights); } } else { CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(PauseManager), disabledActionMaps); uiMode.SetUIMode(previousUIModeType, false); } StartCoroutine(TransitionMenu()); }
private void AttemptPlaceBPMChange(string obj) { if (string.IsNullOrEmpty(obj) || string.IsNullOrWhiteSpace(obj)) { CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); return; } if (float.TryParse(obj, out float bpm)) { CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); queuedData._time = RoundedTime; queuedData._BPM = bpm; base.ApplyToMap(); } else { PersistentUI.Instance.ShowInputBox("Invalid number.\n\nPlease enter the BPM for this new BPM change.", AttemptPlaceBPMChange, BeatSaberSongContainer.Instance.song.beatsPerMinute.ToString()); } }
private void AttemptPlaceBPMChange(string obj) { if (string.IsNullOrEmpty(obj) || string.IsNullOrWhiteSpace(obj)) { CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); containerToEdit = null; return; } if (float.TryParse(obj, out float bpm)) { CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); containerToEdit.bpmData._BPM = bpm; containerToEdit.UpdateGridPosition(); containerToEdit = null; } else { PersistentUI.Instance.ShowInputBox("Invalid number.\n\nPlease enter the new BPM for this BPM change.", AttemptPlaceBPMChange, containerToEdit.bpmData._BPM.ToString()); } }
// Now your FPS no longer drops to like 30 or something when spamming keys public static bool WillReturnFromFunction(InputAction action) { if (!inputActionBlockMap.TryGetValue(action, out var blockingActions)) { return(false); } foreach (var otherAction in blockingActions) { if (CMInputCallbackInstaller.IsActionMapDisabled(otherAction.GetType())) { continue; } if (otherAction.controls.All(x => x.IsPressed() || x.IsActuated())) { return(true); } } return(false); }
public void SetParams(string message, Action <int> result, string button0Text = null, string button1Text = null, string button2Text = null, TMP_FontAsset button0Asset = null, TMP_FontAsset button1Asset = null, TMP_FontAsset button2Asset = null) { if (IsEnabled) { throw new Exception("Dialog box is already enabled! Please wait until this Dialog Box has been disabled."); } CMInputCallbackInstaller.DisableActionMaps(disabledActionMaps); UpdateGroup(true); UIMessage.text = message; resultAction = result; UIButtons[0].gameObject.SetActive(button0Text != null); UIButtons[1].gameObject.SetActive(button1Text != null); UIButtons[2].gameObject.SetActive(button2Text != null); UIButtons[0].GetComponentInChildren <TextMeshProUGUI>().text = button0Text ?? ""; UIButtons[1].GetComponentInChildren <TextMeshProUGUI>().text = button1Text ?? ""; UIButtons[2].GetComponentInChildren <TextMeshProUGUI>().text = button2Text ?? ""; UIButtons[0].GetComponentInChildren <TextMeshProUGUI>().font = button0Asset ?? defaultFont; UIButtons[1].GetComponentInChildren <TextMeshProUGUI>().font = button1Asset ?? defaultFont; UIButtons[2].GetComponentInChildren <TextMeshProUGUI>().font = button2Asset ?? defaultFont; }
public void OnToggleNodeEditor(InputAction.CallbackContext context) { if (nodeEditorInputField.isFocused) { return; } if (Settings.Instance.NodeEditor_UseKeybind && context.performed && !PersistentUI.Instance.InputBox_IsEnabled) { StopAllCoroutines(); if (IsActive) { CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(NodeEditorController), new[] { typeof(CMInput.INodeEditorActions) }); CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(NodeEditorController), actionMapsDisabled); BeatmapActionContainer.RemoveAllActionsOfType <NodeEditorTextChangedAction>(); } else { closeButton.gameObject.SetActive(true); CMInputCallbackInstaller.DisableActionMaps(typeof(NodeEditorController), actionMapsDisabled); } StartCoroutine(UpdateGroup(!IsActive, transform as RectTransform)); } }
public void BrowserForFile() { var exts = new[] { new ExtensionFilter(filetypeName, extensions), new ExtensionFilter("All Files", "*"), }; if (BeatSaberSongContainer.Instance.song is null || BeatSaberSongContainer.Instance.song.directory is null) { PersistentUI.Instance.ShowDialogBox("Cannot locate song directory. Did you forget to save your map?", null, PersistentUI.DialogBoxPresetType.Ok); OnUpdate(); return; } string songDir = BeatSaberSongContainer.Instance.song.directory; CMInputCallbackInstaller.DisableActionMaps(typeof(InputBoxFileValidator), new[] { typeof(CMInput.IMenusExtendedActions) }); var paths = StandaloneFileBrowser.OpenFilePanel("Open File", songDir, exts, false); StartCoroutine(ClearDisabledActionMaps()); if (paths.Length > 0) { DirectoryInfo directory = new DirectoryInfo(songDir); FileInfo file = new FileInfo(paths[0]); string fullDirectory = directory.FullName; string fullFile = file.FullName; #if UNITY_STANDALONE_WIN bool ignoreCase = true; #else bool ignoreCase = false; #endif if (!fullFile.StartsWith(fullDirectory, ignoreCase, CultureInfo.InvariantCulture)) { if (FileExistsAlready(songDir, file.Name)) { return; } PersistentUI.Instance.ShowDialogBox("SongEditMenu", "files.badpath", result => { if (FileExistsAlready(songDir, file.Name)) { return; } if (result == 0) { File.Copy(fullFile, Path.Combine(songDir, file.Name)); input.text = file.Name; OnUpdate(); } }, PersistentUI.DialogBoxPresetType.YesNo); } else { input.text = fullFile.Substring(fullDirectory.Length + 1); OnUpdate(); } } }
public void OnDeselect() { CMInputCallbackInstaller.ClearDisabledActionMaps(GetType(), typeof(CMInput).GetNestedTypes().Where(x => x.IsInterface)); }
private IEnumerator WaitToEnable() { yield return(new WaitForEndOfFrame()); CMInputCallbackInstaller.DisableActionMaps(GetType(), typeof(CMInput).GetNestedTypes().Where(x => x.IsInterface)); }
public void Close() { CMInputCallbackInstaller.ClearDisabledActionMaps(new[] { typeof(CMInput.INodeEditorActions) }); CMInputCallbackInstaller.ClearDisabledActionMaps(actionMapsDisabled); StartCoroutine(UpdateGroup(false, transform as RectTransform)); }
private IEnumerator ClearDisabledActionMaps() { yield return(new WaitForEndOfFrame()); CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(InputBoxFileValidator), new[] { typeof(CMInput.IMenusExtendedActions) }); }
public void SendResult(int buttonID) { CMInputCallbackInstaller.ClearDisabledActionMaps(disabledActionMaps); UpdateGroup(false); resultAction?.Invoke(buttonID); }
private IEnumerator ClearDisabledActionMaps() { yield return(new WaitForEndOfFrame()); CMInputCallbackInstaller.ClearDisabledActionMaps(typeof(ContributorListItem), new[] { typeof(CMInput.IMenusExtendedActions) }); }