From 0443f3267f770f4181e82e422c79d303226f9995 Mon Sep 17 00:00:00 2001 From: Johannes Ringler Date: Thu, 17 Aug 2023 14:01:28 +0200 Subject: [PATCH] tweak reverse entry marker UX closes #133 --- CHANGELOG.md | 3 +- .../layout/block/layout_block_inspector.gd | 37 +++++- .../layout/block/layout_block_inspector.tscn | 120 +++++++++++------- .../layout/block/layout_logical_block.gd | 6 + 4 files changed, 114 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e56063..d232585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ ### Added -- Sensors associated with a selected logical block are now highlighted. +- Improved reverse entry marker UX. User can remove the marker and cancel adding one (https://github.com/Novakasa/brickrail/issues/133). +- Markers associated with a selected logical block are now highlighted. - Trains and Blocks can now be renamed by clicking their names in the inspector (https://github.com/Novakasa/brickrail/issues/122). - Added debug color buffer and plot written to file after unexpected Marker (https://github.com/Novakasa/brickrail/issues/144) - Spacebar now triggers emergency stop. For the extra urgent emergencies. diff --git a/brickrail-gui/layout/block/layout_block_inspector.gd b/brickrail-gui/layout/block/layout_block_inspector.gd index 7d5ec83..a1e1253 100644 --- a/brickrail-gui/layout/block/layout_block_inspector.gd +++ b/brickrail-gui/layout/block/layout_block_inspector.gd @@ -7,10 +7,12 @@ func _enter_tree(): var _err = LayoutInfo.connect("layout_mode_changed", self, "_on_layout_mode_changed") func _on_layout_mode_changed(mode): - var edit_exclusive_nodes = [$AddTrain, $AddPriorSensorButton, $CanStopCheckBox, $CanFlipCheckBox] + var edit_exclusive_nodes = [$AddTrain, $PriorPanel, $PriorLabel, $CanStopCheckBox, $CanFlipCheckBox] for node in edit_exclusive_nodes: node.visible = (mode != "control") + + update_prior_panel() func set_block(p_block): block = p_block @@ -21,8 +23,24 @@ func set_block(p_block): $CanFlipCheckBox.pressed = block.can_flip $RandomTargetCheckBox.pressed = block.random_target $HBoxContainer/WaitTimeEdit.value = block.wait_time + update_prior_panel() _on_layout_mode_changed(LayoutInfo.layout_mode) +func update_prior_panel(): + if block.get_prior_sensor_dirtrack() == null: + if LayoutInfo.layout_mode == "prior_sensor": + $PriorPanel/AddPriorButton.disabled = true + $PriorPanel/RemovePriorButton.disabled = true + $PriorPanel/CancelPriorButton.disabled = false + return + $PriorPanel/AddPriorButton.disabled = false + $PriorPanel/RemovePriorButton.disabled = true + $PriorPanel/CancelPriorButton.disabled = true + return + $PriorPanel/AddPriorButton.disabled = true + $PriorPanel/RemovePriorButton.disabled = false + $PriorPanel/CancelPriorButton.disabled = true + func _on_block_unselected(): queue_free() @@ -37,10 +55,6 @@ func _on_AddTrainDialog_confirmed(): var train: LayoutTrain = LayoutInfo.create_train() train.set_current_block(block) -func _on_AddPriorSensorButton_pressed(): - LayoutInfo.set_layout_mode("prior_sensor") - - func _on_CanStopCheckBox_toggled(button_pressed): if block.can_stop != button_pressed: LayoutInfo.set_layout_changed(true) @@ -60,4 +74,15 @@ func _on_WaitTimeEdit_value_changed(value): func _on_EditableLabel_text_changed(text): LayoutInfo.blocks[block.block_id].set_name(text) $EditableLabel.set_display_text(block.get_name()) - + +func _on_AddPriorSensorButton_pressed(): + LayoutInfo.set_layout_mode("prior_sensor") + update_prior_panel() + +func _on_RemovePriorButton_pressed(): + block.disconnect_prior_sensor_dirtrack() + update_prior_panel() + +func _on_CancelPriorButton_pressed(): + LayoutInfo.set_layout_mode("edit") + update_prior_panel() diff --git a/brickrail-gui/layout/block/layout_block_inspector.tscn b/brickrail-gui/layout/block/layout_block_inspector.tscn index db2197b..faa87e9 100644 --- a/brickrail-gui/layout/block/layout_block_inspector.tscn +++ b/brickrail-gui/layout/block/layout_block_inspector.tscn @@ -9,23 +9,88 @@ margin_bottom = 40.0 script = ExtResource( 1 ) [node name="EditableLabel" type="VBoxContainer" parent="."] -margin_right = 175.0 +margin_right = 183.0 script = ExtResource( 2 ) [node name="AddTrain" type="Button" parent="."] margin_top = 4.0 -margin_right = 175.0 +margin_right = 183.0 margin_bottom = 24.0 text = "Add train" __meta__ = { "_edit_use_anchors_": false } -[node name="AddPriorSensorButton" type="Button" parent="."] +[node name="PriorLabel" type="Label" parent="."] margin_top = 28.0 -margin_right = 175.0 -margin_bottom = 48.0 -text = "Add reverse entry marker" +margin_right = 183.0 +margin_bottom = 42.0 +text = "Reverse Entry Marker" + +[node name="PriorPanel" type="HBoxContainer" parent="."] +margin_top = 46.0 +margin_right = 183.0 +margin_bottom = 66.0 + +[node name="AddPriorButton" type="Button" parent="PriorPanel"] +margin_right = 37.0 +margin_bottom = 20.0 +text = "Add" + +[node name="RemovePriorButton" type="Button" parent="PriorPanel"] +margin_left = 41.0 +margin_right = 125.0 +margin_bottom = 20.0 +text = "Disconnect" + +[node name="CancelPriorButton" type="Button" parent="PriorPanel"] +margin_left = 129.0 +margin_right = 183.0 +margin_bottom = 20.0 +text = "Cancel" + +[node name="ControlLabel" type="Label" parent="."] +margin_top = 70.0 +margin_right = 183.0 +margin_bottom = 84.0 +text = "Train control" + +[node name="CanStopCheckBox" type="CheckBox" parent="."] +margin_top = 88.0 +margin_right = 183.0 +margin_bottom = 112.0 +pressed = true +text = "Can stop" + +[node name="CanFlipCheckBox" type="CheckBox" parent="."] +margin_top = 116.0 +margin_right = 183.0 +margin_bottom = 140.0 +pressed = true +text = "Can reverse" + +[node name="RandomTargetCheckBox" type="CheckBox" parent="."] +margin_top = 144.0 +margin_right = 183.0 +margin_bottom = 168.0 +text = "Random target" + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_top = 172.0 +margin_right = 183.0 +margin_bottom = 196.0 + +[node name="Label" type="Label" parent="HBoxContainer"] +margin_top = 5.0 +margin_right = 82.0 +margin_bottom = 19.0 +text = "Wait time [s]" + +[node name="WaitTimeEdit" type="SpinBox" parent="HBoxContainer"] +margin_left = 86.0 +margin_right = 160.0 +margin_bottom = 24.0 +max_value = 100000.0 [node name="AddTrainDialog" type="ConfirmationDialog" parent="."] margin_top = 42.0 @@ -65,48 +130,13 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="CanStopCheckBox" type="CheckBox" parent="."] -margin_top = 52.0 -margin_right = 175.0 -margin_bottom = 76.0 -pressed = true -text = "Can stop" - -[node name="CanFlipCheckBox" type="CheckBox" parent="."] -margin_top = 80.0 -margin_right = 175.0 -margin_bottom = 104.0 -pressed = true -text = "Can reverse" - -[node name="RandomTargetCheckBox" type="CheckBox" parent="."] -margin_top = 108.0 -margin_right = 175.0 -margin_bottom = 132.0 -text = "Random target" - -[node name="HBoxContainer" type="HBoxContainer" parent="."] -margin_top = 136.0 -margin_right = 175.0 -margin_bottom = 160.0 - -[node name="Label" type="Label" parent="HBoxContainer"] -margin_top = 5.0 -margin_right = 82.0 -margin_bottom = 19.0 -text = "Wait time [s]" - -[node name="WaitTimeEdit" type="SpinBox" parent="HBoxContainer"] -margin_left = 86.0 -margin_right = 160.0 -margin_bottom = 24.0 -max_value = 100000.0 - [connection signal="text_changed" from="EditableLabel" to="." method="_on_EditableLabel_text_changed"] [connection signal="pressed" from="AddTrain" to="." method="_on_AddTrain_pressed"] -[connection signal="pressed" from="AddPriorSensorButton" to="." method="_on_AddPriorSensorButton_pressed"] -[connection signal="confirmed" from="AddTrainDialog" to="." method="_on_AddTrainDialog_confirmed"] +[connection signal="pressed" from="PriorPanel/AddPriorButton" to="." method="_on_AddPriorSensorButton_pressed"] +[connection signal="pressed" from="PriorPanel/RemovePriorButton" to="." method="_on_RemovePriorButton_pressed"] +[connection signal="pressed" from="PriorPanel/CancelPriorButton" to="." method="_on_CancelPriorButton_pressed"] [connection signal="toggled" from="CanStopCheckBox" to="." method="_on_CanStopCheckBox_toggled"] [connection signal="toggled" from="CanFlipCheckBox" to="." method="_on_CanFlipCheckBox_toggled"] [connection signal="toggled" from="RandomTargetCheckBox" to="." method="_on_RandomTargetCheckBox_toggled"] [connection signal="value_changed" from="HBoxContainer/WaitTimeEdit" to="." method="_on_WaitTimeEdit_value_changed"] +[connection signal="confirmed" from="AddTrainDialog" to="." method="_on_AddTrainDialog_confirmed"] diff --git a/brickrail-gui/layout/block/layout_logical_block.gd b/brickrail-gui/layout/block/layout_logical_block.gd index 45a27d8..6987d4b 100644 --- a/brickrail-gui/layout/block/layout_logical_block.gd +++ b/brickrail-gui/layout/block/layout_logical_block.gd @@ -65,6 +65,12 @@ func add_prior_sensor_dirtrack(dirtrack): dirtrack.get_sensor().increment_highlight(1) LayoutInfo.set_layout_changed(true) +func disconnect_prior_sensor_dirtrack(): + assert(get_prior_sensor_dirtrack() != null) + if selected: + nodes[-1].sensors.sensor_dirtracks["enter"].get_sensor().increment_highlight(-1) + nodes[-1].sensors.set_sensor_dirtrack("enter", null) + func get_prior_sensor_dirtrack(): return nodes[-1].sensors.sensor_dirtracks["enter"]