void DrawNewUISoundAndSearch(float width)
        {
            QUI.BeginHorizontal(width);
            {
                #region New UISound
                if (SearchPatternAnimBool.faded < 0.2f)
                {
                    if (QUI.GhostButton("New UISound", QColors.Color.Green, 100 * (1 - SearchPatternAnimBool.faded), 20, NewUISoundAnimBool.value) ||
                        DetectKeyCombo_Alt_N())
                    {
                        NewUISoundAnimBool.target = !NewUISoundAnimBool.target;
                        if (NewUISoundAnimBool.target)
                        {
                            NewUISoundName = "";
                            SearchPatternAnimBool.target = false;
                        }
                    }
                }

                if (NewUISoundAnimBool.target)
                {
                    SearchPatternAnimBool.target = false;
                    QUI.SetGUIBackgroundColor(QColors.GreenLight.Color);
                    QUI.SetNextControlName("NewUISoundName");
                    NewUISoundName = EditorGUILayout.TextField(NewUISoundName, GUILayout.Width((width - 149) * NewUISoundAnimBool.faded));
                    QUI.ResetColors();

                    if (!NewUISoundAnimBool.value && Event.current.type == EventType.Layout) //if NewUISoundAnimBool.target is true and NewUISoundAnimBool.value is false -> in transition -> select the text in the control
                    {
                        QUI.FocusControl("NewUISoundName");
                        QUI.FocusTextInControl("NewUISoundName");
                    }

                    if (QUI.ButtonOk() ||
                        (DetectKey_Return() && QUI.GetNameOfFocusedControl().Equals("NewUISoundName")))
                    {
                        if (NewUISoundName.IsNullOrEmpty())
                        {
                            EditorUtility.DisplayDialog("Info", "Cannot create an unnamed UISound. Try again.", "Ok");
                        }
                        else
                        {
                            if (DUIData.Instance.DatabaseUISounds.Contains(NewUISoundName))
                            {
                                EditorUtility.DisplayDialog("Info", "A UISound named '" + NewUISoundName + "' already exists in the database. Try again.", "Ok");
                            }
                            else
                            {
                                DUIData.Instance.DatabaseUISounds.CreateUISound(NewUISoundName, selectedUISoundsDatabaseFilter, null);
                                NewUISoundAnimBool.target = false;
                            }
                        }
                    }
                    QUI.Space(1);
                    if (QUI.ButtonCancel() ||
                        QUI.DetectKeyDown(Event.current, KeyCode.Escape))
                    {
                        NewUISoundName            = string.Empty;
                        NewUISoundAnimBool.target = false;
                    }
                }
                #endregion
                QUI.FlexibleSpace();
                #region Search
                if (SearchPatternAnimBool.value)
                {
                    NewUISoundAnimBool.target = false;
                    QUI.SetGUIBackgroundColor(QColors.OrangeLight.Color);
                    QUI.SetNextControlName("SearchPattern");
                    SearchPattern = EditorGUILayout.TextField(SearchPattern, GUILayout.Width((width - 104) * SearchPatternAnimBool.faded));
                    QUI.ResetColors();

                    if (SearchPatternAnimBool.target && Event.current.type == EventType.Layout) //if SearchPatternAnimBool.target is true and SearchPatternAnimBool.value is false -> in transition -> select the text in the control
                    {
                        QUI.FocusControl("SearchPattern");
                        QUI.FocusTextInControl("SearchPattern");
                    }
                }


                if (NewUISoundAnimBool.faded < 0.2f)
                {
                    if (QUI.GhostButton(SearchPatternAnimBool.value ? "Clear Search" : "Search", QColors.Color.Orange, 100 * (1 - NewUISoundAnimBool.faded), 20, SearchPatternAnimBool.value) ||
                        DetectKeyCombo_Alt_S() || //Toggle Search
                        (DetectKey_Escape() && SearchPatternAnimBool.target))   //Clear Search
                    {
                        SearchPatternAnimBool.target = !SearchPatternAnimBool.target;
                        if (SearchPatternAnimBool.target)
                        {
                            SearchPattern             = string.Empty;
                            NewUISoundAnimBool.target = false;
                        }
                    }
                }
                #endregion
            }
            QUI.EndHorizontal();
        }
        void DrawGameEventOptions(float width)
        {
            if (!triggerOnGameEvent.boolValue)
            {
                return;
            }

            buttonCategory.stringValue = DUI.UNCATEGORIZED_CATEGORY_NAME;
            buttonName.stringValue     = DUI.DEFAULT_BUTTON_NAME;

            QUI.BeginHorizontal(width);
            {
                if (dispatchAll.boolValue)                //if dispatchAll is enabled -> set game event to empty and disable the field
                {
                    gameEvent.stringValue = string.Empty; //set game event as an empty string
                    GUI.enabled           = false;        //disable gui
                }

                QLabel.text  = "Game Event";
                QLabel.style = Style.Text.Normal;
                QUI.BeginVertical(QLabel.x, QUI.SingleLineHeight);
                {
                    QUI.Label(QLabel);
                    QUI.Space(SPACE_2);
                }
                QUI.EndVertical();

                tempFloat = QLabel.x;          //save label width

                QLabel.text  = "dispatch all"; //create and calculate a new label
                QLabel.style = Style.Text.Normal;

                tempFloat += QLabel.x; //add the second label width
                tempFloat += 12;       //add the size of a toggle
                tempFloat += 8;        //add space (4 to left and 4 to right)
                tempFloat += 24;

                QUI.SetNextControlName("gameEvent");
                EditorGUILayout.DelayedTextField(gameEvent, GUIContent.none, GUILayout.Width(width - tempFloat));

                GUI.enabled = true; //enable gui in case it was disabled by dispatch all

                QUI.BeginChangeCheck();
                QUI.QToggle("dispatch all", dispatchAll);
                if (QUI.EndChangeCheck())
                {
                    if (triggerOnGameEvent.boolValue)
                    {
                        gameEvent.stringValue = dispatchAll.boolValue ? DUI.DISPATCH_ALL : string.Empty;
                        if (!dispatchAll.boolValue)
                        {
                            QUI.FocusTextInControl("gameEvent");
                        }
                    }
                    else if (triggerOnButtonClick.boolValue || triggerOnButtonDoubleClick.boolValue || triggerOnButtonLongClick.boolValue)
                    {
                        buttonName.stringValue = dispatchAll.boolValue ? DUI.DISPATCH_ALL : DUI.DEFAULT_BUTTON_NAME;
                        if (dispatchAll.boolValue)
                        {
                            buttonCategory.stringValue = DUI.UNCATEGORIZED_CATEGORY_NAME;
                        }
                        else
                        {
                            buttonCategory.stringValue = DUI.UNCATEGORIZED_CATEGORY_NAME;
                            buttonName.stringValue     = DUI.DEFAULT_BUTTON_NAME;
                            ValidateButtonCategoryAndButtonName();
                        }
                    }
                }
                QUI.FlexibleSpace();
            }
            QUI.EndHorizontal();

            infoMessage["SetGameEvent"].show.target = triggerOnGameEvent.boolValue && string.IsNullOrEmpty(gameEvent.stringValue) && !dispatchAll.boolValue;
            DrawInfoMessage("SetGameEvent", GlobalWidth);

            infoMessage["DispatchAllGameEvents"].show.target = dispatchAll.boolValue;
            DrawInfoMessage("DispatchAllGameEvents", width);
        }
        public void DrawDatabase(TargetDatabase databaseType, DUIData.Database database, float width)
        {
            DrawNewCategoryAndSearch(width, databaseType);

            QUI.Space(SPACE_16);

            if (database.categories.Count == 0)
            {
                DrawInfoMessage(InfoMessageName.AddCategoryToStart.ToString(), width);
                return;
            }

            DrawExpandCollapseButtons(width, databaseType);

            QUI.Space(SPACE_8);

            foreach (string categoryName in database.categoryNames)
            {
                if (categoryName.Equals(DUI.CUSTOM_NAME))
                {
                    continue;
                }

                QUI.BeginHorizontal(width);
                {
                    #region Button Bar
                    if (RenameCategoryAnimBool.target && RenameCategoryTargetCategoryName.Equals(categoryName))
                    {
                        QLabel.text  = "Rename category to";
                        QLabel.style = Style.Text.Normal;
                        QUI.Label(QLabel);
                        QUI.Space(SPACE_2);
                        QUI.SetNextControlName("RenameCategoryName");
                        RenameCategoryName = QUI.TextField(RenameCategoryName, width - QLabel.x - 46);
                        QUI.Space(1);
                        if (QUI.ButtonOk() ||
                            (DetectKey_Return() && QUI.GetNameOfFocusedControl().Equals("RenameCategoryName")))
                        {
                            RenameCategoryName = RenameCategoryName.Trim();
                            if (string.IsNullOrEmpty(RenameCategoryName))
                            {
                                QUI.DisplayDialog("Action Required",
                                                  "Please enter a new category name in order to cotinue.",
                                                  "Ok");
                            }
                            else if (database.categoryNames.Contains(RenameCategoryName))
                            {
                                QUI.DisplayDialog("Action Required",
                                                  "There is another category with the name '" + RenameCategoryName + "' already in the database." +
                                                  "\n\n" +
                                                  "Enter another category name.",
                                                  "Ok");
                            }
                            else
                            {
                                database.RenameCategory(categoryName, RenameCategoryName);
                                RenameCategoryName               = "";
                                RenameCategoryAnimBool.target    = false;
                                RenameCategoryTargetCategoryName = "";
                                break;
                            }
                        }
                        QUI.Space(1);
                        if (QUI.ButtonCancel() ||
                            QUI.DetectKeyDown(Event.current, KeyCode.Escape))
                        {
                            RenameCategoryName               = "";
                            RenameCategoryAnimBool.target    = false;
                            RenameCategoryTargetCategoryName = "";
                        }
                    }
                    else
                    {
                        if (QUI.GhostBar(categoryName, SearchPatternAnimBool.target ? QColors.Color.Orange : QColors.Color.Blue, database.GetCategory(categoryName).isExpanded, width - 70 * database.GetCategory(categoryName).isExpanded.faded *(1 - SearchPatternAnimBool.faded), BarHeight))
                        {
                            database.GetCategory(categoryName).isExpanded.target = !database.GetCategory(categoryName).isExpanded.target;
                        }

                        if (database.GetCategory(categoryName).isExpanded.faded > 0.7f && SearchPatternAnimBool.faded < 0.3f)
                        {
                            QUI.Space(1);

                            if (QUI.GhostButton("rename", QColors.Color.Gray, 52, BarHeight, database.GetCategory(categoryName).isExpanded.value))
                            {
                                if (QUI.DisplayDialog("Information",
                                                      "Note that after you rename this category, all the UI settings (and code references) that use the current category name, will not get automatically changed." +
                                                      "\n\n" +
                                                      "You are responsible to update your code and the UI settings.",
                                                      "Continue",
                                                      "Cancel"))
                                {
                                    RenameCategoryAnimBool.target    = true;
                                    RenameCategoryName               = categoryName;
                                    RenameCategoryTargetCategoryName = categoryName;
                                    QUI.FocusControl("RenameCategoryName");
                                    QUI.FocusTextInControl("RenameCategoryName");
                                }
                            }

                            QUI.Space(3);

                            if (QUI.ButtonCancel())
                            {
                                if (categoryName.Equals(DUI.UNCATEGORIZED_CATEGORY_NAME))
                                {
                                    QUI.DisplayDialog("Info",
                                                      "You cannot and should not try to delete the '" + categoryName + "' category.",
                                                      "Ok");
                                }
                                else if (QUI.DisplayDialog("Delete category?",
                                                           "Are you sure you want to delete the '" + categoryName + "'?",
                                                           "Yes",
                                                           "Cancel"))
                                {
                                    Undo.RecordObject(DUIData.Instance, "DeleteCategory");
                                    database.RemoveCategory(categoryName, true);
                                    QUI.EndHorizontal();
                                    break;
                                }
                            }
                        }
                    }
                    #endregion
                }
                QUI.EndHorizontal();
                if (QUI.BeginFadeGroup(database.GetCategory(categoryName).isExpanded.faded))
                {
                    DrawStringList(database.GetCategory(categoryName).itemNames, width, database.GetCategory(categoryName).isExpanded);
                    QUI.Space(SPACE_8 * database.GetCategory(categoryName).isExpanded.faded);
                }
                QUI.EndFadeGroup();
                QUI.Space(SPACE_2);
            }
        }