From 18efa6ae3ce7f527f648b05115fe352f3a057b61 Mon Sep 17 00:00:00 2001 From: torsten Date: Fri, 30 Oct 2026 07:49:33 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Sections=20und=20Ghosting-UI=20f=C3=BCr?= =?UTF-8?q?=20das=20Whiteboard=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Abschnittsliste rechts mit Anlegen, Umbenennen, Löschen und Sortieren - aktive Section voll sichtbar, inaktive auf 20 % geghostet - Sequenznummern werden nach Änderungen neu durchnummeriert - Wechsel der Section verwirft die Segmentauswahl - Tests auf 231 Assertions erweitert --- docs/architecture.md | 14 +- rinkplanner/scenes/whiteboard/whiteboard.tscn | 136 ++++++++++++- .../whiteboard/ctrl/whiteboard_controller.gd | 188 +++++++++++++++++- .../src/whiteboard/view/rink_canvas.gd | 12 ++ rinkplanner/tests/run_whiteboard_tests.gd | 125 ++++++++++++ 5 files changed, 470 insertions(+), 5 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index 892ee9f..c4c2b6b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -108,6 +108,12 @@ eine Abkürzung. So kann die UI Fehler konkret anzeigen. Die Bogenparameter werden als `template`, `arc_depth_ratio` und `arc_bulge_left` am `PathSegment` gespeichert, damit die Kurve nach dem Editieren neu aufgebaut werden kann. +- **Section-Verwaltung:** Ein Panel rechts zeigt die chronologische + Abschnittsliste. Neue Sections werden angelegt, umbenannt, gelöscht und + hoch-/runtergeschoben; `sequence_order` wird nach jeder Änderung + durchnummeriert, die Section-IDs bleiben stabil. Die aktive Section wird + voll gezeichnet, alle anderen mit 20 % Deckkraft geghostet. Beim Wechsel + wird eine eventuelle Segmentauswahl verworfen. - **Darstellung:** vorwärts durchgezogen, rückwärts gestrichelt, außen rot, innen blau. Inaktive Sections werden mit 20 % Deckkraft geghostet. - **Ghosting** ist reine View-Logik: pro Section ein eigener Layer, @@ -159,9 +165,10 @@ Aktueller Stand: Template-Metadaten, Section-Aggregation und Routine-Validierung. - **Canvas:** 90 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan, Rink-Kontur und die reine Bogen-Geometrie. -- **Whiteboard:** 68 Assertions für Controller-Verdrahtung, Segmenterzeugung, +- **Whiteboard:** 96 Assertions für Controller-Verdrahtung, Segmenterzeugung, Linien-/Bogenpfade, Klemmen an der Bande, Auswahl, Griff-Bearbeitung, Undo, - Navigationsmodus und den Maus-Drag-Pfad. + Section-Verwaltung, Ghosting-Zustand, Navigationsmodus und den + Maus-Drag-Pfad. Visuelle Smoke-Tests laufen zusätzlich über `xvfb-run` und einen Viewport-Screenshot; sie ersetzen die headless Tests nicht. @@ -184,3 +191,6 @@ Viewport-Screenshot; sie ersetzen die headless Tests nicht. 6. **Segment-Verknüpfung:** Beim Verschieben eines Endpunkts werden Nachbarsegmente nicht automatisch mitgezogen. Ob Pfade später als zusammenhängende Kette editiert werden, ist offen. +7. **Section-Darstellung:** Die aktuelle Scrollliste funktioniert für wenige + Abschnitte. Bei langen Kürprogrammen ist zu prüfen, ob eine horizontale + Timeline mit Zeitproportionen die bessere Bedienung ist. diff --git a/rinkplanner/scenes/whiteboard/whiteboard.tscn b/rinkplanner/scenes/whiteboard/whiteboard.tscn index 670bba4..2d33d3e 100644 --- a/rinkplanner/scenes/whiteboard/whiteboard.tscn +++ b/rinkplanner/scenes/whiteboard/whiteboard.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3] +[gd_scene load_steps=8 format=3] [ext_resource type="Script" path="res://src/whiteboard/ctrl/whiteboard_controller.gd" id="1_controller"] [ext_resource type="Script" path="res://src/whiteboard/view/rink_canvas.gd" id="2_canvas"] @@ -24,6 +24,15 @@ bg_color = Color(0.0431373, 0.0705882, 0.12549, 1) border_width_top = 1 border_color = Color(0.121569, 0.160784, 0.219608, 1) +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sections"] +content_margin_left = 12.0 +content_margin_top = 12.0 +content_margin_right = 12.0 +content_margin_bottom = 12.0 +bg_color = Color(0.0588235, 0.0901961, 0.164706, 1) +border_width_left = 1 +border_color = Color(0.121569, 0.160784, 0.219608, 1) + [node name="Whiteboard" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -136,13 +145,106 @@ layout_mode = 2 theme_override_font_sizes/font_size = 16 text = "Einpassen" -[node name="RinkCanvas" type="Control" parent="Layout"] +[node name="Content" type="HBoxContainer" parent="Layout"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 0 + +[node name="RinkCanvas" type="Control" parent="Layout/Content"] unique_name_in_owner = true clip_contents = true layout_mode = 2 +size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource("2_canvas") +[node name="SectionsPanel" type="PanelContainer" parent="Layout/Content"] +custom_minimum_size = Vector2(300, 0) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_sections") + +[node name="SectionsVBox" type="VBoxContainer" parent="Layout/Content/SectionsPanel"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="Header" type="HBoxContainer" parent="Layout/Content/SectionsPanel/SectionsVBox"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="SectionsTitle" type="Label" parent="Layout/Content/SectionsPanel/SectionsVBox/Header"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.882353, 0.909804, 0.941176, 1) +theme_override_font_sizes/font_size = 18 +text = "Abschnitte" +vertical_alignment = 1 + +[node name="HeaderSpacer" type="Control" parent="Layout/Content/SectionsPanel/SectionsVBox/Header"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="AddSectionButton" type="Button" parent="Layout/Content/SectionsPanel/SectionsVBox/Header"] +unique_name_in_owner = true +custom_minimum_size = Vector2(48, 48) +layout_mode = 2 +theme_override_font_sizes/font_size = 20 +text = "+" +tooltip_text = "Abschnitt hinzufügen" + +[node name="SectionScroll" type="ScrollContainer" parent="Layout/Content/SectionsPanel/SectionsVBox"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 + +[node name="SectionList" type="VBoxContainer" parent="Layout/Content/SectionsPanel/SectionsVBox/SectionScroll"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 6 + +[node name="Footer" type="VBoxContainer" parent="Layout/Content/SectionsPanel/SectionsVBox"] +layout_mode = 2 +theme_override_constants/separation = 6 + +[node name="MoveRow" type="HBoxContainer" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer"] +layout_mode = 2 +theme_override_constants/separation = 6 + +[node name="MoveUpButton" type="Button" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer/MoveRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 48) +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 14 +text = "Hoch" + +[node name="MoveDownButton" type="Button" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer/MoveRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 48) +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 14 +text = "Runter" + +[node name="EditRow" type="HBoxContainer" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer"] +layout_mode = 2 +theme_override_constants/separation = 6 + +[node name="RenameButton" type="Button" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer/EditRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 48) +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 14 +text = "Umbenennen" + +[node name="DeleteButton" type="Button" parent="Layout/Content/SectionsPanel/SectionsVBox/Footer/EditRow"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 48) +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 14 +text = "Löschen" + [node name="StatusBar" type="PanelContainer" parent="Layout"] custom_minimum_size = Vector2(0, 32) layout_mode = 2 @@ -155,3 +257,33 @@ theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1) theme_override_font_sizes/font_size = 14 text = "Abschnitt 1 · 0 Segmente" vertical_alignment = 1 + +[node name="RenameDialog" type="ConfirmationDialog" parent="."] +unique_name_in_owner = true +title = "Abschnitt umbenennen" +size = Vector2i(420, 190) +ok_button_text = "Übernehmen" +cancel_button_text = "Abbrechen" + +[node name="RenameBox" type="VBoxContainer" parent="RenameDialog"] +offset_left = 8.0 +offset_top = 8.0 +offset_right = 412.0 +offset_bottom = 120.0 +theme_override_constants/separation = 8 + +[node name="RenameLabel" type="Label" parent="RenameDialog/RenameBox"] +layout_mode = 2 +text = "Neuer Name" + +[node name="RenameEdit" type="LineEdit" parent="RenameDialog/RenameBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 48) +layout_mode = 2 + +[node name="DeleteDialog" type="ConfirmationDialog" parent="."] +unique_name_in_owner = true +title = "Abschnitt löschen" +size = Vector2i(460, 160) +ok_button_text = "Löschen" +cancel_button_text = "Abbrechen" diff --git a/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd b/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd index 204026f..0307a21 100644 --- a/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd +++ b/rinkplanner/src/whiteboard/ctrl/whiteboard_controller.gd @@ -24,12 +24,23 @@ const EPSILON := 0.0001 @onready var undo_button: Button = %UndoButton @onready var fit_button: Button = %FitButton @onready var status_label: Label = %StatusLabel +@onready var section_list: VBoxContainer = %SectionList +@onready var add_section_button: Button = %AddSectionButton +@onready var move_up_button: Button = %MoveUpButton +@onready var move_down_button: Button = %MoveDownButton +@onready var rename_button: Button = %RenameButton +@onready var delete_button: Button = %DeleteButton +@onready var rename_dialog: ConfirmationDialog = %RenameDialog +@onready var rename_edit: LineEdit = %RenameEdit +@onready var delete_dialog: ConfirmationDialog = %DeleteDialog var _routine: Routine var _active_section: RoutineSection var _current_segment: PathSegment var _selected_segment_id: String = "" var _segment_counter: int = 0 +var _section_counter: int = 1 +var _section_buttons: Dictionary[String, Button] = {} var _tool: Tool = Tool.LINE var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD var _edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE @@ -42,7 +53,7 @@ func _ready() -> void: _routine.rink = RinkDimensions.new() _active_section = RoutineSection.new() - _active_section.section_id = "section-1" + _active_section.section_id = "section-001" _active_section.title = "Abschnitt 1" _active_section.sequence_order = 0 @@ -66,6 +77,13 @@ func _ready() -> void: outside_button.pressed.connect(_on_edge_pressed.bind(PathSegment.Edge.OUTSIDE)) undo_button.pressed.connect(undo_last_segment) fit_button.pressed.connect(rink_canvas.fit_rink) + add_section_button.pressed.connect(add_section) + move_up_button.pressed.connect(_move_active_section.bind(-1)) + move_down_button.pressed.connect(_move_active_section.bind(1)) + rename_button.pressed.connect(_open_rename_dialog) + delete_button.pressed.connect(_open_delete_dialog) + rename_dialog.confirmed.connect(_on_rename_confirmed) + delete_dialog.confirmed.connect(_on_delete_confirmed) rink_canvas.draw_started.connect(_on_draw_started) rink_canvas.draw_updated.connect(_on_draw_updated) @@ -77,6 +95,7 @@ func _ready() -> void: rink_canvas.segment_handle_dragged.connect(_on_handle_dragged) rink_canvas.segment_handle_drag_finished.connect(_on_handle_drag_finished) + _rebuild_section_list() _update_status() @@ -96,6 +115,99 @@ func get_selected_segment() -> PathSegment: return _find_segment(_selected_segment_id) +func add_section() -> RoutineSection: + _section_counter += 1 + + var section := RoutineSection.new() + section.section_id = "section-%03d" % _section_counter + section.title = "Abschnitt %d" % _section_counter + section.sequence_order = _routine.sections.size() + + _routine.sections.append(section) + _renumber_sections() + _rebuild_section_list() + set_active_section(section.section_id) + return section + + +func set_active_section(section_id: String) -> void: + var section := _routine.get_section_by_id(section_id) + if section == null: + return + + rink_canvas.cancel_interaction() + _active_section = section + _selected_segment_id = "" + rink_canvas.set_selected_segment("") + rink_canvas.set_active_section(section.section_id) + _update_section_buttons() + _update_status() + + +func rename_section(section_id: String, new_title: String) -> bool: + var section := _routine.get_section_by_id(section_id) + var title := new_title.strip_edges() + if section == null or title.is_empty(): + return false + + section.title = title + _rebuild_section_list() + _update_status() + return true + + +func delete_section(section_id: String) -> bool: + if _routine.sections.size() <= 1: + return false + + var index := _find_section_index(section_id) + if index < 0: + return false + + var was_active := section_id == _active_section.section_id + _routine.sections.remove_at(index) + _renumber_sections() + + if was_active: + var next_index := clampi(index, 0, _routine.sections.size() - 1) + _rebuild_section_list() + set_active_section(_routine.sections[next_index].section_id) + else: + _rebuild_section_list() + _update_status() + return true + + +func move_section(section_id: String, delta: int) -> bool: + var index := _find_section_index(section_id) + if index < 0: + return false + + var target := clampi(index + delta, 0, _routine.sections.size() - 1) + if target == index: + return false + + var section: RoutineSection = _routine.sections[index] + _routine.sections.remove_at(index) + _routine.sections.insert(target, section) + _renumber_sections() + _rebuild_section_list() + _update_status() + return true + + +func _find_section_index(section_id: String) -> int: + for index: int in range(_routine.sections.size()): + if _routine.sections[index].section_id == section_id: + return index + return -1 + + +func _renumber_sections() -> void: + for index: int in range(_routine.sections.size()): + _routine.sections[index].sequence_order = index + + ## Selects a segment programmatically and switches to the select tool. func select_segment(segment_id: String) -> void: if _find_segment(segment_id) == null: @@ -408,6 +520,80 @@ func _update_duration(segment: PathSegment) -> void: ) +func _rebuild_section_list() -> void: + for child: Node in section_list.get_children(): + child.free() + _section_buttons.clear() + + for index: int in range(_routine.sections.size()): + var section: RoutineSection = _routine.sections[index] + var button := Button.new() + button.toggle_mode = true + button.button_pressed = section.section_id == _active_section.section_id + button.text = "%d · %s" % [index + 1, section.title] + button.tooltip_text = section.title + button.custom_minimum_size = Vector2(0.0, 48.0) + button.alignment = HORIZONTAL_ALIGNMENT_LEFT + button.clip_text = true + button.pressed.connect(_on_section_button_pressed.bind(section.section_id)) + section_list.add_child(button) + _section_buttons[section.section_id] = button + + _update_section_buttons() + + +func _update_section_buttons() -> void: + for section_id: String in _section_buttons.keys(): + var button: Button = _section_buttons[section_id] + button.set_pressed_no_signal(section_id == _active_section.section_id) + + var active_index := _find_section_index(_active_section.section_id) + move_up_button.disabled = active_index <= 0 + move_down_button.disabled = ( + active_index < 0 or active_index >= _routine.sections.size() - 1 + ) + delete_button.disabled = _routine.sections.size() <= 1 + + +func _on_section_button_pressed(section_id: String) -> void: + set_active_section(section_id) + + +func _move_active_section(delta: int) -> void: + if _active_section != null: + move_section(_active_section.section_id, delta) + + +func _open_rename_dialog() -> void: + if _active_section == null: + return + rename_edit.text = _active_section.title + rename_dialog.popup_centered(Vector2i(420, 190)) + rename_edit.grab_focus() + rename_edit.select_all() + + +func _on_rename_confirmed() -> void: + if _active_section == null: + return + rename_section(_active_section.section_id, rename_edit.text) + + +func _open_delete_dialog() -> void: + if _active_section == null or _routine.sections.size() <= 1: + return + delete_dialog.dialog_text = "Abschnitt \"%s\" mit %d Segmenten löschen?" % [ + _active_section.title, + _active_section.segments.size(), + ] + delete_dialog.popup_centered(Vector2i(460, 170)) + + +func _on_delete_confirmed() -> void: + if _active_section != null: + delete_section(_active_section.section_id) + + func _update_status() -> void: if _routine == null or _active_section == null: return diff --git a/rinkplanner/src/whiteboard/view/rink_canvas.gd b/rinkplanner/src/whiteboard/view/rink_canvas.gd index 49de411..f27eeaf 100644 --- a/rinkplanner/src/whiteboard/view/rink_canvas.gd +++ b/rinkplanner/src/whiteboard/view/rink_canvas.gd @@ -104,6 +104,10 @@ func set_active_section(section_id: String) -> void: queue_redraw() +func get_active_section_id() -> String: + return _active_section_id + + func set_drawing_enabled(enabled: bool) -> void: drawing_enabled = enabled if not enabled: @@ -124,6 +128,14 @@ func set_selected_segment(segment_id: String) -> void: queue_redraw() +## Aborts any in-progress draw/handle gesture and clears the selection. +func cancel_interaction() -> void: + _abort_handle_drag() + _cancel_drawing() + _panning = false + _clear_selection() + + func get_selected_segment_id() -> String: return _selected_segment_id diff --git a/rinkplanner/tests/run_whiteboard_tests.gd b/rinkplanner/tests/run_whiteboard_tests.gd index cd1a5d0..0488762 100644 --- a/rinkplanner/tests/run_whiteboard_tests.gd +++ b/rinkplanner/tests/run_whiteboard_tests.gd @@ -340,6 +340,131 @@ func _run() -> void: ) controller.set_tool(WhiteboardController.Tool.LINE) + # Section management and ghosting state. + var first_section_id := section.section_id + var first_segment_count := section.segments.size() + var second_section := controller.add_section() + _check(routine.sections.size() == 2, "add_section appends a section") + _check( + controller.get_active_section() == second_section, + "a new section becomes active" + ) + _check( + second_section.sequence_order == 1, + "new section is ordered after the first" + ) + _check(second_section.segments.is_empty(), "new section starts empty") + _check( + controller.section_list.get_child_count() == 2, + "section list builds one button per section" + ) + _check( + controller.rink_canvas.get_active_section_id() == second_section.section_id, + "canvas switches to the new active section" + ) + _check( + controller.status_label.text.contains("Abschnitt 2"), + "status bar shows the new active section" + ) + + controller.add_segment( + Vector2(-5.0, 10.0), + Vector2(5.0, 10.0), + PathSegment.Direction.FORWARD, + PathSegment.Edge.OUTSIDE + ) + _check( + second_section.segments.size() == 1, + "segments go into the active section" + ) + _check( + section.segments.size() == first_segment_count, + "other sections keep their segments" + ) + + controller.set_active_section(first_section_id) + _check( + controller.get_active_section() == section, + "switching sections changes the active section" + ) + _check( + controller.get_selected_segment() == null, + "switching sections clears the segment selection" + ) + _check( + controller.rink_canvas.get_active_section_id() == first_section_id, + "canvas follows the switched section" + ) + + _check( + controller.rename_section(first_section_id, "Eröffnung"), + "section can be renamed" + ) + _check( + section.title == "Eröffnung", + "rename updates the section title" + ) + var first_button := controller.section_list.get_child(0) as Button + _check( + first_button.text.contains("Eröffnung"), + "section list shows the new title" + ) + + _check( + controller.move_section(first_section_id, 1), + "section can be moved down" + ) + _check( + routine.sections[0] == second_section and routine.sections[1] == section, + "moving reorders the routine sections" + ) + _check( + routine.sections[0].sequence_order == 0 + and routine.sections[1].sequence_order == 1, + "sequence orders are renumbered after moving" + ) + _check( + controller.get_active_section() == section, + "moving a section keeps it active" + ) + + _check( + controller.move_section(first_section_id, -1), + "section can be moved up again" + ) + _check(routine.sections[0] == section, "moving up restores the order") + + _check( + controller.delete_section(second_section.section_id), + "a non-active section can be deleted" + ) + _check(routine.sections.size() == 1, "delete removes the section") + _check( + controller.get_active_section() == section, + "deleting a non-active section keeps the active one" + ) + _check( + not controller.delete_section(first_section_id), + "the last remaining section cannot be deleted" + ) + + var third_section := controller.add_section() + _check( + controller.delete_section(third_section.section_id), + "the active section can be deleted when another exists" + ) + _check( + controller.get_active_section() == section, + "deleting the active section falls back to the remaining one" + ) + + controller.rename_edit.text = "Testname" + controller.rename_dialog.confirmed.emit() + _check( + controller.get_active_section().title == "Testname", + "rename dialog applies the edited title" + ) + scene.queue_free() await process_frame _finish()