Make worldmap event changes fade in instead of pop in

This commit is contained in:
Luke Hubmayer-Werner 2024-07-26 23:04:04 +09:30
parent bb3c850c95
commit 877f1e491b
2 changed files with 14 additions and 10 deletions

View File

@ -97,7 +97,7 @@ void fragment() {
} }
// World 1 also has row #6 cols #12 and #13 swap every 5 frames at 60fps (12Hz) (world 2 portal) // World 1 also has row #6 cols #12 and #13 swap every 5 frames at 60fps (12Hz) (world 2 portal)
vec2 palette_uv = vec2(pal_col, pal_row); vec2 palette_uv = vec2(pal_col, pal_row);
COLOR = texture(palette, palette_uv); COLOR.rgb = texture(palette, palette_uv).rgb;
COLOR.a = step(0.000001, color_idx16); // Branchless transparency COLOR.a *= step(0.000001, color_idx16); // Branchless transparency
} }

View File

@ -11,6 +11,7 @@ var map_textures := [null, null, null, null, null]
var map_regional_replacement_amounts := [0, 0, 0, 0, 0] var map_regional_replacement_amounts := [0, 0, 0, 0, 0]
var map_regional_replacement_lists := [[], [], [], [], []] var map_regional_replacement_lists := [[], [], [], [], []]
var current_texture: Texture var current_texture: Texture
var last_event_texture: Texture # For fading events in
var minimap_mode := 0 var minimap_mode := 0
var minimap_tween := 0.0 var minimap_tween := 0.0
@ -60,6 +61,7 @@ func _jump_to_regional_replacement(region) -> void:
print_debug('Jumping to event position ', self.pos.x, self.pos.y) print_debug('Jumping to event position ', self.pos.x, self.pos.y)
var delay_map_update: float = -1.0 var delay_map_update: float = -1.0
const MAX_DELAY_MAP_UPDATE = 1.0
func _perform_regional_replacement(amount: int) -> void: func _perform_regional_replacement(amount: int) -> void:
var map = MapLoader.worldmaps[current_map_id] var map = MapLoader.worldmaps[current_map_id]
var last_region var last_region
@ -67,7 +69,7 @@ func _perform_regional_replacement(amount: int) -> void:
0: 0:
map.blockmap = map.blockmap_original map.blockmap = map.blockmap_original
self.map_regional_replacement_amounts[current_map_id] = 0 self.map_regional_replacement_amounts[current_map_id] = 0
self.delay_map_update = 0.0001 self.delay_map_update = 0.0
1: 1:
if self.map_regional_replacement_amounts[current_map_id] >= len(self.map_regional_replacement_lists[current_map_id]): if self.map_regional_replacement_amounts[current_map_id] >= len(self.map_regional_replacement_lists[current_map_id]):
return return
@ -75,7 +77,8 @@ func _perform_regional_replacement(amount: int) -> void:
map.apply_event_region_replacement(last_region) map.apply_event_region_replacement(last_region)
self._jump_to_regional_replacement(last_region) self._jump_to_regional_replacement(last_region)
self.map_regional_replacement_amounts[current_map_id] += 1 self.map_regional_replacement_amounts[current_map_id] += 1
self.delay_map_update = 1.0 self.last_event_texture = self.current_texture
self.delay_map_update = MAX_DELAY_MAP_UPDATE
-1: -1:
if self.map_regional_replacement_amounts[current_map_id] < 1: if self.map_regional_replacement_amounts[current_map_id] < 1:
return return
@ -86,9 +89,9 @@ func _perform_regional_replacement(amount: int) -> void:
last_region = self.map_regional_replacement_lists[current_map_id][i] last_region = self.map_regional_replacement_lists[current_map_id][i]
map.apply_event_region_replacement(last_region) map.apply_event_region_replacement(last_region)
# self._jump_to_regional_replacement(last_region) # self._jump_to_regional_replacement(last_region)
self.delay_map_update = 0.0001 self.delay_map_update = 0.0
# self._create_worldmap_texture(current_map_id) self._create_worldmap_texture(current_map_id)
# self._set_map(current_map_id) # refresh shader etc. self._set_map(current_map_id) # refresh shader etc.
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
@ -138,9 +141,6 @@ func _process(delta: float) -> void:
# Hack to do a presentation of map region replacements with a nice before and after # Hack to do a presentation of map region replacements with a nice before and after
if self.delay_map_update > 0.000: if self.delay_map_update > 0.000:
self.delay_map_update -= delta self.delay_map_update -= delta
if self.delay_map_update <= 0.000:
self._create_worldmap_texture(current_map_id)
self._set_map(current_map_id) # refresh shader etc.
update() update()
@ -155,6 +155,10 @@ func _draw() -> void:
var uvpos := pos/256.0 var uvpos := pos/256.0
var v_uvs := PoolVector2Array([uvpos+Vector2(-UV_W2, -UV_H2), uvpos+Vector2(UV_W2, -UV_H2), uvpos+Vector2(UV_W2, UV_H2), uvpos+Vector2(-UV_W2, UV_H2)]) var v_uvs := PoolVector2Array([uvpos+Vector2(-UV_W2, -UV_H2), uvpos+Vector2(UV_W2, -UV_H2), uvpos+Vector2(UV_W2, UV_H2), uvpos+Vector2(-UV_W2, UV_H2)])
draw_primitive(V_POINTS, V_COLORS, v_uvs, self.current_texture) draw_primitive(V_POINTS, V_COLORS, v_uvs, self.current_texture)
if self.delay_map_update > 0.0:
var alpha = self.delay_map_update / MAX_DELAY_MAP_UPDATE
var color = Color(1, 1, 1, alpha)
draw_primitive(V_POINTS, [color, color, color, color], v_uvs, self.last_event_texture)
#draw_texture_rect_region(self.map_textures[0], Rect2(0, 0, 384, 240), Rect2(pos.x, pos.y, pos.x+VW, pos.y+VH), Color.white, false, null, false) #draw_texture_rect_region(self.map_textures[0], Rect2(0, 0, 384, 240), Rect2(pos.x, pos.y, pos.x+VW, pos.y+VH), Color.white, false, null, false)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void: