feat: added advanced settings for showing player movement debug and settings for mouse sensistivity
This commit is contained in:
@@ -28,9 +28,7 @@ func _ready() -> void:
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
var sens := sensitivity
|
||||
if params:
|
||||
sens = params.mouse_sensitivity
|
||||
var sens = SettingsManager.mouse_sensitivity
|
||||
# Yaw: rotate the player (parent)
|
||||
get_parent().rotate_y(-event.relative.x * sens)
|
||||
# Pitch: rotate this pivot
|
||||
|
||||
@@ -13,6 +13,7 @@ var _dash_icon: TextureRect
|
||||
var _grapple_label: Label
|
||||
var _dash_label: Label
|
||||
var _player: CharacterBody3D
|
||||
var _debug_ui_panel: PanelContainer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -400,12 +401,12 @@ func _build_hud() -> void:
|
||||
crosshair.add_child(line)
|
||||
|
||||
# ── Info panel background ─────────────────────────────────────────────
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "InfoPanel"
|
||||
panel.offset_left = 12
|
||||
panel.offset_top = 12
|
||||
panel.offset_right = 400
|
||||
panel.offset_bottom = 120
|
||||
_debug_ui_panel = PanelContainer.new()
|
||||
_debug_ui_panel.name = "InfoPanel"
|
||||
_debug_ui_panel.offset_left = 12
|
||||
_debug_ui_panel.offset_top = 12
|
||||
_debug_ui_panel.offset_right = 400
|
||||
_debug_ui_panel.offset_bottom = 120
|
||||
var panel_style := StyleBoxFlat.new()
|
||||
panel_style.bg_color = Color(0, 0, 0, 0.55)
|
||||
panel_style.corner_radius_top_left = 8
|
||||
@@ -416,12 +417,12 @@ func _build_hud() -> void:
|
||||
panel_style.content_margin_top = 8
|
||||
panel_style.content_margin_right = 12
|
||||
panel_style.content_margin_bottom = 8
|
||||
panel.add_theme_stylebox_override("panel", panel_style)
|
||||
canvas.add_child(panel)
|
||||
_debug_ui_panel.add_theme_stylebox_override("panel", panel_style)
|
||||
canvas.add_child(_debug_ui_panel)
|
||||
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.name = "InfoVBox"
|
||||
panel.add_child(vbox)
|
||||
_debug_ui_panel.add_child(vbox)
|
||||
|
||||
_speed_label = Label.new()
|
||||
_speed_label.name = "SpeedLabel"
|
||||
@@ -560,6 +561,9 @@ func _process(_delta: float) -> void:
|
||||
if not _player or not is_instance_valid(_player):
|
||||
return
|
||||
|
||||
if _debug_ui_panel:
|
||||
_debug_ui_panel.visible = SettingsManager.show_debug_ui
|
||||
|
||||
var vel: Vector3 = _player.velocity
|
||||
var hspeed := Vector2(vel.x, vel.z).length()
|
||||
var total_speed := vel.length()
|
||||
|
||||
@@ -23,6 +23,8 @@ var default_bindings = {
|
||||
}
|
||||
|
||||
var current_bindings = {}
|
||||
var show_debug_ui: bool = false
|
||||
var mouse_sensitivity: float = 0.002
|
||||
|
||||
func _ready() -> void:
|
||||
# Initialize defaults
|
||||
@@ -74,7 +76,9 @@ func reset_to_defaults() -> void:
|
||||
|
||||
func _save_settings() -> void:
|
||||
var save_data = {
|
||||
"bindings": current_bindings
|
||||
"bindings": current_bindings,
|
||||
"show_debug_ui": show_debug_ui,
|
||||
"mouse_sensitivity": mouse_sensitivity
|
||||
}
|
||||
var json_string = JSON.stringify(save_data)
|
||||
var file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
||||
@@ -93,8 +97,13 @@ func _load_settings() -> void:
|
||||
var error = json.parse(json_string)
|
||||
if error == OK:
|
||||
var data = json.get_data()
|
||||
if data is Dictionary and data.has("bindings"):
|
||||
var loaded_bindings = data["bindings"]
|
||||
for action in loaded_bindings:
|
||||
if current_bindings.has(action):
|
||||
current_bindings[action] = loaded_bindings[action]
|
||||
if data is Dictionary:
|
||||
if data.has("bindings"):
|
||||
var loaded_bindings = data["bindings"]
|
||||
for action in loaded_bindings:
|
||||
if current_bindings.has(action):
|
||||
current_bindings[action] = loaded_bindings[action]
|
||||
if data.has("show_debug_ui"):
|
||||
show_debug_ui = data["show_debug_ui"]
|
||||
if data.has("mouse_sensitivity"):
|
||||
mouse_sensitivity = data["mouse_sensitivity"]
|
||||
|
||||
+118
-8
@@ -23,6 +23,9 @@ var editing_index: int = -1
|
||||
# Settings UI
|
||||
var settings_editor: Control
|
||||
var settings_back_btn: Button
|
||||
var _debug_ui_checkbox: CheckButton
|
||||
var _mouse_sens_slider: HSlider
|
||||
var _mouse_sens_input: LineEdit
|
||||
var keybind_vbox: VBoxContainer
|
||||
var rebind_overlay: ColorRect
|
||||
var rebind_label: Label
|
||||
@@ -209,19 +212,78 @@ func _build_ui() -> void:
|
||||
gen_label.text = "Settings coming soon..."
|
||||
general_tab.add_child(gen_label)
|
||||
|
||||
var spacer_gen = Control.new()
|
||||
spacer_gen.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
general_tab.add_child(spacer_gen)
|
||||
|
||||
var reset_gen_btn = Button.new()
|
||||
reset_gen_btn.text = "Reset to Defaults"
|
||||
reset_gen_btn.pressed.connect(func():
|
||||
pass # No settings yet
|
||||
)
|
||||
general_tab.add_child(reset_gen_btn)
|
||||
|
||||
# Mouse Tab
|
||||
var mouse_tab = VBoxContainer.new()
|
||||
mouse_tab.name = "Mouse"
|
||||
mouse_tab.add_theme_constant_override("separation", 10)
|
||||
tab_container.add_child(mouse_tab)
|
||||
|
||||
var sens_hbox = HBoxContainer.new()
|
||||
mouse_tab.add_child(sens_hbox)
|
||||
|
||||
var sens_title = Label.new()
|
||||
sens_title.text = "Sensitivity"
|
||||
sens_title.custom_minimum_size = Vector2(150, 0)
|
||||
sens_hbox.add_child(sens_title)
|
||||
|
||||
_mouse_sens_slider = HSlider.new()
|
||||
_mouse_sens_slider.min_value = 1.0
|
||||
_mouse_sens_slider.max_value = 100.0
|
||||
_mouse_sens_slider.step = 1.0
|
||||
_mouse_sens_slider.value = SettingsManager.mouse_sensitivity * 10000.0
|
||||
_mouse_sens_slider.custom_minimum_size = Vector2(200, 0)
|
||||
_mouse_sens_slider.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
sens_hbox.add_child(_mouse_sens_slider)
|
||||
|
||||
_mouse_sens_input = LineEdit.new()
|
||||
_mouse_sens_input.text = str(round(SettingsManager.mouse_sensitivity * 10000.0))
|
||||
_mouse_sens_input.custom_minimum_size = Vector2(60, 0)
|
||||
sens_hbox.add_child(_mouse_sens_input)
|
||||
|
||||
_mouse_sens_slider.value_changed.connect(func(value: float):
|
||||
_mouse_sens_input.text = str(round(value))
|
||||
SettingsManager.mouse_sensitivity = value / 10000.0
|
||||
SettingsManager._save_settings()
|
||||
)
|
||||
|
||||
_mouse_sens_input.text_submitted.connect(func(new_text: String):
|
||||
var val = new_text.to_float()
|
||||
val = clampf(val, 1.0, 100.0)
|
||||
_mouse_sens_slider.value = val
|
||||
_mouse_sens_input.text = str(round(val))
|
||||
SettingsManager.mouse_sensitivity = val / 10000.0
|
||||
SettingsManager._save_settings()
|
||||
)
|
||||
|
||||
var spacer_mouse = Control.new()
|
||||
spacer_mouse.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
mouse_tab.add_child(spacer_mouse)
|
||||
|
||||
var reset_mouse_btn = Button.new()
|
||||
reset_mouse_btn.text = "Reset to Defaults"
|
||||
reset_mouse_btn.pressed.connect(func():
|
||||
_mouse_sens_slider.value = 20.0
|
||||
SettingsManager.mouse_sensitivity = 0.002
|
||||
SettingsManager._save_settings()
|
||||
)
|
||||
mouse_tab.add_child(reset_mouse_btn)
|
||||
|
||||
# Keybindings Tab
|
||||
var key_tab = VBoxContainer.new()
|
||||
key_tab.name = "Keybindings"
|
||||
tab_container.add_child(key_tab)
|
||||
|
||||
var reset_btn = Button.new()
|
||||
reset_btn.text = "Reset to Defaults"
|
||||
reset_btn.pressed.connect(func():
|
||||
SettingsManager.reset_to_defaults()
|
||||
_populate_keybindings()
|
||||
)
|
||||
key_tab.add_child(reset_btn)
|
||||
|
||||
var scroll = ScrollContainer.new()
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
key_tab.add_child(scroll)
|
||||
@@ -230,6 +292,47 @@ func _build_ui() -> void:
|
||||
keybind_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
scroll.add_child(keybind_vbox)
|
||||
|
||||
var reset_key_btn = Button.new()
|
||||
reset_key_btn.text = "Reset to Defaults"
|
||||
reset_key_btn.pressed.connect(func():
|
||||
SettingsManager.reset_to_defaults()
|
||||
_populate_keybindings()
|
||||
)
|
||||
key_tab.add_child(reset_key_btn)
|
||||
|
||||
# Advanced Tab
|
||||
var advanced_tab = VBoxContainer.new()
|
||||
advanced_tab.name = "Advanced"
|
||||
advanced_tab.add_theme_constant_override("separation", 10)
|
||||
tab_container.add_child(advanced_tab)
|
||||
|
||||
var debug_label = Label.new()
|
||||
debug_label.text = "--- Debug ---"
|
||||
debug_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
advanced_tab.add_child(debug_label)
|
||||
|
||||
_debug_ui_checkbox = CheckButton.new()
|
||||
_debug_ui_checkbox.text = "Show Debug UI (Speed, State, Buffs)"
|
||||
_debug_ui_checkbox.button_pressed = SettingsManager.show_debug_ui
|
||||
_debug_ui_checkbox.toggled.connect(func(toggled_on: bool):
|
||||
SettingsManager.show_debug_ui = toggled_on
|
||||
SettingsManager._save_settings()
|
||||
)
|
||||
advanced_tab.add_child(_debug_ui_checkbox)
|
||||
|
||||
var spacer_adv = Control.new()
|
||||
spacer_adv.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
advanced_tab.add_child(spacer_adv)
|
||||
|
||||
var reset_adv_btn = Button.new()
|
||||
reset_adv_btn.text = "Reset to Defaults"
|
||||
reset_adv_btn.pressed.connect(func():
|
||||
_debug_ui_checkbox.button_pressed = false
|
||||
SettingsManager.show_debug_ui = false
|
||||
SettingsManager._save_settings()
|
||||
)
|
||||
advanced_tab.add_child(reset_adv_btn)
|
||||
|
||||
# Rebind Overlay
|
||||
rebind_overlay = ColorRect.new()
|
||||
rebind_overlay.color = Color(0, 0, 0, 0.85)
|
||||
@@ -286,6 +389,13 @@ func _show_settings() -> void:
|
||||
loadout_editor.visible = false
|
||||
settings_editor.visible = true
|
||||
_populate_keybindings()
|
||||
if _debug_ui_checkbox:
|
||||
_debug_ui_checkbox.button_pressed = SettingsManager.show_debug_ui
|
||||
if _mouse_sens_slider:
|
||||
var display_val = round(SettingsManager.mouse_sensitivity * 10000.0)
|
||||
_mouse_sens_slider.value = display_val
|
||||
if _mouse_sens_input:
|
||||
_mouse_sens_input.text = str(display_val)
|
||||
|
||||
func _populate_keybindings() -> void:
|
||||
for c in keybind_vbox.get_children():
|
||||
|
||||
Reference in New Issue
Block a user