public void OpenShop(Item i)
 {
     ShopPanel.ChosenItem = i;
     Controls.Add(ShopPanel);
     ShopPanel.BringToFront();
     ShopPanel.UpdateInfo();
     Invalidate();
 }
        public void ControlPanelUpdate()
        {
            ControlPanel.Controls.Clear();
            var panel = new Panel()
            {
                Size      = new Size(256, 32),
                BackColor = Color.Black,
            };

            var b = new Button()
            {
                ForeColor = Color.Goldenrod,
                Text      = "SHOP",
                Font      = new Font(FontFamily.GenericSansSerif, 16),
                AutoSize  = true,
                Dock      = DockStyle.Right,
            };

            b.Click += (sender, args) =>
            {
                Game.ChosenHero = Game.CurrentHero;
                StatPanelUpdate();
                ControlPanelUpdate();
                Controls.Add(ShopPanel);
                ShopPanel.BringToFront();
            };

            ///die while my turn
            panel.Controls.Add(new Label
            {
                ForeColor = Game.ChosenHero != null ?
                            Colors.PlayerLightColors[Game.Players.IndexOf(Game.ChosenHero.P) % Colors.count]
                    : Colors.PlayerLightColors[Game.Players.IndexOf(Game.CurrentPlayer) % Colors.count],
                BackColor = Game.ChosenHero == Game.CurrentHero || Game.ChosenHero == null ? Color.Black : Color.DarkSlateGray,
                Text      = Game.ChosenHero != null ? Game.ChosenHero.Name : Game.CurrentHero.Name,
                Font      = new Font(FontFamily.GenericSansSerif, 20),
                Dock      = DockStyle.Fill,
                TextAlign = ContentAlignment.MiddleLeft,
            });

            ControlPanel.Controls.Add(panel);
            if (Game.ChosenHero == Game.CurrentHero || Game.ChosenHero == null)
            {
                panel.Controls.Add(b);
            }

            if (Game.ChosenHero != null)
            {
                SkillPanel = new HeroSkillPanel(Game, Game.ChosenHero, this, ControlPanel.Width);
                ControlPanel.Controls.Add(SkillPanel);
            }
        }
        public ScreenForm(Game game)
        {
            MPainter = new MapPainter(game.Maze, this);
            Game     = game;

            StatPanel = new FlowLayoutPanel
            {
                Padding       = Padding.Empty,
                AutoSize      = true,
                AutoSizeMode  = AutoSizeMode.GrowAndShrink,
                Location      = new System.Drawing.Point(ClientSize.Width - (256 + 16), ClientSize.Height - (32 + 16)),
                Anchor        = (AnchorStyles.Right | AnchorStyles.Bottom),
                Size          = new Size(256, 32),
                BackColor     = Color.OrangeRed,
                FlowDirection = FlowDirection.BottomUp,
            };

            ControlPanel = new FlowLayoutPanel
            {
                Padding       = Padding.Empty,
                AutoSize      = true,
                AutoSizeMode  = AutoSizeMode.GrowAndShrink,
                Bounds        = new Rectangle(ClientSize.Width - 272, levelPanelSize + 16, 256, 0),
                BackColor     = Color.MidnightBlue,
                FlowDirection = FlowDirection.TopDown,
            };

            PerksPanel = new FlowLayoutPanel()
            {
                Location      = new System.Drawing.Point(ClientSize.Width - (256 + perksPanelSide), ClientSize.Height - (perksPanelSide + 24)),
                Anchor        = (AnchorStyles.Right | AnchorStyles.Bottom),
                Size          = new Size(0, perksPanelPadding * 2 + perksPanelSide),
                AutoSize      = true,
                FlowDirection = FlowDirection.RightToLeft,
                BackColor     = Color.OrangeRed,
            };

            var topPanel = new TableLayoutPanel
            {
                Dock      = DockStyle.Top,
                Height    = levelPanelSize,
                BackColor = Color.Black,
            };

            for (int i = 0; i < Game.Players.Count; i++)
            {
                topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f / Game.Players.Count));
            }

            PlayerPanels = CreatePlayerPanels(topPanel, Game.Players);

            View = new MapView(MPainter)
            {
                Dock = DockStyle.Fill
            };

            HeroPanel = new CurrentHeroPanel(Game.CurrentHero, this)
            {
                Size     = new Size(128, 128),
                Anchor   = AnchorStyles.Bottom | AnchorStyles.Left,
                Location = new System.Drawing.Point(32, ClientSize.Height - 160)
            };

            Controls.Add(HeroPanel);
            Controls.Add(ControlPanel);
            Controls.Add(StatPanel);
            Controls.Add(PerksPanel);
            Controls.Add(View);
            Controls.Add(topPanel);

            CenterOnPoint(Game.Maze.UnitPositions[Game.CurrentHero]);

            PlayerPanelUpdate();
            ControlPanelUpdate();
            StatPanelUpdate();

            SkillPanel = new HeroSkillPanel(Game, Game.CurrentHero, this, ControlPanel.Width);

            ShopPanel = new ShopPanel(Game.CurrentHero, this,
                                      new Rectangle(ClientSize.Width / 4, ClientSize.Height / 4, ClientSize.Width / 2, ClientSize.Height / 2));

            SizeChanged += (sender, args) =>
            {
                Controls.Remove(ShopPanel);
                Controls.Remove(SkillPanel);
                //StatPanel.Bounds = new Rectangle(ClientSize.Width - 272, ClientSize.Height - 528, 256, 512);
                MPainter.ResizeMap(Size);
                ResizePlayerPanels(PlayerPanels);

                SkillPanel = new HeroSkillPanel(Game, Game.CurrentHero, this, ControlPanel.Width);
                ShopPanel  = new ShopPanel(Game.CurrentHero, this,
                                           //new Rectangle(ClientSize.Width / 4, ClientSize.Height / 4, ClientSize.Width / 2, ClientSize.Height / 2));
                                           new Rectangle(ClientSize.Width / 2 - 480, ClientSize.Height / 2 - 300, 960, 600));
            };
        }
        public void StatPanelUpdate()
        {
            StatPanel.Controls.Clear();
            PerksPanel.Controls.Clear();
            PerksPanel.Size     = new Size(0, perksPanelPadding * 2 + perksPanelSide);
            PerksPanel.Location = new System.Drawing.Point(ClientSize.Width - (256 + perksPanelSide),
                                                           ClientSize.Height - (perksPanelSide + 24));
            var button = new Button()
            {
                Width     = 256,
                Height    = 64,
                Text      = "END TURN",
                Font      = new Font(FontFamily.GenericSerif, 32),
                ForeColor = Color.White,
                BackColor = Colors.PlayerDarkColors
                            [Game.Players.IndexOf(Game.CurrentPlayer) % Colors.count]
            };

            if (Game.Winner == null)
            {
                button.Click += (sender, args) =>
                {
                    EveryUpdate();
                    Controls.Remove(ShopPanel);
                    Game.EndTurn();
                    PlayerPanelUpdate();
                    StatPanelUpdate();
                    Controls.Remove(HeroPanel);
                    HeroPanel = new CurrentHeroPanel(Game.CurrentHero, this)
                    {
                        Size     = new Size(128, 128),
                        Anchor   = AnchorStyles.Bottom | AnchorStyles.Left,
                        Location = new System.Drawing.Point(32, ClientSize.Height - 160)
                    };
                    Controls.Add(HeroPanel);
                    HeroPanel.BringToFront();
                    ShopPanel = new ShopPanel(Game.CurrentHero, this,
                                              new Rectangle(ClientSize.Width / 2 - 480, ClientSize.Height / 2 - 300, 960, 600));

                    SkillPanel = new HeroSkillPanel(Game, Game.CurrentHero, this, ControlPanel.Width);
                    CenterOnPoint(Game.Maze.UnitPositions[Game.CurrentHero]);
                    ControlPanelUpdate();
                    MapUpdate();
                }
            }
            ;
            else
            {
                button.Text   = "END GAME";
                button.Click += (sender, args) => this.Close();
            }
            StatPanel.Controls.Add(button);

            if (Game.ChosenHero != null)
            {
                var h = new HeroInfo(Game.ChosenHero)
                {
                    Width = StatPanel.Width - 6,
                };
                StatPanel.Controls.Add(h);

                StatPanel.Controls.Add(new Label
                {
                    BackColor = Color.Black,
                    ForeColor = Colors.PlayerLightColors
                                [Game.Players.IndexOf(Game.ChosenHero.P) % Colors.count],
                    Text      = Game.ChosenHero.Name,
                    Font      = new Font(FontFamily.GenericSansSerif, 16),
                    Width     = StatPanel.Width - 6,
                    Height    = 32,
                    TextAlign = ContentAlignment.MiddleCenter
                });

                foreach (var perk in Game.ChosenHero.Perks.Where(p => p.Name != "Perk"))
                {
                    PerksPanel.Controls.Add(new Label
                    {
                        AutoSize  = true,
                        BackColor = Color.Black,
                        Text      = double.IsNaN(perk.Number(Game.ChosenHero)) ?
                                    perk.Name : perk.Name + "\n" + perk.Number(Game.ChosenHero),
                        MinimumSize = new Size(perksPanelSide, perksPanelSide),
                        MaximumSize = new Size(1000, perksPanelSide),
                        Font        = new Font(FontFamily.GenericSansSerif, 16),
                        ForeColor   = Color.Aqua,
                        TextAlign   = ContentAlignment.MiddleCenter,
                        Margin      = new Padding(perksPanelPadding)
                    });
                }
            }
            StatPanel.Refresh();
            PerksPanel.Refresh();
        }