private void OnMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) { Models.Custom.Door dr = DataContext as Models.Custom.Door; dr.IsOpen = !dr.IsOpen; e.Handled = true; } }
private void ConsumeEditorOperation(int pX, int pY) { int delta = CellSize / 6; int lineH = pY / CellSize, lineH2 = lineH + 1; int lineV = pX / CellSize, lineV2 = lineV + 1; int deltaH = pX % CellSize; int deltaV = pY % CellSize; //: new delta means actually it is closer to other side and acceptable distance only int newDeltaH = ((lineV + 1) * CellSize) - pX; if (newDeltaH < deltaH && newDeltaH < delta) { deltaH = newDeltaH; lineV = lineV2; } //: new delta means actually it is closer to other side and acceptable distance only int newDeltaV = ((lineH + 1) * CellSize) - pY; if (newDeltaV < deltaV && newDeltaV < delta) { deltaV = newDeltaV; lineH = lineH2; } //: too close to actual corner point, then ignore this if (deltaH < delta && deltaV < delta) { return; } if (EditorOperation == MapOperations.Door || EditorOperation == MapOperations.Wall) { //: point too in the middle, cannot determine the actual line, ignore this for AddWall/AddDoor if (deltaH > delta && deltaV > delta) { return; } Point first, second; //: horizontal line if (deltaH > deltaV) { first = new Point(lineV, lineH); second = new Point(lineV2, lineH); } //: vertical line else { first = new Point(lineV, lineH); second = new Point(lineV, lineH2); } //: special controls, not needed //if (Math.Abs(first.X - second.X) + Math.Abs(first.Y - second.Y) > 1) throw new Exception("!"); //else if (first == second) throw new Exception("!2"); if (EditorOperation == MapOperations.Door) { Models.Custom.Door existingDoor = MapInfo.Doors.FirstOrDefault(d => (d.First == first && d.Second == second) || (d.Second == first && d.First == second)); if (existingDoor != null) { MapInfo.Doors.Remove(existingDoor); } else { MapInfo.Doors.Add(new Models.Custom.Door { First = first, Second = second, IsOpen = false }); } } else { Models.Custom.Wall existingWall = MapInfo.Walls.FirstOrDefault(d => (d.First == first && d.Second == second) || (d.Second == first && d.First == second)); if (existingWall != null) { MapInfo.Walls.Remove(existingWall); } else { MapInfo.Walls.Add(new Models.Custom.Wall { First = first, Second = second }); } } } else if (EditorOperation == MapOperations.PointOfInterest || EditorOperation == MapOperations.Block) { //: point too close to edges, calculation might be problem, ignore this if (deltaH < delta || deltaV < delta) { return; } //: no note? forgotten? ignore this if (string.IsNullOrEmpty(EditorParameter)) { return; } Point location = new Point(lineV, lineH); if (EditorOperation == MapOperations.PointOfInterest) { Models.Custom.PointOfInterest poi = MapInfo.PointOfInterests.FirstOrDefault(p => p.Location == location); if (poi != null) { MapInfo.PointOfInterests.Remove(poi); } else { MapInfo.PointOfInterests.Add(new Models.Custom.PointOfInterest { Location = location, Notes = EditorParameter }); } } else { Models.Custom.Block block = MapInfo.Blocks.FirstOrDefault(p => p.Location == location); if (block != null) { MapInfo.Blocks.Remove(block); } else { MapInfo.Blocks.Add(new Models.Custom.Block { Location = location, Notes = EditorParameter }); } } } else if (EditorOperation == MapOperations.AddEffect) { //: point too close to edges, calculation might be problem, ignore this if (deltaH < delta || deltaV < delta) { return; } //: no note? forgotten? ignore this if (string.IsNullOrEmpty(EditorParameter)) { return; } Point location = new Point(lineV, lineH); Models.Custom.Effect eff = MapInfo.Effects.FirstOrDefault(p => p.Location == location); if (eff == null) { MapInfo.Effects.Add(new Models.Custom.Effect { Location = location, Notes = EditorParameter }); } } else if (EditorOperation == MapOperations.RemoveEffect) { //: point too close to edges, calculation might be problem, ignore this if (deltaH < delta || deltaV < delta) { return; } //: no note? forgotten? ignore this if (string.IsNullOrEmpty(EditorParameter)) { return; } Point location = new Point(lineV, lineH); Models.Custom.Effect eff = MapInfo.Effects.FirstOrDefault(p => p.Location == location); if (eff != null) { MapInfo.Effects.Remove(eff); } //else MapInfo.PointOfInterests.Add(new Models.Custom.PointOfInterest { Location = location, Notes = EditorParameter }); } }