public void SaveSettings(bool useDialoguePrompt = false) { if (useDialoguePrompt) { DialogResult result = KryptonMessageBox.Show("Do you want to store and save the current setting values?", "Save Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { _mySettings.Save(); } } else { _mySettings.Save(); } }
public MainWindow() { InitializeComponent(); logger = LogManager.GetLogger("GUI"); CloseCommand = new RelayCommand(_ => { logger.Info("Shutdown"); if (DataContext is IDisposable dc) { dc.Dispose(); } CoreSettings.Save(); LogManager.Flush(); Close(); }); MinimizeCommand = new RelayCommand(_ => { WindowState = WindowState.Minimized; }); OpenSettingsCommand = new RelayCommand(_ => { new SettingsWindow().ShowDialog(); }); DataContext = new MainViewModel(); StateChanged += OnStateChanged; }
private void Options_FormClosed(object sender, FormClosedEventArgs e) { CoreSettings.Save(); new Task(() => { NLogConfig.ReloadFileLoggingRule(); gui.ResetGUI(); gui.DrawPackages(); }).Start(); }
public SettingsWindow() { InitializeComponent(); DataContext = new SettingsViewModel(); CloseCommand = new RelayCommand(_ => { CoreSettings.Save(); Close(); }); }
public static void DrawUI(CoreSettings coreSettings) { //serializedCoreSettings.Update(); EditorGUILayout.Space(); CreateHeader("SETTINGS", "1.0", "2018"); GUIStyle subtitleStyle = new GUIStyle { fontSize = 15, fontStyle = FontStyle.Bold }; coreSettings.UpdateFeaturesList(); DisplayList(coreSettings); EditorGUILayout.Space(); EditorGUILayout.Space(); #region Laser Pointer Settings laserPointer.target = coreSettings.UseLaserInteraction; laserPointer.target = EditorGUILayout.ToggleLeft(" Laser Pointer", laserPointer.target, subtitleStyle); coreSettings.UseLaserInteraction = laserPointer.target; //Extra block that can be toggled on and off. if (EditorGUILayout.BeginFadeGroup(laserPointer.faded)) { EditorGUI.indentLevel++; EditorGUILayout.Space(); coreSettings.LaserOnLeftHand = EditorGUILayout.Toggle( new GUIContent("Laser On Left Hand", "Check if you want the laser on the lef" + "t hand, otherwise it will be displayed on the right."), coreSettings.LaserOnLeftHand); coreSettings.LaserLenght = EditorGUILayout.FloatField( new GUIContent("Laser Lenght", "Laser Lenght in meters."), coreSettings.LaserLenght); coreSettings.LaserMaterial = (Material)EditorGUILayout.ObjectField( new GUIContent("Laser Material", "A material for the laser."), coreSettings.LaserMaterial, typeof(Material), true); coreSettings.LaserCollision = EditorGUILayout.MaskField( new GUIContent("Collision Layers", "Every layer selected here will collide with the laser."), coreSettings.LaserCollision, InternalEditorUtility.layers); coreSettings.LaserCollisionMaterial = (Material)EditorGUILayout.ObjectField( new GUIContent("Collision Material", "The material that will show on the collision sprite."), coreSettings.LaserCollisionMaterial, typeof(Material), true); coreSettings.LaserCollisionScale = EditorGUILayout.FloatField( new GUIContent("Collision Sprite Scale", "Scale of the laser collision sprite."), coreSettings.LaserCollisionScale); coreSettings.LaserCollisionSprite = (Sprite)EditorGUILayout.ObjectField( new GUIContent("Collision Sprite", "The sprite that will show once a " + "laser collides with anything"), coreSettings.LaserCollisionSprite, typeof(Sprite), true); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); #endregion EditorGUILayout.Space(); EditorGUILayout.Space(); #region Hint Settings hintAnimBool.target = coreSettings.UseDefaultHints; hintAnimBool.target = EditorGUILayout.ToggleLeft(" Default Hints", hintAnimBool.target, subtitleStyle); coreSettings.UseDefaultHints = hintAnimBool.target; if (EditorGUILayout.BeginFadeGroup(hintAnimBool.faded)) { EditorGUI.indentLevel++; EditorGUILayout.Space(); CreateHintSelectionDropdown(coreSettings); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); #endregion EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); #region Save Button Rect k = EditorGUILayout.BeginHorizontal("Button"); if (GUI.Button(k, GUIContent.none, skin.customStyles[0])) { coreSettings.Save(coreSettings); } EditorGUILayout.LabelField(new GUIContent("Save Changes", "This will save changes to disk."), Array.Find(skin.customStyles, element => element.name == ButtonLabelUIStyle)); EditorGUILayout.EndHorizontal(); #endregion }
private static void CreateHintSelectionDropdown(CoreSettings coreSettings) { int oldAmountOfButtons = 1; int amountOfButtons = oldAmountOfButtons; // No previous serialized settings setting or this was already serialized. // We only load from the serialized settings when the window is open. if (coreSettings.DefaultHintButtons.Count != 0 /*&& !hasInitialized*/) { oldAmountOfButtons = coreSettings.DefaultHintButtons.Count; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Amount of Hints")); amountOfButtons = EditorGUILayout.IntField(oldAmountOfButtons); EditorGUILayout.EndHorizontal(); bool changesWereMade = false; Button.ButtonName[] userSelectedButtons = new Button.ButtonName[coreSettings.DefaultHintButtons.Count]; string[] userSelectedContents = coreSettings.DefaultHintsContent.ToArray(); bool[] userSelectionIsRight = coreSettings.DefaultHintPositions.ToArray(); for (int i = 0; i < coreSettings.DefaultHintButtons.Count; i++) { userSelectedButtons[i] = HintConvert.ConvertToButtonName(coreSettings.DefaultHintButtons[i]); } // Initialize vectors that will hold the new selection by the user.. Button.ButtonName[] newUserSelection = new Button.ButtonName[amountOfButtons]; string[] newUserInputedContent = new string[amountOfButtons]; bool[] newUserSelectionIsRight = new bool[amountOfButtons]; // Expand or retract the vectors of selected options. if (amountOfButtons < userSelectedButtons.Length) { // Retract.. userSelectedButtons = userSelectedButtons.DescreaseArray(userSelectedButtons, userSelectedButtons.Length - amountOfButtons); userSelectedContents = userSelectedContents.DescreaseArray(userSelectedContents, userSelectedContents.Length - amountOfButtons); userSelectionIsRight = newUserSelectionIsRight.DescreaseArray(userSelectionIsRight, userSelectionIsRight.Length - amountOfButtons); } else if (amountOfButtons > userSelectedButtons.Length) { // Expand.. userSelectedButtons = userSelectedButtons.ExpandArray(userSelectedButtons, amountOfButtons - userSelectedButtons.Length); userSelectedContents = userSelectedContents.ExpandArray(userSelectedContents, amountOfButtons - userSelectedContents.Length); userSelectionIsRight = newUserSelectionIsRight.ExpandArray(userSelectionIsRight, amountOfButtons - userSelectionIsRight.Length); } // Now we set each dropdown.. for (int k = 0; k < amountOfButtons; k++) { // Get the available buttons for this platform.. Button.ButtonName[] controllerButtons; controllerButtons = SupportedPlatforms.GetButtons(CoreSettings.EditorSelectedPlatform); // Get the availble positions for this platform.. string[] positions = SupportedPlatforms.GetPositions(CoreSettings.EditorSelectedPlatform); // Create the labels that will be shown on the screen. GUIContent[] controllerLabels = new GUIContent[controllerButtons.Length]; GUIContent[] positionLabels = new GUIContent[positions.Length]; // Write all the info on the labels we just created. for (int i = 0; i < controllerButtons.Length; i++) { controllerLabels[i] = new GUIContent(); controllerLabels[i].text = controllerButtons[i].ToString(); } for (int i = 0; i < positions.Length; i++) { positionLabels[i] = new GUIContent(); positionLabels[i].text = positions[i]; } // Start writing on the screen. EditorGUILayout.BeginHorizontal(); // Write on the window int selectedPosition = 0; if (userSelectionIsRight[k]) { selectedPosition = EditorGUILayout.Popup(1, positionLabels); } else { selectedPosition = EditorGUILayout.Popup(0, positionLabels); } // This is the index on the controllerLabels array of the previously selected button. int selectedIndex = Array.FindIndex(controllerLabels, element => element.text.Equals(userSelectedButtons[k].ToString())); string inputedContent = ""; if (k < coreSettings.DefaultHintsContent.Count) { inputedContent = EditorGUILayout.TextField(coreSettings.DefaultHintsContent[k]); } // This is the newly inputed content. newUserInputedContent[k] = inputedContent; if (inputedContent == null) { continue; // We dont register inputs.. } // This is newly selected index by the user. We must transform it int a ControllerButtons to save it. int newlySelectedIndex = EditorGUILayout.Popup(selectedIndex, controllerLabels); newUserSelection[k] = (Button.ButtonName)Enum.Parse(typeof(Button.ButtonName), controllerLabels[newlySelectedIndex].text, true); if (positions[selectedPosition].Equals("Right")) { newUserSelectionIsRight[k] = true; } else { newUserSelectionIsRight[k] = false; } if (!(newUserSelection[k] == userSelectedButtons[k])) { changesWereMade = true; } if (!(newUserSelectionIsRight[k] == userSelectionIsRight[k])) { changesWereMade = true; } if (!(newUserInputedContent[k].Equals(userSelectedContents[k]))) { changesWereMade = true; } if (amountOfButtons != oldAmountOfButtons) { changesWereMade = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } // Check if there was changes if (changesWereMade) { coreSettings.DefaultHintButtons.Clear(); coreSettings.DefaultHintPositions.Clear(); coreSettings.DefaultHintsContent.Clear(); // If so update the inspector. for (int i = 0; i < newUserSelection.Length; i++) { coreSettings.DefaultHintButtons.Add(HintConvert.ConvertNames(newUserSelection[i], newUserSelectionIsRight[i])); coreSettings.DefaultHintPositions.Add(newUserSelectionIsRight[i]); coreSettings.DefaultHintsContent.Add(newUserInputedContent[i]); } // Serialize Changes! coreSettings.Save(coreSettings); } return; }