* ajout des mutations #86 * changement de l'objectif #85 * refonte de l'inspecteur #71 * changement léger de la plantation * les plantes ne donnent que des graines de leurs espèces * refonte partielle du code, refacto
111 lines
3.1 KiB
GDScript
111 lines
3.1 KiB
GDScript
extends Node
|
|
|
|
signal inspected_changed(info : Inspector.Info)
|
|
|
|
const DEFAULT_ACTION_COLOR = Color.WHITE
|
|
const ENERGY_ACTION_COLOR = Color("ffff2b")
|
|
const ZONE_OPACITY = 0.4
|
|
const ZONE_ACTIVATED_COLOR = Color.TURQUOISE
|
|
const ZONE_DEACTIVATED_COLOR = Color.REBECCA_PURPLE
|
|
|
|
@export var default_cursor : Texture2D
|
|
|
|
var inspected : Node = null
|
|
var inspected_info : Inspector.Info = null
|
|
var player : Player # renseigné par Player
|
|
var can_interact : bool = false
|
|
var current_selected_item : Item = null
|
|
var can_use_item : bool = false
|
|
|
|
func _ready():
|
|
Input.set_custom_mouse_cursor(default_cursor)
|
|
%InspectorText.visible = false
|
|
%Action.visible = false
|
|
|
|
func _input(_event):
|
|
if player:
|
|
if Input.is_action_just_pressed("move"):
|
|
player.try_move(
|
|
player.get_global_mouse_position()
|
|
)
|
|
if Input.is_action_just_pressed("drop"):
|
|
player.drop_item()
|
|
|
|
if Input.is_action_just_pressed("action"):
|
|
if can_interact:
|
|
var interactable = inspected as Interactable
|
|
player.try_interact(interactable)
|
|
elif can_use_item:
|
|
player.try_use_item(
|
|
player.inventory.get_item(),
|
|
player.get_global_mouse_position()
|
|
)
|
|
|
|
func _process(_delta):
|
|
%Inspector.position = get_viewport().get_mouse_position()
|
|
|
|
if player:
|
|
can_interact = (
|
|
inspected
|
|
and inspected is Interactable
|
|
and player.can_interact(inspected)
|
|
)
|
|
|
|
current_selected_item = player.inventory.get_item()
|
|
|
|
can_use_item = (
|
|
current_selected_item
|
|
and player.preview_can_use_item(current_selected_item)
|
|
)
|
|
|
|
if current_selected_item:
|
|
%ActionZone.radius = current_selected_item.usage_zone_radius
|
|
%ActionZone.color = ZONE_ACTIVATED_COLOR if can_use_item else ZONE_DEACTIVATED_COLOR
|
|
else:
|
|
%ActionZone.radius = 0
|
|
|
|
%ActionZone.queue_redraw()
|
|
|
|
update_inspector()
|
|
|
|
func inspect(node : Node, info : Inspector.Info):
|
|
if inspected and inspected != node and inspected.has_method("inspect"):
|
|
inspected.inspect(false)
|
|
inspected_info = info
|
|
inspected = node
|
|
inspected_changed.emit(inspected_info)
|
|
if inspected.has_method("inspect"):
|
|
inspected.inspect(true)
|
|
update_inspector()
|
|
|
|
func update_inspector():
|
|
%InspectorText.visible = inspected != null
|
|
if inspected and inspected is InspectableEntity:
|
|
%InspectorText.text = inspected.pointer_text()
|
|
|
|
if player:
|
|
if can_interact and inspected and inspected is Interactable:
|
|
%Action.visible = true
|
|
%ActionText.text = inspected.interact_text()
|
|
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
|
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
|
elif can_use_item and current_selected_item:
|
|
%Action.visible = true
|
|
%ActionText.text = current_selected_item.use_text()
|
|
%Action.modulate = DEFAULT_ACTION_COLOR if current_selected_item.energy_usage == 0 else ENERGY_ACTION_COLOR
|
|
%ActionEnergyImage.visible = current_selected_item.energy_usage != 0
|
|
else:
|
|
%Action.visible = false
|
|
|
|
else:
|
|
%Action.visible = false
|
|
|
|
func stop_inspect(node : Node):
|
|
if node.has_method("inspect"):
|
|
node.inspect(false)
|
|
if inspected == node:
|
|
inspected = null
|
|
inspected_info = null
|
|
inspected_changed.emit(inspected_info)
|
|
update_inspector()
|