Browse Source

feat: add the window size to the general settings

We could also leverage override.cfg of Godot
for basic settings like this one. (or the clear color)
master
Dominique Merle 2 years ago
parent
commit
b8aece2940
  1. 1
      core/App.gd
  2. 4
      core/Config.gd
  3. 5
      gui/MainMenu.gd
  4. 8
      gui/MainMenu.tscn
  5. 17
      gui/forms/NewPollForm.tscn
  6. 31
      gui/forms/SettingsForm.gd
  7. 54
      gui/forms/SettingsForm.tscn
  8. 5
      project.godot

1
core/App.gd

@ -1,6 +1,7 @@
extends Node
# Unused (see Config.gd)
var config:ConfigResource
var config_path := "user://settings.tres"

4
core/Config.gd

@ -14,10 +14,10 @@ var __config : Dictionary
func get_parameter(parameter_key:String, default=null):
hydrate_lazily()
if self.__config.has(parameter_key):
print("[Config] Reading parameter `%s' from Config." % parameter_key)
# print("[Config] Reading parameter `%s' from Config." % parameter_key)
return self.__config[parameter_key]
else:
print("[Config] Using default value for parameter `%s'." % parameter_key)
# print("[Config] Using default value for parameter `%s'." % parameter_key)
return default

5
gui/MainMenu.gd

@ -6,6 +6,11 @@ onready var NewPollButton = find_node("NewPollButton")
func _ready():
NewPollButton.grab_focus()
var window_size = Vector2(
Config.get_parameter("video.window.width"),
Config.get_parameter("video.window.height")
)
OS.window_size = window_size
func _on_NewPollButton_pressed():

8
gui/MainMenu.tscn

@ -22,10 +22,10 @@ __meta__ = {
}
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 478.0
margin_top = 257.0
margin_right = 546.0
margin_bottom = 343.0
margin_left = 266.0
margin_top = 207.0
margin_right = 334.0
margin_bottom = 293.0
[node name="NewPollButton" type="Button" parent="CenterContainer/VBoxContainer"]
margin_right = 68.0

17
gui/forms/NewPollForm.tscn

@ -25,10 +25,10 @@ __meta__ = {
}
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 397.0
margin_top = 179.0
margin_right = 627.0
margin_bottom = 419.0
margin_left = 185.0
margin_top = 129.0
margin_right = 415.0
margin_bottom = 369.0
__meta__ = {
"_edit_use_anchors_": false
}
@ -127,10 +127,9 @@ size_flags_horizontal = 3
text = "CREATE"
[node name="NoProviderPopup" parent="CenterContainer" instance=ExtResource( 4 )]
visible = false
margin_left = 380.0
margin_top = 194.0
margin_right = 643.0
margin_bottom = 405.0
margin_left = 168.0
margin_top = 144.0
margin_right = 431.0
margin_bottom = 355.0
[connection signal="pressed" from="CenterContainer/VBoxContainer/ButtonsHBoxContainer/CancelButton" to="." method="_on_CancelButton_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/ButtonsHBoxContainer/LaunchButton" to="." method="_on_LaunchButton_pressed"]

31
gui/forms/SettingsForm.gd

@ -3,6 +3,9 @@ extends Control
onready var TwitchCheckButton = find_node("TwitchCheckButton", true)
onready var DemoProviderCheckButton = find_node("DemoProviderCheckButton", true)
onready var WindowSizeWidthLineEdit = find_node("WindowSizeWidthLineEdit", true)
onready var WindowSizeHeightLineEdit = find_node("WindowSizeHeightLineEdit", true)
var initializing = true
func _ready():
@ -14,6 +17,14 @@ func _ready():
"provider_MajorityJudgmentDemoProvider_enabled",
false
)
WindowSizeWidthLineEdit.text = str(Config.get_parameter(
"video.window.width",
OS.window_size.x
))
WindowSizeHeightLineEdit.text = str(Config.get_parameter(
"video.window.height",
OS.window_size.y
))
initializing = false
@ -39,3 +50,23 @@ func _on_DemoProviderCheckButton_toggled(button_pressed):
"provider_MajorityJudgmentDemoProvider_enabled",
button_pressed
)
func _on_WindowSizeWidthLineEdit_focus_exited():
var width = int(WindowSizeWidthLineEdit.text)
if width < 1:
return
Config.set_parameter(
"video.window.width",
width
)
func _on_WindowSizeHeightLineEdit_focus_exited():
var height = int(WindowSizeHeightLineEdit.text)
if height < 1:
return
Config.set_parameter(
"video.window.height",
height
)

