Add activation range and leave events

This commit is contained in:
Hamcha 2020-07-07 09:40:20 +02:00
parent 996af50648
commit 485de5791b
9 changed files with 110 additions and 27 deletions

View 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")

View File

@ -9,6 +9,9 @@ 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
var open = false
onready var activationRange = $ActivationRange as ActivationRange
func set_type(val):
computer_type = val
@ -52,22 +55,30 @@ func manage_controls(show: bool):
$Control/ControlComp.visible = show
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")
func _input_event(viewport, event, shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
manage_controls(true)
$UIAnimation.play("fadein")
if event is InputEventMouseButton and event.pressed and not open:
# Must be in range
if activationRange.in_range():
open = true
manage_controls(true)
$UIAnimation.play("fadein")
var is_inside = false
func _ui_focus_changed(entered):
print(entered)
is_inside = entered
func _ui_fade_completed(anim_name):
if anim_name == "fadeout":
manage_controls(false)
func _force_close_ui():
if open:
open = false
$UIAnimation.play("fadeout")

View File

@ -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.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/UI/ControlComp.tscn" type="PackedScene" id=4]
[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]
blend_mode = 1
@ -94,6 +95,9 @@ tracks/1/keys = {
"times": PoolRealArray( 0, 0.2 )
}
[sub_resource type="RectangleShape2D" id=7]
extents = Vector2( 48, 48 )
[node name="Computer" type="StaticBody2D"]
input_pickable = true
script = ExtResource( 3 )
@ -140,6 +144,14 @@ margin_top = -72.3908
margin_right = 166.574
margin_bottom = 59.6092
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="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="player_left" from="ActivationRange" to="." method="_force_close_ui"]

View File

@ -1,7 +1,12 @@
extends StaticBody2D
onready var activationRange = $ActivationRange as ActivationRange
signal changed(open)
func _ready():
activationRange.visible = true
func set_open(open: bool):
if open:
$Sprite.play("open")
@ -21,10 +26,11 @@ func _animation_finished():
collision_layer = 1
func _input_event(viewport, event, shape_idx):
# Check if we clicked the item
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():
$Sprite.play("close")

View File

@ -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://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]
atlas = ExtResource( 2 )
@ -39,6 +40,9 @@ animations = [ {
[sub_resource type="RectangleShape2D" id=7]
extents = Vector2( 16, 16 )
[sub_resource type="CircleShape2D" id=8]
radius = 64.0
[node name="Door" type="StaticBody2D"]
input_pickable = true
script = ExtResource( 1 )
@ -57,5 +61,13 @@ shape = SubResource( 7 )
[node name="Timer" type="Timer" parent="."]
wait_time = 5.0
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="timeout" from="Timer" to="." method="_close_timer_triggered"]

View File

@ -5,9 +5,10 @@ extends Area2D
enum Direction { LEFT, RIGHT, UP, DOWN }
export(Direction) var direction = Direction.DOWN setget set_direction
export var lit = true setget set_lit
onready var activationRange = $ActivationRange as ActivationRange
func _ready():
$Light2D.set_meta("_edit_lock_", true)
@ -21,26 +22,30 @@ func set_lit(val):
refresh_sprite()
func refresh_sprite():
var rot = 0
var lit_offset = 0
if not lit:
lit_offset = 32
match direction:
Direction.DOWN:
$light.region_rect.position = Vector2(32, lit_offset)
$Light2D.rotation = 0
rot =0
Direction.UP:
$light.region_rect.position = Vector2(0, lit_offset)
$Light2D.rotation = PI
rot = PI
Direction.LEFT:
$light.region_rect.position = Vector2(96, lit_offset)
$Light2D.rotation = -PI/2
rot = -PI/2
Direction.RIGHT:
$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):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed:
set_lit(!lit)
if activationRange.in_range():
set_lit(!lit)

View File

@ -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://Actors/Lightbulb/Lightbulb.gd" type="Script" id=2]
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=3]
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=1]
[ext_resource path="res://Graphics/tgstation/light.png" type="Texture" id=2]
[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]
extents = Vector2( 16, 16 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 48, 32 )
[node name="Lighttube" type="Area2D"]
script = ExtResource( 2 )
script = ExtResource( 3 )
[node name="light" type="Sprite" parent="."]
texture = ExtResource( 1 )
texture = ExtResource( 2 )
region_enabled = true
region_rect = Rect2( 32, 0, 32, 32 )
[node name="Light2D" type="Light2D" parent="."]
texture = ExtResource( 3 )
texture = ExtResource( 1 )
offset = Vector2( 0, -10 )
texture_scale = 4.0
energy = 1.2
@ -32,3 +36,10 @@ __meta__ = {
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
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 )

View File

@ -7,7 +7,7 @@
[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://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]
light_mode = 1
@ -17,7 +17,6 @@ script = ExtResource( 5 )
tilemap_path = NodePath("2x2")
[node name="CanvasModulate" type="CanvasModulate" parent="."]
visible = false
color = Color( 0, 0, 0, 1 )
__meta__ = {
"_edit_group_": true,
@ -69,6 +68,7 @@ position = Vector2( 192, 384 )
[node name="ControlComp" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 576, 256 )
direction = 0
computer_type = 0
[node name="CommsComp" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 576, 224 )
@ -76,7 +76,6 @@ direction = 0
computer_type = 1
[node name="lights" type="Node2D" parent="."]
visible = false
__meta__ = {
"_edit_group_": true,
"_edit_lock_": true

View File

@ -9,6 +9,11 @@
config_version=4
_global_script_classes=[ {
"base": "Area2D",
"class": "ActivationRange",
"language": "GDScript",
"path": "res://Actors/Components/ActivationRange.gd"
}, {
"base": "Node",
"class": "GameInstance",
"language": "GDScript",
@ -45,6 +50,7 @@ _global_script_classes=[ {
"path": "res://Classes/UICommand.gd"
} ]
_global_script_class_icons={
"ActivationRange": "",
"GameInstance": "",
"GameUI": "",
"GameWorld": "",