|
| 1 | +@tool |
| 2 | +extends PanelContainer |
| 3 | + |
| 4 | + |
| 5 | +var shortcuts := [ |
| 6 | + |
| 7 | + {"shortcut":"Ctrl+T", "text":"Add Text event", "editor":"VisualEditor"}, |
| 8 | + {"shortcut":"Ctrl+Shift+T", "text":"Add Text event with current character", "editor":"VisualEditor"}, |
| 9 | + {"shortcut":"Ctrl+Alt/Opt+T", "text":"Add Text event with previous character", "editor":"VisualEditor"}, |
| 10 | + {"shortcut":"Ctrl+E", "text":"Add Character join event", "editor":"VisualEditor"}, |
| 11 | + {"shortcut":"Ctrl+Shift+E", "text":"Add Character update event", "editor":"VisualEditor"}, |
| 12 | + {"shortcut":"Ctrl+Alt/Opt+E", "text":"Add Character leave event", "editor":"VisualEditor"}, |
| 13 | + {"shortcut":"Ctrl+J", "text":"Add Jump event", "editor":"VisualEditor"}, |
| 14 | + {"shortcut":"Ctrl+L", "text":"Add Label event", "editor":"VisualEditor"}, |
| 15 | + {}, |
| 16 | + {"shortcut":"Alt/Opt+Up", "text":"Move selected events/lines up"}, |
| 17 | + {"shortcut":"Alt/Opt+Down", "text":"Move selected events/lines down"}, |
| 18 | + {}, |
| 19 | + {"shortcut":"Ctrl+F", "text":"Search"}, |
| 20 | + |
| 21 | + {}, |
| 22 | + {"shortcut":"Ctrl+C", "text":"Copy"}, |
| 23 | + {"shortcut":"Ctrl+V", "text":"Paste"}, |
| 24 | + {"shortcut":"Ctrl+D", "text":"Duplicate selected events/lines"}, |
| 25 | + {"shortcut":"Ctrl+X", "text":"Cut selected events/lines"}, |
| 26 | + {"shortcut":"Ctrl+#", "text":"Toggle Comment" , "editor":"TextEditor"}, |
| 27 | + {"shortcut":"Delete", "text":"Delete events", "editor":"VisualEditor"}, |
| 28 | + {}, |
| 29 | + {"shortcut":"Ctrl+A", "text":"Select All"}, |
| 30 | + {"shortcut":"Ctrl+Shift+A", "text":"Select Nothing", "editor":"VisualEditor"}, |
| 31 | + {"shortcut":"Up", "text":"Select previous event", "editor":"VisualEditor"}, |
| 32 | + {"shortcut":"Down", "text":"Select next event", "editor":"VisualEditor"}, |
| 33 | + {}, |
| 34 | + {"shortcut":"Ctrl+Z", "text":"Undo"}, |
| 35 | + {"shortcut":"Ctrl+Shift+Z", "text":"Redo"}, |
| 36 | + {}, |
| 37 | +] |
| 38 | + |
| 39 | + |
| 40 | +# Called when the node enters the scene tree for the first time. |
| 41 | +func _ready() -> void: |
| 42 | + %CloseShortcutPanel.icon = get_theme_icon("Close", "EditorIcons") |
| 43 | + get_theme_stylebox("panel").bg_color = get_theme_color("dark_color_3", "Editor") |
| 44 | + |
| 45 | +func reload_shortcuts() -> void: |
| 46 | + for i in %ShortcutList.get_children(): |
| 47 | + i.queue_free() |
| 48 | + |
| 49 | + |
| 50 | + var is_text_editor: bool = %TextEditor.visible |
| 51 | + for i in shortcuts: |
| 52 | + if i.is_empty(): |
| 53 | + %ShortcutList.add_child(HSeparator.new()) |
| 54 | + %ShortcutList.add_child(HSeparator.new()) |
| 55 | + continue |
| 56 | + if "editor" in i and not get_node("%"+i.editor).visible: |
| 57 | + continue |
| 58 | + |
| 59 | + var hbox := HBoxContainer.new() |
| 60 | + hbox.add_theme_constant_override("separation", 0) |
| 61 | + for key_text in i.shortcut.split("+"): |
| 62 | + if hbox.get_child_count(): |
| 63 | + var plus_l := Label.new() |
| 64 | + plus_l.text = "+" |
| 65 | + hbox.add_child(plus_l) |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + var key := Button.new() |
| 70 | + if key_text == "Up": |
| 71 | + key.icon = get_theme_icon("ArrowUp", "EditorIcons") |
| 72 | + elif key_text == "Down": |
| 73 | + key.icon = get_theme_icon("ArrowDown", "EditorIcons") |
| 74 | + else: |
| 75 | + key.text = key_text |
| 76 | + key.disabled = true |
| 77 | + key.theme_type_variation = "ShortcutKeyLabel" |
| 78 | + hbox.add_child(key) |
| 79 | + |
| 80 | + %ShortcutList.add_child(hbox) |
| 81 | + |
| 82 | + var text := Label.new() |
| 83 | + text.text = i.text.replace("events/lines", "lines" if is_text_editor else "events") |
| 84 | + text.theme_type_variation = "DialogicHintText2" |
| 85 | + %ShortcutList.add_child(text) |
| 86 | + |
| 87 | + |
| 88 | +func open(): |
| 89 | + if visible: |
| 90 | + close() |
| 91 | + return |
| 92 | + |
| 93 | + reload_shortcuts() |
| 94 | + |
| 95 | + show() |
| 96 | + size = get_parent().size - Vector2(200, 200)*DialogicUtil.get_editor_scale() |
| 97 | + size.x = %ShortcutList.get_minimum_size().x + 100 |
| 98 | + global_position = get_parent().global_position+get_parent().size/2-size/2 |
| 99 | + |
| 100 | + |
| 101 | +func _on_close_shortcut_panel_pressed() -> void: |
| 102 | + close() |
| 103 | + |
| 104 | +func close() -> void: |
| 105 | + hide() |
0 commit comments