-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlyric.gd
102 lines (85 loc) · 2.63 KB
/
lyric.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
class_name Lyric
extends Control
var dragging : bool = false
var bar : float:
set(value):
bar = value
if chart != null: position.x = chart.bar_to_x(bar)
var text : String:
set(value):
text = value
# if line_edit != null: line_edit.text = value
@onready var line_edit : LineEdit = $LineEdit
@onready var editor = get_parent()
@onready var chart = editor.chart
@onready var chart_view = chart.get_parent()
var is_in_view : bool:
get: return position.x + size.x >= chart.scroll_position \
&& position.x + line_edit.size.x <= chart.scroll_end
func _ready() -> void:
line_edit.text = text
position.x = chart.bar_to_x(bar)
func _draw() -> void:
draw_polyline_colors([Vector2.ZERO,Vector2(0, size.y)],
[Color.TRANSPARENT,Color.PURPLE],2.0
)
func _on_line_edit_text_changed(new_text) -> void: text = new_text
func _on_delete_button_pressed() -> void:
queue_free()
Global.working_tmb.lyrics = editor.package_lyrics()
editor._refresh_lyrics()
func _process(_delta) -> void:
if !dragging: return
if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
dragging = false
return
var pos = chart.get_local_mouse_position()
bar = chart.to_snapped(pos).x
func _on_drag_handle_gui_input(event) -> void:
event = event as InputEventMouseButton
if event == null || event.button_index != MOUSE_BUTTON_LEFT || !event.pressed: return
dragging = true
func scroll_to_lyric(offset : float = 1.0) -> void:
offset = chart.bar_to_x(offset)
chart_view.set_h_scroll(int(position.x - offset))
chart.redraw_notes()
chart.queue_redraw()
func _on_line_edit_gui_input(event:InputEvent) -> void:
if event is InputEventKey:
if not event.pressed:
return
var snap_value = 1.0 / Global.settings.timing_snap
match event.keycode:
KEY_UP:
bar += snap_value
KEY_DOWN:
bar -= snap_value
KEY_ENTER:
var new_lyric : Lyric
var new_bar : float
if editor.enter_mode == 0:
var notes = chart.get_children()
notes.sort_custom(func(a, b): return a.position.x < b.position.x)
var next_note : Note
for note in notes:
if note is not Note: continue
if note.bar > bar:
next_note = note
break
if next_note:
new_bar = next_note.bar
if !new_bar:
new_bar = snapped(bar + snap_value, snap_value)
if new_bar >= Global.working_tmb.endpoint:
return
for lyric in editor.get_children():
if lyric.bar == new_bar:
if !lyric.is_in_view:
lyric.scroll_to_lyric()
lyric.line_edit.grab_focus()
return
new_lyric = editor._add_lyric(new_bar, "")
new_lyric.line_edit.grab_focus()
func _on_line_edit_focus_entered() -> void:
if !is_in_view:
scroll_to_lyric()