示例#1
0
        private void AddSkillsToGroup(string group, List <int> skills)
        {
            MultiSelectionShrinkbox box = new MultiSelectionShrinkbox(0, 0, _container.Width - 30, group, 0, 6, false, true)
            {
                CanMove    = true,
                IsEditable = true
            };

            box.EditStateStart += (ss, e) =>
            {
                Control p     = _container;
                var     items = p.FindControls <ScrollAreaItem>().SelectMany(s => s.Children.OfType <MultiSelectionShrinkbox>());

                foreach (var item in items)
                {
                    foreach (EditableLabel c in item.FindControls <EditableLabel>())
                    {
                        c.SetEditable(false);
                    }
                }
            };

            box.EditStateEnd += (ss, e) =>
            {
                if (!string.IsNullOrWhiteSpace(e.BackupText) && !string.IsNullOrWhiteSpace(e.Text))
                {
                    SkillsGroupManager.ReplaceGroup(e.BackupText, e.Text);
                }
            };

            _container.Add(box);

            SkillControl[] controls = new SkillControl[skills.Count];
            int            idx      = 0;

            foreach (var skill in skills)
            {
                var c = new SkillControl(skill, box.Width - 15, group, box)
                {
                    Width = box.Width - 15
                };
                controls[idx++]          = c;
                _allSkillControls[skill] = c;
            }

            box.SetItemsValue(controls);

            _boxes.Add(box);
        }
            protected override void OnMouseOver(int x, int y)
            {
                if (CanMove)
                {
                    return;
                }

                var c = Engine.UI.MouseOverControl;

                if (c != null && c != this)
                {
                    var p = c.Parent;

                    while (p != null)
                    {
                        if (p is MultiSelectionShrinkbox box)
                        {
                            if (box.LabelText != Group)
                            {
                                SkillsGroupManager.MoveSkillToGroup(Group, box.LabelText, _skillIndex);

                                int index = -1;

                                foreach (SkillControl skillControl in box.Items.OfType <SkillControl>())
                                {
                                    index++;

                                    if (skillControl._skillIndex > _skillIndex)
                                    {
                                        break;
                                    }
                                }

                                _parent.Remove(this);
                                box.AddItem(this, index);

                                _parent = box;
                                Group   = box.LabelText;
                            }

                            break;
                        }

                        p = p.Parent;
                    }
                }

                if (!(c?.RootParent is StandardSkillsGump))
                {
                    uint serial = (uint)(World.Player + _skillIndex + 1);

                    if (Engine.UI.GetGump <SkillButtonGump>(serial) != null)
                    {
                        Engine.UI.Remove <SkillButtonGump>(serial);
                    }

                    SkillButtonGump skillButtonGump = new SkillButtonGump(World.Player.Skills[_skillIndex], Mouse.Position.X, Mouse.Position.Y);
                    Engine.UI.Add(skillButtonGump);
                    Rectangle rect = FileManager.Gumps.GetTexture(0x24B8).Bounds;
                    Engine.UI.AttemptDragControl(skillButtonGump, new Point(Mouse.Position.X + (rect.Width >> 1), Mouse.Position.Y + (rect.Height >> 1)), true);
                }

                base.OnMouseOver(x, y);
            }
            public SkillControl(int skillIndexIndex, int maxWidth, string group, MultiSelectionShrinkbox parent)
            {
                AcceptMouseInput = true;
                CanMove          = true;

                _parent = parent;

                Skill skill = World.Player.Skills[skillIndexIndex];

                _skillIndex = skillIndexIndex;

                if (skill.IsClickable)
                {
                    Button button = new Button(0, 0x0837, 0x0838, 0x0837);
                    button.MouseUp += (ss, e) => { GameActions.UseSkill(skillIndexIndex); };
                    Add(button);
                }

                Label label = new Label(skill.Name, false, 0x0288, maxWidth, 9)
                {
                    X = 12
                };

                Add(label);

                _labelValue = new Label(skill.Value.ToString("F1"), false, 0x0288, maxWidth - 10, 9, align: TEXT_ALIGN_TYPE.TS_RIGHT);
                Add(_labelValue);


                _lock = new GumpPic(maxWidth - 8, 1, GetLockValue(skill.Lock), 0)
                {
                    AcceptMouseInput = true
                };

                _lock.MouseUp += (sender, e) =>
                {
                    byte slock = (byte)skill.Lock;

                    if (slock < 2)
                    {
                        slock++;
                    }
                    else
                    {
                        slock = 0;
                    }

                    skill.Lock = (Lock)slock;

                    GameActions.ChangeSkillLockStatus((ushort)skill.Index, slock);

                    ushort graphic = GetLockValue(skill.Lock);
                    _lock.Graphic = graphic;
                    _lock.Texture = FileManager.Gumps.GetTexture(graphic);
                };
                Add(_lock);

                WantUpdateSize = false;

                Width  = maxWidth;
                Height = label.Height;
                Group  = group;
            }