Skip to content

Commit

Permalink
Added fading in/out functions to scene manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phazorknight committed Sep 22, 2024
1 parent 3e438f4 commit ba42ee2
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 116 deletions.
8 changes: 4 additions & 4 deletions COGITO/CogitoObjects/cogito_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func _physics_process(delta):

if stand_after_roll:
if !is_movement_paused or !is_showing_ui:
print("COGITO Player 500: Standing after roll.")
CogitoSceneManager.cogito_print(is_logging, "cogito_player.gd", "500: Standing after roll.")
head.position.y = lerp(head.position.y, 0.0, delta * LERP_SPEED)
standing_collision_shape.disabled = true
crouching_collision_shape.disabled = false
Expand Down Expand Up @@ -533,7 +533,7 @@ func _physics_process(delta):
is_crouching = true
else:
if !is_showing_ui or !is_movement_paused:
print("COGITO Player 536: Standing up...")
CogitoSceneManager.cogito_print(is_logging, "cogito_player.gd", "536: Standing up...")
head.position.y = lerp(head.position.y, 0.0, delta * LERP_SPEED)
if head.position.y < CROUCHING_DEPTH/4:
# still transitioning from state
Expand Down Expand Up @@ -573,7 +573,7 @@ func _physics_process(delta):
# STANDING UP HANDLING
if is_crouching:
if !is_showing_ui or !is_movement_paused:
print("COGITO Player: standing up...")
CogitoSceneManager.cogito_print(is_logging, "cogito_player.gd", "576 standing up...")
current_speed = lerp(current_speed, WALKING_SPEED, delta * LERP_SPEED)
wiggle_current_intensity = WIGGLE_ON_WALKING_INTENSITY * HEADBOBBLE
wiggle_index += WIGGLE_ON_WALKING_SPEED * delta
Expand Down Expand Up @@ -635,7 +635,7 @@ func _physics_process(delta):
)
else:
if !is_movement_paused or !is_showing_ui:
print("COGITO Player 638: Standing up...")
CogitoSceneManager.cogito_print(is_logging, "cogito_player.gd", "638 Standing up...")
eyes.position.y = lerp(eyes.position.y, 0.0, delta * LERP_SPEED)
eyes.position.x = lerp(eyes.position.x, 0.0, delta * LERP_SPEED)
if last_velocity.y <= -7.5:
Expand Down
12 changes: 0 additions & 12 deletions COGITO/PackedScenes/Player_HUD.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,6 @@ layout_mode = 2
visible = false
layout_mode = 2

[node name="FadeInScreen" type="Panel" parent="."]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme = ExtResource("5_j6s1a")
theme_override_styles/panel = SubResource("StyleBoxFlat_rbke8")

[connection signal="timeout" from="HintTimer" to="." method="_on_hint_timer_timeout"]
[connection signal="drop_slot_data" from="InventoryInterface" to="." method="_on_inventory_interface_drop_slot_data"]
[connection signal="gui_input" from="InventoryInterface" to="InventoryInterface" method="_on_gui_input"]
Expand Down
1 change: 0 additions & 1 deletion COGITO/PackedScenes/cogito_player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
script = ExtResource("1_87we8")
pause_menu = NodePath("PauseMenu")
player_hud = NodePath("Player_HUD")
is_logging = true
fall_damage = 10
inventory_data = ExtResource("2_iyhv4")
jump_sound = ExtResource("3_7ds3n")
Expand Down
45 changes: 45 additions & 0 deletions COGITO/SceneManagement/cogito_scene_manager.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends Node

## Emitted when a fade finishes
signal fade_finished

# Used to set active save slot. This could be set/modified, when selecting a save slot from the MainMenu.
@export var _active_slot : String = "A"

Expand All @@ -23,11 +26,15 @@ enum CogitoSceneLoadMode {TEMP, LOAD_SAVE, RESET}
@export var cogito_scene_state_prefix : String = "COGITO_scene_state_"
@export var cogito_player_state_prefix : String = "COGITO_player_state_"

@export var default_fade_duration : float = .4
@export var fade_panel : Panel = null

func _ready() -> void:
_player_state = get_existing_player_state(_active_slot) #Setting active slot (per default it's A)
_scene_state = get_existing_scene_state(_active_slot)

reset_scene_states()
instantiate_fade_panel()


func switch_active_slot_to(slot_name:String):
Expand Down Expand Up @@ -145,6 +152,7 @@ func load_player_state(player, passed_slot:String):
player.player_interaction_component.set_state.call_deferred() #Calling this deferred as some state calls need to make sure the scene is finished loading.

