void GameMenuDialog::OnKeyPress(int key) { auto action = Input::Get().GetActionForKeyPress(key); if (Action::Requested(action, Action::MenuDown)) { if (this->SelectedOption >= GameMenuDialogOption::_MAX - 1) { this->SelectedOption = (GameMenuDialogOption::GameMenuDialogOption) 0; } else { this->SelectedOption = (GameMenuDialogOption::GameMenuDialogOption) ((int) this->SelectedOption + 1); } } if (Action::Requested(action, Action::MenuUp)) { if (this->SelectedOption <= (GameMenuDialogOption::GameMenuDialogOption) 0) { this->SelectedOption = (GameMenuDialogOption::GameMenuDialogOption) ((int) GameMenuDialogOption::_MAX - 1); } else { this->SelectedOption = (GameMenuDialogOption::GameMenuDialogOption) ((int) this->SelectedOption - 1); } } if (Action::Requested(action, Action::MenuAccept)) { ExecuteSelectedAction(); } if (Action::Requested(action, Action::MenuCancel)) { GameState::Get().PopDialog(); } }
void InventoryDialog::OnKeyPress(int key) { auto action = Input::Get().GetActionForKeyPress(key); auto playerTotalInventoryCount = (int)Player::Get().GetInventory().size(); if (Action::Requested(action, Action::MenuCancel)) { GameState::Get().PopDialog(); } if (playerTotalInventoryCount <= 0) { return; } if (Action::Requested(action, Action::MenuDown)) { this->SelectedInventoryItem++; if (this->SelectedInventoryItem >= playerTotalInventoryCount) { this->SelectedInventoryItem = 0; } } if (Action::Requested(action, Action::MenuUp)) { this->SelectedInventoryItem--; if (this->SelectedInventoryItem < 0) { this->SelectedInventoryItem = playerTotalInventoryCount - 1; } } // Ensure the inventory scrolls properly if (this->SelectedInventoryItem >= (INVENTORY_MAX_ITEMS_SHOWN / 2)) { this->InventoryOffset = this->SelectedInventoryItem - (INVENTORY_MAX_ITEMS_SHOWN / 2); if (this->InventoryOffset >= (playerTotalInventoryCount - INVENTORY_MAX_ITEMS_SHOWN)) { this->InventoryOffset = (playerTotalInventoryCount - INVENTORY_MAX_ITEMS_SHOWN); } if (this->InventoryOffset < 0) { this->InventoryOffset = 0; } } else { this->InventoryOffset = 0; } if (Action::Requested(action, Action::MenuAccept)) { ExecuteSelectedAction(); } }