From 0f3f345b29b4db2633737414ae8698862af13102 Mon Sep 17 00:00:00 2001 From: Johannes Ringler Date: Thu, 17 Aug 2023 15:01:22 +0200 Subject: [PATCH] implement alternative color setting for trains this makes the train color much more obvious at the cost of a unified color scheme --- CHANGELOG.md | 1 + brickrail-gui/gui/main.tscn | 63 ++++++++++--------- brickrail-gui/gui/settings.gd | 10 +++ brickrail-gui/gui/settings_gui.gd | 5 ++ brickrail-gui/layout/train/virtual_train.gd | 17 ++++- .../layout/train/virtual_train_wagon.gd | 3 + brickrail-gui/layout/train/wagon_shader.tres | 20 ++++-- 7 files changed, 83 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2325859..ff6e9645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Added +- Added alternative train colors setting that makes each train color much more obvious at the cost of a unified color scheme. - 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). diff --git a/brickrail-gui/gui/main.tscn b/brickrail-gui/gui/main.tscn index e4aceffc..60631b0d 100644 --- a/brickrail-gui/gui/main.tscn +++ b/brickrail-gui/gui/main.tscn @@ -57,7 +57,7 @@ split_offset = 123 [node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer"] margin_right = 224.0 -margin_bottom = 499.0 +margin_bottom = 530.0 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer"] margin_right = 224.0 @@ -79,13 +79,14 @@ text = "Disconnect hubs" [node name="TabContainer" type="TabContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer"] margin_top = 31.0 margin_right = 224.0 -margin_bottom = 468.0 +margin_bottom = 499.0 mouse_filter = 1 size_flags_vertical = 3 tab_align = 0 use_hidden_tabs_for_min_size = true [node name="Trains" type="ScrollContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 5.0 @@ -126,19 +127,18 @@ margin_bottom = 31.0 size_flags_horizontal = 3 [node name="AddLayoutControllerButton" type="Button" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Controllers/VBoxContainer"] -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 27.0 text = "Add layout controller hub" [node name="controllers" type="VBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Controllers/VBoxContainer"] margin_top = 31.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 31.0 size_flags_horizontal = 3 size_flags_vertical = 3 [node name="Settings" type="VBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 5.0 @@ -147,9 +147,15 @@ margin_right = -5.0 margin_bottom = -5.0 script = ExtResource( 4 ) +[node name="AltTrainColorCheckbox" type="CheckBox" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +margin_right = 214.0 +margin_bottom = 27.0 +text = "Alternative train color" + [node name="GridContainer" type="GridContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] -margin_right = 230.0 -margin_bottom = 89.0 +margin_top = 31.0 +margin_right = 214.0 +margin_bottom = 120.0 columns = 2 [node name="RenderModeLabel" type="Label" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings/GridContainer"] @@ -196,46 +202,46 @@ margin_bottom = 89.0 text = "Remove preset" [node name="BackgroundColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] -margin_top = 93.0 -margin_right = 230.0 -margin_bottom = 120.0 -size_flags_horizontal = 3 - -[node name="SurfaceColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] margin_top = 124.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 151.0 +size_flags_horizontal = 3 -[node name="PrimaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +[node name="SurfaceColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] margin_top = 155.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 182.0 -[node name="SecondaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +[node name="PrimaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] margin_top = 186.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 213.0 -[node name="TertiaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +[node name="SecondaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] margin_top = 217.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 244.0 -[node name="WhiteColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +[node name="TertiaryColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] margin_top = 248.0 -margin_right = 230.0 +margin_right = 214.0 margin_bottom = 275.0 +[node name="WhiteColor" type="ColorPickerButton" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings"] +margin_top = 279.0 +margin_right = 214.0 +margin_bottom = 306.0 + [node name="PresetNameDialog" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings" instance=ExtResource( 8 )] [node name="ConnectBLEServerButton" type="Button" parent="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer"] -margin_top = 472.0 +margin_top = 503.0 margin_right = 224.0 -margin_bottom = 499.0 +margin_bottom = 530.0 text = "Connect BLE Server" [node name="Notifications" type="VBoxContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer"] -margin_top = 507.0 +margin_top = 538.0 margin_right = 224.0 margin_bottom = 689.0 size_flags_horizontal = 3 @@ -249,7 +255,7 @@ window_title = "Info" [node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer2/HSplitContainer/VSplitContainer/Notifications"] margin_right = 224.0 -margin_bottom = 151.0 +margin_bottom = 120.0 size_flags_horizontal = 3 size_flags_vertical = 3 @@ -258,9 +264,9 @@ margin_right = 224.0 size_flags_horizontal = 3 [node name="ClearButton" type="Button" parent="VBoxContainer2/HSplitContainer/VSplitContainer/Notifications"] -margin_top = 155.0 +margin_top = 124.0 margin_right = 224.0 -margin_bottom = 182.0 +margin_bottom = 151.0 text = "Clear" [node name="LayoutGui" type="HSplitContainer" parent="VBoxContainer2/HSplitContainer"] @@ -548,6 +554,7 @@ script = ExtResource( 11 ) [connection signal="pressed" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/HBoxContainer/DisconnectAllButton" to="." method="_on_DisconnectAllButton_pressed"] [connection signal="pressed" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Trains/VBoxContainer/AddTrainButton" to="." method="_on_AddTrainButton_pressed"] [connection signal="pressed" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Controllers/VBoxContainer/AddLayoutControllerButton" to="." method="_on_AddLayoutControllerButton_pressed"] +[connection signal="toggled" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings/AltTrainColorCheckbox" to="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings" method="_on_AltTrainColorCheckbox_toggled"] [connection signal="item_selected" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings/GridContainer/RenderModeOption" to="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings" method="_on_RenderModeOption_item_selected"] [connection signal="meta_selected" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings/GridContainer/PresetSelector" to="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings" method="_on_PresetSelector_meta_selected"] [connection signal="pressed" from="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings/GridContainer/PresetAddButton" to="VBoxContainer2/HSplitContainer/VSplitContainer/VBoxContainer/TabContainer/Settings" method="_on_PresetAddButton_pressed"] diff --git a/brickrail-gui/gui/settings.gd b/brickrail-gui/gui/settings.gd index 52a4f971..a06709ec 100644 --- a/brickrail-gui/gui/settings.gd +++ b/brickrail-gui/gui/settings.gd @@ -26,6 +26,8 @@ var default_presets = [] var color_preset = "custom" var colors = {} +var alt_train_color = false + var hub_program_hashes = {} var hub_io_hub_hashes = {} @@ -48,6 +50,10 @@ func _ready(): func update_clear_color(): VisualServer.set_default_clear_color(colors["background"]) +func set_alt_train_color(val): + alt_train_color = val + emit_signal("colors_changed") + func set_color(cname, color): if color_preset != "custom": presets["custom"] = colors.duplicate() @@ -96,6 +102,7 @@ func save_configfile(): data["hub_program_hashes"] = hub_program_hashes data["hub_io_hub_hashes"] = hub_io_hub_hashes data["layout_train_positions"] = layout_train_positions + data["alt_train_color"] = alt_train_color var jsonstr = JSON.print(data, "\t") var configfil = File.new() configfil.open("user://config.json", File.WRITE) @@ -140,5 +147,8 @@ func read_configfile(): if "layout_train_positions" in data: layout_train_positions = data.layout_train_positions.duplicate() + if "alt_train_color" in data: + alt_train_color = data.alt_train_color + emit_signal("render_mode_changed") emit_signal("colors_changed") diff --git a/brickrail-gui/gui/settings_gui.gd b/brickrail-gui/gui/settings_gui.gd index a5376b24..00e6c90c 100644 --- a/brickrail-gui/gui/settings_gui.gd +++ b/brickrail-gui/gui/settings_gui.gd @@ -8,6 +8,7 @@ func _ready(): $PresetNameDialog.add_text_edit() $PresetNameDialog.add_action_button("cancel", "Cancel") $PresetNameDialog.add_action_button("OK", "OK") + $AltTrainColorCheckbox.pressed = Settings.alt_train_color func _on_settings_presets_changed(): $BackgroundColor.color = Settings.colors["background"] @@ -65,3 +66,7 @@ func _on_PresetAddButton_pressed(): func _on_PresetRemoveButton_pressed(): Settings.remove_color_preset(Settings.color_preset) + + +func _on_AltTrainColorCheckbox_toggled(button_pressed): + Settings.set_alt_train_color(button_pressed) diff --git a/brickrail-gui/layout/train/virtual_train.gd b/brickrail-gui/layout/train/virtual_train.gd index d4ea4ea2..2814633e 100644 --- a/brickrail-gui/layout/train/virtual_train.gd +++ b/brickrail-gui/layout/train/virtual_train.gd @@ -79,6 +79,9 @@ func _init(p_name): logging_module = "virtual-" + train_id var _err = Settings.connect("colors_changed", self, "_on_settings_colors_changed") + color = Settings.colors["tertiary"]*0.8 + color.a = 1.0 + add_wagons(4) _err = connect("visibility_changed", self, "_on_visibility_changed") @@ -109,6 +112,7 @@ func set_color(p_color): color = p_color for wagon in wagons: wagon.set_color(color) + update_wagon_visuals() if train_id != "drag-train": LayoutInfo.set_layout_changed(true) @@ -343,15 +347,22 @@ func set_hover(p_hover): update_wagon_visuals() func update_wagon_visuals(): - var wagon_color + var wagon_color = body_color + var border_color = body_color if selected: + border_color = selected_color wagon_color = selected_color - else: - wagon_color = body_color + if Settings.alt_train_color: + wagon_color = color + border_color = color + if selected: + border_color = Settings.colors["white"] if hover: wagon_color = wagon_color*1.7 + border_color = border_color * 1.7 for wagon in wagons: wagon.set_body_color(wagon_color) + wagon.set_border_color(border_color) wagon.set_facing(0) wagon.set_heading(0) wagon.set_color(color) diff --git a/brickrail-gui/layout/train/virtual_train_wagon.gd b/brickrail-gui/layout/train/virtual_train_wagon.gd index daaed620..510ecc25 100644 --- a/brickrail-gui/layout/train/virtual_train_wagon.gd +++ b/brickrail-gui/layout/train/virtual_train_wagon.gd @@ -8,6 +8,9 @@ func _init(): func set_body_color(color): material.set_shader_param("body_color", color) +func set_border_color(color): + material.set_shader_param("border_color", color) + func set_color(color): material.set_shader_param("id_color", color) diff --git a/brickrail-gui/layout/train/wagon_shader.tres b/brickrail-gui/layout/train/wagon_shader.tres index c96900f1..ddfb96ec 100644 --- a/brickrail-gui/layout/train/wagon_shader.tres +++ b/brickrail-gui/layout/train/wagon_shader.tres @@ -7,6 +7,14 @@ uniform int facing = 1; uniform int heading = 1; uniform vec4 body_color: hint_color = vec4(1.0); uniform vec4 id_color: hint_color = vec4(0.0, 0.0, 0.0, 1.0); +uniform vec4 border_color: hint_color = vec4(1.0); + +float sd_line_segment(in vec2 p, in vec2 a, in vec2 b) { + vec2 ba = b - a; + vec2 pa = p - a; + float h = clamp(dot(pa, ba) / dot(ba, ba), 0., 1.); + return length(pa - h * ba); +} float sd_circle(vec2 pos, vec2 center, float radius) { return length(pos-center)-radius; @@ -57,9 +65,8 @@ void fragment() { float main_body; vec2 position = UV; vec2 rect_size = vec2(0.4, 0.3); - main_body = sd_rect(position, vec2(0.5, 0.5), rect_size); - main_body = sd_merge(main_body, sd_circle(position, vec2(0.5, 0.5)-vec2(rect_size.x*0.5, 0.0), rect_size.y*0.5)); - main_body = sd_merge(main_body, sd_circle(position, vec2(0.5, 0.5)+vec2(rect_size.x*0.5, 0.0), rect_size.y*0.5)); + + main_body = sd_line_segment(position, vec2(0.5, 0.5)-vec2(rect_size.x*0.5, 0.0), vec2(0.5, 0.5)+vec2(rect_size.x*0.5, 0.0)) - rect_size.y*0.5; float s = sign(float(heading)); float heading_arrow = sd_triangle( position, @@ -69,9 +76,11 @@ void fragment() { float facing_window = sd_circle(position, vec2(0.5, 0.5)+vec2(rect_size.x*0.5*sign(float(facing)), 0.0), rect_size.y*0.35); - COLOR = body_color; + COLOR = border_color; COLOR.a = 0.0; - mix_sdf(main_body, COLOR, body_color); + float border = max(main_body - 0.00, -main_body - 0.06); + mix_sdf(main_body + 0.03, COLOR, body_color); + mix_sdf(border, COLOR, border_color); if (heading != 0) mix_sdf(heading_arrow, COLOR, body_color); if (facing != 0) mix_sdf(facing_window, COLOR, vec4(vec3(0.0), 1.0)); if (facing != 0) mix_sdf(facing_window+0.05, COLOR, id_color); @@ -83,3 +92,4 @@ shader_param/facing = 1 shader_param/heading = 1 shader_param/body_color = Color( 0.65098, 0.52549, 0.14902, 1 ) shader_param/id_color = Color( 0.12549, 0.764706, 0.780392, 1 ) +shader_param/border_color = Color( 1, 1, 1, 1 )