classname OptionsTabMenu extends Control signal optionsupdated Grabbing TabContainer…
- User
class_name OptionsTabMenu extends Control signal options_updated
Grabbing TabContainer node for gamepad navigation
@onready var tab_container: CogitoTabMenu = $VBoxContainer/TabContainer
const HSliderWLabel = preload("res://addons/cogito/EasyMenus/Scripts/slider_w_labels.gd") var config = ConfigFile.new()
var have_options_changed: bool = false
GAMEPLAY
@onready var invert_y_check_button: CheckButton = %InvertYAxisCheckButton @onready var toggle_crouching_check_button: CheckButton = %ToggleCrouchingCheckButton @onready var headbob_option_button: OptionButton = %HeadbobOptionButton @onready var mouse_sens_slider: HSlider = %MouseSensSlider @onready var mouse_sens_value_label: Label = %MouseSensValueLabel @onready var gp_look_sens_value_label: Label = %GPLookSensValueLabel @onready var gp_look_sens_slider: HSlider = %GPLookSensSlider
- Assistant
- User
var render_resolution : Vector2i var prev_resolution : Vector2i var render_scale_val : float
const HEADBOB_DICTIONARY : Dictionary = { "Minimal" : 1, "Average" : 3, "Full" : 7, }
Array to set window modes.
const WINDOW_MODE_ARRAY : Array[String] = [ "Exclusive full screen", "Full screen", "Windowed", "Borderless windowed", ]
const RESOLUTION_DICTIONARY : Dictionary = { "1280x720 (16:9)" : Vector2i(1280,720), "1280x800 (16:10)" : Vector2i(1280,800), "1366x768 (16:9)" : Vector2i(1366,768), "1440x900 (16:10)" : Vector2i(1440,900), "1600x900 (16:9)" : Vector2i(1600,900), "1920x1080 (16:9)" : Vector2i(1920,1080), "2560x1440 (16:9)" : Vector2i(2560,1440), "3840x2160 (16:9)" : Vector2i(3840,2160), }
- Assistant
- User
- Assistant
- User
func _ready() -> void: # GAMEPLAY add_headbob_items() headbob_option_button.item_selected.connect(on_headbob_selected) mouse_sens_slider.value_changed.connect(_on_mouse_sens_slider_value_changed) gp_look_sens_slider.value_changed.connect(_on_gp_looksens_slider_value_changed)
# GRAPHICS add_window_mode_items() add_resolution_items() window_mode_option_button.item_selected.connect(on_window_mode_selected) resolution_option_button.item_selected.connect(on_resolution_selected) render_scale_slider.value_changed.connect(_on_render_scale_slider_value_changed) gui_scale_slider.value_changed.connect(_on_gui_scale_slider_value_changed) # AUDIO sfx_bus_index = AudioServer.get_bus_index(OptionsConstants.sfx_bus_name) music_bus_index = AudioServer.get_bus_index(OptionsConstants.music_bus_name) sfx_volume_slider.hslider.value_changed.connect(_on_sfx_volume_slider_value_changed) music_volume_slider.hslider.value_changed.connect(_on_music_volume_slider_value_changed) load_options() load_keybindings_from_config() create_action_remap_items() - Assistant
- User
Called from outside initializes the options menu
func on_open(): pass
Adding headbob options to the button
func add_headbob_items() -> void: for headbob_option in HEADBOB_DICTIONARY: headbob_option_button.add_item(headbob_option)
func on_headbob_selected(index:int) -> void: headbob_strength = HEADBOB_DICTIONARY.values()[index]
func _on_mouse_sens_slider_value_changed(value): mouse_sens = value mouse_sens_value_label.text = str(value)
func _on_gp_looksens_slider_value_changed(value): gp_looksens = value gp_look_sens_value_label.text = str(value)
Adding window modes to the window mode button.
func add_window_mode_items() -> void: for mode in WINDOW_MODE_ARRAY: window_mode_option_button.add_item(mode)
Adding resolutions to the resolution button.
func add_resolution_items() -> void: for resolution_text in RESOLUTION_DICTIONARY: resolution_option_button.add_item(resolution_text)
- Assistant
- User
func on_window_mode_selected(index: int) -> void: match index: 0: #Exclusive full screen DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN) 1: #Full screen DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) 2: #Windowed DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) 3: #Borderless windowed DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
func refresh_render(): get_window().size = render_resolution get_window().content_scale_size = render_resolution get_window().scaling_3d_scale = render_scale_val
var msaa_2d = config.get_value(OptionsConstants.section_name, OptionsConstants.msaa_2d_key, 0) var msaa_3d = config.get_value(OptionsConstants.section_name, OptionsConstants.msaa_3d_key, 0) set_msaa("msaa_2d", msaa_2d) set_msaa("msaa_3d", msaa_3d) - Assistant
- User
func on_window_mode_selected(index: int) -> void: match index: 0: #Exclusive full screen DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN) 1: #Full screen DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) 2: #Windowed DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) 3: #Borderless windowed DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
func refresh_render(): get_window().size = render_resolution get_window().content_scale_size = render_resolution get_window().scaling_3d_scale = render_scale_val
var msaa_2d = config.get_value(OptionsConstants.section_name, OptionsConstants.msaa_2d_key, 0) var msaa_3d = config.get_value(OptionsConstants.section_name, OptionsConstants.msaa_3d_key, 0) set_msaa("msaa_2d", msaa_2d) set_msaa("msaa_3d", msaa_3d)Function to change resolution. Hooked up to the resolution_option_button.
func on_resolution_selected(index:int) -> void: prev_resolution = render_resolution render_resolution = RESOLUTION_DICTIONARY.values()[index] if prev_resolution != render_resolution: have_options_changed = true
- Assistant
- User
Sets the volume for the given audio bus
func set_volume(bus_index, value): AudioServer.set_bus_volume_db(bus_index, linear_to_db(value))
Saves the options
func save_options(): config.set_value(OptionsConstants.section_name, OptionsConstants.invert_vertical_axis_key, invert_y_check_button.button_pressed) config.set_value(OptionsConstants.section_name, OptionsConstants.toggle_crouching_key, toggle_crouching_check_button.button_pressed) config.set_value(OptionsConstants.section_name, OptionsConstants.head_bobble_key, headbob_strength) config.set_value(OptionsConstants.section_name, OptionsConstants.mouse_sens_key, mouse_sens) config.set_value(OptionsConstants.section_name, OptionsConstants.gp_looksens_key, gp_looksens) config.set_value(OptionsConstants.section_name, OptionsConstants.windowmode_key_name, window_mode_option_button.selected) config.set_value(OptionsConstants.section_name, OptionsConstants.resolution_index_key_name, resolution_option_button.selected) config.set_value(OptionsConstants.section_name, OptionsConstants.render_scale_key, render_scale_slider.value); config.set_value(OptionsConstants.section_name, OptionsConstants.gui_scale_key, gui_scale_slider.value); config.set_value(OptionsConstants.section_name, OptionsConstants.vsync_key, vsync_check_button.button_pressed) config.set_value(OptionsConstants.section_name, OptionsConstants.msaa_2d_key, anti_aliasing_2d_option_button.get_selected_id()) config.set_value(OptionsConstants.section_name, OptionsConstants.msaa_3d_key, anti_aliasing_3d_option_button.get_selected_id())
- Assistant
- User
- Assistant
- User
func _on_render_scale_slider_value_changed(value): render_scale_val = value render_scale_current_value_label.text = str(value) have_options_changed = true
func _on_gui_scale_slider_value_changed(value): apply_gui_scale_value()
func _on_gui_scale_slider_drag_ended(_value_changed): apply_gui_scale_value()
func apply_gui_scale_value(): get_viewport().content_scale_factor = gui_scale_slider.value gui_scale_current_value_label.text = str(gui_scale_slider.value) have_options_changed = true
func _on_v_sync_check_button_toggled(button_pressed): # There are multiple V-Sync Methods supported by Godot # For now we just use the simple ones could be worth a consideration to add the others # Just sets V-Sync for the first window. So no support for multi window games if button_pressed: DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) else: DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED)
func _on_anti_aliasing_2d_option_button_item_selected(index): set_msaa("msaa_2d", index)
func _on_anti_aliasing_3d_option_button_item_selected(index): set_msaa("msaa_3d", index)
func set_msaa(mode, index): match index: 0: get_viewport().set(mode,Viewport.MSAA_DISABLED) 1: get_viewport().set(mode,Viewport.MSAA_2X) 2: get_viewport().set(mode,Viewport.MSAA_4X) 3: get_viewport().set(mode,Viewport.MSAA_8X)
- Assistant
- User
func load_keybindings_from_config(): var err = config.load(OptionsConstants.config_file_name) if err != 0: CogitoGlobals.debug_log(true, "OptionsTabMenu.gd","Keybindings: Loading options config failed.") #save_keybindings_to_config()
var serialized_inputs = config.get_value(OptionsConstants.key_binds, OptionsConstants.input_helper_string, serialized_default_inputs) if serialized_inputs: InputHelper.deserialize_inputs_for_actions(serialized_inputs) else: CogitoGlobals.debug_log(true, "OptionsTabMenu.gd","Keybindings: No saved bindings found.")func save_keybindings_to_config(): var serialized_inputs = InputHelper.serialize_inputs_for_actions() config.set_value(OptionsConstants.key_binds, OptionsConstants.input_helper_string, serialized_inputs) config.save(OptionsConstants.config_file_name)
func create_action_remap_items() -> void: for action in input_actions: if action.contains("separator"): var separator = separator_entry.instantiate() bindings_container.add_child(separator) separator.separator_text = input_actions[action] else: var input_entry = remap_entry.instantiate() input_entry.action = action bindings_container.add_child(input_entry) input_entry.label.text = input_actions[action]
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.