Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion Core/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var module_global_data : Dictionary = {}

var _mods_loaded : bool = false

var window_size_set : bool = false

# Array of all serializable BasicSubWindows
var subwindows : Array[BasicSubWindow] = []

Expand Down Expand Up @@ -65,6 +67,44 @@ func set_background_transparency(transparent : bool):
func get_background_transparency() -> bool:
return not get_node("BackgroundLayer").visible

func confirm_window_size(res: Vector2i):
var settings_dict = {}
if not Engine.is_embedded_in_editor():
# Create objects
var timer := Timer.new()
var dialog = ConfirmationDialog.new()

# Setup objects
var original_size := get_tree().get_root().size

timer.one_shot = true
timer.wait_time = 5.0
timer.ignore_time_scale = true
timer.timeout.connect((func (d: ConfirmationDialog):
d.hide()
get_tree().get_root().set_size(original_size)
).bind(dialog))
get_parent().add_child(timer)

dialog.canceled.connect((func (t: Timer):
t.timeout.emit(dialog)
).bind(timer))
dialog.confirmed.connect((func (t: Timer):
settings_dict["window_size"] = [
res[0], res[1]
]
deserialize_settings(settings_dict, true, false)
t.stop()
).bind(timer))
dialog.dialog_text = "Keep resolution? Will reset in " + str(timer.wait_time) + " seconds."
get_parent().add_child(dialog)

# Apply settings
get_tree().get_root().set_size(res)
timer.start()
dialog.popup()
return

## Load the mods at runtime. This function just adds the zip files to the
## project tree.
func _load_mods() -> void:
Expand Down Expand Up @@ -284,6 +324,7 @@ func reset_settings_to_default() -> void:
ProjectSettings.get_setting("display/window/size/viewport_width"),
ProjectSettings.get_setting("display/window/size/viewport_height"))
get_viewport().set_size(viewport_default_size)

# Note: Not messing with window position (it doesn't really have a default).
# FIXME: Make it default to screen center?
get_viewport().mode &= ~Window.MODE_MAXIMIZED
Expand Down Expand Up @@ -322,11 +363,12 @@ func serialize_settings(do_settings=true, do_mods=true):
settings_to_save["colliders"] = colliders_by_model_name

# Window settings
settings_to_save["window_size_set"] = window_size_set
var window_size = get_viewport().get_size()
var window_position = get_viewport().get_position()
settings_to_save["window_size"] = [
window_size[0],
window_size[1]]
var window_position = get_viewport().get_position()
settings_to_save["window_position"] = [
window_position[0],
window_position[1]]
Expand Down Expand Up @@ -477,10 +519,14 @@ func deserialize_settings(settings_dict, do_settings=true, do_mods=true):
# AudioServer.set_output_device("Default")

# Window size/position settings

