public void ClosePanel(string tag) { if (tag == null) { ClosePanelAction.Invoke(this.tag); } else { ClosePanelAction.Invoke(tag); } container.RemoveMenu(this); }
public override void HandleInput(InputManager input) { //Computing absolute position to check collision Vector2f mousePos; bool mouse = input.GetMousePosition(out mousePos); Vector2i origin = new Vector2i(0, 0); MenuComponent bubble = parent; while (bubble != null) { origin += bubble.position; bubble = bubble.parent; } Vector2f pos = new Vector2f((position + origin).X, (origin + position).Y); //If the menu is collided with then it will consume the mouse position so that it does not interact with anything else bool collided = BoundingBox.CheckPointMenuCollision(mousePos.X, mousePos.Y, collisionBox, pos); if (mouse && input.GetMouseClicked(InputBindings.primary, false) && collided && container != null) { container.PushMenuToFront(this); } base.HandleInput(input); if (closePanelKey != InputBindings.nullKey && input.GetKeyPressed(closePanelKey, true)) { ClosePanelAction?.Invoke(tag); container.RemoveMenu(this); return; } //Panel consumes the position of the mouse after processing child input if it hasn't already been consumed. if (collided) { input.ConsumeMousePosition(); } //Dragging logic if (panelState == PanelState.Dragging && input.GetMouseReleased(InputBindings.primary, false)) { panelState = PanelState.Normal; } if (panelState == PanelState.Normal && input.GetMouseClicked(InputBindings.primary, false) && collided) { input.GetMouseClicked(InputBindings.primary, true); panelState = PanelState.Dragging; this.Translate(input.GetMouseDiff()); } if (panelState == PanelState.Dragging) { this.Translate(input.GetMouseDiff()); } }