//When the mouse is clicked, fire the event for when the button is pushed
 public override void onMouseClick(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     if (setEvent != null)
     {
         setEvent(true);
     }
 }
        /*
         * Handles a mouse down action
         */
        internal void mouseDownHandler(MouseKeyBinding.MouseButton button)
        {
            //Update floating pics (could be refactored)
            if (activeTool == actorTool)
            {
                actorTool.floatingPic.pos = new Vector2(engine.graphicsComponent.width, engine.graphicsComponent.height);
            }
            if (activeTool == eraseTool)
            {
                eraseTool.floatingPic.pos = new Vector2(engine.graphicsComponent.width, engine.graphicsComponent.height);
            }

            //Get the mouse position
            Vector2 screenPos = engine.inputComponent.getMousePosition();

            if (isActive && isEditing && editorGui.getItemAt(screenPos) == null)
            {
                //Fix floating pics
                if (activeTool == actorTool)
                {
                    actorTool.floatingPic.pos = screenPos + (new Vector2(actorTool.theActor.xoffset, actorTool.theActor.yoffset));
                }
                if (activeTool == eraseTool)
                {
                    eraseTool.floatingPic.pos = new Vector2(screenPos.x - eraseTool.floatingPic.size.x / 2, screenPos.y - eraseTool.floatingPic.size.y / 2);
                }

                //Notify active tool
                activeTool.downAction(button);
            }
        }
Exemple #3
0
        //Obtains the clicked item, calls that items click handler, and sets focus.
        private void handleClick(MouseKeyBinding.MouseButton button)
        {
            if (items == null)
            {
                return;
            }

            //Find the last (top) clicked item
            InputComponent ic          = graphics.engine.inputComponent;
            Vector2        pos         = ic.getMousePosition();
            GUIItem        clickedItem = getItemAt(pos);

            if (clickedItem != null)
            {
                clickedItem.handleMouseDown(pos, button);
            }

            //Set Focus
            if (focused != null)
            {
                focused.onBlur();
            }
            if (clickedItem == null || clickedItem.focusable)
            {
                focused = clickedItem;
            }
            if (focused != null)
            {
                focused.onFocus();
            }
        }
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            //set selection
            World   world     = editor.engine.world;
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            int xIndex = (int)(worldPos.x / Tile.size);
            int yIndex = (int)(worldPos.y / Tile.size);

            if (xIndex < 0)
            {
                xIndex = 0;
            }
            if (yIndex < 0)
            {
                yIndex = 0;
            }
            if (xIndex > world.width - 1)
            {
                xIndex = world.width - 1;
            }
            if (yIndex > world.height - 1)
            {
                yIndex = world.height - 1;
            }

            origin = new Vector2(xIndex, yIndex);
            Vector2 secondary = origin;

            if (mode == Mode.paste)
            {
                xIndex = (int)(origin.x + copiedSize.x);
                yIndex = (int)(origin.y + copiedSize.y);

                if (xIndex < 0)
                {
                    xIndex = 0;
                }
                if (yIndex < 0)
                {
                    yIndex = 0;
                }
                if (xIndex > world.width - 1)
                {
                    xIndex = world.width - 1;
                }
                if (yIndex > world.height - 1)
                {
                    yIndex = world.height - 1;
                }

                secondary = new Vector2(xIndex, yIndex);
            }


            selection  = new RectangleF(origin, secondary);
            isDragging = true;
        }
        /*
         * The function called when the plus button is pressed.
         * Increases the eraser circle size.
         */

        void increaseSizeAction(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            if (!floatingPic.size.Equals(maxSize))
            {
                floatingPic.size = new Vector2(floatingPic.size.x * 2, floatingPic.size.y * 2);
            }
            plus.texture = plus.unpressedImg;
        }
Exemple #6
0
        public void startGame(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            if (PlayerSelect.StartGame())
            {
                engine.setWorld("Maps/newWorld.map");

                gui.remove(StartLabel);
            }
        }
        /*
         * The function called when the minus button is pressed.
         * Decreases the eraser circle size.
         */

        void decreaseSizeAction(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            if (!floatingPic.size.Equals(minSize))
            {
                floatingPic.size = new Vector2(floatingPic.size.x / 2, floatingPic.size.y / 2);
            }

            minus.texture = minus.unpressedImg;
        }
