예제 #1
0
    VECTOR2 GetCurrentPosition()
    {
        var position = Entry.INPUT.Pointer.Position;

        VECTOR2.Transform(ref position, ref offsetInvert);
        return(position);
    }
예제 #2
0
    protected override void InternalDraw(GRAPHICS spriteBatch, Entry e)
    {
        base.InternalDraw(spriteBatch, e);

        spriteBatch.Draw(TEXTURE.Pixel, new RECT(0, offset.M32, 800, 1), COLOR.Lime, 0, 0, 0.5f, EFlip.None);
        spriteBatch.Draw(TEXTURE.Pixel, new RECT(offset.M31, 0, 1, 800), COLOR.Lime, 0, 0.5f, 0, EFlip.None);

        spriteBatch.Begin(offset);

        if (animation != null)
        {
            VECTOR2 pivotPoint = UIElement.CalcPivotPoint(VECTOR2.One, pivots[pivot]);
            spriteBatch.Draw(animation, VECTOR2.Zero, 0, pivotPoint.X, pivotPoint.Y);
        }

        for (int i = 0; i < rects.Count; i++)
        {
            spriteBatch.Draw(area, rects[i]);
        }
        if (Creating)
        {
            spriteBatch.Draw(area, RECT.CreateRectangle(start, GetCurrentPosition()));
        }

        spriteBatch.End();

        {
            VECTOR2 pivotPoint = UIElement.CalcPivotPoint(new VECTOR2(200, 200), pivots[pivot]);
            spriteBatch.Draw(TEXTURE.Pixel, new VECTOR2(offset.M31 + pivotPoint.X - 100, offset.M32 + pivotPoint.Y - 100), COLOR.Red, 0, 0.5f, 0.5f, 5, 5);
        }
    }
예제 #3
0
    VECTOR2 GetCurrentPosition()
    {
        var position = Entry.INPUT.Pointer.Position;

        VECTOR2.Transform(ref position, ref offsetInvert);
        position.X = (int)position.X / MAP.GRID * MAP.GRID - (position.X < 0 ? MAP.GRID : 0);
        position.Y = (int)position.Y / MAP.GRID * MAP.GRID + (position.Y > 0 ? MAP.GRID : 0);
        return(position);
    }
예제 #4
0
 int ClickIndex(out VECTOR2 position)
 {
     position = GetCurrentPosition();
     for (int i = rects.Count - 1; i >= 0; i--)
     {
         if (rects[i].Contains(position))
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #5
0
    protected override void InternalEvent(Entry e)
    {
        base.InternalEvent(e);
        // 切换锚点
        if (e.INPUT.Keyboard.IsClick(PCKeys.Enter))
        {
            pivot++;
            if (pivot == pivots.Length)
            {
                pivot = 0;
            }
        }
        // 空格重置视口
        if (e.INPUT.Keyboard.IsClick(PCKeys.Space))
        {
            ResetViewport();
        }
        // 保存数据到剪切板
        if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.S))
        {
            Copy();
        }
        // 创建或选中时上下左右微调
        if (dragIndex != -1)
        {
            if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.A) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Left))
            {
                dragOffset.X--;
            }
            if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.D) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Right))
            {
                dragOffset.X++;
            }
            if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.S) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Down))
            {
                dragOffset.Y++;
            }
            if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.W) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Up))
            {
                dragOffset.Y--;
            }
        }
        //else if (Creating)
        //{
        //    if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.A) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Left))
        //        start.X--;
        //    if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.D) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Right))
        //        start.X++;
        //    if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.S) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Down))
        //        start.Y++;
        //    if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.W) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Up))
        //        start.Y--;
        //}
        // 左键拖拽/生成矩形
        if (TBCanvas.IsHover && e.INPUT.Pointer.IsClick(0))
        {
            VECTOR2 position;
            int     index = ClickIndex(out position);
            if (index == -1)
            {
                // 创建新矩形
                start = position;
            }
            else
            {
                // 拖拽旧矩形
                dragIndex  = index;
                dragOffset = rects[dragIndex].Location;
            }
        }

        if (dragIndex != -1 && e.INPUT.Pointer.IsPressed(0))
        {
            // 拖拽
            rects[dragIndex] = new RECT(e.INPUT.Pointer.Position - e.INPUT.Pointer.ClickPosition + dragOffset, rects[dragIndex].Size);
        }

        if (e.INPUT.Pointer.IsRelease(0))
        {
            if (dragIndex != -1)
            {
                // 确认拖拽
                dragIndex = -1;
            }
            else if (Creating)
            {
                // 确认创建
                var add = RECT.CreateRectangle(start, GetCurrentPosition());
                if (add.Width >= 1 && add.Height >= 1)
                {
                    rects.Add(add);
                }
                start.X = float.NaN;
            }
        }

        if (e.INPUT.Pointer.IsClick(1))
        {
            if (dragIndex != -1)
            {
                // 取消拖拽
                rects[dragIndex] = new RECT(e.INPUT.Pointer.ClickPosition - dragOffset, rects[dragIndex].Size);
                dragIndex        = -1;
            }
            else if (Creating)
            {
                // 取消创建新矩形
                start.X = float.NaN;
            }
            else
            {
                // 删除矩形
                int index = ClickIndex();
                if (index != -1)
                {
                    rects.RemoveAt(index);
                }
            }
        }

        if (e.INPUT.Pointer.IsPressed(1))
        {
            // 拖拽地图
            var delta = e.INPUT.Pointer.DeltaPosition;
            offset.M31 += delta.X;
            offset.M32 += delta.Y;
            MATRIX2x3.Invert(ref offset, out offsetInvert);
        }
    }
