Example #1
0
        private static GenericStructure WriteEntity(Entity ent)
        {
            var ret = new GenericStructure("entity");
            ret["id"] = ent.ID.ToString(CultureInfo.InvariantCulture);
            ret["classname"] = ent.EntityData.Name;
            WriteEntityData(ret, ent.EntityData);
            if (!ent.HasChildren) ret["origin"] = FormatCoordinate(ent.Origin);

            var editor = WriteEditor(ent);
            ret.Children.Add(editor);

            foreach (var solid in ent.GetChildren().SelectMany(x => x.FindAll()).OfType<Solid>().OrderBy(x => x.ID))
            {
                ret.Children.Add(WriteSolid(solid));
            }

            return ret;
        }
Example #2
0
        private void AddHardpointMarkersToShip(Entity ship)
        {
            var shipComponent = ship.GetComponent<ShipComponent>();

            const float BaseAlpha = 0.3f;
            foreach (var hardpointEntity in ship.GetChildren().Where(e=>e.HasComponent<HardpointComponent>())){
                var hardpointArc = new HardpointArcDrawingComponent { DrawHardpointIcon = true, Alpha = BaseAlpha };
                hardpointEntity.AddComponent(hardpointArc);
                var entity = World.CreateEntity();
                var xform = hardpointEntity.GetComponent<Transform>();
                var box = HardpointRendererSystem.GetIconBoundingBox(hardpointEntity.GetComponent<HardpointComponent>().Hardpoint);
                var newxform = entity.AddComponentFromPool<Transform>();

                newxform.Position = xform.Position - box.Size / 2;
                newxform.Rotation = 0;
                newxform.Scale = Vector2.One;

                entity.AddComponent(new BoundingBoxComponent(box));

                //entity.AddComponent(new DrawBoundingBoxComponent { Color = Microsoft.Xna.Framework.Color.Red, IsEnabled = true });

                var hover = new MouseHoverComponent { UsePositionOnly = true };
                hover.HoverChanged += (o, e) =>
                {
                    hardpointArc.Alpha = hover.IsHover ? 1 : BaseAlpha;
                    hardpointArc.Thickness = hover.IsHover ? 2 : 1;
                    if (hover.IsHover) _hoverEntities.Add(hardpointEntity);
                    else _hoverEntities.Remove(hardpointEntity);
                };
                entity.AddComponent(hover);
            }
        }