Skip to content

Commit

Permalink
Finally restored what we had working two days ago.
Browse files Browse the repository at this point in the history
Got caught in
godotengine/godot#17326, had to stop using ViewportContainer entirely. Means other hacks (mainly size/positioning in code) but it works
  • Loading branch information
epw committed Dec 29, 2020
1 parent 86e505e commit ce262c7
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 68 deletions.
20 changes: 20 additions & 0 deletions CenterContainer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends CenterContainer


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass


func _on_CenterContainer_mouse_entered():
print("_on_CenterContainer_mouse_entered")
6 changes: 6 additions & 0 deletions Control.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ margin_bottom = 40.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CenterContainer" type="CenterContainer" parent="."]
margin_right = 40.0
margin_bottom = 40.0

[node name="Node2D" type="Node2D" parent="CenterContainer"]
1 change: 1 addition & 0 deletions DialogueButton.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene format=2]

[node name="DialogueButton" type="Button"]
light_mask = 2
margin_right = 12.0
margin_bottom = 20.0
__meta__ = {
Expand Down
2 changes: 1 addition & 1 deletion HUD.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Control
extends Node2D

signal open_student

Expand Down
7 changes: 1 addition & 6 deletions HUD.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ size = 32
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 1 )

[node name="HUD" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="HUD" type="Node2D"]
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="StarMessage" type="RichTextLabel" parent="."]
anchor_top = 1.0
Expand Down
34 changes: 22 additions & 12 deletions Main.gd
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
extends Control
extends Node2D

export (PackedScene) var Student

var HUD
var message_has_mouse = false

func _ready():
HUD = $CenterContainer/MarginContainer/HUD

$HUD/StarMessage.rect_size = Vector2(1024, 128)
$HUD/StarMessage.rect_position = Vector2(0, 768 - $HUD/StarMessage.rect_size.y)

func _process(_delta):
if Input.is_action_pressed("ui_cancel"):
get_tree().quit()
if Input.is_action_just_pressed("ui_accept"):
if not HUD.message_has_mouse:
if not message_has_mouse:
show_message("")

if Input.is_action_just_pressed("ui_right"):
open_student()

func _on_Sky_star_message(message):
print("_on_Star_send_message", message)
# if obscured:
# return
show_message(message)

func show_message(msg):
HUD.show_message(msg)

func _on_HUD_open_student():
func open_student():
print("_on_HUD_open_student")
# obscured = true
show_message("")
var student = Student.instance()
add_child(student)
student.rect_size = Vector2(1024, 768)
student.connect("close", self, "_on_Student_close")

func _on_Student_close():
print("_on_Student_close")
remove_child($Student)
# obscured = false

func show_message(msg):
$HUD/StarMessage.scroll_to_line(0)
$HUD/StarMessage.text = ""
$HUD/StarMessage.append_bbcode("[center]" + msg + "[/center]")

func _on_StarMessage_mouse_entered():
message_has_mouse = true

func _on_StarMessage_mouse_exited():
message_has_mouse = false
65 changes: 27 additions & 38 deletions Main.tscn
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://Sky.tscn" type="PackedScene" id=1]
[ext_resource path="res://HUD.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/ilsscrp.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://Main.gd" type="Script" id=3]
[ext_resource path="res://Student.tscn" type="PackedScene" id=4]

[node name="Main" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
[sub_resource type="DynamicFont" id=1]
size = 40
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 2 )

[node name="Main" type="Node2D"]
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
Student = ExtResource( 4 )

[node name="Sky" parent="." instance=ExtResource( 1 )]

[node name="HUD" type="Node2D" parent="."]

[node name="CenterContainer" type="CenterContainer" parent="."]
margin_right = 40.0
margin_bottom = 40.0
mouse_filter = 2
[node name="StarMessage" type="RichTextLabel" parent="HUD"]
light_mask = 2
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
focus_mode = 2
custom_fonts/normal_font = SubResource( 1 )
custom_colors/default_color = Color( 1, 1, 1, 1 )
custom_colors/selection_color = Color( 1, 1, 0.466667, 1 )
selection_enabled = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ViewportContainer" type="ViewportContainer" parent="CenterContainer"]
margin_right = 1024.0
margin_bottom = 768.0
mouse_filter = 1

[node name="Viewport" type="Viewport" parent="CenterContainer/ViewportContainer"]
size = Vector2( 1024, 768 )
handle_input_locally = false
render_target_update_mode = 3

[node name="Sky" parent="CenterContainer/ViewportContainer/Viewport" instance=ExtResource( 1 )]

[node name="MarginContainer" type="MarginContainer" parent="CenterContainer"]
margin_left = 512.0
margin_top = 384.0
margin_right = 512.0
margin_bottom = 384.0
mouse_filter = 2

[node name="HUD" parent="CenterContainer/MarginContainer" instance=ExtResource( 2 )]
anchor_right = 0.0
anchor_bottom = 0.0
mouse_filter = 2
[connection signal="star_message" from="CenterContainer/ViewportContainer/Viewport/Sky" to="." method="_on_Sky_star_message"]
[connection signal="star_message" from="Sky" to="." method="_on_Sky_star_message"]
[connection signal="mouse_entered" from="HUD/StarMessage" to="." method="_on_StarMessage_mouse_entered"]
[connection signal="mouse_exited" from="HUD/StarMessage" to="." method="_on_StarMessage_mouse_exited"]
14 changes: 14 additions & 0 deletions RootViewport.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://Viewport.gd" type="Script" id=1]
[ext_resource path="res://Sky.tscn" type="PackedScene" id=3]

