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::graphics::UiFactory Class Reference

Factory class for creating UI components in the ECS registry. More...

#include <UiFactory.hpp>

Collaboration diagram for rtp::client::graphics::UiFactory:

Public Member Functions

 UiFactory ()=default
 
 ~UiFactory ()=default
 

Static Public Member Functions

static ecs::Entity createButton (ecs::Registry &registry, const position &position, const size &size, const std::string &label, std::function< void()> onClick=nullptr)
 Create a button UI component.
 
static ecs::Entity createText (ecs::Registry &registry, const position &position, const std::string &content, const std::string &fontPath, unsigned int fontSize, const std::uint8_t zIndex=0, const color &textColor={255, 255, 255})
 
static ecs::Entity createSlider (ecs::Registry &registry, const position &position, const size &size, float minValue, float maxValue, float initialValue, std::function< void(float)> onChange=nullptr)
 
static ecs::Entity createDropdown (ecs::Registry &registry, const position &position, const size &size, const std::vector< std::string > &options, const int selectedIndex, std::function< void(int index)> onSelect=nullptr)
 
static ecs::Entity createTextInput (ecs::Registry &registry, const position &position, const size &size, const std::string &fontPath, unsigned int fontSize, const int maxLength=64, const std::string &placeholder="", std::function< void(const std::string &)> onSubmit=nullptr, std::function< void(const std::string &)> onChange=nullptr)
 
static ecs::Entity createSpritePreview (ecs::Registry &registry, const position &position, const std::string &texturePath, int rectLeft, int rectTop, int rectWidth, int rectHeight, float scale=2.0f, int zIndex=0)
 Create a sprite preview UI component.
 

Detailed Description

Factory class for creating UI components in the ECS registry.

This class provides static methods to create various UI elements

  • such as buttons, text fields, sliders, etc., and add them to the
  • provided ECS registry.

Definition at line 72 of file UiFactory.hpp.

Constructor & Destructor Documentation

◆ UiFactory()

rtp::client::graphics::UiFactory::UiFactory ( )
default

◆ ~UiFactory()

rtp::client::graphics::UiFactory::~UiFactory ( )
default

Member Function Documentation

◆ createButton()

ecs::Entity rtp::client::graphics::UiFactory::createButton ( ecs::Registry registry,
const position position,
const size size,
const std::string &  label,
std::function< void()>  onClick = nullptr 
)
static

Create a button UI component.

Parameters
registryReference to the ECS registry.
xX position of the button.
yY position of the button.
widthWidth of the button.
heightHeight of the button.
labelText label of the button.
onClickCallback function to be called when the button is clicked.
Returns
The created entity representing the button.

Definition at line 17 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::log::error(), rtp::client::graphics::size::height, rtp::ecs::components::ui::Button::onClick, rtp::ecs::components::ui::Button::position, rtp::ecs::components::ui::Button::size, rtp::ecs::Registry::spawn(), rtp::ecs::components::ui::Button::text, rtp::client::graphics::size::width, rtp::client::graphics::position::x, and rtp::client::graphics::position::y.

Referenced by rtp::client::scenes::LobbyScene::buildUi(), rtp::client::scenes::GamepadSettingsScene::onEnter(), rtp::client::scenes::SettingsScene::onEnter(), rtp::client::scenes::CreateRoomScene::onEnter(), rtp::client::scenes::GameOverScene::onEnter(), rtp::client::scenes::KeyBindingScene::onEnter(), rtp::client::scenes::LoginScene::onEnter(), rtp::client::scenes::MenuScene::onEnter(), rtp::client::scenes::PauseScene::onEnter(), rtp::client::scenes::PlayingScene::onEnter(), rtp::client::scenes::RoomWaitingScene::onEnter(), rtp::client::scenes::PlayingScene::openChat(), rtp::client::scenes::RoomWaitingScene::openChat(), rtp::client::scenes::ModMenuScene::showCategoryList(), and rtp::client::scenes::ModMenuScene::showEntityCodex().

◆ createDropdown()

