private void HandleMouseInput(InputEventMouseButton eventMouseButton) { if (eventMouseButton.Pressed == false) { if (eventMouseButton.ButtonIndex == (int)ButtonList.Left) { if (mouseArea.state == MouseArea.State.Valid) { SetCell((int)mouseTile.x, (int)mouseTile.y, tileOf(materialPlaced)); tilePlacer.materialSupply[materialPlaced]--; } } else if (eventMouseButton.ButtonIndex == (int)ButtonList.Right) { var currentCell = GetCell((int)mouseTile.x, (int)mouseTile.y); if (currentCell != -1) { SetCell((int)mouseTile.x, (int)mouseTile.y, -1); tilePlacer.materialSupply[materialOf(currentCell)]++; } } else if (eventMouseButton.ButtonIndex == (int)ButtonList.WheelUp) { SwitchMaterial(); } else if (eventMouseButton.ButtonIndex == (int)ButtonList.WheelDown) { SwitchMaterial(); } } }
public static Vector3 GetMouseClickPosition(InputEventMouseButton mouseEvent) { var from = Camera.ProjectRayOrigin(mouseEvent.GlobalPosition); var to = from + Camera.ProjectRayNormal(mouseEvent.GlobalPosition) * 100; return(Raycast(from, to)); }
public void DoCameraZoom(Player instance, InputEventMouseButton emb) { if (currentZoom == null) { currentZoom = new Vector2(); } if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { if (zoomVal > instance.MinZoom) { currentZoom.x = instance.camera.Translation.z + instance.ZoomSpeed; currentZoom.y = instance.camera.Translation.y - 0.05f; zoomVal -= instance.ZoomSpeed; UpdateCameraZoom(instance); } } else if (emb.ButtonIndex == (int)ButtonList.WheelDown) { if (zoomVal < instance.MaxZoom) { currentZoom.x = instance.camera.Translation.z - instance.ZoomSpeed; currentZoom.y = instance.camera.Translation.y + 0.05f; zoomVal += instance.ZoomSpeed; UpdateCameraZoom(instance); } } } }
public void HandleMouseEvents(InputEventMouseButton button) { if (button.ButtonIndex == ButtonList.Left.Int()) { if (button.IsPressed()) { _leftMousePressed = true; } else if (!button.IsPressed() && _leftMousePressed) { _leftMousePressed = false; } } if (button.ButtonIndex == ButtonList.Right.Int()) { if (button.IsPressed()) { _rightMousePressed = true; } else if (!button.IsPressed() && _rightMousePressed) { _rightMousePressed = false; } } }
public static InputEvent ToAbsolute(this InputEvent _event) { if (_event is InputEventKey) { return(_event); } else if (_event is InputEventMouseButton) { var absolute = new InputEventMouseButton(); absolute.ButtonIndex = (_event as InputEventMouseButton).ButtonIndex; absolute.Pressed = false; return(absolute); } else if (_event is InputEventJoypadButton) { return(_event); } else if (_event is InputEventJoypadMotion) { return(_event); } else { return(_event); } }
/// <summary> /// Detect mouse button presses on this input key Control /// </summary> private void OnButtonPressed(InputEventMouseButton @event) { var groupList = GroupList; if (groupList.IsConflictDialogOpen()) { return; } if (groupList.ListeningForInput) { return; } switch (@event.ButtonIndex) { case (int)ButtonList.Left: wasPressingButton = true; OnRebindButtonPressed(); break; case (int)ButtonList.Right: Delete(); break; } }
/// <summary> /// Detect mouse button presses on this input key Control /// </summary> private void OnButtonPressed(InputEventMouseButton @event) { var groupList = GroupList; if (groupList == null) { GD.PrintErr($"Can't handle button press in {nameof(InputEventItem)} due to missing group list"); return; } if (groupList.IsConflictDialogOpen()) { return; } if (groupList.ListeningForInput) { return; } switch (@event.ButtonIndex) { case (int)ButtonList.Left: wasPressingButton = true; OnRebindButtonPressed(); break; case (int)ButtonList.Right: Delete(); break; } }
public override void _UnhandledInput(InputEvent @event) { if (@event is InputEventMouseButton) { InputEventMouseButton emb = (InputEventMouseButton)@event; if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { _playerCamera.Zoom -= new Vector2(0.1f, 0.1f); } if (emb.ButtonIndex == (int)ButtonList.WheelDown) { _playerCamera.Zoom += new Vector2(0.1f, 0.1f); } if (emb.ButtonIndex == (int)ButtonList.Middle) { _playerCamera.Zoom = new Vector2(1f, 1f); } _playerCamera.Zoom = new Vector2(x: Mathf.Clamp(_playerCamera.Zoom.x, 0.2f, 25), y: Mathf.Clamp(_playerCamera.Zoom.y, 0.2f, 25)); } } }
public override void _GuiInput(InputEvent @event) { var smh = @event; if (smh is InputEventMouseButton) { InputEventMouseButton iemb = (InputEventMouseButton)smh; if (iemb.Pressed) { SetTheme(pressed); isPressed = true; } else { DialoguePanel panel = (DialoguePanel)GetNode("../../../../"); if (isPressed && over && panel.unlocked) { var conn = (Connection)GetNode("../../../../../../../Connection"); var optionPacket = new GUIOptionPacket(uuid); conn.sendPacket(optionPacket); panel.unlocked = false; } SetTheme(over ? hover : normal); isPressed = false; } } }
private InputType GetInputType(InputEvent @event) { if (_commandDialog.Visible) { return(InputType.NOP); } if (@event is InputEventMouseButton) { InputEventMouseButton mouseButton = (InputEventMouseButton)@event; if (mouseButton.Pressed) { if (mouseButton.ButtonIndex == (int)ButtonList.Left) { if (_enemyNeighbors.Count > 0) { return(InputType.SELECT_ENEMY); } if (_selectedUnit != null) { return(InputType.MOVE_UNIT); } return(InputType.SELECT_UNIT); } if (mouseButton.ButtonIndex == (int)ButtonList.Right && _selectedUnit != null) { return(InputType.CANCEL); } } } if (@event is InputEventMouseMotion && _selectedUnit != null && _enemyNeighbors.Count == 0) { return(InputType.DRAW_PATH); } return(InputType.NOP); }
private void HandleMouseInput(InputEventMouseButton _mouseInput) { // Handles state of the mouse click. Move to position is based upon direction of the MoveCursor script, so this might seem a bit strange. // A more effective way wouldn't probably just get the mouse position vector here, do the math and determine the direction from that, but the movement // cursor script was already there doing that work, so why not. Vector2 positionToMove = player.GridPosition + movementCursor.MoveToPosition; if (_mouseInput.IsActionPressed("ui_left_click")) { if (IsPositionWalkable(positionToMove)) { if (!IsPositionOccupied(positionToMove)) { MovePlayer(positionToMove); } else // Position is occupied { InteractWithTileOccupant(positionToMove); turnManager.EmitSignal("turn_completed"); } } else if (!IsPositionWalkable(positionToMove) || movementCursor.MoveToPosition == new Vector2(0, 0)) // In valid turn, skip turn { turnManager.EmitSignal("turn_completed"); } } }
public void _onSelectionMarkerInputEvent(Viewport viewport, InputEventMouse inputEvent, int shapeIdx) { if (!inputEvent.IsPressed()) { return; } if (inputEvent.GetType() != typeof(InputEventMouseButton)) { return; } InputEventMouseButton inputEventMouseButton = inputEvent as InputEventMouseButton; Mob ownerMob = GetParentMob(); switch (inputEventMouseButton.ButtonIndex) { case 1: EmitSignal(nameof(LeftClick), ownerMob); break; case 2: EmitSignal(nameof(RightClick), ownerMob); break; } }
/// <summary> /// Handles input events in the tile bar. Mainly used for dragging the window /// while it's minimized. /// </summary> /// <param name="@event">Godot InputEvent containing event params</param> public void TitleBarGUIInputHandler(InputEvent @event) { if (@event is InputEventMouseButton) { GD.Print(@event); InputEventMouseButton eventArgs = (InputEventMouseButton)@event; if (eventArgs.ButtonIndex == 1) { if (eventArgs.Pressed) { Following = true; DragStart = GetLocalMousePosition(); } else { Following = false; DragStart = new Vector2(); } } } if (@event is InputEventMouseMotion && Following) { OS.WindowPosition += GetGlobalMousePosition() - DragStart; } }
//zoom camera public override void _UnhandledInput(InputEvent @event) { if (tipoCamera == TIPOCAMERA.NOCONTROL) { return; } const float velZ = 0.025f; if (@event is InputEventMouseButton) { InputEventMouseButton emb = (InputEventMouseButton)@event; if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { if (zoom < maxZoom) { zoom += velZ; } } if (emb.ButtonIndex == (int)ButtonList.WheelDown) { if (zoom > minZoom) { zoom -= velZ; } } camera.Zoom = Vector2.One * zoom; screenChange(); //control de limite de camara } } }
private async void OnMouseClick(InputEventMouseButton mouse) { var leftClick = mouse.IsPressed() && mouse.ButtonIndex == 1 && !mouse.Doubleclick; var leftDblClick = mouse.IsPressed() && mouse.ButtonIndex == 1 && mouse.Doubleclick; var rightClick = mouse.IsPressed() && mouse.ButtonIndex == 2 && !mouse.Doubleclick; var rightDblClick = mouse.IsPressed() && mouse.ButtonIndex == 2 && mouse.Doubleclick; var mousePos = mouse.Position; var raycast = await RaycastThroughCamera(mousePos); var shift = Input.IsKeyPressed((int)KeyList.Shift); var ctrl = Input.IsKeyPressed((int)KeyList.Control); var collider = raycast.collider; var pos = raycast.position; var dude = collider as DudeControl; var factory = collider as FactorySimple; var item = collider as GameItem; var block = collider as Block; var just_floor = dude == null && factory == null && item == null && block == null; var selected = Selection.Count > 0; if (leftClick && !shift && dude != null) { SelectOnly(dude); } if (leftClick && shift && dude != null) { SelectDude(dude); } if (leftClick && !shift && dude == null) { DeselectAll(); } if (leftDblClick && dude != null) { SelectAllDudesHere(); } if (leftClick && factory != null) { factory.Produce(); } if (rightClick && selected && !shift) { SelectionClearDuties(); } // if (rightClick && selected && just_floor) // SelectionMoveTo(pos); if (rightClick && selected && item != null) { SelectionMoveToAnd(pos, "Pick up", (d) => d.PickUp(item)); } if (rightClick && ctrl && selected && just_floor) { SelectionMoveToAnd(pos, "Drop item", (d) => d.DropItem()); } if (rightClick && Selection.Count == 1) { ShowPossibleAssignements(mousePos, raycast); } }
public override void _Input(InputEvent ev) { if (ev is InputEventMouseButton) { InputEventMouseButton evMB = (InputEventMouseButton)ev; if (evMB.ButtonIndex == (int)ButtonList.Middle) { dragging = false; if (evMB.Pressed) { dragging = true; } } else if (evMB.ButtonIndex == (int)ButtonList.WheelDown) { if (evMB.Pressed) { desiredCameraZoom += 1f + desiredCameraZoom * .1f; } } else if (evMB.ButtonIndex == (int)ButtonList.WheelUp) { if (evMB.Pressed) { desiredCameraZoom -= 1f + desiredCameraZoom * .1f; } } } if (ev is InputEventMouseMotion) { InputEventMouseMotion evMM = (InputEventMouseMotion)ev; if (dragging) { if (evMM.Shift) { Vector3 localMotion = new Vector3( evMM.Relative.x, evMM.Relative.y, 0f ) * cameraZoom * 0.001f; localMotion.y = -localMotion.y; desiredAnchorPosition -= GlobalTransform.basis.Xform(localMotion); } else { Vector3 rot = desiredAnchorRotation; rot.y -= evMM.Relative.x * .25f; rot.x -= evMM.Relative.y * .25f; desiredAnchorRotation = rot; } } } }
/// <summary> Bind a mouse button to fire an action. </summary> public static void BindMouseButton(ButtonList mouseButton, string actionName) { InputEventMouseButton inputEvent = new InputEventMouseButton(); inputEvent.ButtonIndex = (int)mouseButton; if (!InputMap.HasAction(actionName)) { InputMap.AddAction(actionName); } InputMap.ActionAddEvent(actionName, inputEvent); }
private void buyAndAddPlant(InputEventMouseButton eventMouseButton) { if (eventMouseButton.Pressed && this.money >= PLANT_COST) { plant plant = ((ResourceLoader.Load("plant.tscn") as PackedScene).Instance() as plant); plants.Add(plant); plant.Position = eventMouseButton.Position; AddChild(plant); this.money -= PLANT_COST; this.updateLabels(); } }
/// <summary> /// Move the camera depending of the key pressed or the motion detected /// </summary> /// <param name="inputEvent"></param> public override void _Input(InputEvent inputEvent) { base._Input(inputEvent); // Zoom when wheel is used if (inputEvent is InputEventMouseButton) { InputEventMouseButton mouseButtonEvent = inputEvent as InputEventMouseButton; if (mouseButtonEvent.IsAction("camera_zoom_out")) { if (this.Zoom.x < MAX_ZOOM_OUT.x) { this.Zoom = this.Zoom + Vector2.One * ZOOM_SPEED; } } else if (mouseButtonEvent.IsAction("camera_zoom_in")) { if (this.Zoom.x > MAX_ZOOM_IN.x) { this.Zoom = this.Zoom - Vector2.One * ZOOM_SPEED; } } } // Detect if the right button is just pressed or just released // and start camera movement if (inputEvent is InputEventMouseButton) { InputEventMouseButton mouseButtonEvent = inputEvent as InputEventMouseButton; if (mouseButtonEvent.IsActionPressed("camera_move_mouse")) { Input.SetMouseMode(Input.MouseMode.Captured); } if (mouseButtonEvent.IsActionReleased("camera_move_mouse")) { Input.SetMouseMode(Input.MouseMode.Visible); } } // If motion is detected and the right button is pressed, the camera is moved if (inputEvent is InputEventMouseMotion & Input.IsActionPressed("camera_move_mouse")) { InputEventMouseMotion mouseMotionEvent = inputEvent as InputEventMouseMotion; this.Translate(mouseMotionEvent.Relative); } }
private void OnInputEvent(Node viewport, InputEvent inputEvent, int shape) { if (inputEvent is InputEventMouseButton) { InputEventMouseButton mouseEvent = inputEvent as InputEventMouseButton; if (mouseEvent.Pressed && mouseEvent.ButtonIndex == (int)ButtonList.Left) { wasPressed = true; } if (!mouseEvent.Pressed && mouseEvent.ButtonIndex == (int)ButtonList.Left) { wasPressed = false; EmitSignal(nameof(Clicked)); } } }
public override void _UnhandledInput(InputEvent @event) { if (@event is InputEventMouseButton) { InputEventMouseButton emb = (InputEventMouseButton)@event; if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { Player.UsableSelected = (Usable.Type)Modulo((int)Player.UsableSelected - 1, Usable.nbUsables); } if (emb.ButtonIndex == (int)ButtonList.WheelDown) { Player.UsableSelected = (Usable.Type)Modulo((int)Player.UsableSelected + 1, Usable.nbUsables); } } } }
//public override void _UnhandledInput(InputEvent ev) public override void _Input(InputEvent ev) { if (ev is InputEventMouseButton) { InputEventMouseButton emb = (InputEventMouseButton)ev; if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { camera2D.Zoom *= (1 / 1.05f); } if (emb.ButtonIndex == (int)ButtonList.WheelDown) { camera2D.Zoom *= 1.05f; } } } }
/// <summary> Unbind a mouse button from firing an action. </summary> public static void UnbindMouseButton(ButtonList mouseButton, string actionName) { if (InputMap.HasAction(actionName)) { foreach (InputEvent inputEvent in InputMap.GetActionList(actionName)) { if (inputEvent is InputEventMouseButton) // It could also be an InputEventKey { InputEventMouseButton mbEvent = (InputEventMouseButton)inputEvent; if (mbEvent.ButtonIndex == (int)mouseButton) { InputMap.ActionEraseEvent(actionName, inputEvent); return; } } } } }
private void HandleClicks(InputEventMouseButton mb) { if (mb.IsActionPressed("LeftClick") && currentTile != null) { DragStartPayload payload = new DragStartPayload(this, currentTile); OnDragStarted?.Invoke(payload); currentTile.Visible = false; } else if (mb.IsActionReleased("LeftClick")) { DragStopPayload payload = new DragStopPayload(this); OnDragEnded?.Invoke(payload); } if (mb.IsActionPressed("RightClick")) { GetTree().SetInputAsHandled(); OnShowContextMenu?.Invoke(this); } }
public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion && Inventory.draggingItem && dragging) { RectGlobalPosition = GetGlobalMousePosition() - dragPosition; } if (@event is InputEventMouseButton) { InputEventMouseButton iemb = @event as InputEventMouseButton; if (iemb.ButtonIndex == 2 && GetGlobalRect().HasPoint(iemb.Position)) { if (lastRightclickCheck == 1) { int pos = getSlotPositionUnderMouse(); if (pos > 0) { requestItemUsage(pos); } else { if (window == WINDOW.EQUIPABLES) { if (data.type == ITEM_TYPES.WEAPON) { requestItemUsage(1); } } } } else { lastRightclickCheck = 0; } } lastRightclickCheck++; } }
public override void _UnhandledInput(InputEvent @event) { InputEventMouseButton e = @event as InputEventMouseButton; if (e != null) { if (e.IsActionPressed("mouse_left")) { if (cellHighlight.IsCellVacant()) { gameController.PlaceTower(curTower, gridPos); ChangeSelectedTower(""); } else { //SELECT TOWER // uiController.SetTower(null); gameController.SellTower(cellHighlight.GetCurTower()); } } } InputEventMouseMotion eM = @event as InputEventMouseMotion; if (eM != null) { uiController.SetTower(cellHighlight.GetCurTower()); // if (!cellHighlight.IsCellVacant()) { // uiController.SetTower(cellHighlight.GetCurTower()); // } else { // uiController.Set(); // // GD.Print(cellHighlight.GetCurTower(), "empty"); // } mousePos = eM.GlobalPosition - new Vector2(camera2D.GetOffset().x, 0); } }
public override void _Input(InputEvent @event) { if (@event.IsActionPressed("zoom_in")) { // don't zoom in past 0 if (Zoom > zoomConstant) { Zoom -= zoomConstant; } } else if (@event.IsActionPressed("zoom_out")) { // don't zoom out past 1 if (Zoom <= Vector2.One - zoomConstant) { Zoom += zoomConstant; } } if (@event is InputEventMouseMotion) { if (isPressed) { // event.relative is what direction the mouse is moving // multiply by zoom so that it isn't hard to control when we're zoomed in a lot // multiply by -1 to reverse direction; when the mouse goes left, the camera goes right Position += ((InputEventMouseMotion)@event).Relative * Zoom * -1; } } if (@event is InputEventMouseButton) { InputEventMouseButton mEvent = (InputEventMouseButton)@event; if (mEvent.ButtonIndex == 3 || mEvent.ButtonIndex == 2) { isPressed = mEvent.Pressed; } } }
public override void _GuiInput(InputEvent @event) { var smh = @event; if (smh is InputEventMouseButton) { InputEventMouseButton iemb = (InputEventMouseButton)smh; if (iemb.Pressed) { itemNode.SetTheme(pressed); itemNode.isPressed = true; } else { if (itemNode.isPressed && itemNode.over) { // Get Item Details 'n Stuff } itemNode.SetTheme(itemNode.over ? itemNode.hover : itemNode.normal); itemNode.isPressed = false; } } }
public override void _Input(InputEvent ev) { if (ev is InputEventMouseButton) { InputEventMouseButton emb = (InputEventMouseButton)ev; if (emb.IsPressed()) { if (emb.ButtonIndex == (int)ButtonList.WheelUp) { conternerButton.RectPosition += new Vector2(0, 20); conternerButton.RectPosition = conternerButton.RectPosition.Clamped(100); } if (emb.ButtonIndex == (int)ButtonList.WheelDown) { conternerButton.RectPosition += new Vector2(0, -20); if (conternerButton.RectPosition.y < 0) { conternerButton.RectPosition = Vector2.Zero; } } } } }
public override void _GuiInput(InputEvent @event) { var smh = @event; if (smh is InputEventMouseButton) { InputEventMouseButton iemb = (InputEventMouseButton)smh; if (iemb.Pressed) { SetTheme(pressed); isPressed = true; } else { if (isPressed && over) { // Get Item Details 'n Stuff } SetTheme(over ? hover : normal); isPressed = false; } } }