public HeroSkillPanel(Game g, Hero h, ScreenForm form, int width)
        {
            Game = g;
            Hero = h;

            Skills = new Dictionary <Skill, Panel>();

            AutoSize     = true;
            AutoSizeMode = AutoSizeMode.GrowOnly;
            Width        = width - 6;

            FlowDirection = FlowDirection.TopDown;

            foreach (var skill in Hero.Skills)
            {
                var panel = new Panel();
                panel.Width     = width - 12;
                panel.BackColor = (Game.CurrentHero == Hero && skill.Availiable(Hero)) ? Color.Black : Color.DarkSlateGray;

                var skillName = new Label()
                {
                    Dock        = DockStyle.Top,
                    Text        = skill.Name,
                    TextAlign   = ContentAlignment.MiddleLeft,
                    ForeColor   = Color.Aquamarine,
                    Font        = new Font(FontFamily.GenericSerif, 24),
                    Width       = width - 12,
                    BorderStyle = BorderStyle.None,
                    AutoSize    = true,
                };

                var skillExp = new Label()
                {
                    Dock        = DockStyle.Top,
                    Text        = skill.Explanation(),
                    TextAlign   = ContentAlignment.MiddleLeft,
                    ForeColor   = Color.White,
                    BorderStyle = BorderStyle.None,
                    MaximumSize = new Size(width - 12, 1000),
                    AutoSize    = true,
                };

                panel.Controls.Add(skillExp);
                panel.Controls.Add(skillName);

                if (skill.Timer > 0)
                {
                    panel.Controls.Add(new PictureBox
                    {
                        Size  = new Size(32, 32),
                        Image = resources.IconLoader.GetIcons(new Size(32, 32))["CDR"],
                        Dock  = DockStyle.Right,
                    });

                    panel.Controls.Add(new Label
                    {
                        Text      = skill.Timer.ToString(),
                        AutoSize  = true,
                        Dock      = DockStyle.Right,
                        Font      = new Font(FontFamily.GenericSansSerif, 24),
                        ForeColor = Color.Yellow,
                    });
                }

                panel.Height = skillName.Height + skillExp.Height;

                panel.BringToFront();

                if (Game.CurrentHero == Hero)
                {
                    void OnPanelOnClick(object sender, EventArgs args)
                    {
                        Hero.UseSkill(Hero.Skills.IndexOf(skill));
                        form.ControlPanelUpdate();
                        form.StatPanelUpdate();
                        form.MapUpdate();
                        form.PlayerPanelUpdate();
                    }

                    panel.Click     += OnPanelOnClick;
                    skillName.Click += OnPanelOnClick;
                    skillExp.Click  += OnPanelOnClick;
                }
                Controls.Add(panel);
                Skills.Add(skill, panel);
            }
        }
Ejemplo n.º 2
0
        public ShopPanel(Hero hero, ScreenForm form, Rectangle borders)
        {
            GetOptionsWidth  = () => Width * 2 / 10;
            GetChoosingWidth = () => Width * 3 / 10;
            GetInfoWidth     = () => Width * 5 / 10;

            Items = new List <Item>();

            Customer   = hero;
            Shop       = hero.S;
            ChosenItem = Shop.Items[0];
            Bounds     = borders;

            OptionsPanel = new TableLayoutPanel()
            {
                Location  = new Point(0, 0),
                BackColor = Color.Black,
            };
            OptionsPanel.Size        = new Size(GetOptionsWidth(), Height);
            OptionsPanel.RowCount    = 8;
            OptionsPanel.ColumnCount = 2;

            for (int t = 0; t <= 3; ++t)
            {
                var tier = t;
                var b    = new Button()
                {
                    Size      = new Size(GetOptionsWidth() / OptionsPanel.ColumnCount, Height / OptionsPanel.RowCount),
                    Margin    = new Padding(0),
                    Padding   = new Padding(0),
                    Text      = "T" + (tier).ToString(),
                    Font      = new Font(FontFamily.GenericSansSerif, 36),
                    ForeColor = Colors.ItemTierColors[tier]
                };
                b.Click += (sender, args) =>
                {
                    Items = Shop.GetItemsWithTier(tier);
                    UpdateItems();
                };
                OptionsPanel.Controls.Add(b);
            }

            for (var r = (int)StatType.MaxHP; r < (int)StatType.STOP; ++r)
            {
                var stat = r;
                var b    = new Button()
                {
                    Size    = new Size(GetOptionsWidth() / OptionsPanel.ColumnCount, Height / OptionsPanel.RowCount),
                    Margin  = new Padding(0),
                    Padding = new Padding(0),
                    //Text = "+" + ((StatType)stat).ToString(),
                    Image = IconLoader.GetIcon((StatType)r, new Size(64, 64)),
                };
                b.Click += (sender, args) =>
                {
                    Items = Shop.GetItemsWithSortedStat((StatType)stat);
                    UpdateItems();
                };
                OptionsPanel.Controls.Add(b);
            }

            ItemChoosingPanel = new FlowLayoutPanel()
            {
                Location      = new Point(GetOptionsWidth(), 0),
                FlowDirection = FlowDirection.LeftToRight,
                AutoScroll    = true,
            };
            ItemChoosingPanel.Size = new Size(GetChoosingWidth(), Height);

            InfoPanel = new FlowLayoutPanel()
            {
                Location  = new Point(GetOptionsWidth() + GetChoosingWidth(), 0),
                BackColor = Color.Black
            };
            InfoPanel.Size = new Size(GetInfoWidth(), Height - 128);

            BuyButton = new Button()
            {
                Font = new Font(FontFamily.GenericSansSerif, 32),
            };
            BuyButton.Size     = new Size(GetInfoWidth(), 128);
            BuyButton.Location = new Point(GetOptionsWidth() + GetChoosingWidth(), Height - 128);
            BuyButton.Click   += (sender, args) =>
            {
                Customer.BuyItem(ChosenItem);
                form.StatPanelUpdate();
                form.PlayerPanelUpdate();
            };

            ExplanationPanel             = new FlowLayoutPanel();
            ExplanationPanel.BackColor   = Color.Black;
            ExplanationPanel.MinimumSize = new Size(GetInfoWidth(), 36);
            ExplanationPanel.AutoSize    = true;

            RecipePanel = new TableLayoutPanel()
            {
                RowStyles = { new RowStyle(SizeType.AutoSize) }
            };
            RecipePanel.Size = new Size(GetInfoWidth() / 2, 64);

            UpgradePanel = new TableLayoutPanel()
            {
                RowStyles = { new RowStyle(SizeType.AutoSize) }
            };
            UpgradePanel.Size = new Size(GetInfoWidth() / 2, 64);

            Controls.Add(OptionsPanel);
            Controls.Add(ItemChoosingPanel);
            Controls.Add(InfoPanel);
            Controls.Add(BuyButton);

            UpdateInfo();

            /*
             * SizeChanged += (sender, args) =>
             * {
             *  RecipePanel.Size = new Size(Width * 3 / 10, 64);
             *  ExplanationPanel.Size = new Size(Width * 3 / 10, 36);
             *  ItemChoosingPanel.Size = new Size(Width * 7 / 10, Height);
             *  BuyButton.Size = new Size(Width * 3 / 10, 128);
             *  UpdateInfo();
             * };
             */
        }