ecs::Entity rtp::client::graphics::UiFactory::createDropdown ( ecs::Registry registry,
const position position,
const size size,
const std::vector< std::string > &  options,
const int  selectedIndex,
std::function< void(int index)>  onSelect = nullptr 
)
static
            @brief Create a dropdown UI component.

            * @param registry Reference to the ECS registry.
Parameters
xX position of the dropdown.
yY position of the dropdown.
widthWidth of the dropdown.
heightHeight of the dropdown.
optionsList of options for the dropdown.
selectedIndexIndex of the initially selected option.
  • Parameters
    onSelectCallback function to be called when an option is selected.
    Returns
    The created entity representing the dropdown.

Definition at line 106 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::log::error(), rtp::client::graphics::size::height, rtp::ecs::components::ui::Dropdown::onSelect, rtp::ecs::components::ui::Dropdown::options, rtp::ecs::components::ui::Dropdown::position, rtp::ecs::components::ui::Dropdown::selectedIndex, rtp::ecs::components::ui::Dropdown::size, rtp::ecs::Registry::spawn(), rtp::log::warning(), rtp::client::graphics::size::width, rtp::client::graphics::position::x, and rtp::client::graphics::position::y.

Referenced by rtp::client::scenes::GamepadSettingsScene::onEnter(), rtp::client::scenes::SettingsScene::onEnter(), and rtp::client::scenes::CreateRoomScene::onEnter().

◆ createSlider()

ecs::Entity rtp::client::graphics::UiFactory::createSlider ( ecs::Registry registry,
const position position,
const size size,
float  minValue,
float  maxValue,
float  initialValue,
std::function< void(float)>  onChange = nullptr 
)
static
            @brief Create a slider UI component.

            * @param registry Reference to the ECS registry.
Parameters
xX position of the slider.
yY position of the slider.
widthWidth of the slider.
heightHeight of the slider.
minValueMinimum value of the slider.
maxValueMaximum value of the slider.
initialValueInitial value of the slider.
onChangeCallback function to be called when the slider value changes.
Returns
The created entity representing the slider.

Definition at line 75 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::ecs::components::ui::Slider::currentValue, rtp::log::error(), rtp::client::graphics::size::height, rtp::ecs::components::ui::Slider::maxValue, rtp::ecs::components::ui::Slider::minValue, rtp::ecs::components::ui::Slider::onChange, rtp::ecs::components::ui::Slider::position, rtp::ecs::components::ui::Slider::size, rtp::ecs::Registry::spawn(), rtp::client::graphics::size::width, rtp::client::graphics::position::x, and rtp::client::graphics::position::y.

Referenced by rtp::client::scenes::GamepadSettingsScene::onEnter(), rtp::client::scenes::SettingsScene::onEnter(), rtp::client::scenes::CreateRoomScene::onEnter(), and rtp::client::scenes::PlayingScene::onEnter().

◆ createSpritePreview()

ecs::Entity rtp::client::graphics::UiFactory::createSpritePreview ( ecs::Registry registry,
const position position,
const std::string &  texturePath,
int  rectLeft,
int  rectTop,
int  rectWidth,
int  rectHeight,
float  scale = 2.0f,
int  zIndex = 0 
)
static

Create a sprite preview UI component.

Parameters
registryReference to the ECS registry.
positionPosition of the sprite preview.
texturePathPath to the texture file.
rectLeftLeft coordinate in the texture.
rectTopTop coordinate in the texture.
rectWidthWidth of the sprite in the texture.
rectHeightHeight of the sprite in the texture.
scaleScale factor for display.
zIndexZ-index for rendering order.
Returns
The created entity representing the sprite preview.

Definition at line 177 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::log::error(), rtp::ecs::components::ui::SpritePreview::rectHeight, rtp::ecs::components::ui::SpritePreview::rectLeft, rtp::ecs::components::ui::SpritePreview::rectTop, rtp::ecs::components::ui::SpritePreview::rectWidth, rtp::ecs::components::ui::SpritePreview::scale, rtp::ecs::Registry::spawn(), rtp::ecs::components::ui::SpritePreview::texturePath, rtp::client::graphics::position::x, rtp::ecs::components::ui::SpritePreview::x, rtp::client::graphics::position::y, rtp::ecs::components::ui::SpritePreview::y, and rtp::ecs::components::ui::SpritePreview::zIndex.

