private static void SpawnHistoryWindow(UiWindow window, UiSpacer spacer, Action <Color> setColor)
        {
            var historyWindow = new UiWindow();

            historyWindow.Container.SetBackground(Constants.Backgrounds.Dark);
            historyWindow.ListenForEscape(true);

            var reverse = new List <Color>(_colorHistory);

            reverse.Reverse();

            SpawnColorWindowContent(window, historyWindow, spacer, setColor, SpawnHistoryWindow,
                                    color => { _colorHistory.Remove(color); }, reverse,
                                    ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.history"),
                                    ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.noHistory"), true);

            historyWindow.OnClose += () => {
                window.ListenForEscape(true);
                window.Show();
                window.StartUpdateCalls();
            };

            window.Hide();
            window.ListenForEscape(false);
            window.AddChildWindow(historyWindow);
            window.StopUpdateCalls();
            historyWindow.Show();
        }
        private static void SpawnAddToFavFromHistoryMenu(UiWindow window, UiSpacer spacer, Action <Color> setColor)
        {
            var favFolderMenu = new UiWindow();

            favFolderMenu.Container.SetBackground(Constants.Backgrounds.Dark);
            favFolderMenu.ListenForEscape(true);
            favFolderMenu.StopUpdateCalls();
            favFolderMenu.StartUpdateCalls();

            SpawnAddToFavFromHistoryMenuContent(window, favFolderMenu, spacer, setColor);

            favFolderMenu.OnClose += () => {
                window.ListenForEscape(true);
                window.Show();
                window.StartUpdateCalls();
            };

            window.Hide();
            window.ListenForEscape(false);
            window.AddChildWindow(favFolderMenu);
            window.StopUpdateCalls();
            favFolderMenu.Show();
        }
        private static void SpawnInputTextWindow(UiWindow window, UiSpacer spacer,
                                                 string labelText, string titleText, Func <string, bool> validationAndSuccess, string errorTitle, string errorMessage, Action onClose)
        {
            var textInputWindow = new UiWindow();

            textInputWindow.Container.SetBackground(Constants.Backgrounds.Dark);
            textInputWindow.ListenForEscape(true);

            textInputWindow.OnClose += () => {
                onClose();
            };

            var title = new UiTextBlock();

            title.SetColor(Color.Orange);
            title.SetFont(Constants.Fonts.MyFirstCrush36);
            title.SetString(titleText);
            textInputWindow.AddChild(title);
            textInputWindow.AddChild(spacer);

            var inputRow = new UiRow();

            textInputWindow.AddChild(inputRow);
            textInputWindow.AddChild(spacer);

            var label = new UiTextBlock();

            label.SetString(labelText);
            inputRow.AddChild(label);
            inputRow.AddChild(spacer);

            var input = new UiTextInput();

            input.SetBackgroundColor(new Color(237, 207, 154));
            input.SetTextColor(Color.Black);
            input.SetActiveTextColor(Color.Black);
            input.SetBackground(Constants.Backgrounds.TextInput);
            inputRow.AddChild(input);
            input.SetSize(300);
            input.SetLimit(25);

            var buttonRow = new UiRow();

            textInputWindow.AddChild(buttonRow);

            var createButton = new UiButton();

            buttonRow.AddChild(createButton);
            buttonRow.AddChild(spacer);
            var createText = new UiTextBlock();

            createText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.create"));
            createButton.AddChild(createText);

            createButton.OnClick += () => {
                if (validationAndSuccess(input.GetValue()))
                {
                    textInputWindow.Dispose();
                }
                else
                {
                    var errorWindow = new UiWindow();
                    errorWindow.Container.SetBackground(Constants.Backgrounds.Dark);

                    var errorTitleText = new UiTextBlock();
                    errorTitleText.SetColor(Color.Orange);
                    errorTitleText.SetFont(Constants.Fonts.MyFirstCrush36);
                    errorTitleText.SetString(errorTitle);
                    errorWindow.AddChild(errorTitleText);
                    errorWindow.AddChild(spacer);

                    var message = new UiTextBlock();
                    message.SetString(errorMessage);
                    message.SetColor(Color.Red);
                    errorWindow.AddChild(message);
                    errorWindow.AddChild(spacer);

                    var okButton = new UiButton();
                    var okText   = new UiTextBlock();
                    okText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.ok"));
                    okButton.AddChild(okText);
                    okButton.OnClick += () => {
                        textInputWindow.StartUpdateCalls();
                        errorWindow.Dispose();
                    };
                    errorWindow.AddChild(okButton);

                    textInputWindow.AddChildWindow(errorWindow);
                    textInputWindow.ListenForEscape(false);
                    textInputWindow.StopUpdateCalls();
                    errorWindow.ListenForEscape(true);

                    errorWindow.OnClose += () => {
                        textInputWindow.ListenForEscape(true);
                        textInputWindow.StartUpdateCalls();
                    };

                    errorWindow.Show();
                }
            };

            var cancelButton = new UiButton();

            buttonRow.AddChild(cancelButton);
            var cancelText = new UiTextBlock();

            cancelButton.AddChild(cancelText);
            cancelText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.cancel"));

            cancelButton.OnClick += () => {
                textInputWindow.Dispose();
            };

            window.Hide();
            window.ListenForEscape(false);
            window.AddChildWindow(textInputWindow);
            window.StopUpdateCalls();
            textInputWindow.Show();
        }
        private static UiElement SpawnFolderItem(UiWindow window, UiWindow parent, UiSpacer spacer, Action <Color> setColor, string folder, Func <string, bool> onClick, Action <UiWindow, UiSpacer, Action <Color> > renew)
        {
            var itemRow = new UiRow();

            var itemButton = new UiButton();

            itemRow.AddChild(itemButton);
            var itemText = new UiTextBlock();

            itemText.SetString(folder);
            itemButton.AddChild(itemText);
            itemRow.AddChild(spacer);
            itemButton.OnClick += () => {
                if (onClick(folder))
                {
                    parent.Dispose();
                }
            };

            var deleteButton = new UiButton();

            itemRow.AddChild(deleteButton);
            var deleteIcon = FoxUIHook.Instance.GetPicture("nimbusfox.ui.images.delete.text");

            deleteButton.AddChild(deleteIcon);
            deleteButton.OnClick += () => {
                var confirmWindow = new UiWindow();
                confirmWindow.Container.SetBackground(Constants.Backgrounds.Dark);
                parent.AddChildWindow(confirmWindow);

                var confirmTitle = new UiTextBlock();
                confirmWindow.AddChild(confirmTitle);
                confirmTitle.SetFont(Constants.Fonts.MyFirstCrush36);
                confirmTitle.SetColor(Color.Orange);
                confirmTitle.SetString(string.Format(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.deleteTitle"), folder));
                confirmWindow.AddChild(spacer);

                var confirmMessage = new UiTextBlock();
                confirmWindow.AddChild(confirmMessage);
                confirmMessage.SetString(string.Format(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.deleteMessage"), folder));
                confirmWindow.AddChild(spacer);

                var buttonRow = new UiRow();
                confirmWindow.AddChild(buttonRow);

                var confirmButton = new UiButton();
                buttonRow.AddChild(confirmButton);
                var confirmButtonText = new UiTextBlock();
                confirmButton.AddChild(confirmButtonText);
                confirmButtonText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.delete"));
                buttonRow.AddChild(spacer);
                confirmButton.OnClick += () => {
                    if (_favDir.FileExists(folder))
                    {
                        _favDir.DeleteFile(folder);
                    }
                    parent.Dispose();
                    renew(window, spacer, setColor);
                };

                confirmWindow.OnClose += () => {
                    parent.ListenForEscape(true);
                    parent.Show();
                    parent.StartUpdateCalls();
                };

                var cancelButton = new UiButton();
                buttonRow.AddChild(cancelButton);
                var cancelText = new UiTextBlock();
                cancelButton.AddChild(cancelText);
                cancelText.SetString(ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.cancel"));

                cancelButton.OnClick += () => { confirmWindow.Dispose(); };

                parent.Hide();
                parent.ListenForEscape(false);
                parent.StopUpdateCalls();
                confirmWindow.Show();
            };

            return(itemRow);
        }
        private static void SpawnFolderColorWindow(UiWindow window, UiSpacer spacer, Action <Color> setColor, string folder)
        {
            var historyWindow = new UiWindow();

            historyWindow.Container.SetBackground(Constants.Backgrounds.Dark);
            historyWindow.ListenForEscape(true);

            var colValues = new List <string>();

            if (_favDir.FileExists(folder))
            {
                colValues.AddRange(
                    File.ReadAllLines(
                        Path.Combine(_favDir.GetPath(Path.DirectorySeparatorChar), folder)));
            }

            var colors = new List <Color>();

            foreach (var color in colValues)
            {
                var parsedColor = color;
                if (color.Contains(" "))
                {
                    parsedColor = color.Replace(" ", "");
                }
                if (parsedColor.Length <= 6)
                {
                    var valid = true;
                    foreach (var ch in parsedColor)
                    {
                        switch (ch)
                        {
                        default:
                            valid = false;
                            break;

                        case 'a':
                        case 'A':
                        case 'b':
                        case 'B':
                        case 'c':
                        case 'C':
                        case 'd':
                        case 'D':
                        case 'e':
                        case 'E':
                        case 'f':
                        case 'F':
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                            break;
                        }
                    }

                    if (valid)
                    {
                        colors.Add(ColorMath.ParseString(parsedColor));
                    }
                }
            }

            SpawnColorWindowContent(window, historyWindow, spacer, setColor,
                                    (item1, item2, item3) => { SpawnFolderColorWindow(item1, item2, item3, folder); },
                                    color => {
                var values = new List <string>();
                if (_favDir.FileExists(folder))
                {
                    values.AddRange(
                        File.ReadAllLines(
                            Path.Combine(_favDir.GetPath(Path.DirectorySeparatorChar), folder)));
                }

                var toRemove = "";

                foreach (var val in values)
                {
                    try {
                        var co = ColorMath.ParseString(val);

                        if (co == color)
                        {
                            toRemove = val;
                            break;
                        }
                    } catch {
                        // ignore
                    }
                }

                if (values.Contains(toRemove))
                {
                    values.Remove(toRemove);
                }

                File.WriteAllLines(Path.Combine(_favDir.GetPath(Path.DirectorySeparatorChar), folder), values);
            }, colors, folder, ClientContext.LanguageDatabase.GetTranslationString("nimbusfox.foxcore.text.nocolors"));

            historyWindow.OnClose += () => {
                window.ListenForEscape(true);
                window.Show();
                window.StartUpdateCalls();
            };

            window.Hide();
            window.ListenForEscape(false);
            window.AddChildWindow(historyWindow);
            window.StopUpdateCalls();
            historyWindow.Show();
        }
 public void Hide()
 {
     _current.Hide();
     OnHide?.Invoke();
 }
Example #7
0
 internal void Complete()
 {
     _completed = true;
     _window.Hide();
 }