Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::client::scenes::ModMenuScene Class Reference

Scene for customizing game sprites. More...

#include <ModMenuScene.hpp>

Inheritance diagram for rtp::client::scenes::ModMenuScene:
Collaboration diagram for rtp::client::scenes::ModMenuScene:

Public Types

using ChangeStateFn = std::function< void(GameState)>
 Type alias for a function that changes the game state.
 

Public Member Functions

 ModMenuScene (ecs::Registry &UiRegistry, Settings &settings, TranslationManager &translationManager, graphics::UiFactory &uiFactory, std::function< void(GameState)> changeState)
 Constructor for ModMenuScene.
 
void onEnter (void) override
 Called when the scene is entered.
 
void onExit (void) override
 Called when the scene is exited.
 
void handleEvent (const sf::Event &event) override
 Handle an incoming event.
 
void update (float dt) override
 Update the scene state.
 
- Public Member Functions inherited from rtp::client::interfaces::IScene
virtual ~IScene (void)=default
 

Private Member Functions

void initializeModDirectory ()
 Initialize the custom sprites directory.
 
void loadEntityCategories ()
 Load all entity categories and their sprites.
 
void showCategoryList ()
 Show the main category selection screen.
 
void showEntityCodex (size_t categoryIndex)
 Show the entity codex for a specific category.
 
sf::Texture * loadTexture (const std::string &texturePath)
 Load a texture if not already loaded.
 
std::string openFileDialog ()
 Open file dialog to select a custom sprite.
 
void saveSpriteMappings ()
 Save custom sprite mappings to config file.
 
void loadSpriteMappings ()
 Load custom sprite mappings from config file.
 
void applyCustomSprite (const EntitySpriteInfo &entity, const std::string &categoryName)
 Apply a custom sprite to an entity.
 
sf::Image resizeImage (const sf::Image &sourceImage, unsigned int targetWidth, unsigned int targetHeight)
 Resize an image to match target dimensions.
 
std::string getEntityKey (const EntitySpriteInfo &entity) const
 Get the unique key for an entity.
 

Private Attributes

ecs::Registry_uiRegistry
 Reference to the ECS registry.
 
Settings_settings
 Reference to the application settings.
 
TranslationManager_translationManager
 Reference to the translation manager.
 
graphics::UiFactory_uiFactory
 UI Factory for creating UI components.
 
ChangeStateFn _changeState
 Function to change the game state.
 
std::filesystem::path _customSpritesPath
 Path to custom sprites directory.
 
std::filesystem::path _spriteMappingPath
 Path to sprite mapping config file.
 
std::vector< EntityCategory_categories
 Available entity categories with their sprites.
 
size_t _selectedCategoryIndex
 Currently selected category index.
 
bool _showingCategoryList
 True if showing category list, false if showing entity codex.
 
std::map< std::string, sf::Texture > _loadedTextures
 Cache of loaded textures.
 
std::unordered_map< std::string, std::string > _customSpriteMappings
 

Detailed Description

Scene for customizing game sprites.

This scene allows players to replace game sprites with custom ones. Players can modify sprites for entities, enemies, projectiles, etc.

Definition at line 55 of file ModMenuScene.hpp.

Member Typedef Documentation

◆ ChangeStateFn

Type alias for a function that changes the game state.

Definition at line 75 of file ModMenuScene.hpp.

Constructor & Destructor Documentation

◆ ModMenuScene()

rtp::client::scenes::ModMenuScene::ModMenuScene ( ecs::Registry UiRegistry,
Settings settings,
TranslationManager translationManager,
graphics::UiFactory uiFactory,
std::function< void(GameState)>  changeState 
)

Constructor for ModMenuScene.

Parameters
registryReference to the ECS registry
settingsReference to the application settings
translationManagerReference to the translation manager
uiFactoryReference to the UI factory
changeStateFunction to change the game state

Definition at line 20 of file ModMenuScene.cpp.

References initializeModDirectory(), loadEntityCategories(), and loadSpriteMappings().

Member Function Documentation

◆ applyCustomSprite()

◆ getEntityKey()

std::string rtp::client::scenes::ModMenuScene::getEntityKey ( const EntitySpriteInfo entity) const
private

Get the unique key for an entity.

Parameters
entityEntity information
Returns
Unique key string

Definition at line 372 of file ModMenuScene.cpp.

References rtp::client::scenes::EntitySpriteInfo::name.

Referenced by applyCustomSprite(), and showEntityCodex().

◆ handleEvent()

void rtp::client::scenes::ModMenuScene::handleEvent ( const sf::Event &  event)
overridevirtual

◆ initializeModDirectory()

void rtp::client::scenes::ModMenuScene::initializeModDirectory ( )
private

Initialize the custom sprites directory.

Definition at line 81 of file ModMenuScene.cpp.

References _customSpritesPath, rtp::log::error(), and rtp::log::info().

Referenced by ModMenuScene().

◆ loadEntityCategories()

void rtp::client::scenes::ModMenuScene::loadEntityCategories ( )
private

Load all entity categories and their sprites.

Definition at line 122 of file ModMenuScene.cpp.

References _categories, rtp::client::scenes::EntityCategory::entities, and rtp::client::scenes::EntityCategory::name.

Referenced by ModMenuScene().

◆ loadSpriteMappings()

void rtp::client::scenes::ModMenuScene::loadSpriteMappings ( )
private

Load custom sprite mappings from config file.

Definition at line 393 of file ModMenuScene.cpp.

References _customSpriteMappings, _spriteMappingPath, rtp::log::error(), rtp::log::info(), and rtp::config::loadSpriteMappings().

Referenced by ModMenuScene(), and onEnter().

◆ loadTexture()

