breadwinner/scenes/player/ui_handler_component.gd
Hellie-xd 06bf75a93a started work on procedural map generation
look at detail at maps/dev/procedural_generation_test.tscn
2026-08-07 23:13:17 +02:00

63 lines
2.1 KiB
GDScript

extends Node
@export_category("UI")
@export var UI_SCALE: float = 1 ##rational scale of the ui
@export var UI_MOVEMENT_SENSITIVITY = 0.5 ##how much the UI moves when you move the camera
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
@onready var prompt: Node = %Prompt
@onready var in_game_menu: Control = %InGameMenu
@onready var ui: Control = %PlayerUi
@onready var player_state: Node = %PlayerState
@onready var player_manager: Node = %PlayerManager
@onready var player: CharacterBody3D = $"../.."
@onready var cursor: TextureRect = %Cursor
@onready var player_camera: Camera3D = %PlayerCamera
const SELECTED_COLOR = 0xcfcfcf78
const UNSELECTED_COLOR = 0x3d3d3d78
var action_panel_body = null
func _on_action_finder_body_entered(body: Node3D) -> void:
if body != null:
if body.is_in_group("grabbable"):
prompt.change_text("[LMB] to grab")
elif body.is_in_group("equippable"):
prompt.change_text("[R] to equip")
else:
return
action_panel_body = body
prompt.position = -(cursor.global_position - player_camera.unproject_position(action_panel_body.global_position)) / 2
prompt.visible = true
func _on_action_finder_body_exited(body: Node3D) -> void:
if body != null and body == action_panel_body:
action_panel_body = null
prompt.visible = false
func _process(delta: float) -> void:
if action_panel_body != null:
var target_position = cursor.global_position - player_camera.unproject_position(action_panel_body.global_position)
prompt.position = prompt.position.lerp(-target_position / 2, delta * 50)
func toggle_menu():
if !in_game_menu.visible:
ui.visible = false
in_game_menu.visible = true
cursor.visible = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
player_state.in_menu = true
prompt.visible = false
else:
ui.visible = true
in_game_menu.visible = false
cursor.visible = true
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
player_state.in_menu = false
if action_panel_body != null:
prompt.visible = true
func set_ui_scale(scale:float) -> void:
pass