Now have a do_if on GUECS for many of the 'if this exists do this' patterns.

master
Zed A. Shaw 3 weeks ago
parent 2ecef8d9f9
commit 57e042e786
  1. 2
      combat_ui.cpp
  2. 18
      guecs.cpp
  3. 8
      guecs.hpp
  4. 2
      ritual_ui.cpp
  5. 1
      status_ui.cpp

@ -17,7 +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<Sound>(button, {"ui_click"});
$gui.set<Label>(button, {label});
$gui.set<Effect>(button, {.duration=0.1f});
$gui.set<Clickable>(button,

@ -60,10 +60,7 @@ namespace guecs {
}
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 {
if(!hover) {
sound::play(on_click);
}
}
@ -235,17 +232,14 @@ namespace guecs {
if((x >= cell.x && x <= cell.x + cell.w) &&
(y >= cell.y && y <= cell.y + cell.h))
{
if($world.has<Effect>(ent)) {
auto& effect = $world.get<Effect>(ent);
do_if<Effect>(ent, [hover](auto& effect) {
effect.$shader->setUniform("hover", hover);
effect.run();
}
if($world.has<Sound>(ent)) {
auto& sound = $world.get<Sound>(ent);
sound.play(hover);
}
});
do_if<Sound>(ent, [hover](auto& sound) {
sound.play(hover);
});
if(hover) return; // kinda gross

@ -99,7 +99,6 @@ namespace guecs {
struct Sound {
std::string on_click{""};
std::string on_hover{""};
void play(bool hover);
};
@ -166,6 +165,13 @@ namespace guecs {
$world.set<Comp>(ent, val);
}
template <typename Comp>
void do_if(DinkyECS::Entity ent, std::function<void(Comp &)> cb) {
if($world.has<Comp>(ent)) {
cb($world.get<Comp>(ent));
}
}
lel::Cell& cell_for(DinkyECS::Entity ent) {
return $world.get<lel::Cell>(ent);
}

@ -51,6 +51,7 @@ namespace gui {
$gui.set<Sprite>(button, {
fmt::format("{}-64", junk_list[button % junk_list.size()])});
$gui.set<Effect>(button, {0.4f});
$gui.set<Sound>(button, {"ui_click"});
$gui.set<Clickable>(button, {
[&](auto ent, auto){ inv_slot_clicked(ent); }
});
@ -58,6 +59,7 @@ namespace gui {
$gui.set<Clickable>(button, {
[&](auto, auto){ toggle(); }
});
$gui.set<Sound>(button, {"pickup"});
}
}

@ -48,6 +48,7 @@ namespace gui {
$gui.set<Clickable>(button, {
[this](auto, auto){ select_ritual(); }
});
$gui.set<Sound>(button, {"pickup"});
} else {
$gui.set<Clickable>(button, {
[this](auto ent, auto data){ select_slot(ent, data); }

Loading…
Cancel
Save