public virtual void Update(bool hasFocus = true) { Vector2i mousePos = RB.PointerPos() + new Vector2i(0, 1); // + 0, 1 is workaround for weird hovering behaviour?! UIObj on = null; List <UIObj> objsNoLongerUnderMouse = new List <UIObj>(); foreach (UIObj obj in objUnderMouse) { if (!obj.IsInBounds(mousePos) || !obj.isVisible) { if (objUnderMouse.Contains(obj)) { objsNoLongerUnderMouse.Add(obj); obj.OnMouseExit(); EventBus.UIMouseExit.Invoke(obj); } } } objUnderMouse.RemoveWhere((obj) => objsNoLongerUnderMouse.Contains(obj)); List <UIObj> uiObjsToUpdate = uiObjs; if (currentMsgBox != null) { uiObjsToUpdate = currentMsgBox.GetUIObjs(); } foreach (UIObj obj in uiObjsToUpdate) { if (obj.HasKeybind() && RB.KeyPressed(obj.GetKeybind())) { if (obj.IsInteractable) { EventBus.UIClick.Invoke(obj); obj.OnClick(); } } if (obj.IsInBounds(mousePos) && obj.isVisible) { if (!objUnderMouse.Contains(obj)) { objUnderMouse.Add(obj); obj.OnMouseEnter(); EventBus.UIMouseEnter.Invoke(obj); } } if (obj.IsInBounds(mousePos) && obj.IsInteractable) // && hasFocus) { { if (obj.currentState != UIObj.State.Hovered) { EventBus.UIHoverStart.Invoke(obj); } obj.currentState = UIObj.State.Hovered; on = obj; } else if (obj.currentState != UIObj.State.Disabled) { if (obj.currentState == UIObj.State.Hovered) { EventBus.UIHoverEnd.Invoke(obj); } obj.currentState = UIObj.State.Enabled; } obj.Update(); } if (RB.ButtonPressed(RB.BTN_POINTER_A) && hasFocus) { if (on != null) { on.currentState = UIObj.State.Pressed; mousePressedOn = on; SetFocus(on); } else { SetFocus(null); } } else if (RB.ButtonReleased(RB.BTN_POINTER_A)) { if (on == mousePressedOn && on != null) { if (on.currentState == UIObj.State.Hovered) { EventBus.UIClick.Invoke(on); } mousePressedOn.OnClick(); } mousePressedOn = null; } else if (RB.ButtonDown(RB.BTN_POINTER_A) && hasFocus) { if (mousePressedOn != null && on == mousePressedOn) { mousePressedOn.currentState = UIObj.State.Pressed; } else if (on != null) { on.currentState = UIObj.State.Enabled; } } }