/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List <object>(); foreach (var x in SOM.SelectedObjects.OfType <Entity>().ToImmutable()) { if (map.Spatial.CollectionContains(x)) { map.RemoveEntity(x); if (!x.IsDisposed) { x.Dispose(); } removed.Add(x); } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); // Create entity if (e.Button == MouseButtons.Right) { Type createType = null; // Create using same type as the last entity, if possible if (Input.IsCtrlDown) { createType = _lastCreatedType; } // Display selection dialog if (createType == null) { using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType)) { if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK) { createType = frm.SelectedItem; } } } // Create the type if (createType != null) { _lastCreatedType = null; try { // Create the Entity var entity = (Entity)Activator.CreateInstance(createType); map.AddEntity(entity); entity.Size = new Vector2(64); entity.Position = worldPos - (entity.Size / 2f); GridAligner.Instance.Fit(entity); _lastCreatedType = createType; } catch (Exception ex) { const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, createType, map, ex); } Debug.Fail(string.Format(errmsg, createType, map, ex)); } } } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { int modDepth = 0; if (e.Delta < 0) { modDepth = -1; } else if (e.Delta > 0) { modDepth = 1; } if (modDepth != 0) { // Change layer depth, making sure it is clamped in the needed range foreach (var mapGrh in GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.OfType <MapGrh>()) { if (map.Spatial.CollectionContains(mapGrh)) { mapGrh.LayerDepth = (short)(mapGrh.LayerDepth + modDepth).Clamp(short.MinValue, short.MaxValue); } } GlobalState.Instance.Map.SelectedObjsManager.UpdateFocused(); } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { _mouseOverMap = map; var worldPos = camera.ToWorld(e.Position()); if (IsSelecting) { // Expand selection area _selectionEnd = worldPos; } else { // Create the tooltip var font = ToolTipFont; if (ShowObjectToolTip && font != null) { var hoverEntity = GetObjUnderCursor(map, worldPos); if (hoverEntity == null) { // Nothing under the cursor that we are allowed to select _toolTip = string.Empty; _toolTipObject = null; } else if (_toolTipObject != hoverEntity) { // Something found under the cursor _toolTipObject = hoverEntity; _toolTipPos = e.Position(); _toolTip = GetObjectToolTip(hoverEntity) ?? hoverEntity.ToString(); // Make sure the text stays in the view area const int toolTipPadding = 4; var toolTipSize = font.MeasureString(_toolTip); if (_toolTipPos.X < toolTipPadding) { _toolTipPos.X = toolTipPadding; } else if (_toolTipPos.X + toolTipSize.X + toolTipPadding > camera.Size.X) { _toolTipPos.X = camera.Size.X - toolTipSize.X - toolTipPadding; } if (_toolTipPos.Y < toolTipPadding) { _toolTipPos.Y = toolTipPadding; } else if (_toolTipPos.Y + toolTipSize.Y + toolTipPadding > camera.Size.Y) { _toolTipPos.Y = camera.Size.Y - toolTipSize.Y - toolTipPadding; } } } } base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List<object>(); foreach (var x in SOM.SelectedObjects.OfType<Entity>().ToImmutable()) { if (map.Spatial.CollectionContains(x)) { map.RemoveEntity(x); if (!x.IsDisposed) x.Dispose(); removed.Add(x); } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List <object>(); foreach (var x in SOM.SelectedObjects.OfType <ILight>().ToImmutable()) { if (map.Lights.Contains(x)) { map.RemoveLight(x); removed.Add(x); // Remove the graphic and effect from the map var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { dm.LightManager.Remove(x); } } } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (e.Delta == 0) { return; } // Only change depth on selected MapGrh if only one is selected var focusedMapGrh = GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.FirstOrDefault() as MapGrh; if (focusedMapGrh == null) { return; } // Require the MapGrh to be on the map the scroll event took place on if (!map.Spatial.CollectionContains(focusedMapGrh)) { return; } // Change layer depth, making sure it is clamped in the needed range focusedMapGrh.LayerDepth = (short)(focusedMapGrh.LayerDepth + e.Delta).Clamp(short.MinValue, short.MaxValue); base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Treat as a click unless we're placing grhs not on the grid. Otherwise, that would cause us to place a ton, which is likely not what we want. if (!(Input.IsCtrlDown && (e.Button & MouseButtons.Left) != 0)) { HandleMouseClickAndMove(map, camera, e); } base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { var som = GlobalState.Instance.Map.SelectedObjsManager; if (!e.Control) { return; } switch (e.KeyCode) { case Keys.Left: { var left = new Vector2(-1, 0); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + left); } } break; case Keys.Right: { var right = new Vector2(1, 0); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + right); } } break; case Keys.Up: { var up = new Vector2(0, -1); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + up); } } break; case Keys.Down: { var down = new Vector2(0, 1); foreach (var entity in som.SelectedObjects.OfType <ISpatial>()) { entity.TryMove(entity.Position + down); } } break; } }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (!e.Alt && !e.Shift && !e.Control) { int?num = e.KeyCode.GetNumericKeyAsValue(); if (num.HasValue && num.Value > 0 && num.Value < 10) { GlobalState.Instance.SetGrhFromHotkey(num.Value); } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when a key is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (map != null) { // Save (Ctrl + Shift + S) if (e.KeyCode == Keys.S && e.Control && e.Shift) { MapHelper.SaveMapAs(map, false); return; } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when a key is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (map != null) { // Save (Ctrl + Shift + S) if (e.KeyCode == Keys.S && e.Control && e.Shift) { MapHelper.SaveMapAs(map, false); return; } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && IsSelectMouseButton(e.Button)) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); MapContainer_AreaSelected(map, camera, area, e); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); if (e.Button == MouseButtons.Right) { var entity = new WallEntity(worldPos, new Vector2(4)); GridAligner.Instance.Fit(entity); map.AddEntity(entity); SOM.SetSelected(entity); } base.MapContainer_MouseDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && e.Button == SelectMouseButton) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); var selected = CursorSelectObjects(map, area); GlobalState.Instance.Map.SelectedObjsManager.SetManySelected(selected); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var wasMapGrhPlaced = false; if (e.Button == MouseButtons.Left) { // Left-click if (Input.IsKeyDown(_placeMapGrhKey)) { PlaceMapGrh(map, camera, e.Position(), TileMode); wasMapGrhPlaced = true; } } base.MapContainer_MouseDown(sender, map, camera, e); if (wasMapGrhPlaced) { SOM.Clear(); } }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Terminate any current area selection when any mouse button is pressed _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; _isSelecting = false; var worldPos = camera.ToWorld(e.Position()); var underCursor = GetObjUnderCursor(map, worldPos); GlobalState.Instance.Map.SelectedObjsManager.SetSelected(underCursor); if (e.Button == SelectMouseButton && ((Control.ModifierKeys & SelectKey) != 0)) { // Start area selection _selectionStart = worldPos; _selectionEnd = _selectionStart; _isSelecting = true; } base.MapContainer_MouseDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Change the current depth int modDepth = 0; if (e.Delta < 0) { modDepth = -1; } else if (e.Delta > 0) { modDepth = 1; } if (modDepth != 0) { var currDepth = GlobalState.Instance.Map.LayerDepth; short newDepth = (short)(currDepth + modDepth).Clamp(short.MinValue, short.MaxValue); GlobalState.Instance.Map.LayerDepth = newDepth; } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseDown(sender, map, camera, e); if (IsSelecting) { return; } // Left-click if (e.Button == MouseButtons.Left) { // Place light if (Input.IsKeyDown(_placeLightKey)) { var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { var pos = camera.ToWorld(e.Position()); pos = GridAligner.Instance.Align(pos); var light = new Light { Center = pos, IsEnabled = true, Tag = map }; map.AddLight(light); dm.LightManager.Add(light); } } } } }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; // Support dragging operations when using TileMode if (TileMode) { if (Input.IsKeyDown(_placeMapGrhKey)) { if (e.Button == MouseButtons.Left) { // Drag placement PlaceMapGrh(map, camera, e.Position(), true); } else if (e.Button == MouseButtons.Right) { // Drag delete var worldPos = camera.ToWorld(e.Position()); worldPos = GridAligner.Instance.Align(worldPos, true); var worldPosArea = worldPos.ToRectangle(Vector2.One, false); var toDelete = map.Spatial.GetMany <MapGrh>(worldPosArea, x => IsObjectVisible(map, x)); foreach (var x in toDelete) { map.RemoveMapGrh(x); } } } } }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var wasMapGrhPlaced = false; if (e.Button == MouseButtons.Left) { // Left-click if (Input.IsKeyDown(_placeMapGrhKey)) { PlaceMapGrh(map, camera, e.Position(), TileMode); wasMapGrhPlaced = true; } } base.MapContainer_MouseDown(sender, map, camera, e); if (wasMapGrhPlaced) SOM.Clear(); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected virtual void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (!e.Alt && !e.Shift && !e.Control) { int? num = e.KeyCode.GetNumericKeyAsValue(); if (num.HasValue && num.Value > 0 && num.Value < 10) { GlobalState.Instance.SetGrhFromHotkey(num.Value); } } base.MapContainer_KeyDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { _mouseOverMap = map; var worldPos = camera.ToWorld(e.Position()); if (IsSelecting) { // Expand selection area _selectionEnd = worldPos; } else { // Create the tooltip var font = ToolTipFont; if (ShowObjectToolTip && font != null) { var hoverEntity = GetObjUnderCursor(map, worldPos); if (hoverEntity == null) { // Nothing under the cursor that we are allowed to select _toolTip = string.Empty; _toolTipObject = null; } else if (_toolTipObject != hoverEntity) { // Something found under the cursor _toolTipObject = hoverEntity; _toolTipPos = e.Position(); _toolTip = GetObjectToolTip(hoverEntity) ?? hoverEntity.ToString(); // Make sure the text stays in the view area const int toolTipPadding = 4; var toolTipSize = font.MeasureString(_toolTip); if (_toolTipPos.X < toolTipPadding) _toolTipPos.X = toolTipPadding; else if (_toolTipPos.X + toolTipSize.X + toolTipPadding > camera.Size.X) _toolTipPos.X = camera.Size.X - toolTipSize.X - toolTipPadding; if (_toolTipPos.Y < toolTipPadding) _toolTipPos.Y = toolTipPadding; else if (_toolTipPos.Y + toolTipSize.Y + toolTipPadding > camera.Size.Y) _toolTipPos.Y = camera.Size.Y - toolTipSize.Y - toolTipPadding; } } } base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); if (e.Button == MouseButtons.Right) { var ga = GridAligner.Instance; var entity = new WallEntity(worldPos, ga.GridSize); ga.Fit(entity); map.AddEntity(entity); SOM.SetSelected(entity); } base.MapContainer_MouseDown(sender, map, camera, e); }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseDown(sender, map, camera, e); if (IsSelecting) return; // Left-click if (e.Button == MouseButtons.Left) { // Place light if (Input.IsKeyDown(_placeLightKey)) { var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { var pos = camera.ToWorld(e.Position()); pos = GridAligner.Instance.Align(pos); var light = new Light { Center = pos, IsEnabled = true, Tag = map }; map.AddLight(light); dm.LightManager.Add(light); } } } } }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected virtual void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { }
/// <summary> /// Handles the KeyDown event of this Cursor tool. If the Control key is down then it will shift any selected <see cref="ISpatial"/>'s to the direction of the pressed arrow keys. /// </summary> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { var som = GlobalState.Instance.Map.SelectedObjsManager; if (!e.Control) return; switch (e.KeyCode) { case Keys.Left: { var left = new Vector2(-1, 0); foreach (var entity in som.SelectedObjects.OfType<ISpatial>()) { entity.TryMove(entity.Position + left); } } break; case Keys.Right: { var right = new Vector2(1, 0); foreach (var entity in som.SelectedObjects.OfType<ISpatial>()) { entity.TryMove(entity.Position + right); } } break; case Keys.Up: { var up = new Vector2(0, -1); foreach (var entity in som.SelectedObjects.OfType<ISpatial>()) { entity.TryMove(entity.Position + up); } } break; case Keys.Down: { var down = new Vector2(0, 1); foreach (var entity in som.SelectedObjects.OfType<ISpatial>()) { entity.TryMove(entity.Position + down); } } break; } }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && e.Button == SelectMouseButton) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); var selected = CursorSelectObjects(map, area); GlobalState.Instance.Map.SelectedObjsManager.SetManySelected(selected); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; // Support dragging operations when using TileMode if (TileMode) { if (Input.IsKeyDown(_placeMapGrhKey)) { if (e.Button == MouseButtons.Left) { // Drag placement PlaceMapGrh(map, camera, e.Position(), true); } else if (e.Button == MouseButtons.Right) { // Drag delete var worldPos = camera.ToWorld(e.Position()); worldPos = GridAligner.Instance.Align(worldPos, true); var worldPosArea = worldPos.ToRectangle(Vector2.One, false); var toDelete = map.Spatial.GetMany<MapGrh>(worldPosArea, x => IsObjectVisible(map, x)); foreach (var x in toDelete) { map.RemoveMapGrh(x); } } } } }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Treat as a click unless we're placing grhs not on the grid. Otherwise, that would cause us to place a ton, which is likely not what we want. if (!(Input.IsCtrlDown && (e.Button & MouseButtons.Left) != 0)) { HandleMouseClickAndMove(map, camera, e); } base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (e.Delta == 0) return; // Only change depth on selected MapGrh if only one is selected var focusedMapGrh = GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.FirstOrDefault() as MapGrh; if (focusedMapGrh == null) return; // Require the MapGrh to be on the map the scroll event took place on if (!map.Spatial.CollectionContains(focusedMapGrh)) return; // Change layer depth, making sure it is clamped in the needed range focusedMapGrh.LayerDepth = (short)(focusedMapGrh.LayerDepth + e.Delta).Clamp(short.MinValue, short.MaxValue); base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when a key is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected virtual void MapContainer_KeyPress(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyPressEventArgs e) { }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { base.MapContainer_MouseMove(sender, map, camera, e); var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Change the current depth int modDepth = 0; if (e.Delta < 0) modDepth = -1; else if (e.Delta > 0) modDepth = 1; if (modDepth != 0) { var currDepth = GlobalState.Instance.Map.LayerDepth; short newDepth = (short)(currDepth + modDepth).Clamp(short.MinValue, short.MaxValue); GlobalState.Instance.Map.LayerDepth = newDepth; } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected virtual void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { }
/// <summary> /// Handles when a mouse button is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { // Terminate any current area selection when any mouse button is pressed _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; _isSelecting = false; var worldPos = camera.ToWorld(e.Position()); var underCursor = GetObjUnderCursor(map, worldPos); GlobalState.Instance.Map.SelectedObjsManager.SetSelected(underCursor); if (e.Button == SelectMouseButton && ((Control.ModifierKeys & SelectKey) != 0)) { // Start area selection _selectionStart = worldPos; _selectionEnd = _selectionStart; _isSelecting = true; } base.MapContainer_MouseDown(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { if (IsSelecting && IsSelectMouseButton(e.Button)) { // End the mass selection _selectionEnd = camera.ToWorld(e.Position()); var area = Rectangle.FromPoints(_selectionStart, _selectionEnd); MapContainer_AreaSelected(map, camera, area, e); _isSelecting = false; _selectionStart = Vector2.Zero; _selectionEnd = Vector2.Zero; } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { HandleMouseClickAndMove(map, camera, e); base.MapContainer_MouseMove(sender, map, camera, e); }
/// <summary> /// Handles when the mouse button is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { var cursorPos = e.Position(); var worldPos = camera.ToWorld(cursorPos); // Create entity if (e.Button == MouseButtons.Right) { Type createType = null; // Create using same type as the last entity, if possible if (Input.IsCtrlDown) createType = _lastCreatedType; // Display selection dialog if (createType == null) { using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType)) { if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK) createType = frm.SelectedItem; } } // Create the type if (createType != null) { _lastCreatedType = null; try { // Create the Entity var entity = (Entity)Activator.CreateInstance(createType); map.AddEntity(entity); entity.Size = new Vector2(64); entity.Position = worldPos - (entity.Size / 2f); GridAligner.Instance.Fit(entity); _lastCreatedType = createType; } catch (Exception ex) { const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, createType, map, ex); Debug.Fail(string.Format(errmsg, createType, map, ex)); } } } base.MapContainer_MouseUp(sender, map, camera, e); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List<object>(); foreach (var x in SOM.SelectedObjects.OfType<ILight>().ToImmutable()) { if (map.Lights.Contains(x)) { map.RemoveLight(x); removed.Add(x); // Remove the graphic and effect from the map var msc = MapScreenControl.TryFindInstance(map); if (msc != null) { var dm = msc.DrawingManager; if (dm != null) { dm.LightManager.Remove(x); } } } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
/// <summary> /// Handles when the mouse wheel is moved while over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseWheel(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { int modDepth = 0; if (e.Delta < 0) modDepth = -1; else if (e.Delta > 0) modDepth = 1; if (modDepth != 0) { // Change layer depth, making sure it is clamped in the needed range foreach (var mapGrh in GlobalState.Instance.Map.SelectedObjsManager.SelectedObjects.OfType<MapGrh>()) { if (map.Spatial.CollectionContains(mapGrh)) { mapGrh.LayerDepth = (short)(mapGrh.LayerDepth + modDepth).Clamp(short.MinValue, short.MaxValue); } } GlobalState.Instance.Map.SelectedObjsManager.UpdateFocused(); } base.MapContainer_MouseWheel(sender, map, camera, e); }
/// <summary> /// Handles when the mouse moves over a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_MouseMove(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e) { HandleMouseClickAndMove(map, camera, e); base.MapContainer_MouseMove(sender, map, camera, e); }