Browse Source

started adding a basic calculator not currently working

Jonathan Higgins 6 months ago
parent
commit
4fb37acc81
4 changed files with 285 additions and 2 deletions
  1. 55 0
      scenes/Nodes/calculator.gd
  2. 1 0
      scenes/Nodes/calculator.gd.uid
  3. 218 2
      scenes/Nodes/nodes.tscn
  4. 11 0
      scenes/main/process_help.json

+ 55 - 0
scenes/Nodes/calculator.gd

@@ -0,0 +1,55 @@
+extends GraphNode
+
+var calulated = false
+var expression = ""
+signal open_help
+
+func _ready() -> void:
+	#add button to title bar
+	var titlebar = self.get_titlebar_hbox()
+	var btn = Button.new()
+	btn.text = "?"
+	btn.tooltip_text = "Open help for " + self.title
+	btn.connect("pressed", Callable(self, "_open_help")) #pass key (process name) when button is pressed
+	titlebar.add_child(btn)
+	
+	#this links the buttons, it is stupid but for some reason doing this automatically just would not work reliably
+	$HBoxContainer/Button.pressed.connect(calculate.bind($HBoxContainer/Button))
+	$HBoxContainer/Button2.pressed.connect(calculate.bind($HBoxContainer/Button2))
+	$HBoxContainer/Button3.pressed.connect(calculate.bind($HBoxContainer/Button3))
+	$HBoxContainer/Button4.pressed.connect(calculate.bind($HBoxContainer/Button4))
+	$HBoxContainer5/Button.pressed.connect(calculate.bind($HBoxContainer5/Button))
+	$HBoxContainer5/Button2.pressed.connect(calculate.bind($HBoxContainer5/Button2))
+	$HBoxContainer5/Button3.pressed.connect(calculate.bind($HBoxContainer5/Button3))
+	$HBoxContainer5/Button4.pressed.connect(calculate.bind($HBoxContainer5/Button4))
+	$HBoxContainer2/Button.pressed.connect(calculate.bind($HBoxContainer2/Button))
+	$HBoxContainer2/Button2.pressed.connect(calculate.bind($HBoxContainer2/Button2))
+	$HBoxContainer2/Button3.pressed.connect(calculate.bind($HBoxContainer2/Button3))
+	$HBoxContainer2/Button4.pressed.connect(calculate.bind($HBoxContainer2/Button4))
+	$HBoxContainer3/Button.pressed.connect(calculate.bind($HBoxContainer3/Button))
+	$HBoxContainer3/Button2.pressed.connect(calculate.bind($HBoxContainer3/Button2))
+	$HBoxContainer3/Button3.pressed.connect(calculate.bind($HBoxContainer3/Button3))
+	$HBoxContainer3/Button4.pressed.connect(calculate.bind($HBoxContainer3/Button4))
+	$HBoxContainer4/Button.pressed.connect(calculate.bind($HBoxContainer4/Button))
+	$HBoxContainer4/Button2.pressed.connect(calculate.bind($HBoxContainer4/Button2))
+	$HBoxContainer4/Button3.pressed.connect(calculate.bind($HBoxContainer4/Button3))
+	$HBoxContainer4/Button4.pressed.connect(calculate.bind($HBoxContainer4/Button4))
+	
+func _open_help():
+	open_help.emit(self.get_meta("command"), self.title)
+	
+func calculate(button: Button):
+	print("button pressed")
+	var label = button.text
+	var value = button.get_meta("calc")
+	print(label)
+	print(value)
+	
+	if value == "clear":
+		$Screen.text = ""
+	elif value == "del":
+		$Screen.text = $Screen.text.substr(0, $Screen.text.length() - 1)
+	elif value == "=":
+		pass
+	else:
+		$Screen.text += label

+ 1 - 0
scenes/Nodes/calculator.gd.uid

@@ -0,0 +1 @@
+uid://catbcnplcacvv

+ 218 - 2
scenes/Nodes/nodes.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=8 format=3 uid="uid://duy5epq25pj8u"]
+[gd_scene load_steps=9 format=3 uid="uid://duy5epq25pj8u"]
 
 
 [ext_resource type="Script" uid="uid://bifsyv5gxrddm" path="res://scenes/Nodes/inputfile.gd" id="1_8x08j"]
 [ext_resource type="Script" uid="uid://bifsyv5gxrddm" path="res://scenes/Nodes/inputfile.gd" id="1_8x08j"]
 [ext_resource type="PackedScene" uid="uid://csapiqka522fh" path="res://scenes/Nodes/audioplayer.tscn" id="2_b6nw4"]
 [ext_resource type="PackedScene" uid="uid://csapiqka522fh" path="res://scenes/Nodes/audioplayer.tscn" id="2_b6nw4"]
