Skip to content

Commit

Permalink
Merge pull request #129 from AnonymusRaccoon/menuControllable
Browse files Browse the repository at this point in the history
First Menus
  • Loading branch information
zoriya authored Jun 9, 2021
2 parents 63ca018 + 7a64183 commit ad7b10e
Show file tree
Hide file tree
Showing 51 changed files with 970 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ set(SOURCES
sources/Component/Collision/CollisionComponent.hpp
sources/System/Collision/CollisionSystem.hpp
sources/System/Collision/CollisionSystem.cpp
sources/Component/Button/ButtonComponent.hpp
sources/System/MenuControllable/MenuControllableSystem.cpp
sources/System/MenuControllable/MenuControllableSystem.hpp
sources/Component/Animator/AnimatorComponent.cpp
sources/Component/Animator/AnimatorComponent.hpp
sources/System/Animator/AnimatorSystem.cpp
Expand All @@ -88,6 +91,8 @@ set(SOURCES
sources/Component/Music/MusicComponent.hpp
sources/Component/Sound/SoundComponent.hpp
sources/Component/Sound/SoundComponent.cpp
sources/System/Sound/MenuSoundManagerSystem.cpp
sources/System/Sound/MenuSoundManagerSystem.hpp
sources/System/Sound/PlayerSoundManagerSystem.cpp
sources/System/Sound/PlayerSoundManagerSystem.hpp
sources/System/Music/MusicSystem.hpp
Expand Down
Binary file added assets/bomberman.TTF
Binary file not shown.
Binary file added assets/buttons/button_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_back_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_exit_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_minus_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_new_game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_new_game_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_plus_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/button_settings_hovered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/tickbox_ticked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/buttons/tickbox_unticked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/musics/music_battle.ogg
Binary file not shown.
Binary file modified assets/musics/music_player_select.ogg
Binary file not shown.
Binary file modified assets/musics/music_result.ogg
Binary file not shown.
Binary file modified assets/musics/music_title.ogg
Binary file not shown.
Binary file added assets/plain_menu_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/raylib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sounds/click.ogg
Binary file not shown.
28 changes: 19 additions & 9 deletions lib/Ray/sources/Drawables/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include "Drawables/Image.hpp"
#include "Drawables/ADrawable2D.hpp"
#include "Drawables/2D/Rectangle.hpp"
#include "Exceptions/RayError.hpp"

namespace RAY {
Cache<::Image> Image::_imagesCache(LoadImage, UnloadImage);

Image::Image(const std::string &filename, bool lonely):
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE),
_image(_imagesCache.fetch(filename, lonely))
_image(_imagesCache.fetch(filename, lonely)),
_ressourcePath(filename)
{
this->_dimensions = Vector2(this->_image->width, this->_image->height);
}
Expand All @@ -30,6 +32,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();
Expand All @@ -40,16 +51,15 @@ namespace RAY {
drawable.drawOn(*this);
}

void Image::drawOn(RAY::Window &)
void Image::resize(const RAY::Vector2 &dimensions)
{
//Since the image is a shared object, when it is resized, it mush be resized after to its previous dimensions
Vector2 oldDims = Vector2(this->_image->width, this->_image->height);

ImageResize(*this, this->_dimensions.x, this->_dimensions.y);
Texture texture(*this);
ImageResize(*this, dimensions.x, dimensions.y);
this->setDimensions(dimensions);
}

DrawTexture(texture, this->_position.x, this->_position.y, this->_color);
ImageResize(*this, oldDims.x, oldDims.y);
void Image::drawOn(RAY::Window &)
{
throw RAY::Exception::NotSupportedError("An image cannot be drawn onto a window");
}

void Image::drawOn(RAY::Image &image)
Expand Down
7 changes: 7 additions & 0 deletions lib/Ray/sources/Drawables/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ namespace RAY

//! @brief Draw image on another image
void drawOn(RAY::Image &image) override;

//! @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
Expand Down
21 changes: 21 additions & 0 deletions lib/Ray/sources/Drawables/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,46 @@
*/

#include "Drawables/Texture.hpp"
#include "Drawables/2D/Rectangle.hpp"
#include "Drawables/Image.hpp"

namespace RAY {

Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture);

Texture::Texture(const std::string &filename, bool lonely):
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE),
_texture(_texturesCache.fetch(filename, lonely)),
_resourcePath(filename)
{
this->_dimensions = Vector2(this->_texture->width, this->_texture->height);
}

Texture::Texture(const Image &image):
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE),
_texture(std::make_shared<::Texture>(LoadTextureFromImage(image))),
_resourcePath()
{
}

Texture &Texture::use(const std::string &filename)
{
if (this->_resourcePath == filename)
return *this;
this->_texture = this->_texturesCache.fetch(filename);
this->_resourcePath = filename;
return *this;
}

Texture::operator ::Texture() const
{
return *this->_texture;
}

void Texture::drawOn(RAY::Window &)
{
float scale = this->_dimensions.x / this->_texture->width;

DrawTextureEx(*this, this->_position, 0, scale, this->_color);
}
}
9 changes: 8 additions & 1 deletion lib/Ray/sources/Drawables/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <raylib.h>
#include <string>
#include "Utils/Cache.hpp"
#include "Drawables/2D/Rectangle.hpp"

namespace RAY
{
//! @brief Object representation of a texture
class Texture {
class Texture: public Drawables::Drawables2D::Rectangle {
public:
//! @brief Create an texture, loading a file
//! @param filename: path to file to load
Expand All @@ -34,6 +35,12 @@ namespace RAY
//! @brief Texture destructor, will not unload ressources
~Texture() = default;

//! @brief draw texture on a window
void drawOn(RAY::Window &) override;

//! @brief Load texture from file, lets one use one entity for multiple files
Texture &use(const std::string &filename);

protected:
private:
//! @brief Texture, really, that's just it...
Expand Down
11 changes: 6 additions & 5 deletions lib/Ray/sources/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool RAY::Window::open(void)
}
InitWindow(this->_dimensions.x, this->_dimensions.y, this->_title.c_str());
this->_isOpen = true;
this->setExitKey(Controller::Keyboard::Key::KEY_DELETE);
InitAudioDevice();
return true;
}
Expand Down Expand Up @@ -160,11 +161,6 @@ void RAY::Window::draw(RAY::Drawables::IDrawable &drawable)
drawable.drawOn(*this);
}

void RAY::Window::draw(const RAY::Texture &texture, const Vector2 &position, const Color &tint)
{
DrawTexture(texture, position.x, position.y, tint);
}

void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix &transform)
{
DrawMesh(mesh, material, transform);
Expand All @@ -183,4 +179,9 @@ void RAY::Window::drawFPS(const RAY::Vector2 &position)
bool RAY::Window::isReady() const
{
return IsWindowReady();
}

void RAY::Window::setExitKey(RAY::Controller::Keyboard::Key key)
{
SetExitKey(key);
}
12 changes: 5 additions & 7 deletions lib/Ray/sources/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "Camera/Camera2D.hpp"
#include "Camera/Camera3D.hpp"
#include "Color.hpp"
#include "Drawables/Texture.hpp"

namespace RAY {
//! @brief Window manager
Expand Down Expand Up @@ -124,12 +123,6 @@ namespace RAY {
//! @param drawable The drawable to render on screen
void draw(RAY::Drawables::IDrawable &drawable);

//! @brief draw texture at position
//! @param texture The object to render
//! @param position The position of the texture relative to the top left window corner
//! @param tint
void draw(const Texture &texture, const Vector2 &position, const Color &tint);

//! @brief Draw a 3d mesh with material and transform
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);

Expand All @@ -138,6 +131,11 @@ namespace RAY {
//! @return true if the window's context has been correctly initialized
bool isReady() const;

//! @param key if this key is pressed, the window will close
//! @info Default is ESC key
//! @info Calling this function override the previous closing key
void setExitKey(Controller::Keyboard::Key key);


private:
//! @brief Creates window, and opens it if openNow is set to true
Expand Down
5 changes: 5 additions & 0 deletions lib/wal/sources/Entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace WAL
this->_scene._componentRemoved(*this, type);
}

bool Entity::operator==(const Entity &other) const
{
return other.getUid() == this->_uid;
}

bool Entity::shouldDelete() const
{
return this->_shouldDelete;
Expand Down
5 changes: 4 additions & 1 deletion lib/wal/sources/Entity/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ namespace WAL
friend Scene;
friend class Wal;
protected:
public:
//! @brief A reference to the ECS.
Scene &_scene;
public:
//! @brief Get the ID of the entity.
unsigned getUid() const;
//! @brief Get the name fo the entity
Expand Down Expand Up @@ -181,5 +181,8 @@ namespace WAL
~Entity() = default;
//! @brief An entity is not assignable
Entity &operator=(const Entity &) = delete;

//! @return true if the two entities hold the same uid
bool operator==(const Entity &) const;
};
} // namespace WAL
10 changes: 5 additions & 5 deletions lib/wal/sources/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace WAL
}
}

int Scene::getID() const
{
return this->_id;
}

void Scene::_entityRemoved(const Entity &entity)
{
for (auto &view : this->_views)
Expand Down Expand Up @@ -81,9 +86,4 @@ namespace WAL
}
this->_entities.splice(this->_entities.end(), this->_newEntities);
}

int Scene::getID() const
{
return this->_id;
}
} // namespace WAL
74 changes: 74 additions & 0 deletions sources/Component/Button/ButtonComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Created by Louis Auzuret on 06/03/21
//

#pragma once

#include "Models/Callback.hpp"
#include "Component/Component.hpp"
#include "Entity/Entity.hpp"
#include <optional>
#include "Wal.hpp"

namespace BBM
{
enum ButtonComponentType { IDLE, CLICK, HOVER };

template<enum ButtonComponentType T>
class ButtonComponent: public WAL::Component
{
public:
//! @brief onEvent callback
WAL::Callback<WAL::Entity &, WAL::Wal &> onEvent;

//! @brief button which is at the top of this button
WAL::Entity *_up;
//! @brief button which is below of this button
WAL::Entity *_down;
//! @brief button which is on the right of this button
WAL::Entity *_right;
//! @brief button which is on the left of this button
WAL::Entity *_left;

//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override
{
return new ButtonComponent(entity, onEvent);
}

//! @brief Initialize a new Button component.
explicit ButtonComponent(WAL::Entity &entity)
: WAL::Component(entity), onEvent()
{ }

//! @brief Constructor with the 3 callback
ButtonComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, WAL::Wal &> callback)
: WAL::Component(entity),
onEvent(callback), _up(nullptr), _down(nullptr), _left(nullptr), _right(nullptr)
{ }

ButtonComponent &setButtonLinks(WAL::Entity *up = nullptr, WAL::Entity *down = nullptr,
WAL::Entity *left = nullptr, WAL::Entity *right = nullptr)
{
this->_up = up;
this->_down = down;
this->_left = left;
this->_right = right;
return *this;
}

//! @brief A Controllable component is copy constructable.
ButtonComponent(const ButtonComponent<T> &) = default;
//! @brief default destructor
~ButtonComponent() override = default;
//! @brief A Button component default assign operator
ButtonComponent<T> &operator=(const ButtonComponent<T> &) = default;

//! @brief Empty button callback
static void emptyButtonCallback(WAL::Entity &)
{ }
};
typedef ButtonComponent<IDLE> OnIdleComponent;
typedef ButtonComponent<CLICK> OnClickComponent;
typedef ButtonComponent<HOVER> OnHoverComponent;
}
2 changes: 1 addition & 1 deletion sources/Component/Keyboard/KeyboardComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace BBM
//! @brief bomb key
Key keyBomb = KEY_E;
//! @brief pause key
Key keyPause = KEY_ESCAPE;
Key keyPause = RAY::Controller::Keyboard::Key::KEY_ESCAPE;
//! @brief move right key
Key keyRight = KEY_D;
//! @brief move left key
Expand Down
Loading

0 comments on commit ad7b10e

Please sign in to comment.