示例#1
0
        private void RemoveComponentImmediate(GameComponent component)
        {
            if (!Components.ContainsKey(component.GlobalID))
            {
                return;
            }

            Components.Remove(component.GlobalID);
            if (component is IUpdateableComponent)
            {
                var type = component.GetType();
                if (UpdateableComponents.ContainsKey(type))
                {
                    UpdateableComponents[type].Remove(component as IUpdateableComponent);
                }
            }
            if (component is IRenderableComponent)
            {
                RenderableComponents.Remove(component as IRenderableComponent);
            }

            foreach (var child in component.GetAllChildrenRecursive())
            {
                RemoveComponentImmediate(child);
            }
        }
示例#2
0
 private void AddComponentImmediate(GameComponent component)
 {
     if (Components.ContainsKey(component.GlobalID) && Components[component.GlobalID] != component)
     {
         throw new IndexOutOfRangeException("Component was added that already exists.");
     }
     else if (!Components.ContainsKey(component.GlobalID))
     {
         Components[component.GlobalID] = component;
         if (component is IUpdateableComponent)
         {
             var type = component.GetType();
             if (!UpdateableComponents.ContainsKey(type))
             {
                 UpdateableComponents.Add(type, new List <IUpdateableComponent>());
             }
             UpdateableComponents[type].Add(component as IUpdateableComponent);
         }
         if (component is IRenderableComponent)
         {
             RenderableComponents.Add(component as IRenderableComponent);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Adds the child if it has not been added already.
        /// </summary>
        /// <param name="child">The child.</param>
        public GameComponent AddChild(GameComponent child)
        {
            if (child == this)
            {
                throw new InvalidOperationException("Object added to itself");
            }
            lock (Children)
            {
                global::System.Diagnostics.Debug.Assert(child.Parent == null, "Child was already added to another component. Child is a " + child.GetType().Name);

                Children.Add(child);

                if (this != Manager.RootComponent)
                {
                    child.Active    = Active;
                    child.IsVisible = IsVisible;
                    child.IsDead    = IsDead;
                }

                child.Parent = this;
            }

            return(child);
        }
        public override void Construct()
        {
            Border      = "border-one";
            Font        = "font10";
            OnConstruct = (sender) =>
            {
                sender.Root.RegisterForUpdate(sender);

                AddChild(new Widget
                {
                    AutoLayout         = AutoLayout.DockBottom,
                    MinimumSize        = new Point(0, 32),
                    Text               = "CLOSE",
                    ChangeColorOnHover = true,
                    OnClick            = (sender1, args) => sender.Close()
                });

                ComponentProperties = AddChild(new Widget
                {
                    AutoLayout  = AutoLayout.DockBottom,
                    MinimumSize = new Point(0, 128),
                });

                ListView = AddChild(new WidgetListView
                {
                    AutoLayout = AutoLayout.DockFill,
                    SelectedItemForegroundColor = new Vector4(0, 0, 0, 1),
                    ChangeColorOnSelected       = false,
                    Border     = null,
                    ItemHeight = 24
                }) as WidgetListView;

                ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used.
            };

            OnUpdate = (sender, time) =>
            {
                if (sender.Hidden)
                {
                    return;
                }
                if (SelectedEntity == null)
                {
                    SelectedComponent = null;
                    ListView.ClearItems();
                    return;
                }

                var components = SelectedEntity.EnumerateAll();

                int i = 0;
                ListView.ClearItems();
                foreach (var component in components)
                {
                    i++;
                    var tag        = component.GuiTag as Widget;
                    var lambdaCopy = component;

                    if (tag != null)
                    {
                        ListView.AddItem(tag);
                    }
                    else
                    {
                        #region Create gui row

                        tag = Root.ConstructWidget(new Widget
                        {
                            Text              = component.GetType().Name,
                            MinimumSize       = new Point(0, 16),
                            Padding           = new Margin(0, 0, 4, 4),
                            TextVerticalAlign = VerticalAlign.Center,
                            Tag = lambdaCopy
                        });

                        tag.OnClick = (sender1, args) =>
                        {
                            if (tag.IsAnyParentHidden())
                            {
                                return;
                            }
                            SelectedComponent = lambdaCopy;
                        };

                        #endregion

                        component.GuiTag = tag;
                        ListView.AddItem(tag);
                    }
                }

                ListView.Invalidate();

                if (SelectedComponent != null)
                {
                    Drawer3D.DrawBox(SelectedComponent.GetBoundingBox(), Color.White, 0.1f, true);
                    ComponentProperties.Text = SelectedComponent.GetType().Name
                                               + "\n" + SelectedComponent.Position.ToString()
                                               + "\nBB Extents: " + SelectedComponent.BoundingBoxSize.ToString()
                                               + "\nBB Offset: " + SelectedComponent.LocalBoundingBoxOffset.ToString();
                }
                else
                {
                    ComponentProperties.Text = "";
                }
            };

            base.Construct();
        }