From 483c50dfac2fd7dc769a22705b0197232ef7d2a6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 15 Jun 2020 18:37:51 +0200 Subject: [PATCH] Added a touchscreen mode setting, and an AdaptiveButton that will set it's own min size if the setting is enabled. I did not replace all buttons yet, just made sure everything looks consistent. Also smaller theme improvements. --- game/autoload/SettingsManager.gd | 4 +++ game/scenes/ConnectButton.gd | 3 ++ game/scenes/HostButton.gd | 3 +- game/scenes/Menu.tscn | 28 +++++++++++-------- game/scripts/ui/AdaptiveButton.gd | 6 ++++ game/ui/ingame_menu/ExitButton.gd | 3 ++ game/ui/ingame_menu/IngameMenu.tscn | 6 +++- game/ui/options/Options.tscn | 27 ++++++++++++++++-- game/ui/player_ui/player_ui.tscn | 3 +- game/ui/theme/tab_button_bg_stylebox.tres | 14 ++++++++++ .../theme/tab_button_bg_stylebox_focus.tres | 14 ++++++++++ .../theme/tab_button_bg_stylebox_hover.tres | 13 +++++++++ game/ui/theme/ui_theme.tres | 11 +++++--- 13 files changed, 112 insertions(+), 23 deletions(-) create mode 100644 game/scripts/ui/AdaptiveButton.gd create mode 100644 game/ui/theme/tab_button_bg_stylebox.tres create mode 100644 game/ui/theme/tab_button_bg_stylebox_focus.tres create mode 100644 game/ui/theme/tab_button_bg_stylebox_hover.tres diff --git a/game/autoload/SettingsManager.gd b/game/autoload/SettingsManager.gd index a3d98e09..1b037822 100644 --- a/game/autoload/SettingsManager.gd +++ b/game/autoload/SettingsManager.gd @@ -36,6 +36,9 @@ var _settings : Dictionary = { "use_vsync" : ProjectSettings.get("display/window/vsync/use_vsync"), "vsync_via_compositor" : ProjectSettings.get("display/window/vsync/vsync_via_compositor"), }, + "ui" : { + "touchscreen_mode" : OS.has_touchscreen_ui_hint(), + }, "debug" : { "debug_info" : false } @@ -132,3 +135,4 @@ func set_rendering_vsync_via_compositor(value : bool) -> void: ProjectSettings.set("display/window/vsync/vsync_via_compositor", value) OS.vsync_via_compositor = value + diff --git a/game/scenes/ConnectButton.gd b/game/scenes/ConnectButton.gd index f44a6616..41e251ee 100644 --- a/game/scenes/ConnectButton.gd +++ b/game/scenes/ConnectButton.gd @@ -21,6 +21,9 @@ extends Button # SOFTWARE. func _ready(): + if Settings.get_value("ui", "touchscreen_mode"): + rect_min_size = Vector2(rect_min_size.x, 40) + get_tree().connect("connected_to_server", self, "connected_to_server") get_tree().connect("server_disconnected", self, "server_disconnected") diff --git a/game/scenes/HostButton.gd b/game/scenes/HostButton.gd index af0c14a4..f003296d 100644 --- a/game/scenes/HostButton.gd +++ b/game/scenes/HostButton.gd @@ -26,7 +26,8 @@ extends Button # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + if Settings.get_value("ui", "touchscreen_mode"): + rect_min_size = Vector2(rect_min_size.x, 40) #func _pressed(): # Server.start_hosting() diff --git a/game/scenes/Menu.tscn b/game/scenes/Menu.tscn index 163f90e6..45b200e4 100644 --- a/game/scenes/Menu.tscn +++ b/game/scenes/Menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=24 format=2] [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=1] [ext_resource path="res://ui/menu/CharacterEntry.tscn" type="PackedScene" id=2] @@ -19,13 +19,7 @@ [ext_resource path="res://modules/planets/test_planet/voxel_library/1_main_lib_merger_empty.tres" type="VoxelmanLibraryMerger" id=17] [ext_resource path="res://scripts/world_generators/MainPlanetGenerator.gd" type="Script" id=18] [ext_resource path="res://scripts/settings/DirectionalLightSettings.gd" type="Script" id=19] - - - - - - - +[ext_resource path="res://scripts/ui/AdaptiveButton.gd" type="Script" id=20] [sub_resource type="VoxelmanLevelGenerator" id=1] script = ExtResource( 18 ) @@ -168,6 +162,7 @@ margin_top = 8.0 margin_right = 261.0 margin_bottom = 34.269 text = "Continue" +script = ExtResource( 20 ) [node name="Renounce" type="Button" parent="CharacterSelectorMenu/CharacterSelector/VBoxContainer/CharacterSelector/VBoxContainer"] margin_top = 42.0 @@ -176,6 +171,7 @@ margin_bottom = 68.269 size_flags_horizontal = 3 size_flags_vertical = 3 text = "Renounce" +script = ExtResource( 20 ) [node name="New" type="Button" parent="CharacterSelectorMenu/CharacterSelector/VBoxContainer/CharacterSelector/VBoxContainer"] margin_top = 76.0 @@ -184,6 +180,7 @@ margin_bottom = 102.269 size_flags_horizontal = 3 size_flags_vertical = 3 text = "New" +script = ExtResource( 20 ) [node name="PlayerDisplays" type="Node" parent="CharacterSelectorMenu"] @@ -268,6 +265,7 @@ margin_right = 253.0 margin_bottom = 81.269 size_flags_horizontal = 3 text = "Create" +script = ExtResource( 20 ) __meta__ = { "_edit_use_anchors_": false } @@ -277,6 +275,7 @@ margin_top = 89.0 margin_right = 253.0 margin_bottom = 115.269 text = "Back" +script = ExtResource( 20 ) [node name="ConnectMenu" type="Control" parent="."] visible = false @@ -367,6 +366,7 @@ margin_top = 224.0 margin_right = 244.0 margin_bottom = 250.269 text = "Cancel" +script = ExtResource( 20 ) [node name="HostMenu" type="Control" parent="."] visible = false @@ -444,6 +444,7 @@ margin_top = 169.0 margin_right = 244.0 margin_bottom = 195.269 text = "Cancel" +script = ExtResource( 20 ) [node name="OptionsButton" type="MarginContainer" parent="."] anchor_right = 1.0 @@ -491,9 +492,9 @@ __meta__ = { } [node name="Connect" type="Button" parent="OptionsButton/Control/VBoxContainer"] -margin_top = 13.0 +margin_top = 81.0 margin_right = 120.0 -margin_bottom = 39.269 +margin_bottom = 107.269 rect_min_size = Vector2( 120, 0 ) text = "Connect" script = ExtResource( 11 ) @@ -502,9 +503,9 @@ __meta__ = { } [node name="Host" type="Button" parent="OptionsButton/Control/VBoxContainer"] -margin_top = 47.0 +margin_top = 115.0 margin_right = 120.0 -margin_bottom = 73.269 +margin_bottom = 141.269 rect_min_size = Vector2( 120, 0 ) text = "Host" script = ExtResource( 12 ) @@ -513,6 +514,7 @@ __meta__ = { } [node name="Button2" type="Button" parent="OptionsButton/Control/VBoxContainer"] +visible = false margin_top = 81.0 margin_right = 120.0 margin_bottom = 107.269 @@ -523,6 +525,7 @@ __meta__ = { } [node name="Button3" type="Button" parent="OptionsButton/Control/VBoxContainer"] +visible = false margin_top = 115.0 margin_right = 120.0 margin_bottom = 141.269 @@ -538,6 +541,7 @@ margin_right = 120.0 margin_bottom = 175.269 rect_min_size = Vector2( 120, 0 ) text = "Options" +script = ExtResource( 20 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/game/scripts/ui/AdaptiveButton.gd b/game/scripts/ui/AdaptiveButton.gd new file mode 100644 index 00000000..74e76374 --- /dev/null +++ b/game/scripts/ui/AdaptiveButton.gd @@ -0,0 +1,6 @@ +extends Button + +func _ready(): + if Settings.get_value("ui", "touchscreen_mode"): + rect_min_size = Vector2(rect_min_size.x, 40) + diff --git a/game/ui/ingame_menu/ExitButton.gd b/game/ui/ingame_menu/ExitButton.gd index 51d0a9c6..ab0de1ed 100644 --- a/game/ui/ingame_menu/ExitButton.gd +++ b/game/ui/ingame_menu/ExitButton.gd @@ -22,6 +22,9 @@ extends Button func _ready(): + if Settings.get_value("ui", "touchscreen_mode"): + rect_min_size = Vector2(rect_min_size.x, 40) + connect("pressed", self, "on_click") func on_click() -> void: diff --git a/game/ui/ingame_menu/IngameMenu.tscn b/game/ui/ingame_menu/IngameMenu.tscn index bae325c7..ecab38dd 100644 --- a/game/ui/ingame_menu/IngameMenu.tscn +++ b/game/ui/ingame_menu/IngameMenu.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=1] [ext_resource path="res://ui/options/Options.tscn" type="PackedScene" id=2] [ext_resource path="res://ui/ingame_menu/ExitButton.gd" type="Script" id=3] [ext_resource path="res://ui/keybinds/Keybinds.tscn" type="PackedScene" id=4] +[ext_resource path="res://scripts/ui/AdaptiveButton.gd" type="Script" id=5] [node name="IngameMenu" type="Control"] anchor_right = 1.0 @@ -37,18 +38,21 @@ margin_bottom = 132.0 margin_right = 147.0 margin_bottom = 26.269 text = "Resume" +script = ExtResource( 5 ) [node name="Keybinds" type="Button" parent="Menu/VBoxContainer"] margin_top = 34.0 margin_right = 147.0 margin_bottom = 60.269 text = "Keybinds" +script = ExtResource( 5 ) [node name="Options" type="Button" parent="Menu/VBoxContainer"] margin_top = 68.0 margin_right = 147.0 margin_bottom = 94.269 text = "Options" +script = ExtResource( 5 ) [node name="Exit" type="Button" parent="Menu/VBoxContainer"] margin_top = 102.0 diff --git a/game/ui/options/Options.tscn b/game/ui/options/Options.tscn index 6f54cf20..ee5f0c01 100644 --- a/game/ui/options/Options.tscn +++ b/game/ui/options/Options.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=1] [ext_resource path="res://ui/player_ui/RemoveProfile.gd" type="Script" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://ui/options/OptionCheckboxRow.tscn" type="PackedScene" id=4] [ext_resource path="res://ui/options/OptionCheckBox.gd" type="Script" id=5] [ext_resource path="res://ui/options/OptionEnumRow.tscn" type="PackedScene" id=6] +[ext_resource path="res://scripts/ui/AdaptiveButton.gd" type="Script" id=7] [ext_resource path="res://ui/options/OptionsSpinboxRow.tscn" type="PackedScene" id=8] [node name="Options" type="Control"] @@ -47,7 +48,7 @@ tab_align = 0 anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 -margin_top = 30.0 +margin_top = 31.0 margin_right = -4.0 margin_bottom = -4.0 size_flags_horizontal = 3 @@ -69,7 +70,9 @@ property_category = "rendering" property_name = "viewport_scale" property_label = "Viewport Scale" min_value = 20 +max_value = 100 step = 5 +prefix = "" suffix = "%" [node name="Borderless" parent="PanelContainer/VBoxContainer/TabContainer/Video" instance=ExtResource( 4 )] @@ -122,12 +125,29 @@ property_category = "rendering" property_name = "vsync_via_compositor" property_label = "VSync Via Compositor" +[node name="Interface" type="VBoxContainer" parent="PanelContainer/VBoxContainer/TabContainer"] +visible = false +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 31.0 +margin_right = -4.0 +margin_bottom = -4.0 +size_flags_horizontal = 3 + +[node name="OptionToggleRow" parent="PanelContainer/VBoxContainer/TabContainer/Interface" instance=ExtResource( 4 )] +margin_top = 0.0 +margin_bottom = 26.0 +property_category = "ui" +property_name = "touchscreen_mode" +property_label = "Touchscreen Mode" + [node name="Debug" type="VBoxContainer" parent="PanelContainer/VBoxContainer/TabContainer"] visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 -margin_top = 30.0 +margin_top = 31.0 margin_right = -4.0 margin_bottom = -4.0 size_flags_horizontal = 3 @@ -153,4 +173,5 @@ margin_top = 439.0 margin_right = 535.0 margin_bottom = 465.269 text = "Close" +script = ExtResource( 7 ) [connection signal="pressed" from="PanelContainer/VBoxContainer/Close" to="." method="hide"] diff --git a/game/ui/player_ui/player_ui.tscn b/game/ui/player_ui/player_ui.tscn index 283e8ccb..700a97bd 100644 --- a/game/ui/player_ui/player_ui.tscn +++ b/game/ui/player_ui/player_ui.tscn @@ -431,8 +431,7 @@ margin_left = -331.0 margin_bottom = 123.0 [node name="Castbar" parent="GUI" instance=ExtResource( 16 )] -margin_top = 0.0 -mouse_filter = 2 +visible = false [node name="ErrorFrame" parent="GUI" instance=ExtResource( 4 )] anchor_left = 0.5 diff --git a/game/ui/theme/tab_button_bg_stylebox.tres b/game/ui/theme/tab_button_bg_stylebox.tres new file mode 100644 index 00000000..5843cc0a --- /dev/null +++ b/game/ui/theme/tab_button_bg_stylebox.tres @@ -0,0 +1,14 @@ +[gd_resource type="StyleBoxTexture" load_steps=2 format=2] + +[ext_resource path="res://ui/theme/button_bg_atlas.tres" type="Texture" id=1] + +[resource] +texture = ExtResource( 1 ) +region_rect = Rect2( 0, 0, 13, 14 ) +margin_left = 8.65868 +margin_right = 8.7872 +margin_top = 6.0 +margin_bottom = 6.0 +axis_stretch_horizontal = 2 +axis_stretch_vertical = 2 +modulate_color = Color( 0.772549, 0.772549, 0.772549, 1 ) diff --git a/game/ui/theme/tab_button_bg_stylebox_focus.tres b/game/ui/theme/tab_button_bg_stylebox_focus.tres new file mode 100644 index 00000000..2e732535 --- /dev/null +++ b/game/ui/theme/tab_button_bg_stylebox_focus.tres @@ -0,0 +1,14 @@ +[gd_resource type="StyleBoxTexture" load_steps=2 format=2] + +[ext_resource path="res://ui/theme/button_bg_atlas.tres" type="Texture" id=1] + +[resource] +texture = ExtResource( 1 ) +region_rect = Rect2( 0, 0, 13, 14 ) +margin_left = 8.40166 +margin_right = 8.01612 +margin_top = 6.0 +margin_bottom = 6.0 +axis_stretch_horizontal = 2 +axis_stretch_vertical = 2 +modulate_color = Color( 0.807843, 0.807843, 0.807843, 1 ) diff --git a/game/ui/theme/tab_button_bg_stylebox_hover.tres b/game/ui/theme/tab_button_bg_stylebox_hover.tres new file mode 100644 index 00000000..8f2d6688 --- /dev/null +++ b/game/ui/theme/tab_button_bg_stylebox_hover.tres @@ -0,0 +1,13 @@ +[gd_resource type="StyleBoxTexture" load_steps=2 format=2] + +[ext_resource path="res://ui/theme/button_bg_atlas.tres" type="Texture" id=1] + +[resource] +texture = ExtResource( 1 ) +region_rect = Rect2( 0, 0, 13, 14 ) +margin_left = 8.27315 +margin_right = 8.14463 +margin_top = 6.0 +margin_bottom = 6.0 +axis_stretch_horizontal = 2 +axis_stretch_vertical = 2 diff --git a/game/ui/theme/ui_theme.tres b/game/ui/theme/ui_theme.tres index efc6352b..20dc78d7 100644 --- a/game/ui/theme/ui_theme.tres +++ b/game/ui/theme/ui_theme.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=30 format=2] +[gd_resource type="Theme" load_steps=33 format=2] [ext_resource path="res://ui/theme/h_scroll_bar_texture.tres" type="Texture" id=1] [ext_resource path="res://ui/theme/button_bg_stylebox_disabled.tres" type="StyleBox" id=2] @@ -20,6 +20,9 @@ [ext_resource path="res://ui/theme/checkbox_texture.tres" type="Texture" id=18] [ext_resource path="res://ui/theme/checkbox_checked_texture.tres" type="Texture" id=19] [ext_resource path="res://ui/theme/dropdown_icon.tres" type="Texture" id=20] +[ext_resource path="res://ui/theme/tab_button_bg_stylebox_focus.tres" type="StyleBox" id=21] +[ext_resource path="res://ui/theme/tab_button_bg_stylebox_hover.tres" type="StyleBox" id=22] +[ext_resource path="res://ui/theme/tab_button_bg_stylebox.tres" type="StyleBox" id=23] [sub_resource type="Image" id=10] data = { @@ -234,9 +237,9 @@ TabContainer/icons/increment_highlight = null TabContainer/icons/menu = null TabContainer/icons/menu_highlight = null TabContainer/styles/panel = ExtResource( 8 ) -TabContainer/styles/tab_bg = ExtResource( 4 ) -TabContainer/styles/tab_disabled = ExtResource( 5 ) -TabContainer/styles/tab_fg = ExtResource( 3 ) +TabContainer/styles/tab_bg = ExtResource( 23 ) +TabContainer/styles/tab_disabled = ExtResource( 22 ) +TabContainer/styles/tab_fg = ExtResource( 21 ) Tabs/colors/font_color_bg = Color( 0.69, 0.69, 0.69, 1 ) Tabs/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 ) Tabs/colors/font_color_fg = Color( 0.94, 0.94, 0.94, 1 )