コード例 #1
0
        public TestUI(UIStyle style, GraphicsDevice graphicsDevice)
        {
            UISystem = new UISystem(graphicsDevice);
            // panel 1
            UIPanel panel = new UIPanel(25, 25, 150, 150, hastitle: true, title: "Test Panel 1", titlesize: 16);

            UISystem.Add(panel);

            UILabel label1 = new UILabel(0, 0, panel.Width - 10, 10, "text goes here let's see if it will wrap automatically, which it should if everything is working properly.", fontsize: 12,
                                         font: "NotoSans_regular"); // test spritefont

            panel.AddAuto(label1);

            // panel 2
            UIPanel panel2 = new UIPanel(225, 25, 150, 150, hastitle: true, title: "Test Panel 2", titlesize: 16);

            UISystem.Add(panel2);

            UIButton button1 = new UIButton(5, 5, 75, 25, "Test Button");

            panel2.AddAuto(button1);

            UICheckbox chk1 = new UICheckbox(5, 40, 20, 20);

            panel2.Add(chk1);
            UILabel chk1label = new UILabel(30, 40, 100, 20, "unchecked");

            panel2.Add(chk1label);
            chk1.EventCheckChanged += (sender, args) =>
            {
                if (chk1.Checked)
                {
                    chk1label.Text = "checked";
                }
                else
                {
                    chk1label.Text = "unchecked";
                }
                chk1label.ProcessText();
            };


            // panel 3
            UIPanel panel3 = new UIPanel(425, 25, 150, 150, hastitle: true, title: "Test Panel 3", titlesize: 12);

            UISystem.Add(panel3);

            UITextField textfield1 = new UITextField(5, 5, 135, 25, "", fontsize: 16, placeholdertext: "Try Typing...");

            panel3.AddAuto(textfield1);

            UINumberField numfield1 = new UINumberField(5, 5, 135, 35, 40, "0", true, fontsize: 16);

            panel3.AddAuto(numfield1);

            UINumberField numfield2 = new UINumberField(5, 5, 135, 35, 40, "0.0", false, fontsize: 16);

            panel3.AddAuto(numfield2);

            // panel 4
            UIPanel panel4 = new UIPanel(625, 25, 150, 150, hastitle: true, title: "Test Panel 4", titlesize: 14);

            UISystem.Add(panel4);

            UILabel label2 = new UILabel(0, 0, panel4.Width - 10, 10, "text goes here let's see if it will wrap automatically, which it should if everything is working properly.", fontsize: 18);

            label2.TextSplitWords = true;
            panel4.AddAuto(label2);
            UILabel label3 = new UILabel(0, 10, panel4.Width - 10, 10, "A second auto-label. This gal should automatically get cut off when it goes too long", fontsize: 16);

            label3.TextSplitWords = true;
            panel4.AddAuto(label3);

            // panel 5
            UIPanel panel5 = new UIPanel(25, 200, 150, 150, true, "Dropdown Test");

            UISystem.Add(panel5);

            UIDropdown drop1 = new UIDropdown(0, 0, 80, 30, "droptest");

            drop1.AddItem("log A", (uid, args) => { drop1.Text = "AAAA"; drop1.ProcessText(); });
            drop1.AddItem("log B", (uid, args) => { drop1.Text = "BBBB"; drop1.ProcessText(); });
            panel5.AddAuto(drop1);

            // panel 6
            UIPanel panel6 = new UIPanel(200, 200, 150, 150, true, "Scroll Vert Test", hasscrolling: true, scrollh: 400);

            UISystem.Add(panel6);
            UILabel label4 = new UILabel(0, 10, panel6.Width - 20, 350, "newlines \n should be auto processed 1\n 2\n 3\n 4\n 5\n test the bottom \n test", fontsize: 16);

            panel6.AddAuto(label4);

            // panel 7
            UIPanel panel7 = new UIPanel(400, 200, 150, 150, true, "Scroll Horz Test", hasscrolling: true, scrollw: 400);

            UISystem.Add(panel7);
            UILabel label5 = new UILabel(0, 10, panel7.ScrollWidth - 10, 10, "a very long bit a text. It just goes on and on and doesn't end. A very long line that should be much smaller. But it's not, it's very large, instead.", fontsize: 18);

            panel7.AddAuto(label5);

            // panel 8
            UIPanel panel8 = new UIPanel(600, 200, 150, 150, true, "Dialogs Test");

            UISystem.Add(panel8);
            UIButton popupbtn = new UIButton(0, 0, 100, 30, "pop up");

            panel8.AddAuto(popupbtn);
            UIButton filebtn = new UIButton(0, 0, 100, 30, "open file");

            panel8.AddAuto(filebtn);

            popupbtn.EventFocused += (sender, args) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = args as UIComponent.EventFocusedHandlerArgs;
                DialogPopup popup = new DialogPopup("Popup", "time elapsed: " + eargs.ElapsedMS);
                popup.Popup(UISystem);
                popup.EventClosed += (innersender, innerargs) =>
                {
                    popup.Dispose();
                };
            };
            filebtn.EventFocused += (sender, args) =>
            {
                UIComponent.EventFocusedHandlerArgs eargs = args as UIComponent.EventFocusedHandlerArgs;
                DialogFile filepopup = new DialogFile(DialogFile.eMode.SELECT_FILE, ".\\", "file.txt", "Select a File");
                filepopup.Popup(UISystem);
                filepopup.EventClosed += (innersender, innerargs) =>
                {
                    filepopup.Dispose();
                };
            };

            // panel 9
            UIPanel panel9 = new UIPanel(100, 350, 220, 100);

            UISystem.Add(panel9);
            UITextField multiLineText = new UITextField(0, 0, 200, 80, "", autoheight: false, placeholdertext: "try typing multi lines", fontsize: 11)
            {
                MultiLine = true
            };

            multiLineText.SetTextStyler(new TextStylerTest());
            panel9.Add(multiLineText);

            // panel 10
            UIPanel panel10 = new UIPanel(20, 20, 400, 400, true, "RelaScript", titlesize: 12, hasclose: true);

            panel10.CloseButton.EventFocused += (sender, eargs) =>
            {
                panel10.Visible = false;
            };
            UISystem.Add(panel10);
            UITextField relaMultiText = new UITextField(5, 5, 380, 350, "", autoheight: false,
                                                        fontsize: 18, font: "NotoMono-Regular")
            {
                MultiLine = true
            };

            relaMultiText.EventPostInit += (sender, eargs) =>
            {
                relaMultiText.TextColor = new Microsoft.Xna.Framework.Color(218, 218, 218, 255);
            };
            relaMultiText.SetTextStyler(new TextStylerRelaScript());
            panel10.Add(relaMultiText);

            UISystem.Init(style);
        }