Exemple #8
0
        public void showControls(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            menuUnload();
            addBackButton();

            Controls     = new GUILabel(gui, new Handle(engine.resourceComponent, "Menu/Controls.png"));
            Controls.pos = new Vector2(width / 2 - 475, height / 2 - 290);
            gui.add(Controls);
        }
Exemple #9
0
        private void handleClickUp(MouseKeyBinding.MouseButton m)
        {
            InputComponent ic  = graphics.engine.inputComponent;
            Vector2        pos = ic.getMousePosition();

            if (focused != null)
            {
                focused.handleMouseUp(pos, m);
            }
        }
        /*
         * Handles a mouse up action
         */
        internal void mouseUpHandler(MouseKeyBinding.MouseButton button)
        {
            //Get the mouse position
            Vector2 screenPos = engine.inputComponent.getMousePosition();

            if (isActive && isEditing && editorGui.getItemAt(screenPos) == null)
            {
                //Notify active tool
                activeTool.upAction(button);
            }
        }
 public void clearAction(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     for (int x = (int)selection.left; x <= (int)selection.right; x++)
     {
         for (int y = (int)selection.top; y <= (int)selection.bottom; y++)
         {
             editor.engine.world.file.worldTileData[0, x, y] = new Mapfile.TileData("");
             editor.engine.world.tileArray[x, y]             = new Tile(editor.engine.world, x, y, new Mapfile.TileData(""));
         }
     }
 }
 //Called when the mousebutton is pressed down
 public override void onMouseDown(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     if (isDown)
     {
         texture = checkUpImage;
     }
     else
     {
         texture = checkDownImage;
     }
 }
Exemple #13
0
 //Called when the mouse is pressed down. Changes the image on the button
 public override void onMouseDown(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     if (texture == _unpressedImg)
     {
         texture = _pressedImg;
     }
     else
     {
         texture = _unpressedImg;
     }
 }
Exemple #14
0
        public void loadTeamSelect(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            menuUnload();

            PlayerSelect = new PlayerSelection(engine, gui);

            PlayerSelect.LoadGuiElements();

            StartLabel = new GUILabel(gui, new Handle(engine.resourceComponent, "Menu/Start.png"));
            StartLabel.mouseClickEvent += startGame;
            StartLabel.pos              = new Vector2(width / 2 - 110, height - 96);
            gui.add(StartLabel);
        }
        //GUIItem's reaction to clicks
        internal virtual void handleMouseDown(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            if (!visible)
            {
                return;
            }

            //Handle Clicks
            onMouseDown(pos, button);
            if (mouseDownEvent != null)
            {
                mouseDownEvent(pos, button);
            }
        }
        public void pasteAction(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            if (mode != Mode.paste)
            {
                return;
            }

            for (int x = 0; x <= (int)selection.width; x++)
            {
                for (int y = 0; y <= (int)selection.height; y++)
                {
                    editor.engine.world.file.worldTileData[0, (int)selection.left + x, (int)selection.top + y].overWriteData(copiedTileData[x, y]);
                    editor.engine.world.tileArray[(int)selection.left + x, (int)selection.top + y].overWriteFromTileData(copiedTileData[x, y]);
                }
            }
        }
        public void copyAction(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            if (mode == Mode.paste)
            {
                return;
            }
            if (selection.topLeft == new Vector2(-1, -1))
            {
                return;
            }

            if (selection.size == Vector2.Zero)
            {
                editor.currentValues            = editor.engine.world.file.worldTileData[0, (int)selection.left, (int)selection.top];
                editor.currentValues.leftSlope  = 1f;
                editor.currentValues.rightSlope = 1f;
                editor.currentValues.normal     = 1;
                editor.currentTile = editor.currentValues;
                editor.pencilTool.updateStatus();
                return;
            }

            copiedSize     = selection.size;
            copiedTileData = new Mapfile.TileData[(int)selection.width + 1, (int)selection.height + 1];
            copiedTiles    = new Tile[(int)selection.width + 1, (int)selection.height + 1];
            Mapfile.TileData defaultTileData = new Mapfile.TileData("");

            for (int x = 0; x <= (int)selection.width; x++)
            {
                for (int y = 0; y <= (int)selection.height; y++)
                {
                    copiedTileData[x, y] = editor.engine.world.file.worldTileData[0, (int)selection.left + x, (int)selection.top + y];
                    if (copiedTileData[x, y].Equals(defaultTileData))
                    {
                        copiedTileData[x, y].setToIgnore();
                        copiedTiles[x, y] = new Tile(editor.engine.world, 0, 0, defaultTileData);
                    }
                    else
                    {
                        copiedTiles[x, y] = new Tile(editor.engine.world, (int)selection.left + x, (int)selection.top + y, copiedTileData[x, y]);
                    }
                }
            }

            mode = Mode.paste;
            modeControl.pressed = (int)mode;
        }