@@ -7,6 +7,7 @@
 [ext_resource type="Script" uid="uid://cy8x5wubj2kr6" path="res://scenes/Nodes/notes_to_hz.gd" id="4_0jqh0"]
 [ext_resource type="Script" uid="uid://cy8x5wubj2kr6" path="res://scenes/Nodes/notes_to_hz.gd" id="4_0jqh0"]
 [ext_resource type="FontFile" uid="uid://bfnlymfdfb0e7" path="res://theme/BravuraText_SoundThread.otf" id="5_0jqh0"]
 [ext_resource type="FontFile" uid="uid://bfnlymfdfb0e7" path="res://theme/BravuraText_SoundThread.otf" id="5_0jqh0"]
 [ext_resource type="Script" uid="uid://cuk68115uw1ge" path="res://scenes/Nodes/convert_time.gd" id="7_w2x51"]
 [ext_resource type="Script" uid="uid://cuk68115uw1ge" path="res://scenes/Nodes/convert_time.gd" id="7_w2x51"]
+[ext_resource type="Script" uid="uid://catbcnplcacvv" path="res://scenes/Nodes/calculator.gd" id="8_5syjs"]
 
 
 [node name="Control" type="Control"]
 [node name="Control" type="Control"]
 layout_mode = 3
 layout_mode = 3
@@ -376,7 +377,7 @@ layout_mode = 0
 offset_left = 1982.0
 offset_left = 1982.0
 offset_top = 34.0
 offset_top = 34.0
 offset_right = 2365.0
 offset_right = 2365.0
-offset_bottom = 293.0
+offset_bottom = 330.0
 tooltip_text = "Converts between various units of time"
 tooltip_text = "Converts between various units of time"
 title = "Convert Time Units"
 title = "Convert Time Units"
 slot/0/left_enabled = false
 slot/0/left_enabled = false
@@ -538,6 +539,221 @@ layout_mode = 2
 size_flags_horizontal = 3
 size_flags_horizontal = 3
 tooltip_text = "The length of time in seconds to a percentage of"
 tooltip_text = "The length of time in seconds to a percentage of"
 
 
