This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Actors/Objects/Computer/Computer.gd

66 lines
2.0 KiB
GDScript

tool
extends StaticBody2D
enum Direction { LEFT, RIGHT, UP, DOWN }
enum ComputerType { ShipCommand, Comms, Medical, Research, ShipEngine, Atmos }
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
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)
ComputerType.ShipEngine:
screen_region_offset = Vector2(128, 224)
ComputerType.Atmos:
screen_region_offset = Vector2(0, 256)
# Refresh sprite
set_direction(direction)
func set_direction(dir):
direction = dir
match direction:
Direction.DOWN:
$computer.region_rect.position = Vector2(0, 0)
$computer/screen.region_rect.position = screen_region_offset + Vector2(0, 0)
Direction.UP:
$computer.region_rect.position = Vector2(0, 32)
$computer/screen.region_rect.position = screen_region_offset + Vector2(32, 0)
Direction.LEFT:
$computer.region_rect.position = Vector2(32, 32)
$computer/screen.region_rect.position = screen_region_offset + Vector2(96, 0)
Direction.RIGHT:
$computer.region_rect.position = Vector2(32, 0)
$computer/screen.region_rect.position = screen_region_offset + Vector2(64, 0)
func manage_controls(show: bool):
match computer_type:
ComputerType.ShipCommand:
$Control/ControlComp.visible = show
func _input(event):
if event is InputEventMouseButton and event.pressed and not is_inside:
manage_controls(false)
func _input_event(viewport, event, shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
manage_controls(true)
var is_inside = false
func _ui_focus_changed(entered):
print(entered)
is_inside = entered