/// <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 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) { 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 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); }