diff --git a/CHANGELOG.md b/CHANGELOG.md index 673da33..d375c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ### 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) + ### Fixed - Don't allow adding train to occupied block. This previously created invalid state. diff --git a/brickrail-gui/ble/ble_controller.gd b/brickrail-gui/ble/ble_controller.gd index 76d3c5a..5e2ca08 100644 --- a/brickrail-gui/ble/ble_controller.gd +++ b/brickrail-gui/ble/ble_controller.gd @@ -75,6 +75,8 @@ func are_hubs_ready(): if not $BLECommunicator.connected: return false for hub in hubs.values(): + if not hub.active: + continue if not hub.running: return false return true @@ -82,6 +84,8 @@ func are_hubs_ready(): func get_hub_status(): var status = {} for hub in hubs.values(): + if not hub.active: + continue if hub.busy: status[hub.name] = hub.status return status @@ -124,6 +128,8 @@ func clean_exit_coroutine(): func connect_and_run_all_coroutine(): yield(Devices.get_tree(), "idle_frame") for hub in hubs.values(): + if not hub.active: + continue if not hub.connected: var result = yield(hub.connect_coroutine(), "completed") if result == "error": diff --git a/brickrail-gui/ble/ble_hub.gd b/brickrail-gui/ble/ble_hub.gd index d58ab54..f6b008d 100644 --- a/brickrail-gui/ble/ble_hub.gd +++ b/brickrail-gui/ble/ble_hub.gd @@ -12,6 +12,7 @@ var busy = false var status = "disconnected" var battery_voltage = -1.0 var battery_current = -1.0 +var active = false var storage = {} @@ -32,6 +33,7 @@ signal removing(name) signal state_changed() signal battery_changed() signal skip_download_changed(value) +signal active_changed(p_active) func set_skip_download(value): skip_download = value @@ -88,6 +90,10 @@ func _on_ble_communicator_status_changed(): func set_responsiveness(val): responsiveness = val emit_signal("responsiveness_changed", val) + +func set_active(p_active): + active = p_active + emit_signal("active_changed", p_active) func set_name(p_new_name): var old_name = name diff --git a/brickrail-gui/ble/hub_control_gui.tscn b/brickrail-gui/ble/hub_control_gui.tscn index 72e5ec8..7304cbc 100644 --- a/brickrail-gui/ble/hub_control_gui.tscn +++ b/brickrail-gui/ble/hub_control_gui.tscn @@ -14,28 +14,38 @@ scan_button = NodePath("HBoxContainer2/scan_button") [node name="HBoxContainer2" type="HBoxContainer" parent="."] margin_right = 237.0 -margin_bottom = 20.0 +margin_bottom = 40.0 + +[node name="ActiveButton" type="CheckButton" parent="HBoxContainer2"] +margin_right = 76.0 +margin_bottom = 40.0 +hint_tooltip = "Indicates whether hub will be connected via bluetooth when \"control devices\" is turned on. +This is set automatically when the hub is assigned to a train and the train is not in a \"disable train\" block. +Is also set automatically when a switch or crossing motor is assigned to a port of this hub." +button_mask = 0 [node name="BatteryLabel" type="Label" parent="HBoxContainer2"] -margin_top = 3.0 -margin_bottom = 17.0 +margin_left = 80.0 +margin_top = 13.0 +margin_right = 80.0 +margin_bottom = 27.0 [node name="Control" type="Control" parent="HBoxContainer2"] -margin_left = 4.0 +margin_left = 84.0 margin_right = 143.0 -margin_bottom = 20.0 +margin_bottom = 40.0 size_flags_horizontal = 3 [node name="scan_button" type="Button" parent="HBoxContainer2"] margin_left = 147.0 margin_right = 237.0 -margin_bottom = 20.0 +margin_bottom = 40.0 text = "Scan for hub" [node name="HBoxContainer" type="HBoxContainer" parent="."] -margin_top = 24.0 +margin_top = 44.0 margin_right = 237.0 -margin_bottom = 48.0 +margin_bottom = 68.0 [node name="connect_button" type="Button" parent="HBoxContainer"] margin_right = 64.0 diff --git a/brickrail-gui/ble/hub_controls.gd b/brickrail-gui/ble/hub_controls.gd index 220ecdb..f54515a 100644 --- a/brickrail-gui/ble/hub_controls.gd +++ b/brickrail-gui/ble/hub_controls.gd @@ -12,13 +12,18 @@ func setup(p_hub): _on_hubs_state_changed() _err = hub.connect("battery_changed", self, "_on_hub_battery_changed") _err = hub.connect("skip_download_changed", self, "_on_hub_skip_download_changed") + _err = hub.connect("active_changed", self, "_on_hub_active_changed") $HBoxContainer/DownloadCheckbox.pressed = not hub.skip_download + $HBoxContainer2/ActiveButton.pressed = hub.active func _on_hub_skip_download_changed(value): $HBoxContainer/DownloadCheckbox.pressed = not value func _on_hub_battery_changed(): - $HBoxContainer2/BatteryLabel.text = ("Battery %.2f" % hub.battery_voltage) + "V" + $HBoxContainer2/BatteryLabel.text = ("%.2f" % hub.battery_voltage) + "V" + +func _on_hub_active_changed(p_active): + $HBoxContainer2/ActiveButton.pressed = p_active func _on_hubs_state_changed(): var controller = Devices.get_ble_controller() diff --git a/brickrail-gui/brickrail-layouts/ro_4trains.brl b/brickrail-gui/brickrail-layouts/ro_4trains.brl index 9ce665c..a401b89 100644 --- a/brickrail-gui/brickrail-layouts/ro_4trains.brl +++ b/brickrail-gui/brickrail-layouts/ro_4trains.brl @@ -1644,6 +1644,243 @@ "center" ] } + }, + { + "l_idx": 2, + "x_idx": 5, + "y_idx": 1, + "connections": { + "E": [ + + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 5, + "y_idx": 2, + "connections": { + "E": [ + + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 5, + "y_idx": 3, + "connections": { + "E": [ + + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 2, + "x_idx": 1, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + + ] + } + }, + { + "l_idx": 2, + "x_idx": 1, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + + ] + } + }, + { + "l_idx": 2, + "x_idx": 1, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + + ] + } } ], "blocks": [ @@ -1699,6 +1936,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -1753,6 +1994,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -1807,6 +2052,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -1861,6 +2110,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -1915,6 +2168,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -1962,6 +2219,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -2009,6 +2270,10 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false } }, { @@ -2056,6 +2321,163 @@ "wait_time": { "0": 4, "1": 4 + }, + "disable_train": { + "0": false, + "1": false + } + }, + { + "block_name": "shed1", + "section": { + "tracks": [ + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": true, + "1": true + } + }, + { + "block_name": "shed2", + "section": { + "tracks": [ + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": true, + "1": true + } + }, + { + "block_name": "shed3", + "section": { + "tracks": [ + { + "l_idx": 2, + "x_idx": 2, + "y_idx": 3, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 3, + "y_idx": 3, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 2, + "x_idx": 4, + "y_idx": 3, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": true, + "1": true } } ], diff --git a/brickrail-gui/brickrail-layouts/test-hub-active.brl b/brickrail-gui/brickrail-layouts/test-hub-active.brl new file mode 100644 index 0000000..6bcef03 --- /dev/null +++ b/brickrail-gui/brickrail-layouts/test-hub-active.brl @@ -0,0 +1,567 @@ +{ + "version": "1.0.0", + "devices": { + "trains": [ + { + "name": "city-blue", + "storage": { + "0": 3500, + "1": 40, + "2": 90, + "4": 40, + "5": 75, + "3": 100, + "6": 0 + } + } + ], + "controllers": [ + + ] + }, + "layout": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 5, + "connections": { + "E": [ + "right" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 0, + "connections": { + "E": [ + "center" + ], + "W": [ + + ] + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "left" + ] + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 5, + "connections": { + "E": [ + "center" + ], + "W": [ + "right" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 5, + "connections": { + "N": [ + "center" + ], + "E": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 4, + "connections": { + "N": [ + "center" + ], + "S": [ + "left" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 3, + "connections": { + "N": [ + "right" + ], + "S": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 2, + "connections": { + "S": [ + "center" + ], + "E": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 6, + "connections": { + "E": [ + "center" + ], + "W": [ + "right" + ] + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 0, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 6, + "connections": { + "N": [ + "left" + ], + "E": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "N": "cruise", + "E": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 5, + "connections": { + "S": [ + "left" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 0, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 2, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 6, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 0, + "connections": { + "E": [ + + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 8, + "y_idx": 2, + "connections": { + "S": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 8, + "y_idx": 3, + "connections": { + "N": [ + "left" + ], + "S": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 8, + "y_idx": 4, + "connections": { + "N": [ + "center" + ], + "S": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 8, + "y_idx": 5, + "connections": { + "N": [ + "center" + ], + "S": [ + "right" + ] + } + }, + { + "l_idx": 0, + "x_idx": 8, + "y_idx": 6, + "connections": { + "N": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 7, + "y_idx": 2, + "connections": { + "E": [ + "right" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 7, + "y_idx": 6, + "connections": { + "E": [ + "left" + ], + "W": [ + "center" + ] + } + } + ], + "blocks": [ + { + "block_name": "block0", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 2, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": false, + "1": false + } + }, + { + "block_name": "block1", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 6, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 6, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 6, + "next_slot": "N", + "orientation": "NE" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": false, + "1": false + } + }, + { + "block_name": "block2", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 0, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 0, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + }, + "random_target": { + "0": true, + "1": true + }, + "wait_time": { + "0": 4, + "1": 4 + }, + "disable_train": { + "0": true, + "1": true + } + } + ], + "trains": [ + { + "train_name": "train0", + "facing": 1, + "reversing_behavior": "off", + "color": "ff773ecc", + "num_wagons": 4, + "random_targets": true, + "block_id": "block2", + "blockindex": 0, + "ble_train": "city-blue" + } + ] + } +} \ No newline at end of file diff --git a/brickrail-gui/devices/layout_controller/layout_controller.gd b/brickrail-gui/devices/layout_controller/layout_controller.gd index 95b80de..cdebf1a 100644 --- a/brickrail-gui/devices/layout_controller/layout_controller.gd +++ b/brickrail-gui/devices/layout_controller/layout_controller.gd @@ -51,12 +51,18 @@ func set_device(port, type): assert(false) devices[port] = device device.connect("removing", self, "_on_device_removing") + hub.set_active(true) emit_signal("devices_changed", name) return device func _on_device_removing(_controllername, port): devices[port].disconnect("removing", self, "_on_device_removing") devices[port] = null + var active=false + for port in devices: + if devices[port] != null: + active=true + hub.set_active(active) emit_signal("devices_changed", name) func _on_hub_runtime_data_received(_data): diff --git a/brickrail-gui/layout/block/layout_block.gd b/brickrail-gui/layout/block/layout_block.gd index 8ffe154..f1dae83 100644 --- a/brickrail-gui/layout/block/layout_block.gd +++ b/brickrail-gui/layout/block/layout_block.gd @@ -93,6 +93,7 @@ func serialize(): var can_flip = {} var random_target = {} var wait_time = {} + var disable_train = {} for block_index in [0,1]: var prior_dirtrack = logical_blocks[block_index].get_prior_sensor_dirtrack() if prior_dirtrack != null: @@ -101,12 +102,14 @@ func serialize(): can_flip[block_index] = logical_blocks[block_index].can_flip random_target[block_index] = logical_blocks[block_index].random_target wait_time[block_index] = logical_blocks[block_index].wait_time + disable_train[block_index] = logical_blocks[block_index].disable_train result["prior_sensors"] = sensors result["can_stop"] = can_stop result["can_flip"] = can_flip result["random_target"] = random_target result["wait_time"] = wait_time + result["disable_train"] = disable_train return result func remove(): diff --git a/brickrail-gui/layout/block/layout_block_inspector.gd b/brickrail-gui/layout/block/layout_block_inspector.gd index 9e9a7fd..044cc02 100644 --- a/brickrail-gui/layout/block/layout_block_inspector.gd +++ b/brickrail-gui/layout/block/layout_block_inspector.gd @@ -7,7 +7,7 @@ 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, $PriorPanel, $PriorLabel, $CanStopCheckBox, $CanFlipCheckBox] + var edit_exclusive_nodes = [$AddTrain, $PriorPanel, $PriorLabel, $CanStopCheckBox, $CanFlipCheckBox, $DisableTrainCheckbox] for node in edit_exclusive_nodes: node.visible = (mode != "control") @@ -23,6 +23,7 @@ func set_block(p_block): $CanStopCheckBox.pressed = block.can_stop $CanFlipCheckBox.pressed = block.can_flip $RandomTargetCheckBox.pressed = block.random_target + $DisableTrainCheckbox.pressed = block.disable_train $HBoxContainer/WaitTimeEdit.value = block.wait_time update_prior_panel() _on_layout_mode_changed(LayoutInfo.layout_mode) @@ -47,7 +48,7 @@ func _on_block_unselected(): queue_free() func _on_block_locked_changed(trainname): - prints("locked changed", trainname) + # prints("locked changed", trainname) $AddTrain.disabled = (trainname != null) func _on_AddTrain_pressed(): @@ -92,3 +93,7 @@ func _on_RemovePriorButton_pressed(): func _on_CancelPriorButton_pressed(): LayoutInfo.set_layout_mode("edit") update_prior_panel() + +func _on_DisableTrainCheckbox_toggled(button_pressed): + block.set_disable_train(button_pressed) + block.get_opposite_block().set_disable_train(button_pressed) diff --git a/brickrail-gui/layout/block/layout_block_inspector.tscn b/brickrail-gui/layout/block/layout_block_inspector.tscn index faa87e9..02f951d 100644 --- a/brickrail-gui/layout/block/layout_block_inspector.tscn +++ b/brickrail-gui/layout/block/layout_block_inspector.tscn @@ -55,30 +55,39 @@ margin_right = 183.0 margin_bottom = 84.0 text = "Train control" -[node name="CanStopCheckBox" type="CheckBox" parent="."] +[node name="DisableTrainCheckbox" type="CheckBox" parent="."] margin_top = 88.0 margin_right = 183.0 margin_bottom = 112.0 +hint_tooltip = "Enabling this setting effectively disables any train occupying this block. +Will apply for the opposite direction as well. Use this setting to store unused trains. +Disabled trains will not be connected via bluetooth when \"control devices\" is turned on." +text = "Disable train" + +[node name="CanStopCheckBox" type="CheckBox" parent="."] +margin_top = 116.0 +margin_right = 183.0 +margin_bottom = 140.0 pressed = true text = "Can stop" [node name="CanFlipCheckBox" type="CheckBox" parent="."] -margin_top = 116.0 +margin_top = 144.0 margin_right = 183.0 -margin_bottom = 140.0 +margin_bottom = 168.0 pressed = true text = "Can reverse" [node name="RandomTargetCheckBox" type="CheckBox" parent="."] -margin_top = 144.0 +margin_top = 172.0 margin_right = 183.0 -margin_bottom = 168.0 +margin_bottom = 196.0 text = "Random target" [node name="HBoxContainer" type="HBoxContainer" parent="."] -margin_top = 172.0 +margin_top = 200.0 margin_right = 183.0 -margin_bottom = 196.0 +margin_bottom = 224.0 [node name="Label" type="Label" parent="HBoxContainer"] margin_top = 5.0 @@ -135,6 +144,7 @@ __meta__ = { [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="DisableTrainCheckbox" to="." method="_on_DisableTrainCheckbox_toggled"] [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"] diff --git a/brickrail-gui/layout/block/layout_logical_block.gd b/brickrail-gui/layout/block/layout_logical_block.gd index 2070811..79d35f3 100644 --- a/brickrail-gui/layout/block/layout_logical_block.gd +++ b/brickrail-gui/layout/block/layout_logical_block.gd @@ -14,6 +14,7 @@ var can_stop = true var can_flip = true var random_target = true var wait_time = 4.0 +var disable_train = false var LayoutBlockInspector = preload("res://layout/block/layout_block_inspector.tscn") @@ -45,6 +46,11 @@ func set_section(p_section): section.connect("sensor_changed", self, "_on_section_sensor_changed") find_sensors() +func set_disable_train(p_disable_train): + if p_disable_train != disable_train: + LayoutInfo.set_layout_changed(true) + disable_train = p_disable_train + func set_random_target(value): if value != random_target: LayoutInfo.set_layout_changed(true) diff --git a/brickrail-gui/layout/layout_info.gd b/brickrail-gui/layout/layout_info.gd index 53fb32d..36d32af 100644 --- a/brickrail-gui/layout/layout_info.gd +++ b/brickrail-gui/layout/layout_info.gd @@ -239,6 +239,9 @@ func load(struct): if "wait_time" in block_data: for index in block_data.wait_time: block.logical_blocks[int(index)].set_wait_time(block_data.wait_time[index]) + if "disable_train" in block_data: + for index in block_data.disable_train: + block.logical_blocks[int(index)].set_disable_train(block_data.disable_train[index]) if "trains" in struct: for train_data in struct.trains: diff --git a/brickrail-gui/layout/train/layout_train.gd b/brickrail-gui/layout/train/layout_train.gd index fa98812..dbfd4f1 100644 --- a/brickrail-gui/layout/train/layout_train.gd +++ b/brickrail-gui/layout/train/layout_train.gd @@ -89,6 +89,8 @@ func set_ble_train(p_train_id): ble_train = Devices.trains[p_train_id] var _err = ble_train.connect("sensor_advance", self, "_on_ble_train_sensor_advance") _err = ble_train.connect("removing", self, "_on_ble_train_removing") + if block != null: + ble_train.hub.set_active(not block.disable_train) LayoutInfo.set_layout_changed(true) update_control_ble_train() emit_signal("ble_train_changed") @@ -414,6 +416,8 @@ func set_current_block(p_block, teleport=true): set_as_home() if teleport: virtual_train.set_dirtrack(block.get_train_spawn_dirtrack(facing), true) + if ble_train != null: + ble_train.hub.set_active(not block.disable_train) else: virtual_train.visible=false