Skip to content

Commit

Permalink
Add support for UI scaling and "4.x-dev#" releases
Browse files Browse the repository at this point in the history
Center window when scaling
  • Loading branch information
noidexe committed May 11, 2023
1 parent 8f54734 commit 610c8d7
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 70 deletions.
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Globals="*res://scenes/Globals.gd"
[display]

window/size/width=1080
window/dpi/allow_hidpi=true
window/energy_saving/keep_screen_on=false

[input]
Expand Down
9 changes: 5 additions & 4 deletions scenes/Globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_CONFIG : Dictionary = { "ui":{"alpha": false, "beta": false, "rc":
# Add '-devel' for versions not intended for release
# Remove '-devel' when commiting a build to be tagged as release
# Remember to update version in export settings before exporting
const version_tag = "v1.11.2"
const version_tag = "v1.12"
var user_agent : String

func _ready():
Expand Down Expand Up @@ -39,16 +39,17 @@ func write_config(config: Dictionary):
file.close()

# Update the ui_flag
func update_ui_flag(flag: String, switch: bool):
func update_ui_flag(flag: String, value): #switch: bool):
var config = read_config()

if not "ui" in config:
# There should be a better way to define this
config["ui"] = {"alpha": false, "beta": false, "rc": false}
config["ui"] = {"alpha": false, "beta": false, "rc": false, "dev": false, "scale": 1.0 }

config.ui[flag] = switch
config.ui[flag] = value
write_config(config)


# Read the download db from file
func read_download_db() -> Dictionary:
var file = File.new()
Expand Down
159 changes: 95 additions & 64 deletions scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=20 format=2]

[ext_resource path="res://scenes/OpenFolder.gd" type="Script" id=1]
[ext_resource path="res://scenes/Add.gd" type="Script" id=2]
Expand All @@ -14,6 +14,7 @@
[ext_resource path="res://theme/round_and_shaded.stylebox" type="StyleBox" id=12]
[ext_resource path="res://scenes/NewsFeed.gd" type="Script" id=13]
[ext_resource path="res://icon.png" type="Texture" id=14]
[ext_resource path="res://scenes/UIScale.gd" type="Script" id=15]

[sub_resource type="StyleBoxFlat" id=3055]
bg_color = Color( 0.815686, 0.815686, 0.815686, 1 )
Expand Down Expand Up @@ -63,9 +64,58 @@ size_flags_vertical = 3
size_flags_stretch_ratio = 0.5
custom_constants/separation = 10

[node name="Include" type="HBoxContainer" parent="MarginContainer/HBox/MenuBar"]
margin_right = 300.0
margin_bottom = 27.0
custom_constants/separation = -3

[node name="Include" type="Label" parent="MarginContainer/HBox/MenuBar/Include"]
margin_right = 56.0
margin_bottom = 27.0
size_flags_horizontal = 3
size_flags_vertical = 1
text = "Include:"

[node name="Stable" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 53.0
margin_right = 114.0
margin_bottom = 27.0
size_flags_horizontal = 3
pressed = true
text = "Stable"

[node name="Alpha" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 111.0
margin_right = 168.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Alpha"

[node name="Beta" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 165.0
margin_right = 217.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Beta"

[node name="RC" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 214.0
margin_right = 256.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "RC"

[node name="Dev" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 253.0
margin_right = 300.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Dev"

[node name="Version&Refresh" type="HBoxContainer" parent="MarginContainer/HBox/MenuBar"]
margin_top = 37.0
margin_right = 300.0
margin_bottom = 50.0
margin_bottom = 87.0
rect_min_size = Vector2( 0, 50 )

[node name="VersionSelect" type="OptionButton" parent="MarginContainer/HBox/MenuBar/Version&Refresh"]
Expand All @@ -86,6 +136,7 @@ stable_button_path = NodePath("../../Include/Stable")
alpha_button_path = NodePath("../../Include/Alpha")
beta_button_path = NodePath("../../Include/Beta")
rc_button_path = NodePath("../../Include/RC")
dev_button_path = NodePath("../../Include/Dev")

[node name="autoupdate" type="Timer" parent="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect"]
wait_time = 300.0
Expand All @@ -104,52 +155,11 @@ size_flags_vertical = 3
size_flags_stretch_ratio = 0.01
text = "Refresh"

[node name="Include" type="HBoxContainer" parent="MarginContainer/HBox/MenuBar"]
margin_top = 60.0
margin_right = 300.0
margin_bottom = 87.0

[node name="Include" type="Label" parent="MarginContainer/HBox/MenuBar/Include"]
margin_right = 56.0
margin_bottom = 27.0
size_flags_horizontal = 3
size_flags_vertical = 1
text = "Include:"

[node name="Stable" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 59.0
margin_right = 120.0
margin_bottom = 27.0
size_flags_horizontal = 3
pressed = true
text = "Stable"

[node name="Alpha" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 123.0
margin_right = 180.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Alpha"

[node name="Beta" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 183.0
margin_right = 240.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Beta"

[node name="RC" type="CheckBox" parent="MarginContainer/HBox/MenuBar/Include"]
margin_left = 243.0
margin_right = 300.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "RC"

[node name="Download" type="Button" parent="MarginContainer/HBox/MenuBar"]
margin_top = 97.0
margin_right = 300.0
margin_bottom = 197.0
rect_min_size = Vector2( 0, 100 )
margin_bottom = 157.0
rect_min_size = Vector2( 0, 60 )
hint_tooltip = "Download the selected version"
size_flags_horizontal = 3
text = "Download"
Expand All @@ -158,9 +168,9 @@ __meta__ = {
}

[node name="Add" type="Button" parent="MarginContainer/HBox/MenuBar"]
margin_top = 207.0
margin_top = 167.0
margin_right = 300.0
margin_bottom = 257.0
margin_bottom = 217.0
rect_min_size = Vector2( 0, 50 )
hint_tooltip = "Add a custom version or another tool from an .exe"
size_flags_horizontal = 3
Expand All @@ -173,9 +183,9 @@ add_popup = NodePath("../../../../AddNew")

[node name="Donate" type="TextureButton" parent="MarginContainer/HBox/MenuBar"]
visible = false
margin_top = 454.0
margin_right = 250.0
margin_bottom = 522.0
margin_top = 267.0
margin_right = 300.0
margin_bottom = 287.0
rect_min_size = Vector2( 0, 20 )
size_flags_horizontal = 3
size_flags_vertical = 3
Expand All @@ -189,9 +199,9 @@ __meta__ = {
}

[node name="OpenFolder" type="Button" parent="MarginContainer/HBox/MenuBar"]
margin_top = 267.0
margin_top = 227.0
margin_right = 300.0
margin_bottom = 292.0
margin_bottom = 252.0
hint_tooltip = "Add a custom version or another tool from an .exe"
size_flags_horizontal = 3
text = "Open Download Folder"
Expand All @@ -200,8 +210,26 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="UIScale" type="HBoxContainer" parent="MarginContainer/HBox/MenuBar"]
margin_top = 262.0
margin_right = 300.0
margin_bottom = 289.0
script = ExtResource( 15 )

[node name="Label" type="Label" parent="MarginContainer/HBox/MenuBar/UIScale"]
margin_right = 67.0
margin_bottom = 27.0
text = "UI SCALE:"

[node name="SpinBox" type="SpinBox" parent="MarginContainer/HBox/MenuBar/UIScale"]
margin_left = 70.0
margin_right = 139.0
margin_bottom = 27.0
max_value = 3.0
step = 0.1

[node name="LogoContainer" type="MarginContainer" parent="MarginContainer/HBox/MenuBar"]
margin_top = 302.0
margin_top = 299.0
margin_right = 300.0
margin_bottom = 523.0
hint_tooltip = "Click to go to releases webpage"
Expand All @@ -216,31 +244,32 @@ custom_constants/margin_bottom = 30
margin_left = 35.0
margin_top = 30.0
margin_right = 265.0
margin_bottom = 191.0
margin_bottom = 194.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/panel = SubResource( 3055 )

[node name="HBox" type="VBoxContainer" parent="MarginContainer/HBox/MenuBar/LogoContainer/Panel"]
margin_right = 230.0
margin_bottom = 161.0
margin_bottom = 164.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Name" type="Label" parent="MarginContainer/HBox/MenuBar/LogoContainer/Panel/HBox"]
margin_top = 1.0
margin_right = 230.0
margin_bottom = 27.0
margin_bottom = 28.0
size_flags_horizontal = 3
size_flags_vertical = 6
text = "Godot Version Manager"
align = 1

[node name="Logo" type="TextureRect" parent="MarginContainer/HBox/MenuBar/LogoContainer/Panel/HBox"]
margin_top = 30.0
margin_top = 32.0
margin_right = 230.0
margin_bottom = 130.0
margin_bottom = 132.0
rect_min_size = Vector2( 0, 100 )
mouse_filter = 2
size_flags_horizontal = 3
Expand All @@ -250,9 +279,9 @@ expand = true
stretch_mode = 6

[node name="Copyright" type="Label" parent="MarginContainer/HBox/MenuBar/LogoContainer/Panel/HBox"]
margin_top = 133.0
margin_top = 136.0
margin_right = 230.0
margin_bottom = 160.0
margin_bottom = 163.0
size_flags_horizontal = 3
size_flags_vertical = 6
text = "Copyright ©2022 Red Mage Games"
Expand Down Expand Up @@ -498,18 +527,20 @@ mode = 0
access = 2
filters = PoolStringArray( "*.exe ; Windows executable", "*.app ; OSX Application", "*.64,*.x86_64 ; Linux executable" )

[connection signal="refresh_finished" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_VersionSelect_refresh_finished"]
[connection signal="version_added" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" to="MarginContainer/HBox/Installed" method="_on_version_added"]
[connection signal="timeout" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect/autoupdate" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_autoupdate_timeout"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Version&Refresh/Refresh" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Refresh_pressed"]
[connection signal="toggled" from="MarginContainer/HBox/MenuBar/Include/Stable" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Stable_toggled"]
[connection signal="toggled" from="MarginContainer/HBox/MenuBar/Include/Alpha" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Alpha_toggled"]
[connection signal="toggled" from="MarginContainer/HBox/MenuBar/Include/Beta" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Beta_toggled"]
[connection signal="toggled" from="MarginContainer/HBox/MenuBar/Include/RC" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_RC_toggled"]
[connection signal="toggled" from="MarginContainer/HBox/MenuBar/Include/Dev" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Dev_toggled"]
[connection signal="refresh_finished" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_VersionSelect_refresh_finished"]
[connection signal="version_added" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" to="MarginContainer/HBox/Installed" method="_on_version_added"]
[connection signal="timeout" from="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect/autoupdate" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_autoupdate_timeout"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Version&Refresh/Refresh" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Refresh_pressed"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Download" to="MarginContainer/HBox/MenuBar/Version&Refresh/VersionSelect" method="_on_Download_pressed"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Add" to="MarginContainer/HBox/MenuBar/Add" method="_on_Add_pressed"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Donate" to="MarginContainer/HBox/MenuBar/Donate" method="_on_Donate_pressed"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/OpenFolder" to="MarginContainer/HBox/MenuBar/OpenFolder" method="_on_OpenFolder_pressed"]
[connection signal="value_changed" from="MarginContainer/HBox/MenuBar/UIScale/SpinBox" to="MarginContainer/HBox/MenuBar/UIScale" method="_on_SpinBox_value_changed"]
[connection signal="gui_input" from="MarginContainer/HBox/MenuBar/LogoContainer" to="MarginContainer/HBox/MenuBar/Version" method="_on_LogoContainer_gui_input"]
[connection signal="pressed" from="MarginContainer/HBox/MenuBar/Version/update" to="MarginContainer/HBox/MenuBar/Version" method="_on_update_pressed"]
[connection signal="request_completed" from="MarginContainer/HBox/MenuBar/Version/req" to="MarginContainer/HBox/MenuBar/Version" method="_on_request_completed"]
Expand Down
27 changes: 27 additions & 0 deletions scenes/UIScale.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Control

var host_device_dpi := 96.0
var stretch_mode := SceneTree.STRETCH_MODE_DISABLED
var stretch_aspect := SceneTree.STRETCH_ASPECT_IGNORE
onready var target_device_dpi := OS.get_screen_dpi()
onready var base_window_size := Vector2(
ProjectSettings.get_setting("display/window/size/width"),
ProjectSettings.get_setting("display/window/size/height"))

func _ready():
var shrink = target_device_dpi / host_device_dpi
var config = Globals.read_config()
if "ui" in config:
shrink = config.ui.get("scale", shrink )
$SpinBox.value = shrink


func _rescale_ui(scale: float):
get_tree().set_screen_stretch(stretch_mode, stretch_aspect, Vector2.ZERO, scale)
OS.window_size = base_window_size * scale
OS.center_window()


func _on_SpinBox_value_changed(value):
_rescale_ui(value)
Globals.update_ui_flag("scale", value)
Loading

0 comments on commit 610c8d7

Please sign in to comment.