public void MouseDown(MapEditorTools Tool)
 {
     if (tool == MapEditorTools.None)
     {
         tool = Tool;
         if (tool == MapEditorTools.Pencil)
         {
             selectX = mouseX;
             selectY = mouseY;
             rectColor = rectPaintColor;
         }
         else
             rectColor = rectDefaultColor;
     }
 }
 public void MouseDown(MapEditorTools Tool)
 {
     if (tool == MapEditorTools.None)
     {
         tool = Tool;
         if (tool == MapEditorTools.Pencil || tool == MapEditorTools.Eyedropper)
         {
             selectX = mouseX;
             selectY = mouseY;
             selectWidth = 1;
             selectHeight = 1;
             endMouseX = mouseX;
             endMouseY = mouseY;
             if (tool == MapEditorTools.Pencil)
                 rectColor = rectPaintColor;
             else
                 rectColor = rectSelectColor;
         }
         else
             rectColor = rectDefaultColor;
     }
 }
        public void MouseUp(MapEditorTools Tool)
        {
            if (tool == Tool)
            {
                selectX = mouseX;
                selectY = mouseY;
                editorSelectWidth = 1;
                editorSelectHeight = 1;
                selectArray = new byte[] { (byte)(selectX + (selectY * 4)) };

                tool = MapEditorTools.None;
                rectColor = rectPaintColor;
            }
        }
        public void MouseUp(MapEditorTools Tool)
        {
            if (tool == Tool)
            {
                selectX = (mouseX > endMouseX) ? endMouseX : mouseX;
                selectY = (mouseY > endMouseY) ? endMouseY : mouseY;
                selectWidth = Math.Abs(mouseX - endMouseX) + 1;
                selectHeight = Math.Abs(mouseY - endMouseY) + 1;

                selectArray = new short[selectWidth * selectHeight];

                for (int i = 0; i < selectHeight; i++)
                    for (int j = 0; j < selectWidth; j++)
                        selectArray[(i * selectWidth) + j] = (short)((selectX + (selectY * 8)) + (i * 8) + j);
                /*
                foreach (var item in Program.glMapEditor.selectArray)
                {
                    Console.WriteLine(item.ToString("X4"));
                }*/

                tool = MapEditorTools.None;
                rectColor = rectPaintColor;
            }
        }
 public void MouseDown(MapEditorTools Tool)
 {
     if (tool == MapEditorTools.None)
     {
         tool = Tool;
         if (tool == MapEditorTools.Pencil)
         {
             rectColor = rectPaintColor;
             oldBorder = new short[Program.currentLayout.borderWidth * Program.currentLayout.borderHeight];
             Buffer.BlockCopy(Program.currentLayout.border, 0, oldBorder, 0, Program.currentLayout.border.Length);
             PaintBlocksToBorder(Program.glBlockChooser.selectArray, mouseX, mouseY, Program.glBlockChooser.editorSelectWidth, Program.glBlockChooser.editorSelectHeight);
             //Paint();
         }
         else if (tool == MapEditorTools.Eyedropper)
         {
             Program.glBlockChooser.editorSelectWidth = 1;
             Program.glBlockChooser.editorSelectHeight = 1;
             endMouseX = mouseX;
             endMouseY = mouseY;
             rectColor = rectSelectColor;
         }
         else if (tool == MapEditorTools.Fill)
         {
             if (Program.glBlockChooser.selectArray.Length == 1)
             {
                 short originalBlock = Program.currentLayout.border[(mouseX + (mouseY * Program.currentLayout.borderWidth))];
                 short newBlock = Program.glBlockChooser.selectArray[0];
                 rectColor = rectPaintColor;
                 if (originalBlock != newBlock)
                 {
                     oldBorder = new short[Program.currentLayout.borderWidth * Program.currentLayout.borderHeight];
                     Buffer.BlockCopy(Program.currentLayout.border, 0, oldBorder, 0, Program.currentLayout.border.Length);
                     FillBlocks(mouseX, mouseY, originalBlock, newBlock);
                     StoreChangesToUndoBufferAndRedraw();
                 }
             }
         }
         else if (tool == MapEditorTools.FillAll)
         {
             if (Program.glBlockChooser.selectArray.Length == 1)
             {
                 short originalBlock = Program.currentLayout.border[(mouseX + (mouseY * Program.currentLayout.layoutWidth))];
                 short newBlock = Program.glBlockChooser.selectArray[0];
                 if (originalBlock != newBlock)
                 {
                     rectColor = rectPaintColor;
                     oldBorder = new short[Program.currentLayout.borderWidth * Program.currentLayout.borderHeight];
                     Buffer.BlockCopy(Program.currentLayout.border, 0, oldBorder, 0, Program.currentLayout.border.Length);
                     for (int i = 0; i < Program.currentLayout.border.Length; i++)
                     {
                         if (Program.currentLayout.border[i] == originalBlock)
                             Program.currentLayout.border[i] = newBlock;
                     }
                     StoreChangesToUndoBufferAndRedraw();
                 }
             }
         }
         else
             rectColor = rectDefaultColor;
     }
 }
        public void MouseUp(MapEditorTools Tool)
        {
            if (tool == Tool)
            {
                if (tool == MapEditorTools.Eyedropper)
                {
                    Program.glBlockChooser.editorSelectWidth = Math.Abs(mouseX - endMouseX) + 1;
                    Program.glBlockChooser.editorSelectHeight = Math.Abs(mouseY - endMouseY) + 1;

                    Program.glBlockChooser.selectArray = new short[Program.glBlockChooser.editorSelectWidth * Program.glBlockChooser.editorSelectHeight];

                    for (int i = 0; i < Program.glBlockChooser.editorSelectHeight; i++)
                        for (int j = 0; j < Program.glBlockChooser.editorSelectWidth; j++)
                            Program.glBlockChooser.selectArray[(i * Program.glBlockChooser.editorSelectWidth) + j] = Program.currentLayout.border[(((mouseX > endMouseX) ? endMouseX : mouseX) + (((mouseY > endMouseY) ? endMouseY : mouseY) * Program.currentLayout.borderWidth)) + (i * Program.currentLayout.borderWidth) + j];

                    /*
                    foreach (var item in selectArray)
                    {
                        Console.WriteLine(item.ToString("X4"));
                    }*/

                    if (Program.glBlockChooser.editorSelectWidth == 1 && Program.glBlockChooser.editorSelectHeight == 1)
                        Program.glBlockChooser.SelectBlock(Program.glBlockChooser.selectArray[0] & 0x3FF);

                    else if (Program.glBlockChooser.editorSelectWidth > 1 || Program.glBlockChooser.editorSelectHeight > 1)
                        Program.glBlockChooser.SelectBlock(-1);
                }
                else if (tool == MapEditorTools.Pencil)
                {
                    int x = int.MaxValue;
                    int y = int.MaxValue;
                    int w = -1;
                    int h = -1;

                    for (int i = 0; i < oldBorder.Length; i++)
                    {
                        if (oldBorder[i] != Program.currentLayout.border[i])
                        {
                            if (i % Program.currentLayout.borderWidth < x)
                                x = i % Program.currentLayout.borderWidth;
                            if (i / Program.currentLayout.borderWidth < y)
                                y = i / Program.currentLayout.borderWidth;
                        }
                    }

                    if (x < int.MaxValue && y < int.MaxValue)
                    {
                        for (int i = oldBorder.Length - 1; i >= 0; i--)
                        {
                            if (oldBorder[i] != Program.currentLayout.border[i])
                            {
                                if (i % Program.currentLayout.borderWidth - x + 1 > w)
                                    w = i % Program.currentLayout.borderWidth - x + 1;
                                if (i / Program.currentLayout.borderWidth - y + 1 > h)
                                    h = i / Program.currentLayout.borderWidth - y + 1;
                            }
                        }

                        if (w > 0 && h > 0)
                        {
                            short[] oldData = new short[w * h];
                            short[] newData = new short[w * h];
                            for (int k = 0; k < h; k++)
                            {
                                for (int l = 0; l < w; l++)
                                {
                                    if ((x + l < Program.currentLayout.borderWidth) && (y + k < Program.currentLayout.borderHeight))
                                    {
                                        oldData[(k * w) + l] = oldBorder[(x + (y * Program.currentLayout.borderWidth)) + (k * Program.currentLayout.borderWidth) + l];
                                        newData[(k * w) + l] = Program.currentLayout.border[(x + (y * Program.currentLayout.borderWidth)) + (k * Program.currentLayout.borderWidth) + l];
                                    }
                                }
                            }
                            UndoManager.Add(new Undo.PaintBorderUndo(oldData, newData, x, y, w, h), false);
                        }
                    }
                }

                tool = MapEditorTools.None;
                rectColor = rectDefaultColor;
            }
        }
        public void MouseUp(MapEditorTools Tool)
        {
            if (tool == Tool)
            {
                if (tool == MapEditorTools.Eyedropper)
                {
                    if (Program.showingPerms)
                    {
                        Program.glPermsChooser.editorSelectWidth = Math.Abs(mouseX - endMouseX) + 1;
                        Program.glPermsChooser.editorSelectHeight = Math.Abs(mouseY - endMouseY) + 1;

                        Program.glPermsChooser.selectArray = new byte[Program.glPermsChooser.editorSelectWidth * Program.glPermsChooser.editorSelectHeight];

                        for (int i = 0; i < Program.glPermsChooser.editorSelectHeight; i++)
                            for (int j = 0; j < Program.glPermsChooser.editorSelectWidth; j++)
                                Program.glPermsChooser.selectArray[(i * Program.glPermsChooser.editorSelectWidth) + j] = (byte)((Program.currentLayout.layout[(((mouseX > endMouseX) ? endMouseX : mouseX) + (((mouseY > endMouseY) ? endMouseY : mouseY) * Program.currentLayout.layoutWidth)) + (i * Program.currentLayout.layoutWidth) + j] & 0xFC00) >> 10);

                        if (Program.glPermsChooser.editorSelectWidth == 1 && Program.glPermsChooser.editorSelectHeight == 1)
                            Program.glPermsChooser.SelectPerm(Program.glPermsChooser.selectArray[0]);

                        else if (Program.glPermsChooser.editorSelectWidth > 1 || Program.glPermsChooser.editorSelectHeight > 1)
                            Program.glPermsChooser.SelectPerm(-1);
                    }
                    else
                    {
                        Program.glBlockChooser.editorSelectWidth = Math.Abs(mouseX - endMouseX) + 1;
                        Program.glBlockChooser.editorSelectHeight = Math.Abs(mouseY - endMouseY) + 1;

                        Program.glBlockChooser.selectArray = new short[Program.glBlockChooser.editorSelectWidth * Program.glBlockChooser.editorSelectHeight];

                        for (int i = 0; i < Program.glBlockChooser.editorSelectHeight; i++)
                            for (int j = 0; j < Program.glBlockChooser.editorSelectWidth; j++)
                                Program.glBlockChooser.selectArray[(i * Program.glBlockChooser.editorSelectWidth) + j] = Program.currentLayout.layout[(((mouseX > endMouseX) ? endMouseX : mouseX) + (((mouseY > endMouseY) ? endMouseY : mouseY) * Program.currentLayout.layoutWidth)) + (i * Program.currentLayout.layoutWidth) + j];

                        if (Program.glBlockChooser.editorSelectWidth == 1 && Program.glBlockChooser.editorSelectHeight == 1)
                            Program.glBlockChooser.SelectBlock(Program.glBlockChooser.selectArray[0] & 0x3FF);

                        else if (Program.glBlockChooser.editorSelectWidth > 1 || Program.glBlockChooser.editorSelectHeight > 1)
                            Program.glBlockChooser.SelectBlock(-1);
                    }
                }
                else if (tool == MapEditorTools.Pencil)
                {
                    int x = int.MaxValue;
                    int y = int.MaxValue;
                    int w = -1;
                    int h = -1;

                    for (int i = 0; i < oldLayout.Length; i++)
                    {
                        if (oldLayout[i] != Program.currentLayout.layout[i])
                        {
                            if (i % Program.currentLayout.layoutWidth < x)
                                x = i % Program.currentLayout.layoutWidth;
                            if (i / Program.currentLayout.layoutWidth < y)
                                y = i / Program.currentLayout.layoutWidth;
                        }
                    }

                    if (x < int.MaxValue && y < int.MaxValue)
                    {
                        for (int i = oldLayout.Length - 1; i >= 0; i--)
                        {
                            if (oldLayout[i] != Program.currentLayout.layout[i])
                            {
                                if (i % Program.currentLayout.layoutWidth - x + 1 > w)
                                    w = i % Program.currentLayout.layoutWidth - x + 1;
                                if (i / Program.currentLayout.layoutWidth - y + 1 > h)
                                    h = i / Program.currentLayout.layoutWidth - y + 1;
                            }
                        }

                        if (w > 0 && h > 0)
                        {
                            short[] oldData = new short[w * h];
                            short[] newData = new short[w * h];
                            for (int k = 0; k < h; k++)
                            {
                                for (int l = 0; l < w; l++)
                                {
                                    if ((x + l < Program.currentLayout.layoutWidth) && (y + k < Program.currentLayout.layoutHeight))
                                    {
                                        oldData[(k * w) + l] = oldLayout[(x + (y * Program.currentLayout.layoutWidth)) + (k * Program.currentLayout.layoutWidth) + l];
                                        newData[(k * w) + l] = Program.currentLayout.layout[(x + (y * Program.currentLayout.layoutWidth)) + (k * Program.currentLayout.layoutWidth) + l];
                                    }
                                }
                            }
                            UndoManager.Add(new Undo.PaintUndo(oldData, newData, x, y, w, h), false);
                        }
                    }
                }

                tool = MapEditorTools.None;
                rectColor = rectDefaultColor;
            }
        }
 public void MouseDown(MapEditorTools Tool)
 {
     if (tool == MapEditorTools.None)
     {
         tool = Tool;
         if (tool == MapEditorTools.Pencil)
         {
             rectColor = rectPaintColor;
             oldLayout = new short[Program.currentLayout.layoutWidth * Program.currentLayout.layoutHeight];
             Buffer.BlockCopy(Program.currentLayout.layout, 0, oldLayout, 0, Program.currentLayout.layout.Length);
             if(Program.showingPerms)
                 PaintPermsToMap(Program.glPermsChooser.selectArray, mouseX, mouseY, Program.glPermsChooser.editorSelectWidth, Program.glPermsChooser.editorSelectHeight);
             else
                 PaintBlocksToMap(Program.glBlockChooser.selectArray, mouseX, mouseY, Program.glBlockChooser.editorSelectWidth, Program.glBlockChooser.editorSelectHeight);
             //Paint();
         }
         else if (tool == MapEditorTools.Eyedropper)
         {
             if (Program.showingPerms)
             {
                 Program.glPermsChooser.editorSelectWidth = 1;
                 Program.glPermsChooser.editorSelectHeight = 1;
             }
             else
             {
                 Program.glBlockChooser.editorSelectWidth = 1;
                 Program.glBlockChooser.editorSelectHeight = 1;
             }
             endMouseX = mouseX;
             endMouseY = mouseY;
             rectColor = rectSelectColor;
         }
         else if (tool == MapEditorTools.Fill)
         {
             if (Program.glBlockChooser.selectArray.Length == 1)
             {
                 if (Program.showingPerms)
                 {
                     byte originalPerm = (byte)((Program.currentLayout.layout[(mouseX + (mouseY * Program.currentLayout.layoutWidth))] & 0xFC00) >> 10);
                     byte newPerm = Program.glPermsChooser.selectArray[0];
                     rectColor = rectPaintColor;
                     if (originalPerm != newPerm)
                     {
                         oldLayout = new short[Program.currentLayout.layoutWidth * Program.currentLayout.layoutHeight];
                         Buffer.BlockCopy(Program.currentLayout.layout, 0, oldLayout, 0, Program.currentLayout.layout.Length);
                         FillPerms(mouseX, mouseY, originalPerm, newPerm);
                         StoreChangesToUndoBufferAndRedraw();
                     }
                 }
                 else
                 {
                     short originalBlock = (short)(Program.currentLayout.layout[(mouseX + (mouseY * Program.currentLayout.layoutWidth))] & 0x3FF);
                     short newBlock = (short)(Program.glBlockChooser.selectArray[0] & 0x3FF);
                     rectColor = rectPaintColor;
                     if (originalBlock != newBlock)
                     {
                         oldLayout = new short[Program.currentLayout.layoutWidth * Program.currentLayout.layoutHeight];
                         Buffer.BlockCopy(Program.currentLayout.layout, 0, oldLayout, 0, Program.currentLayout.layout.Length);
                         FillBlocks(mouseX, mouseY, originalBlock, newBlock);
                         StoreChangesToUndoBufferAndRedraw();
                     }
                 }
             }
         }
         else if (tool == MapEditorTools.FillAll)
         {
             if (Program.glBlockChooser.selectArray.Length == 1)
             {
                 if (Program.showingPerms)
                 {
                     byte originalPerm = (byte)((Program.currentLayout.layout[(mouseX + (mouseY * Program.currentLayout.layoutWidth))] & 0xFC00) >> 10);
                     byte newPerm = Program.glPermsChooser.selectArray[0];
                     rectColor = rectPaintColor;
                     if (originalPerm != newPerm)
                     {
                         oldLayout = new short[Program.currentLayout.layoutWidth * Program.currentLayout.layoutHeight];
                         Buffer.BlockCopy(Program.currentLayout.layout, 0, oldLayout, 0, Program.currentLayout.layout.Length);
                         for (int i = 0; i < Program.currentLayout.layout.Length; i++)
                         {
                             if ((byte)((Program.currentLayout.layout[i] & 0xFC00) >> 10) == originalPerm)
                                 Program.currentLayout.layout[i] = (short)((Program.currentLayout.layout[i] & 0x3FF) + (newPerm << 10));
                         }
                         StoreChangesToUndoBufferAndRedraw();
                     }
                 }
                 else
                 {
                     short originalBlock = (short)(Program.currentLayout.layout[(mouseX + (mouseY * Program.currentLayout.layoutWidth))] & 0x3FF);
                     short newBlock = (short)(Program.glBlockChooser.selectArray[0] & 0x3FF);
                     if (originalBlock != newBlock)
                     {
                         rectColor = rectPaintColor;
                         oldLayout = new short[Program.currentLayout.layoutWidth * Program.currentLayout.layoutHeight];
                         Buffer.BlockCopy(Program.currentLayout.layout, 0, oldLayout, 0, Program.currentLayout.layout.Length);
                         for (int i = 0; i < Program.currentLayout.layout.Length; i++)
                         {
                             if ((short)(Program.currentLayout.layout[i] & 0x3FF) == originalBlock)
                                 Program.currentLayout.layout[i] = (short)(newBlock + (Program.currentLayout.layout[i] & 0xFC00));
                         }
                         StoreChangesToUndoBufferAndRedraw();
                     }
                 }
             }
         }
         else
             rectColor = rectDefaultColor;
     }
 }
