Пример #1
0
        /// <summary>
        /// When overridden in the derived class, handles performing drawing after the GUI for a <see cref="IDrawableMap"/> has been draw.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param>
        /// <param name="map">The <see cref="IDrawableMap"/> being drawn.</param>
        protected override void HandleAfterDrawMapGUI(ISpriteBatch spriteBatch, IDrawableMap map)
        {
            base.HandleAfterDrawMapGUI(spriteBatch, map);

            if (!IsEnabled)
            {
                return;
            }

            if (map != _mouseOverMap)
            {
                return;
            }

            var grh      = GlobalState.Instance.Map.GrhToPlace;
            var worldPos = map.Camera.ToWorld(_mousePos);
            var drawPos  = worldPos - map.Camera.Min;

            if (!Input.IsCtrlDown)
            {
                drawPos = GridAligner.Instance.Align(drawPos, true).Round();
            }

            if (Input.IsShiftDown)
            {
                // Display tooltip of what would be selected
                var grhToSelect = MapGrhPencilTool.GetGrhToSelect(map, worldPos);
                MapGrhPencilTool.DrawMapGrhTooltip(spriteBatch, map, grhToSelect, worldPos);
            }
            else
            {
                grh.Update(map.GetTime());
                grh.Draw(spriteBatch, drawPos, new Color(255, 255, 255, 180));
            }
        }
Пример #2
0
        IEnumerable <MapGrh> GetFillMapGrhs(EditorMap map, Vector2 worldPos)
        {
            MapGrh           mapGrh = MapGrhPencilTool.GetGrhToSelect(map, worldPos);
            HashSet <MapGrh> ret    = new HashSet <MapGrh>();

            GetFillMapGrhs(map, mapGrh, ret);
            return(ret.ToArray());
        }
Пример #3
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);
                    }
                }
            }
        }