xiandie/manager/deploy/scene/scene_manager.gd

260 lines
6.2 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Node
enum VIBE {
NORAML,
MYSTERY,
DANGEROUS,
TOUCHING,
}
@export var first_entered = true
var prop_bag_instance = preload("res://scene/prop/prop_bag.tscn").instantiate()
func _ready() -> void:
add_child(prop_bag_instance)
prop_bag_instance.visible = false
#### Ground and Loader ####
func get_ground_loader() -> GroundLoader:
return get_node_or_null("/root/Main/GroundLoader") as GroundLoader
func get_ground() -> Ground2D:
var loader = get_ground_loader()
if loader:
return loader.ground
# 在 editor 编辑时ground 在 Section 节点下
var root = get_node("/root")
for child in root.get_children():
if child.name.begins_with("S0") or child.name.begins_with("S1"):
return child.get_node_or_null("Ground") as Ground2D
return null
func get_camera_marker():
var ground = get_ground()
if ground:
return ground.camera_focus_marker
return null
func get_player() -> MainPlayer:
var ground = get_ground()
if ground:
return ground.player
return null
func focus_nodepath(node_path: NodePath) -> void:
if not node_path:
printerr("Node path is empty")
return
var node = get_node_or_null(node_path)
if node:
focus_node(node)
else:
printerr("Node not found:", node_path)
func focus_node(node: CanvasItem) -> void:
var ground = get_ground()
if ground:
ground.focus_node(node)
func focus_player() -> void:
var ground = get_ground()
if ground:
ground.focus_player()
func focus_player_and_reset_zoom(duration := .5) -> void:
var marker = get_camera_marker()
if marker:
marker.tween_zoom(1.0, duration).tween_callback(focus_player)
# action_locked 用于设置界面等强制锁定action_freezed 用于查看物品等锁定
# action_locked 优先级高于 action_freezed
# action_locked 对应 lock 与 unlock 方法
func lock_player():
var player = get_player()
if player:
player.action_locked = true
func unlock_player():
var player = get_player()
if player:
player.action_locked = false
# action_freezed 对应 freeze 与 release 方法
# lock_time: the time to lock the player action. 0 means lock forever, thus the player will be locked until release_player is called.
func freeze_player(
lock_time: float, action := PlayerAnimationConfig.ACTION_NONE, auto_quit := false
) -> void:
var player = get_player()
if player:
player.freeze_player(lock_time, action, auto_quit)
else:
printerr("Player node not found")
func freeze_and_play(lock_time: float, animation := "", auto_quit := false) -> void:
var player = get_player()
if player:
player.freeze_and_play(lock_time, animation, auto_quit)
else:
printerr("Player node not found")
func release_player():
var player = get_player()
if player:
player.release_player()
else:
printerr("Player node not found")
func set_camera_boundary(rect: Rect2) -> void:
var camera_marker = get_camera_marker()
camera_marker.limit_left = rect.position.x
camera_marker.limit_right = rect.position.x + rect.size.x
camera_marker.limit_top = rect.position.y
camera_marker.limit_bottom = rect.position.y + rect.size.y
func set_player_boundary(rect: Rect2) -> void:
var player = get_player()
if player:
player.player_movement_rect = rect
else:
printerr("Player node not found")
#### Prop ####
var hud_path = ""
func get_prop_hud() -> PropHud:
var hud = get_node_or_null("/root/Main/UILayer/PropHUD") as PropHud
if hud:
return hud
if hud_path:
hud = get_node_or_null(hud_path) as PropHud
if hud:
return hud
else:
hud_path = ""
# 如果在 debug 模式从其他场景启动,没有 HUD 但又要获取,就新建 hud 放进场景
var ground = get_ground()
if ground:
var parent = ground.get_parent()
if parent:
var layer = CanvasLayer.new()
layer.layer = GlobalConfig.CANVAS_LAYER_UI
layer.name = "UILayer"
hud = preload("res://scene/prop/prop_hud.tscn").instantiate()
hud.name = "PropHUD"
layer.add_child(hud)
hud.inventory = ArchiveManager.archive.prop_inventory
parent.call_deferred("add_child", layer)
hud_path = str(parent.get_path()) + "/UILayer/PropHUD"
print("New HUD path:", hud_path)
return hud
func get_current_prop(must_selected: bool) -> String:
var prop_hud = get_prop_hud()
if prop_hud and (not must_selected or prop_hud.selected):
return prop_hud.inventory.current_item_key()
return ""
func enable_prop_item(prop_key: String) -> void:
var prop_hud = get_prop_hud()
if prop_hud:
prop_hud.enable_prop_item(prop_key)
func disable_prop_item(prop_key: String) -> void:
var prop_hud = get_prop_hud()
if prop_hud:
prop_hud.disable_prop_item(prop_key)
func pop_os(lines := []):
var player = get_player()
if player:
player.pop_os(lines)
else:
printerr("Player node not found")
func pop_notification(msg: String, number := 1) -> void:
var notification_node = get_node_or_null("/root/Main/UILayer/Notification")
if notification_node:
notification_node.show_notification(msg, number)
else:
printerr("Notification node not found")
func pop_dialog(
character: String,
content: String,
character_color := "orange",
content_color := "white",
duration := 2.5
) -> void:
var dialog_node = get_node_or_null("/root/Main/UILayer/Dialog")
if dialog_node:
dialog_node.append_dialog(character, content, character_color, content_color, duration)
else:
printerr("Dialog node not found")
# func pop_note(note: String, note_color := "white", duration := 2.5) -> void:
# var dialog_node = get_node_or_null("/root/Main/UILayer/Dialog")
# if dialog_node:
# dialog_node.append_note(note, note_color, duration)
# else:
# printerr("Dialog node not found")
func get_inspector() -> PropInspector:
return get_node_or_null("/root/Main/PropInspector") as PropInspector
func checkout_index_page():
ArchiveManager.save_all()
# get_tree().change_scene_to_file("res://scene/index_page.tscn")
get_tree().change_scene_to_packed(preload("res://scene/index_page.tscn"))
func show_bag():
freeze_player(0)
prop_bag_instance.visible = true
func hide_bag():
release_player()
prop_bag_instance.visible = false
func quit_game():
ArchiveManager.save_all()
get_tree().quit()
# func player_moved_delta_x(delta_x: float) -> void:
# # fog effect offset
# var fog = get_node_or_null("/root/Main/ShadingLayer/Fog")
# # if fog:
# # fog.texture.noise.offset.x += delta_x * 0.2