54
gui/forms/SettingsForm.tscn

@ -24,10 +24,10 @@ __meta__ = {
}
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 337.0
margin_top = 173.0
margin_right = 687.0
margin_bottom = 427.0
margin_left = 125.0
margin_top = 123.0
margin_right = 475.0
margin_bottom = 377.0
[node name="TabContainer" type="TabContainer" parent="CenterContainer/VBoxContainer"]
margin_right = 350.0
@ -35,6 +35,7 @@ margin_bottom = 230.0
rect_min_size = Vector2( 350, 230 )
[node name="Providers" type="Control" parent="CenterContainer/VBoxContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 4.0
@ -112,7 +113,6 @@ disabled = true
text = "Some other Chat Commands"
[node name="General" type="Control" parent="CenterContainer/VBoxContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 4.0
@ -120,16 +120,54 @@ margin_top = 32.0
margin_right = -4.0
margin_bottom = -4.0
[node name="HelpLabel" type="RichTextLabel" parent="CenterContainer/VBoxContainer/TabContainer/General"]
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/General"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HelpLabel" type="RichTextLabel" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer"]
margin_right = 342.0
margin_bottom = 166.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "TODO: General settings like background color (right now you ned to run the source and change the clear color in the project settings)"
text = "TODO: General settings like background color (right now you need to run the source and change the clear color in the project settings)"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="WindowSizeContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer"]
margin_top = 170.0
margin_right = 342.0
margin_bottom = 194.0
[node name="WindowSizeLabel" type="Label" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer"]
margin_top = 5.0
margin_right = 122.0
margin_bottom = 19.0
text = "Initial Window Size"
[node name="WindowSizeWidthLineEdit" type="LineEdit" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer"]
margin_left = 126.0
margin_right = 184.0
margin_bottom = 24.0
[node name="XLabel" type="Label" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer"]
margin_left = 188.0
margin_top = 5.0
margin_right = 195.0
margin_bottom = 19.0
text = "x"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="WindowSizeHeightLineEdit" type="LineEdit" parent="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer"]
margin_left = 199.0
margin_right = 257.0
margin_bottom = 24.0
[node name="PanelContainer" type="PanelContainer" parent="CenterContainer/VBoxContainer"]
visible = false
margin_top = 40.0
@ -159,4 +197,6 @@ visible = false
[connection signal="toggled" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/DemoContainer/DemoProviderCheckButton" to="." method="_on_DemoProviderCheckButton_toggled"]
[connection signal="toggled" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/TwitchContainer/TwitchCheckButton" to="." method="_on_TwitchCheckButton_toggled"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/TabContainer/Providers/VBoxContainer/TwitchContainer/TwitchConfigureButton" to="." method="_on_TwitchConfigureButton_pressed"]
[connection signal="focus_exited" from="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer/WindowSizeWidthLineEdit" to="." method="_on_WindowSizeWidthLineEdit_focus_exited"]
[connection signal="focus_exited" from="CenterContainer/VBoxContainer/TabContainer/General/VBoxContainer/WindowSizeContainer/WindowSizeHeightLineEdit" to="." method="_on_WindowSizeHeightLineEdit_focus_exited"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/DoneButton" to="." method="_on_DoneButton_pressed"]

5
project.godot

@ -258,6 +258,11 @@ config/icon="res://icon.png"
App="*res://core/App.gd"
Config="*res://core/Config.gd"
[display]
window/size/width=600
window/size/height=500
[editor_plugins]
enabled=PoolStringArray( "WAT", "majority_judgment" )

Loading…
Cancel
Save