player.player_state_loaded.emit()
CogitoSceneManager.fade_in()
else:
print("CSM: Player state of slot ", passed_slot, " doesn't exist.")

Expand Down Expand Up @@ -342,6 +350,8 @@ func save_scene_state(_scene_name_to_save, slot: String):

# Function to transition to another scene via the loading screen.
func load_next_scene(target : String, connector_name: String, passed_slot: String, load_mode: CogitoSceneLoadMode) -> void:
# fade_out()

var loading_screen = preload("res://COGITO/SceneManagement/LoadingScene.tscn").instantiate()
loading_screen.next_scene_path = target
loading_screen.connector_name = connector_name
Expand Down Expand Up @@ -478,3 +488,38 @@ func _exit_tree() -> void:
func cogito_print(is_logging: bool, _class: String, _message: String) -> void:
if is_logging:
print("COGITO: ", _class, ": ", _message)


### FUNCTIONS TO HANDLE SCREEN FADING

func instantiate_fade_panel() -> void:
fade_panel = Panel.new()

var black_stylebox := StyleBoxFlat.new()
black_stylebox.bg_color = Color.BLACK

fade_panel.set_anchors_preset(Control.PRESET_FULL_RECT)
fade_panel.focus_mode = Control.FOCUS_NONE
fade_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
fade_panel.set_modulate(Color.TRANSPARENT)
fade_panel.add_theme_stylebox_override("panel", black_stylebox)

add_child(fade_panel)


func fade_in(fade_duration:float = default_fade_duration) -> void:
fade_panel.set_modulate(Color.BLACK)
var fade_tween = get_tree().create_tween()

fade_tween.tween_property(fade_panel, "modulate", Color.TRANSPARENT, fade_duration).set_trans(Tween.TRANS_CUBIC)
await fade_tween.finished
fade_finished.emit()


func fade_out(fade_duration:float = default_fade_duration) -> void:
fade_panel.set_modulate(Color.TRANSPARENT)
var fade_tween = get_tree().create_tween()

fade_tween.tween_property(fade_panel, "modulate", Color.BLACK, fade_duration).set_trans(Tween.TRANS_CUBIC)
await fade_tween.finished
fade_finished.emit()
1 change: 1 addition & 0 deletions COGITO/SceneManagement/loading_screen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ func _process(_delta):

if connector_name != "": #If a connector name has been passed, move the player to it. This requires the target scene to have a cogito scene script attached to it's root scene node.
new_scene_node.move_player_to_connector(connector_name)

current_scene.queue_free() # Removing previous scene.
10 changes: 1 addition & 9 deletions COGITO/Scripts/player_hud_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var interaction_texture : Texture2D
@onready var prompt_area: Control = $PromptArea
@onready var hint_area: Control = $HintArea
@onready var ui_attribute_area : VBoxContainer = $MarginContainer_BottomUI/PlayerAttributes/MarginContainer/VBoxContainer
@onready var fade_in_screen: Panel = $FadeInScreen
@onready var crosshair: Control = $Crosshair

#endregion
Expand All @@ -57,13 +56,12 @@ func _ready():

_setup_player.call_deferred()
connect_to_external_inventories.call_deferred()

fade_in.call_deferred(1.5)


func setup_player(new_player : Node):
player = new_player
_setup_player()



func _setup_player():
Expand All @@ -89,12 +87,6 @@ func connect_to_player_signals():
player.player_state_loaded.connect(_on_player_state_load)


func fade_in(fade_in_duration: float):
fade_in_screen.set_modulate(Color.BLACK)
var fade_tween = get_tree().create_tween()
fade_tween.tween_property(fade_in_screen, "modulate", Color.TRANSPARENT, fade_in_duration)


func instantiate_player_attribute_ui():
for n in ui_attribute_area.get_children():
ui_attribute_area.remove_child(n)
Expand Down
4 changes: 4 additions & 0 deletions COGITO/Scripts/scene_transition_zone.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ func transition_to_next_scene():
current_scene_statename = get_tree().get_current_scene().get_name()
CogitoSceneManager.save_scene_state(current_scene_statename,"temp")
CogitoSceneManager.save_player_state(CogitoSceneManager._current_player_node, "temp")

CogitoSceneManager.fade_out()
await CogitoSceneManager.fade_finished

CogitoSceneManager.load_next_scene(path_to_new_scene, target_connector, "temp", CogitoSceneManager.CogitoSceneLoadMode.TEMP)
Loading

0 comments on commit ba42ee2

Please sign in to comment.