コード例 #1
0
ファイル: EntityConnectable.cs プロジェクト: dsmo7206/Lemma
		public static void AttachEditorComponents(Entity entity, string name, Property<Entity.Handle> target)
		{
			entity.Add(name, target);
			if (entity.EditorSelected != null)
			{
				Transform transform = entity.Get<Transform>("Transform");

				LineDrawer connectionLines = new LineDrawer { Serialize = false };
				connectionLines.Add(new Binding<bool>(connectionLines.Enabled, entity.EditorSelected));

				connectionLines.Add(new NotifyBinding(delegate()
				{
					connectionLines.Lines.Clear();
					Entity targetEntity = target.Value.Target;
					if (targetEntity != null)
					{
						Transform targetTransform = targetEntity.Get<Transform>("Transform");
						if (targetTransform != null)
						{
							connectionLines.Lines.Add
							(
								new LineDrawer.Line
								{
									A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
									B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(targetTransform.Position, connectionLineColor)
								}
							);
						}
					}
				}, transform.Position, target, entity.EditorSelected));

				entity.Add(connectionLines);
			}
		}
コード例 #2
0
ファイル: EntityConnectable.cs プロジェクト: sparker/Lemma
		public static void AttachEditorComponents(Entity result, ListProperty<Entity.Handle> target)
		{
			Transform transform = result.Get<Transform>();

			Property<bool> selected = result.GetOrMakeProperty<bool>("EditorSelected");

			Command<Entity> toggleEntityConnected = new Command<Entity>
			{
				Action = delegate(Entity entity)
				{
					if (target.Contains(entity))
						target.Remove(entity);
					else if (entity != result)
						target.Add(entity);
				}
			};
			result.Add("ToggleEntityConnected", toggleEntityConnected);

			LineDrawer connectionLines = new LineDrawer { Serialize = false };
			connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

			Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
			ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, target, delegate(Entity.Handle entity)
			{
				return new LineDrawer.Line
				{
					A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
					B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(entity.Target.Get<Transform>().Position, connectionLineColor)
				};
			}, x => x.Target != null && x.Target.Active);
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, selected));
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, () => selected, transform.Position));
			connectionLines.Add(connectionBinding);
			result.Add(connectionLines);
		}
コード例 #3
0
ファイル: EntityConnectable.cs プロジェクト: sparker/Lemma
		public static void AttachEditorComponents(Entity result, Property<Entity.Handle> target)
		{
			Transform transform = result.Get<Transform>();

			Property<bool> selected = result.GetOrMakeProperty<bool>("EditorSelected");
			selected.Serialize = false;

			Command<Entity> toggleEntityConnected = new Command<Entity>
			{
				Action = delegate(Entity entity)
				{
					if (target.Value.Target == entity)
						target.Value = null;
					else if (entity != result)
						target.Value = entity;
				}
			};
			result.Add("ToggleEntityConnected", toggleEntityConnected);

			LineDrawer connectionLines = new LineDrawer { Serialize = false };
			connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

			Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);

			connectionLines.Add(new NotifyBinding(delegate()
			{
				connectionLines.Lines.Clear();
				Entity targetEntity = target.Value.Target;
				if (targetEntity != null)
				{
					connectionLines.Lines.Add
					(
						new LineDrawer.Line
						{
							A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
							B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(targetEntity.Get<Transform>().Position, connectionLineColor)
						}
					);
				}
			}, transform.Position, target, selected));

			result.Add(connectionLines);
		}
コード例 #4
0
ファイル: EntityConnectable.cs プロジェクト: dsmo7206/Lemma
		public static void AttachEditorComponents(Entity entity, string name, ListProperty<Entity.Handle> target)
		{
			entity.Add(name, target);
			if (entity.EditorSelected != null)
			{
				Transform transform = entity.Get<Transform>("Transform");

				LineDrawer connectionLines = new LineDrawer { Serialize = false };
				connectionLines.Add(new Binding<bool>(connectionLines.Enabled, entity.EditorSelected));

				ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, target, delegate(Entity.Handle other)
				{
					return new LineDrawer.Line
					{
						A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
						B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(other.Target.Get<Transform>("Transform").Position, connectionLineColor)
					};
				}, x => x.Target != null && x.Target.Active);
				entity.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, entity.EditorSelected));
				entity.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, transform.Position));
				connectionLines.Add(connectionBinding);
				entity.Add(connectionLines);
			}
		}
