I think this is the best I can do for a hover vs. click shader effect. Just do it in a shader based on a uniform setting.
This commit is contained in:
parent
84a5f06dac
commit
7186c2ecb0
16 changed files with 54 additions and 38 deletions
|
@ -5,18 +5,25 @@ uniform float u_time;
|
|||
uniform float u_time_end;
|
||||
uniform sampler2D texture;
|
||||
uniform bool is_shape;
|
||||
uniform bool hover;
|
||||
|
||||
vec4 blink() {
|
||||
if(hover) {
|
||||
return vec4(0.95, 0.95, 1.0, 1.0);
|
||||
} else {
|
||||
float tick = (u_time_end - u_time) / u_duration;
|
||||
float blink = mix(0.5, 1.0, tick);
|
||||
return vec4(blink, blink, blink, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
vec4 color = blink();
|
||||
|
||||
if(!is_shape) {
|
||||
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;
|
||||
color *= pixel;
|
||||
}
|
||||
|
||||
gl_FragColor = gl_Color * color;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<lel::Cell, Clickable>([&](auto ent, auto& cell, auto &clicked) {
|
||||
|
@ -227,10 +227,13 @@ namespace guecs {
|
|||
(y >= cell.y && y <= cell.y + cell.h))
|
||||
{
|
||||
if($world.has<Effect>(ent)) {
|
||||
auto& shader = $world.get<Effect>(ent);
|
||||
shader.run();
|
||||
auto& effect = $world.get<Effect>(ent);
|
||||
effect.$shader->setUniform("hover", hover);
|
||||
effect.run();
|
||||
}
|
||||
|
||||
if(hover) return; // kinda gross
|
||||
|
||||
if(auto action_data = get_if<ActionData>(ent)) {
|
||||
clicked.action(ent, action_data->data);
|
||||
} else {
|
||||
|
|
|
@ -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 <typename Comp>
|
||||
|
|
16
gui_fsm.cpp
16
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::Event::MouseMoved>()) {
|
||||
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<sf::Event::KeyPressed>()) {
|
||||
|
|
|
@ -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>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue