breadwinner/classes/options/display_option.gd
Hellie-xd 900f5eb6c3 kinda working options menu, but needs work
also audio lags on my pc, probably the cpu cant keep up with the audio
2026-08-12 01:47:15 +02:00

77 lines
2.1 KiB
GDScript

class_name DisplayOptions extends Options
#TODO: add gameplay related settings here, each have their own property
var current_resolution: Vector2 = Vector2(1920, 1080):
set(value):
current_resolution = value
# 1. Grab the SceneTree directly from the Engine
var tree := Engine.get_main_loop() as SceneTree
# 2. SAFETY CHECK: If the game is still booting up, ignore this
if not tree or not tree.root:
return
var window_size = Vector2i(value.x, value.y)
if tree.root.mode == Window.MODE_WINDOWED:
tree.root.size = window_size
var screen_size = DisplayServer.screen_get_size()
tree.root.position = (screen_size / 2) - (window_size / 2)
var max_framerate: float = 0:
set(value):
Engine.max_fps = int(value)
func _apply_windowed_size() -> void:
var tree := Engine.get_main_loop() as SceneTree
if not tree or not tree.root:
return
var window_size = Vector2i(current_resolution.x, current_resolution.y)
# Apply size to the root window (Forces UI to scale properly)
tree.root.size = window_size
var screen_size = DisplayServer.screen_get_size()
tree.root.position = (screen_size / 2) - (window_size / 2)
@export var current_window_mode: WindowMode = WindowMode.WINDOWED:
set(value):
current_window_mode = value
var tree := Engine.get_main_loop() as SceneTree
if not tree or not tree.root:
return
match value:
WindowMode.WINDOWED:
tree.root.mode = Window.MODE_WINDOWED
_apply_windowed_size.call_deferred()
WindowMode.FULLSCREEN:
tree.root.mode = Window.MODE_EXCLUSIVE_FULLSCREEN
WindowMode.BORDERLESS:
tree.root.mode = Window.MODE_FULLSCREEN
var vsync: bool = false:
set(value):
if value:
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED)
else:
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED)
static var available_resolutions: Array[Vector2] = [Vector2(1920,1080), Vector2(1280, 720), Vector2(1080, 1920)]
enum WindowMode {
FULLSCREEN,
WINDOWED,
BORDERLESS
}
func _init() -> void:
cur_type = Options.type.GRAPHICS
func _ready() -> void:
current_resolution = current_resolution
current_window_mode = current_window_mode