コード例 #5
0
ファイル: JointFactory.cs プロジェクト: kernelbitch/Lemma
        private static void attachEditorComponents(Entity result, Main main)
        {
            Transform transform = result.Get<Transform>();

            Property<bool> selected = new Property<bool> { Value = false, Editable = false, Serialize = false };
            result.Add("EditorSelected", selected);

            Property<Entity.Handle> parentMap = result.GetOrMakeProperty<Entity.Handle>("Parent");

            Command<Entity> toggleEntityConnected = new Command<Entity>
            {
                Action = delegate(Entity entity)
                {
                    parentMap.Value = entity;
                }
            };
            result.Add("ToggleEntityConnected", toggleEntityConnected);

            LineDrawer connectionLines = new LineDrawer { Serialize = false };
            connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

            Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);

            Action recalculateLine = delegate()
            {
                connectionLines.Lines.Clear();
                Entity parent = parentMap.Value.Target;
                if (parent != null)
                {
                    connectionLines.Lines.Add(new LineDrawer.Line
                    {
                        A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
                        B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(parent.Get<Transform>().Position, connectionLineColor)
                    });
                }
            };

            Model model = new Model();
            model.Filename.Value = "Models\\cone";
            model.Editable = false;
            model.Serialize = false;
            result.Add("DirectionModel", model);

            Property<Direction> dir = result.GetProperty<Direction>("Direction");
            Transform mapTransform = result.Get<Transform>("MapTransform");
            model.Add(new Binding<Matrix>(model.Transform, delegate()
            {
                Matrix m = Matrix.Identity;
                m.Translation = transform.Position;

                if (dir == Direction.None)
                    m.Forward = m.Right = m.Up = Vector3.Zero;
                else
                {
                    Vector3 normal = Vector3.TransformNormal(dir.Value.GetVector(), mapTransform.Matrix);

                    m.Forward = -normal;
                    if (normal.Equals(Vector3.Up))
                        m.Right = Vector3.Left;
                    else if (normal.Equals(Vector3.Down))
                        m.Right = Vector3.Right;
                    else
                        m.Right = Vector3.Normalize(Vector3.Cross(normal, Vector3.Down));
                    m.Up = Vector3.Cross(normal, m.Left);
                }
                return m;
            }, transform.Matrix, mapTransform.Matrix));

            NotifyBinding recalculateBinding = null;
            Action rebuildBinding = delegate()
            {
                if (recalculateBinding != null)
                {
                    connectionLines.Remove(recalculateBinding);
                    recalculateBinding = null;
                }
                if (parentMap.Value.Target != null)
                {
                    recalculateBinding = new NotifyBinding(recalculateLine, parentMap.Value.Target.Get<Transform>().Matrix);
                    connectionLines.Add(recalculateBinding);
                }
                recalculateLine();
            };
            connectionLines.Add(new NotifyBinding(rebuildBinding, parentMap));

            connectionLines.Add(new NotifyBinding(recalculateLine, selected));
            connectionLines.Add(new NotifyBinding(recalculateLine, () => selected, transform.Position));
            result.Add(connectionLines);
        }