sf::Texture * rtp::client::scenes::ModMenuScene::loadTexture ( const std::string &  texturePath)
private

Load a texture if not already loaded.

Parameters
texturePathPath to the texture file
Returns
Pointer to the texture, or nullptr if failed

Definition at line 355 of file ModMenuScene.cpp.

References _loadedTextures, and rtp::log::error().

◆ onEnter()

void rtp::client::scenes::ModMenuScene::onEnter ( void  )
overridevirtual

Called when the scene is entered.

Implements rtp::client::interfaces::IScene.

Definition at line 40 of file ModMenuScene.cpp.

References _loadedTextures, _showingCategoryList, rtp::log::info(), loadSpriteMappings(), and showCategoryList().

◆ onExit()

void rtp::client::scenes::ModMenuScene::onExit ( void  )
overridevirtual

Called when the scene is exited.

Implements rtp::client::interfaces::IScene.

Definition at line 49 of file ModMenuScene.cpp.

References _loadedTextures, and rtp::log::info().

◆ openFileDialog()

std::string rtp::client::scenes::ModMenuScene::openFileDialog ( )
private

Open file dialog to select a custom sprite.

Returns
Selected file path, or empty string if cancelled

Definition at line 408 of file ModMenuScene.cpp.

References rtp::log::error().

Referenced by applyCustomSprite().

◆ resizeImage()

sf::Image rtp::client::scenes::ModMenuScene::resizeImage ( const sf::Image &  sourceImage,
unsigned int  targetWidth,
unsigned int  targetHeight 
)
private

Resize an image to match target dimensions.

Parameters
sourceImageSource image to resize
targetWidthTarget width
targetHeightTarget height
Returns
Resized image

Definition at line 457 of file ModMenuScene.cpp.

Referenced by applyCustomSprite().

◆ saveSpriteMappings()

void rtp::client::scenes::ModMenuScene::saveSpriteMappings ( )
private

Save custom sprite mappings to config file.

Definition at line 380 of file ModMenuScene.cpp.

References _customSpriteMappings, _spriteMappingPath, rtp::log::error(), rtp::log::info(), and rtp::config::saveSpriteMappings().

Referenced by applyCustomSprite(), and showEntityCodex().

◆ showCategoryList()

◆ showEntityCodex()

◆ update()

void rtp::client::scenes::ModMenuScene::update ( float  dt)
overridevirtual

Update the scene state.

Parameters
dtTime delta since the last update.

Implements rtp::client::interfaces::IScene.

Definition at line 72 of file ModMenuScene.cpp.

Member Data Documentation

◆ _categories

std::vector<EntityCategory> rtp::client::scenes::ModMenuScene::_categories
private

Available entity categories with their sprites.

Definition at line 108 of file ModMenuScene.hpp.

Referenced by loadEntityCategories(), showCategoryList(), and showEntityCodex().

◆ _changeState

ChangeStateFn rtp::client::scenes::ModMenuScene::_changeState
private

Function to change the game state.

Definition at line 104 of file ModMenuScene.hpp.

Referenced by handleEvent(), and showCategoryList().

◆ _customSpriteMappings

std::unordered_map<std::string, std::string> rtp::client::scenes::ModMenuScene::_customSpriteMappings
private

◆ _customSpritesPath

std::filesystem::path rtp::client::scenes::ModMenuScene::_customSpritesPath
private

Path to custom sprites directory.

Definition at line 106 of file ModMenuScene.hpp.

Referenced by applyCustomSprite(), and initializeModDirectory().

◆ _loadedTextures

std::map<std::string, sf::Texture> rtp::client::scenes::ModMenuScene::_loadedTextures
private

Cache of loaded textures.

Definition at line 113 of file ModMenuScene.hpp.

Referenced by applyCustomSprite(), loadTexture(), onEnter(), onExit(), and showEntityCodex().

◆ _selectedCategoryIndex

size_t rtp::client::scenes::ModMenuScene::_selectedCategoryIndex
private

Currently selected category index.

Definition at line 109 of file ModMenuScene.hpp.

Referenced by applyCustomSprite(), showCategoryList(), and showEntityCodex().

◆ _settings

Settings& rtp::client::scenes::ModMenuScene::_settings
private

Reference to the application settings.

Definition at line 101 of file ModMenuScene.hpp.

◆ _showingCategoryList

bool rtp::client::scenes::ModMenuScene::_showingCategoryList
private

True if showing category list, false if showing entity codex.

Definition at line 110 of file ModMenuScene.hpp.

Referenced by handleEvent(), onEnter(), showCategoryList(), and showEntityCodex().

◆ _spriteMappingPath

std::filesystem::path rtp::client::scenes::ModMenuScene::_spriteMappingPath
private

Path to sprite mapping config file.

Definition at line 107 of file ModMenuScene.hpp.

Referenced by loadSpriteMappings(), and saveSpriteMappings().

◆ _translationManager

TranslationManager& rtp::client::scenes::ModMenuScene::_translationManager
private

Reference to the translation manager.

Definition at line 102 of file ModMenuScene.hpp.

Referenced by showCategoryList(), and showEntityCodex().

◆ _uiFactory

graphics::UiFactory& rtp::client::scenes::ModMenuScene::_uiFactory
private

UI Factory for creating UI components.

Definition at line 103 of file ModMenuScene.hpp.

Referenced by showCategoryList(), and showEntityCodex().

◆ _uiRegistry

ecs::Registry& rtp::client::scenes::ModMenuScene::_uiRegistry
private

Reference to the ECS registry.

Definition at line 100 of file ModMenuScene.hpp.

Referenced by applyCustomSprite(), handleEvent(), showCategoryList(), and showEntityCodex().


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