void ValiateUIButtonNameAndCategory() { if (string.IsNullOrEmpty(buttonName.stringValue)) //buttonName is empty? -> reset button name to default { buttonName.stringValue = DUI.DEFAULT_BUTTON_NAME; } if (buttonCategory.stringValue != DUI.CUSTOM_NAME) { if (!DUI.UIButtonCategoryExists(buttonCategory.stringValue)) //category does not exist -> reset button category to default { EditorUtility.DisplayDialog("Information", "This button's category is set to '" + buttonCategory.stringValue + "', but this category was not found in the UIButtons Database.\nResetting this button's category to the default value (" + DUI.DEFAULT_CATEGORY_NAME + ").", "Ok"); buttonCategory.stringValue = DUI.DEFAULT_CATEGORY_NAME; } if (!DUI.UIButtonNameExists(buttonCategory.stringValue, buttonName.stringValue)) //button name does not exist in the set category -> change category to default & add the button name to the database { if (EditorUtility.DisplayDialog("Action Required", "This button's name is set to '" + buttonName.stringValue + "', but it was not found in the '" + buttonCategory.stringValue + "' category.\nDo you want to add the name to the set category?", "Yes", "No")) { DUI.AddUIButtonName(buttonCategory.stringValue, buttonName.stringValue); buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } else { EditorUtility.DisplayDialog("Information", "This button's category was reset to the default value (" + DUI.DEFAULT_CATEGORY_NAME + ").", "Ok"); buttonCategory.stringValue = DUI.DEFAULT_CATEGORY_NAME; if (!DUI.UIButtonNameExists(buttonCategory.stringValue, buttonName.stringValue)) { if (EditorUtility.DisplayDialog("Action Required", "This button's name is set to '" + buttonName.stringValue + "', but it was not found in the '" + buttonCategory.stringValue + "' category.\nDo you want to add the name to the set category?", "Yes", "No")) { DUI.AddUIButtonName(buttonCategory.stringValue, buttonName.stringValue); buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } else { EditorUtility.DisplayDialog("Information", "This button's name was reset to the default value (" + DUI.DEFAULT_BUTTON_NAME + ").", "Ok"); buttonName.stringValue = DUI.DEFAULT_BUTTON_NAME; buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } } else { buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } } } else { buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } } else { buttonNameIndex = DUI.GetUIButtonNames(DUI.DEFAULT_CATEGORY_NAME).IndexOf(DUI.DEFAULT_BUTTON_NAME); } buttonCategoryIndex = DUI.UIButtonCategories.IndexOf(buttonCategory.stringValue); }
void DrawButtonCategory() { QUI.BeginHorizontal(WIDTH_420); { QUI.Label("Button Category", DUIStyles.GetStyle(DUIStyles.TextStyle.LabelNormal), WIDTH_105); if (EditorApplication.isPlayingOrWillChangePlaymode) { QUI.Label(buttonCategory.stringValue, DUIStyles.GetStyle(DUIStyles.TextStyle.LabelNormalItalic)); } else { QUI.BeginChangeCheck(); { buttonCategoryIndex = EditorGUILayout.Popup(buttonCategoryIndex, DUI.UIButtonCategories.ToArray()); } if (QUI.EndChangeCheck()) { if (!DUI.UIButtonCategories[buttonCategoryIndex].Equals(DUI.CUSTOM_NAME)) //not custom name category? { if (DUI.UIButtonNameExists(DUI.UIButtonCategories[buttonCategoryIndex], buttonName.stringValue)) //does the new category have the button name? { buttonCategory.stringValue = DUI.UIButtonCategories[buttonCategoryIndex]; buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } else if (buttonName.stringValue.Equals(DUI.DEFAULT_BUTTON_NAME) && DUI.GetUIButtonNames(DUI.UIButtonCategories[buttonCategoryIndex]).Count > 0) //is the button name the default value? && is the new category not empty? -> set button name as the first value { buttonCategory.stringValue = DUI.UIButtonCategories[buttonCategoryIndex]; buttonName.stringValue = DUI.GetUIButtonNames(buttonCategory.stringValue)[0]; } else if (!buttonName.stringValue.Equals(DUI.DEFAULT_BUTTON_NAME) && !string.IsNullOrEmpty(buttonName.stringValue.Trim()) && EditorUtility.DisplayDialog("Action Required", "The '" + buttonName.stringValue + "' button name does not exist in the '" + DUI.UIButtonCategories[buttonCategoryIndex] + "' category database.\nDo you want to add it now?", "Yes", "No")) { DUI.AddUIButtonName(DUI.UIButtonCategories[buttonCategoryIndex], buttonName.stringValue); buttonCategory.stringValue = DUI.UIButtonCategories[buttonCategoryIndex]; buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } else if (DUI.GetUIButtonNames(DUI.UIButtonCategories[buttonCategoryIndex]).Count == 0) { if (EditorUtility.DisplayDialog("Information", "The '" + DUI.UIButtonCategories[buttonCategoryIndex] + "' category is empty.\n\nOpen the UIButtons Database and add some button names to it or delete it.\n\nThe button name and category will now be reset to the default values.", "Ok")) { buttonCategory.stringValue = DUI.DEFAULT_CATEGORY_NAME; buttonCategoryIndex = DUI.UIButtonCategories.IndexOf(buttonCategory.stringValue); buttonName.stringValue = DUI.DEFAULT_BUTTON_NAME; buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } } else { buttonCategory.stringValue = DUI.UIButtonCategories[buttonCategoryIndex]; buttonName.stringValue = DUI.GetUIButtonNames(buttonCategory.stringValue)[0]; buttonNameIndex = DUI.GetUIButtonNames(buttonCategory.stringValue).IndexOf(buttonName.stringValue); } } else { buttonCategory.stringValue = DUI.UIButtonCategories[buttonCategoryIndex]; } } } } QUI.EndHorizontal(); }