-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ActionPopupPanel.gd
797 lines (614 loc) · 23.9 KB
/
ActionPopupPanel.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
extends WindowDialog
signal ok_signal
signal cancel
signal error
var components = []
var parameters = {}
var new_template = null
var prev_template = null
var edit_mode = false
var action_filter = "3D"
var three_d_actions = null
var two_d_actions = null
var wp_actions = null
var selector_actions = null
"""
Called when this control is ready to display.
"""
func _ready():
var three_d_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/ThreeDButton
three_d_btn.hint_tooltip = tr("THREE_D_BUTTON_HINT_TOOLTIP")
# Make sure 3D is selected by default
three_d_btn.pressed = true
var action_tree = $VBoxContainer/ActionContainer/ActionTree
# Add the tooltips to the group buttons
var wp_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/WorkplaneButton
wp_btn.hint_tooltip = tr("WORKPLANE_BUTTON_HINT_TOOLTIP")
var sketch_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SketchButton
sketch_btn.hint_tooltip = tr("SKETCH_BUTTON_HINT_TOOLTIP")
var select_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SelectorButton
select_btn.hint_tooltip = tr("SELECTOR_BUTTON_HINT_TOOLTIP")
# Add a tooltip to the modify operation buttons
var add_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/AddButton
add_btn.hint_tooltip = tr("ADD_BUTTON_HINT_TOOLTIP")
var update_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer/UpdateButton
update_btn.hint_tooltip = tr("UPDATE_BUTTON_HINT_TOOLTIP")
var delete_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer/DeleteButton
delete_btn.hint_tooltip = tr("DELETE_BUTTON_HINT_TOOLTIP")
var move_up_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer/MoveUpButton
move_up_btn.hint_tooltip = tr("MOVE_UP_BUTTON_HINT_TOOLTIP")
var move_down_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer/MoveDownButton
move_down_btn.hint_tooltip = tr("MOVE_DOWN_BUTTON_HINT_TOOLTIP")
# Create the root of the object tree
var action_tree_root = action_tree.create_item()
action_tree_root.set_text(0, "Actions")
# Work-around to make sure we unlock the mouse controls for the 3D view again
var btn = self.get_close_button()
btn.visible = false
"""
Sets the Action control based on what is selected in the option button.
"""
func _set_action_control():
var aob = $VBoxContainer/ActionOptionButton
# Make sure to free the previous control
var cont = $VBoxContainer/ActionContainer/DynamicContainer.get_children()
if cont.size() > 0:
var cont_current = cont[0]
if cont_current != null:
cont_current.free()
# Get the currently selected item
var selected = aob.get_item_text(aob.get_selected_id())
# Get the action for the name
var act = ContextHandler.get_action_for_name(selected)
# Set the action control
_clear_popup()
var dyn_cont = $VBoxContainer/ActionContainer/DynamicContainer
var new_cont = load(act.action.control)
new_cont = new_cont.new()
dyn_cont.add_child(new_cont)
"""
Clears the previous dynamic controls from this popup.
"""
func _clear_popup():
# Clear the previous control item(s) from the DynamicContainer
for child in $VBoxContainer/ActionContainer/DynamicContainer.get_children():
$VBoxContainer/ActionContainer/DynamicContainer.remove_child(child)
child.free()
"""
Finds out which trigger was selected by the user.
"""
func _get_selected_trigger():
var aob = self.get_node("VBoxContainer/ActionOptionButton")
return aob.get_item_text(aob.get_selected_id())
"""
Sets the ActionPopupPanel up for an edit of a history item.
"""
func activate_edit_mode(component_text, item_text, new_components, new_parameters):
prev_template = item_text
components = new_components
parameters = new_parameters
# Get the control that matches the edit trigger for the history code, if any
var popup_action = ContextHandler.find_matching_edit_trigger(item_text)
# If the returned control is null, there is not need continuing
if popup_action == null or popup_action.size() == 0:
emit_signal("error", "You cannot edit this operation.")
return
# Show the popup
activate_popup(component_text, true, components, parameters, null)
# Select the correct group button based on the next action
_select_group_button(popup_action.values()[0].group)
# Make sure the correct item is selected
Common.set_option_btn_by_text($VBoxContainer/ActionOptionButton, popup_action.values()[0].name)
_set_action_control()
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var action_tree_root = action_tree.get_root()
# Check to see if there are multiple actions in the item_text
# and fill the actions tree with them
var parts = item_text.split(").")
# See if this is a binary (i.e. boolean) item
var is_binary = ContextHandler.is_binary(item_text)
# Fille the 2D history tree, if needed
if parts.size() > 1 and not is_binary and \
item_text.begins_with(".Workplane(") == false and \
item_text.begins_with(".workplane(") == false and \
item_text.begins_with(".faces(") == false and \
item_text.begins_with(".edges(") == false and \
item_text.begins_with(".vertices(") == false:
# Walk through all the actions
var i = 0
for part in parts:
# If we are past the first action, prepend the period
if i > 0:
part = "." + part
# If not at the last action, append the closing parenthesis
if i < parts.size() - 1:
part += ")"
# Add the current Action string back to the Action tree
Common.add_item_to_tree(part, action_tree, action_tree_root)
i += 1
# _render_action_tree()
# Set the values of the control being edited
$VBoxContainer/ActionContainer/DynamicContainer.get_children()[0].set_values_from_string(item_text)
"""
Attempt to contain popup actions in one place.
"""
func activate_popup(component_text, edit_mode_new, new_components, new_parameters, selector_str):
# Save the incoming components for binary operations and duplicate checks
components = new_components
parameters = new_parameters
# Save edit mode for when the user hits the OK button
edit_mode = edit_mode_new
# Setup and show the dialog
show_modal(true)
popup_centered()
_on_VBoxContainer_resized()
# Make sure the Update button is hidden
var is_cont = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer
is_cont.hide()
var next_action = null
# If there is a selector string, short circuit and open the selection dialog for that
if selector_str:
next_action = ContextHandler.find_matching_edit_trigger(selector_str)
else:
# Get the next action based on whether edit mode is engaged
if edit_mode:
next_action = ContextHandler.find_matching_edit_trigger(prev_template)
else:
next_action = ContextHandler.get_next_action(component_text)
# If we did not get a matching action, the user might be doing something like defining parameters
if next_action.empty():
next_action["Workplane"] = Triggers.get_triggers()["Workplane"].action
# Select the correct group button based on the next action
_select_group_button(next_action[next_action.keys()[0]].group)
# Set the selector string within the control, if present
if selector_str:
var cont = $VBoxContainer/ActionContainer/DynamicContainer.get_children()[0]
cont.set_values_from_string(selector_str)
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var action_tree_root = action_tree.get_root()
# Clear any left-over actions from the action tree
if action_tree != null:
action_tree.clear()
# Create the root of the object tree
action_tree_root = action_tree.create_item()
action_tree_root.set_text(0, "Actions")
"""
Selects the correct group button based on an Action's group.
"""
func _select_group_button(group):
var wp_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/WorkplaneButton
var three_d_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/ThreeDButton
var sketch_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SketchButton
var selector_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SelectorButton
if group == "WP":
wp_btn.pressed = true
_on_WorkplaneButton_toggled(wp_btn)
elif group == "3D":
three_d_btn.pressed = true
_on_ThreeDButton_toggled(three_d_btn)
elif group == "SELECTORS":
selector_btn.pressed = true
else:
sketch_btn.pressed = true
_on_SketchButton_toggled(sketch_btn)
_on_VBoxContainer_resized()
"""
Called when the Ok button is pressed so that the GUI can collect the changed context.
"""
func _on_OkButton_button_down():
# Current control loaded
var cont = $VBoxContainer/ActionContainer/DynamicContainer.get_children()[0]
# Make sure the form is valid
if not cont.is_valid():
emit_signal("error", "There are errors on the form, please correct them.")
return
# Get the completed template from the current control
new_template = cont.get_completed_template()
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var action_tree_root = action_tree.get_root()
# Used if the user added multiple actions to the actions tree
var cur_item = action_tree_root.get_children()
if cur_item != null:
new_template = _update_multiple_actions(cur_item)
# Make sure the user has not specified a duplicate component name
if not edit_mode:
var new_comp_name = ContextHandler.get_objects_from_context(new_template)
if new_comp_name in components:
# Let the user know they have entered a duplicate name
emit_signal("error", "The component/workplane name has already been used.\nPlease select another one.")
return
# Handle binary controls
var combine_map = null
if cont.is_binary():
combine_map = cont.get_combine_map()
emit_signal("ok_signal", new_template, combine_map)
hide()
"""
Checks whether or not the component name has been used before.
"""
func _is_component_dup(original_context, dup_template):
# Regex to search for tags, which are used for component names
var rgx = RegEx.new()
rgx.compile("\\.tag\\(.*\\)")
var res = rgx.search_all(dup_template)
# If there is no match at all, then we cannot have a duplicate
if not res:
return false
else:
# Search all of the results to see if there is a match from the original context
for r in res:
if original_context.find(r.get_string()) > 0:
return true
return false
"""
Pull multiple items from the action tree to update the context string.
"""
func _update_multiple_actions(tree_children):
var updated_context = ""
while true:
if tree_children == null:
break
else:
updated_context += tree_children.get_text(0)
tree_children = tree_children.get_next()
return updated_context
"""
Called when the Cancel button is pressed so that this popup can just be closed.
"""
func _on_CancelButton_button_down():
emit_signal("cancel")
hide()
"""
Called when the user selects a different trigger from the top option button.
"""
func _on_ActionOptionButton_item_selected(_index):
# Clear the dynamic action items from the popup
_clear_popup()
# Populate the appropriate action control
_set_action_control()
"""
Called whenever the contents of the main VBoxContainer require a size change.
"""
func _on_VBoxContainer_resized():
var vb_cont = $VBoxContainer
# Make sure the panel is the correct size to contain all controls
rect_size = Vector2(vb_cont.rect_size[0] + 7, vb_cont.rect_size[1] + 7)
# Work-around to force the size changes to take effect
if visible == true:
hide()
show()
else:
show()
hide()
"""
Called when the user clicks the 3D button and toggles it.
"""
func _on_ThreeDButton_toggled(_button_pressed):
var three_d_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/ThreeDButton
# Make sure that the other buttons are not toggled
if three_d_btn.pressed:
# Untoggle all other group buttons
_untoggle_all_group_buttons(three_d_btn)
action_filter = "3D"
# Fill the 3D actions list up the first time it is requested
if three_d_actions == null:
three_d_actions = ContextHandler.get_3d_actions()
# Repopulate the action option button
var opt_btn = $VBoxContainer/ActionOptionButton
opt_btn.clear()
Common.load_option_button($VBoxContainer/ActionOptionButton, three_d_actions)
# Set the help tooltips for all the items in the dropdown
_set_tooltips()
_set_action_control()
# Hide any previously shown sketch tools
_hide_sketch_controls()
# Make sure the dialog is sized correctly
_on_VBoxContainer_resized()
"""
Called when the user clicks the Sketch button and toggles it.
"""
func _on_SketchButton_toggled(_button_pressed):
var sketch_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SketchButton
if sketch_btn.pressed:
# Untoggle all other group buttons
_untoggle_all_group_buttons(sketch_btn)
action_filter = "2D"
# Fill the 2D actions list up the first time it is requested
if two_d_actions == null:
two_d_actions = ContextHandler.get_2d_actions()
# Repopulate the action option button
var opt_btn = $VBoxContainer/ActionOptionButton
opt_btn.clear()
Common.load_option_button($VBoxContainer/ActionOptionButton, two_d_actions)
# Set the help tooltips for all the items in the dropdown
_set_tooltips()
_set_action_control()
# Show preview controls
var add_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/AddButton
add_btn.show()
var action_tree = $VBoxContainer/ActionContainer/ActionTree
action_tree.show()
# Make sure the dialog is sized correctly
_on_VBoxContainer_resized()
"""
Called when the user clicks on the Workplane button and toggles it.
"""
func _on_WorkplaneButton_toggled(_button_pressed):
var wp_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/WorkplaneButton
if wp_btn.pressed:
# Untoggle all other group buttons
_untoggle_all_group_buttons(wp_btn)
action_filter = "WP"
# Fill in the workplane action list the first time it is requested
if wp_actions == null:
wp_actions = ContextHandler.get_wp_actions()
# Repopulate the action option button
var opt_btn = $VBoxContainer/ActionOptionButton
opt_btn.clear()
Common.load_option_button($VBoxContainer/ActionOptionButton, wp_actions)
# Set the help tooltips for all the items in the dropdown
_set_tooltips()
_set_action_control()
# Hide any previously shown sketch tools
_hide_sketch_controls()
# Make sure the dialog is sized correctly
_on_VBoxContainer_resized()
"""
Called when the user clicks on the selector button to display
the selector controls.
"""
func _on_SelectorButton_toggled(_button_pressed):
var selector_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SelectorButton
if selector_btn.pressed:
# Untoggle all other group buttons
_untoggle_all_group_buttons(selector_btn)
action_filter = "SELECTORS"
# Fill the selector actions listup the first time it is requested
if selector_actions == null:
selector_actions = ContextHandler.get_selector_actions()
# Repopulate the action option button
var opt_btn = $VBoxContainer/ActionOptionButton
opt_btn.clear()
Common.load_option_button($VBoxContainer/ActionOptionButton, selector_actions)
_set_action_control()
# Hide any previously shown sketch tools
_hide_sketch_controls()
# Make sure the dialog is sized correctly
_on_VBoxContainer_resized()
"""
Called when switching to another group control and needing to hide
any previously displayed sketch controls.
"""
func _hide_sketch_controls():
var add_btn = $VBoxContainer/ActionContainer/ActionButtonContainer/AddButton
add_btn.hide()
var action_tree = $VBoxContainer/ActionContainer/ActionTree
action_tree.hide()
var is_cont = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer
is_cont.hide()
"""
Called when a new group button is toggled so that all
others can be untoggled.
"""
func _untoggle_all_group_buttons(except):
var wp_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/WorkplaneButton
var three_d_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/ThreeDButton
var sketch_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SketchButton
var selector_btn = $VBoxContainer/ActionGroupsVBoxContainer/HBoxContainer/SelectorButton
# Untoggle all buttons except the one that was passed
if except != wp_btn:
wp_btn.pressed = false
if except != three_d_btn:
three_d_btn.pressed = false
if except != sketch_btn:
sketch_btn.pressed = false
if except != selector_btn:
selector_btn.pressed = false
"""
Called when the Add button is clicked.
"""
func _on_AddButton_button_down():
# Get the template from the active control
var cont = $VBoxContainer/ActionContainer/DynamicContainer.get_children()[0]
var preview_context = cont.get_completed_template()
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var action_tree_root = action_tree.get_root()
# Add the item to the action tree
Common.add_item_to_tree(preview_context, $VBoxContainer/ActionContainer/ActionTree, action_tree_root)
# _render_action_tree()
"""
Collects all of the completed templates in the Action tree and
renders them on the 2D canvas.
"""
#func _render_action_tree():
# var script_text = "import cadquery as cq\n"
#
# # Collect all of the parameters into a string the starts the script
# for param in parameters.keys():
# script_text += param + "=" + parameters[param] + "\n"
#
# # Start to build the preview string based on what is in the actions list
# script_text += "result=cq.Workplane()"
#
# var action_tree = $VBoxContainer/HBoxContainer/ActionContainer/ActionTree
# var action_tree_root = action_tree.get_root()
#
# # Search the tree and update the matchine entry in the tree
# var cur_item = action_tree_root.get_children()
# while true:
# if cur_item == null:
# break
# else:
# script_text += cur_item.get_text(0)
#
# cur_item = cur_item.get_next()
#
# # Make sure all the wires show up
# script_text += ".consolidateWires()\nshow_object(result)"
#
# # Export the file to the user data directory temporarily
# var json_string = cqgipy
# json_string = json_string.build(script_text)
#
# if json_string.begins_with("error~"):
# # Let the user know there was an error
# var err = json_string.split("~")[1]
# emit_signal("error", err)
# else:
# var component_json = JSON.parse(json_string)
# component_json = component_json.result
# var canvas_2d = $VBoxContainer/HBoxContainer/CanvasMarginContainer/Canvas2D
#
# for component in component_json["components"]:
# # If we've found a larger dimension, save the safe scaling, which is the maximum dimension of any component
# var max_dim = component["largestDim"]
# canvas_2d.set_max_dim(max_dim)
#
# # Add the edge representations
# for edge in component["cqEdges"]:
# # Add the current line
# canvas_2d.lines.append([Vector2(edge[0], edge[1]), Vector2(edge[3], edge[4])])
#
# # Have the 2D canvas re-render the lines that are set for it
# canvas_2d.update()
"""
Allows action items to be edited by selecting the correct control.
"""
#func _on_ActionTree_item_activated():
# var action_tree = $VBoxContainer/HBoxContainer/ActionContainer/ActionTree
# Get the action name so that we can set the action option correctly
# var item_text = action_tree.get_selected().get_text(0)
# var action_key = item_text.split(".")[1].split("(")[0]
# Make sure the correct item is selected
# Common.set_option_btn_by_text($VBoxContainer/ActionOptionButton, action_key)
# _set_action_control()
"""
Updates the selected action tree item with new settings.
"""
func _on_UpdateButton_button_down():
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var orig_text = action_tree.get_selected().get_text(0)
# Get the template from the active control
var cont = $VBoxContainer/ActionContainer/DynamicContainer.get_children()[0]
var new_text = cont.get_completed_template()
# Update the old action template to reflect the new settings
Common.update_tree_item(action_tree, orig_text, new_text)
# Re-render everything in the action tree
# _update_preview()
"""
Called when an item is selected in the Action tree.
"""
func _on_ActionTree_item_selected():
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var selected = action_tree.get_selected()
# Make sure there is an item to work with
if selected == null:
return
# Figure out which control needs to be loaded from the operations list
var selected_text = selected.get_text(0)
var ctrl_text = "(" + selected_text.split(".")[1].split("(")[0] + ")"
# Set the control in the operations drop down based on our partial text
Common.set_option_btn_by_partial_text($VBoxContainer/ActionOptionButton, ctrl_text)
# Make sure the matching control is loaded
_on_ActionOptionButton_item_selected(0)
# Repopulate the control with the previous settings
var cur_control = $VBoxContainer/ActionContainer/DynamicContainer.get_children()[0]
cur_control.set_values_from_string(selected_text)
# Unhide the item editing controls so the user can change the selected tree item
var is_cont = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer
is_cont.show()
"""
Called when nothing is selected in the action tree.
"""
func _on_ActionTree_nothing_selected():
# Hide the item editing controls so that the user can no longer change the selected tree item
var is_cont = $VBoxContainer/ActionContainer/ActionButtonContainer/ItemSelectedContainer
is_cont.hide()
"""
Called when the user clicks the delete tree item button.
"""
func _on_DeleteButton_button_down():
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var action_tree_root = action_tree.get_root()
var selected = action_tree.get_selected()
# Make sure there is an item to delete
if selected == null:
return
# Remove the item from the history tree
action_tree_root.remove_child(selected)
selected.free()
# Force an update of the tree
action_tree.update()
# Updated the 2D preview
# _update_preview()
"""
Called when the move action item up button is pressed.
"""
func _on_MoveUpButton_button_down():
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var selected = action_tree.get_selected()
# Make sure there is an item to delete
if selected == null:
return
# Move the item up in the action tree one position
Common.move_tree_item_up(action_tree, selected)
"""
Called when the move action item down button is pressed.
"""
func _on_MoveDownButton_button_down():
var action_tree = $VBoxContainer/ActionContainer/ActionTree
var selected = action_tree.get_selected()
# Make sure there is an item to delete
if selected == null:
return
# Move the item up in the action tree one position
Common.move_tree_item_down(action_tree, selected)
"""
Called whenever the 2D preview needs to be updated.
"""
#func _update_preview():
# # Reset and update the 2D preview
# var canvas_2d = $VBoxContainer/HBoxContainer/CanvasMarginContainer/Canvas2D
# canvas_2d.reset()
# canvas_2d.update()
# self._render_action_tree()
"""
Called when the control loaded in the dynamic contrainer
is changed.
"""
func _on_DynamicContainer_resized():
_on_VBoxContainer_resized()
"""
Allows a child control to pop up the error dialog.
"""
func _on_error(error_msg):
emit_signal("error", error_msg)
"""
Allows tooltips to be set for each of the operation items.
"""
func _set_tooltips():
var opt_btn = $VBoxContainer/ActionOptionButton
var popup = opt_btn.get_popup()
# Step through all of the items in the popup, adding their tooltips
for i in range(0, popup.get_item_count()):
# Match the item that is being hovered over to a tooltip
var child_name = popup.get_item_text(i)
# Figure out the prefix of the tooltip based on the text in the dropdown popup item
var child_name_upper = child_name.to_upper()
if child_name_upper.find("(") > 0:
child_name_upper = child_name_upper.split("(")[1].split(")")[0]
# Combine the prefix with the postfix to dynamically find the correct tooltip text
popup.set_item_tooltip(i, tr(child_name_upper) + "_TOOLTIP")
"""
Allows a control to get only the names of parameters that are tuples.
"""
func get_tuple_param_names():
# Filter the paramters down to only tuple lists
# var filtered_params = {}
var filtered_param_names = []
for param_name in parameters.keys():
# The parameter is a tuple list
if parameters[param_name].begins_with("["):
# filtered_params[param_name] = parameters[param_name]
filtered_param_names.append(param_name)
return filtered_param_names