Add activation range and leave events
This commit is contained in:
parent
996af50648
commit
485de5791b
9 changed files with 110 additions and 27 deletions
21
Actors/Components/ActivationRange.gd
Normal file
21
Actors/Components/ActivationRange.gd
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
class_name ActivationRange
|
||||||
|
|
||||||
|
signal player_entered()
|
||||||
|
signal player_left()
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
connect("body_entered", self, "_body_entered")
|
||||||
|
connect("body_exited", self, "_body_left")
|
||||||
|
|
||||||
|
func in_range():
|
||||||
|
return overlaps_body($"/root/scene/world".player)
|
||||||
|
|
||||||
|
func _body_entered(body: Node):
|
||||||
|
if body == $"/root/scene/world".player:
|
||||||
|
emit_signal("player_entered")
|
||||||
|
|
||||||
|
func _body_left(body: Node):
|
||||||
|
if body == $"/root/scene/world".player:
|
||||||
|
emit_signal("player_left")
|
|
@ -9,6 +9,9 @@ export(Direction) var direction = Direction.DOWN setget set_direction
|
||||||
export(ComputerType) var computer_type = ComputerType.ShipCommand setget set_type
|
export(ComputerType) var computer_type = ComputerType.ShipCommand setget set_type
|
||||||
|
|
||||||
var screen_region_offset = Vector2.ZERO
|
var screen_region_offset = Vector2.ZERO
|
||||||
|
var open = false
|
||||||
|
|
||||||
|
onready var activationRange = $ActivationRange as ActivationRange
|
||||||
|
|
||||||
func set_type(val):
|
func set_type(val):
|
||||||
computer_type = val
|
computer_type = val
|
||||||
|
@ -52,22 +55,30 @@ func manage_controls(show: bool):
|
||||||
$Control/ControlComp.visible = show
|
$Control/ControlComp.visible = show
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event is InputEventMouseButton and event.pressed and not is_inside:
|
if event is InputEventMouseButton and event.pressed and not is_inside and open:
|
||||||
|
open = false
|
||||||
$UIAnimation.play("fadeout")
|
$UIAnimation.play("fadeout")
|
||||||
|
|
||||||
func _input_event(viewport, event, shape_idx):
|
func _input_event(viewport, event, shape_idx):
|
||||||
if Engine.editor_hint:
|
if Engine.editor_hint:
|
||||||
return
|
return
|
||||||
if event is InputEventMouseButton and event.pressed:
|
if event is InputEventMouseButton and event.pressed and not open:
|
||||||
manage_controls(true)
|
# Must be in range
|
||||||
$UIAnimation.play("fadein")
|
if activationRange.in_range():
|
||||||
|
open = true
|
||||||
|
manage_controls(true)
|
||||||
|
$UIAnimation.play("fadein")
|
||||||
|
|
||||||
var is_inside = false
|
var is_inside = false
|
||||||
func _ui_focus_changed(entered):
|
func _ui_focus_changed(entered):
|
||||||
print(entered)
|
|
||||||
is_inside = entered
|
is_inside = entered
|
||||||
|
|
||||||
|
|
||||||
func _ui_fade_completed(anim_name):
|
func _ui_fade_completed(anim_name):
|
||||||
if anim_name == "fadeout":
|
if anim_name == "fadeout":
|
||||||
manage_controls(false)
|
manage_controls(false)
|
||||||
|
|
||||||
|
|
||||||
|
func _force_close_ui():
|
||||||
|
if open:
|
||||||
|
open = false
|
||||||
|
$UIAnimation.play("fadeout")
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
[gd_scene load_steps=12 format=2]
|
[gd_scene load_steps=14 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Graphics/tgstation/computer-screens.png" type="Texture" id=1]
|
[ext_resource path="res://Graphics/tgstation/computer-screens.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Graphics/tgstation/computer.png" type="Texture" id=2]
|
[ext_resource path="res://Graphics/tgstation/computer.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://Actors/Objects/Computer/Computer.gd" type="Script" id=3]
|
[ext_resource path="res://Actors/Objects/Computer/Computer.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://Actors/Objects/Computer/UI/ControlComp.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://Actors/Objects/Computer/UI/ControlComp.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=5]
|
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=5]
|
||||||
|
[ext_resource path="res://Actors/Components/ActivationRange.gd" type="Script" id=6]
|
||||||
|
|
||||||
[sub_resource type="CanvasItemMaterial" id=1]
|
[sub_resource type="CanvasItemMaterial" id=1]
|
||||||
blend_mode = 1
|
blend_mode = 1
|
||||||
|
@ -94,6 +95,9 @@ tracks/1/keys = {
|
||||||
"times": PoolRealArray( 0, 0.2 )
|
"times": PoolRealArray( 0, 0.2 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=7]
|
||||||
|
extents = Vector2( 48, 48 )
|
||||||
|
|
||||||
[node name="Computer" type="StaticBody2D"]
|
[node name="Computer" type="StaticBody2D"]
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
@ -140,6 +144,14 @@ margin_top = -72.3908
|
||||||
margin_right = 166.574
|
margin_right = 166.574
|
||||||
margin_bottom = 59.6092
|
margin_bottom = 59.6092
|
||||||
rect_scale = Vector2( 0.5, 0.5 )
|
rect_scale = Vector2( 0.5, 0.5 )
|
||||||
|
|
||||||
|
[node name="ActivationRange" type="Area2D" parent="."]
|
||||||
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="ActivationRange"]
|
||||||
|
position = Vector2( 16, 16 )
|
||||||
|
shape = SubResource( 7 )
|
||||||
[connection signal="animation_finished" from="UIAnimation" to="." method="_ui_fade_completed"]
|
[connection signal="animation_finished" from="UIAnimation" to="." method="_ui_fade_completed"]
|
||||||
[connection signal="mouse_entered" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ true ]]
|
[connection signal="mouse_entered" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ true ]]
|
||||||
[connection signal="mouse_exited" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ false ]]
|
[connection signal="mouse_exited" from="Control/ControlComp" to="." method="_ui_focus_changed" binds= [ false ]]
|
||||||
|
[connection signal="player_left" from="ActivationRange" to="." method="_force_close_ui"]
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
onready var activationRange = $ActivationRange as ActivationRange
|
||||||
|
|
||||||
signal changed(open)
|
signal changed(open)
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
activationRange.visible = true
|
||||||
|
|
||||||
func set_open(open: bool):
|
func set_open(open: bool):
|
||||||
if open:
|
if open:
|
||||||
$Sprite.play("open")
|
$Sprite.play("open")
|
||||||
|
@ -21,10 +26,11 @@ func _animation_finished():
|
||||||
collision_layer = 1
|
collision_layer = 1
|
||||||
|
|
||||||
func _input_event(viewport, event, shape_idx):
|
func _input_event(viewport, event, shape_idx):
|
||||||
|
# Check if we clicked the item
|
||||||
if event is InputEventMouseButton and event.pressed:
|
if event is InputEventMouseButton and event.pressed:
|
||||||
set_open($Sprite.animation == "close")
|
# Must be in activation range
|
||||||
|
if activationRange.in_range():
|
||||||
|
set_open($Sprite.animation == "close")
|
||||||
|
|
||||||
func _close_timer_triggered():
|
func _close_timer_triggered():
|
||||||
$Sprite.play("close")
|
$Sprite.play("close")
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=10 format=2]
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Actors/Objects/Door/Door.gd" type="Script" id=1]
|
[ext_resource path="res://Actors/Objects/Door/Door.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Graphics/tgstation/opening-sheet.png" type="Texture" id=2]
|
[ext_resource path="res://Graphics/tgstation/opening-sheet.png" type="Texture" id=2]
|
||||||
|
[ext_resource path="res://Actors/Components/ActivationRange.gd" type="Script" id=3]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=1]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 2 )
|
atlas = ExtResource( 2 )
|
||||||
|
@ -39,6 +40,9 @@ animations = [ {
|
||||||
[sub_resource type="RectangleShape2D" id=7]
|
[sub_resource type="RectangleShape2D" id=7]
|
||||||
extents = Vector2( 16, 16 )
|
extents = Vector2( 16, 16 )
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id=8]
|
||||||
|
radius = 64.0
|
||||||
|
|
||||||
[node name="Door" type="StaticBody2D"]
|
[node name="Door" type="StaticBody2D"]
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
@ -57,5 +61,13 @@ shape = SubResource( 7 )
|
||||||
[node name="Timer" type="Timer" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
wait_time = 5.0
|
wait_time = 5.0
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="ActivationRange" type="Area2D" parent="."]
|
||||||
|
visible = false
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="ActivationRange"]
|
||||||
|
position = Vector2( 16, 16 )
|
||||||
|
shape = SubResource( 8 )
|
||||||
[connection signal="animation_finished" from="Sprite" to="." method="_animation_finished"]
|
[connection signal="animation_finished" from="Sprite" to="." method="_animation_finished"]
|
||||||
[connection signal="timeout" from="Timer" to="." method="_close_timer_triggered"]
|
[connection signal="timeout" from="Timer" to="." method="_close_timer_triggered"]
|
||||||
|
|
|
@ -5,9 +5,10 @@ extends Area2D
|
||||||
enum Direction { LEFT, RIGHT, UP, DOWN }
|
enum Direction { LEFT, RIGHT, UP, DOWN }
|
||||||
|
|
||||||
export(Direction) var direction = Direction.DOWN setget set_direction
|
export(Direction) var direction = Direction.DOWN setget set_direction
|
||||||
|
|
||||||
export var lit = true setget set_lit
|
export var lit = true setget set_lit
|
||||||
|
|
||||||
|
onready var activationRange = $ActivationRange as ActivationRange
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$Light2D.set_meta("_edit_lock_", true)
|
$Light2D.set_meta("_edit_lock_", true)
|
||||||
|
|
||||||
|
@ -21,26 +22,30 @@ func set_lit(val):
|
||||||
refresh_sprite()
|
refresh_sprite()
|
||||||
|
|
||||||
func refresh_sprite():
|
func refresh_sprite():
|
||||||
|
var rot = 0
|
||||||
var lit_offset = 0
|
var lit_offset = 0
|
||||||
if not lit:
|
if not lit:
|
||||||
lit_offset = 32
|
lit_offset = 32
|
||||||
match direction:
|
match direction:
|
||||||
Direction.DOWN:
|
Direction.DOWN:
|
||||||
$light.region_rect.position = Vector2(32, lit_offset)
|
$light.region_rect.position = Vector2(32, lit_offset)
|
||||||
$Light2D.rotation = 0
|
rot =0
|
||||||
Direction.UP:
|
Direction.UP:
|
||||||
$light.region_rect.position = Vector2(0, lit_offset)
|
$light.region_rect.position = Vector2(0, lit_offset)
|
||||||
$Light2D.rotation = PI
|
rot = PI
|
||||||
Direction.LEFT:
|
Direction.LEFT:
|
||||||
$light.region_rect.position = Vector2(96, lit_offset)
|
$light.region_rect.position = Vector2(96, lit_offset)
|
||||||
$Light2D.rotation = -PI/2
|
rot = -PI/2
|
||||||
Direction.RIGHT:
|
Direction.RIGHT:
|
||||||
$light.region_rect.position = Vector2(64, lit_offset)
|
$light.region_rect.position = Vector2(64, lit_offset)
|
||||||
$Light2D.rotation = PI/2
|
rot = PI/2
|
||||||
|
$Light2D.rotation = rot
|
||||||
|
$ActivationRange.rotation = rot
|
||||||
|
|
||||||
|
|
||||||
func _input_event(viewport, event, shape_idx):
|
func _input_event(viewport, event, shape_idx):
|
||||||
if Engine.editor_hint:
|
if Engine.editor_hint:
|
||||||
return
|
return
|
||||||
if event is InputEventMouseButton and event.pressed:
|
if event is InputEventMouseButton and event.pressed:
|
||||||
set_lit(!lit)
|
if activationRange.in_range():
|
||||||
|
set_lit(!lit)
|
|
@ -1,22 +1,26 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Graphics/tgstation/light.png" type="Texture" id=1]
|
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Actors/Lightbulb/Lightbulb.gd" type="Script" id=2]
|
[ext_resource path="res://Graphics/tgstation/light.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=3]
|
[ext_resource path="res://Actors/Objects/Lightbulb/Lightbulb.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://Actors/Components/ActivationRange.gd" type="Script" id=4]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
extents = Vector2( 16, 16 )
|
extents = Vector2( 16, 16 )
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=2]
|
||||||
|
extents = Vector2( 48, 32 )
|
||||||
|
|
||||||
[node name="Lighttube" type="Area2D"]
|
[node name="Lighttube" type="Area2D"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="light" type="Sprite" parent="."]
|
[node name="light" type="Sprite" parent="."]
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 2 )
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
region_rect = Rect2( 32, 0, 32, 32 )
|
region_rect = Rect2( 32, 0, 32, 32 )
|
||||||
|
|
||||||
[node name="Light2D" type="Light2D" parent="."]
|
[node name="Light2D" type="Light2D" parent="."]
|
||||||
texture = ExtResource( 3 )
|
texture = ExtResource( 1 )
|
||||||
offset = Vector2( 0, -10 )
|
offset = Vector2( 0, -10 )
|
||||||
texture_scale = 4.0
|
texture_scale = 4.0
|
||||||
energy = 1.2
|
energy = 1.2
|
||||||
|
@ -32,3 +36,10 @@ __meta__ = {
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[node name="ActivationRange" type="Area2D" parent="."]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="ActivationRange"]
|
||||||
|
position = Vector2( 0, 16 )
|
||||||
|
shape = SubResource( 2 )
|
|
@ -7,7 +7,7 @@
|
||||||
[ext_resource path="res://Scenes/Map.gd" type="Script" id=5]
|
[ext_resource path="res://Scenes/Map.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://Actors/Objects/Computer/Computer.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://Actors/Objects/Computer/Computer.tscn" type="PackedScene" id=6]
|
||||||
[ext_resource path="res://Graphics/space.png" type="Texture" id=7]
|
[ext_resource path="res://Graphics/space.png" type="Texture" id=7]
|
||||||
[ext_resource path="res://Actors/Lightbulb/Lightbulb.tscn" type="PackedScene" id=8]
|
[ext_resource path="res://Actors/Objects/Lightbulb/Lightbulb.tscn" type="PackedScene" id=8]
|
||||||
|
|
||||||
[sub_resource type="CanvasItemMaterial" id=1]
|
[sub_resource type="CanvasItemMaterial" id=1]
|
||||||
light_mode = 1
|
light_mode = 1
|
||||||
|
@ -17,7 +17,6 @@ script = ExtResource( 5 )
|
||||||
tilemap_path = NodePath("2x2")
|
tilemap_path = NodePath("2x2")
|
||||||
|
|
||||||
[node name="CanvasModulate" type="CanvasModulate" parent="."]
|
[node name="CanvasModulate" type="CanvasModulate" parent="."]
|
||||||
visible = false
|
|
||||||
color = Color( 0, 0, 0, 1 )
|
color = Color( 0, 0, 0, 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_group_": true,
|
"_edit_group_": true,
|
||||||
|
@ -69,6 +68,7 @@ position = Vector2( 192, 384 )
|
||||||
[node name="ControlComp" parent="objects" instance=ExtResource( 6 )]
|
[node name="ControlComp" parent="objects" instance=ExtResource( 6 )]
|
||||||
position = Vector2( 576, 256 )
|
position = Vector2( 576, 256 )
|
||||||
direction = 0
|
direction = 0
|
||||||
|
computer_type = 0
|
||||||
|
|
||||||
[node name="CommsComp" parent="objects" instance=ExtResource( 6 )]
|
[node name="CommsComp" parent="objects" instance=ExtResource( 6 )]
|
||||||
position = Vector2( 576, 224 )
|
position = Vector2( 576, 224 )
|
||||||
|
@ -76,7 +76,6 @@ direction = 0
|
||||||
computer_type = 1
|
computer_type = 1
|
||||||
|
|
||||||
[node name="lights" type="Node2D" parent="."]
|
[node name="lights" type="Node2D" parent="."]
|
||||||
visible = false
|
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_group_": true,
|
"_edit_group_": true,
|
||||||
"_edit_lock_": true
|
"_edit_lock_": true
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
config_version=4
|
config_version=4
|
||||||
|
|
||||||
_global_script_classes=[ {
|
_global_script_classes=[ {
|
||||||
|
"base": "Area2D",
|
||||||
|
"class": "ActivationRange",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Actors/Components/ActivationRange.gd"
|
||||||
|
}, {
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "GameInstance",
|
"class": "GameInstance",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
@ -45,6 +50,7 @@ _global_script_classes=[ {
|
||||||
"path": "res://Classes/UICommand.gd"
|
"path": "res://Classes/UICommand.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
|
"ActivationRange": "",
|
||||||
"GameInstance": "",
|
"GameInstance": "",
|
||||||
"GameUI": "",
|
"GameUI": "",
|
||||||
"GameWorld": "",
|
"GameWorld": "",
|
||||||
|
|
Reference in a new issue