public static void AddOldStyle(Popup popup, String subtitle, Panel contentPanel, Panel buttonPanel, bool padding = true) { if (padding) { Label pAddingRight = new Label(" ", Location.EAST, 5); //PAdding Right popup.AddComponent(pAddingRight); Label pAddingLeft = new Label(" ", Location.WEST, 5); //PAdding Left popup.AddComponent(pAddingLeft); } Panel topPanel = new Panel(Location.CENTER); popup.AddComponent(topPanel); Panel headerPanel = new Panel(Location.NORTH); topPanel.AddComponent(headerPanel); headerPanel.AddComponent(new Label(" ", Location.NORTH, 5)); //PAdding Top if (subtitle != null) { headerPanel.AddComponent(new Label(subtitle, Location.CENTER, 18, 'b', new int[] { 0xE5, 0xE5, 0xFF })); //Subtitle } headerPanel.AddComponent(new Label(" ", Location.SOUTH, 5)); //PAdding Header <-> Content topPanel.AddComponent(contentPanel); if (buttonPanel != null) { topPanel.AddComponent(buttonPanel); } }
public static String Create(String title, String subtitle, String message, int width, int height, List <IComponent> controls = null) { Popup popup = new Popup(title, width, height); Panel contentPanel = new Panel(new BorderLayout(), Location.CENTER); contentPanel.AddComponent(new TextPanel( message, width - 10, height - 10, Location.CENTER )); //KCode if (controls != null) { Panel buttonPanel = new Panel(new FlowLayout(), Location.SOUTH); foreach (var com in controls) { buttonPanel.AddComponent(com); } AddOldStyle(popup, subtitle, contentPanel, buttonPanel); } else { AddOldStyle(popup, subtitle, contentPanel, null); } return(popup.ToString()); }
private void displaySelectedUnits(List <IUnit> units) { if (EntityDetails != null) { overlay.RemoveComponent(EntityDetails); } EntityDetails = new Panel(Game, new Rectangle(new Point(217, 359), new Point(336, 121)), this);//TODO this will need to be more automatic if I add different resolutions/screen sizes EntityDetails.Initialize(); Component com = null; float comX = 217; foreach (IUnit unit in units) { com = new ImageBox(((ModifiableTile)unit).block.texture, new Vector2(comX, 359), new Point(1, 1), Color.White); com.Scale = 1; EntityDetails.AddComponent(com); com = new ImageBox(unit.healthBar.Health, new Vector2(comX, 359 + 19), new Point(1, 1), Color.White); com.Scale = 1; EntityDetails.AddComponent(com); comX += (unit.Size.X * 16) + 5; } overlay.AddComponent(EntityDetails); }
void ConstructChoiceList() { int yOfs = 5; foreach (var str in _items) { var l = _choice.AddComponent <Text> (); l.Content = str.ToString(); l.Alignment = Alignment.TopLeft; l.Offset = new Point(5, yOfs); l.Height = 12; yOfs += 13; _choiceLabels.Add(l); } var cfRt = _choiceFrame.RectTransform; cfRt.Padding = new Padding(1, 21 + yOfs / 2, 3, 0); cfRt.Size = new Point(0, yOfs + 6); }
private void AddQueueables(Tile tile) { if (EntityDetails != null) { overlay.RemoveComponent(EntityActions); } EntityActions = new Panel(Game, new Rectangle(new Point(591, 359), new Point(200, 120)), this); EntityActions.Initialize(); //BuildQueue size //Pos: (591,391) Size: (200,120) float x = 591; //MaxX = 791 float y = 359; //MaxY = 511 float scale = 0.25f; if (tile is BasicUnit && !(tile is HostileMob) && ((BasicUnit)tile).QueueableThings != null) // HACK need to move the queueable things up the chain { foreach (IQueueable <TextureValue> queueable in ((BasicUnit)tile).QueueableThings) { if (queueable is Building) { ((Building)queueable).UpdatePosition(Game.GraphicsDevice, new Vector2(x, y)); Component com = new CommandButton(Game.GraphicsDevice, new BuildSelectCommand((Building)queueable), new Vector2(x, y), queueable.Icon, new Point(32)); float width = ((Building)queueable).Size.X; float height = ((Building)queueable).Size.Y; com.Scale = 0.25f; EntityActions.AddComponent(com); x += 128 * scale; if (x + 128 * scale > 791) { x = 591; y += 128 * scale; } } } } else if (tile is Building && ((ModifiableTile)tile).built) { foreach (IQueueable <TextureValue> queueable in ((Building)tile).QueueableThings) { if (queueable is BasicUnit) { ((BasicUnit)queueable).UpdatePosition(Game.GraphicsDevice, new Vector2(x, y)); Component com = new CommandButton(Game.GraphicsDevice, new TrainCommand((IUnit)queueable, (Building)tile), queueable, new Point(32)); float width = ((BasicUnit)queueable).Size.X; float height = ((BasicUnit)queueable).Size.Y; com.Scale = 2; EntityActions.AddComponent(com); x += 128 * scale; if (x + 128 * scale > 791) { x = 591; y += 128 * scale; } } if (queueable is ITech) { ((Technology)queueable).Position = new Vector2(x, y); Component com = new CommandButton(Game.GraphicsDevice, new LearnCommand((ITech)queueable, (Building)tile), queueable, new Point(32)); float width = ContentHandler.DrawnTexture(((Technology)queueable).Icon).Bounds.Size.X; float height = ContentHandler.DrawnTexture(((Technology)queueable).Icon).Bounds.Size.Y; com.Scale = 0.5f; EntityActions.AddComponent(com); x += 128 * scale; if (x + 128 * scale > 791) { x = 591; y += 128 * scale; } } } if (((Building)tile).QueueableThings.Find(l => l is BasicUnit) != null) { Component com = new CommandButton(Game.GraphicsDevice, new SetSpawnPointCommand(CurrentPos, (Building)tile), new Vector2(757, 447), TextureValue.SpawnPoint, new Point(32)); com.Scale = 2; EntityActions.AddComponent(com); } } overlay.AddComponent(EntityActions); }
private void SelectedUnitDisplay(ModifiableTile tile) { if (EntityDetails != null) { overlay.RemoveComponent(EntityDetails); } EntityDetails = new UpdatePanel(tile, Game, new Rectangle(new Point(217, 359), new Point(336, 121)), this);//TODO this will need to be more automatic if I add different resolutions/screen sizes EntityDetails.Initialize(); Component com = new ImageBox(tile.block.texture, new Vector2(227, 359), (tile.Size * 16).ToPoint(), Color.White); com.Scale = 2 / (tile.Size.X); if (tile is Building) { com = new ImageBox(((Building)tile).Icon, new Vector2(227, 359), (tile.Size * 16).ToPoint(), Color.White); com.Scale = 0.25f; } EntityDetails.AddComponent(com); float y = 359; for (int i = 0; i < tile.stats.Count; i++) { if (tile.stats[i] is Health) { com = new ImageBoxHealth(tile.healthBar.Health, new Vector2(227, 359 + 32), new Point((int)com.Scale, 1), Color.White, tile); com.Scale = 2; EntityDetails.AddComponent(com); if (tile.TeamStats != null) { com = new StatComponent(new Label(new Vector2(224, 359 + 46), $"{tile.CurrentHealth}/{tile.TotalHealth}", Color.White), tile.stats[typeof(Health)].GetType(), tile.stats[typeof(Health)].Value + tile.stats[typeof(Health)].Value); } else { com = new StatComponent(new Label(new Vector2(224, 359 + 46), $"{tile.CurrentHealth}/{tile.TotalHealth}", Color.White), tile.stats[typeof(Health)].GetType(), tile.stats[typeof(Health)].Value); } } else { com = new ImageBox(tile.stats[i].Texture, new Vector2(300, y - 8), new Point(16), Color.White); com.Scale = 0.25f; EntityDetails.AddComponent(com); string display = tile.stats[i].Value.ToString(); if (tile is BasicUnit) { Stat stat = null; if (((BasicUnit)tile).teamStats != null) { stat = ((BasicUnit)tile).teamStats[tile.stats[i].GetType()]; } if (stat != null) { display += $" ({stat.Value.ToString()})"; } } if (tile.TeamStats != null) { com = new StatComponent(new Label(new Vector2(330, y - 8), display, Color.White), tile.stats[i].GetType(), tile.stats[i].Value + tile.TeamStats[i].Value); } else { com = new StatComponent(new Label(new Vector2(330, y - 8), display, Color.White), tile.stats[i].GetType(), tile.stats[i].Value); } com.Scale = 1; } com.drawComponent = true; EntityDetails.AddComponent(com); y += 12 + 5; } overlay.AddComponent(EntityDetails); }
private Hud(SceneObject root, Color backgroundColor, Color foregroundColor) { _canvas = SceneObject.Instantiate <Canvas>(root); _backgroundColor = backgroundColor; _foregroundColor = foregroundColor; // Init Top Panel Panel panelTop = SceneObject.Instantiate <Panel>(_canvas); panelTop.Background.Color = _backgroundColor.Value; panelTop.RectTransform.Alignment = Alignment.TopHStretch; panelTop.RectTransform.Size = new Point(Renderer.ScreenWidth, 120); _scoreText = panelTop.AddComponent <Text>(); _scoreText.Alignment = Alignment.BottomLeft; _scoreText.Offset = new Point(10, -10); SetScore(0); _stageText = panelTop.AddComponent <Text>(); _stageText.Alignment = Alignment.BottomRight; _stageText.Offset = new Point(-10, -10); SetStage(0); // Init Bottom Panel Panel panelBottom = SceneObject.Instantiate <Panel>(_canvas); panelBottom.Background.Color = _backgroundColor.Value; panelBottom.RectTransform.Alignment = Alignment.BottomHStretch; panelBottom.RectTransform.Size = new Point(Renderer.ScreenWidth, 120); _eneryText = panelBottom.AddComponent <Text>(); _eneryText.Alignment = Alignment.TopLeft; _eneryText.Offset = new Point(10, 10); SetEnergy(100); _weaponText = panelBottom.AddComponent <Text>(); _weaponText.Alignment = Alignment.TopRight; _weaponText.Offset = new Point(-10, 10); SetWeapon(Weapon); _gamePausedDialogPanel = CreateDialogPanel(); _gameOverDialogPanel = CreateDialogPanel(); Text gameOverText = _gameOverDialogPanel.AddComponent <Text>(); gameOverText.FontName = FontName; gameOverText.Alignment = Alignment.Center; gameOverText.Offset = new Point(0, -Renderer.ScreenHeight * 0.15f); gameOverText.Content = "Game Over"; Text nameText = _gameOverDialogPanel.AddComponent <Text>(); nameText.FontName = FontName; nameText.Alignment = Alignment.Left; nameText.Offset = new Point(30, Renderer.ScreenHeight * 0.15f); nameText.Content = "Your name:"; _nameTextInput = SceneObject.Instantiate <TextInput>(_gameOverDialogPanel); _nameTextInput.RectTransform.Size = new Point(Renderer.ScreenWidth * 0.35f, 50); _nameTextInput.RectTransform.Alignment = Alignment.Center; _nameTextInput.RectTransform.Padding = new Padding(0, Renderer.ScreenHeight * 0.15f); _nameTextInput.Text.Content = Environment.UserName; _nameTextInput.Ctrl.OnSubmit += (s, e) => { // To ensure the text is not cleared and shown again next time e.Handled = true; ConfirmNameEntry(); }; Button confirmNameButton = SceneObject.Instantiate <Button>(_gameOverDialogPanel); confirmNameButton.RectTransform.Padding = new Padding(-90, Renderer.ScreenHeight * 0.15f); confirmNameButton.Ctrl.Text.Content = "OK"; confirmNameButton.Ctrl.OnPressed += () => { ConfirmNameEntry(); }; Text gamePausedText = _gamePausedDialogPanel.AddComponent <Text>(); gamePausedText.FontName = FontName; gamePausedText.Alignment = Alignment.Center; gamePausedText.Offset = new Point(0, -Renderer.ScreenHeight * 0.15f); gamePausedText.Content = "Game Paused"; Button resumeGameButton = SceneObject.Instantiate <Button>(_gamePausedDialogPanel); resumeGameButton.RectTransform.Padding = new Padding(-Renderer.ScreenWidth * 0.25f, Renderer.ScreenHeight * 0.15f); resumeGameButton.Ctrl.Text.Content = "Resume Game"; resumeGameButton.Ctrl.OnPressed += () => { if (ResumeGameClicked != null) { ResumeGameClicked(); } }; Button exitGameButton = SceneObject.Instantiate <Button>(_gamePausedDialogPanel); exitGameButton.RectTransform.Padding = new Padding(Renderer.ScreenWidth * 0.25f, Renderer.ScreenHeight * 0.15f); exitGameButton.Ctrl.Text.Content = "Exit Game"; exitGameButton.Ctrl.OnPressed += () => { if (GameExited != null) { GameExited(_nameTextInput.Text.Content, Score, false); } }; _canvas.ForEachComponent <Text>(c => { c.Color = _foregroundColor ?? new Color(); c.FontName = FontName; c.Height = HudFontHeight; }); // Overwrite previously set Text values gameOverText.Height = 128; gamePausedText.Height = 128; // Apply shared style between the 'Resume Game' and 'Exit Game' buttons _canvas.ForEach <Button>(x => { x.RectTransform.Size = new Point(Renderer.ScreenWidth * 0.26f, Renderer.ScreenWidth * 0.13f); x.Background.Color = Color.FromRGB(0, 0, 0.5f).WithAlpha(0.5f); x.RectTransform.Alignment = Alignment.Center; x.Ctrl.Text.Height = 32; }); // Overwrite previously set Button values confirmNameButton.RectTransform.Alignment = Alignment.Right; confirmNameButton.RectTransform.Size = new Point(120, 60); Hide(); }
public static void AddNewStyle(Popup popup, String subtitle, TextPanel kcPanel, List <IComponent> controls) { popup.background = new int[] { 255, 255, 255 }; var framePaddingPanel = new Panel(new BorderLayout(), Location.CENTER); framePaddingPanel.AddComponent(new Panel(null, Location.EAST, "pics/layout/bg_trend.png", 1, 10)); framePaddingPanel.AddComponent(new Panel(null, Location.WEST, "pics/layout/bg_trend.png", 1, 10)); framePaddingPanel.AddComponent(new Panel(null, Location.NORTH, "-", 10, 1)); framePaddingPanel.AddComponent(new Panel(null, Location.SOUTH, "-", 10, 1) { Background = new int[] { 235, 235, 255 } }); popup.AddComponent(framePaddingPanel); var baseFramePanel = new Panel(new BorderLayout(), Location.CENTER); framePaddingPanel.AddComponent(baseFramePanel); #region Controls var southOuterGridPanel = new Panel(new GridLayout(1, 1, 1, 1), Location.SOUTH) { Background = new int[] { 235, 235, 255 } }; baseFramePanel.AddComponent(southOuterGridPanel); var southFlowPanel = new Panel(new FlowLayout()); southOuterGridPanel.AddComponent(southFlowPanel); var southGridPanel = new Panel(new GridLayout(0, 1, 1, 1)); southFlowPanel.AddComponent(southGridPanel); foreach (var control in controls) { var controlPanel = new Panel(new BorderLayout(), Location.NONE); southGridPanel.AddComponent(controlPanel); controlPanel.AddComponent(control); } #endregion var borderLayoutPanel = new Panel(new BorderLayout(), Location.NORTH); baseFramePanel.AddComponent(borderLayoutPanel); #region Header #region Header Top Border var northPanelOuter = new Panel(new BorderLayout(), Location.NORTH); borderLayoutPanel.AddComponent(northPanelOuter); var northPanel = new Panel(new BorderLayout(), Location.NORTH); northPanelOuter.AddComponent(northPanel); northPanel.AddComponent(new Panel(new BorderLayout(), Location.WEST, "pics/layout/boxS_tl.png", 16, 16)); northPanel.AddComponent(new Panel(new BorderLayout(), Location.CENTER, "pics/layout/boxS_tc.png", 16, 16)); northPanel.AddComponent(new Panel(new BorderLayout(), Location.EAST, "pics/layout/boxS_tr.png", 16, 16)); #endregion #region Header Content Left Right borderLayoutPanel.AddComponent(new Panel(new BorderLayout(), Location.WEST, "pics/layout/boxS_cl.png", 16, 16)); borderLayoutPanel.AddComponent(new Panel(new BorderLayout(), Location.EAST, "pics/layout/boxS_cr.png", 16, 16)); #endregion #region Bottom Border var borderSouthPanel = new Panel(null, Location.SOUTH); borderLayoutPanel.AddComponent(borderSouthPanel); borderSouthPanel.AddComponent(new Panel(new BorderLayout(), Location.WEST, "pics/layout/boxS_bl.png", 16, 16)); borderSouthPanel.AddComponent(new Panel(new BorderLayout(), Location.CENTER, "pics/layout/boxS_bc.png", 16, 16)); borderSouthPanel.AddComponent(new Panel(new BorderLayout(), Location.EAST, "pics/layout/boxS_br.png", 16, 16)); #endregion #region Header Center Label var borderCenterPanel = new Panel(new GridLayout(0, 1, 1, 1), Location.CENTER); var borderCenterLabelPanel = new Panel(new BorderLayout(), Location.CENTER); borderCenterPanel.AddComponent(borderCenterLabelPanel); borderLayoutPanel.AddComponent(new Label(subtitle, Location.CENTER, 18, 'b') { Background = new int[] { 222, 222, 255 } }); #endregion #endregion #region Content var contentLayoutPanel = new Panel(new BorderLayout(), Location.CENTER); baseFramePanel.AddComponent(contentLayoutPanel); var contentCenterPanel = new Panel(new BorderLayout(), Location.CENTER, "-", 15, 1); contentLayoutPanel.AddComponent(contentCenterPanel); contentCenterPanel.AddComponent(new Panel(new BorderLayout(), Location.NORTH, "-", 4, 1)); var contentPanel = new Panel(new BorderLayout(), Location.CENTER); contentCenterPanel.AddComponent(contentPanel); contentPanel.AddComponent(kcPanel); contentCenterPanel.AddComponent(new Panel(new BorderLayout(), Location.EAST, "pics/layout/bg_trend.png", 1, 16)); contentCenterPanel.AddComponent(new Panel(new BorderLayout(), Location.WEST, "pics/layout/bg_trend.png", 1, 16)); #endregion }
public override void Play() { Global.CurrentScene = this; Global.DebugRenderEnabled = false; // // Contents // Content.LoadMenu(); //----------------------------- // Background //----------------------------- Entity entBack = CreateGameEntity(new Vector2(0, 0)); entBack.Name = "background"; Sprite sp = new Sprite(Content.backGround); sp.FitWindow = true; entBack.Add(sp); entPanel = CreateSceneEntity(new Vector2(150, 200)); //position of panel entPanel.Name = "panel"; position = entPanel.Get <Transform>().Position; //----------------------------- // Panel (menu type) //----------------------------- Panel menuPanel = new Panel(position, 300, 250, Color.BLANK); // // add a label on top // Label lbl = new Label(new Vector2(80, 10), "This is a Menu"); menuPanel.AddComponent(lbl); // // play button (position is with respect to the panel) // Button playBt = new Button(new Vector2(110, 40), 74, 35, "Play", -2, +5); playBt.Tag = 1; playBt.Image = Content.buttonEmpty; playBt.Click += ActionButton; menuPanel.AddComponent(playBt); // // Map button // Button setupBt = new Button(new Vector2(110, 85), 74, 35, "Options", -27, +5); setupBt.Tag = 2; setupBt.Image = Content.buttonEmpty; setupBt.Click += ActionButton; menuPanel.AddComponent(setupBt); // // Cards button // Button cardBt = new Button(new Vector2(110, 130), 74, 35, "Cards", -12, +5); cardBt.Tag = 3; cardBt.Image = Content.buttonEmpty; cardBt.Click += ActionButton; menuPanel.AddComponent(cardBt); // // Exit button // Button exitBt = new Button(new Vector2(110, 175), 74, 35, "Exit", -2, +5); exitBt.Tag = 4; exitBt.Image = Content.buttonEmpty; exitBt.Click += ExitButton; menuPanel.AddComponent(exitBt); entPanel.Add(menuPanel); }