Exemple #18
0
        //Loads a new map
        void confirmAction(Vector2 confirmPos, MouseKeyBinding.MouseButton mouseButton)
        {
            int width  = 0;
            int height = 0;

            try
            {
                width  = int.Parse(widthEntry.text);
                height = int.Parse(heightEntry.text);
            }
            catch (Exception) { Trace.WriteLine("Bad input."); return; }

            editor.engine.newWorld(width, height);

            toolButton.resetImg();
            editor.editorGui.remove(toolDialog);
        }
Exemple #19
0
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            Tile victim = editor.engine.world.getTileAt(worldPos);

            if (victim != null)
            {
                FillToolAction action = fill(victim);
                if (action != null)
                {
                    toolAction.Push(action);
                    undos.Clear();
                }
            }

            isDragging = false;
        }
Exemple #20
0
        public void updateType(Vector2 pos, MouseKeyBinding.MouseButton mouseButton)
        {
            switch (TeamVal.PlayerType)
            {
            case player_type_t.Human:
                TeamVal.PlayerType = player_type_t.Computer;
                GuiLabel.texture   = new Handle(gameEngine.resourceComponent, SelectHandleNames.computerResString);
                break;

            case player_type_t.Computer:
                TeamVal.PlayerType = player_type_t.None;
                GuiLabel.texture   = new Handle(gameEngine.resourceComponent, SelectHandleNames.noneResString);
                break;

            case player_type_t.None:
                TeamVal.PlayerType = player_type_t.Human;
                GuiLabel.texture   = new Handle(gameEngine.resourceComponent, SelectHandleNames.humanResString);
                break;
            }
        }
        /**
         * This function is called when the mouse button is pressed down.
         *
         * @param button The MouseKeyBinding.MouseButton that was clicked down
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            IEnumerable <Actor> actorsToErase = editor.engine.world.getActorsInCone(worldPos, (floatingPic.size.x / 2) / (editor.engine.graphicsComponent.camera.scale), new Vector2(16, 16), 360, null);

            foreach (Actor target in actorsToErase)
            {
                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)editor.engine.world.actorFactory.names[target.actorName];
                w.x  = target.spawn.x;
                w.y  = target.spawn.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Remove(w);
                editor.engine.world.actors.Remove(target);
                target.removeMe = true;
            }

            isDragging = true;
        }
        public void selectBehaviorAction(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            openFile = "";
            DialogResult res;

            try
            {
                res = openDlg.ShowDialog();

                if (res == DialogResult.OK)
                {
                    openFile = openDlg.FileName;
                }
            }
            catch (Exception e) { }

            if (!openFile.Equals(""))
            {
                string key = ResourceComponent.getKeyFromPath(openFile);
                editor.engine.world.setWorldBehavior(editor.engine.resourceComponent.get(key));
                editor.engine.world.file.worldBehaviorKey = key;
            }
        }
        //GUIItem's reaction to released clicks
        internal virtual void handleMouseUp(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            if (!visible)
            {
                return;
            }

            //Handle Clicks
            onMouseUp(pos, button);
            if (mouseUpEvent != null)
            {
                mouseUpEvent(pos, button);
            }

            if (this.pos.x <= pos.x && pos.x <= this.pos.x + this.size.x &&
                this.pos.y <= pos.y && pos.y <= this.pos.y + this.size.y)
            {
                onMouseClick(pos, button);
                if (mouseClickEvent != null)
                {
                    mouseClickEvent(pos, button);
                }
            }
        }
Exemple #24
0
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public override void downAction(MouseKeyBinding.MouseButton button)
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();;
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            Tile victim = editor.engine.world.getTileAt(editor.engine.graphicsComponent.camera.screen2World(screenPos));

            if (victim != null)
            {
                Actor p = editor.engine.world.actorFactory.createActor(currentActorIndex, new Vector2(worldPos.x, worldPos.y), new Vector2(0, 0));
                editor.engine.world.addActor(p);

                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)currentActorIndex;
                w.x  = worldPos.x;
                w.y  = worldPos.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Add(w);

                undos.Clear();

                toolAction.Push(new ActorToolAction(w, this));
            }
        }
 /**
  * Called whenever the GUIItem is unclicked.
  */
 public virtual void onMouseUp(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
 }
 //Called when the mousebutton is let up
 public override void onMouseUp(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     refresh();
 }
        public bool pollEvents()
        {
            // Handle events
            Sdl.SDL_Event evt;
            MouseKeyBinding.MouseButton button = MouseKeyBinding.MouseButton.LEFT;
            if (Sdl.SDL_PollEvent(out evt) != 0)
            {
                switch (evt.type)
                {
                case Sdl.SDL_KEYDOWN:
                    keyEvent(evt.key.keysym.sym, evt.key.keysym.mod, true);
                    break;

                case Sdl.SDL_KEYUP:
                    keyEvent(evt.key.keysym.sym, evt.key.keysym.mod, false);
                    break;

                case Sdl.SDL_MOUSEMOTION:
                    mouseAxisEvent(InputComponent.MouseAxis.X, evt.motion.x);
                    mouseAxisEvent(InputComponent.MouseAxis.Y, evt.motion.y);
                    break;

                case Sdl.SDL_MOUSEBUTTONDOWN:
                    switch (evt.button.button)
                    {
                    case Sdl.SDL_BUTTON_LEFT:
                        button = MouseKeyBinding.MouseButton.LEFT;
                        break;

                    case Sdl.SDL_BUTTON_MIDDLE:
                        button = MouseKeyBinding.MouseButton.MIDDLE;
                        break;

                    case Sdl.SDL_BUTTON_RIGHT:
                        button = MouseKeyBinding.MouseButton.RIGHT;
                        break;
                    }
                    mouseButtonEvent(button, true);
                    break;

                case Sdl.SDL_MOUSEBUTTONUP:
                    switch (evt.button.button)
                    {
                    case Sdl.SDL_BUTTON_LEFT:
                        button = MouseKeyBinding.MouseButton.LEFT;
                        break;

                    case Sdl.SDL_BUTTON_MIDDLE:
                        button = MouseKeyBinding.MouseButton.MIDDLE;
                        break;

                    case Sdl.SDL_BUTTON_RIGHT:
                        button = MouseKeyBinding.MouseButton.RIGHT;
                        break;
                    }
                    mouseButtonEvent(button, false);
                    break;

                case Sdl.SDL_JOYBUTTONDOWN:
                    joyButtonEvent(evt.jbutton.which, evt.jbutton.button, true);
                    break;

                case Sdl.SDL_JOYBUTTONUP:
                    joyButtonEvent(evt.jbutton.which, evt.jbutton.button, false);
                    break;

                case Sdl.SDL_JOYAXISMOTION:
                    joyAxisEvent(evt.jaxis.which, evt.jaxis.axis, evt.jaxis.val);
                    break;

                case Sdl.SDL_JOYHATMOTION:
                    joyHatEvent(evt.jhat.which, evt.jhat.hat, evt.jhat.val);
                    break;

                case Sdl.SDL_QUIT:
                    return(true);
                }
            }

            return(false);
        }
 public void mouseButtonEvent(MouseKeyBinding.MouseButton id, bool down)
 {
     fireEvent(new MouseButtonEvent(id, down));
 }
Exemple #29
0
 public MouseButtonEvent(MouseKeyBinding.MouseButton id, bool down = false)
     : base(down)
 {
     this.id = id;
 }
Exemple #30
0
 //Called when the mouse is released
 public override void onMouseUp(Vector2 pos, MouseKeyBinding.MouseButton button)
 {
     base.onMouseUp(pos, button);
     texture = _unpressedImg;
 }