2020-07-06 19:58:42 +00:00
|
|
|
tool
|
|
|
|
|
|
|
|
extends StaticBody2D
|
|
|
|
|
2020-07-07 11:01:12 +00:00
|
|
|
class_name GameObjectComputer
|
|
|
|
|
2020-07-06 19:58:42 +00:00
|
|
|
enum Direction { LEFT, RIGHT, UP, DOWN }
|
2020-07-16 12:37:56 +00:00
|
|
|
enum ComputerType { ShipCommand, Comms, Medical, Research, Energy, ShipEngine, Atmos, Monitoring }
|
2020-07-06 19:58:42 +00:00
|
|
|
|
|
|
|
export(Direction) var direction = Direction.DOWN setget set_direction
|
|
|
|
export(ComputerType) var computer_type = ComputerType.ShipCommand setget set_type
|
|
|
|
|
|
|
|
var screen_region_offset = Vector2.ZERO
|
2020-07-07 07:40:20 +00:00
|
|
|
var open = false
|
|
|
|
|
|
|
|
onready var activationRange = $ActivationRange as ActivationRange
|
2020-07-09 14:50:34 +00:00
|
|
|
onready var manager = $PowerManager as PowerManager
|
2020-07-06 19:58:42 +00:00
|
|
|
|
2020-07-07 08:38:32 +00:00
|
|
|
func _ready():
|
|
|
|
if not Engine.editor_hint:
|
|
|
|
activationRange.visible = true
|
2020-07-16 12:44:35 +00:00
|
|
|
$computer/screen/Light2D.visible = true
|
2020-07-07 08:38:32 +00:00
|
|
|
|
2020-07-06 19:58:42 +00:00
|
|
|
func set_type(val):
|
|
|
|
computer_type = val
|
|
|
|
match computer_type:
|
|
|
|
ComputerType.ShipCommand:
|
|
|
|
screen_region_offset = Vector2(0, 0)
|
|
|
|
ComputerType.Comms:
|
|
|
|
screen_region_offset = Vector2(0, 32)
|
|
|
|
ComputerType.Medical:
|
|
|
|
screen_region_offset = Vector2(0, 64)
|
|
|
|
ComputerType.Research:
|
|
|
|
screen_region_offset = Vector2(128, 0)
|
2020-07-07 16:08:56 +00:00
|
|
|
ComputerType.Energy:
|
2020-07-06 19:58:42 +00:00
|
|
|
screen_region_offset = Vector2(128, 224)
|
|
|
|
ComputerType.Atmos:
|
2020-07-07 16:08:56 +00:00
|
|
|
screen_region_offset = Vector2(128, 192)
|
|
|
|
ComputerType.ShipEngine:
|
2020-07-06 19:58:42 +00:00
|
|
|
screen_region_offset = Vector2(0, 256)
|
2020-07-16 12:37:56 +00:00
|
|
|
ComputerType.Monitoring:
|
|
|
|
screen_region_offset = Vector2(128, 32)
|
2020-07-07 16:08:56 +00:00
|
|
|
|
2020-07-07 00:47:29 +00:00
|
|
|
refresh_sprite()
|
2020-07-06 19:58:42 +00:00
|
|
|
|
|
|
|
func set_direction(dir):
|
|
|
|
direction = dir
|
2020-07-07 00:47:29 +00:00
|
|
|
refresh_sprite()
|
|
|
|
|
|
|
|
func refresh_sprite():
|
2020-07-06 19:58:42 +00:00
|
|
|
match direction:
|
|
|
|
Direction.DOWN:
|
|
|
|
$computer.region_rect.position = Vector2(0, 0)
|
|
|
|
$computer/screen.region_rect.position = screen_region_offset + Vector2(0, 0)
|
2020-07-07 16:08:56 +00:00
|
|
|
$computer/screen/Light2D.rotation = 0
|
2020-07-06 19:58:42 +00:00
|
|
|
Direction.UP:
|
|
|
|
$computer.region_rect.position = Vector2(0, 32)
|
|
|
|
$computer/screen.region_rect.position = screen_region_offset + Vector2(32, 0)
|
2020-07-07 16:08:56 +00:00
|
|
|
$computer/screen/Light2D.rotation = PI
|
2020-07-06 19:58:42 +00:00
|
|
|
Direction.LEFT:
|
|
|
|
$computer.region_rect.position = Vector2(32, 32)
|
|
|
|
$computer/screen.region_rect.position = screen_region_offset + Vector2(96, 0)
|
2020-07-07 16:08:56 +00:00
|
|
|
$computer/screen/Light2D.rotation = PI/2
|
2020-07-06 19:58:42 +00:00
|
|
|
Direction.RIGHT:
|
|
|
|
$computer.region_rect.position = Vector2(32, 0)
|
|
|
|
$computer/screen.region_rect.position = screen_region_offset + Vector2(64, 0)
|
2020-07-07 16:08:56 +00:00
|
|
|
$computer/screen/Light2D.rotation = -PI/2
|
2020-07-06 22:00:39 +00:00
|
|
|
|
2020-07-06 22:09:37 +00:00
|
|
|
func manage_controls(show: bool):
|
2020-07-06 22:00:39 +00:00
|
|
|
match computer_type:
|
|
|
|
ComputerType.ShipCommand:
|
2020-07-06 22:09:37 +00:00
|
|
|
$Control/ControlComp.visible = show
|
|
|
|
|
|
|
|
func _input(event):
|
2020-07-07 07:40:20 +00:00
|
|
|
if event is InputEventMouseButton and event.pressed and not is_inside and open:
|
|
|
|
open = false
|
2020-07-07 00:47:29 +00:00
|
|
|
$UIAnimation.play("fadeout")
|
2020-07-06 22:00:39 +00:00
|
|
|
|
2020-07-07 16:08:56 +00:00
|
|
|
func _input_event(_viewport, event, _shape_idx):
|
2020-07-06 22:00:39 +00:00
|
|
|
if Engine.editor_hint:
|
|
|
|
return
|
2020-07-07 07:40:20 +00:00
|
|
|
if event is InputEventMouseButton and event.pressed and not open:
|
|
|
|
# Must be in range
|
2020-07-09 14:50:34 +00:00
|
|
|
if activationRange.in_range() and manager.powered:
|
2020-07-07 07:40:20 +00:00
|
|
|
open = true
|
|
|
|
manage_controls(true)
|
|
|
|
$UIAnimation.play("fadein")
|
2020-07-06 22:09:37 +00:00
|
|
|
|
|
|
|
var is_inside = false
|
|
|
|
func _ui_focus_changed(entered):
|
|
|
|
is_inside = entered
|
2020-07-07 00:47:29 +00:00
|
|
|
|
|
|
|
func _ui_fade_completed(anim_name):
|
|
|
|
if anim_name == "fadeout":
|
|
|
|
manage_controls(false)
|
2020-07-07 07:40:20 +00:00
|
|
|
|
|
|
|
func _force_close_ui():
|
|
|
|
if open:
|
|
|
|
open = false
|
|
|
|
$UIAnimation.play("fadeout")
|
2020-07-14 21:28:13 +00:00
|
|
|
match computer_type:
|
|
|
|
ComputerType.ShipCommand:
|
|
|
|
$Control/ControlComp.force_close()
|
2020-07-09 14:50:34 +00:00
|
|
|
|
|
|
|
func _power_status_changed(powered: bool) -> void:
|
2020-07-16 12:37:56 +00:00
|
|
|
print(name, " is ", powered)
|
2020-07-09 14:50:34 +00:00
|
|
|
activationRange.visible = powered
|
|
|
|
if powered:
|
|
|
|
$ScreenAnimation.play("on")
|
|
|
|
else:
|
|
|
|
$ScreenAnimation.play("off")
|
2020-07-13 19:01:36 +00:00
|
|
|
|
|
|
|
func serialize():
|
|
|
|
return {
|
|
|
|
"direction": direction,
|
|
|
|
"computer_type": computer_type
|
|
|
|
}
|
|
|
|
|
|
|
|
func deserialize(data):
|
|
|
|
set_direction(data["direction"])
|
|
|
|
set_type(data["computer_type"])
|