Beispiel #1
0
        public StatsPanel(Model.Character c)
        {
            character = c;
            name.Text = character.name;
            vitals    = new Vitals(character);

            Width = 200;

            foreach (var n in Model.Character.stat_names)
            {
                var stat = new Stat(n);
                stat.value.Value   = character.stats[n];
                stat.value.Change += v => { character.stats[n] = v; vitals.Update(); };
                stats.Add(stat);
            }
            foreach (var s in character.skills)
            {
                AddSkill(s.Key, s.Value);
            }
            foreach (var item in character.items)
            {
                items.Add(new Item(item));
            }
            items.Add(new Item(new Model.ItemInstance {
                name = "Item of ultimate test"
            }));

            var add_skill = new PropertyAdder();
            var add_item  = new PropertyAdder();

            Children.Add(name);
            Children.Add(vitals);
            Children.Add(stats);
            Children.Add(new Label {
                Content = "Skills", HorizontalAlignment = HorizontalAlignment.Center, FontSize = 14
            });
            Children.Add(skills);
            Children.Add(add_skill);
            Children.Add(new Label {
                Content = "Items", HorizontalAlignment = HorizontalAlignment.Center, FontSize = 14
            });
            Children.Add(items);
            Children.Add(add_item);

            add_skill.Added += (name, accept) =>
            {
                var added = AddSkill(name, 0);
                if (added != null)
                {
                    added.value.Focus();
                }
                else
                {
                    accept.accepted = false;
                }
            };
            add_item.Added += (name, accept) =>
            {
                var item = new Item(new Model.ItemInstance {
                    name = name
                });
                items.Add(item);
            };
            name.TextChanged += (s, e) =>
            {
                if (character == null)
                {
                    return;
                }
                character.name = name.Text;
                ((CharacterPanel)Parent).Update(character);
            };
        }