Пример #1
0
        public Editor(EventHandler callback, string mapFilePath, int mapWidth, int mapHeight)
            : base(callback)
        {
            if (mapFilePath != null)
                map = new Map(mapFilePath);
            else
                map = new Map(mapWidth, mapHeight);

            actualMapWidth = map.Width * map.TileSize;
            actualMapHeight = map.Height * map.TileSize;

            uiViewport = GraphicsDevice.Viewport;
            worldViewport = GraphicsDevice.Viewport;
            worldViewport.Height -= (minimapSize + minimapBorderSize * 2);
            GraphicsDevice.Viewport = worldViewport;

            initializeMinimap();

            camera = new Camera();
            camera.Pos = new Vector2(worldViewport.Width / 2, worldViewport.Height / 2);

            if (!contentLoaded)
            {
                normalCursor = Util.LoadCustomCursor(@"Content/SC2-cursor.cur");

                tileSelectionFont = Content.Load<SpriteFont>("tileSelectionFont");
                buttonFont = Content.Load<SpriteFont>("buttonFont");
                smallFont = Content.Load<SpriteFont>("smallFont");

                whiteBoxTexture = Content.Load<Texture2D>("whitebox");
                boulder1Texture = Content.Load<Texture2D>("boulder1");
                tree1Texture = Content.Load<Texture2D>("tree2");
                roksTexture = Content.Load<Texture2D>("WC2Gold");
                startingPointTexture = Content.Load<Texture2D>("HumanTownhall");
                eraserTexture = Content.Load<Texture2D>("eraser");

                mirrorLeftToRightTexture = Content.Load<Texture2D>("rotate left to right");
                mirrorTopToBottomTexture = Content.Load<Texture2D>("rotate top to bottom");
                rotateTexture = Content.Load<Texture2D>("rotate");

                contentLoaded = true;
            }

            initializeTileSelectionAreas();

            winForm = (Form)Form.FromHandle(Game1.Game.Window.Handle);
            //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size);
            //winForm.Cursor = normalCursor;

            line = new PrimitiveLine(GraphicsDevice, 1);
            line.Colour = Color.White * .5f;
            //line.Alpha = .5f;

            int buttonWidth = 50, buttonHeight = 20;
            int buttonPosY = minimap.Y + minimap.Height - buttonHeight;
            int saveButtonPosX = (int)(minimapPosX + minimap.Width + (resourceSelectionArea.X - minimapPosX - minimap.Width) * .3f - buttonWidth / 2);
            saveButton = new SimpleButton(new Rectangle(saveButtonPosX, buttonPosY, buttonWidth, buttonHeight));
            SimpleButton.AddButton(saveButton);

            int exitButtonPosX = (int)(minimapPosX + minimap.Width + (resourceSelectionArea.X - minimapPosX - minimap.Width) * .6f - buttonWidth / 2);
            exitButton = new SimpleButton(new Rectangle(exitButtonPosX, buttonPosY, buttonWidth, buttonHeight));
            SimpleButton.AddButton(exitButton);

            buttonWidth = buttonWidth / 2 - 1;
            buttonHeight -= 1;

            mirrorLeftToRightButton = new SimpleButton(new Rectangle(saveButtonPosX, minimapPosY + buttonHeight + 2, buttonWidth, buttonHeight), mirrorLeftToRightTexture, null, null);
            SimpleButton.AddButton(mirrorLeftToRightButton);

            mirrorTopToBottomButton = new SimpleButton(new Rectangle(saveButtonPosX + buttonWidth + 2, minimapPosY + buttonHeight + 2, buttonWidth, buttonHeight), mirrorTopToBottomTexture, null, null);
            SimpleButton.AddButton(mirrorTopToBottomButton);

            rotateLeftToRightButton = new SimpleButton(new Rectangle(saveButtonPosX, mirrorLeftToRightButton.Y + buttonHeight + 1, buttonWidth, buttonHeight), mirrorLeftToRightTexture, null, null);
            SimpleButton.AddButton(rotateLeftToRightButton);

            rotateTopToBottomButton = new SimpleButton(new Rectangle(saveButtonPosX + buttonWidth + 2, mirrorLeftToRightButton.Y + buttonHeight + 1, buttonWidth, buttonHeight), mirrorTopToBottomTexture, null, null);
            SimpleButton.AddButton(rotateTopToBottomButton);

            rotateButton = new SimpleButton(new Rectangle(saveButtonPosX, rotateLeftToRightButton.Y + buttonHeight + 1, buttonWidth, buttonHeight), rotateTexture, null, null);
            SimpleButton.AddButton(rotateButton);

            int brushSizePosX = exitButtonPosX + exitButton.Width / 2 - buttonWidth / 2;

            brushSize0Button = new SimpleButton(new Rectangle(brushSizePosX, minimapPosY + 2 + buttonHeight + 1, buttonWidth, buttonHeight), ColorTexture.Black, null, null);
            SimpleButton.AddButton(brushSize0Button);

            brushSize1Button = new SimpleButton(new Rectangle(brushSizePosX, brushSize0Button.Y + buttonHeight + 1, buttonWidth, buttonHeight), ColorTexture.Black, null, null);
            SimpleButton.AddButton(brushSize1Button);

            brushSize2Button = new SimpleButton(new Rectangle(brushSizePosX, brushSize1Button.Y + buttonHeight + 1, buttonWidth, buttonHeight), ColorTexture.Black, null, null);
            SimpleButton.AddButton(brushSize2Button);

            int startingPointButtonPosX = (int)(minimapPosX + minimap.Width + (resourceSelectionArea.X - minimapPosX - minimap.Width) * .825f - buttonWidth / 2);
            startingPointButton = new SimpleButton(new Rectangle(startingPointButtonPosX, resourceSelectionArea.Y + resourceSelectionArea.Height / 3 - buttonHeight / 2, buttonWidth, buttonHeight));
            startingPointButton.Texture = startingPointTexture;
            SimpleButton.AddButton(startingPointButton);

            eraserButton = new SimpleButton(new Rectangle(startingPointButtonPosX, (int)(resourceSelectionArea.Y + resourceSelectionArea.Height * .7f - buttonHeight / 2), buttonWidth, buttonHeight));
            eraserButton.Texture = eraserTexture;
            SimpleButton.AddButton(eraserButton);

            int saveMenuWidth = uiViewport.Width / 3, saveMenuHeight = uiViewport.Height / 3;
            saveMenuRectangle = new Rectangle(uiViewport.Width / 2 - saveMenuWidth / 2, uiViewport.Height / 2 - saveMenuHeight / 2, saveMenuWidth, saveMenuHeight);

            buttonWidth = saveMenuRectangle.Width / 5;
            buttonHeight = saveMenuRectangle.Height / 8;
            int spacing = 5;

            saveMenuSaveButton = new SimpleButton(new Rectangle(saveMenuRectangle.X + spacing, saveMenuRectangle.Y + saveMenuRectangle.Height - buttonHeight - spacing, buttonWidth, buttonHeight));
            SimpleButton.AddButton(saveMenuSaveButton);

            saveMenuExitButton = new SimpleButton(new Rectangle(saveMenuRectangle.X + saveMenuRectangle.Width - buttonWidth - spacing, saveMenuRectangle.Y + saveMenuRectangle.Height - buttonHeight - spacing, buttonWidth, buttonHeight));
            SimpleButton.AddButton(saveMenuExitButton);
        }
Пример #2
0
        void initializeMinimap()
        {
            minimapPosX = minimapBorderSize;
            minimapPosY = uiViewport.Height - minimapSize - minimapBorderSize;
            minimapToMapRatioX = (float)minimapSize / (map.Width * map.TileSize);
            minimapToMapRatioY = (float)minimapSize / (map.Height * map.TileSize);
            minimapToScreenRatioX = (float)minimapSize / worldViewport.Width;
            minimapToScreenRatioY = (float)minimapSize / worldViewport.Height;
            minimap = new Rectangle(minimapPosX, minimapPosY, minimapSize, minimapSize);
            minimapScreenIndicatorBox = new BaseObject(new Rectangle(0, 0, (int)(worldViewport.Width * minimapToMapRatioX), (int)(worldViewport.Height * minimapToMapRatioY)));

            minimapScreenIndicatorBoxLine = new PrimitiveLine(GraphicsDevice, 1);
            minimapScreenIndicatorBoxLine.Colour = Color.White;
        }