コード例 #6
0
ファイル: ZoneFactory.cs プロジェクト: kernelbitch/Lemma
        public override void AttachEditorComponents(Entity result, Main main)
        {
            Transform transform = result.Get<Transform>();

            Zone zone = result.Get<Zone>();

            Property<bool> selected = new Property<bool> { Value = false, Editable = false, Serialize = false };
            result.Add("EditorSelected", selected);

            Command<Entity> toggleEntityConnected = new Command<Entity>
            {
                Action = delegate(Entity entity)
                {
                    if (zone.ConnectedEntities.Contains(entity))
                    {
                        zone.ConnectedEntities.Remove(entity);
                        Zone z = entity.Get<Zone>();
                        if (z != null)
                            z.Parent.Value = null;
                    }
                    else
                    {
                        zone.ConnectedEntities.Add(entity);
                        Zone z = entity.Get<Zone>();
                        if (z != null)
                            z.Parent.Value = result;
                    }
                }
            };
            result.Add("ToggleEntityConnected", toggleEntityConnected);

            LineDrawer connectionLines = new LineDrawer { Serialize = false };
            connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

            Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
            ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, zone.ConnectedEntities, delegate(Entity.Handle entity)
            {
                if (entity.Target == null)
                    return new LineDrawer.Line[] { };
                else
                {
                    return new[]
                    {
                        new LineDrawer.Line
                        {
                            A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
                            B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(entity.Target.Get<Transform>().Position, connectionLineColor)
                        }
                    };
                }
            });
            result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, selected));
            result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, () => selected, transform.Position));
            connectionLines.Add(connectionBinding);
            result.Add(connectionLines);

            Model model = new Model();
            model.Filename.Value = "Models\\sphere";
            model.Color.Value = this.Color;
            model.IsInstanced.Value = false;
            model.Scale.Value = new Vector3(0.5f);
            model.Editable = false;
            model.Serialize = false;
            result.Add("EditorModel", model);
            model.Add(new Binding<Matrix, Vector3>(model.Transform, x => Matrix.CreateTranslation(x), transform.Position));

            Property<Vector3> corner1 = new Property<Vector3> { Editable = false, Serialize = false, Value = zone.BoundingBox.Value.Min };
            Property<Vector3> corner2 = new Property<Vector3> { Editable = false, Serialize = false, Value = zone.BoundingBox.Value.Max };

            result.Add(new Binding<BoundingBox>(zone.BoundingBox, delegate()
            {
                Vector3 a = corner1, b = corner2;
                return new BoundingBox(new Vector3(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Min(a.Z, b.Z)), new Vector3(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y), Math.Max(a.Z, b.Z)));
            }, corner1, corner2));

            Transform cornerTransform1 = this.addCornerModel(result, selected);
            cornerTransform1.Add(new TwoWayBinding<Vector3, Vector3>
            (
                corner1,
                x => Vector3.Transform(x, Matrix.Invert(transform.Matrix)),
                new[] { transform.Matrix },
                cornerTransform1.Position,
                x => Vector3.Transform(x, transform.Matrix),
                new[] { transform.Matrix }
            ));

            Transform cornerTransform2 = this.addCornerModel(result, selected);
            cornerTransform2.Add(new TwoWayBinding<Vector3, Vector3>
            (
                corner2,
                x => Vector3.Transform(x, Matrix.Invert(transform.Matrix)),
                new[] { transform.Matrix },
                cornerTransform2.Position,
                x => Vector3.Transform(x, transform.Matrix),
                new[] { transform.Matrix }
            ));

            ModelAlpha box = new ModelAlpha();
            box.Filename.Value = "Models\\alpha-box";
            box.Color.Value = new Vector3(this.Color.X, this.Color.Y, this.Color.Z);
            box.Alpha.Value = 0.125f;
            box.IsInstanced.Value = false;
            box.Editable = false;
            box.Serialize = false;
            box.DrawOrder.Value = 11; // In front of water
            box.DisableCulling.Value = true;
            result.Add(box);
            box.Add(new Binding<Matrix>(box.Transform, delegate()
            {
                BoundingBox b = zone.BoundingBox;
                return Matrix.CreateScale(b.Max - b.Min) * Matrix.CreateTranslation((b.Min + b.Max) * 0.5f) * transform.Matrix;
            }, zone.BoundingBox, transform.Matrix));
            box.Add(new Binding<bool>(box.Enabled, selected));
            box.Add(new Binding<BoundingBox>(box.BoundingBox, zone.BoundingBox));
            box.CullBoundingBox.Value = false;
        }