improve ui and bug fix
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 5.4 KiB |
@@ -31,9 +31,10 @@ func get_all_collectibles() -> Array[CollectibleResource]:
|
||||
func get_unlocked_collectible_ids() -> Array[StringName]:
|
||||
return unlocked_collectibles_ids
|
||||
|
||||
func save_photo_to_disk_async() -> void:
|
||||
await RenderingServer.frame_post_draw
|
||||
var image = get_viewport().get_texture().get_image()
|
||||
func save_photo_to_disk_async(image: Image) -> void:
|
||||
if not image:
|
||||
return
|
||||
|
||||
|
||||
if not DirAccess.dir_exists_absolute("user://photos"):
|
||||
DirAccess.make_dir_absolute("user://photos")
|
||||
|
||||
@@ -21,9 +21,13 @@ var previous_camera: Camera3D
|
||||
var initial_local_pos: Vector3
|
||||
var initial_local_basis: Basis
|
||||
|
||||
var is_making_photo = false
|
||||
var captured_image: Image
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.on_enable_photo_mode_request.connect(enable_photo_mode)
|
||||
GameState.on_disable_photo_mode_request.connect(disable_photo_mode)
|
||||
GameState.on_photo_taken_making.connect(take_photo_async)
|
||||
|
||||
initial_local_pos = position
|
||||
initial_local_basis = basis
|
||||
@@ -50,13 +54,23 @@ func _input(event: InputEvent) -> void:
|
||||
if not is_active:
|
||||
GameState.on_enable_photo_mode_request.emit()
|
||||
else:
|
||||
GameState.on_disable_photo_mode_request.emit()
|
||||
if not is_making_photo:
|
||||
GameState.on_disable_photo_mode_request.emit()
|
||||
|
||||
if event is InputEventMouseMotion and is_active:
|
||||
total_yaw -= event.relative.x * rotation_speed
|
||||
|
||||
if event.is_action_pressed("take_photo"):
|
||||
take_photo_async()
|
||||
if !is_active or is_making_photo:
|
||||
return
|
||||
is_making_photo = true
|
||||
|
||||
GameState.on_photo_taken_prepare.emit()
|
||||
|
||||
await RenderingServer.frame_post_draw
|
||||
captured_image = get_viewport().get_texture().get_image()
|
||||
|
||||
GameState.on_photo_taken_started.emit()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not is_active:
|
||||
@@ -81,13 +95,10 @@ func _process(delta: float) -> void:
|
||||
basis = rotated_basis.orthonormalized()
|
||||
|
||||
func take_photo_async() -> void:
|
||||
if !is_active:
|
||||
return
|
||||
|
||||
var targets = get_tree().get_nodes_in_group("collectible")
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
|
||||
await CollectionManager.save_photo_to_disk_async()
|
||||
await CollectionManager.save_photo_to_disk_async(captured_image)
|
||||
|
||||
for target in targets:
|
||||
if not target.collectible_data:
|
||||
@@ -104,3 +115,5 @@ func take_photo_async() -> void:
|
||||
CollectionManager.unlock_collectible(target.collectible_data.id)
|
||||
|
||||
GameState.save_game()
|
||||
GameState.on_photo_taken_finished.emit()
|
||||
is_making_photo = false
|
||||
|
||||
Reference in New Issue
Block a user