From 1d9ba2a124eb927937c98fe20ce0f32b0e440922 Mon Sep 17 00:00:00 2001 From: WallK Date: Mon, 25 Sep 2023 11:10:38 +0300 Subject: [PATCH] Add progress bar, CheckButton and comments --- tools/configurator/Button.gd | 5 +-- tools/configurator/Button2.gd | 8 ++-- tools/configurator/ProgressBar.gd | 32 +++++++++++++++ tools/configurator/ProgressButton.gd | 17 ++++++++ tools/configurator/main.gd | 2 +- tools/configurator/main.tscn | 58 +++++++++++++++++++++------- tools/configurator/progress_file.sh | 15 +++++++ 7 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 tools/configurator/ProgressBar.gd create mode 100644 tools/configurator/ProgressButton.gd create mode 100644 tools/configurator/progress_file.sh diff --git a/tools/configurator/Button.gd b/tools/configurator/Button.gd index 7d329d49..a20d6ed6 100644 --- a/tools/configurator/Button.gd +++ b/tools/configurator/Button.gd @@ -4,9 +4,8 @@ func _ready(): self.pressed.connect(self._button_pressed) func _button_pressed(): - var output = [] -# var exit_code = OS.execute("ls", ["-l", "/"], output, true) - var exit_code = OS.execute("touch", ["godot_configurator_hardcoded"], output) + var output := [] #[] is shared, Array isn't (maybe fixed in 4.1) + var exit_code := OS.execute("touch", ["godot_configurator_hardcoded"], output) print("exit code: ", exit_code) print("output: ", output) diff --git a/tools/configurator/Button2.gd b/tools/configurator/Button2.gd index 9476e0a0..2587f5a2 100644 --- a/tools/configurator/Button2.gd +++ b/tools/configurator/Button2.gd @@ -4,9 +4,7 @@ func _ready(): self.pressed.connect(self._button_pressed) func _button_pressed(): - var output = [] -# var exit_code = OS.execute("ls", ["-l", "/"], output, true) - var exit_code = OS.execute("bash", ["touch_external.sh"], output) + var output := [] #[] is shared, Array isn't (maybe fixed in 4.1) + var exit_code := OS.execute("bash", ["touch_external.sh"], output) print("exit code: ", exit_code) - print("output: ", - output) + print("output: ", output) diff --git a/tools/configurator/ProgressBar.gd b/tools/configurator/ProgressBar.gd new file mode 100644 index 00000000..1bf0ca89 --- /dev/null +++ b/tools/configurator/ProgressBar.gd @@ -0,0 +1,32 @@ +extends ProgressBar + +var progress_file := "progress" #File with progress from 0 to 100 +var progress_button: Button +var file := FileAccess + +var prev_prog: float = 0 + +func _ready(): + self.value = 0 + progress_button = $"../HBoxContainerProgress/ProgressButton" + +func _process(delta): + if file.file_exists(progress_file): #File to be removed after script is done + var file := FileAccess.open(progress_file, FileAccess.READ) + var _progress := float(file.get_as_text()) + if prev_prog != _progress: #To not rewrite every frame + self.value = _progress + print("boom", _progress) + prev_prog = _progress + else: + if prev_prog == 100: + progress_button.disabled = false #Reenable progress button + prev_prog = 0 + + +func _on_check_button_toggled(button_pressed): + var _fill_color := Color("999999") + if button_pressed: + _fill_color = Color("FF0000") + self.get("theme_override_styles/fill").set_bg_color(_fill_color) + diff --git a/tools/configurator/ProgressButton.gd b/tools/configurator/ProgressButton.gd new file mode 100644 index 00000000..d100a4ad --- /dev/null +++ b/tools/configurator/ProgressButton.gd @@ -0,0 +1,17 @@ +extends Button + +var thread: Thread + +func _ready(): + self.pressed.connect(self._button_pressed) + +func _button_pressed(): + thread = Thread.new() + thread.start(_execute_bash.bind(["progress_file.sh"])) #Need to bind + self.disabled = true #To prevent multiple launches +# thread.wait_to_finish() #Should be done somewhere + +func _execute_bash(filename): + var output := [] + var exit_code := OS.execute("bash", filename, output) + print(exit_code) diff --git a/tools/configurator/main.gd b/tools/configurator/main.gd index 40eb1fbb..c66797c5 100644 --- a/tools/configurator/main.gd +++ b/tools/configurator/main.gd @@ -1,4 +1,4 @@ extends Control func _ready(): - $VBoxContainerButtons/Button.grab_focus() + $VBoxContainerButtons/Button.grab_focus() #Required to enable controller focusing diff --git a/tools/configurator/main.tscn b/tools/configurator/main.tscn index 28a6df46..b11ddbd0 100644 --- a/tools/configurator/main.tscn +++ b/tools/configurator/main.tscn @@ -1,13 +1,21 @@ -[gd_scene load_steps=6 format=3 uid="uid://qk2gw74anwlq"] +[gd_scene load_steps=9 format=3 uid="uid://qk2gw74anwlq"] [ext_resource type="Texture2D" uid="uid://bv6vh33cnfaw4" path="res://icon.svg" id="1_axfei"] [ext_resource type="Script" path="res://main.gd" id="1_obpq7"] [ext_resource type="Script" path="res://Button.gd" id="3_aenvv"] [ext_resource type="Script" path="res://Button2.gd" id="4_u2f14"] +[ext_resource type="Script" path="res://ProgressButton.gd" id="5_slq0p"] +[ext_resource type="Script" path="res://ProgressBar.gd" id="6_cx658"] [sub_resource type="LabelSettings" id="LabelSettings_b77hh"] font_size = 24 +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xyjyy"] +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + [node name="Control" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -52,31 +60,55 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -70.5 -offset_top = -33.0 -offset_right = 70.5 -offset_bottom = 33.0 +offset_left = -74.0 +offset_top = -66.0 +offset_right = 273.0 +offset_bottom = 66.0 grow_horizontal = 2 grow_vertical = 2 [node name="Button" type="Button" parent="VBoxContainerButtons"] +custom_minimum_size = Vector2(150, 0) layout_mode = 2 -size_flags_horizontal = 4 -focus_neighbor_top = NodePath("../Button2") +size_flags_horizontal = 0 +focus_neighbor_top = NodePath("../HBoxContainerProgress/ProgressButton") focus_neighbor_bottom = NodePath("../Button2") text = "Hardcoded script" script = ExtResource("3_aenvv") [node name="Button2" type="Button" parent="VBoxContainerButtons"] +custom_minimum_size = Vector2(150, 0) layout_mode = 2 -size_flags_horizontal = 4 +size_flags_horizontal = 0 focus_neighbor_top = NodePath("../Button") -focus_neighbor_bottom = NodePath("../CheckButton") +focus_neighbor_bottom = NodePath("../HBoxContainerProgress/ProgressButton") text = "External script" script = ExtResource("4_u2f14") -[node name="CheckButton" type="CheckButton" parent="VBoxContainerButtons"] +[node name="HBoxContainerProgress" type="HBoxContainer" parent="VBoxContainerButtons"] layout_mode = 2 -focus_neighbor_top = NodePath("../Button2") -focus_neighbor_bottom = NodePath("../Button") -text = "Hardcore mode" + +[node name="ProgressButton" type="Button" parent="VBoxContainerButtons/HBoxContainerProgress"] +custom_minimum_size = Vector2(150, 0) +layout_mode = 2 +focus_neighbor_top = NodePath("../../Button2") +focus_neighbor_bottom = NodePath("../../Button") +text = "Start progress" +script = ExtResource("5_slq0p") + +[node name="CheckButton" type="CheckButton" parent="VBoxContainerButtons/HBoxContainerProgress"] +layout_mode = 2 +text = "Make progress red" + +[node name="ProgressBar" type="ProgressBar" parent="VBoxContainerButtons"] +custom_minimum_size = Vector2(150, 0) +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 1 +size_flags_stretch_ratio = 8.13 +theme_override_styles/fill = SubResource("StyleBoxFlat_xyjyy") +step = 1.0 +value = 25.0 +script = ExtResource("6_cx658") + +[connection signal="toggled" from="VBoxContainerButtons/HBoxContainerProgress/CheckButton" to="VBoxContainerButtons/ProgressBar" method="_on_check_button_toggled"] diff --git a/tools/configurator/progress_file.sh b/tools/configurator/progress_file.sh new file mode 100644 index 00000000..5233bf11 --- /dev/null +++ b/tools/configurator/progress_file.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +progress_file="progress" +echo "0" > "$progress_file" + +for ((i=1; i<=100; i++)); do + echo -ne "$i" > "$progress_file" +# echo $i +# sleep 0.1 + sleep $((RANDOM / 30000)) +done + +sleep 1 + +rm "$progress_file"