Пример #9
0
        public MapEditor(GraphicsDevice graphicsDevice, ContentManager content)
        {
            GraphicsDevice = graphicsDevice;
            Content        = content;
            Input          = new Input();
            var bindings = new Dictionary <string, List <Keys> > {
                [Commands.CameraStrafeLeft] = new List <Keys> {
                    Keys.Left
                },
                [Commands.CameraStrafeRight] = new List <Keys> {
                    Keys.Right
                },
                [Commands.CameraForward] = new List <Keys> {
                    Keys.Up
                },
                [Commands.CameraBackward] = new List <Keys> {
                    Keys.Down
                },
                [Commands.CameraZoomIn] = new List <Keys> {
                    Keys.OemPlus, Keys.Add
                },
                [Commands.CameraZoomOut] = new List <Keys> {
                    Keys.OemMinus, Keys.Subtract
                },
                [Commands.CameraOrbitRight] = new List <Keys> {
                    Keys.PageDown
                },
                [Commands.CameraOrbitLeft] = new List <Keys> {
                    Keys.Delete
                },
                [Commands.CameraOrbitDown] = new List <Keys> {
                    Keys.End
                },
                [Commands.CameraOrbitUp] = new List <Keys> {
                    Keys.Home
                },

                [Commands.OpenMenu] = new List <Keys> {
                    Keys.Escape
                },

                [Commands.ToggleHexCoordinates] = new List <Keys> {
                    Keys.C
                },
                [Commands.ToggleHexGrid] = new List <Keys> {
                    Keys.G
                },
                [Commands.ToggleWireframe] = new List <Keys> {
                    Keys.W
                },
                [Commands.ToggleHexHeights] = new List <Keys> {
                    Keys.H
                },
                [Commands.CmdRaiseTerrain] = new List <Keys> {
                    Keys.F1
                },
                [Commands.CmdTrees] = new List <Keys> {
                    Keys.F2
                },


                [Commands.SaveMap] = new List <Keys> {
                    Keys.S
                },
                [Commands.LoadMap] = new List <Keys> {
                    Keys.L
                }
            };

            Input.AddBindings(bindings);

            Camera = new Camera(Input);
            Camera.SetLens(MathHelper.ToRadians(45), graphicsDevice.DisplayMode.AspectRatio, .01f, 1000f);
            Camera.LookAt(new Vector3(0, 10, 1), Vector3.Zero, Vector3.Up);

            SettingsMenu = new SettingsMenu(Exit, SaveMap, LoadMap);

            EditorPanel = new MapEditorTools(content);
            Interface.AddEntity(EditorPanel);



            SpriteBatch = new SpriteBatch(GraphicsDevice);
            _font       = Content.Load <SpriteFont>("default");

            var texture = Content.Load <Texture2D>("Dry Grass 2");

            Map = new HexMap(GraphicsDevice, 100, 100, texture, _font);
            MapResources.LoadContent(Content);
        }