add graphics settings save
This commit is contained in:
@@ -5,18 +5,36 @@ class_name SettingsMenu
|
|||||||
@onready var audio_options_container: VBoxContainer = $%AudioOptionsContainer
|
@onready var audio_options_container: VBoxContainer = $%AudioOptionsContainer
|
||||||
@onready var aliasing_checkbox: CustomCheckbox = $%AliasingCheckbox
|
@onready var aliasing_checkbox: CustomCheckbox = $%AliasingCheckbox
|
||||||
|
|
||||||
|
@onready var window_option_menu = $VBoxContainer/WindowOptionMenu
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_refresh_audio_options()
|
_refresh_audio_options()
|
||||||
|
|
||||||
if aliasing_checkbox:
|
if aliasing_checkbox:
|
||||||
aliasing_checkbox.button_pressed = get_viewport().use_taa or get_viewport().msaa_3d != Viewport.MSAA_DISABLED
|
aliasing_checkbox.button_pressed = GameState.save_data.anti_aliasing
|
||||||
aliasing_checkbox.toggled.connect(_on_aliasing_toggled)
|
aliasing_checkbox.toggled.connect(_on_aliasing_toggled)
|
||||||
|
|
||||||
|
if window_option_menu:
|
||||||
|
var initial_res = Vector2i(GameState.save_data.resolution_x, GameState.save_data.resolution_y)
|
||||||
|
window_option_menu.initialize(GameState.save_data.window_mode_index, initial_res)
|
||||||
|
window_option_menu.mode_changed.connect(_on_window_mode_changed)
|
||||||
|
window_option_menu.resolution_changed.connect(_on_resolution_changed)
|
||||||
|
|
||||||
func _on_aliasing_toggled(toggled_on: bool) -> void:
|
func _on_aliasing_toggled(toggled_on: bool) -> void:
|
||||||
get_viewport().use_taa = toggled_on
|
GameState.save_data.anti_aliasing = toggled_on
|
||||||
var msaa_mode = Viewport.MSAA_2X if toggled_on else Viewport.MSAA_DISABLED
|
GameState.save_game()
|
||||||
get_viewport().msaa_3d = msaa_mode
|
GameState.apply_video_settings()
|
||||||
get_viewport().msaa_2d = msaa_mode
|
|
||||||
|
func _on_window_mode_changed(mode_index: int) -> void:
|
||||||
|
GameState.save_data.window_mode_index = mode_index
|
||||||
|
GameState.save_game()
|
||||||
|
GameState.apply_video_settings()
|
||||||
|
|
||||||
|
func _on_resolution_changed(resolution: Vector2i) -> void:
|
||||||
|
GameState.save_data.resolution_x = resolution.x
|
||||||
|
GameState.save_data.resolution_y = resolution.y
|
||||||
|
GameState.save_game()
|
||||||
|
GameState.apply_video_settings()
|
||||||
|
|
||||||
func _get_audio_options() -> Array[AudioOption]:
|
func _get_audio_options() -> Array[AudioOption]:
|
||||||
var audio_options: Array[AudioOption] = []
|
var audio_options: Array[AudioOption] = []
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ signal resolution_changed(resolution: Vector2i)
|
|||||||
@export var window_option_menu_button_scene: PackedScene
|
@export var window_option_menu_button_scene: PackedScene
|
||||||
|
|
||||||
var current_mode_index: int = 0
|
var current_mode_index: int = 0
|
||||||
|
var current_resolution: Vector2i = Vector2i.ZERO
|
||||||
|
|
||||||
var available_resolutions: Array[Vector2i] = [
|
var available_resolutions: Array[Vector2i] = [
|
||||||
Vector2i(1280, 720),
|
Vector2i(1280, 720),
|
||||||
@@ -37,6 +38,11 @@ func _ready() -> void:
|
|||||||
_populate_resolutions()
|
_populate_resolutions()
|
||||||
_update_ui()
|
_update_ui()
|
||||||
|
|
||||||
|
func initialize(mode_index: int, res: Vector2i) -> void:
|
||||||
|
current_mode_index = mode_index
|
||||||
|
current_resolution = res
|
||||||
|
_update_ui()
|
||||||
|
|
||||||
func _populate_resolutions() -> void:
|
func _populate_resolutions() -> void:
|
||||||
var screen_size = DisplayServer.screen_get_size()
|
var screen_size = DisplayServer.screen_get_size()
|
||||||
|
|
||||||
@@ -63,6 +69,7 @@ func _on_resolution_selected(res: Vector2i, btn) -> void:
|
|||||||
button.deselect()
|
button.deselect()
|
||||||
|
|
||||||
btn.select()
|
btn.select()
|
||||||
|
current_resolution = res
|
||||||
resolution_changed.emit(res)
|
resolution_changed.emit(res)
|
||||||
|
|
||||||
func _on_left_arrow_pressed() -> void:
|
func _on_left_arrow_pressed() -> void:
|
||||||
@@ -95,7 +102,16 @@ func _update_ui() -> void:
|
|||||||
else:
|
else:
|
||||||
button.disable()
|
button.disable()
|
||||||
|
|
||||||
var btn = res_buttons[0]
|
if res_buttons.size() > 0:
|
||||||
btn.select()
|
var target_index = 0
|
||||||
if show_res:
|
for idx in range(_valid_resolutions.size()):
|
||||||
resolution_changed.emit(available_resolutions[0])
|
if _valid_resolutions[idx] == current_resolution:
|
||||||
|
target_index = idx
|
||||||
|
break
|
||||||
|
|
||||||
|
var btn = res_buttons[target_index]
|
||||||
|
btn.select()
|
||||||
|
current_resolution = _valid_resolutions[target_index]
|
||||||
|
|
||||||
|
if show_res:
|
||||||
|
resolution_changed.emit(current_resolution)
|
||||||
|
|||||||
@@ -28,6 +28,31 @@ var is_loaded: bool = false
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
load_game()
|
load_game()
|
||||||
|
apply_video_settings()
|
||||||
|
|
||||||
|
func apply_video_settings() -> void:
|
||||||
|
get_viewport().use_taa = save_data.anti_aliasing
|
||||||
|
var msaa_mode = Viewport.MSAA_2X if save_data.anti_aliasing else Viewport.MSAA_DISABLED
|
||||||
|
get_viewport().msaa_3d = msaa_mode
|
||||||
|
get_viewport().msaa_2d = msaa_mode
|
||||||
|
|
||||||
|
match save_data.window_mode_index:
|
||||||
|
0:
|
||||||
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
|
||||||
|
1:
|
||||||
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||||
|
2:
|
||||||
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||||
|
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
|
||||||
|
|
||||||
|
if save_data.window_mode_index == 2 and save_data.resolution_x > 0 and save_data.resolution_y > 0:
|
||||||
|
DisplayServer.window_set_size(Vector2i(save_data.resolution_x, save_data.resolution_y))
|
||||||
|
|
||||||
|
# Optional: center the window if resized
|
||||||
|
var screen_center = DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2
|
||||||
|
var window_size = DisplayServer.window_get_size()
|
||||||
|
DisplayServer.window_set_position(screen_center - window_size / 2)
|
||||||
|
|
||||||
|
|
||||||
func save_game() -> void:
|
func save_game() -> void:
|
||||||
var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ var unlocked_collectibles_ids: Array[StringName] = []
|
|||||||
var saved_photos: Array[String] = []
|
var saved_photos: Array[String] = []
|
||||||
var audio_bus_volumes: Dictionary[String, float] = {}
|
var audio_bus_volumes: Dictionary[String, float] = {}
|
||||||
|
|
||||||
|
var anti_aliasing: bool = true
|
||||||
|
var window_mode_index: int = 0
|
||||||
|
var resolution_x: int = 1920
|
||||||
|
var resolution_y: int = 1080
|
||||||
|
|
||||||
func to_dictionary() -> Dictionary:
|
func to_dictionary() -> Dictionary:
|
||||||
var serialized_collectible_ids: Array[String] = []
|
var serialized_collectible_ids: Array[String] = []
|
||||||
for collectible_id in unlocked_collectibles_ids:
|
for collectible_id in unlocked_collectibles_ids:
|
||||||
@@ -14,6 +19,10 @@ func to_dictionary() -> Dictionary:
|
|||||||
"unlocked_collectibles_ids": serialized_collectible_ids,
|
"unlocked_collectibles_ids": serialized_collectible_ids,
|
||||||
"saved_photos": saved_photos,
|
"saved_photos": saved_photos,
|
||||||
"audio_bus_volumes": audio_bus_volumes,
|
"audio_bus_volumes": audio_bus_volumes,
|
||||||
|
"anti_aliasing": anti_aliasing,
|
||||||
|
"window_mode_index": window_mode_index,
|
||||||
|
"resolution_x": resolution_x,
|
||||||
|
"resolution_y": resolution_y,
|
||||||
}
|
}
|
||||||
|
|
||||||
static func from_dictionary(data: Dictionary) -> SaveGameData:
|
static func from_dictionary(data: Dictionary) -> SaveGameData:
|
||||||
@@ -31,4 +40,16 @@ static func from_dictionary(data: Dictionary) -> SaveGameData:
|
|||||||
for bus_name in data["audio_bus_volumes"]:
|
for bus_name in data["audio_bus_volumes"]:
|
||||||
save_game_data.audio_bus_volumes[str(bus_name)] = float(data["audio_bus_volumes"][bus_name])
|
save_game_data.audio_bus_volumes[str(bus_name)] = float(data["audio_bus_volumes"][bus_name])
|
||||||
|
|
||||||
|
if data.has("anti_aliasing"):
|
||||||
|
save_game_data.anti_aliasing = bool(data["anti_aliasing"])
|
||||||
|
|
||||||
|
if data.has("window_mode_index"):
|
||||||
|
save_game_data.window_mode_index = int(data["window_mode_index"])
|
||||||
|
|
||||||
|
if data.has("resolution_x"):
|
||||||
|
save_game_data.resolution_x = int(data["resolution_x"])
|
||||||
|
|
||||||
|
if data.has("resolution_y"):
|
||||||
|
save_game_data.resolution_y = int(data["resolution_y"])
|
||||||
|
|
||||||
return save_game_data
|
return save_game_data
|
||||||
|
|||||||
Reference in New Issue
Block a user