コード例 #2
0
        private void DisplayFolder(string folderPath, float elapsedms, InputManager input, bool skipinit = false)
        {
            // clear all items in the file list panel
            FileListPanel.RemoveAll();
            FileListPanel.ScrollCurrentY = 0;

            // find the given folder
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            if (!dir.Exists)
            {
                return;
            }

            SetFolderText(dir.FullName, elapsedms, input);

            List <DirectoryInfo> subdirs  = dir.EnumerateDirectories().ToList();
            List <FileInfo>      subfiles = dir.EnumerateFiles().ToList();

            int maxheight = subdirs.Count * 30 + subfiles.Count * 30 + 1;

            FileListPanel.ScrollHeight = maxheight;

            // find each folder in the given folderpath and display it in the file list
            foreach (var subdir in subdirs)
            {
                UIButton dirbtn = new UIButton(0, 0, FileListPanel.Width - 10, 30, "[ ] " + subdir.Name)
                {
                    Justified = eUIJustify.LEFT
                };
                dirbtn.EventPostInit += (sender, args) =>
                {
                    dirbtn.HasBorder = false;
                };
                dirbtn.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    DisplayFolder(subdir.FullName, eargs.ElapsedMS, eargs.Input);
                };
                FileListPanel.AddAuto(dirbtn);
                if (!skipinit)
                {
                    dirbtn.Init();
                }
            }

            // find each file in the given folderpath and dsiplay it in the file list
            foreach (var subfile in subfiles)
            {
                UIButton filebtn = new UIButton(0, 0, FileListPanel.Width - 10, 30, " # " + subfile.Name)
                {
                    Justified = eUIJustify.LEFT
                };
                filebtn.EventPostInit += (sender, args) =>
                {
                    filebtn.HasBorder           = false;
                    filebtn.HoverBackgroundOnly = true;
                };
                filebtn.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    SelectFile(subfile.Name, eargs.Input, eargs.ElapsedMS);
                };
                if (Mode == eMode.SELECT_FOLDER)
                {
                    filebtn.Enabled = false;
                }
                FileListPanel.AddAuto(filebtn);
                if (!skipinit)
                {
                    filebtn.Init();
                }
            }

            // call panel init again to properly space all the components
            if (!skipinit)
            {
                FileListPanel.Init();
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
0
        protected override void Construct()
        {
            Tuple <float, float> cpos = GetCenterOfParent();

            int width  = ((int)cpos.Item2 * 4 / 3);
            int height = 200;

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

            UILabel textlabel = new UILabel(10, 10, Panel.Width - 20, 110, Text, fontsize: TextFontSize);

            Panel.AddAuto(textlabel);

            UIPanel btnspanel = new UIPanel(0, 15, Panel.Width, 30)
            {
                HasBorder       = false,
                InnerMargin     = 0,
                AutoOrientation = eUIOrientation.HORIZONTAL,
            };

            Panel.AddAuto(btnspanel);

            switch (ButtonStyle)
            {
            case eDialogPopupButtons.OK:
            {
                UIButton btnok = new UIButton(Panel.Width - (Panel.Width / 4) - 10, 0, Panel.Width / 4, 30,
                                              "OK", fontsize: TitleFontSize);
                btnok.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    OKResult(eargs.ElapsedMS, eargs.Input);
                };
                btnspanel.AddAuto(btnok);
                break;
            }

            case eDialogPopupButtons.OK_CANCEL:
            {
                UIButton btncancel = new UIButton(10, 0, Panel.Width / 4, 30,
                                                  "Cancel", fontsize: TitleFontSize);
                btncancel.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    CancelResult(eargs.ElapsedMS, eargs.Input);
                };
                btnspanel.AddAuto(btncancel);
                UIButton btnok = new UIButton(Panel.Width - (Panel.Width / 2) - 10, 0, Panel.Width / 4, 30,
                                              "OK", fontsize: TitleFontSize);
                btnok.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    OKResult(eargs.ElapsedMS, eargs.Input);
                };
                btnspanel.AddAuto(btnok);
                break;
            }

            case eDialogPopupButtons.YES_NO:
            {
                UIButton btncancel = new UIButton(10, 0, Panel.Width / 4, 30,
                                                  "No", fontsize: TitleFontSize);
                btncancel.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    CancelResult(eargs.ElapsedMS, eargs.Input);
                };
                btnspanel.AddAuto(btncancel);
                UIButton btnok = new UIButton(Panel.Width - (Panel.Width / 2) - 10, 0, Panel.Width / 4, 30,
                                              "Yes", fontsize: TitleFontSize);
                btnok.EventFocused += (sender, e) =>
                {
                    UIComponent.EventFocusedHandlerArgs eargs = e as UIComponent.EventFocusedHandlerArgs;
                    OKResult(eargs.ElapsedMS, eargs.Input);
                };
                btnspanel.AddAuto(btnok);
                break;
            }

            default:
            {
                break;
            }
            }

            Panel.EventPostInit += (sender, args) =>
            {
                Panel.Height -= (110 - textlabel.Height);
            };
            // end construct
        }