/// <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);
        }
Example #2
0
        /// <summary>
        /// Handles when the mouse moves.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseMove(MouseEventArgs e, ICamera2D camera)
        {
            if (_transBoxes.Count == 0)
            {
                return(false);
            }

            var worldPos = camera.ToWorld(e.Position());

            _lastWorldPos = worldPos;

            // Update what transbox is under the cursor
            if (SelectedTransBox != null)
            {
                UnderCursor = SelectedTransBox;
            }
            else
            {
                UnderCursor = FindBoxAt(worldPos);
            }

            // Update position
            if (SelectedTransBox != null)
            {
                SelectedTransBox.CursorMoved(_lastWorldPos);
            }

            return(SelectedTransBox != null);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <summary>
        /// Handles the MouseMove event of the gameScreen control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        void gameScreen_MouseMove(object sender, MouseEventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            if ((e.Button & MouseButtons.Left) == 0)
            {
                return;
            }

            var emitter = lstEmitters.SelectedItem as ParticleEmitter;

            if (emitter == null)
            {
                return;
            }

            var camera = gameScreen.Camera;

            if (camera == null)
            {
                return;
            }

            emitter.Origin = camera.ToWorld(e.Position());

            if (!lstEmitters.Items.Contains(emitter))
            {
                lstEmitters.Items.Add(emitter);
            }
        }
        /// <summary>
        /// Handles both mouse clicks and moves (does the place/deletes of grhs).
        /// </summary>
        /// <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>
        void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            // Update some vars
            var cursorPos = e.Position();

            _mouseOverMap = map;
            _mousePos     = cursorPos;

            // Don't do any place/deletes while selecting
            if (IsSelecting)
            {
                return;
            }

            Vector2 worldPos = camera.ToWorld(cursorPos);

            // Handle mouse
            if (e.Button == MouseButtons.Left)
            {
                if (!Input.IsShiftDown)
                {
                    // Place grh
                    PlaceMapGrhAtScreenPos(map, camera, cursorPos, !Input.IsCtrlDown);
                }
                else
                {
                    // Select grh under cursor
                    var grhToSelect = GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                    {
                        GlobalState.Instance.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex);
                        GlobalState.Instance.Map.Layer      = grhToSelect.MapRenderLayer;
                        GlobalState.Instance.Map.LayerDepth = grhToSelect.LayerDepth;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (!Input.IsShiftDown)
                {
                    // Delete from current layer
                    var grhToDelete = GetGrhToSelect(map, worldPos, mustBeOnLayer: GlobalState.Instance.Map.Layer);
                    if (grhToDelete != null)
                    {
                        map.RemoveMapGrh(grhToDelete);
                    }
                }
                else
                {
                    // Delete from all layers
                    var grhToSelect = GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                    {
                        map.RemoveMapGrh(grhToSelect);
                    }
                }
            }
        }
        /// <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;
        }
Example #7
0
        /// <summary>
        /// Handles both mouse clicks and moves.
        /// </summary>
        /// <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>
        void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e)
        {
            // Update some vars
            var cursorPos = e.Position();

            _mouseOverMap = map;
            _mousePos     = cursorPos;

            var globalState    = GlobalState.Instance;
            var currentGrhData = globalState.Map.GrhToPlace.GrhData;

            Vector2 worldPos = camera.ToWorld(cursorPos);

            // Handle mouse
            if (e.Button == MouseButtons.Left)
            {
                if (!Input.IsShiftDown)
                {
                    // Fill
                    if (currentGrhData != null)
                    {
                        var mapGrhsToReplace = GetFillMapGrhs(map, worldPos);
                        foreach (var mapGrh in mapGrhsToReplace)
                        {
                            mapGrh.Grh.SetGrh(currentGrhData);
                        }
                    }
                }
                else
                {
                    // Select grh under cursor
                    var grhToSelect = MapGrhPencilTool.GetGrhToSelect(map, worldPos);
                    if (grhToSelect != null)
                    {
                        globalState.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex);
                        globalState.Map.Layer      = grhToSelect.MapRenderLayer;
                        globalState.Map.LayerDepth = grhToSelect.LayerDepth;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                // Fill-delete
                if (currentGrhData != null)
                {
                    var mapGrhsToReplace = GetFillMapGrhs(map, worldPos);
                    foreach (var mapGrh in mapGrhsToReplace)
                    {
                        map.RemoveMapGrh(mapGrh);
                    }
                }
            }
        }
        /// <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 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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseMove"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (DesignMode)
            {
                base.OnMouseMove(e);
                return;
            }

            var screenPos = e.Position();
            var worldPos  = Camera.ToWorld(screenPos);

            MainForm.UpdateCursorPos(worldPos, screenPos);

            if (TransBoxManager.HandleMouseMove(e, Camera))
            {
                return;
            }

            base.OnMouseMove(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);
        }
Example #13
0
        /// <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();
            }
        }
Example #14
0
        /// <summary>
        /// Handles when a mouse button is pressed down.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param>
        /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns>
        public bool HandleMouseDown(MouseEventArgs e, ICamera2D camera)
        {
            if (e.Button == DragButton)
            {
                var worldPos = camera.ToWorld(e.Position());

                UnderCursor      = FindBoxAt(worldPos);
                SelectedTransBox = UnderCursor;
                _lastWorldPos    = worldPos;

                if (SelectedTransBox != null)
                {
                    _selectedTransBoxButton = e.Button;
                }
                else
                {
                    _selectedTransBoxButton = MouseButtons.None;
                }
            }

            return(SelectedTransBox != null);
        }
        /// <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 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);
                        }
                    }
                }
            }
        }