R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Game::KeyBindingsMenu Class Reference

Menu for viewing and remapping key bindings. More...

#include <KeyBindingsMenu.hpp>

Inheritance diagram for Game::KeyBindingsMenu:
Inheritance graph
Collaboration diagram for Game::KeyBindingsMenu:
Collaboration graph

Classes

struct  BindingButtons
 

Public Types

enum class  Mode { FULLSCREEN , OVERLAY }
 Display mode for the menu. More...
 

Public Member Functions

 KeyBindingsMenu (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics)
 Construct a new KeyBindingsMenu.
 
 ~KeyBindingsMenu () override=default
 
void Initialize () override
 Initialize UI elements.
 
void Update () override
 Update menu state (should be called every frame).
 
void Render () override
 Render menu (should be called every frame).
 
void SetMode (Mode mode)
 
Mode GetMode () const
 
void SetOverlayDimColor (unsigned int color)
 
unsigned int GetOverlayDimColor () const
 
bool ShouldDimBackground () const
 
void SetOnBack (std::function< void()> callback)
 Set callback for when back button is pressed.
 
void SetOnBindingsChanged (std::function< void()> callback)
 Set callback for when bindings are changed.
 
- Public Member Functions inherited from Game::BaseMenu
 BaseMenu (UI::IUIFactory &uiFactory)
 Constructor with UI factory reference.
 
virtual ~BaseMenu ()=default
 Virtual destructor.
 
virtual void Show ()
 Show the menu.
 
virtual void Hide ()
 Hide the menu.
 
virtual bool IsVisible () const
 Check if menu is currently visible.
 
void SetSoundEffectService (Audio::ISoundEffectService *soundService)
 Set the sound effect service for playing UI sounds.
 

Private Member Functions

void CreateBindingRow (Input::GameAction action, float yOffset)
 Create a binding row for an action.
 
void UpdateBindingButtonText (Input::GameAction action, bool isPrimary)
 Update the display text for a binding button.
 
void StartKeyCapture (Input::GameAction action, bool isPrimary)
 Start listening for a new key press to remap.
 
void CancelKeyCapture ()
 Cancel key capture mode.
 
void HandleCapturedKey (int key)
 Handle a key press during capture mode.
 
void RefreshAllBindings ()
 Refresh all binding button texts.
 

Private Attributes

Graphics::IGraphics_graphics
 
Mode _mode {Mode::FULLSCREEN}
 
unsigned int _overlayDimColor {0x80000000}
 
std::function< void()> _onBack
 
std::function< void()> _onBindingsChanged
 
bool _isCapturing {false}
 
Input::GameAction _captureAction {Input::GameAction::MOVE_UP}
 
bool _capturePrimary {true}
 
std::unordered_map< Input::GameAction, BindingButtons_bindingButtons
 
std::shared_ptr< UI::IButton_backButton
 
std::shared_ptr< UI::IButton_resetButton
 

Additional Inherited Members

- Protected Member Functions inherited from Game::BaseMenu
std::function< void()> WrapWithClickSound (std::function< void()> callback)
 Wrap a callback to play click sound before executing.
 
std::shared_ptr< UI::IButtonCreateCenteredButton (const char *label, float offsetY, float width, float height, unsigned int backgroundColor, unsigned int hoverColor, std::function< void()> callback)
 Create a button with standard styling and positioning.
 
- Protected Attributes inherited from Game::BaseMenu
UI::IUIFactory_uiFactory
 
std::shared_ptr< UI::IMenu_menu
 
Audio::ISoundEffectService_soundService {nullptr}
 

Detailed Description

Menu for viewing and remapping key bindings.

Displays all game actions with their current key bindings. Allows users to remap keys by clicking on a binding and pressing a new key.

Definition at line 28 of file KeyBindingsMenu.hpp.

Member Enumeration Documentation

◆ Mode

enum class Game::KeyBindingsMenu::Mode
strong

Display mode for the menu.

Enumerator
FULLSCREEN 

Takes the whole window.

OVERLAY 

Displays over the game with dimmed background.

Definition at line 33 of file KeyBindingsMenu.hpp.

Constructor & Destructor Documentation

◆ KeyBindingsMenu()

Game::KeyBindingsMenu::KeyBindingsMenu ( UI::IUIFactory uiFactory,
Graphics::IGraphics graphics 
)
explicit

Construct a new KeyBindingsMenu.

Parameters
uiFactoryUI factory for creating elements
graphicsGraphics interface for rendering

Definition at line 14 of file KeyBindingsMenu.cpp.

◆ ~KeyBindingsMenu()

Game::KeyBindingsMenu::~KeyBindingsMenu ( )
overridedefault

Member Function Documentation

◆ CancelKeyCapture()

void Game::KeyBindingsMenu::CancelKeyCapture ( )
private

Cancel key capture mode.

Definition at line 272 of file KeyBindingsMenu.cpp.

References LOG_INFO.

◆ CreateBindingRow()

void Game::KeyBindingsMenu::CreateBindingRow ( Input::GameAction  action,
float  yOffset 
)
private

Create a binding row for an action.

Parameters
actionThe game action
yOffsetVertical offset for positioning

Definition at line 110 of file KeyBindingsMenu.cpp.

References Input::KeyBindings::ClearSecondaryKey(), Input::KeyBindings::GetActionName(), Input::KeyBindings::GetBindingName(), and Input::KeyBindings::getInstance().

Referenced by Initialize().

Here is the call graph for this function:

◆ GetMode()