[node name="Viewport" type="Viewport"]
size = Vector2( 1024, 768 )
handle_input_locally = false
render_target_update_mode = 3
physics_object_picking = true
gui_disable_input = true
script = ExtResource( 1 )

[node name="Sky" parent="." instance=ExtResource( 3 )]
1 change: 0 additions & 1 deletion Sky.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ func _ready():

func _on_Star_send_message(star):
emit_signal("star_message", star.message)

20 changes: 10 additions & 10 deletions Sky.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
[ext_resource path="res://Sky.gd" type="Script" id=3]
[ext_resource path="res://CanvasLayer.gd" type="Script" id=6]

[sub_resource type="CircleShape2D" id=6]
[sub_resource type="CircleShape2D" id=1]
radius = 30.9577

[sub_resource type="CircleShape2D" id=7]
[sub_resource type="CircleShape2D" id=2]
radius = 46.4871

[sub_resource type="ViewportTexture" id=5]
[sub_resource type="ViewportTexture" id=3]
viewport_path = NodePath("StarViewport")

[node name="Sky" type="Node2D"]
script = ExtResource( 3 )

[node name="Background" type="Sprite" parent="."]
position = Vector2( 583.328, 388.202 )
scale = Vector2( 1.45447, 1.45447 )
position = Vector2( 512.219, 340.826 )
scale = Vector2( 1.2767, 1.2767 )
texture = ExtResource( 1 )

[node name="StarViewport" type="Viewport" parent="."]
Expand All @@ -36,22 +36,22 @@ script = ExtResource( 6 )
[node name="Stars" type="Node2D" parent="."]

[node name="StarSpot" parent="Stars" instance=ExtResource( 2 )]
position = Vector2( 603.869, 140.007 )
position = Vector2( 602.455, 161.22 )

[node name="CollisionShape2D" parent="Stars/StarSpot" index="0"]
shape = SubResource( 6 )
shape = SubResource( 1 )

[node name="StarSpot2" parent="Stars" instance=ExtResource( 2 )]
position = Vector2( 516.188, 231.931 )
position = Vector2( 448.306, 207.889 )
message = "The first comet after the flood was a cause of panic. It seemed that the hubris of returning to the valley was about to lead to destruction by flood again. I saw the people reach out, desperate for anything to save them. One man found one of my cousins, falling towards him as he strove. Their lives joined, and the new Sorcerer-King told the fearful he had banished the waters and demanded their allegiance."

[node name="CollisionShape2D" parent="Stars/StarSpot2" index="0"]
shape = SubResource( 7 )
shape = SubResource( 2 )

[node name="StarMask" type="Light2D" parent="."]
visible = false
position = Vector2( 513.359, 386.08 )
texture = SubResource( 5 )
texture = SubResource( 3 )
mode = 3

[editable path="Stars/StarSpot"]
Expand Down
7 changes: 7 additions & 0 deletions StarSpot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var highlight = null
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
set_process_unhandled_input(true)
highlight = Color.from_hsv(randf(), 0.6, 1, 1)

if get_parent():
Expand All @@ -33,3 +34,9 @@ func _on_StarSpot_mouse_entered():
func _on_StarSpot_mouse_exited():
modulate = initial_modulation
pointed_at = false

#func _input(event):
# print("Star Spot event: ", event)

#func _unhandled_input(event):
# print("Star Spot unhandled event: ", event)
4 changes: 4 additions & 0 deletions Student.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ size = 32
font_data = ExtResource( 3 )

[node name="Student" type="MarginContainer"]
light_mask = -2147483646
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = 6.10352e-05
Expand All @@ -21,6 +22,7 @@ __meta__ = {
Button = ExtResource( 4 )

[node name="ColorRect" type="ColorRect" parent="."]
light_mask = 2
margin_right = 1024.0
margin_bottom = 768.0
color = Color( 0.145098, 0.129412, 0.0196078, 1 )
Expand All @@ -29,10 +31,12 @@ color = Color( 0.145098, 0.129412, 0.0196078, 1 )
dialog_file = "res://student.json"

[node name="VBoxContainer" type="VBoxContainer" parent="."]
light_mask = 2
margin_right = 1024.0
margin_bottom = 768.0

[node name="RichTextLabel" type="RichTextLabel" parent="VBoxContainer"]
light_mask = 2
margin_right = 1024.0
margin_bottom = 768.0
focus_mode = 2
Expand Down
12 changes: 12 additions & 0 deletions Viewport.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Viewport


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

func _ready():
pass
# set_process_input(true)
# set_process_unhandled_input(true)

17 changes: 17 additions & 0 deletions ViewportContainer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends ViewportContainer


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

func _on_ViewportContainer_mouse_entered():
print("_on_ViewportContainer_mouse_entered")

func _input( event ):
if event is InputEventMouse:
var mouseEvent = event.duplicate()
mouseEvent.position = get_global_transform().xform_inv(event.global_position)
$Viewport.unhandled_input(mouseEvent)
else:
$Viewport.unhandled_input(event)

0 comments on commit ce262c7

Please sign in to comment.