Skip to content

Commit

Permalink
improve portal edit UX
Browse files Browse the repository at this point in the history
ability to cancel adding a portal as well as removing existing portal
closes #94.
  • Loading branch information
Novakasa committed Jan 3, 2024
1 parent 3e3f121 commit 5c9bac2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions brickrail-gui/layout/track/directed_layout_track.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions brickrail-gui/layout/track/layout_section_inspector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5c9bac2

Please sign in to comment.