|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
Scene for customizing game sprites. More...
#include <ModMenuScene.hpp>
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 |
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.
| using rtp::client::scenes::ModMenuScene::ChangeStateFn = std::function<void(GameState)> |
Type alias for a function that changes the game state.
Definition at line 75 of file ModMenuScene.hpp.
| rtp::client::scenes::ModMenuScene::ModMenuScene | ( | ecs::Registry & | UiRegistry, |
| Settings & | settings, | ||
| TranslationManager & | translationManager, | ||
| graphics::UiFactory & | uiFactory, | ||
| std::function< void(GameState)> | changeState | ||
| ) |
Constructor for ModMenuScene.
| registry | Reference to the ECS registry |
| settings | Reference to the application settings |
| translationManager | Reference to the translation manager |
| uiFactory | Reference to the UI factory |
| changeState | Function to change the game state |
Definition at line 20 of file ModMenuScene.cpp.
References initializeModDirectory(), loadEntityCategories(), and loadSpriteMappings().
|
private |
Apply a custom sprite to an entity.
| entity | Entity information |
| categoryName | Category name for organizing sprites |
Definition at line 474 of file ModMenuScene.cpp.
References _customSpriteMappings, _customSpritesPath, _loadedTextures, _selectedCategoryIndex, _uiRegistry, rtp::ecs::Registry::clear(), rtp::client::SpriteCustomizer::clearTextureCaches(), rtp::log::error(), getEntityKey(), rtp::client::SpriteCustomizer::getInstance(), rtp::log::info(), openFileDialog(), rtp::client::scenes::EntitySpriteInfo::rectHeight, rtp::client::scenes::EntitySpriteInfo::rectWidth, rtp::client::SpriteCustomizer::reloadMappings(), resizeImage(), saveSpriteMappings(), and showEntityCodex().
Referenced by showEntityCodex().
|
private |
Get the unique key for an entity.
| entity | Entity information |
Definition at line 372 of file ModMenuScene.cpp.
References rtp::client::scenes::EntitySpriteInfo::name.
Referenced by applyCustomSprite(), and showEntityCodex().
|
overridevirtual |
Handle an incoming event.
| event | The event to handle. |
Implements rtp::client::interfaces::IScene.
Definition at line 55 of file ModMenuScene.cpp.
References _changeState, _showingCategoryList, _uiRegistry, rtp::ecs::Registry::clear(), rtp::client::SpriteCustomizer::getInstance(), rtp::client::Menu, rtp::client::SpriteCustomizer::reloadMappings(), and showCategoryList().
|
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().
|
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().
|
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().
|
private |
Load a texture if not already loaded.
| texturePath | Path to the texture file |
Definition at line 355 of file ModMenuScene.cpp.
References _loadedTextures, and rtp::log::error().
|
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().
|
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().
|
private |
Open file dialog to select a custom sprite.
Definition at line 408 of file ModMenuScene.cpp.
References rtp::log::error().
Referenced by applyCustomSprite().
|
private |
Resize an image to match target dimensions.
| sourceImage | Source image to resize |
| targetWidth | Target width |
| targetHeight | Target height |
Definition at line 457 of file ModMenuScene.cpp.
Referenced by applyCustomSprite().
|
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().
|
private |
Show the main category selection screen.
Definition at line 169 of file ModMenuScene.cpp.
References _categories, _changeState, _selectedCategoryIndex, _showingCategoryList, _translationManager, _uiFactory, _uiRegistry, rtp::ecs::Registry::clear(), rtp::client::graphics::UiFactory::createButton(), rtp::client::graphics::UiFactory::createText(), rtp::client::TranslationManager::get(), rtp::client::SpriteCustomizer::getInstance(), rtp::client::Menu, rtp::client::SpriteCustomizer::reloadMappings(), and showEntityCodex().
Referenced by handleEvent(), onEnter(), and showEntityCodex().
|
private |
Show the entity codex for a specific category.
| categoryIndex | Index of the category to display |
Definition at line 229 of file ModMenuScene.cpp.
References _categories, _customSpriteMappings, _loadedTextures, _selectedCategoryIndex, _showingCategoryList, _translationManager, _uiFactory, _uiRegistry, applyCustomSprite(), rtp::ecs::Registry::clear(), rtp::client::SpriteCustomizer::clearTextureCaches(), rtp::client::graphics::UiFactory::createButton(), rtp::client::graphics::UiFactory::createSpritePreview(), rtp::client::graphics::UiFactory::createText(), rtp::log::error(), rtp::client::TranslationManager::get(), getEntityKey(), rtp::client::SpriteCustomizer::getInstance(), rtp::log::info(), rtp::client::SpriteCustomizer::reloadMappings(), saveSpriteMappings(), showCategoryList(), and showEntityCodex().
Referenced by applyCustomSprite(), showCategoryList(), and showEntityCodex().
|
overridevirtual |
Update the scene state.
| dt | Time delta since the last update. |
Implements rtp::client::interfaces::IScene.
Definition at line 72 of file ModMenuScene.cpp.
|
private |
Available entity categories with their sprites.
Definition at line 108 of file ModMenuScene.hpp.
Referenced by loadEntityCategories(), showCategoryList(), and showEntityCodex().
|
private |
Function to change the game state.
Definition at line 104 of file ModMenuScene.hpp.
Referenced by handleEvent(), and showCategoryList().
|
private |
Definition at line 116 of file ModMenuScene.hpp.
Referenced by applyCustomSprite(), loadSpriteMappings(), saveSpriteMappings(), and showEntityCodex().
|
private |
Path to custom sprites directory.
Definition at line 106 of file ModMenuScene.hpp.
Referenced by applyCustomSprite(), and initializeModDirectory().
|
private |
Cache of loaded textures.
Definition at line 113 of file ModMenuScene.hpp.
Referenced by applyCustomSprite(), loadTexture(), onEnter(), onExit(), and showEntityCodex().
|
private |
Currently selected category index.
Definition at line 109 of file ModMenuScene.hpp.
Referenced by applyCustomSprite(), showCategoryList(), and showEntityCodex().
|
private |
Reference to the application settings.
Definition at line 101 of file ModMenuScene.hpp.
|
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().
|
private |
Path to sprite mapping config file.
Definition at line 107 of file ModMenuScene.hpp.
Referenced by loadSpriteMappings(), and saveSpriteMappings().
|
private |
Reference to the translation manager.
Definition at line 102 of file ModMenuScene.hpp.
Referenced by showCategoryList(), and showEntityCodex().
|
private |
UI Factory for creating UI components.
Definition at line 103 of file ModMenuScene.hpp.
Referenced by showCategoryList(), and showEntityCodex().
|
private |
Reference to the ECS registry.
Definition at line 100 of file ModMenuScene.hpp.
Referenced by applyCustomSprite(), handleEvent(), showCategoryList(), and showEntityCodex().