private ScreenLayerInfo LoadScreenLayer(XElement node, string stagePath, string name, Tileset tileset, int tileStartX, int tileStartY, bool foreground) { var tileFilePath = Path.Combine(stagePath, name + ".scn"); var tileArray = LoadTiles(tileFilePath); var tileLayer = new TileLayer(tileArray, tileset, tileStartX, tileStartY); var keyframes = new List <ScreenLayerKeyframe>(); foreach (var keyframeNode in node.Elements("Keyframe")) { var frame = LoadScreenLayerKeyFrame(keyframeNode); keyframes.Add(frame); } var layer = new ScreenLayerInfo(name, tileLayer, foreground, keyframes); foreach (XElement entity in node.Elements("Entity")) { EntityPlacement info = _entityReader.Load(entity); layer.AddEntity(info); } return(layer); }
private void PlaceEntity(int index, GameEntity entity) { EntityPlacement info = _info.Entities[index]; // can't respawn until the spawn point goes off screen _spawnable[index] = false; _respawnTracker.Track(info, entity); entity.Direction = info.direction; entity.Start(_stage); entity.GetComponent <PositionComponent>().SetPosition(new PointF(info.screenX, info.screenY)); if (info.state != "Start") { StateMessage msg = new StateMessage(null, info.state); entity.SendMessage(msg); } _entities[index] = entity; Action remove = () => { }; remove += () => { _entities[index] = null; entity.Removed -= remove; }; entity.Removed += remove; }
public EntityPlacementControlViewModel(EntityPlacement placement, EntityInfo entityInfo, ScreenDocument screen) { if (placement == null) { throw new ArgumentNullException("placement"); } if (entityInfo == null) { throw new ArgumentNullException("entityInfo"); } if (screen == null) { throw new ArgumentNullException("screen"); } this.Placement = placement; this._entityInfo = entityInfo; this._screen = screen; DeleteCommand = new RelayCommand(Delete); FlipCommand = new RelayCommand(Flip); RespawnCommand = new RelayCommand(SetRespawnMode); StartStateCommand = new RelayCommand(SetStartState); ViewModelMediator.Current.GetEvent <ZoomChangedEventArgs>().Subscribe(ZoomChanged); }
public EntityPlacement Load(XElement node) { EntityPlacement info = new EntityPlacement(); info.Id = node.TryAttribute("id", Guid.NewGuid().ToString()); info.entity = node.TryAttribute("name", node.GetAttribute <string>("entity")); info.state = node.TryAttribute("state", "Start"); info.screenX = node.GetAttribute <int>("x"); info.screenY = node.GetAttribute <int>("y"); var dirAttr = node.Attribute("direction"); if (dirAttr != null) { Direction dir = Direction.Left; Enum.TryParse <Direction>(dirAttr.Value, true, out dir); info.direction = dir; } var respawnAttr = node.Attribute("respawn"); if (respawnAttr != null) { RespawnBehavior respawn = RespawnBehavior.Offscreen; Enum.TryParse <RespawnBehavior>(respawnAttr.Value, true, out respawn); info.respawn = respawn; } return(info); }
private void StopBeingHeld() { if (beingHeld != null) { beingHeld.Drop(); } beingHeld = null; }
public void AddEntity(EntityPlacement info) { screen.Layers[0].Entities.Add(info); Dirty = true; if (EntityAdded != null) { EntityAdded(info); } }
public void RemoveEntity(EntityPlacement info) { screen.Layers[0].Entities.Remove(info); Dirty = true; if (EntityRemoved != null) { EntityRemoved(info); } }
public bool IsRespawnable(EntityPlacement placement) { if (_respawnableEntities.ContainsKey(placement)) { return(_respawnableEntities[placement]); } return(true); }
private void DisableRespawn(EntityPlacement placement, GameEntity entity) { if (placement.respawn != RespawnBehavior.Offscreen) { _respawnableEntities[placement] = false; } entity.Removed -= () => DisableRespawn(placement, entity); }
public void StartBeingHeld() // called when instantiating an entity from the ui { if (beingHeld != null) { beingHeld.Drop(); } beingHeld = this; OnStartedBeingHeld?.Invoke(); }
private void EntityRemoved(EntityPlacement placement) { var ctrl = this.Children.OfType <EntityPlacementControl>().SingleOrDefault(c => ((EntityPlacementControlViewModel)c.DataContext).Placement == placement); if (ctrl != null) { this.Children.Remove(ctrl); } Update(); }
public EntityPlacement AddEntity(EntityInfo entity, Point location) { var info = new EntityPlacement { entity = entity.Name, screenX = location.X, screenY = location.Y, }; screen.Layers[0].Entities.Add(info); Dirty = true; return(info); }
public static EntityPlacement LoadEntityPlacement(XElement entity) { EntityPlacement info = new EntityPlacement(); info.Id = entity.TryAttribute <string>("id", Guid.NewGuid().ToString()); var nameAttr = entity.Attribute("name"); if (nameAttr == null) { nameAttr = entity.RequireAttribute("entity"); } info.entity = nameAttr.Value; string state = "Start"; XAttribute stateAttr = entity.Attribute("state"); if (stateAttr != null) { state = stateAttr.Value; } info.state = state; info.screenX = entity.GetAttribute <int>("x"); info.screenY = entity.GetAttribute <int>("y"); var dirAttr = entity.Attribute("direction"); if (dirAttr != null) { Direction dir = Direction.Left; Enum.TryParse <Direction>(dirAttr.Value, true, out dir); info.direction = dir; } var respawnAttr = entity.Attribute("respawn"); if (respawnAttr != null) { RespawnBehavior respawn = RespawnBehavior.Offscreen; Enum.TryParse <RespawnBehavior>(respawnAttr.Value, true, out respawn); info.respawn = respawn; } return(info); }
private void EntityAdded(EntityPlacement placement) { var ctrl = new EntityPlacementControl(); var info = this.Screen.Stage.Project.EntityByName(placement.entity); var vm = new EntityPlacementControlViewModel(placement, info, Screen); ctrl.DataContext = vm; ctrl.Visibility = Visibility.Visible; PositionControl(ctrl, vm); Canvas.SetZIndex(ctrl, 10000); vm.PlacementModified += (s, e) => PositionControl(ctrl, vm); this.Children.Add(ctrl); Update(); }
private bool EntityBounded(EntityPlacement entityInfo, Point location) { Entity entity = Stage.Project.EntityByName(entityInfo.entity); RectangleF bounds; if (entity.MainSprite == null) { bounds = new RectangleF(-8, -8, 16, 16); } else { bounds = entity.MainSprite.BoundBox; bounds.Offset(-entity.MainSprite.HotSpot.X, -entity.MainSprite.HotSpot.Y); } bounds.Offset(entityInfo.screenX, entityInfo.screenY); return(bounds.Contains(location)); }
public void Click(ScreenDrawingSurface surface, System.Drawing.Point location) { // select nearest entity var index = surface.Screen.FindEntityAt(location); surface.Screen.SelectEntity(index); surface.ReDrawEntities(); heldEntity = surface.Screen.GetEntity(index); if (heldEntity != null) { entityAnchor = new Point(location.X - (int)heldEntity.screenX, location.Y - (int)heldEntity.screenY); } else { entityAnchor = Point.Empty; } }
public void Write(EntityPlacement info, XmlWriter writer) { writer.WriteStartElement("Entity"); if (info.Id != null) { writer.WriteAttributeString("id", info.Id); } writer.WriteAttributeString("entity", info.entity); if (info.state != "Start") { writer.WriteAttributeString("state", info.state); } writer.WriteAttributeString("x", info.screenX.ToString()); writer.WriteAttributeString("y", info.screenY.ToString()); writer.WriteAttributeString("direction", info.direction.ToString()); writer.WriteAttributeString("respawn", info.respawn.ToString()); writer.WriteEndElement(); }
private void OnEnable() { beingHeld = null; wasMousedOverLastF = false; }
public void RemoveEntity(EntityPlacement info) { screen.Layers[0].Entities.Remove(info); }
public void AddEntity(EntityPlacement info) { screen.Layers[0].Entities.Add(info); Dirty = true; }
public AddEntityAction(EntityPlacement entity, ScreenDocument screen) { this.entity = entity; this.screen = screen; }
public void Track(EntityPlacement placement, GameEntity entity) { entity.Removed += () => DisableRespawn(placement, entity); }
public AddEntityAction(EntityPlacement entity, ScreenDrawingSurface surface) { this.entity = entity; this.surface = surface; }