Skip to content

Commit

Permalink
Prototyping UI with Restart Button and ValueBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianEgbert committed Nov 8, 2023
1 parent 8814e55 commit 24395d4
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions addons/pronto/behaviors/CodeBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func lines():

## Executes the code provided in [member CodeBehavior.evaluate] and emits the [signal CodeBehavior.after] signal afterwards.
func execute(args: Array = []):
print("executing ", self)
assert(args.size() == arguments.size(), "Argument names and values for eval need to have the same size.")
var result = await evaluate.run(args, self)
after.emit(result)
Expand Down
7 changes: 6 additions & 1 deletion addons/pronto/behaviors/ValueBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var float_step_size:float = 1:

var float_value:float = 0:
set(val):
print("Setting", val)
if(!value_init):
float_default = snapped(val, float_step_size)
value_init = true
Expand Down Expand Up @@ -158,7 +159,11 @@ func _get_property_list():
func _ready():
super._ready()
renamed.connect(queue_redraw)
G.put(name, float_value)
var loaded_value = G.at(name)
if (loaded_value):
float_value = loaded_value
else:
G.put(name, float_value)
value_changed.emit(G.at(name))

func _forward_canvas_draw_over_viewport(viewport_control: Control):
Expand Down
8 changes: 7 additions & 1 deletion addons/pronto/helpers/G.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extends Node

var values = {}
var _store_update = {}
var current_root = null

func put(name: String, value: Variant):
_put(name, value)
Expand Down Expand Up @@ -45,14 +46,19 @@ func _register_store(store: StoreBehavior, prop: String):
func _ready():
if not Engine.is_editor_hint():
maybe_add_value_user_interface()
get_tree().tree_changed.connect(maybe_add_value_user_interface)


func maybe_add_value_user_interface():
if (current_root and current_root.get_ref()): return
current_root = weakref(get_tree().current_scene)
if not Utils.all_nodes_that(get_tree().root, func (node): return node is PrototypingUIBehavior).is_empty():
return

await get_tree().process_frame
var ui = PrototypingUIBehavior.new()
ui.name = 'Config'
# Place the PrototypingUI in its own CanvasLayer
var canvasLayer = CanvasLayer.new()
canvasLayer.add_child(ui)
add_child(canvasLayer)
get_tree().current_scene.add_child(canvasLayer)
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config_version=5
[application]

config/name="pronto"
run/main_scene="res://prototypes/game-test-PUI/game-test-PUI.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
run/low_processor_mode=true
config/icon="res://icon.svg"
Expand Down
54 changes: 54 additions & 0 deletions prototypes/game-test-PUI/game-test-PUI.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[gd_scene load_steps=9 format=3 uid="uid://chj6nkvr0sh3x"]

[ext_resource type="Script" path="res://addons/pronto/behaviors/ExportBehavior.gd" id="1"]
[ext_resource type="Script" path="res://addons/pronto/behaviors/CodeBehavior.gd" id="2_m18cy"]
[ext_resource type="Script" path="res://addons/pronto/helpers/ConnectionScript.gd" id="3_qub70"]
[ext_resource type="Script" path="res://addons/pronto/behaviors/PlaceholderBehavior.gd" id="4_x8ykv"]
[ext_resource type="Texture2D" uid="uid://bhos8bn4u0qp8" path="res://addons/pronto/icons/MissingTexture.svg" id="5_6wfp8"]
[ext_resource type="Script" path="res://addons/pronto/behaviors/ValueBehavior.gd" id="9_b7gob"]

[sub_resource type="GDScript" id="GDScript_8ds22"]
script/source = "@tool
extends U
@warning_ignore(\"unused_parameter\")
func run():
print(\"Before\")
print(get_parent().get_tree().reload_current_scene())
print(\"Restarting Game\")
"
[sub_resource type="Resource" id="Resource_5iqmk"]
script = ExtResource("3_qub70")
nested_script = SubResource("GDScript_8ds22")
argument_names = []
return_value = true
[node name="Node2D" type="Node2D"]
[node name="ExportBehavior" type="Node2D" parent="."]
position = Vector2(576, 324)
script = ExtResource("1")
title = "Test"
authors = PackedStringArray("Julian")
description = "Testing Prototyping UI and persistency between restarts."
[node name="Reload Game" type="Node2D" parent="ExportBehavior"]
position = Vector2(-28.2843, 28.2843)
script = ExtResource("2_m18cy")
evaluate = SubResource("Resource_5iqmk")
[node name="RigidBody2D" type="RigidBody2D" parent="."]
position = Vector2(129, 25)
[node name="PlaceholderBehavior" type="Node2D" parent="RigidBody2D"]
script = ExtResource("4_x8ykv")
sprite_texture = ExtResource("5_6wfp8")
placeholder_size = Vector2(20, 20)
[node name="ValueBehavior" type="Node2D" parent="RigidBody2D/PlaceholderBehavior"]
position = Vector2(447, 299)
script = ExtResource("9_b7gob")
float_min = 0.0
float_max = 100.0
float_value = 88.0
float_step_size = 1.0
7 changes: 7 additions & 0 deletions prototypes/game-test-PUI/game_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"authors": [
"<Author>"
],
"time": "2023-11-08",
"title": "Test"
}
Binary file added prototypes/game-test-PUI/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions prototypes/game-test-PUI/thumbnail.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://enk0drpv1764"
path="res://.godot/imported/thumbnail.png-7b00f17db0f0351e6b68de14ac130b90.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://prototypes/game-test-PUI/thumbnail.png"
dest_files=["res://.godot/imported/thumbnail.png-7b00f17db0f0351e6b68de14ac130b90.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

0 comments on commit 24395d4

Please sign in to comment.