KeyBindingsMenu::Mode Game::KeyBindingsMenu::GetMode ( ) const

Definition at line 327 of file KeyBindingsMenu.cpp.

◆ GetOverlayDimColor()

unsigned int Game::KeyBindingsMenu::GetOverlayDimColor ( ) const

Definition at line 335 of file KeyBindingsMenu.cpp.

◆ HandleCapturedKey()

void Game::KeyBindingsMenu::HandleCapturedKey ( int  key)
private

Handle a key press during capture mode.

Parameters
keyThe key that was pressed

Definition at line 277 of file KeyBindingsMenu.cpp.

References Input::KeyBindings::GetActionName(), Input::KeyBindings::getInstance(), Input::KeyBindings::GetKeyName(), and LOG_INFO.

Here is the call graph for this function:

◆ Initialize()

◆ RefreshAllBindings()

void Game::KeyBindingsMenu::RefreshAllBindings ( )
private

Refresh all binding button texts.

Definition at line 316 of file KeyBindingsMenu.cpp.

◆ Render()

void Game::KeyBindingsMenu::Render ( )
overridevirtual

Render menu (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 226 of file KeyBindingsMenu.cpp.

References Input::KeyBindings::GetActionName().

Here is the call graph for this function:

◆ SetMode()

void Game::KeyBindingsMenu::SetMode ( Mode  mode)

Definition at line 323 of file KeyBindingsMenu.cpp.

◆ SetOnBack()

void Game::KeyBindingsMenu::SetOnBack ( std::function< void()>  callback)

Set callback for when back button is pressed.

Definition at line 343 of file KeyBindingsMenu.cpp.

◆ SetOnBindingsChanged()

void Game::KeyBindingsMenu::SetOnBindingsChanged ( std::function< void()>  callback)

Set callback for when bindings are changed.

Definition at line 347 of file KeyBindingsMenu.cpp.

◆ SetOverlayDimColor()

void Game::KeyBindingsMenu::SetOverlayDimColor ( unsigned int  color)

Definition at line 331 of file KeyBindingsMenu.cpp.

◆ ShouldDimBackground()

bool Game::KeyBindingsMenu::ShouldDimBackground ( ) const

Definition at line 339 of file KeyBindingsMenu.cpp.

◆ StartKeyCapture()

void Game::KeyBindingsMenu::StartKeyCapture ( Input::GameAction  action,
bool  isPrimary 
)
private

Start listening for a new key press to remap.

Parameters
actionThe action to remap
isPrimaryWhether remapping primary or secondary key

Definition at line 263 of file KeyBindingsMenu.cpp.

References Input::KeyBindings::GetActionName(), and LOG_INFO.

Here is the call graph for this function:

◆ Update()

void Game::KeyBindingsMenu::Update ( )
overridevirtual

Update menu state (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 177 of file KeyBindingsMenu.cpp.

References Input::GamepadButtonToBinding().

Here is the call graph for this function:

◆ UpdateBindingButtonText()

void Game::KeyBindingsMenu::UpdateBindingButtonText ( Input::GameAction  action,
bool  isPrimary 
)
private

Update the display text for a binding button.

Parameters
actionThe game action whose button to update
isPrimaryWhether to update primary or secondary button

Definition at line 298 of file KeyBindingsMenu.cpp.

References Input::KeyBindings::GetBindingName(), and Input::KeyBindings::getInstance().

Here is the call graph for this function:

Member Data Documentation

◆ _backButton

std::shared_ptr<UI::IButton> Game::KeyBindingsMenu::_backButton
private

Definition at line 135 of file KeyBindingsMenu.hpp.

◆ _bindingButtons

std::unordered_map<Input::GameAction, BindingButtons> Game::KeyBindingsMenu::_bindingButtons
private

Definition at line 132 of file KeyBindingsMenu.hpp.

Referenced by Initialize().

◆ _captureAction

Input::GameAction Game::KeyBindingsMenu::_captureAction {Input::GameAction::MOVE_UP}
private

Definition at line 124 of file KeyBindingsMenu.hpp.

◆ _capturePrimary

bool Game::KeyBindingsMenu::_capturePrimary {true}
private

Definition at line 125 of file KeyBindingsMenu.hpp.

◆ _graphics

Graphics::IGraphics& Game::KeyBindingsMenu::_graphics
private

Definition at line 112 of file KeyBindingsMenu.hpp.

Referenced by Initialize().

◆ _isCapturing

bool Game::KeyBindingsMenu::_isCapturing {false}
private

Definition at line 123 of file KeyBindingsMenu.hpp.

◆ _mode

Mode Game::KeyBindingsMenu::_mode {Mode::FULLSCREEN}
private

Definition at line 115 of file KeyBindingsMenu.hpp.

◆ _onBack

std::function<void()> Game::KeyBindingsMenu::_onBack
private

Definition at line 119 of file KeyBindingsMenu.hpp.

◆ _onBindingsChanged

std::function<void()> Game::KeyBindingsMenu::_onBindingsChanged
private

Definition at line 120 of file KeyBindingsMenu.hpp.

◆ _overlayDimColor

unsigned int Game::KeyBindingsMenu::_overlayDimColor {0x80000000}
private

Definition at line 116 of file KeyBindingsMenu.hpp.

◆ _resetButton

std::shared_ptr<UI::IButton> Game::KeyBindingsMenu::_resetButton
private

Definition at line 136 of file KeyBindingsMenu.hpp.

Referenced by Initialize().


The documentation for this class was generated from the following files: