RTYPE TECHNICAL DOCUMENTATION
  • Introduction
  • Classes
    • utils::InputMap
    • utils::Window
    • utils::constant::ButtonValue
    • network::Client
    • network::LockedQueue
    • network::Server
    • ecs::EnemyFactory
    • ecs::Engine
    • ecs::Entity
    • ecs::Event
    • ecs::Registry
    • ecs::SparseArray
    • ecs::World
    • ecs::WorldManager
    • ecs::component::Activable
    • ecs::component::Animated
    • ecs::component::Animated::AnimFrame
    • ecs::component::AttackAI
    • ecs::component::AttackAI::Action
    • ecs::component::AttackAI::AI
    • ecs::component::AttackAI::AI::Pattern
    • ecs::component::Controllable
    • ecs::component::Direction
    • ecs::component::Drawable
    • ecs::component::EntityType
    • ecs::component::Faction
    • ecs::component::FollowEntity
    • ecs::component::Health
    • ecs::component::Hitbox
    • ecs::component::MovementAI
    • ecs::component::MovementAI::AI
    • ecs::component::NetworkId
    • ecs::component::Parallax
    • ecs::component::Position
    • ecs::component::Projectile
    • ecs::component::Score
    • ecs::component::Shootable
    • ecs::component::Size
    • ecs::component::Text
    • ecs::component::textColor
    • ecs::component::Velocity
    • ecs::component::Weapon
    • audio::AudioManager
    • asset::AssetLoader
    • anim::Animation
  • Namespaces
    • utils
    • utils::constant
    • network
    • ecs
    • ecs::component
    • ecs::systems
    • audio
    • asset
    • anim
  • Modules
    • Input
  • Files
    • src
    • src/client
    • Animation.cpp
    • Animation.hpp
    • AssetLoader.cpp
    • AssetLoader.hpp
    • AudioManager.cpp
    • AudioManager.hpp
    • entrypoint.cpp
    • GetWorld.cpp
    • GetWorld.hpp
    • NetworkClient.cpp
    • NetworkClient.hpp
    • src/ecs
    • src/ecs/components
    • src/ecs/components/client
    • Activable.hpp
    • Animated.hpp
    • Controllable.hpp
    • Drawable.hpp
    • Hitbox.hpp
    • Parallax.hpp
    • Shootable.hpp
    • Text.hpp
    • src/ecs/components/server
    • AttackAI.cpp
    • AttackAI.hpp
    • FollowEntity.hpp
    • Projectile.hpp
    • Direction.hpp
    • EntityType.hpp
    • Faction.hpp
    • Health.hpp
    • MovementAI.cpp
    • MovementAI.hpp
    • NetworkId.hpp
    • Position.hpp
    • Score.hpp
    • Size.hpp
    • Velocity.hpp
    • Weapon.hpp
    • src/ecs/systems
    • src/ecs/systems/client
    • Animate.hpp
    • Draw.hpp
    • ExecuteOnce.hpp
    • HandleIncomingMessages.hpp
    • HandleParallaxBounds.hpp
    • HandleSFMLEvents.hpp
    • HandleSFMLKeys.hpp
    • HealthBar.hpp
    • MenuSelect.hpp
    • ScoreUpdate.hpp
    • SendDirection.hpp
    • src/ecs/systems/server
    • DeathUpdate.hpp
    • FollowEntitySystem.hpp
    • HandleIncomingMessage.hpp
    • PlayerHealthUpdate.hpp
    • PositionUpdate.hpp
    • ProjectileCollision.hpp
    • RunAttackAI.hpp
    • Waves.hpp
    • ManageClientEvents.hpp
    • Movement.hpp
    • PositionLogger.hpp
    • RunMovementAI.hpp
    • EnemyFactory.cpp
    • EnemyFactory.hpp
    • Engine.hpp
    • Entity.hpp
    • Event.hpp
    • LockedQueue.hpp
    • Registry.hpp
    • SparseArray.hpp
    • World.hpp
    • WorldManager.cpp
    • WorldManager.hpp
    • src/server
    • entrypoint.cpp
    • Server.cpp
    • Server.hpp
    • src/utils
    • Constant.hpp
    • InputMap.cpp
    • InputMap.hpp
    • Window.cpp
    • README.md
  • Pages
    • deprecated
  • GitHub
Powered by GitBook
On this page
  • Namespaces
  • Source code
  1. Files

MenuSelect.hpp

Namespaces

Name

Source code

/*
** EPITECH PROJECT, 2022
** R-TYPEMIRROR
** File description:
** Buttons
*/

#pragma once

#include "World.hpp"
#include "SFML/Graphics.hpp"
#include "../../../client/GetWorld.hpp"
#include "../../../client/AudioManager.hpp"

namespace ecs::systems
{
    std::function<void(World &)> menuSelect = [](World &world) {
      auto &positions = world.registry.getComponents<component::Position>();
      auto &drawables = world.registry.getComponents<component::Drawable>();
      auto &sizes = world.registry.getComponents<component::Size>();
      auto &activables = world.registry.getComponents<component::Activable>();
      auto mousePosition = sf::Mouse::getPosition(utils::Window::getInstance());
      auto itButton = utils::constant::buttonValueMap.find(utils::constant::PLAY);
      auto itButtonRoom = utils::constant::buttonValueMap.find(utils::constant::ROOM);
      auto itHoveredButton = utils::constant::buttonValueMap.find(utils::constant::PLAY_HOVER);

      for (size_t i = 0; i < positions.size() && i < drawables.size() && i < sizes.size(); i++) {
          auto &pos = positions[i];
          auto &draw = drawables[i];
          auto &size = sizes[i];
          auto &activ = activables[i];

          if (draw && pos && size && activ) {
              if ((mousePosition.x >= pos->x && mousePosition.x <= pos->x + size->width) && (mousePosition.y >= pos->y && mousePosition.y <= pos->y + size->height) && activ->getIsButton()) {
                  if (!activ->getIsHover() && activ->getIsActivate())
                      audio::AudioManager::playSFX("button_hover");
                  switch(activ->getButtonType()) {
                      case utils::constant::PLAY: {
                          activ->setButtonType(utils::constant::PLAY_HOVER);
                          draw->rect.top = itHoveredButton->second.rectTop;
                          draw->rect.left = 220;
                          draw->rect.width = itHoveredButton->second.defaultRectWidth;
                          draw->rect.height = itHoveredButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::OPTION: {
                          activ->setButtonType(utils::constant::OPTION_HOVER);
                          draw->rect.top = itHoveredButton->second.rectTop;
                          draw->rect.left = 3542;
                          draw->rect.width = itHoveredButton->second.defaultRectWidth;
                          draw->rect.height = itHoveredButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::QUIT: {
                          activ->setButtonType(utils::constant::QUIT_HOVER);
                          draw->rect.top = itHoveredButton->second.rectTop;
                          draw->rect.left = 4670;
                          draw->rect.width = itHoveredButton->second.defaultRectWidth;
                          draw->rect.height = itHoveredButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::ROOM: {
                          activ->setButtonType(utils::constant::ROOM_HOVER);
                          draw->rect.top = 1510;
                          draw->rect.width = itHoveredButton->second.defaultRectWidth;
                          draw->rect.height = itHoveredButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::SOUND_LEFT: {
                          auto itLeft = utils::constant::buttonValueMap.find(utils::constant::SOUND_LEFT_HOVER);
                          activ->setButtonType(utils::constant::SOUND_LEFT_HOVER);
                          draw->rect.top = itLeft->second.rectTop;
                          draw->rect.left = itLeft->second.rectLeft;
                          break;
                      }
                      case utils::constant::SOUND_RIGHT: {
                          auto itRight = utils::constant::buttonValueMap.find(utils::constant::SOUND_RIGHT_HOVER);
                          activ->setButtonType(utils::constant::SOUND_RIGHT_HOVER);
                          draw->rect.top = itRight->second.rectTop;
                          draw->rect.left = itRight->second.rectLeft;
                          break;
                      }
                      case utils::constant::MUSIC_LEFT: {
                          auto itLeft = utils::constant::buttonValueMap.find(utils::constant::MUSIC_LEFT_HOVER);
                          activ->setButtonType(utils::constant::MUSIC_LEFT_HOVER);
                          draw->rect.top = itLeft->second.rectTop;
                          draw->rect.left = itLeft->second.rectLeft;
                          break;
                      }
                      case utils::constant::MUSIC_RIGHT: {
                          auto itRight = utils::constant::buttonValueMap.find(utils::constant::MUSIC_RIGHT_HOVER);
                          activ->setButtonType(utils::constant::MUSIC_RIGHT_HOVER);
                          draw->rect.top = itRight->second.rectTop;
                          draw->rect.left = itRight->second.rectLeft;
                          break;
                      }
                      case utils::constant::HOW_TO: {
                          auto itHowTo = utils::constant::buttonValueMap.find(utils::constant::HOW_TO_HOVER);
                          activ->setButtonType(utils::constant::HOW_TO_HOVER);
                          draw->rect.top = itHowTo->second.rectTop;
                          draw->rect.left = itHowTo->second.rectLeft;
                          break;
                      }
                      case utils::constant::SETTINGS: {
                          auto itSettings = utils::constant::buttonValueMap.find(utils::constant::SETTINGS_HOVER);
                          activ->setButtonType(utils::constant::SETTINGS_HOVER);
                          draw->rect.top = itSettings->second.rectTop;
                          draw->rect.left = itSettings->second.rectLeft;
                          break;
                      }
                      default: break;
                  }
                  if (activ->getButtonType() == utils::constant::QUIT_HOVER)
                      if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                          utils::Window::getInstance().close();
                  activ->setIsHover(true);
              } else if (activ->getIsHover() && activ->getIsButton()){
                  activ->getButtonType() == utils::constant::ROOM ? draw->rect.top = itButtonRoom->second.rectTop : 0;
                  switch(activ->getButtonType()) {
                      case utils::constant::PLAY_HOVER: {
                          activ->setButtonType(utils::constant::PLAY);
                          draw->rect.left = 324;
                          draw->rect.top = itButton->second.rectTop;
                          draw->rect.width = itButton->second.defaultRectWidth;
                          draw->rect.height = itButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::OPTION_HOVER: {
                          activ->setButtonType(utils::constant::OPTION);
                          draw->rect.left = 3651;
                          draw->rect.top = itButton->second.rectTop;
                          draw->rect.width = itButton->second.defaultRectWidth;
                          draw->rect.height = itButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::QUIT_HOVER: {
                          activ->setButtonType(utils::constant::QUIT);
                          draw->rect.left = 4760;
                          draw->rect.top = itButton->second.rectTop;
                          draw->rect.width = itButton->second.defaultRectWidth;
                          draw->rect.height = itButton->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::ROOM_HOVER: {
                          activ->setButtonType(utils::constant::ROOM);
                          draw->rect.top = 456;
                          draw->rect.width = itButtonRoom->second.defaultRectWidth;
                          draw->rect.height = itButtonRoom->second.defaultRectHeight;
                          break;
                      }
                      case utils::constant::SOUND_LEFT_HOVER: {
                          auto itLeft = utils::constant::buttonValueMap.find(utils::constant::SOUND_LEFT);
                          activ->setButtonType(utils::constant::SOUND_LEFT);
                          draw->rect.top = itLeft->second.rectTop;
                          draw->rect.left = itLeft->second.rectLeft;
                          break;
                      }
                      case utils::constant::SOUND_RIGHT_HOVER: {
                          auto itRight = utils::constant::buttonValueMap.find(utils::constant::SOUND_RIGHT);
                          activ->setButtonType(utils::constant::SOUND_RIGHT);
                          draw->rect.top = itRight->second.rectTop;
                          draw->rect.left = itRight->second.rectLeft;
                          break;
                      }
                      case utils::constant::MUSIC_LEFT_HOVER: {
                          auto itLeft = utils::constant::buttonValueMap.find(utils::constant::MUSIC_LEFT);
                          activ->setButtonType(utils::constant::MUSIC_LEFT);
                          draw->rect.top = itLeft->second.rectTop;
                          draw->rect.left = itLeft->second.rectLeft;
                          break;
                      }
                      case utils::constant::MUSIC_RIGHT_HOVER: {
                          auto itRight = utils::constant::buttonValueMap.find(utils::constant::MUSIC_RIGHT);
                          activ->setButtonType(utils::constant::MUSIC_RIGHT);
                          draw->rect.top = itRight->second.rectTop;
                          draw->rect.left = itRight->second.rectLeft;
                          break;
                      }
                      case utils::constant::HOW_TO_HOVER: {
                          auto itHowTo = utils::constant::buttonValueMap.find(utils::constant::HOW_TO);
                          activ->setButtonType(utils::constant::HOW_TO);
                          draw->rect.top = itHowTo->second.rectTop;
                          draw->rect.left = itHowTo->second.rectLeft;
                          break;
                      }
                      case utils::constant::SETTINGS_HOVER: {
                          auto itSettings = utils::constant::buttonValueMap.find(utils::constant::SETTINGS);
                          activ->setButtonType(utils::constant::SETTINGS);
                          draw->rect.top = itSettings->second.rectTop;
                          draw->rect.left = itSettings->second.rectLeft;
                          break;
                      }
                      default:
                          break;
                  }
                  activ->setIsHover(false);
              }
          }
      }
    };
} // namespace ecs::systems

Updated on 2022-11-13 at 17:21:37 +0100

PreviousHealthBar.hppNextScoreUpdate.hpp

Last updated 2 years ago

ecs
ecs::systems