Added in an initial test to blur the current screen for any pause actions, before doing a modal or new UI.
This commit is contained in:
		
							parent
							
								
									28d19d80a2
								
							
						
					
					
						commit
						db441000f8
					
				
					 2 changed files with 63 additions and 5 deletions
				
			
		
							
								
								
									
										62
									
								
								gui.cpp
									
										
									
									
									
								
							
							
						
						
									
										62
									
								
								gui.cpp
									
										
									
									
									
								
							|  | @ -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(); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										6
									
								
								gui.hpp
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								gui.hpp
									
										
									
									
									
								
							|  | @ -50,6 +50,10 @@ class GUI { | |||
|   SoundManager $sounds; | ||||
|   SFMLRender $renderer; | ||||
| 
 | ||||
|   sf::Texture paused_texture; | ||||
|   sf::Sprite paused_sprite; | ||||
|   sf::Shader paused_shader; | ||||
| 
 | ||||
| public: | ||||
|   GUI(DinkyECS::World& world, Map& game_map); | ||||
|   // disable copying
 | ||||
|  | @ -65,5 +69,7 @@ public: | |||
|   void save_world(); | ||||
|   void shake(); | ||||
|   void shutdown(); | ||||
|   void create_modal(); | ||||
|   void draw_modal(); | ||||
|   int main(bool run_once=false); | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw