Пример #1
0
        protected override void Construct()
        {
            Tuple <float, float> cpos = GetCenterOfParent();

            int width  = ((int)cpos.Item2 * 5 / 3);
            int height = 400;

            Width  = width;
            Height = height;

            Panel = new UIPanel(cpos.Item1 - width / 2, cpos.Item2 - height / 2, width, height,
                                hastitle: !string.IsNullOrEmpty(Title), title: Title, titlesize: TitleFontSize);
            Panel.LockFocus = true;

            UIAutoList tops = new UIAutoList(eUIOrientation.HORIZONTAL, width - 10, 40)
            {
                HasBorder      = false,
                HasOuterBorder = false,
                MarginX        = 0,
                MarginY        = 0,
            };

            Panel.AddAuto(tops);

            UIButton upbtn = new UIButton(0, 0, 50, 30, "Up");

            upbtn.EventFocused += (sender, args) =>
            {
                var eargs = args as UITextField.EventFocusedHandlerArgs;
                try
                {
                    DisplayFolder(Directory.GetParent(FolderText.Text).FullName, eargs.ElapsedMS, eargs.Input);
                }
                catch
                {
                    // just don't do anything
                }

                if (ParentSystem != null)
                {
                    ParentSystem.ProposedFocus = FileListPanel;
                }
            };
            tops.AddAuto(upbtn);

            FolderText = new UITextField(0, 0, width - 50 - 10, 30, DefaultFolderPath, fontsize: 12, autoheight: false);
            FolderText.EventEnterPressed += (sender, args) =>
            {
                var eargs = args as UITextField.EventEnterPressedHandlerArgs;
                DisplayFolder(FolderText.Text, eargs.ElapsedMS, eargs.Input);
            };
            tops.AddAuto(FolderText);

            FileListPanel = new UIPanel(0, 5, width - 10, height - 35 - 110, hasscrolling: true, scrollh: height - 30 - 110);
            Panel.AddAuto(FileListPanel);

            FileText = new UITextField(0, 5, width - 10, 30, DefaultFileName, fontsize: 12, autoheight: false);
            FileText.EventEnterPressed += (sender, args) =>
            {
                var eargs = args as UITextField.EventEnterPressedHandlerArgs;
                OKResult(eargs.ElapsedMS, eargs.Input);
            };
            if (Mode != eMode.SELECT_FOLDER)
            {
                Panel.AddAuto(FileText);
            }

            UIAutoList bottomButtons = new UIAutoList(eUIOrientation.HORIZONTAL, width - 10, 50)
            {
                LeftAlign      = true,
                HasBorder      = false,
                HasOuterBorder = false,
                MarginX        = 10,
                MarginY        = 5,
                y = 5,
            };

            Panel.AddAuto(bottomButtons);

            NewFolderButton = new UIButton(0, 5, 100, 35, "New Folder");
            bottomButtons.AddAuto(NewFolderButton);
            SelectButton = new UIButton(0, 5, 100, 35, SelectNames[Mode]);
            bottomButtons.AddAuto(SelectButton);
            CancelButton = new UIButton(0, 5, 100, 35, "Cancel");
            bottomButtons.AddAuto(CancelButton);

            NewFolderButton.EventFocused += (sender, e) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                DialogTextInput dialogTextInput           = new DialogTextInput("New Folder", "Name the new folder:", "", "Folder Name...");
                dialogTextInput.Popup(ParentSystem);

                dialogTextInput.EventClosedHandler += (innersender, innerargs) =>
                {
                    var innereargs = innerargs as DialogBase.EventClosedHandlerArgs;
                    // only process if OK was selected
                    if (dialogTextInput.Result)
                    {
                        string folderName = dialogTextInput.ResultText;
                        string folderPath = string.Empty;
                        bool   failed     = false;
                        // try to create this folder
                        try
                        {
                            folderPath = Path.Combine(FolderText.Text, folderName);
                            Directory.CreateDirectory(folderPath);
                        }
                        catch (Exception ex)
                        {
                            failed = true;
                            DialogPopup errorPopup = new DialogPopup("Failed to Create Folder", "Folder could not be created: " + ex.Message);
                            errorPopup.Popup(ParentSystem);
                        }

                        if (!failed)
                        {
                            DisplayFolder(folderPath, innereargs.ElapsedMS, innereargs.Input);
                        }
                    }
                };
            };
            SelectButton.EventFocused += (sender, e) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                OKResult(eargs.ElapsedMS, eargs.Input);
            };
            CancelButton.EventFocused += (sender, e) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                CancelResult(eargs.ElapsedMS, eargs.Input);
            };

            DisplayFolder(DefaultFolderPath, 0, null, skipinit: true);

            if (ParentSystem != null)
            {
                ParentSystem.ProposedFocus = FileListPanel;
            }
        }
Пример #2
0
        public ConsoleUI(UIBoss boss, UIStyle style, GraphicsDevice g, IConsole console,
                         int width, int height,
                         int logstoload = 30, string font = "NotoMono-Regular", int?fontsize = 16)
        {
            Boss = boss;

            Console  = console;
            UISystem = new UISystem(g);

            LogsToLoad = logstoload;
            int hperlog = 16;

            int innerHeight = (hperlog + 4) * LogsToLoad;

            LogList = new UIAutoList(eUIOrientation.VERTICAL, width - 16 - 4, innerHeight,
                                     fixedindexwidth: width - 16 - 4, fixedindexheight: hperlog, alternatesBackground: true);
            LogList.HasBorder      = false;
            LogList.HasOuterBorder = false;
            LogList.MarginY        = 2;


            for (int i = 0; i < LogsToLoad; i++)
            {
                UILabel lab = new UILabel(0, 0, width - 16, hperlog, "",
                                          font: font, fontsize: fontsize)
                {
                    TextOneLineOnly = true
                };
                Labels.Add(lab);
                LogList.AddAuto(lab);
            }



            LogPanel = new UIPanel(0, 0, width, height,
                                   true, "Console",
                                   hasscrolling: true, scrollh: innerHeight);
            LogPanel.AutoScrollHeight = true;
            LogPanel.AddAuto(LogList);

            LogPanel.Visible = false;

            ScrapLabel         = new UILabel(0, 0, width - 32, hperlog, "");
            ScrapLabel.Visible = false;
            LogPanel.Add(ScrapLabel);

            InputField = new UITextField(0, 0, width - 24, hperlog, "",
                                         font: font, fontsize: fontsize, placeholdertext: "Input...");
            InputField.EventEnterPressed += (sender, e) =>
            {
                string inputtext = InputField.Text;
                UITextField.EventEnterPressedHandlerArgs eargs = (e as UITextField.EventEnterPressedHandlerArgs);
                InputField.ClearText(eargs.ElapsedMS, eargs.Input);
                InputField.CaretPosition = 0;
                Console.Input(inputtext);
            };
            LogPanel.AddAuto(InputField);

            UISystem.Add(LogPanel);

            UISystem.Init(style);

            LogPanel.SnapScrollToBottom();

            /*UILabel firstLabel = (LogList.Components[0] as UILabel);
             * firstLabel.EventPostInit += (sender, args) =>
             * {
             *  MaxLength = (LogPanel.Width - 32) / firstLabel.FontSettings.MonospaceSize;
             * };*/
        }