private void CheckSpeciesNumber() { if (numSpecies > 0 && numSpecies < 6) { UserInterface.Active.Clear(); species = new List <Attributes>(); this.mainPanel = new Panel(new Vector2(Graphics.WINDOW_WIDTH / 2, Graphics.WINDOW_HEIGHT / 1.25f)); setupComplete = new Button("Finish"); errorMessage = new Header(""); //this.mainPanel = new Panel(); PanelTabs tabs = new PanelTabs(); this.mainPanel.AddChild(tabs); TabData tab; for (int i = 0; i < numSpecies; i++) { tab = tabs.AddTab("Organism " + (i + 1), PanelSkin.Golden); tab.panel.AddChild(new SetupSimulationPanel(tab.button.Size.Y)); } setupComplete.OnClick = (Entity button) => { TabData speciesTab; for (int i = 0; i < numSpecies; i++) { tabs.SelectTab("Organism " + (i + 1)); speciesTab = tabs.ActiveTab; Nullable <Attributes> starting; starting = ((SetupSimulationPanel)speciesTab.panel.Children.First()).GetPanelData(); if (starting.HasValue) { Attributes toReturn; toReturn = starting.GetValueOrDefault(); species.Add(toReturn); } } if (species.Count != numSpecies) { SetupFinished = false; species.Clear(); } else { SetupFinished = true; } }; UserInterface.Active.AddEntity(setupComplete); UserInterface.Active.AddEntity(mainPanel); UserInterface.Active.AddEntity(errorMessage); } }
public GameListMenu() : base("Join Game") { Size = new Vector2(800, 0); Open += (s, e) => { Lobby = new LobbyClient(); Lobby.UpdatedOnlineGameList += UpdateOnlineGameList; Lobby.UpdatedLocalGameList += UpdateLocalGameList; Lobby.StartLocalDiscovery(); }; Close += (s, e) => { Lobby?.Dispose(); Lobby = null; }; var panel = new Panel(new Vector2(0, -1), PanelSkin.None); var onlineTab = OnlineLocalTabs.AddTab("Online", PanelSkin.None); onlineTab.panel.AddChild(new Header("Join Online Game")); onlineTab.panel.AddChild(OnlineGameList); onlineTab.panel.AddChild(StatusLabel); JoinOnlineButton.OnClick += (e) => JoinSelectedGame(online: true); onlineTab.panel.AddChild(JoinOnlineButton); onlineTab.panel.AddChild(new Gui.BackButton()); var localTab = OnlineLocalTabs.AddTab("Local", PanelSkin.None); localTab.panel.AddChild(new Header("Join Local Game")); localTab.panel.AddChild(LocalGameList); JoinLocalButton.OnClick += (e) => JoinSelectedGame(online: false); localTab.panel.AddChild(JoinLocalButton); localTab.panel.AddChild(new Gui.BackButton()); panel.AddChild(OnlineLocalTabs); AddChild(panel); }
protected void LoadUIContent() { int screenHeight = GraphicsDevice.Viewport.Height; int screenWidth = GraphicsDevice.Viewport.Width; Panel background = new Panel(new Vector2(screenWidth, screenHeight)); background.Padding = new Vector2(10, 10); UserInterface.Active.AddEntity(background); Panel avatarPanel = new Panel(new Vector2(screenWidth / 3.5f, screenHeight / 2), anchor: Anchor.TopLeft, skin: PanelSkin.Simple); Header title = new Header("Sua Coisinha Verde"); avatarPanel.AddChild(title); avatarPanel.AddChild(new HorizontalLine()); background.AddChild(avatarPanel); Panel statusPanel = new Panel(new Vector2(screenWidth / 3.5f, screenHeight / 2), anchor: Anchor.BottomLeft, skin: PanelSkin.Simple); statusPanel.AddChild(new Header("Os paranaues")); statusPanel.AddChild(new HorizontalLine()); background.AddChild(statusPanel); PanelTabs skillTabs = new PanelTabs(); skillTabs.SetAnchor(Anchor.BottomRight); skillTabs.BackgroundSkin = PanelSkin.Simple; skillTabs.Size = new Vector2(screenWidth / 1.5f, screenHeight / 2); skillTabs.Offset = new Vector2(10, 10); background.AddChild(skillTabs); listTexts = new List <TabData>(); for (int i = 1; i <= 3; i++) { TabData tab = skillTabs.AddTab("Nivel " + i); tab.button.ToolTipText = "Habilidade so pode ser utilizada no nivel " + i; tab.button.Size = new Vector2(tab.button.Size.X, 50); Header skillHeader = new Header("", anchor: Anchor.TopLeft); skillHeader.Identifier = "HeaderText"; Paragraph skillText = new Paragraph(""); skillText.Identifier = "ParagraphText"; tab.panel.AddChild(skillHeader); tab.panel.AddChild(skillText); listTexts.Add(tab); } Button createGoblin = new Button("Recriar Goblin", anchor: Anchor.TopRight, offset: new Vector2(10, 10), size: new Vector2(screenWidth / 3, 50)); createGoblin.OnClick = (Entity btn) => { ResetGoblin(); }; background.AddChild(createGoblin); }
public override void LoadContent(JContent content) { MainPanel = new Panel(new Vector2(400, 320), PanelSkin.Simple, Anchor.BottomRight, new Vector2(10, 10)); MainPanel.Draggable = true; PanelTabs tabs = new PanelTabs(PanelSkin.None); MainPanel.AddChild(tabs); var threadTab = tabs.AddTab("Pathing"); threadTab.button.MaxSize = new Vector2(500, 32); var threadPanel = threadTab.panel; threadPanel.AddChild(new CheckBox("Draw Paths") { OnValueChange = (e) => { JEngine.Entities.DrawPathfindingDebug = (e as CheckBox).Checked; }, Checked = false }); threadPanel.AddChild(ThreadPendingLabel = new Label("Pending: 0")); threadPanel.AdjustHeightAutomatically = true; ThreadLabels = new Paragraph[JEngine.PathfindingThreadCount]; ThreadBars = new ProgressBar[JEngine.PathfindingThreadCount]; for (int i = 0; i < JEngine.PathfindingThreadCount; i++) { threadPanel.AddChild(ThreadLabels[i] = new Paragraph($"{i}: 0%, Avg: 0.0ms, Max: 0.0ms") { Padding = new Vector2(0, 0), Scale = 0.5f }); threadPanel.AddChild(ThreadBars[i] = new ProgressBar(0, 100) { Value = 40, Size = new Vector2(-1, 24), Padding = Vector2.Zero }); } UserInterface.Active.AddEntity(MainPanel); }
void LoadMainGame(Zombicide game) { //Initialize map map = new TiledSharp.TmxMap(@"Content/Tiled/Big Game Hunting.tmx"); mapPic = game.Content.Load <Texture2D>(@"Tiled/Big Game Hunting"); Highlight = game.Content.Load <Texture2D>(@"Highlight"); closedDoor = game.Content.Load <Texture2D>(@"ClosedDoor"); openDoor = game.Content.Load <Texture2D>(@"OpenDoor"); mapX = (game.GraphicsDevice.Viewport.Width / 2) - (mapWidth / 2); mapY = (game.GraphicsDevice.Viewport.Height / 2) - (mapHeight / 2); tilesHigh = Convert.ToInt32(map.Layers[0].Properties.Where(x => x.Key == "TilesHigh").FirstOrDefault().Value); tilesWide = Convert.ToInt32(map.Layers[0].Properties.Where(x => x.Key == "TilesWide").FirstOrDefault().Value); tileWidth = mapWidth / tilesWide; tileHeight = mapHeight / tilesHigh; litTiles = new List <Tile>(); doorTiles = new List <Tile>(); tileData = LoadTileData("BigGameHunting"); foreach (Tile T in tileData) { if (T.LeftSide == RoomSide.closeddoor || T.LeftSide == RoomSide.opendoor || T.TopSide == RoomSide.closeddoor || T.TopSide == RoomSide.opendoor) { doorTiles.Add(T); } } //Initialize random number generator RNG = new Random(); //Place reset map Button resetMapButton = game.Content.Load <Texture2D>(@"CenterMapButton"); resetMapX = 1200 - 54; resetMapY = game.GraphicsDevice.Viewport.Height - 54; //read in Start tile from map data and place player there var startTile = map.Layers[0].Properties.Where(x => x.Key == "StartTile").FirstOrDefault().Value.Split(','); game.ActiveCharacter.Move(startTile, true); //Load Zombie Spawns Zombie.SpawnTiles = map.Layers[0].Properties.Where(x => x.Key.StartsWith("SpawnZone")).Select(x => x.Value.Split(',').Select(y => Convert.ToInt32(y)).ToArray()).ToList(); //Load and initialize objectives Objective.ObjectiveTiles = map.Layers[0].Properties.Where(x => x.Key.StartsWith("Objective")).Select(x => x.Value.Split(',').Select(y => Convert.ToInt32(y)).ToArray()).ToList(); Objective.Initialize(game); //Initialize UI for Main game screen PanelTabs tabs = new PanelTabs(); PanelTabs RightTabs = new PanelTabs(); Panel movePanel = new Panel(new Vector2(400, 750), PanelSkin.Default, Anchor.TopRight, new Vector2(0, 50)); Panel playerPanel = new Panel(new Vector2(400, 750), PanelSkin.Default, Anchor.TopLeft, new Vector2(0, 50)); playerPanel.AddChild(tabs); movePanel.AddChild(RightTabs); TabData EquipmentTab = RightTabs.AddTab("Equipment"); Item MH = game.ActiveCharacter.MainHandSlot; MainHand = new Image(MH.Texture, new Vector2(MH.Size.X, MH.Size.Y), anchor: Anchor.TopLeft); MainHand.OutlineWidth = 3; var mainWeap = (Weapon)game.ActiveCharacter.MainHandSlot; MainHand.ToolTipText = "Damage: " + mainWeap.Damage + "\nDice: " + mainWeap.Dice + "\nHit Value: " + mainWeap.DiceThreshold + "\nRange: " + mainWeap.MinRange + "-" + mainWeap.MaxRange; MainHand.OnClick = (Entity pgh) => { game.ActiveCharacter.SetActiveWeapon("MAIN"); }; OffHand = new Image(Character.EmptyHand, new Vector2(MH.Size.X, MH.Size.Y), anchor: Anchor.TopRight); OffHand.OutlineWidth = 3; OffHand.OutlineColor = Color.White; OffHand.OnClick = (Entity pgh) => { if (game.ActiveCharacter.OffHandSlot != null) { game.ActiveCharacter.SetActiveWeapon("OFF"); } }; ArmorSlot = new Image(Character.EmptyArmor, new Vector2(MH.Size.X, MH.Size.Y), anchor: Anchor.AutoCenter, offset: new Vector2(0, 50)); ArmorSlot.OutlineWidth = 3; ArmorSlot.OutlineColor = Color.White; EquipmentTab.button.Padding = new Vector2(0, 0); EquipmentTab.button.Size = new Vector2(100, 50); EquipmentTab.button.Offset = new Vector2(0, -50); EquipmentTab.panel.Offset = new Vector2(0, -50); EquipmentTab.button.ButtonParagraph.Scale = .9f; EquipmentTab.panel.AddChild(MainHand); EquipmentTab.panel.AddChild(OffHand); EquipmentTab.panel.AddChild(ArmorSlot); TabData SkillTab = RightTabs.AddTab("Skills"); BlueSkill = new Paragraph(game.ActiveCharacter.BlueSkill.SkillName, Anchor.Auto, color: Color.DeepSkyBlue); YellowSkill = new Paragraph(game.ActiveCharacter.YellowSkill.SkillName, Anchor.Auto, color: Color.DarkGray); OrangeSkill1 = new Paragraph(game.ActiveCharacter.OrangeSkills.First().SkillName, Anchor.Auto, color: Color.DarkGray); OrangeSkill2 = new Paragraph(game.ActiveCharacter.OrangeSkills.Last().SkillName, Anchor.Auto, color: Color.DarkGray); RedSkill1 = new Paragraph(game.ActiveCharacter.RedSkills.First().SkillName, Anchor.Auto, color: Color.DarkGray); RedSkill2 = new Paragraph(game.ActiveCharacter.RedSkills.ElementAt(1).SkillName, Anchor.Auto, color: Color.DarkGray); RedSkill3 = new Paragraph(game.ActiveCharacter.RedSkills.Last().SkillName, Anchor.Auto, color: Color.DarkGray); SkillTab.panel.AddChild(BlueSkill); SkillTab.panel.AddChild(YellowSkill); SkillTab.panel.AddChild(OrangeSkill1); SkillTab.panel.AddChild(OrangeSkill2); SkillTab.panel.AddChild(RedSkill1); SkillTab.panel.AddChild(RedSkill2); SkillTab.panel.AddChild(RedSkill3); SkillTab.button.Padding = new Vector2(0, 0); SkillTab.button.Size = new Vector2(100, 50); SkillTab.panel.Offset = new Vector2(0, -50); SkillTab.button.ButtonParagraph.Scale = .9f; TabData tab1 = tabs.AddTab("Player"); life = new Paragraph("Life: " + (game.ActiveCharacter.DeathThreshold - game.ActiveCharacter.GetDamageTaken()).ToString()); moves = new Paragraph("Moves Left: " + (game.ActiveCharacter.movesLeft).ToString()); level = new Paragraph("Level: " + (game.ActiveCharacter.Level).ToString()); experience = new Paragraph("Experience: " + (game.ActiveCharacter.Experience).ToString()); forfeitMove = new Button("Forfeit Move", anchor: Anchor.BottomCenter); forfeitMove.OnClick = (Entity btn) => { game.ActiveCharacter.movesLeft--; }; tab1.button.Padding = new Vector2(0, 0); tab1.button.Size = new Vector2(100, 50); tab1.button.Offset = new Vector2(0, -50); tab1.panel.Offset = new Vector2(0, -50); tab1.panel.AddChild(new Header(game.ActiveCharacter.CharacterName)); tab1.panel.AddChild(new HorizontalLine()); tab1.panel.AddChild(life); tab1.panel.AddChild(moves); tab1.panel.AddChild(level); tab1.panel.AddChild(experience); tab1.panel.AddChild(forfeitMove); tab1.button.ButtonParagraph.Scale = .9f; BackPackTab = tabs.AddTab("Backpack"); BackPackTab.panel.AddChild(new Header("Items")); BackPackTab.button.Padding = new Vector2(0, 0); BackPackTab.button.Size = new Vector2(100, 50); BackPackTab.button.ButtonParagraph.Scale = .9f; TabData tab3 = tabs.AddTab("Team"); tab3.button.Padding = new Vector2(0, 0); tab3.button.Size = new Vector2(100, 50); tab3.button.ButtonParagraph.Scale = .9f; UserInterface.Active.AddEntity(playerPanel); UserInterface.Active.AddEntity(movePanel); whosTurn = MoveState.PlayerTurn; applyMoveTiles(game); //Initialize Dice and Zombies Zombie.Initialize(game); Dice.Initialize(game); }
/// <summary> /// Create the top bar with next / prev buttons etc, and init all UI example panels. /// </summary> protected void InitExamplesAndUI() { // create top panel int topPanelHeight = 65; Panel topPanel = new Panel(new Vector2(0, topPanelHeight + 2), PanelSkin.Simple, Anchor.TopCenter); topPanel.Padding = Vector2.Zero; UIManager.AddEntity(topPanel); // add previous example button previousExampleButton = new Button("<- Back", ButtonSkin.Default, Anchor.TopLeft, new Vector2(300, topPanelHeight)); previousExampleButton.OnClick = (Entity btn) => { this.PreviousExample(); }; topPanel.AddChild(previousExampleButton); // add next example button nextExampleButton = new Button("Next ->", ButtonSkin.Default, Anchor.TopRight, new Vector2(300, topPanelHeight)); nextExampleButton.OnClick = (Entity btn) => { this.NextExample(); }; topPanel.AddChild(nextExampleButton); // add show-get button Button showGitButton = new Button("Git Repo", ButtonSkin.Fancy, Anchor.TopCenter, new Vector2(280, topPanelHeight)); showGitButton.OnClick = (Entity btn) => { System.Diagnostics.Process.Start("https://github.com/RonenNess/GeonBit.UI"); }; topPanel.AddChild(showGitButton); // add exit button Button exitBtn = new Button("Exit", anchor: Anchor.BottomRight, size: new Vector2(200, -1)); exitBtn.OnClick = (Entity entity) => { System.Environment.Exit(1); }; UIManager.AddEntity(exitBtn); // events panel for debug Panel eventsPanel = new Panel(new Vector2(400, 500), PanelSkin.Simple, Anchor.CenterLeft, new Vector2(-10, 0)); eventsPanel.Visible = false; // events log (single-time events) eventsPanel.AddChild(new Label("Events Log:")); SelectList eventsLog = new SelectList(size: new Vector2(-1, 280)); eventsLog.ExtraSpaceBetweenLines = -8; eventsLog.ItemsScale = 0.5f; eventsLog.Locked = true; eventsPanel.AddChild(eventsLog); // current events (events that happen while something is true) eventsPanel.AddChild(new Label("Current Events:")); SelectList eventsNow = new SelectList(size: new Vector2(-1, 100)); eventsNow.ExtraSpaceBetweenLines = -8; eventsNow.ItemsScale = 0.5f; eventsNow.Locked = true; eventsPanel.AddChild(eventsNow); // add the events panel UIManager.AddEntity(eventsPanel); // whenever events log list size changes, make sure its not too long. if it is, trim it. eventsLog.OnListChange = (Entity entity) => { SelectList list = (SelectList)entity; if (list.Count > 100) { list.RemoveItem(0); } }; // listen to all global events - one timers UserInterface.OnClick = (Entity entity) => { eventsLog.AddItem("Click: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseDown = (Entity entity) => { eventsLog.AddItem("MouseDown: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseEnter = (Entity entity) => { eventsLog.AddItem("MouseEnter: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseLeave = (Entity entity) => { eventsLog.AddItem("MouseLeave: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseReleased = (Entity entity) => { eventsLog.AddItem("MouseReleased: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnMouseWheelScroll = (Entity entity) => { eventsLog.AddItem("Scroll: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnStartDrag = (Entity entity) => { eventsLog.AddItem("StartDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnStopDrag = (Entity entity) => { eventsLog.AddItem("StopDrag: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; UserInterface.OnValueChange = (Entity entity) => { if (entity.Parent == eventsLog) { return; } eventsLog.AddItem("ValueChanged: " + entity.GetType().Name); eventsLog.scrollToEnd(); }; // clear the current events after every frame they were drawn eventsNow.AfterDraw = (Entity entity) => { eventsNow.ClearItems(); }; // listen to all global events - happening now UserInterface.WhileDragging = (Entity entity) => { eventsNow.AddItem("Dragging: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; UserInterface.WhileMouseDown = (Entity entity) => { eventsNow.AddItem("MouseDown: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; UserInterface.WhileMouseHover = (Entity entity) => { eventsNow.AddItem("MouseHover: " + entity.GetType().Name); eventsNow.scrollToEnd(); }; // add extra info button Button infoBtn = new Button(" Events", anchor: Anchor.BottomLeft, size: new Vector2(280, -1), offset: new Vector2(140, 0)); infoBtn.AddChild(new Icon(IconType.Scroll, Anchor.CenterLeft), true); infoBtn.OnClick = (Entity entity) => { eventsPanel.Visible = !eventsPanel.Visible; }; UIManager.AddEntity(infoBtn); // zoom in / out factor float zoominFactor = 0.05f; // scale show Paragraph scaleShow = new Paragraph("100%", Anchor.BottomLeft, offset: new Vector2(10, 70)); UIManager.AddEntity(scaleShow); // init zoom-out button Button zoomout = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70)); Icon zoomoutIcon = new Icon(IconType.ZoomOut, Anchor.Center, 0.75f); zoomout.AddChild(zoomoutIcon, true); zoomout.OnClick = (Entity btn) => { if (UserInterface.SCALE > 0.5f) { UserInterface.SCALE -= zoominFactor; } scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%"; }; UIManager.AddEntity(zoomout); // init zoom-in button Button zoomin = new Button("", ButtonSkin.Default, Anchor.BottomLeft, new Vector2(70, 70), new Vector2(70, 0)); Icon zoominIcon = new Icon(IconType.ZoomIn, Anchor.Center, 0.75f); zoomin.AddChild(zoominIcon, true); zoomin.OnClick = (Entity btn) => { if (UserInterface.SCALE < 1.45f) { UserInterface.SCALE += zoominFactor; } scaleShow.Text = ((int)System.Math.Round(UserInterface.SCALE * 100f)).ToString() + "%"; }; UIManager.AddEntity(zoomin); // init all examples // example: welcome message { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 650)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text Image title = new Image(Content.Load <Texture2D>("example/GeonBitUI-sm"), new Vector2(400, 240), anchor: Anchor.TopCenter, offset: new Vector2(0, -20)); title.ShadowColor = Color.Black; title.ShadowOffset = Vector2.One * -3; panel.AddChild(title); panel.AddChild(new Paragraph(@"Welcome to GeonBit UI! This UI is part of the GeonBit project. It provide a simple yet extensive UI for MonoGame based projects. To start the demo, please click the 'Next' button on the top navbar.")); } // example: featues list { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 640)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Widgets Types")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"GeonBit.UI implements the following widgets: - Paragraphs - Headers - Buttons - Panels - CheckBox - Radio buttons - Rectangles - Images & Icons - Select List - Dropdown - Panel Tabs - Sliders & Progressbars - Text input - And more... ")); } // example: basic concepts { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(740, 680)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Basic Concepts")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"Panels are the basic containers of GeonBit.UI. They are like window forms. To position elements inside panels or other widgets, you set an anchor and offset. An anchor is a pre-defined position in parent element, like top-left corner, center, etc. and offset is just the distance from that point. Another thing to keep in mind is size; Most widgets come with a default size, but for those you need to set size for remember that setting size 0 will take full width / height. For example, size of X = 0, Y = 100 means the widget will be 100 pixels height and the width of its parent (minus the parent padding).")); } // example: anchors { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(800, 650)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Paragraph(@"Anchors help position elements. For example, this paragraph anchor is 'center'. The most common anchors are 'Auto' and 'AutoInline', which will place entities one after another automatically.", Anchor.Center, Color.White, 0.8f, new Vector2(320, 0))); panel.AddChild(new Header("Anchors", Anchor.TopCenter, new Vector2(0, 100))); panel.AddChild(new Paragraph("top-left", Anchor.TopLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("top-center", Anchor.TopCenter, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("top-right", Anchor.TopRight, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-left", Anchor.BottomLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-center", Anchor.BottomCenter, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("bottom-right", Anchor.BottomRight, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("center-left", Anchor.CenterLeft, Color.Yellow, 0.8f)); panel.AddChild(new Paragraph("center-right", Anchor.CenterRight, Color.Yellow, 0.8f)); } // example: buttons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 700)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Buttons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with 3 button skins:")); // add default buttons panel.AddChild(new Button("Default", ButtonSkin.Default)); panel.AddChild(new Button("Alternative", ButtonSkin.Alternative)); panel.AddChild(new Button("Fancy", ButtonSkin.Fancy)); // custom button Button custom = new Button("Custom Skin", ButtonSkin.Default, size: new Vector2(0, 80)); custom.SetCustomSkin( Content.Load <Texture2D>("example/btn_default"), Content.Load <Texture2D>("example/btn_hover"), Content.Load <Texture2D>("example/btn_down")); panel.AddChild(custom); // toggle button panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); panel.AddChild(new LineSpace()); panel.AddChild(new Paragraph("Note: buttons can also work in toggle mode:")); Button btn = new Button("Toggle Me!", ButtonSkin.Default); btn.ToggleMode = true; panel.AddChild(btn); } // example: checkboxes and radio buttons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 570)); panels.Add(panel); UIManager.AddEntity(panel); // checkboxes example panel.AddChild(new Header("CheckBox")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("CheckBoxes example:")); panel.AddChild(new CheckBox("CheckBox 1")); panel.AddChild(new CheckBox("CheckBox 2")); // radio example panel.AddChild(new LineSpace(3)); panel.AddChild(new Header("Radio buttons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Radio buttons example:")); panel.AddChild(new RadioButton("Option 1")); panel.AddChild(new RadioButton("Option 2")); panel.AddChild(new RadioButton("Option 3")); } // example: panels { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 660)); panels.Add(panel); UIManager.AddEntity(panel); // title and text panel.AddChild(new Header("Panels")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with 4 alternative panel skins:")); int panelHeight = 110; { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Fancy, Anchor.Auto); intPanel.AddChild(new Paragraph("Fancy Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Golden, Anchor.Auto); intPanel.AddChild(new Paragraph("Golden Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.Simple, Anchor.Auto); intPanel.AddChild(new Paragraph("Simple Panel", Anchor.Center)); panel.AddChild(intPanel); } { Panel intPanel = new Panel(new Vector2(0, panelHeight), PanelSkin.ListBackground, Anchor.Auto); intPanel.AddChild(new Paragraph("List Background", Anchor.Center)); panel.AddChild(intPanel); } } // example: draggable { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 690)); panel.Draggable = true; panels.Add(panel); UIManager.AddEntity(panel); // title and text panel.AddChild(new Header("Draggable")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("This panel can be dragged, try it out!")); panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); panel.AddChild(new LineSpace()); Paragraph paragraph = new Paragraph("Note that any type of entity can become draggable. For example, try to drag this paragraph!"); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Yellow)); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseHover); paragraph.Draggable = true; paragraph.LimitDraggingToParentBoundaries = false; panel.AddChild(paragraph); // internal panel with internal draggable Panel panelInt = new Panel(new Vector2(250, 250), PanelSkin.Golden, Anchor.AutoCenter); panelInt.Draggable = true; panelInt.AddChild(new Paragraph("This panel is draggable too, but limited to its parent boundaries.", Anchor.Center, Color.White, 0.85f)); panel.AddChild(panelInt); } // example: sliders { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 600)); panels.Add(panel); UIManager.AddEntity(panel); // sliders title panel.AddChild(new Header("Sliders")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Sliders help pick numeric value in range:")); panel.AddChild(new Paragraph("\nDefault slider")); panel.AddChild(new Slider(0, 10, SliderSkin.Default)); panel.AddChild(new Paragraph("\nFancy slider")); panel.AddChild(new Slider(0, 10, SliderSkin.Fancy)); // progressbar title panel.AddChild(new LineSpace(3)); panel.AddChild(new Header("Progress bar")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Works just like sliders:")); panel.AddChild(new ProgressBar(0, 10)); } // example: lists { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // list title panel.AddChild(new Header("SelectList")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("SelectLists let you pick a value from a list of items:")); SelectList list = new SelectList(new Vector2(0, 250)); list.AddItem("Warrior"); list.AddItem("Mage"); list.AddItem("Ranger"); list.AddItem("Rogue"); list.AddItem("Paladin"); list.AddItem("Cleric"); list.AddItem("Warlock"); list.AddItem("Barbarian"); list.AddItem("Monk"); list.AddItem("Ranger"); panel.AddChild(list); } // example: lists skins { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // list title panel.AddChild(new Header("SelectList - Skin")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Just like panels, SelectList can also use alternative skins:")); SelectList list = new SelectList(new Vector2(0, 250), skin: PanelSkin.Golden); list.AddItem("Warrior"); list.AddItem("Mage"); list.AddItem("Ranger"); list.AddItem("Rogue"); list.AddItem("Paladin"); list.AddItem("Cleric"); list.AddItem("Warlock"); list.AddItem("Barbarian"); list.AddItem("Monk"); list.AddItem("Ranger"); panel.AddChild(list); } // example: dropdown { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 480)); panels.Add(panel); UIManager.AddEntity(panel); // dropdown title panel.AddChild(new Header("DropDown")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("DropDown is just like a list, but take less space since it hide the list when not used:")); DropDown drop = new DropDown(new Vector2(0, 280)); drop.AddItem("Warrior"); drop.AddItem("Mage"); drop.AddItem("Ranger"); drop.AddItem("Rogue"); drop.AddItem("Paladin"); drop.AddItem("Cleric"); drop.AddItem("Warlock"); drop.AddItem("Barbarian"); drop.AddItem("Monk"); drop.AddItem("Ranger"); panel.AddChild(drop); panel.AddChild(new Paragraph("And like list, we can set different skins:")); drop = new DropDown(new Vector2(0, 240), skin: PanelSkin.Golden); drop.AddItem("Warrior"); drop.AddItem("Mage"); drop.AddItem("Ranger"); panel.AddChild(drop); } // example: icons { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(460, 670)); panels.Add(panel); UIManager.AddEntity(panel); // icons title panel.AddChild(new Header("Icons")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("GeonBit.UI comes with some built-in icons:")); foreach (IconType icon in System.Enum.GetValues(typeof(IconType))) { if (icon == IconType.None) { continue; } panel.AddChild(new Icon(icon, Anchor.AutoInline)); } panel.AddChild(new Paragraph("And you can also add an inventory-like frame:")); for (int i = 0; i < 6; ++i) { panel.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true)); } } // example: text input { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(450, 590)); panels.Add(panel); UIManager.AddEntity(panel); // text input example panel.AddChild(new Header("Text Input")); panel.AddChild(new HorizontalLine()); // inliner panel.AddChild(new Paragraph("Text input let you get free text from the user:"******"Insert text.."; panel.AddChild(text); // multiline panel.AddChild(new Paragraph("Text input can also be multiline, and use different panel skins:")); TextInput textMulti = new TextInput(true, new Vector2(0, 220), skin: PanelSkin.Golden); textMulti.PlaceholderText = @"Insert multiline text.."; panel.AddChild(textMulti); } // example: locked text input { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 590)); panels.Add(panel); UIManager.AddEntity(panel); // text input example panel.AddChild(new Header("Locked Text Input")); panel.AddChild(new HorizontalLine()); // inliner panel.AddChild(new Paragraph("A locked multiline text is a cool trick to create long, scrollable text:")); TextInput textMulti = new TextInput(true, new Vector2(0, 370)); textMulti.Locked = true; textMulti.TextParagraph.Scale = 0.6f; textMulti.Value = @"The Cleric, Priest, or Bishop is a character class in Dungeons & Dragons and other fantasy role-playing games. The cleric is a healer, usually a priest and a holy warrior, originally modeled on or inspired by the Military Orders. Clerics are usually members of religious orders, with the original intent being to portray soldiers of sacred orders who have magical abilities, although this role was later taken more clearly by the paladin. Most clerics have powers to heal wounds, protect their allies and sometimes resurrect the dead, as well as summon, manipulate and banish undead. A description of Priests and Priestesses from the Nethack guidebook: Priests and Priestesses are clerics militant, crusaders advancing the cause of righteousness with arms, armor, and arts thaumaturgic. Their ability to commune with deities via prayer occasionally extricates them from peril, but can also put them in it.[1] A common feature of clerics across many games is that they may not equip pointed weapons such as swords or daggers, and must use blunt weapons such as maces, war-hammers, shields or wand instead. This is based on a popular, but erroneous, interpretation of the depiction of Odo of Bayeux and accompanying text. They are also often limited in what types of armor they can wear, though usually not as restricted as mages. Related to the cleric is the paladin, who is typically a Lawful Good[citation needed] warrior often aligned with a religious order, and who uses their martial skills to advance its holy cause."; panel.AddChild(textMulti); } // example: panel tabs { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(540, 480)); panels.Add(panel); UIManager.AddEntity(panel); // create panel tabs PanelTabs tabs = new PanelTabs(); panel.AddChild(tabs); // add first panel { PanelTabs.TabData tab = tabs.AddTab("Tab 1"); tab.panel.AddChild(new Header("PanelTabs")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph(@"PanelTab creates a group of internal panels with toggle buttons to switch between them. Choose a tab in the buttons above for more info...")); } // add second panel { PanelTabs.TabData tab = tabs.AddTab("Tab 2"); tab.panel.AddChild(new Header("Tab 2")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph(@"Awesome, you got to tab2! Maybe something interesting in tab3?")); } // add third panel { PanelTabs.TabData tab = tabs.AddTab("Tab 3"); tab.panel.AddChild(new Header("Nope.")); tab.panel.AddChild(new HorizontalLine()); tab.panel.AddChild(new Paragraph("Nothing to see here.")); } } // example: disabled { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(480, 650)); panel.Disabled = true; panels.Add(panel); UIManager.AddEntity(panel); // disabled title panel.AddChild(new Header("Disabled")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Entities can be disabled:")); // internal panel Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto); panel2.Padding = Vector2.Zero; panel.AddChild(panel2); panel2.AddChild(new Button("button")); for (int i = 0; i < 6; ++i) { panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6))); } panel2.AddChild(new Paragraph("\nDisabled entities are drawn in black & white, and you cannot interact with them..")); SelectList list = new SelectList(new Vector2(0, 130)); list.AddItem("Warrior"); list.AddItem("Mage"); panel2.AddChild(list); panel2.AddChild(new CheckBox("disabled..")); } // example: Locked { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(520, 680)); panels.Add(panel); UIManager.AddEntity(panel); // locked title panel.AddChild(new Header("Locked")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Entities can also be locked:", Anchor.Auto)); Panel panel2 = new Panel(Vector2.Zero, PanelSkin.None, Anchor.Auto); panel2.Padding = Vector2.Zero; panel2.Locked = true; panel.AddChild(panel2); panel2.AddChild(new Button("button")); for (int i = 0; i < 6; ++i) { panel2.AddChild(new Icon((IconType)i, Anchor.AutoInline, 1, true, new Vector2(12, 6))); } panel2.AddChild(new Paragraph("\nLocked entities will not respond to input, but unlike disabled entities they are drawn normally, eg with colors:")); SelectList list = new SelectList(new Vector2(0, 130)); list.AddItem("Warrior"); list.AddItem("Mage"); panel2.AddChild(list); panel2.AddChild(new CheckBox("locked..")); } // example: Misc { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(530, 650)); panels.Add(panel); UIManager.AddEntity(panel); // misc title panel.AddChild(new Header("Miscellaneous")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph("Some cool tricks you can do:")); // button with icon Button btn = new Button("Button With Icon"); btn.ButtonParagraph.SetPosition(Anchor.CenterLeft, new Vector2(60, 0)); btn.AddChild(new Icon(IconType.Book, Anchor.CenterLeft), true); panel.AddChild(btn); // change progressbar color panel.AddChild(new Paragraph("Different PrograssBar colors:")); ProgressBar pb = new ProgressBar(); pb.ProgressFill.FillColor = Color.Red; panel.AddChild(pb); // paragraph style with mouse panel.AddChild(new LineSpace()); panel.AddChild(new HorizontalLine()); Paragraph paragraph = new Paragraph("Hover / click styling.."); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Purple), EntityState.MouseDown); paragraph.SetStyleProperty("FillColor", new StyleProperty(Color.Red), EntityState.MouseHover); panel.AddChild(paragraph); panel.AddChild(new HorizontalLine()); // colored rectangle panel.AddChild(new Paragraph("Colored rectangle:")); ColoredRectangle rect = new ColoredRectangle(Color.Blue, Color.Red, 4, new Vector2(0, 40)); panel.AddChild(rect); panel.AddChild(new HorizontalLine()); // custom icons panel.AddChild(new Paragraph("Custom icons / images:")); Icon icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/warrior"); panel.AddChild(icon); icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/monk"); panel.AddChild(icon); icon = new Icon(IconType.None, Anchor.AutoInline, 1, true, new Vector2(12, 10)); icon.Texture = Content.Load <Texture2D>("example/mage"); panel.AddChild(icon); } // example: character build page - intro { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 380)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Final Example")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"The next example will show a fully-functional character creation page, that use different entities, events, etc. Click on 'Next' to see the character creation demo.")); } // example: character build page - final { int panelWidth = 730; // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(panelWidth, 570)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("Create New Character")); panel.AddChild(new HorizontalLine()); // create an internal panel to align components better - a row that covers the entire width split into 3 columns (left, center, right) // first the container panel Panel entitiesGroup = new Panel(new Vector2(0, 240), PanelSkin.None, Anchor.AutoCenter); entitiesGroup.Padding = Vector2.Zero; panel.AddChild(entitiesGroup); // now left side Panel leftPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopLeft); leftPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(leftPanel); // right side Panel rightPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopRight); rightPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(rightPanel); // center Panel centerPanel = new Panel(new Vector2(0.33f, 0), PanelSkin.None, Anchor.TopCenter); centerPanel.Padding = Vector2.Zero; entitiesGroup.AddChild(centerPanel); // create a character preview panel centerPanel.AddChild(new Label(@"Preview", Anchor.AutoCenter)); Panel charPreviewPanel = new Panel(new Vector2(180, 180), PanelSkin.Simple, Anchor.AutoCenter); charPreviewPanel.Padding = Vector2.Zero; centerPanel.AddChild(charPreviewPanel); // create preview pics of character Image previewImage = new Image(Content.Load <Texture2D>("example/warrior"), Vector2.Zero, anchor: Anchor.Center); Image previewImageColor = new Image(Content.Load <Texture2D>("example/warrior_color"), Vector2.Zero, anchor: Anchor.Center); Image previewImageSkin = new Image(Content.Load <Texture2D>("example/warrior_skin"), Vector2.Zero, anchor: Anchor.Center); charPreviewPanel.AddChild(previewImage); charPreviewPanel.AddChild(previewImageColor); charPreviewPanel.AddChild(previewImageSkin); // add skin tone slider Slider skin = new Slider(0, 10, new Vector2(0, -1), SliderSkin.Default, Anchor.Auto); skin.OnValueChange = (Entity entity) => { Slider slider = (Slider)entity; int alpha = (int)(slider.GetValueAsPercent() * 255); previewImageSkin.FillColor = new Color(60, 32, 25, alpha); }; skin.Value = 5; charPreviewPanel.AddChild(skin); // create the class selection list leftPanel.AddChild(new Label(@"Class", Anchor.AutoCenter)); SelectList classTypes = new SelectList(new Vector2(0, 208), Anchor.Auto); classTypes.AddItem("Warrior"); classTypes.AddItem("Mage"); classTypes.AddItem("Ranger"); classTypes.AddItem("Monk"); classTypes.SelectedIndex = 0; leftPanel.AddChild(classTypes); classTypes.OnValueChange = (Entity entity) => { string texture = ((SelectList)(entity)).SelectedValue.ToLower(); previewImage.Texture = Content.Load <Texture2D>("example/" + texture); previewImageColor.Texture = Content.Load <Texture2D>("example/" + texture + "_color"); previewImageSkin.Texture = Content.Load <Texture2D>("example/" + texture + "_skin"); }; // create color selection buttons rightPanel.AddChild(new Label(@"Color", Anchor.AutoCenter)); Color[] colors = { Color.White, Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Purple, Color.Cyan, Color.Brown }; int colorPickSize = 24; foreach (Color baseColor in colors) { rightPanel.AddChild(new LineSpace()); for (int i = 0; i < 8; ++i) { Color color = baseColor * (1.0f - (i * 2 / 16.0f)); color.A = 255; ColoredRectangle currColorButton = new ColoredRectangle(color, Vector2.One * colorPickSize, Anchor.AutoInline); currColorButton.SpaceAfter = currColorButton.SpaceBefore = Vector2.Zero; currColorButton.OnClick = (Entity entity) => { previewImageColor.FillColor = entity.FillColor; }; rightPanel.AddChild(currColorButton); } } // gender selection (radio buttons) entitiesGroup.AddChild(new LineSpace()); entitiesGroup.AddChild(new RadioButton("Male", Anchor.Auto, new Vector2(180, 60), isChecked: true)); entitiesGroup.AddChild(new RadioButton("Female", Anchor.AutoInline, new Vector2(240, 60))); // hardcore mode Button hardcore = new Button("Hardcore", ButtonSkin.Fancy, Anchor.AutoInline, new Vector2(220, 60)); hardcore.ButtonParagraph.Scale = 0.8f; hardcore.ToggleMode = true; entitiesGroup.AddChild(hardcore); entitiesGroup.AddChild(new HorizontalLine()); // add character name, last name, and age // first add the labels entitiesGroup.AddChild(new Label(@"First Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1))); entitiesGroup.AddChild(new Label(@"Last Name: ", Anchor.AutoInline, size: new Vector2(0.4f, -1))); entitiesGroup.AddChild(new Label(@"Age: ", Anchor.AutoInline, size: new Vector2(0.2f, -1))); // now add the text inputs // first name TextInput firstName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.Auto); firstName.PlaceholderText = "Name"; firstName.Validators.Add(new TextValidatorEnglishCharsOnly()); firstName.Validators.Add(new TextValidatorMakeTitle()); entitiesGroup.AddChild(firstName); // last name TextInput lastName = new TextInput(false, new Vector2(0.4f, -1), anchor: Anchor.AutoInline); lastName.PlaceholderText = "Surname"; lastName.Validators.Add(new TextValidatorEnglishCharsOnly()); lastName.Validators.Add(new TextValidatorMakeTitle()); entitiesGroup.AddChild(lastName); // age TextInput age = new TextInput(false, new Vector2(0.2f, -1), anchor: Anchor.AutoInline); age.Validators.Add(new TextValidatorNumbersOnly(false, 0, 80)); age.Value = "20"; entitiesGroup.AddChild(age); } // example: epilogue { // create panel and add to list of panels and manager Panel panel = new Panel(new Vector2(500, 560)); panels.Add(panel); UIManager.AddEntity(panel); // add title and text panel.AddChild(new Header("End Of Examples")); panel.AddChild(new HorizontalLine()); panel.AddChild(new Paragraph(@"That's it for now! There is still much to learn about GeonBit.UI, but these examples were enough to get you going. To learn more, please visit the git repo, read the docs, or go through some source code. If you liked GeonBit.UI feel free to star the repo on GitHub. :)")); } // init panels and buttons UpdateAfterExapmleChange(); // once done init, clear events log eventsLog.ClearItems(); // call base initialize base.Initialize(); }
private void InitUI() { UserInterface.Initialize(XNAContent, BuiltinThemes.editor); UserInterface.Active.ShowCursor = false; return; var realPanel = new Panel(new Vector2(500, 650)); realPanel.Draggable = true; var tabs = new PanelTabs(); realPanel.AddChild(tabs); var MainPanel = tabs.AddTab("Some Tab").panel; var tab2 = tabs.AddTab("Some Other Tab"); //tab2.button.Enabled = false; tab2.button.ToolTipText = "This is tab 2."; tab2.panel.AddChild(new TextInput() { CharactersLimit = 16 }); UserInterface.Active.AddEntity(realPanel); MainPanel.AddChild(new Header("Some Header Text")); MainPanel.AddChild(new HorizontalLine()); MainPanel.AddChild(new Paragraph("This is a UI test.")); var b = new Button("This is a button!"); b.ToolTipText = "Some tooltip!"; MainPanel.AddChild(b); MainPanel.AddChild(new Slider(0, 100, SliderSkin.Default) { Enabled = false }); var toggle = new GeonBit.UI.Entities.CheckBox("Some Check", Anchor.Auto); MainPanel.AddChild(toggle); var test = new Panel(new Vector2(300, 140), PanelSkin.Fancy, Anchor.AutoInline); test.AddChild(new Label("I am a label")); test.AddChild(new CheckBox("I'm a box")); test.AdjustHeightAutomatically = true; MainPanel.AddChild(test); var list = new SelectList(); list.AddItem("Option A"); list.AddItem("Option B"); list.AddItem("Option C"); list.SetHeightBasedOnChildren(); var drop = new DropDown(); drop.AddItem("Something A"); drop.AddItem("Something B"); drop.AddItem("Something C"); MainPanel.AddChild(drop); var pan2 = new Panel(); pan2.AddChild(new Header("Some sub-panel")); pan2.AddChild(new CheckBox("Cool?") { OnValueChange = (e) => { Debug.Log((e as CheckBox).Checked.ToString()); } }); tab2.panel.AddChild(pan2, true); //pan2.Anchor = Anchor.AutoInline; Debug.Log(MainPanel.Padding.ToString()); MainPanel.AddChild(list); MainPanel.Padding = new Vector2(10, 5); MainPanel.SetHeightBasedOnChildren(); }
internal void GenerateUserInterface(GameState tempGameState) { switch (tempGameState) { case GameState.MainGame: UserInterface.SetCursor(_game1.transparent); _game1.shopHUDButton = new Button("Shop (G)", anchor: Anchor.BottomRight, size: new Vector2(150, 50), skin: ButtonSkin.Alternative); _game1.shopHUDButton.ButtonParagraph.Scale = 0.5f; _game1.shopHUDButton.ButtonParagraph.WrapWords = false; _game1.shopHUDButton.OnClick = (Entity btn) => { if (_game1.gameState == GameState.MainGame) { _game1.ChangeState(GameState.ShopMenu); } else if (_game1.gameState == GameState.ShopMenu) { _game1.ChangeState(GameState.MainGame); } }; UserInterface.AddEntity(_game1.shopHUDButton); break; case GameState.EndScreen: UserInterface.SetCursor(CursorType.Default); break; case GameState.MainMenu: _game1.mainMenuPanel = new Panel(new Vector2(300, 500)); UserInterface.AddEntity(_game1.mainMenuPanel); mainMenuPlayButton = new Button("Play"); mainMenuPlayButton.ButtonParagraph.Scale = 0.5f; var mainMenuControlsButton = new Button("Controls"); mainMenuControlsButton.ButtonParagraph.Scale = 0.5f; mainMenuSettingsButton = new Button("Settings"); mainMenuSettingsButton.ButtonParagraph.Scale = 0.5f; mainMenuExitButton = new Button("Quit"); mainMenuExitButton.ButtonParagraph.Scale = 0.5f; //var LoadButton = new Button("Load names"); //LoadButton.ButtonParagraph.Scale = 0.5f; _game1.mainMenuPanel.AddChild(mainMenuPlayButton); _game1.mainMenuPanel.AddChild(mainMenuControlsButton); _game1.mainMenuPanel.AddChild(mainMenuSettingsButton); _game1.mainMenuPanel.AddChild(mainMenuExitButton); //_game1.mainMenuPanel.AddChild(LoadButton); //LoadButton.OnClick = (Entity btn) => //{ // _game1.LoadNames(); //}; mainMenuControlsButton.OnClick = (Entity btn) => { _game1.ChangeState(GameState.ControlsMenu); }; mainMenuPlayButton.OnClick = (Entity btn) => { _game1.ResetGame(); _game1.ChangeState(GameState.MainGame); }; mainMenuSettingsButton.OnClick = (Entity btn) => { _game1.ChangeState(GameState.SettingsMenu); }; mainMenuExitButton.OnClick = (Entity btn) => { _game1.Exit(); }; break; case GameState.ControlsMenu: _game1.controlsMenuPanel = new Panel(new Vector2(700, 500)); UserInterface.AddEntity(_game1.controlsMenuPanel); var backButton2 = new Button("Back"); backButton2.ButtonParagraph.Scale = 0.5f; backButton2.OnClick = (Entity btn) => { _game1.ChangeState(GameState.MainMenu); }; _game1.controlsMenuPanel.AddChild(backButton2); var forwardKeyButton = new Button(_game1.forwardKey.ToString(), size: new Vector2(75, 75), anchor: Anchor.TopLeft, offset: new Vector2(0, 75 + 30)); forwardKeyButton.ButtonParagraph.Scale = 1.0f; forwardKeyButton.ButtonParagraph.SetAnchor(Anchor.BottomCenter); forwardKeyButton.ButtonParagraph.SetOffset(new Vector2(0, -27)); var forwardKeyButton2 = new Button(_game1.forwardKey2.ToString(), size: new Vector2(75, 75), anchor: Anchor.TopLeft, offset: new Vector2(75 + 30, 75 + 30)); forwardKeyButton2.ButtonParagraph.Scale = 1.0f; forwardKeyButton2.ButtonParagraph.SetAnchor(Anchor.BottomCenter); forwardKeyButton2.ButtonParagraph.SetOffset(new Vector2(0, -27)); var forwardKeyParagraph = new Paragraph(" - Forward", anchor: Anchor.TopLeft, offset: new Vector2(150 + 30, 75 + 30 + 5)); forwardKeyParagraph.Scale = 1.0f; _game1.controlsMenuPanel.AddChild(forwardKeyParagraph); _game1.controlsMenuPanel.AddChild(forwardKeyButton); _game1.controlsMenuPanel.AddChild(forwardKeyButton2); break; case GameState.SettingsMenu: UserInterface.SetCursor(CursorType.Default); _game1.settingsMenuPanel = new Panel(new Vector2(700, 500)); UserInterface.AddEntity(_game1.settingsMenuPanel); var backButton = new Button("Back"); backButton.ButtonParagraph.Scale = 0.5f; backButton.OnClick = btn => { _game1.ChangeState(_game1.oldGameState); }; _game1.settingsMenuPanel.AddChild(backButton); var fullscreenCheckbox = new CheckBox("Fullscreen"); fullscreenCheckbox.Checked = _game1.Graphics.IsFullScreen; fullscreenCheckbox.TextParagraph.Scale = 0.5f; fullscreenCheckbox.OnValueChange = box => { _game1.Graphics.IsFullScreen = fullscreenCheckbox.Checked; _game1.Graphics.ApplyChanges(); }; _game1.settingsMenuPanel.AddChild(fullscreenCheckbox); var dropDown2 = new DropDown(new Vector2(0, 0)); dropDown2.SelectedTextPanelParagraph.Text = CurrentScreenWidth + "x" + CurrentScreenHeight; dropDown2.AddItem("2560x1080"); dropDown2.AddItem("1920x1080"); dropDown2.AddItem("1680x1050"); dropDown2.AddItem("1440x900"); dropDown2.AddItem("1336x768"); dropDown2.AddItem("1280x800"); dropDown2.AddItem("1240x720"); dropDown2.OnValueChange = (Entity drop) => { string selected = dropDown2.SelectedValue; var index = selected.IndexOf('x'); var widthRes = selected.Substring(0, index); var heightRes = selected.Substring(index + 1); CurrentScreenWidth = Convert.ToInt16(widthRes); CurrentScreenHeight = Convert.ToInt16(heightRes); _game1.halfScreen = new Vector2(CurrentScreenWidth / 2f, CurrentScreenHeight / 2f); _game1.Graphics.ApplyChanges(); }; _game1.settingsMenuPanel.AddChild(dropDown2); break; case GameState.ShopMenu: UserInterface.SetCursor(CursorType.Default); _game1.shopPanel = new Panel(new Vector2(500, 300), anchor: Anchor.TopLeft, offset: new Vector2(0, 70)); UserInterface.AddEntity(_game1.shopPanel); tabs = new PanelTabs(); tab0 = tabs.AddTab("Warp"); tab0.button.ButtonParagraph.Scale = 0.5f; tab1 = tabs.AddTab("Shop"); tab1.button.ButtonParagraph.Scale = 0.5f; tab2 = tabs.AddTab("Upgrades"); tab2.button.ButtonParagraph.Scale = 0.5f; tab2.button.ButtonParagraph.WrapWords = false; tab3 = tabs.AddTab("Refitting"); tab3.button.ButtonParagraph.Scale = 0.5f; tab3.button.ButtonParagraph.WrapWords = false; //first tab var para = new Paragraph("Current sector: " + _game1.currentSector.Name); para.Scale = 0.7f; para.WrapWords = false; tab0.panel.AddChild(para); warpButton = new Button("Warp to new sector"); warpButton.ButtonParagraph.Scale = 0.5f; warpButton.OnClick = (Entity btn) => { ChangeSector(_game1.GenerateSector()); _game1.ChangeState(GameState.MainGame); }; tab0.panel.AddChild(warpButton); tab0.panel.AddChild(new HorizontalLine()); var dropDown = new DropDown(new Vector2(0, 0)); dropDown.SelectedTextPanelParagraph.Scale = 0.5f; dropDown.SelectList.ItemsScale = 0.5f; dropDown.SelectedTextPanelParagraph.Text = "Warp to an old sector"; for (int i = 0; i < _game1.sectors.Count; i++) { if (_game1.sectors[i].Name == _game1.currentSector.Name) { continue; } dropDown.AddItem(_game1.sectors[i].Name); } dropDown.AttachedData = dropDown.SelectedValue; dropDown.OnValueChange = (Entity drop) => { var dropDownSector = _game1.sectors.FirstOrDefault(x => x.Name == dropDown.SelectedValue); ChangeSector(dropDownSector); }; tab0.panel.AddChild(dropDown); //for (int i = 0; i < sectors.Count; i++) //{ // var button = new Button("Sector: " + sectors[i].Name); // button.Identifier = i.ToString(); // button.OnClick = (Entity btn) => { // currentSector = sectors[Convert.ToInt16(btn.Identifier)]; // ChangeState(GameState.MainGame); // }; // tab0.panel.AddChild(button); // tab0.panel.AddChild(new HorizontalLine()); //} //second tab int height = 200; //TODO: offset = text width, measurestring for (int i = 0; i < _game1.availableShips.Count; i++) { CreateShopSection(tab1, height, i); } tab1.panel.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll; tab1.panel.Scrollbar.Max = Convert.ToUInt16((int)((_game1.availableShips.Count * (height + 20)) - _game1.shopPanel.Size.Y)); tab1.panel.Scrollbar.StepsCount = (uint)_game1.availableShips.Count * 5; //third tab int height2 = 200; //TODO: offset = text width, measurestring for (int i = 0; i < _game1.availableUpgrades.Count; i++) //TODO change max to randomly generated upgrades { CreateUpgradeShopSection(tab2, height2, i); } tab2.panel.PanelOverflowBehavior = PanelOverflowBehavior.VerticalScroll; tab2.panel.Scrollbar.Max = Convert.ToUInt16((int)((_game1.availableShips.Count * (height + 20)) - _game1.shopPanel.Size.Y)); tab2.panel.Scrollbar.StepsCount = (uint)_game1.availableShips.Count * 5; //fourth tab //last tab end _game1.shopPanel.AddChild(tabs); break; case GameState.PauseMenu: UserInterface.SetCursor(CursorType.Default); //panel _game1.pauseMenuPanel = new Panel(new Vector2(300, 520)); UserInterface.AddEntity(_game1.pauseMenuPanel); //resumebutton var resumeButton = new Button("Resume"); resumeButton.ButtonParagraph.Scale = 0.5f; resumeButton.OnClick = (Entity btn) => { _game1.ChangeState(GameState.MainGame); }; _game1.pauseMenuPanel.AddChild(resumeButton); //save button var saveButton = new Button("Save game"); saveButton.ButtonParagraph.Scale = 0.5f; saveButton.OnClick = (Entity btn) => { SaveGame(); }; _game1.pauseMenuPanel.AddChild(saveButton); //load button var loadButton = new Button("Load game"); loadButton.ButtonParagraph.Scale = 0.5f; loadButton.OnClick = (Entity btn) => { LoadGame(); }; _game1.pauseMenuPanel.AddChild(loadButton); //settings button var settingsMenuButton = new Button("Settings"); settingsMenuButton.ButtonParagraph.Scale = 0.5f; settingsMenuButton.OnClick = (Entity btn) => { _game1.ChangeState(GameState.SettingsMenu); }; _game1.pauseMenuPanel.AddChild(settingsMenuButton); //main menu button var mainMenuButton = new Button("Main Menu"); mainMenuButton.ButtonParagraph.Scale = 0.5f; mainMenuButton.OnClick = (Entity btn) => { _game1.ChangeState(GameState.MainMenu); }; _game1.pauseMenuPanel.AddChild(mainMenuButton); //exit button var exitButton = new Button("Exit"); exitButton.ButtonParagraph.Scale = 0.5f; exitButton.OnClick = (Entity btn) => { _game1.Exit(); }; _game1.pauseMenuPanel.AddChild(exitButton); break; default: throw new ArgumentOutOfRangeException(nameof(tempGameState), tempGameState, null); } }