当前位置: 首页>>代码示例>>C#>>正文


C# EditorMap类代码示例

本文整理汇总了C#中EditorMap的典型用法代码示例。如果您正苦于以下问题:C# EditorMap类的具体用法?C# EditorMap怎么用?C# EditorMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EditorMap类属于命名空间,在下文中一共展示了EditorMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MapContainer_KeyUp

        /// <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);
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:32,代码来源:MapEntityCursorTool.cs

示例2: GetObjUnderCursor

        /// <summary>
        /// Gets the selectable object currently under the cursor.
        /// </summary>
        /// <param name="map">The <see cref="EditorMap"/>.</param>
        /// <param name="worldPos">The world position.</param>
        /// <returns>The selectable object currently under the cursor, or null if none.</returns>
        protected override object GetObjUnderCursor(EditorMap map, Vector2 worldPos)
        {
            var closestLight = map.Lights.MinElementOrDefault(x => worldPos.QuickDistance(x.Center));
            if (closestLight == null)
                return null;

            if (worldPos.QuickDistance(closestLight.Center) > 10)
                return null;

            return closestLight;
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:17,代码来源:MapLightCursorTool.cs

示例3: MapContainer_KeyDown

        /// <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);
        }
开发者ID:wtfcolt,项目名称:game,代码行数:21,代码来源:MapSaveAsTool.cs

示例4: MapContainer_MouseMove

        /// <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);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:59,代码来源:MapCursorToolBase.cs

示例5: CanSelect

 /// <summary>
 /// When overridden in the derived class, gets if this cursor can select the given object.
 /// </summary>
 /// <param name="map">The map containing the object to be selected.</param>
 /// <param name="obj">The object to try to select.</param>
 /// <returns>
 /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false.
 /// </returns>
 protected override bool CanSelect(EditorMap map, object obj)
 {
     return (obj is MapGrh) && base.CanSelect(map, obj);
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:12,代码来源:MapGrhCursorTool.cs

示例6: MapContainer_MouseUp

        /// <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);
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:61,代码来源:MapEntityCursorTool.cs

示例7: MapContainer_MouseMove

        /// <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;
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:17,代码来源:MapLightCursorTool.cs

示例8: CanSelect

        /// <summary>
        /// When overridden in the derived class, gets if this cursor can select the given object.
        /// </summary>
        /// <param name="map">The map containing the object to be selected.</param>
        /// <param name="obj">The object to try to select.</param>
        /// <returns>
        /// True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false.
        /// </returns>
        protected override bool CanSelect(EditorMap map, object obj)
        {
            if (Input.IsKeyDown(_placeMapGrhKey))
                return false;

            return (obj is MapGrh) && base.CanSelect(map, obj);
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:15,代码来源:MapGrhCursorTool.cs

示例9: GetFillMapGrhs

 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();
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:7,代码来源:MapGrhFillTool.cs

示例10: HandleMouseClickAndMove

        /// <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);
                    }
                }
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:59,代码来源:MapGrhFillTool.cs

示例11: CanSelect

 /// <summary>
 /// When overridden in the derived class, gets if this cursor can select the given object.
 /// </summary>
 /// <param name="map">The map containing the object to be selected.</param>
 /// <param name="obj">The object to try to select.</param>
 /// <returns>True if the <paramref name="obj"/> can be selected and handled by this cursor; otherwise false.</returns>
 protected virtual bool CanSelect(EditorMap map, object obj)
 {
     return IsObjectVisible(map, obj);
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:10,代码来源:MapCursorToolBase.cs

示例12: MapContainer_MouseUp

        /// <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);
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:28,代码来源:MapCursorToolBase.cs

示例13: MapContainer_MouseMove

        /// <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);
                        }
                    }
                }
            }
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:43,代码来源:MapGrhCursorTool.cs

示例14: MapContainer_MouseWheel

        /// <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);
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:27,代码来源:MapGrhCursorTool.cs

示例15: MapContainer_MouseMove

 /// <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);
 }
开发者ID:mateuscezar,项目名称:netgore,代码行数:12,代码来源:MapGrhFillTool.cs


注:本文中的EditorMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。