public void FocusFirstElement() { var firstElement = _interactableElements.FirstOrDefault(); if (firstElement == CurrentElement) { return; } CurrentElement?.Unfocus(); _elementToGetFocus = firstElement; }
public void ControllerOnMoveToPreviousElement() { var lastElement = CurrentElement; if (CurrentElement == null) { CurrentElement = _interactableElements.FirstOrDefault(); } else { var index = _interactableElements.IndexOf(CurrentElement); CurrentElement = index == 0 ? _interactableElements[_interactableElements.Count - 1] : _interactableElements[index - 1]; } if (lastElement != CurrentElement) { lastElement?.Unfocus(); CurrentElement?.Focus(); } }
public virtual void Update(GameTime gameTime) { if (_rearrangeList) { _interactableElements.RemoveAll(e => !e.IsInteractable); _interactableElements.Sort((e1, e2) => e1.TabIndex.CompareTo(e2.TabIndex)); } foreach (var inputController in InputControllers) { inputController.Update(this); } if (_elementToGetFocus != null && _elementToGetFocus.State == UiState.Active) { _elementToGetFocus.Focus(); CurrentElement = _elementToGetFocus; _elementToGetFocus = null; } }
private void ControllerOnMoveToNextElement() { var lastElement = CurrentElement; if (CurrentElement == null) { CurrentElement = _interactableElements.FirstOrDefault(); } else { var index = _interactableElements.IndexOf(CurrentElement); CurrentElement = index == _interactableElements.Count - 1 ? _interactableElements[0] : _interactableElements[index + 1]; } if (lastElement != CurrentElement) { lastElement?.Unfocus(); CurrentElement?.Focus(); } }
protected void AddUiElement(UiElement element) { _interactableElements.Add(element); _rearrangeList = true; }
public UiFocusContainer() { _interactableElements = new List <UiElement>(); InputControllers = new List <OverlayInputController>(); CurrentElement = null; }
private void ControllerOnOnAction(UiElement uiElement) { CurrentElement?.OnAction(); }
protected void RemoveChild(UiElement element) { _children.Remove(element); }
/// <summary> /// Adds a child control to compound element. /// </summary> /// <param name="element"></param> protected void AddChildElement(UiElement element) { _children.Add(element); }
protected void InvokeAction(UiElement element) { OnAction?.Invoke(element); }