mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-30 01:05:24 +00:00
main menu button hover callback
This commit is contained in:
@@ -14,7 +14,8 @@ namespace RAY {
|
||||
|
||||
Image::Image(const std::string &filename):
|
||||
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE),
|
||||
_image(_imagesCache.fetch(filename))
|
||||
_image(_imagesCache.fetch(filename)),
|
||||
_ressourcePath(filename)
|
||||
{
|
||||
this->_dimensions = Vector2(this->_image->width, this->_image->height);
|
||||
}
|
||||
@@ -30,6 +31,15 @@ namespace RAY {
|
||||
return *this->_image;
|
||||
}
|
||||
|
||||
Image &Image::use(const std::string &filename)
|
||||
{
|
||||
if (this->_ressourcePath == filename)
|
||||
return *this;
|
||||
this->_image = this->_imagesCache.fetch(filename);
|
||||
this->_ressourcePath = filename;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Image::operator ::Image *()
|
||||
{
|
||||
return this->_image.get();
|
||||
|
||||
@@ -48,12 +48,17 @@ namespace RAY
|
||||
//! @brief Resize image;
|
||||
void resize(const RAY::Vector2 &dimensions);
|
||||
|
||||
//! @brief Load image from file, lets one use one entity for multiple files
|
||||
Image &use(const std::string &filename);
|
||||
|
||||
private:
|
||||
//! @brief Image, really, that's just it...
|
||||
std::shared_ptr<::Image> _image;
|
||||
|
||||
static Cache<::Image> _imagesCache;
|
||||
|
||||
std::string _ressourcePath;
|
||||
|
||||
|
||||
INTERNAL:
|
||||
//! @brief get image
|
||||
|
||||
+42
-12
@@ -109,27 +109,57 @@ namespace BBM
|
||||
scene->addEntity("play button")
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 540, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Image>("assets/buttons/button_new_game.png")
|
||||
.addComponent<ButtonComponent>(
|
||||
.addComponent<ButtonComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_new_game.png");
|
||||
}, [](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_new_game_hovered.png");
|
||||
},
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback);
|
||||
ButtonComponent::emptyButtonCallback)
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>();
|
||||
scene->addEntity("settings button")
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 360, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Image>("assets/buttons/button_settings.png")
|
||||
.addComponent<ButtonComponent>(
|
||||
.addComponent<ButtonComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_settings.png");
|
||||
}, [](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_settings_hovered.png");
|
||||
},
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback);
|
||||
ButtonComponent::emptyButtonCallback)
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>();
|
||||
scene->addEntity("exit button")
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Image>("assets/buttons/button_exit.png")
|
||||
.addComponent<ButtonComponent>(
|
||||
.addComponent<ButtonComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_exit.png");
|
||||
}, [](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Image *image = dynamic_cast<RAY::Image *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
image->use("assets/buttons/button_exit_hovered.png");
|
||||
},
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback,
|
||||
ButtonComponent::emptyButtonCallback);
|
||||
ButtonComponent::emptyButtonCallback)
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>();
|
||||
//needed material
|
||||
//play button
|
||||
//play button assets
|
||||
|
||||
Reference in New Issue
Block a user