예제 #6
0
    protected override void InternalDraw(GRAPHICS spriteBatch, Entry e)
    {
        base.InternalDraw(spriteBatch, e);

        #region 绘制网格
        if (display)
        {
            int size = (int)(MAP.GRID * offset.M11);

            int  col = (int)TBMap.Width / size / 2 + 1;
            int  row = (int)TBMap.Height / size / 2 + 1;
            RECT rect;
            rect.X      = 0;
            rect.Width  = TBMap.Width;
            rect.Height = 1;
            for (int i = -row; i <= row; i++)
            {
                rect.Y = TBMap.Height * 0.5f + offset.M32 % size - TBMap.Height * 0.5f % size + i * size;
                spriteBatch.Draw(TEXTURE.Pixel, rect, COLOR.Lime, 0, 0, 0.5f, EFlip.None);
            }
            rect.Y      = 0;
            rect.Width  = 1;
            rect.Height = TBMap.Height;
            for (int i = -col; i <= col; i++)
            {
                rect.X = TBMap.Width * 0.5f + offset.M31 % size - TBMap.Width * 0.5f % size + i * size;
                spriteBatch.Draw(TEXTURE.Pixel, rect, COLOR.Lime, 0, 0.5f, 0, EFlip.None);
            }
        }
        #endregion

        spriteBatch.Begin(offset);

        #region 绘制地图
        foreach (var item in map.Terrains)
        {
            item.Draw();
        }
        foreach (var item in map.Terrains)
        {
            if (item.Texture == null)
            {
                item.DrawHitArea();
            }
        }
        if (display)
        {
            foreach (var item in map.Terrains)
            {
                if (item.Texture != null)
                {
                    item.Draw();
                }
            }
            // 绘制地形的格子
            foreach (var item in map.Terrains)
            {
                spriteBatch.Draw(TEXTURE.Pixel, new RECT(item.X, item.Y, MAP.GRID, MAP.GRID), new COLOR(255, 255, 0, 32), 0, 0, 1, EFlip.None);
            }
            // 绘制地形碰撞信息

            // 绘制地形锁定信息
            foreach (var item in map.Terrains)
            {
                if (item.Lock == ELockMode.LockBack)
                {
                    font.Text = "←";
                    font.Draw(spriteBatch, new RECT(item.X, item.Y - MAP.GRID, MAP.GRID, MAP.GRID));
                }
                else if (item.Lock == ELockMode.LockForward)
                {
                    font.Text = "→";
                    font.Draw(spriteBatch, new RECT(item.X, item.Y - MAP.GRID, MAP.GRID, MAP.GRID));
                }
            }
        }
        #endregion

        spriteBatch.Draw(TEXTURE.Pixel, VECTOR2.Zero, COLOR.Yellow, 0, 0.5f, 0.5f, 5, 5);

        VECTOR2 position = GetCurrentPosition();
        #region 绘制当前绘制项

        // 绘制当前选中的格子
        spriteBatch.Draw(patchSelectedGrid, new RECT(position.X, position.Y, MAP.GRID, MAP.GRID), 0, 0, 1);

        if (painting.ID != 0)
        {
            if (painting.Texture == null)
            {
                painting.Data.DrawHitArea(position.X, position.Y - painting.Data.BoundingBox.Height, 1);
            }
            else
            {
                spriteBatch.Draw(painting.Texture, new VECTOR2(painting.X, painting.Y), new COLOR(255, 255, 255, 160), 0, 0, 1, 1, 1, painting.Data.Flip);
            }
        }

        #endregion

        spriteBatch.End();
    }
