272 lines
7.0 KiB
GDScript
272 lines
7.0 KiB
GDScript
extends Node
|
||
|
||
enum VIBE {
|
||
NORAML,
|
||
MYSTERY,
|
||
DANGEROUS,
|
||
TOUCHING,
|
||
}
|
||
|
||
@export var first_entered = true
|
||
|
||
# func _ready():
|
||
# get_tree().node_added.connect("_on_node_added")
|
||
|
||
#### 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
|
||
return get_tree().current_scene.get_node_or_null("Ground")
|
||
|
||
|
||
func get_camera_marker() -> CameraFocusMarker:
|
||
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_node(node: Node2D, duration := 0.0) -> void:
|
||
var marker = get_camera_marker()
|
||
if marker:
|
||
marker.focus_node(node, duration)
|
||
|
||
|
||
func focus_player_and_reset_zoom(duration := 1.2) -> void:
|
||
var marker = get_camera_marker()
|
||
if marker:
|
||
# marker.force_offset = Vector2.ZERO
|
||
marker.tween_zoom(1.0, duration)
|
||
# 运镜更平滑一些
|
||
marker.focus_node(get_player(), duration + .3)
|
||
|
||
|
||
# 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")
|
||
|
||
|
||
var balloon_node
|
||
|
||
|
||
func pop_debug_dialog_info(character: String, content: String):
|
||
if GlobalConfig.DEBUG:
|
||
if not is_instance_valid(balloon_node):
|
||
balloon_node = preload("res://scene/dialog/balloon_debug.tscn").instantiate()
|
||
var title = "title"
|
||
var body = "~ " + title + "\n"
|
||
body += character + ": " + content + "\n"
|
||
body += "=> END"
|
||
var res = DialogueManager.create_resource_from_text(body)
|
||
DialogueManager.show_dialogue_balloon_scene(balloon_node, res, title)
|
||
|
||
|
||
#### Shader ####
|
||
|
||
|
||
func get_shading_layer() -> ShadingLayer:
|
||
return get_node_or_null("/root/Main/ShadingLayer") as ShadingLayer
|
||
|
||
|
||
#### Prop ####
|
||
|
||
|
||
func get_prop_hud() -> PropHud:
|
||
return get_node_or_null("/root/Main/UILayer/PropHUD") as PropHud
|
||
|
||
|
||
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)
|
||
else:
|
||
printerr("enable_prop_item PropHud node not found")
|
||
|
||
|
||
func disable_prop_item(prop_key: String) -> void:
|
||
var prop_hud = get_prop_hud()
|
||
if prop_hud:
|
||
prop_hud.disable_prop_item(prop_key)
|
||
else:
|
||
printerr("disable_prop_item PropHud node not found")
|
||
|
||
|
||
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)
|
||
elif GlobalConfig.DEBUG:
|
||
# debug 模式,新建一个
|
||
var n = _create_debug_notification()
|
||
n.call_deferred("show_notification", msg, number)
|
||
else:
|
||
printerr("pop_notification: Notification node not found")
|
||
|
||
|
||
func pop_center_notification(msg: String) -> void:
|
||
var notification_node = get_node_or_null("/root/Main/UILayer/Notification")
|
||
if notification_node:
|
||
notification_node.show_center_notification(msg)
|
||
elif GlobalConfig.DEBUG:
|
||
# debug 模式,新建一个
|
||
var n = _create_debug_notification()
|
||
n.call_deferred("show_center_notification", msg)
|
||
else:
|
||
printerr("pop_center_notification: Notification node not found")
|
||
|
||
|
||
func pop_center_texture(texture: Texture2D, duration := 3.5) -> void:
|
||
var notification_node = get_node_or_null("/root/Main/UILayer/Notification")
|
||
if notification_node:
|
||
notification_node.show_center_texture(texture, duration)
|
||
elif GlobalConfig.DEBUG:
|
||
# debug 模式,新建一个
|
||
var n = _create_debug_notification()
|
||
n.call_deferred("show_center_texture", texture)
|
||
else:
|
||
printerr("pop_center_texture: Notification node not found")
|
||
|
||
|
||
# debug 模式,新建一个 notification node
|
||
func _create_debug_notification() -> Notification:
|
||
if not GlobalConfig.DEBUG:
|
||
return null
|
||
var main = get_node_or_null("/root/Main")
|
||
if not main:
|
||
main = Control.new()
|
||
main.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||
main.name = "Main"
|
||
get_tree().root.call_deferred("add_child", main)
|
||
var n = preload("res://scene/notification/notification.tscn").instantiate()
|
||
main.add_child(n)
|
||
return n
|
||
|
||
|
||
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"))
|
||
|
||
|
||
var prop_bag = preload("res://scene/prop/prop_bag.tscn")
|
||
|
||
|
||
func show_bag():
|
||
pass
|
||
# 暂时不启用背包
|
||
# get_node("/root/Main").add_child(prop_bag.instantiate())
|
||
|
||
|
||
func quit_game():
|
||
ArchiveManager.save_all()
|
||
get_tree().quit()
|