cleaned up interaction code
This commit is contained in:
@@ -5,7 +5,6 @@ var rayRange = 2000
|
|||||||
@onready var crosshair = %CrosshairCenter
|
@onready var crosshair = %CrosshairCenter
|
||||||
@export var terminal: TerminalControls
|
@export var terminal: TerminalControls
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
Get_Camera_Collision()
|
Get_Camera_Collision()
|
||||||
|
|
||||||
@@ -24,24 +23,26 @@ func Get_Camera_Collision():
|
|||||||
if crosshair and is_instance_valid(crosshair):
|
if crosshair and is_instance_valid(crosshair):
|
||||||
crosshair.set_highlight(is_highlighted)
|
crosshair.set_highlight(is_highlighted)
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event is InputEventKey and event.pressed and crosshair.is_highlighted:
|
if event is InputEventKey and event.pressed and crosshair.is_highlighted:
|
||||||
|
|
||||||
if event.keycode == KEY_PAGEUP:
|
match event.keycode:
|
||||||
terminal.ScrollUp()
|
KEY_PAGEUP:
|
||||||
|
terminal.ScrollUp()
|
||||||
if event.keycode == KEY_PAGEDOWN:
|
|
||||||
terminal.ScrollDown()
|
|
||||||
|
|
||||||
if event.keycode == KEY_BACKSPACE:
|
|
||||||
|
|
||||||
terminal.InputDelChar()
|
KEY_PAGEDOWN:
|
||||||
|
terminal.ScrollDown()
|
||||||
|
|
||||||
|
KEY_BACKSPACE:
|
||||||
|
terminal.InputDelChar()
|
||||||
|
|
||||||
|
KEY_ENTER:
|
||||||
|
terminal.EnterCommand()
|
||||||
|
|
||||||
if event.unicode > 31:
|
if event.unicode > 31:
|
||||||
var character = char(event.unicode)
|
var character = char(event.unicode)
|
||||||
|
|
||||||
if terminal: # Check that you assigned the node in the Inspector
|
if terminal: # Check that you assigned the node in the Inspector
|
||||||
terminal.InputChar(character)
|
terminal.InputChar(character)
|
||||||
|
|
||||||
if event.keycode == KEY_ENTER:
|
|
||||||
terminal.EnterCommand()
|
|
||||||
|
|||||||
@@ -38,20 +38,19 @@ func reset_blink() -> void:
|
|||||||
|
|
||||||
# --- Input Handling ---
|
# --- Input Handling ---
|
||||||
func InputChar(input) -> void:
|
func InputChar(input) -> void:
|
||||||
var charPos = terminalLine.get_character_bounds(max(0, terminalLine.text.length() - 1))
|
|
||||||
if input == null:
|
if input == null:
|
||||||
return
|
return
|
||||||
if charPos.end.x > 1600:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
command = input
|
command = input
|
||||||
terminalLine.text += command
|
terminalLine.text += command
|
||||||
UpdateCaretPos()
|
UpdateCaretPos()
|
||||||
|
await get_tree().create_timer(.01).timeout
|
||||||
reset_blink()
|
reset_blink()
|
||||||
func InputDelChar() -> void:
|
func InputDelChar() -> void:
|
||||||
if terminalLine.text.length() > ("user@work " + directory).length() + 1:
|
if terminalLine.text.length() > ("user@work " + directory).length() + 1:
|
||||||
terminalLine.text = terminalLine.text.left(-1)
|
terminalLine.text = terminalLine.text.left(-1)
|
||||||
UpdateCaretPos()
|
UpdateCaretPos()
|
||||||
|
await get_tree().create_timer(.01).timeout
|
||||||
reset_blink()
|
reset_blink()
|
||||||
|
|
||||||
func EnterCommand() -> void:
|
func EnterCommand() -> void:
|
||||||
@@ -199,7 +198,7 @@ func ScrollUp():
|
|||||||
|
|
||||||
await get_tree().create_timer(.0001).timeout
|
await get_tree().create_timer(.0001).timeout
|
||||||
scroll.set_deferred("scroll_vertical", scroll.get_v_scroll_bar().value - 10 )
|
scroll.set_deferred("scroll_vertical", scroll.get_v_scroll_bar().value - 10 )
|
||||||
call("ScrollUp")
|
call_deferred("ScrollUp")
|
||||||
|
|
||||||
|
|
||||||
func ScrollDown():
|
func ScrollDown():
|
||||||
@@ -207,7 +206,7 @@ func ScrollDown():
|
|||||||
|
|
||||||
await get_tree().create_timer(.0001).timeout
|
await get_tree().create_timer(.0001).timeout
|
||||||
scroll.set_deferred("scroll_vertical", scroll.get_v_scroll_bar().value + 10 )
|
scroll.set_deferred("scroll_vertical", scroll.get_v_scroll_bar().value + 10 )
|
||||||
call("ScrollDown")
|
call_deferred("ScrollDown")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user