+[node name="calculator" type="GraphNode" parent="."]
+layout_mode = 0
+offset_left = 2453.0
+offset_top = 33.0
+offset_right = 2836.0
+offset_bottom = 330.0
+tooltip_text = "A simple calculator for quick maths"
+title = "Calculator"
+slot/0/left_enabled = false
+slot/0/left_type = 1
+slot/0/left_color = Color(0, 0, 0, 1)
+slot/0/left_icon = null
+slot/0/right_enabled = false
+slot/0/right_type = 1
+slot/0/right_color = Color(0, 0, 0, 1)
+slot/0/right_icon = null
+slot/0/draw_stylebox = true
+slot/1/left_enabled = false
+slot/1/left_type = 0
+slot/1/left_color = Color(1, 1, 1, 1)
+slot/1/left_icon = null
+slot/1/right_enabled = false
+slot/1/right_type = 0
+slot/1/right_color = Color(1, 1, 1, 1)
+slot/1/right_icon = null
+slot/1/draw_stylebox = true
+slot/2/left_enabled = false
+slot/2/left_type = 0
+slot/2/left_color = Color(1, 1, 1, 1)
+slot/2/left_icon = null
+slot/2/right_enabled = false
+slot/2/right_type = 0
+slot/2/right_color = Color(1, 1, 1, 1)
+slot/2/right_icon = null
+slot/2/draw_stylebox = true
+slot/3/left_enabled = false
+slot/3/left_type = 0
+slot/3/left_color = Color(1, 1, 1, 1)
+slot/3/left_icon = null
+slot/3/right_enabled = false
+slot/3/right_type = 0
+slot/3/right_color = Color(1, 1, 1, 1)
+slot/3/right_icon = null
+slot/3/draw_stylebox = true
+slot/4/left_enabled = false
+slot/4/left_type = 0
+slot/4/left_color = Color(1, 1, 1, 1)
+slot/4/left_icon = null
+slot/4/right_enabled = false
+slot/4/right_type = 0
+slot/4/right_color = Color(1, 1, 1, 1)
+slot/4/right_icon = null
+slot/4/draw_stylebox = true
+slot/5/left_enabled = false
+slot/5/left_type = 0
+slot/5/left_color = Color(1, 1, 1, 1)
+slot/5/left_icon = null
+slot/5/right_enabled = false
+slot/5/right_type = 0
+slot/5/right_color = Color(1, 1, 1, 1)
+slot/5/right_icon = null
+slot/5/draw_stylebox = true
+script = ExtResource("8_5syjs")
+metadata/command = "calculator"
+metadata/utility = true
+metadata/input = false
+
+[node name="Screen" type="RichTextLabel" parent="calculator"]
+custom_minimum_size = Vector2(0, 100)
+layout_mode = 2
+theme_override_font_sizes/normal_font_size = 24
+bbcode_enabled = true
+scroll_following = true
+horizontal_alignment = 2
+
+[node name="HBoxContainer" type="HBoxContainer" parent="calculator"]
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+
+[node name="Button" type="Button" parent="calculator/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "("
+metadata/calc = "("
+
+[node name="Button2" type="Button" parent="calculator/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = ")"
+metadata/calc = ")"
+
+[node name="Button3" type="Button" parent="calculator/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "C"
+metadata/calc = "clear"
+
+[node name="Button4" type="Button" parent="calculator/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "⌫"
+metadata/calc = "del"
+
+[node name="HBoxContainer5" type="HBoxContainer" parent="calculator"]
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+
+[node name="Button" type="Button" parent="calculator/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "7"
+metadata/calc = "7"
+
+[node name="Button2" type="Button" parent="calculator/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "8"
+metadata/calc = "8"
+
+[node name="Button3" type="Button" parent="calculator/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "9"
+metadata/calc = "9"
+
+[node name="Button4" type="Button" parent="calculator/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "÷"
+metadata/calc = "/"
+
+[node name="HBoxContainer2" type="HBoxContainer" parent="calculator"]
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+
+[node name="Button" type="Button" parent="calculator/HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "4"
+metadata/calc = "4"
+
+[node name="Button2" type="Button" parent="calculator/HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "5"
+metadata/calc = "5"
+
+[node name="Button3" type="Button" parent="calculator/HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "6"
+metadata/calc = "6"
+
+[node name="Button4" type="Button" parent="calculator/HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "x"
+metadata/calc = "*"
+
+[node name="HBoxContainer3" type="HBoxContainer" parent="calculator"]
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+
+[node name="Button" type="Button" parent="calculator/HBoxContainer3"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "1"
+metadata/calc = "1"
+
+[node name="Button2" type="Button" parent="calculator/HBoxContainer3"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "2"
+metadata/calc = "2"
+
+[node name="Button3" type="Button" parent="calculator/HBoxContainer3"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "3"
+metadata/calc = "3"
+
+[node name="Button4" type="Button" parent="calculator/HBoxContainer3"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "-"
+metadata/calc = "-"
+
+[node name="HBoxContainer4" type="HBoxContainer" parent="calculator"]
+custom_minimum_size = Vector2(0, 50)
+layout_mode = 2
+
+[node name="Button" type="Button" parent="calculator/HBoxContainer4"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "0"
+metadata/calc = "0"
+
+[node name="Button2" type="Button" parent="calculator/HBoxContainer4"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "."
+metadata/calc = "."
+
+[node name="Button3" type="Button" parent="calculator/HBoxContainer4"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "="
+metadata/calc = "="
+
+[node name="Button4" type="Button" parent="calculator/HBoxContainer4"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "+"
+metadata/calc = "+"
+
 [connection signal="text_submitted" from="outputfile/FileNameField" to="outputfile" method="_on_file_name_field_text_submitted"]
 [connection signal="text_submitted" from="outputfile/FileNameField" to="outputfile" method="_on_file_name_field_text_submitted"]
 [connection signal="toggled" from="outputfile/DeleteIntermediateFilesToggle" to="outputfile" method="_on_delete_intermediate_files_toggle_toggled"]
 [connection signal="toggled" from="outputfile/DeleteIntermediateFilesToggle" to="outputfile" method="_on_delete_intermediate_files_toggle_toggled"]
 [connection signal="toggled" from="outputfile/ReuseFolderToggle" to="outputfile" method="_on_reuse_folder_toggle_toggled"]
 [connection signal="toggled" from="outputfile/ReuseFolderToggle" to="outputfile" method="_on_reuse_folder_toggle_toggled"]

+ 11 - 0
scenes/main/process_help.json

@@ -5205,6 +5205,17 @@
 	"subcategory": "",
 	"subcategory": "",
 	"title": "Output File"
 	"title": "Output File"
   },
   },
+  "calculator": {
+	"category": "utility",
+	"description": "This is a basic calculator for quick maths, it can be used in conjunction with other convert nodes to quickly work out parameter values.\n",
+	"inputtype": "",
+	"outputtype": "",
+	"parameters": {},
+	"short_description": "A simple calculator for quick maths",
+	"stereo": false,
+	"subcategory": "utility",
+	"title": "Calculator"
+  },
   "note_to_hz": {
   "note_to_hz": {
 	"category": "utility",
 	"category": "utility",
 	"description": "Utility for quickly getting frequencies, values are truncated to two decimal places so are not entirely accurate. Particularly useful for tuning filters and filterbanks. Note, you can highlight and copy a frequency and then paste that into the value for the slider.\n",
 	"description": "Utility for quickly getting frequencies, values are truncated to two decimal places so are not entirely accurate. Particularly useful for tuning filters and filterbanks. Note, you can highlight and copy a frequency and then paste that into the value for the slider.\n",