73 lines
2.5 KiB
GDScript3
73 lines
2.5 KiB
GDScript3
|
|
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
|
||
|
|
|
||
|
|
@export var GRAB_PANEL: PackedScene
|
||
|
|
|
||
|
|
@onready var in_game_menu: Control = %InGameMenu
|
||
|
|
@onready var ui: Control = %PlayerUi
|
||
|
|
@onready var popup_panels: Control = %PopupPanels
|
||
|
|
@onready var player_state: Node = %PlayerState
|
||
|
|
@onready var player_properties: Node = %PlayerProperties
|
||
|
|
@onready var player: PlayerCharacter = $"../.."
|
||
|
|
@onready var cursor: TextureRect = %Cursor
|
||
|
|
@onready var player_camera: Camera3D = %PlayerCamera
|
||
|
|
|
||
|
|
var grabbable_panel = null
|
||
|
|
var grabbable_panel_body = null
|
||
|
|
|
||
|
|
func _on_grabbable_finder_body_entered(body: Node3D) -> void:
|
||
|
|
if body.is_in_group("grabbable"):
|
||
|
|
grabbable_panel = GRAB_PANEL.instantiate()
|
||
|
|
popup_panels.add_child(grabbable_panel)
|
||
|
|
grabbable_panel_body = body
|
||
|
|
|
||
|
|
func _on_grabbable_finder_body_exited(body: Node3D) -> void:
|
||
|
|
if body == grabbable_panel_body:
|
||
|
|
popup_panels.remove_child(grabbable_panel)
|
||
|
|
grabbable_panel = null
|
||
|
|
grabbable_panel_body = null
|
||
|
|
|
||
|
|
func _process(delta: float) -> void:
|
||
|
|
if grabbable_panel != null:
|
||
|
|
var target_position = cursor.position - player_camera.unproject_position(grabbable_panel_body.global_position)
|
||
|
|
grabbable_panel.position = grabbable_panel.position.lerp(-target_position / 2, delta * 50)
|
||
|
|
|
||
|
|
func toggle_menu():
|
||
|
|
if !in_game_menu.visible:
|
||
|
|
ui.visible = false
|
||
|
|
popup_panels.visible = false
|
||
|
|
in_game_menu.visible = true
|
||
|
|
cursor.visible = false
|
||
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||
|
|
player_state.in_menu = true
|
||
|
|
else:
|
||
|
|
ui.visible = true
|
||
|
|
popup_panels.visible = true
|
||
|
|
in_game_menu.visible = false
|
||
|
|
cursor.visible = true
|
||
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||
|
|
player_state.in_menu = false
|
||
|
|
|
||
|
|
func next_item():
|
||
|
|
if player_properties.selected_item + 1 > player_properties.INVENTORY_MAX - 1:
|
||
|
|
player_properties.selected_item = 0
|
||
|
|
else:
|
||
|
|
player_properties.selected_item += 1
|
||
|
|
ui.select_item(player_properties.selected_item)
|
||
|
|
|
||
|
|
func prev_item():
|
||
|
|
if player_properties.selected_item - 1 < 0:
|
||
|
|
player_properties.selected_item = player_properties.INVENTORY_MAX - 1
|
||
|
|
else:
|
||
|
|
player_properties.selected_item -= 1
|
||
|
|
ui.select_item(player_properties.selected_item)
|
||
|
|
|
||
|
|
func select_item(index: int):
|
||
|
|
player_properties.select_item(index)
|
||
|
|
ui.select_item(index)
|