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) global_shell.cd(tmp_prefix)
# Quoted HERE doc doesn't do any substitutions inside. # Quoted HERE doc doesn't do any substitutions inside.
global_shell.run("cat > '%s' <<'HEREHEREHERE'\n%s\nHEREHEREHERE" % [filename, content]) 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() terminal.find_node("TextEditor").close()
update_repos() update_repos()
game.notify("Level loaded!")
# Unmute the audio after a while, so that player can hear pop sounds for # Unmute the audio after a while, so that player can hear pop sounds for
# nodes they create. # 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
}

View file

@ -1,4 +1,4 @@
[gd_resource type="Theme" load_steps=24 format=2] [gd_resource type="Theme" load_steps=25 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://fonts/monospace.tres" type="DynamicFont" id=2] [ext_resource path="res://fonts/monospace.tres" type="DynamicFont" id=2]
@ -131,6 +131,17 @@ corner_radius_bottom_right = 5
corner_radius_bottom_left = 5 corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id=18] [sub_resource type="StyleBoxFlat" id=18]
content_margin_left = 0.0
content_margin_right = 0.0
content_margin_top = 0.0
content_margin_bottom = 0.0
bg_color = Color( 0.027451, 0.34902, 0.141176, 0.745098 )
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
[sub_resource type="StyleBoxFlat" id=19]
content_margin_left = 5.0 content_margin_left = 5.0
content_margin_right = 5.0 content_margin_right = 5.0
content_margin_top = 10.0 content_margin_top = 10.0
@ -146,7 +157,7 @@ corner_radius_top_right = 10
corner_radius_bottom_right = 10 corner_radius_bottom_right = 10
corner_radius_bottom_left = 10 corner_radius_bottom_left = 10
[sub_resource type="StyleBoxFlat" id=19] [sub_resource type="StyleBoxFlat" id=20]
content_margin_left = 5.0 content_margin_left = 5.0
content_margin_right = 5.0 content_margin_right = 5.0
content_margin_top = 5.0 content_margin_top = 5.0
@ -157,7 +168,7 @@ corner_radius_top_right = 10
corner_radius_bottom_right = 10 corner_radius_bottom_right = 10
corner_radius_bottom_left = 10 corner_radius_bottom_left = 10
[sub_resource type="StyleBoxFlat" id=20] [sub_resource type="StyleBoxFlat" id=21]
content_margin_left = 5.0 content_margin_left = 5.0
content_margin_right = 5.0 content_margin_right = 5.0
content_margin_top = 5.0 content_margin_top = 5.0
@ -168,7 +179,7 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5 corner_radius_bottom_right = 5
corner_radius_bottom_left = 5 corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id=21] [sub_resource type="StyleBoxFlat" id=22]
bg_color = Color( 0.309804, 0.317647, 0.372549, 1 ) bg_color = Color( 0.309804, 0.317647, 0.372549, 1 )
corner_radius_top_left = 5 corner_radius_top_left = 5
corner_radius_top_right = 5 corner_radius_top_right = 5
@ -239,6 +250,7 @@ PopupMenu/styles/labeled_separator_right = null
PopupMenu/styles/panel = SubResource( 17 ) PopupMenu/styles/panel = SubResource( 17 )
PopupMenu/styles/panel_disabled = null PopupMenu/styles/panel_disabled = null
PopupMenu/styles/separator = null PopupMenu/styles/separator = null
PopupPanel/styles/panel = SubResource( 18 )
RichTextLabel/colors/default_color = Color( 1, 1, 1, 1 ) RichTextLabel/colors/default_color = Color( 1, 1, 1, 1 )
RichTextLabel/colors/font_color_selected = Color( 0.49, 0.49, 0.49, 1 ) RichTextLabel/colors/font_color_selected = Color( 0.49, 0.49, 0.49, 1 )
RichTextLabel/colors/font_color_shadow = Color( 0, 0, 0, 0 ) RichTextLabel/colors/font_color_shadow = Color( 0, 0, 0, 0 )
@ -292,8 +304,8 @@ TextEdit/icons/folded = null
TextEdit/icons/space = null TextEdit/icons/space = null
TextEdit/icons/tab = null TextEdit/icons/tab = null
TextEdit/styles/completion = null TextEdit/styles/completion = null
TextEdit/styles/focus = SubResource( 18 ) TextEdit/styles/focus = SubResource( 19 )
TextEdit/styles/normal = SubResource( 19 ) TextEdit/styles/normal = SubResource( 20 )
TextEdit/styles/read_only = null TextEdit/styles/read_only = null
Tree/colors/custom_button_font_highlight = Color( 0.94, 0.94, 0.94, 1 ) Tree/colors/custom_button_font_highlight = Color( 0.94, 0.94, 0.94, 1 )
Tree/colors/drop_position_color = Color( 1, 0.3, 0.2, 1 ) Tree/colors/drop_position_color = Color( 1, 0.3, 0.2, 1 )
@ -318,7 +330,7 @@ Tree/icons/checked = null
Tree/icons/select_arrow = null Tree/icons/select_arrow = null
Tree/icons/unchecked = null Tree/icons/unchecked = null
Tree/icons/updown = null Tree/icons/updown = null
Tree/styles/bg = SubResource( 20 ) Tree/styles/bg = SubResource( 21 )
Tree/styles/bg_focus = null Tree/styles/bg_focus = null
Tree/styles/button_pressed = null Tree/styles/button_pressed = null
Tree/styles/cursor = null Tree/styles/cursor = null
@ -326,7 +338,7 @@ Tree/styles/cursor_unfocused = null
Tree/styles/custom_button = null Tree/styles/custom_button = null
Tree/styles/custom_button_hover = null Tree/styles/custom_button_hover = null
Tree/styles/custom_button_pressed = null Tree/styles/custom_button_pressed = null
Tree/styles/selected = SubResource( 21 ) Tree/styles/selected = SubResource( 22 )
Tree/styles/selected_focus = null Tree/styles/selected_focus = null
Tree/styles/title_button_hover = null Tree/styles/title_button_hover = null
Tree/styles/title_button_normal = null Tree/styles/title_button_normal = null