Referenced by rtp::client::scenes::ModMenuScene::showEntityCodex().

◆ createText()

ecs::Entity rtp::client::graphics::UiFactory::createText ( ecs::Registry registry,
const position position,
const std::string &  content,
const std::string &  fontPath,
unsigned int  fontSize,
const std::uint8_t  zIndex = 0,
const color textColor = {255, 255, 255} 
)
static
            @brief Create a text UI component.

            * @param registry Reference to the ECS registry.
Parameters
xX position of the text.
yY position of the text.
contentText content.
fontPathPath to the font file.
fontSizeSize of the font.
  • Parameters
    zIndexZ-index for rendering order.
    textColorColor of the text.
    Returns
    The created entity representing the text.

Definition at line 43 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::client::graphics::color::b, rtp::ecs::components::ui::Text::blue, rtp::ecs::components::ui::Text::content, rtp::log::error(), rtp::ecs::components::ui::Text::fontPath, rtp::ecs::components::ui::Text::fontSize, rtp::client::graphics::color::g, rtp::ecs::components::ui::Text::green, rtp::ecs::components::ui::Text::position, rtp::client::graphics::color::r, rtp::ecs::components::ui::Text::red, rtp::ecs::Registry::spawn(), rtp::client::graphics::position::x, rtp::client::graphics::position::y, and rtp::ecs::components::ui::Text::zIndex.

Referenced by rtp::client::scenes::LobbyScene::buildUi(), rtp::client::scenes::GamepadSettingsScene::onEnter(), rtp::client::scenes::SettingsScene::onEnter(), rtp::client::scenes::CreateRoomScene::onEnter(), rtp::client::scenes::GameOverScene::onEnter(), rtp::client::scenes::KeyBindingScene::onEnter(), rtp::client::scenes::LoginScene::onEnter(), rtp::client::scenes::MenuScene::onEnter(), rtp::client::scenes::PauseScene::onEnter(), rtp::client::scenes::PlayingScene::onEnter(), rtp::client::scenes::RoomWaitingScene::onEnter(), rtp::client::scenes::PlayingScene::openChat(), rtp::client::scenes::RoomWaitingScene::openChat(), rtp::client::scenes::ModMenuScene::showCategoryList(), and rtp::client::scenes::ModMenuScene::showEntityCodex().

◆ createTextInput()

ecs::Entity rtp::client::graphics::UiFactory::createTextInput ( ecs::Registry registry,
const position position,
const size size,
const std::string &  fontPath,
unsigned int  fontSize,
const int  maxLength = 64,
const std::string &  placeholder = "",
std::function< void(const std::string &)>  onSubmit = nullptr,
std::function< void(const std::string &)>  onChange = nullptr 
)
static
            @brief Create a text input UI component.

            * @param registry Reference to the ECS registry.
Parameters
xX position of the text input.
yY position of the text input.
widthWidth of the text input.
heightHeight of the text input.
fontPathPath to the font file.
fontSizeSize of the font.
maxLengthMaximum length of the input text.
placeholderPlaceholder text when input is empty.
onChangeCallback function to be called when the text changes.
Returns
The created entity representing the text input.

Definition at line 142 of file UiFactory.cpp.

References rtp::ecs::Registry::add(), rtp::log::error(), rtp::ecs::components::ui::TextInput::fontPath, rtp::ecs::components::ui::TextInput::fontSize, rtp::client::graphics::size::height, rtp::ecs::components::ui::TextInput::maxLength, rtp::ecs::components::ui::TextInput::onChange, rtp::ecs::components::ui::TextInput::onSubmit, rtp::ecs::components::ui::TextInput::placeholder, rtp::ecs::components::ui::TextInput::position, rtp::ecs::components::ui::TextInput::size, rtp::ecs::Registry::spawn(), rtp::client::graphics::size::width, rtp::client::graphics::position::x, and rtp::client::graphics::position::y.

Referenced by rtp::client::scenes::CreateRoomScene::onEnter(), rtp::client::scenes::LoginScene::onEnter(), rtp::client::scenes::PlayingScene::openChat(), and rtp::client::scenes::RoomWaitingScene::openChat().


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