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); }
private void SetupMainPanel() { panelMain = new BaseElement { Width = { Percent = 100 }, Height = { Pixels = -28, Percent = 100 }, Y = { Pixels = 28 } }; UIPanel panelLocations = new UIPanel { Width = { Percent = 100 }, Height = { Pixels = -48, Percent = 100 } }; panelMain.Add(panelLocations); gridLocations = new UIGrid <UITeleporterItem> { Width = { Pixels = -28, Percent = 100 }, Height = { Percent = 100 } }; panelLocations.Add(gridLocations); UpdateGrid(); gridLocations.scrollbar.Height = new StyleDimension { Percent = 100 }; gridLocations.scrollbar.X.Percent = 100; panelLocations.Add(gridLocations.scrollbar); UITextButton buttonDialOnce = new UITextButton(Language.GetText("Mods.Teleportation.UI.DialOnce")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, Y = { Percent = 100 } }; buttonDialOnce.OnClick += args => { if (SelectedTeleporter == null) { return; } if (SelectedTeleporter.Destination == Container) { SelectedTeleporter = null; } else { Container.Destination = SelectedTeleporter; Container.DialOnce = true; Net.SendTeleporterDestination(Container); } }; panelMain.Add(buttonDialOnce); UITextButton buttonDial = new UITextButton(Language.GetText("Mods.Teleportation.UI.Dial")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, Y = { Percent = 100 }, X = { Percent = 33 } }; buttonDial.OnClick += args => { if (SelectedTeleporter == null) { return; } if (SelectedTeleporter.Destination == Container) { SelectedTeleporter = null; } else { Container.Destination = SelectedTeleporter; Container.DialOnce = false; Net.SendTeleporterDestination(Container); } }; panelMain.Add(buttonDial); UITextButton buttonInterrupt = new UITextButton(Language.GetText("Mods.Teleportation.UI.Interrupt")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, X = { Percent = 50 }, Y = { Percent = 100 } }; buttonInterrupt.OnClick += args => { if (SelectedTeleporter != null) { SelectedTeleporter.Destination = null; } SelectedTeleporter = null; Container.Destination = null; Container.DialOnce = false; Net.SendTeleporterDestination(Container); }; panelMain.Add(buttonInterrupt); UIContainerSlot slotFuel = new UIContainerSlot(() => Container.Handler) { Width = { Pixels = -4, Percent = 25 }, X = { Percent = 100 }, Y = { Percent = 100 }, Padding = new Padding(0, 24, 24, 0), PreviewItem = new Item() }; slotFuel.PreviewItem.SetDefaults(ModContent.ItemType <FuelCell>()); panelMain.Add(slotFuel); }
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; * };*/ }
public RequesterModulePanel(RequesterModule module) : base(module) { Width.Pixels = 60 + (SlotSize + SlotMargin) * Columns - SlotMargin; Height.Pixels = 144 + (SlotSize + SlotMargin) * (Rows + 2) - SlotMargin * 2; X.Percent = Y.Percent = 50; UITextButton buttonClose = new UITextButton("X") { Width = { Pixels = 20 }, Height = { Pixels = 20 }, X = { Percent = 100 }, RenderPanel = false, Padding = new Padding(0) }; buttonClose.OnClick += args => { if (args.Button != MouseButton.Left) { return; } PanelUI.Instance.CloseUI(Container); }; Add(buttonClose); textQueue = new UIText("Queue") { Width = { Percent = 50 }, HorizontalAlignment = HorizontalAlignment.Left }; Add(textQueue); UIText textLabel = new UIText("Requester Module") { Width = { Percent = 100 }, HorizontalAlignment = HorizontalAlignment.Center }; Add(textLabel); UIPanel panel = new UIPanel { Y = { Pixels = 28 }, Width = { Percent = 100 }, Height = { Pixels = (SlotSize + SlotMargin) * Rows - SlotMargin }, BorderColor = Color.Transparent, BackgroundColor = Utility.ColorPanel_Selected * 0.75f }; Add(panel); gridSlots = new UIGrid <UIRequesterSlot>(Columns) { Width = { Percent = 100, Pixels = -26 }, Height = { Percent = 100 }, ItemMargin = SlotMargin }; gridSlots.SearchSelector += item => { if (string.IsNullOrWhiteSpace(search.Value)) { return(true); } string itemName = item.Item.HoverName.ToLower(); string searchName = search.Value.ToLower(); return(itemName.Contains(searchName)); }; panel.Add(gridSlots); gridSlots.scrollbar.X.Percent = 100; gridSlots.scrollbar.Y.Pixels = 0; gridSlots.scrollbar.Height.Percent = 100; panel.Add(gridSlots.scrollbar); UITextInput inputSearch = new UITextInput(ref search) { Y = { Pixels = 36 + (SlotSize + SlotMargin) * Rows - SlotMargin }, Width = { Percent = 100 }, Height = { Pixels = 40 }, RenderPanel = true, VerticalAlignment = VerticalAlignment.Center, HintText = "Search", Padding = new Padding(8) }; inputSearch.OnKeyPressed += args => { if (inputSearch.Focused && (args.Key == Keys.Enter || args.Key == Keys.Escape)) { args.Handled = true; inputSearch.Focused = false; } }; inputSearch.OnTextChange += () => gridSlots.Search(); Add(inputSearch); // requested items { UIText textRequestedItem = new UIText("Requested Items") { Width = { Pixels = (SlotSize + SlotMargin) * 10 - SlotMargin }, Margin = new Margin(8, 0, 0, 0), Y = { Pixels = 84 + (SlotSize + SlotMargin) * Rows - SlotMargin }, HorizontalAlignment = HorizontalAlignment.Center }; Add(textRequestedItem); panel = new UIPanel { Y = { Pixels = 112 + (SlotSize + SlotMargin) * Rows - SlotMargin }, Width = { Percent = 100 }, Height = { Pixels = 16 + (SlotSize + SlotMargin) * 2 - SlotMargin }, BorderColor = Color.Transparent, BackgroundColor = Utility.ColorPanel_Selected * 0.75f }; Add(panel); UIGrid <UIContainerSlot> gridOutout = new UIGrid <UIContainerSlot>(10) { Width = { Pixels = (SlotSize + SlotMargin) * 10 }, Height = { Percent = 100 }, ItemMargin = SlotMargin }; panel.Add(gridOutout); for (int i = 0; i < Container.Handler.Slots; i++) { UIContainerSlot slot = new UIContainerSlot(() => Container.Handler, i) { Width = { Pixels = SlotSize }, Height = { Pixels = SlotSize }, Padding = new Padding(2) }; gridOutout.Add(slot); } } // return items { UIText textReturnItems = new UIText("Return") { Width = { Pixels = (SlotSize + SlotMargin) * 3 - SlotMargin }, Margin = new Margin(0, 0, 8, 0), X = { Percent = 100 }, Y = { Pixels = 84 + (SlotSize + SlotMargin) * Rows - SlotMargin }, HorizontalAlignment = HorizontalAlignment.Center }; Add(textReturnItems); UIGrid <UIContainerSlot> gridInput = new UIGrid <UIContainerSlot>(3) { Width = { Pixels = (SlotSize + SlotMargin) * 3 - SlotMargin }, Height = { Percent = 100 }, X = { Percent = 100 }, ItemMargin = SlotMargin }; panel.Add(gridInput); for (int i = 0; i < Container.ReturnHandler.Slots; i++) { UIContainerSlot slot = new UIContainerSlot(() => Container.ReturnHandler, i) { Width = { Pixels = SlotSize }, Height = { Pixels = SlotSize }, Padding = new Padding(2) }; gridInput.Add(slot); } } UIButton buttonTransfer = new UIButton(ModContent.GetTexture("BaseLibrary/Textures/UI/QuickStack")) { Y = { Percent = 50 }, X = { Pixels = 6 + (SlotSize + SlotMargin) * 10 - SlotMargin }, Width = { Pixels = 20 }, Height = { Pixels = 20 }, HoverText = "Transfer items" }; buttonTransfer.OnClick += args => { for (int i = 0; i < Container.Handler.Slots; i++) { ref Item item = ref Container.Handler.GetItemInSlotByRef(i); Container.ReturnHandler.InsertItem(ref item); if (!item.IsAir) { break; } } Recipe.FindRecipes(); };
public UpgradeStationUI() { UIPanel panelMain = new UIPanel { Width = { Pixels = 1000 }, Height = { Pixels = 550 + 28 }, X = { Percent = 50 }, Y = { Percent = 50 }, Settings = { Draggable = true, DragZones = new List <DragZone> { new DragZone { Width = { Percent = 100 },Height = { Pixels = 28 } } } } }; Add(panelMain); panelMain.With(() => { UIText title = new UIText("Upgrade Station") { Height = { Pixels = 20 } }; panelMain.Add(title); UIText closeButton = new UIText("X") { Height = { Pixels = 20 }, Width = { Pixels = 20 }, X = { Percent = 100 } }; closeButton.OnClick += args => { args.Handled = true; Display = Display.None; }; closeButton.OnMouseEnter += args => closeButton.Settings.TextColor = Color.Red; closeButton.OnMouseLeave += args => closeButton.Settings.TextColor = Color.White; panelMain.Add(closeButton); UIPanel panelItems = new UIPanel { Width = { Pixels = 64 }, Height = { Percent = 100, Pixels = -28 }, Y = { Pixels = 28 }, Settings = { BorderColor = Color.Transparent, BackgroundColor = DrawingUtility.Colors.PanelSelected * 0.75f } }; panelMain.Add(panelItems); panelMain.With(() => { gridItems = new UIGrid <UIModularItem> { Width = { Percent = 100 }, Height = { Percent = 100 }, Settings = { MaxSelectedItems = 1 } }; panelItems.Add(gridItems); }); UIPanel panelModules = new UIPanel { Width = { Percent = 40, Pixels = -64 }, Height = { Percent = 100, Pixels = -28 }, X = { Pixels = 64 }, Y = { Pixels = 28 }, Settings = { BorderColor = Color.Transparent, BackgroundColor = DrawingUtility.Colors.PanelSelected * 0.75f } }; panelMain.Add(panelModules); panelModules.With(() => { UIPanel inputBG = new UIPanel { Width = { Percent = 100 }, Height = { Pixels = 36 }, Settings = { BorderColor = Color.Transparent } }; panelModules.Add(inputBG); UITextInput input = new UITextInput(ref search) { Width = { Percent = 100 }, Height = { Percent = 100 }, OnTextChange = () => gridModules.Search(), Settings = { HintText = "<Search>" } }; inputBG.Add(input); // todo: category buttons gridModules = new UIGrid <UIModule> { Width = { Percent = 100 }, Height = { Percent = 100, Pixels = -44 }, Y = { Pixels = 44 }, SearchSelector = item => string.IsNullOrWhiteSpace(search.Value) || TextUtility.Search(item.Module.DisplayName.Get().ToLower(), search.Value.ToLower()).Any() }; panelModules.Add(gridModules); }); UIPanel panelInfo = new UIPanel { Width = { Percent = 60 }, Height = { Percent = 100, Pixels = -28 }, X = { Percent = 100 }, Y = { Pixels = 28 }, Settings = { BorderColor = Color.Transparent, BackgroundColor = DrawingUtility.Colors.PanelSelected * 0.75f } }; panelMain.Add(panelInfo); panelInfo.With(() => { textModule = new UIText("") { Width = { Percent = 100 }, Height = { Pixels = 20 } }; panelInfo.Add(textModule); UIDivider divider = new UIDivider { Width = { Percent = 100 }, Y = { Pixels = 28 } }; panelInfo.Add(divider); textModuleDescription = new UIText("") { Width = { Percent = 100 }, Height = { Percent = 100 }, Y = { Pixels = 36 } }; panelInfo.Add(textModuleDescription); textRequirements = new UIText("") { Width = { Percent = 50 }, Height = { Pixels = 20 }, Y = { Pixels = 100 + 36 } }; panelInfo.Add(textRequirements); textIncompatible = new UIText("") { Width = { Percent = 50 }, Height = { Pixels = 20 }, X = { Percent = 100 }, Y = { Pixels = 100 + 36 } }; panelInfo.Add(textIncompatible); buttonInstall = new UITextButton("Install") { Width = { Percent = 50, Pixels = -4 }, Height = { Pixels = 30 }, Y = { Percent = 100 }, Settings = { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center } }; buttonInstall.OnClick += args => { args.Handled = true; if (selectedItem.CanInstall(selectedModule.Type)) { BaseModule clone = selectedModule.Clone(); clone.InternalInstall(selectedItem); gridModules.Children.OfType <UIModule>().FirstOrDefault(x => x.Module == selectedModule).Color = Color.LimeGreen; buttonInstall.Settings.Disabled = true; buttonUninstall.Settings.Disabled = false; } }; panelInfo.Add(buttonInstall); buttonUninstall = new UITextButton("Uninstall") { Width = { Percent = 50, Pixels = -4 }, Height = { Pixels = 30 }, X = { Percent = 100 }, Y = { Percent = 100 }, Settings = { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center } }; buttonUninstall.OnClick += args => { args.Handled = true; if (selectedItem.CanUninstall(selectedModule.Type)) { BaseModule clone = selectedItem.InstalledModules.First(x => x.Type == selectedModule.Type); clone.InternalRemove(selectedItem); gridModules.Children.OfType <UIModule>().FirstOrDefault(x => x.Module == selectedModule).Color = Color.Red; buttonInstall.Settings.Disabled = false; buttonUninstall.Settings.Disabled = true; } }; panelInfo.Add(buttonUninstall); }); }); }