public async Task <object> GetSelectionAsync(Func <bool> isCancelled = null, Coordinates focus = null) { focus = focus ?? new Coordinates(); foreach (List <MenuItemUI> row in menuItems) { foreach (MenuItemUI item in row) { item.UnHighlight(); } } menuItems[focus.Row][focus.Col].Highlight(); while (true) { Coordinates oldFocus = new Coordinates(focus); if (ControlManager.GetInputPressed(ControlManager.Left) || ControlManager.GetAxisPressed(ControlManager.Horizontal, false)) { focus.Col--; } if (ControlManager.GetInputPressed(ControlManager.Right) || ControlManager.GetAxisPressed(ControlManager.Horizontal, true)) { focus.Col++; } if (ControlManager.GetInputPressed(ControlManager.Up) || ControlManager.GetAxisPressed(ControlManager.Vertical, true)) { focus.Row--; } if (ControlManager.GetInputPressed(ControlManager.Down) || ControlManager.GetAxisPressed(ControlManager.Vertical, false)) { focus.Row++; } if (focus.Row < 0) { focus.Row = 0; } if (focus.Row >= menuItems.Count) { focus.Row = menuItems.Count - 1; } if (focus.Col < 0) { focus.Col = 0; } if (focus.Col >= menuItems[focus.Row].Count) { focus.Col = menuItems[focus.Row].Count - 1; } if (!focus.SameAs(oldFocus)) { foreach (List <MenuItemUI> row in menuItems) { foreach (MenuItemUI item in row) { item.UnHighlight(); } } menuItems[focus.Row][focus.Col].Highlight(); } if (ControlManager.GetInputPressed(ControlManager.Accept)) { return(menuItems[focus.Row][focus.Col].Data); } if (ControlManager.GetInputPressed(ControlManager.Deny) && cancelable) { return(null); } if (isCancelled != null && isCancelled()) { return(null); } await new WaitForUpdate(); } }
public async Task <object> GetSelectionAsync(Func <bool> isCancelled = null, int?startFocus = null) { focus = startFocus ?? focus; foreach (MenuItemUI item in menuItems) { item.UnHighlight(); } menuItems[focus].Highlight(); while (true) { int oldFocus = focus; // Handle player input if (ControlManager.GetInputPressed(ControlManager.Left) || ControlManager.GetAxisPressed(ControlManager.Horizontal, false)) { focus--; } if (ControlManager.GetInputPressed(ControlManager.Right) || ControlManager.GetAxisPressed(ControlManager.Horizontal, true)) { focus++; } // Cap focus if (focus < 0) { focus = 0; } if (focus >= menuItems.Count) { focus = menuItems.Count - 1; } // Handle moved selection if (focus != oldFocus) { foreach (MenuItemUI item in menuItems) { item.UnHighlight(); } menuItems[focus].Highlight(); if (!string.IsNullOrWhiteSpace(moveSound)) { AudioManager.PlaySoundEffect(moveSound); } } // Execute context action if (menuItems[focus].ContextAction != null) { menuItems[focus].ContextAction(menuItems[focus]); } // Return selected option if (ControlManager.GetInputPressed(ControlManager.Accept)) { // Play select sound if (!string.IsNullOrWhiteSpace(menuItems[focus].SelectSound)) { AudioManager.PlaySoundEffect(menuItems[focus].SelectSound); } else if (!string.IsNullOrWhiteSpace(selectSound)) { AudioManager.PlaySoundEffect(selectSound); } return(menuItems[focus].Data); } // Cancel if ( (ControlManager.GetInputPressed(ControlManager.Deny) && cancelable || queueCancel) || (isCancelled != null && isCancelled()) ) { if (!string.IsNullOrWhiteSpace(cancelSound)) { AudioManager.PlaySoundEffect(cancelSound); } return(null); } await new WaitForUpdate(); } }
public async Task <object> GetSelectionAsync(Func <bool> isCancelled = null, int focus = 0, int pageFocus = 0) { pages[pageFocus].gameObject.SetActive(true); pageCountComponent.text = $"{pageFocus + 1}/{pages.Count}"; while (true) { int oldFocus = focus; int oldPageFocus = pageFocus; if (ControlManager.GetInputPressed(ControlManager.Up) || ControlManager.GetAxisPressed(ControlManager.Vertical, true)) { focus--; } if (ControlManager.GetInputPressed(ControlManager.Down) || ControlManager.GetAxisPressed(ControlManager.Vertical, false)) { focus++; } if (ControlManager.GetInputPressed(ControlManager.Left) || ControlManager.GetAxisPressed(ControlManager.Horizontal, false)) { pageFocus--; } if (ControlManager.GetInputPressed(ControlManager.Right) || ControlManager.GetAxisPressed(ControlManager.Horizontal, true)) { pageFocus++; } if (pageFocus < 0) { pageFocus = 0; } if (pageFocus > pages.Count - 1) { pageFocus = pages.Count - 1; } if (focus < 0) { focus = 0; } if (focus > pages[pageFocus].MenuItems.Count - 1) { focus = pages[pageFocus].MenuItems.Count - 1; } if (pageFocus != oldPageFocus) { pageCountComponent.text = $"{pageFocus + 1}/{pages.Count}"; foreach (PageUI page in pages) { page.gameObject.SetActive(false); } pages[pageFocus].gameObject.SetActive(true); pages[pageFocus].HighlightItem(focus); } if (focus != oldFocus) { pages[pageFocus].HighlightItem(focus); } if (ControlManager.GetInputPressed(ControlManager.Accept)) { return(pages[pageFocus].MenuItems[focus].Data); } if (ControlManager.GetInputPressed(ControlManager.Deny) && cancelable) { return(null); } if (isCancelled != null && isCancelled()) { return(null); } await new WaitForUpdate(); } }