コード例 #1
0
 static public ContextMenuStrip Get(ISceneDecorator target)
 {
     _target = target;
     foreach (ToolStripMenuItem item in _menu.Items)
     {
         item.Checked = target.ContainsDecoration((Type)item.Tag);
     }
     return(_menu);
 }
コード例 #2
0
        public void Build()
        {
            Core.IBreath src = this.Tag;
            _node.Text = src.ToString();
            Core.IEntry entry = src as Core.IEntry;

            // entry
            if (entry != null)
            {
                ISceneDecorator deco  = DecoratorFactory.GetEntryDecorator(entry);
                string          image = (entry.Enabled && entry.IsVisible()) ? "entry.png" : "entry_gray.png";
                _node.ImageKey         = image;
                _node.SelectedImageKey = image;
            }

            // scene
            if (entry != null)
            {
                TreeNode node = this.Find("scene");
                if (node == null)
                {
                    node = _node.Nodes.Insert(
                        0, "scene", "描画情報", "scene.png", "scene.png"
                        );
                }
                ISceneDecorator elm = entry.GetElement <ISceneDecorator>();
                node.Tag = elm;
                node.Nodes.Clear();
                string icon = "decoration.png";
                foreach (IDecoration d in elm.Decorations)
                {
                    string   name = d.GetType().Name;
                    TreeNode dec  = node.Nodes.Add(name, name, icon, icon);
                    dec.Tag = d;
                }
            }

            // entity
            if (entry != null)
            {
                TreeNode node = this.Find("entity");
                if (entry.Entity != null)
                {
                    string name = entry.Entity.GetType().Name;
                    if (node == null)
                    {
                        node = _node.Nodes.Insert(
                            1, "entity", name, "entity.png", "entity.png");
                    }
                    else if (node.Text != name)
                    {
                        node.Text = name;
                    }
                    node.Tag = entry.Entity;
                }
                else if (node != null)
                {
                    _node.Nodes.Remove(node);
                }
            }

            // 不要な TreeNode を削除
            {
                List <TreeNode> removing = new List <TreeNode>();
                foreach (TreeNode node in _node.Nodes)
                {
                    if (node.Name == "scene")
                    {
                        continue;
                    }
                    if (node.Name == "entity")
                    {
                        continue;
                    }
                    TreeNodeBuilder tnb = (TreeNodeBuilder)node.Tag;
                    Core.IEntry     e   = tnb.Tag as Core.IEntry;
                    if (e == null || !this.SubEntries.Contains(e.ID))
                    {
                        removing.Add(node);
                    }
                }
                foreach (TreeNode node in removing)
                {
                    _node.Nodes.Remove(node);
                }
            }
        }