public void PlaySelectSound(SelectSound selectSound, float vol) { shortSrcIndex = (shortSrcIndex + 1) % shortAudioSources.Length; shortAudioSources[shortSrcIndex].PlaySound(selectSounds[(int)selectSound], vol * .6f, .05f); }
/// <summary> /// Handler for keyboard key presses /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void OnKeyPressed(object sender, KeyEventArgs e) { Vector2f?pointerPosition; if ((pointerPosition = Pointer.GetPosition()) == null) { LogManager.LogWarning("No position for the pointer found on the main menu"); return; } switch (e.Code) { case Keyboard.Key.Up: if (_currentNode != null && (_currentNode = _currentNode.Previous) != null) { pointerPosition = _currentNode.Value; } else { _currentNode = _pointerPositions.Last; pointerPosition = _currentNode.Value; } ShiftSound.Play(); break; case Keyboard.Key.Down: if (_currentNode != null && (_currentNode = _currentNode.Next) != null) { pointerPosition = _currentNode.Value; } else { _currentNode = _pointerPositions.First; pointerPosition = _currentNode.Value; } ShiftSound.Play(); break; case Keyboard.Key.Return: try { var item = MenuItems[_itemIndex]; SelectSound.Play(); if (item.DoAction() == false) { LogManager.LogWarning("Failed to do menu item's action."); } } catch (IndexOutOfRangeException) { LogManager.LogWarning("No menu item found at index: " + _itemIndex); } break; case Keyboard.Key.Escape: if (_displayChars) { _itemIndex = 4; DisplayCharMenuItemFunc(); } else { ExitGameFunc(); } break; } for (var i = 0; i < MenuItems.Count; i++) { if ((Math.Abs(pointerPosition.Value.Y - MenuItems[i].Position.Y) <= 0.1)) { _itemIndex = i; } } Pointer.SetPosition(pointerPosition.Value); }