diff --git a/assets/shaders/ui_shader.frag b/assets/shaders/ui_shader.frag index d60b826..73b77b4 100644 --- a/assets/shaders/ui_shader.frag +++ b/assets/shaders/ui_shader.frag @@ -5,18 +5,25 @@ uniform float u_time; uniform float u_time_end; uniform sampler2D texture; uniform bool is_shape; +uniform bool hover; -void main() { - if(is_shape) { - float tick = (u_time_end - u_time) / u_duration; - float blink = mix(0.5, 1.0, tick); - vec4 color = vec4(blink, blink, blink, 1.0); - gl_FragColor = gl_Color * color; +vec4 blink() { + if(hover) { + return vec4(0.95, 0.95, 1.0, 1.0); } else { - vec4 pixel = texture2D(texture, gl_TexCoord[0].xy); float tick = (u_time_end - u_time) / u_duration; float blink = mix(0.5, 1.0, tick); - vec4 color = vec4(blink, blink, blink, 1.0); - gl_FragColor = gl_Color * color * pixel; + return vec4(blink, blink, blink, 1.0); } } + +void main() { + vec4 color = blink(); + + if(!is_shape) { + vec4 pixel = texture2D(texture, gl_TexCoord[0].xy); + color *= pixel; + } + + gl_FragColor = gl_Color * color; +} diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index e757fb1..486ecd2 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -139,12 +139,12 @@ namespace gui { $overlay.render(window); } - bool BossFightUI::mouse(float x, float y) { - if($status.mouse(x, y)) { + bool BossFightUI::mouse(float x, float y, bool hover) { + if($status.mouse(x, y, hover)) { dbc::log("STATUS button pressed"); } - if($overlay.mouse(x, y)) { + if($overlay.mouse(x, y, hover)) { $animation.play(); sound::play("Sword_Hit_1"); $boss_hit = !$boss_hit; diff --git a/boss_fight_ui.hpp b/boss_fight_ui.hpp index 8d48495..3fbe208 100644 --- a/boss_fight_ui.hpp +++ b/boss_fight_ui.hpp @@ -38,7 +38,7 @@ namespace gui { void init(); void render(sf::RenderWindow& window); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void bounce_boss(sf::RenderWindow& window); bool boss_dead() { return $combat.hp < 0; } void configure_sprite(); diff --git a/combat_ui.cpp b/combat_ui.cpp index fe83137..da9ebe6 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -46,7 +46,7 @@ namespace gui { init(); } - bool CombatUI::mouse(float x, float y) { - return $gui.mouse(x, y); + bool CombatUI::mouse(float x, float y, bool hover) { + return $gui.mouse(x, y, hover); } } diff --git a/combat_ui.hpp b/combat_ui.hpp index 3402e46..2eb01d3 100644 --- a/combat_ui.hpp +++ b/combat_ui.hpp @@ -17,7 +17,7 @@ namespace gui { void render(sf::RenderWindow& window); void update_level(GameLevel &level); void set_damage(float percent); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void make_button(std::string name, std::wstring label, Events::GUI event); }; } diff --git a/debug_ui.cpp b/debug_ui.cpp index b4626ff..8c18efe 100644 --- a/debug_ui.cpp +++ b/debug_ui.cpp @@ -95,8 +95,8 @@ namespace gui { } } - bool DebugUI::mouse(float x, float y) { - return $gui.mouse(x, y); + bool DebugUI::mouse(float x, float y, bool hover) { + return $gui.mouse(x, y, hover); } void DebugUI::update_level(GameLevel &level) { diff --git a/debug_ui.hpp b/debug_ui.hpp index 57fb070..04adb26 100644 --- a/debug_ui.hpp +++ b/debug_ui.hpp @@ -17,7 +17,7 @@ namespace gui { void init(lel::Cell cell); void render(sf::RenderWindow& window); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void debug(); void update_level(GameLevel &level); void spawn(std::string enemy_key); diff --git a/guecs.cpp b/guecs.cpp index a3c84e4..0866f78 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -219,7 +219,7 @@ namespace guecs { }); } - bool UI::mouse(float x, float y) { + bool UI::mouse(float x, float y, bool hover) { int action_count = 0; $world.query([&](auto ent, auto& cell, auto &clicked) { @@ -227,10 +227,13 @@ namespace guecs { (y >= cell.y && y <= cell.y + cell.h)) { if($world.has(ent)) { - auto& shader = $world.get(ent); - shader.run(); + auto& effect = $world.get(ent); + effect.$shader->setUniform("hover", hover); + effect.run(); } + if(hover) return; // kinda gross + if(auto action_data = get_if(ent)) { clicked.action(ent, action_data->data); } else { diff --git a/guecs.hpp b/guecs.hpp index 3bd8990..a75dd5e 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -143,7 +143,7 @@ namespace guecs { void init(); void render(sf::RenderWindow& window); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void debug_layout(sf::RenderWindow& window); template diff --git a/gui_fsm.cpp b/gui_fsm.cpp index ff5d316..b47cab0 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -235,18 +235,24 @@ namespace gui { if(mouse->button == sf::Mouse::Button::Left) { sf::Vector2f pos = $window.mapPixelToCoords(mouse->position); if(in_state(State::NEXT_LEVEL)) { - $boss_fight_ui->mouse(pos.x, pos.y); + $boss_fight_ui->mouse(pos.x, pos.y, false); if($boss_fight_ui->boss_dead()) { event(Event::STAIRS_DOWN); } } else { - $debug_ui.mouse(pos.x, pos.y); - $combat_ui.mouse(pos.x, pos.y); - $status_ui.mouse(pos.x, pos.y); - $main_ui.mouse(pos.x, pos.y); + $debug_ui.mouse(pos.x, pos.y, false); + $combat_ui.mouse(pos.x, pos.y, false); + $status_ui.mouse(pos.x, pos.y, false); + $main_ui.mouse(pos.x, pos.y, false); } } + } else if(const auto* mouse = ev->getIf()) { + sf::Vector2f pos = $window.mapPixelToCoords(mouse->position); + $debug_ui.mouse(pos.x, pos.y, true); + $combat_ui.mouse(pos.x, pos.y, true); + $status_ui.mouse(pos.x, pos.y, true); + $main_ui.mouse(pos.x, pos.y, true); } if(const auto* key = ev->getIf()) { diff --git a/main_ui.cpp b/main_ui.cpp index c2001e3..17cd45e 100644 --- a/main_ui.cpp +++ b/main_ui.cpp @@ -124,13 +124,13 @@ namespace gui { dirty(); } - void MainUI::mouse(int x, int y) { + void MainUI::mouse(int x, int y, bool hover) { if($show_level) { $show_level = false; $level.world->send(Events::GUI::STAIRS_DOWN, $level.player, {}); $overlay_ui.close_label("middle"); } else { - $overlay_ui.$gui.mouse(x, y); + $overlay_ui.$gui.mouse(x, y, hover); } } } diff --git a/main_ui.hpp b/main_ui.hpp index 5a3ea6b..0145ea1 100644 --- a/main_ui.hpp +++ b/main_ui.hpp @@ -26,7 +26,7 @@ namespace gui { MainUI(sf::RenderWindow& window); - void mouse(int x, int y); + void mouse(int x, int y, bool hover); void debug(); void render_debug(); diff --git a/ritual_ui.cpp b/ritual_ui.cpp index 401ae16..2be5c9d 100644 --- a/ritual_ui.cpp +++ b/ritual_ui.cpp @@ -113,8 +113,8 @@ namespace gui { animation::rotate(*bs.sprite, 20.0); } - bool RitualUI::mouse(float x, float y) { - return $gui.mouse(x, y); + bool RitualUI::mouse(float x, float y, bool hover) { + return $gui.mouse(x, y, hover); } void RitualUI::toggle() { diff --git a/ritual_ui.hpp b/ritual_ui.hpp index 06fc71c..9be3011 100644 --- a/ritual_ui.hpp +++ b/ritual_ui.hpp @@ -24,7 +24,7 @@ namespace gui { GameLevel $level; RitualUI(GameLevel level); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void toggle(); bool is_open(); void init(); diff --git a/status_ui.cpp b/status_ui.cpp index 2a422c3..98aaef4 100644 --- a/status_ui.cpp +++ b/status_ui.cpp @@ -60,11 +60,11 @@ namespace gui { $gui.init(); } - bool StatusUI::mouse(float x, float y) { + bool StatusUI::mouse(float x, float y, bool hover) { if($ritual_ui.is_open()) { - return $ritual_ui.mouse(x, y); + return $ritual_ui.mouse(x, y, hover); } else { - return $gui.mouse(x, y); + return $gui.mouse(x, y, hover); } } diff --git a/status_ui.hpp b/status_ui.hpp index 255c330..2861d7a 100644 --- a/status_ui.hpp +++ b/status_ui.hpp @@ -20,7 +20,7 @@ namespace gui { void select_slot(DinkyECS::Entity ent, std::any data); void select_ritual(); void update_level(GameLevel &level); - bool mouse(float x, float y); + bool mouse(float x, float y, bool hover); void log(std::wstring msg); void init(); void render(sf::RenderWindow &window);