Have a basic little click sound going, but hover events will need some work. I'm doing those on every mouse move.
This commit is contained in:
parent
7186c2ecb0
commit
2ecef8d9f9
6 changed files with 36 additions and 11 deletions
|
@ -17,7 +17,9 @@
|
|||
"Marmot_Scream_1": "assets/sounds/Creature_Sounds-Marmot_Scream_1.ogg",
|
||||
"blank": "assets/sounds/blank.ogg",
|
||||
"pickup": "assets/sounds/pickup.ogg",
|
||||
"ambient_1": "assets/sounds/ambient_1.ogg"
|
||||
"ambient_1": "assets/sounds/ambient_1.ogg",
|
||||
"ui_click": "assets/sounds/ui_click.ogg",
|
||||
"ui_hover": "assets/sounds/ui_hover.ogg"
|
||||
},
|
||||
"sprites": {
|
||||
"gold_savior":
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace gui {
|
|||
auto button = $gui.entity(name);
|
||||
$gui.set<Sprite>(button, {"leather_pouch-128"});
|
||||
// $gui.set<Rectangle>(button, {});
|
||||
$gui.set<Sound>(button, {"ui_click", "ui_hover"});
|
||||
$gui.set<Label>(button, {label});
|
||||
$gui.set<Effect>(button, {.duration=0.1f});
|
||||
$gui.set<Clickable>(button,
|
||||
|
|
15
guecs.cpp
15
guecs.cpp
|
@ -1,5 +1,6 @@
|
|||
#include "guecs.hpp"
|
||||
#include "shaders.hpp"
|
||||
#include "sound.hpp"
|
||||
|
||||
namespace guecs {
|
||||
|
||||
|
@ -58,6 +59,14 @@ namespace guecs {
|
|||
bar.init(cell);
|
||||
}
|
||||
|
||||
void Sound::play(bool hover) {
|
||||
if(hover) {
|
||||
// BUG: need to sort out how to make hover a one shot thing
|
||||
// sound::play(on_hover);
|
||||
} else {
|
||||
sound::play(on_click);
|
||||
}
|
||||
}
|
||||
|
||||
void Background::init() {
|
||||
sf::Vector2f size{float(w), float(h)};
|
||||
|
@ -232,6 +241,12 @@ namespace guecs {
|
|||
effect.run();
|
||||
}
|
||||
|
||||
if($world.has<Sound>(ent)) {
|
||||
auto& sound = $world.get<Sound>(ent);
|
||||
sound.play(hover);
|
||||
}
|
||||
|
||||
|
||||
if(hover) return; // kinda gross
|
||||
|
||||
if(auto action_data = get_if<ActionData>(ent)) {
|
||||
|
|
|
@ -97,6 +97,13 @@ namespace guecs {
|
|||
shared_ptr<sf::Shader> checkout_ptr();
|
||||
};
|
||||
|
||||
struct Sound {
|
||||
std::string on_click{""};
|
||||
std::string on_hover{""};
|
||||
|
||||
void play(bool hover);
|
||||
};
|
||||
|
||||
struct Background {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
|
|
10
sound.cpp
10
sound.cpp
|
@ -37,7 +37,7 @@ namespace sound {
|
|||
}
|
||||
}
|
||||
|
||||
void load(const std::string name, const std::string sound_path) {
|
||||
void load(const std::string& name, const std::string& sound_path) {
|
||||
dbc::check(fs::exists(sound_path), fmt::format("sound file {} does not exist", sound_path));
|
||||
|
||||
// create the buffer and keep in the buffer map
|
||||
|
@ -51,7 +51,7 @@ namespace sound {
|
|||
SMGR.sounds.try_emplace(name, buffer, sound);
|
||||
}
|
||||
|
||||
void play(const std::string name, bool loop) {
|
||||
void play(const std::string& name, bool loop) {
|
||||
if(muted) return;
|
||||
auto& pair = get_sound_pair(name);
|
||||
pair.sound->setLooping(loop);
|
||||
|
@ -59,18 +59,18 @@ namespace sound {
|
|||
pair.sound->play();
|
||||
}
|
||||
|
||||
void stop(const std::string name) {
|
||||
void stop(const std::string& name) {
|
||||
auto& pair = get_sound_pair(name);
|
||||
pair.sound->stop();
|
||||
}
|
||||
|
||||
bool playing(const std::string name) {
|
||||
bool playing(const std::string& name) {
|
||||
auto& pair = get_sound_pair(name);
|
||||
auto status = pair.sound->getStatus();
|
||||
return status == sf::SoundSource::Status::Playing;
|
||||
}
|
||||
|
||||
void play_at(const std::string name, float x, float y, float z) {
|
||||
void play_at(const std::string& name, float x, float y, float z) {
|
||||
auto& pair = get_sound_pair(name);
|
||||
pair.sound->setPosition({x, y, z});
|
||||
pair.sound->play();
|
||||
|
|
10
sound.hpp
10
sound.hpp
|
@ -16,11 +16,11 @@ namespace sound {
|
|||
};
|
||||
|
||||
void init();
|
||||
void load(const std::string name, const std::string path);
|
||||
void play(const std::string name, bool loop=false);
|
||||
void play_at(const std::string name, float x, float y, float z);
|
||||
void stop(const std::string name);
|
||||
void load(const std::string& name, const std::string& path);
|
||||
void play(const std::string& name, bool loop=false);
|
||||
void play_at(const std::string& name, float x, float y, float z);
|
||||
void stop(const std::string& name);
|
||||
void mute(bool setting);
|
||||
bool playing(const std::string name);
|
||||
bool playing(const std::string& name);
|
||||
SoundPair& get_sound_pair(const std::string& name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue