|
|
|
@ -29,6 +29,33 @@ using namespace std::chrono_literals; |
|
|
|
|
using namespace ftxui; |
|
|
|
|
using namespace components; |
|
|
|
|
|
|
|
|
|
const std::string modal_shader = R"( |
|
|
|
|
uniform sampler2D source; |
|
|
|
|
uniform sampler2D bloom; |
|
|
|
|
uniform vec2 offsetFactor; |
|
|
|
|
uniform float darkness; |
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
|
{ |
|
|
|
|
vec2 textureCoordinates = gl_TexCoord[0].xy; |
|
|
|
|
vec4 color = vec4(0.0); |
|
|
|
|
color += texture2D(source, textureCoordinates - 4.0 * offsetFactor) * 0.0162162162; |
|
|
|
|
color += texture2D(source, textureCoordinates - 3.0 * offsetFactor) * 0.0540540541; |
|
|
|
|
color += texture2D(source, textureCoordinates - 2.0 * offsetFactor) * 0.1216216216; |
|
|
|
|
color += texture2D(source, textureCoordinates - offsetFactor) * 0.1945945946; |
|
|
|
|
color += texture2D(source, textureCoordinates) * 0.2270270270; |
|
|
|
|
color += texture2D(source, textureCoordinates + offsetFactor) * 0.1945945946; |
|
|
|
|
color += texture2D(source, textureCoordinates + 2.0 * offsetFactor) * 0.1216216216; |
|
|
|
|
color += texture2D(source, textureCoordinates + 3.0 * offsetFactor) * 0.0540540541; |
|
|
|
|
color += texture2D(source, textureCoordinates + 4.0 * offsetFactor) * 0.0162162162; |
|
|
|
|
|
|
|
|
|
vec4 sourceFragment = texture2D(source, gl_TexCoord[0].xy); |
|
|
|
|
vec4 bloomFragment = texture2D(bloom, gl_TexCoord[0].xy); |
|
|
|
|
gl_FragColor = color + sourceFragment - bloomFragment - darkness; |
|
|
|
|
} |
|
|
|
|
)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUI::GUI(DinkyECS::World &world, Map& game_map) : |
|
|
|
|
$game_map(game_map), |
|
|
|
|
$log({{"Welcome to the game!"}}), |
|
|
|
@ -204,6 +231,9 @@ bool GUI::handle_ui_events() { |
|
|
|
|
} else if(KB::isKeyPressed(KB::L)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.LIGHT = !debug.LIGHT; |
|
|
|
|
} else if(KB::isKeyPressed(KB::I)) { |
|
|
|
|
create_modal(); |
|
|
|
|
$show_modal = !$show_modal; |
|
|
|
|
} else if(KB::isKeyPressed(KB::P)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.PATHS = !debug.PATHS; |
|
|
|
@ -227,6 +257,25 @@ bool GUI::handle_ui_events() { |
|
|
|
|
return event_happened; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::create_modal() { |
|
|
|
|
println("CREATING MODAL"); |
|
|
|
|
auto &window = $renderer.$window; |
|
|
|
|
auto size = window.getSize(); |
|
|
|
|
|
|
|
|
|
paused_texture.create(size.x, size.y); |
|
|
|
|
paused_texture.update(window); |
|
|
|
|
bool good = paused_shader.loadFromMemory(modal_shader, sf::Shader::Fragment); |
|
|
|
|
paused_shader.setUniform("offsetFactor", sf::Glsl::Vec2{0.001f, 0.001f}); |
|
|
|
|
paused_shader.setUniform("darkness", 0.05f); |
|
|
|
|
dbc::check(good, "shader could not be loaded"); |
|
|
|
|
paused_sprite.setTexture(paused_texture); |
|
|
|
|
paused_sprite.setPosition(0,0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::draw_modal() { |
|
|
|
|
auto &window = $renderer.$window; |
|
|
|
|
window.draw(paused_sprite, &paused_shader); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::run_systems() { |
|
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
@ -251,12 +300,15 @@ void GUI::shake() { |
|
|
|
|
void GUI::render_scene() { |
|
|
|
|
$renderer.clear(); |
|
|
|
|
|
|
|
|
|
$map_view.render(); |
|
|
|
|
$renderer.draw($map_view); |
|
|
|
|
|
|
|
|
|
$status_ui.render(); |
|
|
|
|
$renderer.draw($status_ui); |
|
|
|
|
if($show_modal) { |
|
|
|
|
draw_modal(); |
|
|
|
|
} else { |
|
|
|
|
$map_view.render(); |
|
|
|
|
$renderer.draw($map_view); |
|
|
|
|
|
|
|
|
|
$status_ui.render(); |
|
|
|
|
$renderer.draw($status_ui); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$renderer.display(); |
|
|
|
|
} |
|
|
|
|