void FloodFill(Layer layer, Vector2 orginal, Vector2 node, Tile target, Tile replacement) { if (target == replacement) return; bool nodeExists = layer.Tiles.ContainsKey(node); if ((!nodeExists && target != null) || (nodeExists && target == null) || (nodeExists && layer.Tiles[node] != target)) return; if (nodeExists) layer.Tiles[node] = replacement; else layer.Tiles.Add(node, replacement); if (node.X < orginal.X + 32 && node.X > orginal.X - 32) { FloodFill(layer, orginal, new Vector2(node.X - 1, node.Y), target, replacement); FloodFill(layer, orginal, new Vector2(node.X + 1, node.Y), target, replacement); } if (node.Y < orginal.Y + 32 && node.Y > orginal.Y - 32) { FloodFill(layer, orginal, new Vector2(node.X, node.Y - 1), target, replacement); FloodFill(layer, orginal, new Vector2(node.X, node.Y + 1), target, replacement); } }
void DrawTile(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { if (!string.IsNullOrEmpty(selectedTileName)) { var point = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32)); if (layer.Tiles.ContainsKey(point)) layer.Tiles.Remove(point); layer.Tiles.Add(point, TileRepository.GetTile(selectedTileName)); /*UndoService.Current[map].AddChange(new DelegateChange(null, new Action(() => { layer.Tiles.Remove(point); }), new Action(() => { layer.Tiles.Add(point, TileRepository.GetTile(selectedTileName)); }), selectedTileName), "Draw a tile");*/ /*MainForm.MapPanel.AddShadowForObject(Texture2D.FromStream(MainForm.MapPanel.GraphicsDevice, TileRepository.GetTile(selectedTileName).Texture), point);*/ base.OnMouseMove(map, layer, camera, position, selectedTileName); } }
void PickTile(Layer layer, Camera2D camera, Vector2 position) { var point = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32)); if (layer.Tiles.ContainsKey(point)) { _form.SelectTile(layer.Tiles[point].Name); } }
void Erase(Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { if (!string.IsNullOrEmpty(selectedTileName)) { var point = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32)); if (layer.Tiles.ContainsKey(point)) layer.Tiles.Remove(point); } }
public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { if (!string.IsNullOrEmpty(selectedTileName)) { var orginal = new Vector2((int)((camera.Position.X + position.X) / 32), (int)((camera.Position.Y + position.Y) / 32)); Tile target = null; layer.Tiles.TryGetValue(orginal, out target); FloodFill(layer, orginal, orginal, target, TileRepository.GetTile(selectedTileName)); } }
public static Layer LoadFromXml(XElement element) { Layer layer = new Layer(); layer.Name = element.Attribute("Name").Value; layer.Order = int.Parse(element.Attribute("Order").Value); foreach (var tile in element.Elements()) { layer.Tiles.Add(new Vector2(float.Parse(tile.Attribute("X").Value), float.Parse(tile.Attribute("Y").Value)), TileRepository.GetTile(tile.Attribute("Name").Value)); } return layer; }
public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { bool add = true; foreach (Light2D light in MainForm.MapPanel.Krpyton.Lights) { var mouse = (new Vector2(camera.Position.X, camera.Position.Y) + position).ToPoint(); for (int i = 0; i < MainForm.MapPanel._lightSymbolPixelData.Length; i++) { int x = i % MainForm.MapPanel._lightSymbolTexture.Width; int y = i / MainForm.MapPanel._lightSymbolTexture.Width; // System.Windows.Forms.MessageBox.Show(mouse.ToString() + " , " + x + (int)light.Position.X + " " + y + (int)light.Position.Y); if (new Rectangle(x + (int)light.Position.X, y + (int)light.Position.Y, 16, 16).Contains(mouse)) { add = false; ((MainForm)MainForm.ActiveForm).OpenProperties(light); MainForm.MapPanel.SelectedLight = light; } } } if (add) { var light = new Light2D() { Position = new Vector2(camera.Position.X + position.X, camera.Position.Y + position.Y), Color = Color.White, Texture = MapPanel.LightTexture, Range = 100, IsOn = true, Intensity = 1.5f, ShadowType = ShadowType.Occluded }; MainForm.MapPanel.Krpyton.Lights.Add(light); ((MainForm)MainForm.ActiveForm).OpenProperties(light); MainForm.MapPanel.SelectedLight = light; } }
public override void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { foreach (Light2D light in MainForm.MapPanel.Krpyton.Lights) { var mouse = (new Vector2(camera.Position.X, camera.Position.Y) + position).ToPoint(); for (int i = 0; i < MainForm.MapPanel._lightSymbolPixelData.Length; i++) { int x = i % MainForm.MapPanel._lightSymbolTexture.Width; int y = i / MainForm.MapPanel._lightSymbolTexture.Width; if (MainForm.MapPanel._movingLight == light || new Rectangle(x + (int)light.Position.X, y + (int)light.Position.Y, 1, 1) .Contains(mouse)) { if (MainForm.MapPanel._movingLight == null) MainForm.MapPanel._movingLight = light; light.Position = (new Vector2(camera.Position.X, camera.Position.Y) + position); } } } base.OnMouseMove(map, layer, camera, position, selectedTileName); }
public virtual void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { }
public override void OnMouseMove(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { Erase(layer, camera, position, selectedTileName); base.OnMouseMove(map, layer, camera, position, selectedTileName); }
public override void OnMouseClick(Map map, Layer layer, Camera2D camera, Vector2 position, string selectedTileName) { PickTile(layer, camera, position); }
void DrawLayer(Layer layer) { foreach (var tile in layer.Tiles) { if (!_cache.ContainsKey(tile.Value.Name)) { var texture = Texture2D.FromStream(GraphicsDevice, tile.Value.Texture); _cache.Add(tile.Value.Name, texture); } _spriteBatch.Draw(_cache[tile.Value.Name], new Vector2(tile.Key.X * 32 + 1, tile.Key.Y * 32), Color.White); } }