-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shortcuts for suggested actions, list shortcuts on the settings s…
…creen Not ideal to show them on the settings screen when they are not configurable, but the about/help screen is very saturated as it is.
- Loading branch information
Showing
11 changed files
with
681 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
################################################### | ||
# Part of Glasan FX # | ||
# Copyright (c) 2024 Yuri Sizov and contributors # | ||
# Provided under MIT # | ||
################################################### | ||
|
||
@tool | ||
class_name PianoOverlay extends Control | ||
|
||
@export var piano_container: PianoContainer = null: | ||
set = set_piano_container | ||
|
||
var _shortcut_buffers: Array[TextLine] = [] | ||
|
||
|
||
func _ready() -> void: | ||
_update_shortcut_buffers() | ||
|
||
|
||
func _draw() -> void: | ||
if not is_instance_valid(piano_container): | ||
return | ||
|
||
for i in _shortcut_buffers.size(): | ||
var text_buffer := _shortcut_buffers[i] | ||
var text_color := PianoKey.LIGHT_COLOR if Note.is_note_sharp(i) else PianoKey.DARK_COLOR | ||
|
||
var key_rect := piano_container._valid_children[i].get_rect() | ||
var text_position := key_rect.position + Vector2(key_rect.size.x / 2.0, key_rect.size.y) | ||
text_position.x -= text_buffer.get_size().x / 2.0 | ||
text_position.y -= text_buffer.get_size().y + 6.0 | ||
|
||
text_buffer.draw(get_canvas_item(), text_position, text_color) | ||
|
||
|
||
func _update_shortcut_buffers() -> void: | ||
_shortcut_buffers.clear() | ||
if not is_instance_valid(piano_container): | ||
return | ||
|
||
var font := get_theme_font("font") | ||
var font_size := get_theme_font_size("font_size") | ||
|
||
for i in piano_container.number_of_keys: | ||
var text_buffer := TextLine.new() | ||
var shortcut_name := &"glasan_play_key%d" % [ i ] | ||
var shortcut_text := ShortcutLine.get_action_as_string(shortcut_name) | ||
|
||
text_buffer.add_string(shortcut_text, font, font_size) | ||
_shortcut_buffers.push_back(text_buffer) | ||
|
||
queue_redraw() | ||
|
||
|
||
func set_piano_container(value: PianoContainer) -> void: | ||
if piano_container == value: | ||
return | ||
|
||
piano_container = value | ||
_update_shortcut_buffers() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
################################################### | ||
# Part of Glasan FX # | ||
# Copyright (c) 2024 Yuri Sizov and contributors # | ||
# Provided under MIT # | ||
################################################### | ||
|
||
@tool | ||
class_name ShortcutLine extends HBoxContainer | ||
|
||
@export var key_text: String = "KEY": | ||
set = set_key_text | ||
@export var key_is_action: bool = true: | ||
set = set_key_is_action | ||
@export_multiline var description_text: String = "Description": | ||
set = set_description_text | ||
|
||
@onready var _key_label: Label = $KeyLabel | ||
@onready var _description_label: Label = $DescriptionLabel | ||
|
||
|
||
func _ready() -> void: | ||
_update_labels() | ||
|
||
|
||
func _update_labels() -> void: | ||
if not is_inside_tree(): | ||
return | ||
|
||
if key_is_action: | ||
_key_label.text = get_action_as_string(key_text) | ||
else: | ||
_key_label.text = key_text | ||
|
||
_description_label.text = description_text | ||
|
||
|
||
func set_key_text(value: String) -> void: | ||
key_text = value | ||
_update_labels() | ||
|
||
|
||
func set_key_is_action(value: bool) -> void: | ||
key_is_action = value | ||
_update_labels() | ||
|
||
|
||
func set_description_text(value: String) -> void: | ||
description_text = value | ||
_update_labels() | ||
|
||
|
||
static func get_action_as_string(action_text: String) -> String: | ||
var bound_events := InputMap.action_get_events(action_text) | ||
if bound_events.size() <= 0: | ||
return "[UNBOUND]" | ||
|
||
var first_event := bound_events[0] | ||
if first_event is InputEventKey: | ||
var key_event := first_event as InputEventKey | ||
var key_bits := PackedStringArray() | ||
|
||
if key_event.shift_pressed: | ||
key_bits.push_back("SHIFT") | ||
if key_event.ctrl_pressed: | ||
key_bits.push_back("CTRL") | ||
if key_event.meta_pressed: | ||
if OS.has_feature("macos") || OS.has_feature("web_macos"): | ||
key_bits.push_back("CMD") | ||
elif OS.has_feature("windows") || OS.has_feature("web_windows"): | ||
key_bits.push_back("WIN") | ||
else: | ||
key_bits.push_back("META") | ||
if key_event.alt_pressed: | ||
key_bits.push_back("ALT") | ||
|
||
var keycode := key_event.keycode | ||
if keycode == KEY_NONE: | ||
keycode = key_event.physical_keycode | ||
|
||
var keycode_string := OS.get_keycode_string(keycode) | ||
if keycode in [ KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT ]: | ||
keycode_string = "ARROW " + keycode_string | ||
|
||
if keycode_string.is_empty(): | ||
keycode_string = "[UNKNOWN]" | ||
key_bits.append(keycode_string) | ||
|
||
return " + ".join(key_bits) | ||
|
||
return first_event.as_text() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://cinwiem08gkak"] | ||
|
||
[ext_resource type="Script" path="res://gui/components/help/ShortcutLine.gd" id="1_06v85"] | ||
|
||
[node name="ShortcutLine" type="HBoxContainer"] | ||
auto_translate_mode = 1 | ||
anchors_preset = 10 | ||
anchor_right = 1.0 | ||
offset_bottom = 28.0 | ||
grow_horizontal = 2 | ||
script = ExtResource("1_06v85") | ||
|
||
[node name="KeyLabel" type="Label" parent="."] | ||
auto_translate_mode = 1 | ||
layout_mode = 2 | ||
size_flags_horizontal = 0 | ||
theme_type_variation = &"ShortcutLabelAccented" | ||
text = "[UNBOUND]" | ||
uppercase = true | ||
|
||
[node name="Filler" type="Control" parent="."] | ||
auto_translate_mode = 1 | ||
custom_minimum_size = Vector2(12, 0) | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
|
||
[node name="DescriptionLabel" type="Label" parent="."] | ||
auto_translate_mode = 1 | ||
layout_mode = 2 | ||
size_flags_horizontal = 0 | ||
theme_type_variation = &"ShortcutLabel" | ||
text = "Description" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.