From 5c9bac222bb26109f06234c3270fcd177681fe97 Mon Sep 17 00:00:00 2001 From: Johannes Ringler Date: Wed, 3 Jan 2024 15:56:08 +0100 Subject: [PATCH] improve portal edit UX ability to cancel adding a portal as well as removing existing portal closes #94. --- CHANGELOG.md | 1 + .../layout/track/directed_layout_track.gd | 7 +++++++ .../layout/track/layout_section_inspector.gd | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5468312..7dab894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Added - Added "disable train" setting for blocks. Any train in a block with this setting enabled will not be connected via bluetooth. Layout Controllers will only need to connect when a device is assigned to one of it's ports. (https://github.com/Novakasa/brickrail/issues/161) +- Improved Portal UX. Made add portal process cancellable, added option to remove the Portal again (https://github.com/Novakasa/brickrail/issues/94). ### Fixed diff --git a/brickrail-gui/layout/track/directed_layout_track.gd b/brickrail-gui/layout/track/directed_layout_track.gd index 221ad6e..fc846ca 100644 --- a/brickrail-gui/layout/track/directed_layout_track.gd +++ b/brickrail-gui/layout/track/directed_layout_track.gd @@ -519,6 +519,13 @@ func has_portal(): if not is_continuous_to(connections[turn], turn): return true return false + +func remove_portal(first_call=true): + for turn in connections: + if not is_continuous_to(connections[turn], turn): + if first_call: + connections[turn].get_opposite().remove_portal(false) + disconnect_turn(turn) func get_shader_state(turn): var state = 0 diff --git a/brickrail-gui/layout/track/layout_section_inspector.gd b/brickrail-gui/layout/track/layout_section_inspector.gd index 70d0d3a..8b2a54c 100644 --- a/brickrail-gui/layout/track/layout_section_inspector.gd +++ b/brickrail-gui/layout/track/layout_section_inspector.gd @@ -7,6 +7,9 @@ func _enter_tree(): var _err = LayoutInfo.connect("layout_mode_changed", self, "_on_layout_mode_changed") func _on_layout_mode_changed(mode): + if mode == "edit": + # if portal is added + _on_section_track_added(null) if mode == "control": section.unselect() @@ -38,6 +41,10 @@ func _on_section_track_added(_track): update_speed_select() if dirtrack.get_next() == null: $AddPortal.visible=true + $AddPortal.text = "Add portal" + elif dirtrack.has_portal(): + $AddPortal.visible=true + $AddPortal.text = "Remove portal" else: $AddPortal.visible=false $FacingFilterSelector.visible=true @@ -140,8 +147,16 @@ func _on_OneWayCheckbox_toggled(button_pressed): section.tracks[0].set_one_way(button_pressed) func _on_AddPortal_pressed(): - LayoutInfo.set_portal_dirtrack(dirtrack) - LayoutInfo.set_layout_mode("portal") + if section.tracks[0].has_portal(): + section.tracks[0].remove_portal() + _on_section_track_added(null) + elif LayoutInfo.layout_mode != "portal": + LayoutInfo.set_portal_dirtrack(dirtrack) + LayoutInfo.set_layout_mode("portal") + $AddPortal.text = "Cancel portal" + else: + LayoutInfo.set_layout_mode("edit") + $AddPortal.text = "Add portal" func _on_FacingFilterSelector_meta_selected(meta): section.tracks[0].set_facing_filter(meta)