/// <summary> /// Creates a tile layer by reading the contentManager we got from the SharpTiles library. This will create our tile layers of type "Floor" and "Objects". /// </summary> /// <param name="layerContent"></param> /// <param name="tileSets"></param> /// <returns></returns> private TileLayer CreateTileLayer(LayerContent layerContent, IEnumerable <TileSetContent> tileSets) { if (layerContent == null) { throw new ArgumentNullException("layerContent"); } if (tileSets == null) { throw new ArgumentNullException("tileSets"); } TileLayerContent tileLayerContent = layerContent as TileLayerContent; TileLayerType tileLayerType = GetTileLayerType(layerContent); TileLayer tileLayer = new TileLayer(layerContent.Name, tileLayerContent.Width, tileLayerContent.Height, tileLayerType); foreach (uint tileID in tileLayerContent.Data) { uint flippedHorizontallyFlag = 0x80000000; uint flippedVerticallyFlag = 0x40000000; int tileIndex = (int)(tileID & ~(flippedVerticallyFlag | flippedHorizontallyFlag)); Tile tile = CreateTile(tileIndex, tileSets, tileLayerType); tileLayer.AddTile(tile); } return(tileLayer); }
/// <summary> /// Creates the proper map object layer based on the layer name such as collidables and path nodes. /// </summary> /// <param name="layer"></param> /// <param name="orientation"></param> /// <returns></returns> private MapObjectLayer CreateObjectLayer(LayerContent layer, Orientation orientation) { if (layer == null) { throw new ArgumentNullException("layer"); } ObjectLayerContent objectLayerContent = layer as ObjectLayerContent; MapObjectLayerType mapObjectLayerType; MapObjectType mapObjectType; if (objectLayerContent.Name == "DeadZones") { mapObjectLayerType = MapObjectLayerType.DeadZone; mapObjectType = MapObjectType.DeadZone; } else if (objectLayerContent.Name == "PathNodes") { mapObjectLayerType = MapObjectLayerType.PathNode; mapObjectType = MapObjectType.PathNode; } else if (objectLayerContent.Name == "Equipment") { mapObjectLayerType = MapObjectLayerType.Equipment; mapObjectType = MapObjectType.Equipment; } else { throw new Exception("Unknown map object layer type. Did you name your layer correctly? \"DeadZones\", \"PathNodes\", and \"Equipment\" are valid layers."); } MapObjectLayer mapObjectLayer = new MapObjectLayer(objectLayerContent.Name, mapObjectLayerType); foreach (ObjectContent objectContent in objectLayerContent.MapObjects) { if (mapObjectLayer.Type == MapObjectLayerType.PathNode) { PathNode pathNode = new PathNode(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties); mapObjectLayer.AddMapObject(pathNode); } else if (mapObjectLayer.Type == MapObjectLayerType.Equipment) { EquipmentObjectType equipmentObjectType = GetEquipmentObjectType(objectContent); EquipmentObject equipmentObject = new EquipmentObject(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties, equipmentObjectType); mapObjectLayer.AddMapObject(equipmentObject); } else { MapObject mapObject = new MapObject(objectContent.Name, objectContent.Bounds, orientation, mapObjectType, objectContent.Properties); mapObjectLayer.AddMapObject(mapObject); } } return(mapObjectLayer); }
internal void UpdateScaleVisibility(double scale, bool isParentVisible) { IsInScaleRange = isParentVisible && LayerContent.IsVisibleAtScale(scale); _currentScale = scale; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsInScaleRange))); if (Sublayers != null) { foreach (var item in Sublayers) { item.UpdateScaleVisibility(scale, IsInScaleRange); } } }
private async void BuildSublayerList() { if (LayerContent is ILoadable) { var loadable = (ILoadable)LayerContent; if (loadable.LoadStatus != LoadStatus.Loaded) { loadable.Loaded += OnLayerContentLoaded; } } if (LayerContent.SublayerContents != null && LayerContent.SublayerContents.Count > 0) { _sublayers = new List <LayerContentViewModel>(LayerContent.SublayerContents.ToArray().Where(t => t.ShowInLegend).Select(t => new LayerContentViewModel(t, _view, null, _generateLegend))).ToArray(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Sublayers))); } else { _sublayers = null; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Sublayers))); if (_generateLegend) { IReadOnlyList <LegendInfo> legend; try { legend = await LayerContent.GetLegendInfosAsync(); } catch { return; } if (legend != null && legend.Count > 0) { _sublayers = new List <LayerContentViewModel>(legend.Select(l => new LayerContentViewModel(new LegendContentInfo(l, LayerContent.IsVisibleAtScale), _view, l.Symbol, _generateLegend))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Sublayers))); } } } if (_sublayers != null && !double.IsNaN(_currentScale)) { foreach (var item in _sublayers) { item.UpdateScaleVisibility(_currentScale, IsInScaleRange); } } }
/// <summary> /// Returns the type of the tile layer according to the layer's name as read from the Tiled map editor. /// </summary> /// <param name="layerContent"></param> /// <returns></returns> private static TileLayerType GetTileLayerType(LayerContent layerContent) { if (layerContent == null) { throw new ArgumentNullException("layerContent"); } TileLayerType tileLayerType = TileLayerType.None; if (layerContent.Name.Contains("Floor")) { tileLayerType = TileLayerType.Floor; } else if (layerContent.Name.Contains("Objects")) { tileLayerType = TileLayerType.Objects; } return(tileLayerType); }
/// <summary> /// Creates the proper map object layer based on the layer name such as collidables and path nodes. /// </summary> /// <param name="layer"></param> /// <param name="orientation"></param> /// <returns></returns> private MapObjectLayer CreateObjectLayer(LayerContent layer, Orientation orientation) { if (layer == null) { throw new ArgumentNullException("layer"); } ObjectLayerContent objectLayerContent = layer as ObjectLayerContent; MapObjectLayer mapObjectLayer = new MapObjectLayer(objectLayerContent.Name); foreach (ObjectContent objectContent in objectLayerContent.MapObjects) { MapObject mapObject = new MapObject(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties); mapObjectLayer.AddMapObject(mapObject); } return(mapObjectLayer); }
private static Layer LoadLayer(Map map, LayerContent layerContent) { switch (layerContent) { case TileLayerContent tileLayerContent: return(LoadTileLayer(map, tileLayerContent)); case ObjectLayerContent objectLayerContent: return(LoadObjectLayer(map, objectLayerContent)); case ImageLayerContent imageLayerContent: return(LoadImageLayer(map, imageLayerContent)); case GroupLayerContent groupLayerContent: return(LoadGroupLayer(map, groupLayerContent)); default: throw new ArgumentOutOfRangeException(); } }
public ReboundView(LayerContent holder) { InitializeComponent(); DataContext = holder; this.holder = holder; }
static public void DestroyLayerContent(LayerContent content) { _LayerContentCache.PushCacheableObject(content); }
private void PreLoading() { if (m_map == null) { return; } m_layers = new List <LayerContent>(); foreach (var layer in m_map.Layers.OrderBy(x => x.LayerId)) { LayerContent instanceLayer = null; if (!m_layers.Any(x => x.Type == (LayerEnum)layer.LayerId)) { m_layers.Add(new LayerContent() { Type = (LayerEnum)layer.LayerId }); } instanceLayer = m_layers.First(x => x.Type == (LayerEnum)layer.LayerId); // recupere Identifier qui est egale au ElementId que le serveur doit envoyer List <int> Identifierlist = (from i in layer.Cells from y in i.Elements where y is GraphicalElement && (y as GraphicalElement).Identifier != 0 select(y as GraphicalElement).Identifier).ToList(); List <int> ElementIdlist = (from i in layer.Cells from y in i.Elements where y is GraphicalElement && Identifierlist.Contains((y as GraphicalElement).Identifier) select(y as GraphicalElement).ElementId).ToList(); foreach (var cell in layer.Cells.OrderBy(x => x.CellId)) { foreach (GraphicalElement element in cell.Elements.Where(x => x is GraphicalElement)) { var graphicElement = TextureManager.Instance.GetElementData(element.ElementId); if (graphicElement is NormalGraphicalElementData) { NormalGraphicalElementData g = graphicElement as NormalGraphicalElementData; if (g != null && TextureManager.Instance.GetImageGfx(g.Gfx) != null) { var instance = new Test() { CellID = cell.CellId, GraphicalElement = element, Sprite = new Sprite(TextureManager.Instance.GetImageGfx(g.Gfx)), GraphicElement = graphicElement, Manager = this }; var test = instance.GetPosToDrawTexture(); var currentCell = GetCell(new System.Drawing.Point((int)test.X, (int)test.Y), false, instance.Sprite.TextureRect.Width, instance.Sprite.TextureRect.Height); var d = instance.Sprite.TextureRect; var testg = instance.GraphicalElement.PixelOffsetX; instanceLayer.AddElement(cell.CellId, instance); } } else if (graphicElement is EntityGraphicalElementData) { var d = ActorLook.Parse((graphicElement as EntityGraphicalElementData).EntityLook); if (d.BonesID == 650) { var j = TextureManager.Instance.GetImageGfx(650); var instance = new Test() { CellID = cell.CellId, GraphicalElement = element, Sprite = new Sprite(new Texture(@"E:\Map Editor Britana\DesignEditeurMap\DesignEditeurMap\bin\Debug\data\img\655450.png")), GraphicElement = graphicElement, Manager = this }; instanceLayer.AddElement(cell.CellId, instance); } } } } } }
public Graphics(LayerContent layerContent) { }
public Layer(string id, LayerContent content) { Id = id; Content = content; }