Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Fix loading display settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremi360 committed Jan 13, 2019
1 parent cab1ab2 commit a75816a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions addons/Ren/Ren.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
[ext_resource path="res://addons/Ren/nodes/ren_timer.gd" type="Script" id=19]
[ext_resource path="res://addons/Ren/icons/ren_timer.svg" type="Texture" id=20]

[node name="Ren" type="Node"]
[node name="Ren" type="Node" index="0"]

pause_mode = 2
script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ]
game_title = "Your New Game"
game_version = "0.0.1"
game_credits = "Your Company"
markups = "ren"
markup = "ren"
links_color = Color( 0.133333, 0.368627, 0.74902, 1 )
debug_on = false
save_folder = "saves"
Expand Down
2 changes: 1 addition & 1 deletion scenes/examples/Test/Test.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tracks/0/keys = {
"values": [ 0.0, 360.0 ]
}

[node name="Test" type="Node2D" index="0"]
[node name="Test" type="Node2D"]

script = ExtResource( 1 )
_sections_unfolded = [ "Material", "Transform", "Z Index" ]
Expand Down
3 changes: 2 additions & 1 deletion scenes/gui/OptionsBox/ApplyButton.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extends Button

func _ready():
connect("pressed", settings, "apply")
connect("pressed", settings, "apply")

1 change: 1 addition & 0 deletions scenes/gui/Screens/Screens.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ onready var in_game_gui = get_node("/root/Window/InGameGUI")

var current_node = self
var nav_path = "Navigation/ScrollContainer/VBoxContainer/"

func _ready():
get_tree().set_auto_accept_quit(false)
connect("visibility_changed", self, "_on_visibility_changed")
Expand Down
2 changes: 2 additions & 0 deletions scenes/gui/Window/Window.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extends Node2D

func _ready():
var default = settings.default_window_size
scale = OS.window_size / default
settings.connect("window_size_changed", self, "_on_window_size_changed")

func _on_window_size_changed(prev, now):
Expand Down
55 changes: 28 additions & 27 deletions scenes/gui/settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,10 @@ func _process(delta):
_prev_window_maximized = OS.window_maximized
_prev_window_fullscreen = OS.window_fullscreen

func set_window_options(fullscreen, maximized):
window_fullscreen = fullscreen
window_maximized = maximized

func apply():
match temp_window_type_id:
0: # Windowed
set_window_options(false, false)
1: # Fullscreen
set_window_options(true, false)
2: # Maximized
set_window_options(false, true)

window_size = temp_window_size
OS.vsync_enabled = temp_vsync_enabled

func save_conf():
var config = ConfigFile.new()
config.set_value("display", "width", window_size.x)
config.set_value("display", "height", window_size.y)
config.set_value("display", "width", _get_window_size().x)
config.set_value("display", "height", _get_window_size().y)
config.set_value("display", "fullscreen", get_window_type_id())
config.set_value("display", "vsync", OS.vsync_enabled)

Expand Down Expand Up @@ -145,13 +129,16 @@ func save_conf():
func load_conf():
var config = ConfigFile.new()
var err = config.load("user://settings.cfg")
if err == OK: # if not, something went wrong with the file loading
# Look for the display/width pair, and default to 1024 if missing
temp_window_size.x = config.get_value("display", "width", default_window_size.x)
temp_window_size.y = config.get_value("display", "height", default_window_size.y)
temp_window_type_id = config.get_value("display", "fullscreen", 0)
temp_vsync_enabled = config.get_value("display", "vsync", true)
apply()
if err != OK: # if not, something went wrong with the file loading
return

# Look for the display/width pair, and default to 1024 if missing
temp_window_size.x = config.get_value("display", "width", default_window_size.x)
temp_window_size.y = config.get_value("display", "height", default_window_size.y)
temp_window_type_id = config.get_value("display", "fullscreen", 0)
temp_vsync_enabled = config.get_value("display", "vsync", true)

apply()

var audio_bus = [
"Master",
Expand Down Expand Up @@ -184,5 +171,19 @@ func load_conf():
Ren.set_var("skip_all_text", skip_all_text)
Ren.set_var("skip_after_choices", skip_after_choices)

# Save the changes by overwriting the previous file
config.save("user://settings.cfg")
func set_window_options(fullscreen, maximized):
_set_window_fullscreen(fullscreen)
_set_window_maximized(maximized)

func apply():
match temp_window_type_id:
0: # Windowed
set_window_options(false, false)
1: # Fullscreen
set_window_options(true, false)
2: # Maximized
set_window_options(false, true)

_set_window_size(temp_window_size)
OS.vsync_enabled = temp_vsync_enabled

0 comments on commit a75816a

Please sign in to comment.