if _setting_changed("window_size", old_settings_dict, settings_dict):
get_viewport().set_size(Vector2i(
settings_dict["window_size"][0],
settings_dict["window_size"][1]))
if _setting_changed("window_size_set", old_settings_dict, settings_dict):
window_size_set = settings_dict["window_size_set"]
get_viewport().set_flag(Window.FLAG_RESIZE_DISABLED, settings_dict["window_size_set"])
if _setting_changed("window_position", old_settings_dict, settings_dict):
get_viewport().set_position(Vector2i(
settings_dict["window_position"][0],
Expand Down
15 changes: 7 additions & 8 deletions Core/UI/BasicSubWindow.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://cq0bbpieyhdug"]
[gd_scene format=3 uid="uid://cq0bbpieyhdug"]

[ext_resource type="Script" uid="uid://bkxrcd77vs68q" path="res://Core/UI/BasicSubWindow.gd" id="1_f1sax"]

Expand All @@ -21,7 +21,7 @@ corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4

[node name="BasicSubWindow" type="Control"]
[node name="BasicSubWindow" type="Control" unique_id=1045047529]
custom_minimum_size = Vector2(100, 100)
layout_mode = 3
anchors_preset = 0
Expand All @@ -33,7 +33,7 @@ focus_mode = 1
mouse_force_pass_scroll_events = false
script = ExtResource("1_f1sax")

[node name="WindowBorder" type="Panel" parent="."]
[node name="WindowBorder" type="Panel" parent="." unique_id=1505211846]
layout_mode = 1
anchors_preset = -1
anchor_right = 1.0
Expand All @@ -45,17 +45,16 @@ offset_bottom = 8.0
focus_mode = 1
theme_override_styles/panel = SubResource("StyleBoxFlat_uo2qt")

[node name="WindowTitlePanel" type="Panel" parent="."]
[node name="WindowTitlePanel" type="Panel" parent="." unique_id=546126327]
clip_contents = true
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_top = -24.0
offset_right = 278.0
grow_horizontal = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_aj8ap")

[node name="WindowTitle" type="Label" parent="WindowTitlePanel"]
[node name="WindowTitle" type="Label" parent="WindowTitlePanel" unique_id=2090174781]
clip_contents = true
layout_mode = 1
offset_left = 8.0
Expand All @@ -64,7 +63,7 @@ offset_bottom = 26.0
text = "Window"
clip_text = true

[node name="PopoutButton" type="Button" parent="WindowTitlePanel"]
[node name="PopoutButton" type="Button" parent="WindowTitlePanel" unique_id=1168963718]
visible = false
layout_mode = 1
anchors_preset = 11
Expand All @@ -79,7 +78,7 @@ focus_mode = 0
theme_override_font_sizes/font_size = 10
text = "p"

[node name="CloseButton" type="Button" parent="WindowTitlePanel"]
[node name="CloseButton" type="Button" parent="WindowTitlePanel" unique_id=970561988]
layout_mode = 1
anchors_preset = 11
anchor_left = 1.0
Expand Down
18 changes: 18 additions & 0 deletions Core/UI/SettingsWindow_Window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ extends BasicSubWindow

func _ready() -> void:
register_serializable_subwindow()
%resolutionSet.pressed.connect((func (w, h: LineEdit):
if w.text.is_valid_int() && h.text.is_valid_int():
_get_app_root().confirm_window_size(Vector2i(int(w.text), int(h.text)))
%width.remove_theme_color_override("font_color")
%height.remove_theme_color_override("font_color")
elif w.text == "" && h.text == "":
_get_app_root().deserialize_settings({"window_size_set": false})
else:
%width.add_theme_color_override("font_color", Color(1, 0, 0))
%height.add_theme_color_override("font_color", Color(1, 0, 0))
).bind(%width, %height))

super._ready()

func settings_changed_from_app():
Expand All @@ -16,6 +28,11 @@ func settings_changed_from_app():
%CheckBox_HideWindowDecorations.button_pressed = settings_dict["hide_window_decorations"]
if "vsync_mode" in settings_dict:
%OptionButton_VSyncMode.selected = settings_dict["vsync_mode"]
if "window_size_set" in settings_dict:
%Checkbox_FixedSize.button_pressed = settings_dict["window_size_set"]
if "window_size" in settings_dict:
%width.text = str(settings_dict["window_size"][0])
%height.text = str(settings_dict["window_size"][1])

func show_window():
super.show_window()
Expand All @@ -31,6 +48,7 @@ func update_to_app():
settings_dict["background_color"] = %ColorPickerButton_BackgroundColor.color.to_html()
settings_dict["hide_window_decorations"] = %CheckBox_HideWindowDecorations.button_pressed
settings_dict["vsync_mode"] = %OptionButton_VSyncMode.selected
settings_dict["window_size_set"] = %Checkbox_FixedSize.button_pressed

app.deserialize_settings(settings_dict)

Expand Down
58 changes: 46 additions & 12 deletions Core/UI/SettingsWindow_Window.tscn
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[gd_scene load_steps=3 format=3 uid="uid://c0krlpbiun1ic"]
[gd_scene format=3 uid="uid://c0krlpbiun1ic"]

[ext_resource type="PackedScene" uid="uid://cq0bbpieyhdug" path="res://Core/UI/BasicSubWindow.tscn" id="1_g1tow"]
[ext_resource type="Script" uid="uid://c86snfjcgxmfx" path="res://Core/UI/SettingsWindow_Window.gd" id="2_v2kbv"]

[node name="SettingsWindow_Window" instance=ExtResource("1_g1tow")]
[node name="SettingsWindow_Window" unique_id=386011437 instance=ExtResource("1_g1tow")]
offset_right = 426.0
offset_bottom = 189.0
script = ExtResource("2_v2kbv")
label_text = "Window Settings"

[node name="WindowTitle" parent="WindowTitlePanel" index="0"]
[node name="WindowTitle" parent="WindowTitlePanel" parent_id_path=PackedInt32Array(546126327) index="0" unique_id=2090174781]
text = "Window Settings"

[node name="GridContainer" type="GridContainer" parent="." index="2"]
[node name="GridContainer" type="GridContainer" parent="." index="2" unique_id=1672555084]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
Expand All @@ -23,48 +23,82 @@ theme_override_constants/h_separation = 16
theme_override_constants/v_separation = 2
columns = 2

[node name="Label3" type="Label" parent="GridContainer" index="0"]
[node name="Label3" type="Label" parent="GridContainer" index="0" unique_id=139084595]
layout_mode = 2
text = "Transparent background"

[node name="CheckBox_TransparentBackground" type="CheckBox" parent="GridContainer" index="1"]
[node name="CheckBox_TransparentBackground" type="CheckBox" parent="GridContainer" index="1" unique_id=104646065]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3

[node name="Label" type="Label" parent="GridContainer" index="2"]
[node name="Label" type="Label" parent="GridContainer" index="2" unique_id=1355445278]
layout_mode = 2
text = "Hide window decorations with UI"

[node name="CheckBox_HideWindowDecorations" type="CheckBox" parent="GridContainer" index="3"]
[node name="CheckBox_HideWindowDecorations" type="CheckBox" parent="GridContainer" index="3" unique_id=80076001]
unique_name_in_owner = true
layout_mode = 2

[node name="Label6" type="Label" parent="GridContainer" index="4"]
[node name="Label6" type="Label" parent="GridContainer" index="4" unique_id=984155105]
layout_mode = 2
text = "Background color"

[node name="ColorPickerButton_BackgroundColor" type="ColorPickerButton" parent="GridContainer" index="5"]
[node name="ColorPickerButton_BackgroundColor" type="ColorPickerButton" parent="GridContainer" index="5" unique_id=244886536]
unique_name_in_owner = true
layout_mode = 2

[node name="Label7" type="Label" parent="GridContainer" index="6"]
[node name="Label7" type="Label" parent="GridContainer" index="6" unique_id=70365081]
layout_mode = 2
text = "VSync Mode"

[node name="OptionButton_VSyncMode" type="OptionButton" parent="GridContainer" index="7"]
[node name="OptionButton_VSyncMode" type="OptionButton" parent="GridContainer" index="7" unique_id=53440715]
unique_name_in_owner = true
layout_mode = 2
selected = 0
item_count = 4
popup/item_0/text = "Disabled"
popup/item_0/id = 0
popup/item_1/text = "Enabled"
popup/item_1/id = 1
popup/item_2/text = "Adaptive"
popup/item_2/id = 2
popup/item_3/text = "Mailbox"
popup/item_3/id = 3

[node name="Label4" type="Label" parent="GridContainer" index="8" unique_id=251408528]
layout_mode = 2
text = "Fixed window size"

[node name="Checkbox_FixedSize" type="CheckBox" parent="GridContainer" index="9" unique_id=197175402]
unique_name_in_owner = true
layout_mode = 2

[node name="Label2" type="Label" parent="GridContainer" index="10" unique_id=1382637437]
layout_mode = 2
text = "Set window size"

[node name="GridContainer2" type="GridContainer" parent="GridContainer" index="11" unique_id=1950473523]
layout_mode = 2
columns = 3

[node name="width" type="LineEdit" parent="GridContainer/GridContainer2" index="0" unique_id=2047638636]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "Width"
virtual_keyboard_type = 2

[node name="height" type="LineEdit" parent="GridContainer/GridContainer2" index="1" unique_id=1897443031]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "Height"
virtual_keyboard_type = 2

[node name="resolutionSet" type="Button" parent="GridContainer/GridContainer2" index="2" unique_id=1294896589]
unique_name_in_owner = true
layout_mode = 2
text = "Set"

[connection signal="toggled" from="GridContainer/CheckBox_TransparentBackground" to="." method="_any_value_changed"]
[connection signal="toggled" from="GridContainer/CheckBox_HideWindowDecorations" to="." method="_any_value_changed"]
[connection signal="color_changed" from="GridContainer/ColorPickerButton_BackgroundColor" to="." method="_any_value_changed"]
Expand Down