game.notify() creates a popup

This commit is contained in:
blinry 2020-12-22 15:38:43 +01:00
parent 34841c496b
commit cf10605bf4
5 changed files with 74 additions and 8 deletions

View file

@ -49,3 +49,9 @@ func create_file_in_game_env(filename, content):
global_shell.cd(tmp_prefix)
# Quoted HERE doc doesn't do any substitutions inside.
global_shell.run("cat > '%s' <<'HEREHEREHERE'\n%s\nHEREHEREHERE" % [filename, content])
func notify(text):
print(text)
var notification = preload("res://scenes/notification.tscn").instance()
notification.text = text
get_tree().root.call_deferred("add_child", notification)

View file

@ -97,6 +97,7 @@ func load_level(level_id):
terminal.find_node("TextEditor").close()
update_repos()
game.notify("Level loaded!")
# Unmute the audio after a while, so that player can hear pop sounds for
# nodes they create.

14
scenes/notification.gd Normal file
View file

@ -0,0 +1,14 @@
extends PopupPanel
var text setget _set_text
func _ready():
popup()
func _gui_input(event):
if event is InputEventMouseButton:
queue_free()
func _set_text(new_text):
text = new_text
$Label.text = new_text

33
scenes/notification.tscn Normal file
View file

@ -0,0 +1,33 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://styles/theme.tres" type="Theme" id=2]
[ext_resource path="res://scenes/notification.gd" type="Script" id=3]
[node name="Notification" type="PopupPanel"]
visible = true
margin_left = 16.0
margin_top = 16.0
margin_right = 369.0
margin_bottom = 212.0
theme = ExtResource( 2 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
anchor_left = 0.045
anchor_top = 0.082
anchor_right = 0.955
anchor_bottom = 0.918
margin_left = 0.115
margin_top = -0.0720005
margin_right = -0.115021
margin_bottom = 0.071991
custom_fonts/font = ExtResource( 1 )
text = "This is a hint! This is a hint! This is a hint! This is a hint! This is a hint! This is a hint! This is a hint! This is a hint! This is a hint!"
autowrap = true
__meta__ = {
"_edit_use_anchors_": false
}