예제 #7
0
    protected override void InternalEvent(Entry e)
    {
        base.InternalEvent(e);

        // 空格重置视口
        if (e.INPUT.Keyboard.IsClick(PCKeys.Space))
        {
            ResetViewport();
        }
        // 滑轮缩放地图
        if (e.INPUT.Mouse.ScrollWheelValue != 0)
        {
            float scale = offset.M11;
            scale      = _MATH.Clamp(scale + e.INPUT.Mouse.ScrollWheelValue * 0.1f, 0.2f, 1);
            offset.M11 = scale;
            offset.M22 = scale;
            MATRIX2x3.Invert(ref offset, out offsetInvert);
        }
        if (e.INPUT.Pointer.IsPressed(1))
        {
            // 拖拽地图
            var delta = e.INPUT.Pointer.DeltaPosition;
            offset.M31 += delta.X;
            offset.M32 += delta.Y;
            MATRIX2x3.Invert(ref offset, out offsetInvert);
        }
        if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.A))
        {
            NewMap();
        }

        VECTOR2 position = GetCurrentPosition();

        painting.X = (int)position.X;
        painting.Y = (int)position.Y;
        int index = -1;

        for (int i = 0; i < map.Terrains.Count; i++)
        {
            if (map.Terrains[i].X == position.X && map.Terrains[i].Y == position.Y)
            {
                index = i;
                break;
            }
        }
        if (e.INPUT.Pointer.IsTap(1))
        {
            // 右键删除地形
            if (index != -1)
            {
                map.Terrains.RemoveAt(index);
            }
            // 右键取消绘制
            else
            {
                painting.ID = 0;
            }
        }
        // 左键刷地形
        if (e.INPUT.Pointer.IsClick(0))
        {
            if (painting.ID == 0)
            {
                // 拿起之前绘制的地形变成笔刷
                if (index != -1)
                {
                    painting.ID      = map.Terrains[index].ID;
                    painting.Data    = map.Terrains[index].Data;
                    painting.Texture = map.Terrains[index].Texture;
                }
            }
        }
        if (e.INPUT.Pointer.IsPressed(0))
        {
            if (e.INPUT.Keyboard.Alt)
            {
                // Alt + 左键删除地形
                if (index != -1)
                {
                    map.Terrains.RemoveAt(index);
                }
            }
            else if (painting.ID != 0 && TBMap.IsHover)
            {
                RECT rect = painting.Area;
                if (!map.Terrains.Any(t => t.Area.Intersects(rect)))
                {
                    // 刷地形
                    TERRAIN terrain = new TERRAIN();
                    terrain.ID      = painting.ID;
                    terrain.X       = painting.X;
                    terrain.Y       = painting.Y;
                    terrain.Data    = painting.Data;
                    terrain.Texture = painting.Texture;
                    map.Terrains.Add(terrain);
                }
            }
        }
        if (e.INPUT.Keyboard.IsClick(PCKeys.D1))
        {
            // 1修改锁定信息
            if (index != -1)
            {
                int value = (int)map.Terrains[index].Lock + 1;
                if (value > 2)
                {
                    value = 0;
                }
                map.Terrains[index].Lock = (ELockMode)value;
            }
        }
        else if (e.INPUT.Keyboard.IsClick(PCKeys.D2))
        {
        }
        else if (e.INPUT.Keyboard.IsClick(PCKeys.D3))
        {
            // 3修改显示额外信息
            display = !display;
        }
        // 保存地图
        if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.S))
        {
            if (e.INPUT.Keyboard.Shift || string.IsNullOrEmpty(mapFile))
            {
                _IO._iO.FileBrowserSave("NewMap", new string[] { MAP.FILE.Substring(1) },
                                        file =>
                {
                    mapFile = Path.GetFileNameWithoutExtension(file.File);
                    MAP.Save(mapFile, map.Terrains);
                });
            }
            else
            {
                MAP.Save(mapFile, map.Terrains);
            }
        }
    }