ajout de la scène du cockpit
This commit is contained in:
16
stages/cockpit/scripts/cockpit.gd
Normal file
16
stages/cockpit/scripts/cockpit.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
extends Node3D
|
||||
class_name Cockpit
|
||||
|
||||
func _ready():
|
||||
if not GameInfo.game_data.get_current_planet_data():
|
||||
%ExitAction.hide()
|
||||
|
||||
|
||||
func _on_map_action_clicked():
|
||||
SceneManager.change_scene(SceneManager.REGION_SELECTION_SCREEN)
|
||||
|
||||
func _on_exit_action_clicked():
|
||||
if GameInfo.game_data.get_current_planet_data():
|
||||
%ArriveAnimationPlayer.play_backwards("arrive")
|
||||
await %ArriveAnimationPlayer.animation_finished
|
||||
SceneManager.change_scene(SceneManager.PLANET_SCENE)
|
||||
1
stages/cockpit/scripts/cockpit.gd.uid
Normal file
1
stages/cockpit/scripts/cockpit.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b4tpigoloyxu0
|
||||
17
stages/cockpit/scripts/cockpit_action.gd
Normal file
17
stages/cockpit/scripts/cockpit_action.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Area3D
|
||||
class_name CockpitAction
|
||||
|
||||
signal clicked
|
||||
|
||||
@export var animation_player : AnimationPlayer
|
||||
|
||||
func click():
|
||||
clicked.emit()
|
||||
|
||||
func _on_mouse_entered():
|
||||
if animation_player:
|
||||
animation_player.play("hover")
|
||||
|
||||
func _on_mouse_exited():
|
||||
if animation_player:
|
||||
animation_player.stop()
|
||||
1
stages/cockpit/scripts/cockpit_action.gd.uid
Normal file
1
stages/cockpit/scripts/cockpit_action.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bj4d1x8n8ina
|
||||
39
stages/cockpit/scripts/cockpit_camera.gd
Normal file
39
stages/cockpit/scripts/cockpit_camera.gd
Normal file
@@ -0,0 +1,39 @@
|
||||
extends Camera3D
|
||||
|
||||
const RAY_LENGTH = 1000.
|
||||
|
||||
var cockpit_action_hovered : CockpitAction = null
|
||||
var _mouse_event : InputEventMouse
|
||||
var _query_mouse := false
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouse:
|
||||
_mouse_event = event
|
||||
_query_mouse = true
|
||||
if event.is_action_pressed("action") and cockpit_action_hovered and cockpit_action_hovered:
|
||||
cockpit_action_hovered.click()
|
||||
|
||||
func _physics_process(_delta):
|
||||
if _query_mouse:
|
||||
update_mouse_hovered_cockpit_actions()
|
||||
_query_mouse = false
|
||||
|
||||
func update_mouse_hovered_cockpit_actions() -> void:
|
||||
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
var from = project_ray_origin(_mouse_event.position)
|
||||
var to = from + project_ray_normal(_mouse_event.position) * RAY_LENGTH
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.create(from, to)
|
||||
query.collide_with_areas = true
|
||||
var result = space_state.intersect_ray(query)
|
||||
|
||||
if result.is_empty():
|
||||
if cockpit_action_hovered:
|
||||
cockpit_action_hovered._on_mouse_exited()
|
||||
cockpit_action_hovered = null
|
||||
elif result.collider is CockpitAction:
|
||||
if cockpit_action_hovered and cockpit_action_hovered != result.collider:
|
||||
cockpit_action_hovered._on_mouse_exited()
|
||||
cockpit_action_hovered = result.collider
|
||||
cockpit_action_hovered._on_mouse_entered()
|
||||
1
stages/cockpit/scripts/cockpit_camera.gd.uid
Normal file
1
stages/cockpit/scripts/cockpit_camera.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jsxatpqfid88
|
||||
Reference in New Issue
Block a user