/// <summary>
        /// Add custom attack button and squad list
        /// </summary>
        public static void SetupPanel(CharacterOverviewUI panel)
        {
            const string AttackLbl = "Attack";
            const string MoveToLbl = "Move To";
            const string ListItemFormat = "{0} ({1})";

            var controls = panel.Controls.Where(c => c is ClipBox).Single().Controls;
            var oldAttackBtn = controls.Where(c => c.Text == AttackLbl).SingleOrDefault();

            if (oldAttackBtn == null)
                return;

            panel.Remove(oldAttackBtn);
            oldAttackBtn = null;

            var target = (Character)panelTarget.GetValue(panel);
            var moveToBtn = controls.Where(c => c.Text == MoveToLbl).SingleOrDefault();
            var squadNames = GnomanEmpire.Instance.Fortress.Military.Squads.Select((s, i) => new
                                                                                             {
                                                                                                 Index = i,
                                                                                                 Text = string.Format(ListItemFormat, s.Name, s.Members.Count(m => m != null)),
                                                                                                 CanAttack = s.Formation.CarryOutAttackOrders
                                                                                             })
                                                                           .Where(s => s.CanAttack)
                                                                           .OrderBy(s => s.Text);

            var newAttackBtn = new Button(panel.Manager);
            newAttackBtn.Init();
            newAttackBtn.Margins = new Margins(4, 0, 4, 0);
            newAttackBtn.Left = moveToBtn.Left + moveToBtn.Width + moveToBtn.Margins.Right + newAttackBtn.Margins.Left;
            newAttackBtn.Top = moveToBtn.Top;
            newAttackBtn.Text = "Attack";
            newAttackBtn.Width = 125;

            LoweredPanel loweredPanel = new LoweredPanel(panel.Manager);
            loweredPanel.Init();
            loweredPanel.Left = newAttackBtn.Left + newAttackBtn.Width + newAttackBtn.Margins.Right + loweredPanel.Margins.Left;
            loweredPanel.Top = moveToBtn.Top;
            loweredPanel.Width = 235;
            loweredPanel.Height = panel.ClientHeight - loweredPanel.Top - loweredPanel.Margins.Bottom;
            loweredPanel.Anchor = Anchors.Vertical | Anchors.Horizontal;
            loweredPanel.AutoScroll = true;
            loweredPanel.Passive = true;
            loweredPanel.CanFocus = false;

            CheckBoxTree tree = new CheckBoxTree(panel.Manager);
            tree.Init();
            tree.Left = tree.Margins.Left;
            tree.Top = tree.Margins.Top;
            tree.Expanded = true;
            tree.Width = loweredPanel.Width;
            tree.Anchor = Anchors.Top | Anchors.Horizontal;
            tree.Text = Military.AllSquadsDisplay;

            foreach (var squad in squadNames)
                tree.AddChild(CreateCheckbox(panel.Manager, squad.Text, squad.Index));

            tree.EvaluateState();
            panel.Add(loweredPanel);
            loweredPanel.Add(tree);

            newAttackBtn.Click += (object sender, Game.GUI.Controls.EventArgs e) =>
            {
                GnomanEmpire.Instance.Fortress.Military.AddAttackTarget(target);    // For save compatibility
                var checkBoxes = tree.Controls.Where(c => c is ClipBox).Single().Controls.Where(c => c is CheckBox && ((CheckBox)c).Checked && c.Tag != null);
                military.AddTarget(checkBoxes.Select(c => (int)c.Tag), target);
            };

            panel.Add(newAttackBtn);
        }
Exemple #2
0
        /// <summary>
        /// Add custom attack button and squad list
        /// </summary>
        public static void SetupPanel(CharacterOverviewUI panel)
        {
            const string AttackLbl      = "Attack";
            const string MoveToLbl      = "Move To";
            const string ListItemFormat = "{0} ({1})";

            var controls     = panel.Controls.Where(c => c is ClipBox).Single().Controls;
            var oldAttackBtn = controls.Where(c => c.Text == AttackLbl).SingleOrDefault();

            if (oldAttackBtn == null)
            {
                return;
            }

            panel.Remove(oldAttackBtn);
            oldAttackBtn = null;

            var target     = (Character)panelTarget.GetValue(panel);
            var moveToBtn  = controls.Where(c => c.Text == MoveToLbl).SingleOrDefault();
            var squadNames = GnomanEmpire.Instance.Fortress.Military.Squads.Select((s, i) => new
            {
                Index     = i,
                Text      = string.Format(ListItemFormat, s.Name, s.Members.Count(m => m != null)),
                CanAttack = s.Formation.CarryOutAttackOrders
            })
                             .Where(s => s.CanAttack)
                             .OrderBy(s => s.Text);

            var newAttackBtn = new Button(panel.Manager);

            newAttackBtn.Init();
            newAttackBtn.Margins = new Margins(4, 0, 4, 0);
            newAttackBtn.Left    = moveToBtn.Left + moveToBtn.Width + moveToBtn.Margins.Right + newAttackBtn.Margins.Left;
            newAttackBtn.Top     = moveToBtn.Top;
            newAttackBtn.Text    = "Attack";
            newAttackBtn.Width   = 125;

            LoweredPanel loweredPanel = new LoweredPanel(panel.Manager);

            loweredPanel.Init();
            loweredPanel.Left       = newAttackBtn.Left + newAttackBtn.Width + newAttackBtn.Margins.Right + loweredPanel.Margins.Left;
            loweredPanel.Top        = moveToBtn.Top;
            loweredPanel.Width      = 235;
            loweredPanel.Height     = panel.ClientHeight - loweredPanel.Top - loweredPanel.Margins.Bottom;
            loweredPanel.Anchor     = Anchors.Vertical | Anchors.Horizontal;
            loweredPanel.AutoScroll = true;
            loweredPanel.Passive    = true;
            loweredPanel.CanFocus   = false;

            CheckBoxTree tree = new CheckBoxTree(panel.Manager);

            tree.Init();
            tree.Left     = tree.Margins.Left;
            tree.Top      = tree.Margins.Top;
            tree.Expanded = true;
            tree.Width    = loweredPanel.Width;
            tree.Anchor   = Anchors.Top | Anchors.Horizontal;
            tree.Text     = Military.AllSquadsDisplay;

            foreach (var squad in squadNames)
            {
                tree.AddChild(CreateCheckbox(panel.Manager, squad.Text, squad.Index));
            }

            tree.EvaluateState();
            panel.Add(loweredPanel);
            loweredPanel.Add(tree);

            newAttackBtn.Click += (object sender, Game.GUI.Controls.EventArgs e) =>
            {
                GnomanEmpire.Instance.Fortress.Military.AddAttackTarget(target);    // For save compatibility
                var checkBoxes = tree.Controls.Where(c => c is ClipBox).Single().Controls.Where(c => c is CheckBox && ((CheckBox)c).Checked && c.Tag != null);
                military.AddTarget(checkBoxes.Select(c => (int)c.Tag), target);
            };

            panel.Add(newAttackBtn);
        }