Compare commits

...

18 Commits

Author SHA1 Message Date
cbf625d2ff fix: update scene files for unique IDs and adjust JumpForce in JumpPadComponent 2026-03-19 11:32:48 +01:00
057cf7b368 feat: add UID files for InputDeviceManager, SettingsManager, DisplaySettings, GameplaySettings, and InputSettings 2026-03-19 03:53:49 +01:00
829d081eab fix: unsubscribe VisibilityChanged in _ExitTree, use IsActionReleased for ui_cancel, expose ApplyGamepadDeadzone public 2026-03-19 03:51:01 +01:00
38c86f1a67 feat: gameplay settings screen (deadzone + sensitivity) 2026-03-19 03:47:15 +01:00
e647cd7b29 feat: marketplace keyboard/gamepad navigation 2026-03-19 03:44:35 +01:00
9043cfa63c fix: InputSettings PhysicalKeycode, visibility guard, dead code, delegate save 2026-03-19 03:42:47 +01:00
dc46769c11 feat: input remapping screen with conflict detection and config persistence 2026-03-19 03:39:19 +01:00
47600be867 fix: route resolution change through SettingsManager.ApplyDisplaySettings 2026-03-19 03:36:29 +01:00
3e74959bb9 fix: DisplaySettings focus mode, remove duplicate ApplyWindowMode 2026-03-19 03:35:28 +01:00
8cce1866b1 feat: display settings screen with window mode and resolution picker 2026-03-19 03:32:40 +01:00
0105698c33 fix: guard GrabFirstFocus on pointerless, unsub VisibilityChanged in _ExitTree 2026-03-19 03:29:36 +01:00
3b18e328b2 feat: gamepad/keyboard UI navigation on all menus 2026-03-19 03:26:50 +01:00
2bc0b76050 fix: joypad drift threshold + move InputDevice enum inside class 2026-03-19 03:24:19 +01:00
d83e3b4d82 feat: add InputDeviceManager autoload for input device tracking 2026-03-19 03:22:17 +01:00
42d7df27ae fix: SettingsManager null guard, ui_ filter, double cast for sensitivity/deadzone 2026-03-19 03:21:04 +01:00
fd54e16bf4 fix: make GamepadDeadzone/Sensitivity/WindowMode/Resolution setters public 2026-03-19 03:18:46 +01:00
92a3c4f79a feat: add SettingsManager autoload for display, gamepad and input binding settings 2026-03-19 03:17:26 +01:00
654a8b7ea7 fix: add .worktrees/ to gitignore 2026-03-19 03:15:09 +01:00
31 changed files with 1099 additions and 81 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
# Godot 4+ specific ignores # Godot 4+ specific ignores
.godot/ .godot/
/android/ /android/
builds/.worktrees/ builds/
.worktrees/

View File

@@ -0,0 +1,54 @@
using Godot;
namespace Mr.BrickAdventures.Autoloads;
public partial class InputDeviceManager : Node
{
public enum InputDevice { Mouse, Keyboard, Gamepad }
public static InputDeviceManager Instance { get; private set; }
public InputDevice CurrentDevice { get; private set; } = InputDevice.Mouse;
public bool IsPointerless => CurrentDevice is InputDevice.Keyboard or InputDevice.Gamepad;
[Signal] public delegate void DeviceChangedEventHandler(int device);
public override void _Ready()
{
Instance = this;
Input.MouseMode = Input.MouseModeEnum.Visible;
}
public override void _ExitTree()
{
if (Instance == this) Instance = null;
}
public override void _Input(InputEvent @event)
{
InputDevice detected;
if (@event is InputEventMouseMotion or InputEventMouseButton)
detected = InputDevice.Mouse;
else if (@event is InputEventKey)
detected = InputDevice.Keyboard;
else if (@event is InputEventJoypadButton)
detected = InputDevice.Gamepad;
else if (@event is InputEventJoypadMotion joyEvent)
{
if (Mathf.Abs(joyEvent.AxisValue) <= 0.15f) return;
detected = InputDevice.Gamepad;
}
else
return;
if (detected == CurrentDevice) return;
CurrentDevice = detected;
Input.MouseMode = CurrentDevice == InputDevice.Mouse
? Input.MouseModeEnum.Visible
: Input.MouseModeEnum.Hidden;
EmitSignal(SignalName.DeviceChanged, (int)CurrentDevice);
}
}

View File

@@ -0,0 +1 @@
uid://b81610g8fd6p1

View File

@@ -0,0 +1,203 @@
using Godot;
using System.Collections.Generic;
namespace Mr.BrickAdventures.Autoloads;
public partial class SettingsManager : Node
{
public static SettingsManager Instance { get; private set; }
public float GamepadDeadzone { get; set; } = 0.2f;
public float GamepadSensitivity { get; set; } = 1.0f;
public string WindowMode { get; set; } = "fullscreen";
public Vector2I Resolution { get; set; } = new Vector2I(1920, 1080);
private static readonly List<Vector2I> CuratedResolutions = new()
{
// 4:3
new Vector2I(640, 480),
new Vector2I(800, 600),
new Vector2I(1024, 768),
new Vector2I(1280, 960),
new Vector2I(1600, 1200),
// 16:9
new Vector2I(1280, 720),
new Vector2I(1366, 768),
new Vector2I(1600, 900),
new Vector2I(1920, 1080),
new Vector2I(2560, 1440),
new Vector2I(3840, 2160),
// 16:10
new Vector2I(1280, 800),
new Vector2I(1440, 900),
new Vector2I(1920, 1200),
new Vector2I(2560, 1600),
};
private readonly List<Vector2I> _customResolutions = new();
private static readonly string[] DeadzoneActions = { "left", "right", "up", "down" };
public override void _Ready()
{
Instance = this;
if (ConfigFileHandler.Instance == null)
{
GD.PushError("SettingsManager: ConfigFileHandler.Instance is null");
return;
}
var cfg = ConfigFileHandler.Instance.SettingsConfig;
// --- display_settings ---
WindowMode = cfg.GetValue("display_settings", "window_mode", Variant.From("fullscreen")).AsString();
var resStr = cfg.GetValue("display_settings", "resolution", Variant.From("1920x1080")).AsString();
Resolution = ParseResolution(resStr, new Vector2I(1920, 1080));
var customResStr = cfg.GetValue("display_settings", "custom_resolutions", Variant.From("")).AsString();
if (!string.IsNullOrWhiteSpace(customResStr))
{
foreach (var part in customResStr.Split(','))
{
var r = ParseResolution(part.Trim(), Vector2I.Zero);
if (r != Vector2I.Zero)
_customResolutions.Add(r);
}
}
ApplyDisplaySettings();
// --- gameplay_settings ---
GamepadDeadzone = (float)cfg.GetValue("gameplay_settings", "gamepad_deadzone", Variant.From(0.2)).AsDouble();
GamepadSensitivity = (float)cfg.GetValue("gameplay_settings", "gamepad_sensitivity", Variant.From(1.0)).AsDouble();
ApplyGamepadDeadzone();
// --- input_settings ---
ApplyInputBindings(cfg);
}
public override void _ExitTree()
{
if (Instance == this) Instance = null;
}
// ── public API ───────────────────────────────────────────────────────────
public List<Vector2I> GetAllResolutions()
{
var all = new List<Vector2I>(CuratedResolutions);
all.AddRange(_customResolutions);
return all;
}
public void SaveDisplaySettings()
{
var cfg = ConfigFileHandler.Instance.SettingsConfig;
cfg.SetValue("display_settings", "window_mode", WindowMode);
cfg.SetValue("display_settings", "resolution", $"{Resolution.X}x{Resolution.Y}");
cfg.SetValue("display_settings", "custom_resolutions", BuildCustomResolutionsString());
cfg.Save(ConfigFileHandler.SettingsPath);
}
public void SaveGameplaySettings()
{
var cfg = ConfigFileHandler.Instance.SettingsConfig;
cfg.SetValue("gameplay_settings", "gamepad_deadzone", (double)GamepadDeadzone);
cfg.SetValue("gameplay_settings", "gamepad_sensitivity", (double)GamepadSensitivity);
cfg.Save(ConfigFileHandler.SettingsPath);
}
public void SaveInputSettings()
{
var cfg = ConfigFileHandler.Instance.SettingsConfig;
foreach (var action in InputMap.GetActions())
{
if (action.ToString().StartsWith("ui_")) continue;
foreach (var ev in InputMap.ActionGetEvents(action))
{
if (ev is InputEventKey key)
{
cfg.SetValue("input_settings", action, (long)key.PhysicalKeycode);
break;
}
}
}
cfg.Save(ConfigFileHandler.SettingsPath);
}
// ── apply helpers ────────────────────────────────────────────────────────
public void ApplyDisplaySettings()
{
switch (WindowMode)
{
case "fullscreen":
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
break;
case "borderless":
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Borderless, true);
DisplayServer.WindowSetSize(Resolution);
break;
default: // "windowed"
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Borderless, false);
DisplayServer.WindowSetSize(Resolution);
break;
}
}
public void ApplyGamepadDeadzone()
{
foreach (var action in DeadzoneActions)
{
if (InputMap.HasAction(action))
InputMap.ActionSetDeadzone(action, GamepadDeadzone);
}
}
private static void ApplyInputBindings(ConfigFile cfg)
{
if (!cfg.HasSection("input_settings")) return;
foreach (var actionName in cfg.GetSectionKeys("input_settings"))
{
if (actionName.StartsWith("ui_")) continue;
if (!InputMap.HasAction(actionName)) continue;
var scancode = (Key)(long)cfg.GetValue("input_settings", actionName);
// Remove existing keyboard events for this action
var events = InputMap.ActionGetEvents(actionName);
foreach (var ev in events)
{
if (ev is InputEventKey)
InputMap.ActionEraseEvent(actionName, ev);
}
// Add the saved key
var newKey = new InputEventKey { PhysicalKeycode = scancode };
InputMap.ActionAddEvent(actionName, newKey);
}
}
// ── util ─────────────────────────────────────────────────────────────────
private static Vector2I ParseResolution(string s, Vector2I fallback)
{
var parts = s.Split('x');
if (parts.Length == 2 && int.TryParse(parts[0], out var w) && int.TryParse(parts[1], out var h))
return new Vector2I(w, h);
return fallback;
}
private string BuildCustomResolutionsString()
{
var parts = new List<string>();
foreach (var r in _customResolutions)
parts.Add($"{r.X}x{r.Y}");
return string.Join(",", parts);
}
}

View File

@@ -0,0 +1 @@
uid://d4jyxtm4jgtka

View File

@@ -4,12 +4,8 @@
[ext_resource type="Resource" uid="uid://vgutbpovj8hc" path="res://resources/movement_presets/platform_movement.tres" id="2_7til7"] [ext_resource type="Resource" uid="uid://vgutbpovj8hc" path="res://resources/movement_presets/platform_movement.tres" id="2_7til7"]
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"] [ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"]
[ext_resource type="Texture2D" uid="uid://jl1gwqchhpdc" path="res://sprites/left_eye.png" id="3_2srrh"] [ext_resource type="Texture2D" uid="uid://jl1gwqchhpdc" path="res://sprites/left_eye.png" id="3_2srrh"]
[ext_resource type="Script" uid="uid://bf4yclropol43" path="res://scripts/components/Movement/GroundMovementAbility.cs" id="4_7til7"]
[ext_resource type="Texture2D" uid="uid://iiawtnwmeny3" path="res://sprites/right_eye.png" id="4_ccn81"] [ext_resource type="Texture2D" uid="uid://iiawtnwmeny3" path="res://sprites/right_eye.png" id="4_ccn81"]
[ext_resource type="Texture2D" uid="uid://0l454rfplmqg" path="res://sprites/MrBrick_base-sheet.png" id="5_yysbb"] [ext_resource type="Texture2D" uid="uid://0l454rfplmqg" path="res://sprites/MrBrick_base-sheet.png" id="5_yysbb"]
[ext_resource type="Script" uid="uid://chgw53qwt7rt8" path="res://scripts/components/Movement/GravityAbility.cs" id="6_xuhvf"]
[ext_resource type="Script" uid="uid://ccksp2e76s7sr" path="res://scripts/components/Movement/VariableJumpAbility.cs" id="7_bl1gx"]
[ext_resource type="Script" uid="uid://ck6kmnbwhsttt" path="res://scripts/components/Movement/OneWayPlatformAbility.cs" id="7_uno3u"]
[ext_resource type="Texture2D" uid="uid://dhkwyv6ayb5qb" path="res://sprites/flying_ship.png" id="8_6lsog"] [ext_resource type="Texture2D" uid="uid://dhkwyv6ayb5qb" path="res://sprites/flying_ship.png" id="8_6lsog"]
[ext_resource type="Script" uid="uid://dy78ak8eykw6e" path="res://scripts/components/FlipComponent.cs" id="9_yysbb"] [ext_resource type="Script" uid="uid://dy78ak8eykw6e" path="res://scripts/components/FlipComponent.cs" id="9_yysbb"]
[ext_resource type="Script" uid="uid://mnjg3p0aw1ow" path="res://scripts/components/CanPickUpComponent.cs" id="10_yysbb"] [ext_resource type="Script" uid="uid://mnjg3p0aw1ow" path="res://scripts/components/CanPickUpComponent.cs" id="10_yysbb"]
@@ -69,7 +65,7 @@ point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_xoue7"] [sub_resource type="CurveTexture" id="CurveTexture_xoue7"]
curve = SubResource("Curve_82d6e") curve = SubResource("Curve_82d6e")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_e5pae"] [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_oxudy"]
resource_local_to_scene = true resource_local_to_scene = true
lifetime_randomness = 1.0 lifetime_randomness = 1.0
particle_flag_disable_z = true particle_flag_disable_z = true
@@ -96,25 +92,6 @@ metadata/_custom_type_script = "uid://csel4s0e4g5uf"
[node name="Movements" type="Node" parent="." unique_id=1545001] [node name="Movements" type="Node" parent="." unique_id=1545001]
[node name="GroundMovementAbility" type="Node" parent="Movements" unique_id=1025594633]
script = ExtResource("4_7til7")
MaxSpeed = 376.0
Friction = 2500.0
metadata/_custom_type_script = "uid://bf4yclropol43"
[node name="GravityAbility" type="Node" parent="Movements" unique_id=1144662059]
script = ExtResource("6_xuhvf")
metadata/_custom_type_script = "uid://chgw53qwt7rt8"
[node name="VariableJumpAbility" type="Node" parent="Movements" unique_id=632375899]
script = ExtResource("7_bl1gx")
JumpCutMultiplier = 0.507
metadata/_custom_type_script = "uid://ccksp2e76s7sr"
[node name="OneWayPlatformAbility" type="Node" parent="Movements" unique_id=800681205]
script = ExtResource("7_uno3u")
metadata/_custom_type_script = "uid://ck6kmnbwhsttt"
[node name="Graphics" type="Node2D" parent="." unique_id=271317654] [node name="Graphics" type="Node2D" parent="." unique_id=271317654]
[node name="Root" type="Node2D" parent="Graphics" unique_id=2012260442] [node name="Root" type="Node2D" parent="Graphics" unique_id=2012260442]
@@ -247,7 +224,7 @@ offset_right = 23.0
offset_bottom = -20.0 offset_bottom = -20.0
[node name="HitParticles" parent="." unique_id=1322585720 instance=ExtResource("28_jh5m0")] [node name="HitParticles" parent="." unique_id=1322585720 instance=ExtResource("28_jh5m0")]
process_material = SubResource("ParticleProcessMaterial_e5pae") process_material = SubResource("ParticleProcessMaterial_oxudy")
[node name="ShipShooter" type="Node" parent="." unique_id=1147013800 node_paths=PackedStringArray("BulletSpawn", "ShootSfx")] [node name="ShipShooter" type="Node" parent="." unique_id=1147013800 node_paths=PackedStringArray("BulletSpawn", "ShootSfx")]
script = ExtResource("30_usc1p") script = ExtResource("30_usc1p")

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://cm3rixnnev1pg"] [gd_scene format=3 uid="uid://cm3rixnnev1pg"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_ctugi"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_ctugi"]
[ext_resource type="Script" uid="uid://bgbnof7aeydmq" path="res://scripts/components/JumpPadComponent.cs" id="2_huktk"] [ext_resource type="Script" uid="uid://bgbnof7aeydmq" path="res://scripts/components/JumpPadComponent.cs" id="2_huktk"]
@@ -6,23 +6,23 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ci3ij"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ci3ij"]
size = Vector2(16, 6) size = Vector2(16, 6)
[node name="Jump pad" type="Area2D"] [node name="Jump pad" type="Area2D" unique_id=986549607]
collision_layer = 0 collision_layer = 0
collision_mask = 4 collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1755302504]
position = Vector2(0, 5) position = Vector2(0, 5)
shape = SubResource("RectangleShape2D_ci3ij") shape = SubResource("RectangleShape2D_ci3ij")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="." unique_id=1150967280]
texture = ExtResource("1_ctugi") texture = ExtResource("1_ctugi")
hframes = 12 hframes = 12
vframes = 12 vframes = 12
frame = 120 frame = 120
[node name="JumpPadComponent" type="Node" parent="." node_paths=PackedStringArray("Area", "Sprite")] [node name="JumpPadComponent" type="Node" parent="." unique_id=1295810804 node_paths=PackedStringArray("Area", "Sprite")]
script = ExtResource("2_huktk") script = ExtResource("2_huktk")
JumpForce = 1110.0 JumpForce = 1210.0
Area = NodePath("..") Area = NodePath("..")
Sprite = NodePath("../Sprite2D") Sprite = NodePath("../Sprite2D")
StartAnimationIndex = 120 StartAnimationIndex = 120

View File

@@ -4,6 +4,6 @@
[node name="VariableJumpAbility" type="Node" unique_id=735694377] [node name="VariableJumpAbility" type="Node" unique_id=735694377]
script = ExtResource("1_y30i5") script = ExtResource("1_y30i5")
JumpHeight = 120.0 JumpHeight = 112.0
JumpCutMultiplier = 0.507 JumpCutMultiplier = 0.507
metadata/_custom_type_script = "uid://ccksp2e76s7sr" metadata/_custom_type_script = "uid://ccksp2e76s7sr"

View File

@@ -0,0 +1,77 @@
[gd_scene load_steps=3 format=3 uid="uid://display_settings_scene"]
[ext_resource type="Script" uid="uid://display_settings_script" path="res://scripts/UI/DisplaySettings.cs" id="1_dispset"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dispset"]
bg_color = Color(0, 0, 0, 1)
[node name="Display settings" type="Control" node_paths=PackedStringArray("WindowModeButton", "ResolutionButton", "DisplaySettingsControl")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 6
size_flags_vertical = 6
script = ExtResource("1_dispset")
WindowModeButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Window Mode/WindowModeButton")
ResolutionButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Resolution/ResolutionButton")
DisplaySettingsControl = NodePath(".")
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_dispset")
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Display" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "DISPLAY"
horizontal_alignment = 1
vertical_alignment = 1
uppercase = true
[node name="Spacer" type="Control" parent="PanelContainer/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 32)
layout_mode = 2
size_flags_vertical = 3
[node name="Window Mode" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 4
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Window Mode"]
layout_mode = 2
text = "WINDOW_MODE"
horizontal_alignment = 1
[node name="WindowModeButton" type="OptionButton" parent="PanelContainer/MarginContainer/VBoxContainer/Window Mode"]
layout_mode = 2
[node name="Resolution" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 4
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Resolution"]
layout_mode = 2
text = "RESOLUTION"
horizontal_alignment = 1
[node name="ResolutionButton" type="OptionButton" parent="PanelContainer/MarginContainer/VBoxContainer/Resolution"]
layout_mode = 2

View File

@@ -0,0 +1,97 @@
[gd_scene load_steps=3 format=3 uid="uid://gameplay_settings_scene"]
[ext_resource type="Script" uid="uid://gameplay_settings_script" path="res://scripts/UI/GameplaySettings.cs" id="1_gameplay"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gameplay"]
bg_color = Color(0, 0, 0, 1)
[node name="Gameplay Settings" type="Control" node_paths=PackedStringArray("DeadzoneSlider", "DeadzoneValueLabel", "SensitivitySlider", "SensitivityValueLabel", "GameplaySettingsControl")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 6
size_flags_vertical = 6
script = ExtResource("1_gameplay")
DeadzoneSlider = NodePath("PanelContainer/MarginContainer/VBoxContainer/Deadzone/HSlider")
DeadzoneValueLabel = NodePath("PanelContainer/MarginContainer/VBoxContainer/Deadzone/HBoxContainer/DeadzoneValueLabel")
SensitivitySlider = NodePath("PanelContainer/MarginContainer/VBoxContainer/Sensitivity/HSlider")
SensitivityValueLabel = NodePath("PanelContainer/MarginContainer/VBoxContainer/Sensitivity/HBoxContainer/SensitivityValueLabel")
GameplaySettingsControl = NodePath(".")
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_gameplay")
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Gameplay" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "GAMEPLAY"
horizontal_alignment = 1
vertical_alignment = 1
uppercase = true
[node name="Spacer" type="Control" parent="PanelContainer/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 32)
layout_mode = 2
size_flags_vertical = 3
[node name="Deadzone" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 4
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/Deadzone"]
layout_mode = 2
[node name="DeadzoneLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Deadzone/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "GAMEPAD_DEADZONE"
[node name="DeadzoneValueLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Deadzone/HBoxContainer"]
layout_mode = 2
text = "0.20"
[node name="HSlider" type="HSlider" parent="PanelContainer/MarginContainer/VBoxContainer/Deadzone"]
custom_minimum_size = Vector2(64, 0)
layout_mode = 2
value = 0.2
[node name="Sensitivity" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 4
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/Sensitivity"]
layout_mode = 2
[node name="SensitivityLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Sensitivity/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "GAMEPAD_SENSITIVITY"
[node name="SensitivityValueLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Sensitivity/HBoxContainer"]
layout_mode = 2
text = "1.00"
[node name="HSlider" type="HSlider" parent="PanelContainer/MarginContainer/VBoxContainer/Sensitivity"]
custom_minimum_size = Vector2(64, 0)
layout_mode = 2
value = 1.0

View File

@@ -1,17 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://cvfsbiy5ggrpg"] [gd_scene load_steps=4 format=3 uid="uid://cvfsbiy5ggrpg"]
[ext_resource type="PackedScene" uid="uid://bxpr4m7lq7clh" path="res://objects/ui/input_button.tscn" id="1_h8s4o"] [ext_resource type="PackedScene" uid="uid://bxpr4m7lq7clh" path="res://objects/ui/input_button.tscn" id="1_h8s4o"]
[ext_resource type="Script" uid="uid://input_settings_script" path="res://scripts/UI/InputSettings.cs" id="2_inputs"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_se25o"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_se25o"]
bg_color = Color(0, 0, 0, 1) bg_color = Color(0, 0, 0, 1)
[node name="Input Settings" type="Control"] [node name="Input Settings" type="Control" node_paths=PackedStringArray("ActionsContainer", "ResetButton", "InputSettingsControl")]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("2_inputs")
ActionsContainer = NodePath("PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions")
ResetButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Reset to default Button")
InputSettingsControl = NodePath(".")
InputButtonScene = ExtResource("1_h8s4o")
[node name="PanelContainer" type="PanelContainer" parent="."] [node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 1 layout_mode = 1
@@ -48,24 +54,6 @@ layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
theme_override_constants/separation = 8 theme_override_constants/separation = 8
[node name="Input button" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Input button2" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Input button3" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Input button4" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Input button5" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Input button6" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Actions" instance=ExtResource("1_h8s4o")]
layout_mode = 2
[node name="Reset to default Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Reset to default Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
text = "RESET_TO_DEFAULT_BUTTON" text = "RESET_TO_DEFAULT_BUTTON"

View File

@@ -4,6 +4,7 @@
[ext_resource type="Script" uid="uid://vokgv56bjpf1" path="res://scripts/UI/MarketplaceButton.cs" id="2_vb2qn"] [ext_resource type="Script" uid="uid://vokgv56bjpf1" path="res://scripts/UI/MarketplaceButton.cs" id="2_vb2qn"]
[node name="MarketplaceButton" type="Button" node_paths=PackedStringArray("SkillLevelContainer")] [node name="MarketplaceButton" type="Button" node_paths=PackedStringArray("SkillLevelContainer")]
focus_mode = 2
offset_right = 8.0 offset_right = 8.0
offset_bottom = 8.0 offset_bottom = 8.0
size_flags_horizontal = 3 size_flags_horizontal = 3

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://i6mnjbjcoqe5"] [gd_scene format=3 uid="uid://i6mnjbjcoqe5"]
[ext_resource type="Script" uid="uid://cakgxndurgfa3" path="res://scripts/UI/PauseMenu.cs" id="1_h4pd5"] [ext_resource type="Script" uid="uid://cakgxndurgfa3" path="res://scripts/UI/PauseMenu.cs" id="1_h4pd5"]
[ext_resource type="PackedScene" uid="uid://cl00e2ocomk3m" path="res://scenes/main_menu.tscn" id="2_h4pd5"] [ext_resource type="PackedScene" uid="uid://cl00e2ocomk3m" path="res://scenes/main_menu.tscn" id="2_h4pd5"]
@@ -6,7 +6,7 @@
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_g4ivv"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_g4ivv"]
bg_color = Color(0, 0, 0, 1) bg_color = Color(0, 0, 0, 1)
[node name="Pause menu" type="Control" node_paths=PackedStringArray("PauseMenuControl", "ResumeButton", "MainMenuButton", "QuitButton", "SettingsButton")] [node name="Pause menu" type="Control" unique_id=923659871 node_paths=PackedStringArray("PauseMenuControl", "ResumeButton", "MainMenuButton", "QuitButton", "SettingsButton")]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@@ -23,7 +23,7 @@ QuitButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Quit game Bu
SettingsButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Settings Button") SettingsButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/Settings Button")
MainMenuScene = ExtResource("2_h4pd5") MainMenuScene = ExtResource("2_h4pd5")
[node name="PanelContainer" type="PanelContainer" parent="."] [node name="PanelContainer" type="PanelContainer" parent="." unique_id=1782689001]
layout_mode = 1 layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@@ -32,46 +32,52 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_g4ivv") theme_override_styles/panel = SubResource("StyleBoxFlat_g4ivv")
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] [node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=824088919]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 8 theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8 theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer" unique_id=1826945529]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 4 size_flags_vertical = 4
[node name="Pause" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Pause" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=1706564131]
layout_mode = 2 layout_mode = 2
text = "PAUSE" text = "PAUSE"
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1
uppercase = true uppercase = true
[node name="Spacer" type="Control" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Spacer" type="Control" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=868621584]
custom_minimum_size = Vector2(0, 32) custom_minimum_size = Vector2(0, 32)
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="Resume Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Resume Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=826636099]
layout_mode = 2 layout_mode = 2
focus_next = NodePath("../Settings Button")
text = "RESUME_BUTTON" text = "RESUME_BUTTON"
flat = true flat = true
[node name="Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=334350065]
layout_mode = 2 layout_mode = 2
focus_next = NodePath("../Exit to menu Button")
focus_previous = NodePath("../Resume Button")
text = "SETTINGS_BUTTON" text = "SETTINGS_BUTTON"
flat = true flat = true
[node name="Exit to menu Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Exit to menu Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=683937353]
layout_mode = 2 layout_mode = 2
focus_next = NodePath("../Quit game Button")
focus_previous = NodePath("../Settings Button")
text = "EXIT_TO_MENU_BUTTON" text = "EXIT_TO_MENU_BUTTON"
flat = true flat = true
[node name="Quit game Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Quit game Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=2008979602]
layout_mode = 2 layout_mode = 2
focus_previous = NodePath("../Exit to menu Button")
text = "QUIT_BUTTON" text = "QUIT_BUTTON"
flat = true flat = true

View File

@@ -53,13 +53,11 @@ size_flags_vertical = 3
[node name="Input Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Input Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
disabled = true
text = "INPUT_BUTTON" text = "INPUT_BUTTON"
flat = true flat = true
[node name="Display Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Display Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
disabled = true
text = "DISPLAY_BUTTON" text = "DISPLAY_BUTTON"
flat = true flat = true
@@ -70,7 +68,6 @@ flat = true
[node name="Gameplay Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"] [node name="Gameplay Settings Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
disabled = true
text = "GAMEPLAY_BUTTON" text = "GAMEPLAY_BUTTON"
flat = true flat = true

View File

@@ -4,6 +4,7 @@
[ext_resource type="Script" uid="uid://bw8dlgq86jrtt" path="res://scripts/UI/SkillButton.cs" id="2_m2732"] [ext_resource type="Script" uid="uid://bw8dlgq86jrtt" path="res://scripts/UI/SkillButton.cs" id="2_m2732"]
[node name="SkillButton" type="Button"] [node name="SkillButton" type="Button"]
focus_mode = 2
offset_right = 8.0 offset_right = 8.0
offset_bottom = 8.0 offset_bottom = 8.0
size_flags_horizontal = 3 size_flags_horizontal = 3

View File

@@ -37,6 +37,8 @@ PhantomCameraManager="*res://addons/phantom_camera/scripts/managers/phantom_came
AudioController="*res://objects/audio_controller.tscn" AudioController="*res://objects/audio_controller.tscn"
UIManager="*res://Autoloads/UIManager.cs" UIManager="*res://Autoloads/UIManager.cs"
ConfigFileHandler="*res://Autoloads/ConfigFileHandler.cs" ConfigFileHandler="*res://Autoloads/ConfigFileHandler.cs"
SettingsManager="*res://Autoloads/SettingsManager.cs"
InputDeviceManager="*res://Autoloads/InputDeviceManager.cs"
SaveSystem="*res://Autoloads/SaveSystem.cs" SaveSystem="*res://Autoloads/SaveSystem.cs"
ConsoleManager="*res://Autoloads/ConsoleManager.cs" ConsoleManager="*res://Autoloads/ConsoleManager.cs"
LimboConsole="*uid://dyxornv8vwibg" LimboConsole="*uid://dyxornv8vwibg"

View File

@@ -67,7 +67,7 @@ transition = 3
[node name="Brick Player" parent="." unique_id=1617406140 instance=ExtResource("1_dnj2y")] [node name="Brick Player" parent="." unique_id=1617406140 instance=ExtResource("1_dnj2y")]
z_index = 10 z_index = 10
[node name="HitParticles" parent="Brick Player" index="23"] [node name="HitParticles" parent="Brick Player" index="23" unique_id=1322585720]
process_material = SubResource("ParticleProcessMaterial_84xgs") process_material = SubResource("ParticleProcessMaterial_84xgs")
[node name="WorldEnvironment" parent="." unique_id=1232714328 instance=ExtResource("2_1vw1j")] [node name="WorldEnvironment" parent="." unique_id=1232714328 instance=ExtResource("2_1vw1j")]

View File

@@ -1,10 +1,12 @@
[gd_scene load_steps=6 format=3 uid="uid://cl00e2ocomk3m"] [gd_scene load_steps=8 format=3 uid="uid://cl00e2ocomk3m"]
[ext_resource type="PackedScene" uid="uid://8b6ol5sssbgo" path="res://objects/ui/main_menu.tscn" id="1_ekxnf"] [ext_resource type="PackedScene" uid="uid://8b6ol5sssbgo" path="res://objects/ui/main_menu.tscn" id="1_ekxnf"]
[ext_resource type="PackedScene" uid="uid://y0ae6e7t70fj" path="res://objects/ui/settings_menu.tscn" id="2_bqqt6"] [ext_resource type="PackedScene" uid="uid://y0ae6e7t70fj" path="res://objects/ui/settings_menu.tscn" id="2_bqqt6"]
[ext_resource type="PackedScene" uid="uid://bwgmrcyj4mvu" path="res://objects/ui/credits.tscn" id="3_bqqt6"] [ext_resource type="PackedScene" uid="uid://bwgmrcyj4mvu" path="res://objects/ui/credits.tscn" id="3_bqqt6"]
[ext_resource type="PackedScene" uid="uid://b5fx1vdfky307" path="res://objects/ui/audio_settings.tscn" id="4_8ln24"] [ext_resource type="PackedScene" uid="uid://b5fx1vdfky307" path="res://objects/ui/audio_settings.tscn" id="4_8ln24"]
[ext_resource type="PackedScene" uid="uid://cvfsbiy5ggrpg" path="res://objects/ui/input_settings.tscn" id="5_rtw2f"] [ext_resource type="PackedScene" uid="uid://cvfsbiy5ggrpg" path="res://objects/ui/input_settings.tscn" id="5_rtw2f"]
[ext_resource type="PackedScene" uid="uid://display_settings_scene" path="res://objects/ui/display_settings.tscn" id="6_dispset"]
[ext_resource type="PackedScene" uid="uid://gameplay_settings_scene" path="res://objects/ui/gameplay_settings.tscn" id="7_gameplay"]
[node name="Main menu" type="CanvasLayer"] [node name="Main menu" type="CanvasLayer"]
@@ -28,14 +30,8 @@ visible = false
[node name="Input Settings" parent="." instance=ExtResource("5_rtw2f")] [node name="Input Settings" parent="." instance=ExtResource("5_rtw2f")]
visible = false visible = false
[node name="Gameplay Settings" type="Control" parent="."] [node name="Gameplay Settings" parent="." instance=ExtResource("7_gameplay")]
layout_mode = 3 visible = false
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="Display Settings" type="Control" parent="."] [node name="Display Settings" parent="." instance=ExtResource("6_dispset")]
layout_mode = 3 visible = false
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0

View File

@@ -16,19 +16,45 @@ public partial class AudioSettings : Control
public override void _Ready() public override void _Ready()
{ {
MasterVolumeSlider.FocusMode = Control.FocusModeEnum.All;
MusicVolumeSlider.FocusMode = Control.FocusModeEnum.All;
SfxVolumeSlider.FocusMode = Control.FocusModeEnum.All;
Initialize(); Initialize();
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged; MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged; MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged; SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged;
LoadSettings(); LoadSettings();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
AudioSettingsControl.VisibilityChanged += OnVisibilityChanged;
} }
public override void _ExitTree() public override void _ExitTree()
{ {
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
AudioSettingsControl.VisibilityChanged -= OnVisibilityChanged;
SaveSettings(); SaveSettings();
} }
private void OnVisibilityChanged()
{
if (AudioSettingsControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && AudioSettingsControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => MasterVolumeSlider.GrabFocus();
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {
if (!@event.IsActionReleased("ui_cancel")) return; if (!@event.IsActionReleased("ui_cancel")) return;

View File

@@ -0,0 +1,125 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.UI;
public partial class DisplaySettings : Control
{
[Export] public OptionButton WindowModeButton { get; set; }
[Export] public OptionButton ResolutionButton { get; set; }
[Export] public Control DisplaySettingsControl { get; set; }
private UIManager UIManager => UIManager.Instance;
public override void _Ready()
{
PopulateWindowMode();
PopulateResolutions();
WindowModeButton.ItemSelected += OnWindowModeChanged;
ResolutionButton.ItemSelected += OnResolutionChanged;
WindowModeButton.FocusMode = Control.FocusModeEnum.All;
ResolutionButton.FocusMode = Control.FocusModeEnum.All;
LoadSettings();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
DisplaySettingsControl.VisibilityChanged += OnVisibilityChanged;
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
DisplaySettingsControl.VisibilityChanged -= OnVisibilityChanged;
SettingsManager.Instance?.SaveDisplaySettings();
}
public override void _UnhandledInput(InputEvent @event)
{
if (!@event.IsActionReleased("ui_cancel")) return;
if (!UIManager.IsScreenOnTop(DisplaySettingsControl)) return;
SettingsManager.Instance?.SaveDisplaySettings();
UIManager.PopScreen();
}
private void OnVisibilityChanged()
{
if (DisplaySettingsControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && DisplaySettingsControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => WindowModeButton.GrabFocus();
private void PopulateWindowMode()
{
WindowModeButton.Clear();
WindowModeButton.AddItem("Fullscreen", 0);
WindowModeButton.AddItem("Borderless", 1);
WindowModeButton.AddItem("Windowed", 2);
}
private void PopulateResolutions()
{
ResolutionButton.Clear();
foreach (var res in SettingsManager.Instance.GetAllResolutions())
{
string label = $"{res.X}×{res.Y}";
ResolutionButton.AddItem(label);
}
}
private void OnWindowModeChanged(long idx)
{
string mode = idx switch
{
0 => "fullscreen",
1 => "borderless",
_ => "windowed"
};
SettingsManager.Instance.WindowMode = mode;
SettingsManager.Instance.ApplyDisplaySettings();
ResolutionButton.Disabled = mode == "fullscreen";
SettingsManager.Instance.SaveDisplaySettings();
}
private void OnResolutionChanged(long idx)
{
var resolutions = SettingsManager.Instance.GetAllResolutions();
if (idx < 0 || idx >= resolutions.Count) return;
var res = resolutions[(int)idx];
SettingsManager.Instance.Resolution = res;
SettingsManager.Instance.ApplyDisplaySettings();
SettingsManager.Instance.SaveDisplaySettings();
}
private void LoadSettings()
{
var mode = SettingsManager.Instance.WindowMode;
WindowModeButton.Selected = mode switch
{
"fullscreen" => 0,
"borderless" => 1,
_ => 2
};
ResolutionButton.Disabled = mode == "fullscreen";
var resolution = SettingsManager.Instance.Resolution;
var resolutions = SettingsManager.Instance.GetAllResolutions();
int resIdx = resolutions.IndexOf(resolution);
if (resIdx >= 0)
ResolutionButton.Selected = resIdx;
}
}

View File

@@ -0,0 +1 @@
uid://cplbdp0i08n0n

View File

@@ -13,8 +13,27 @@ public partial class GameOverScreen : Control
public override void _Ready() public override void _Ready()
{ {
RestartButton.FocusMode = Control.FocusModeEnum.All;
MainMenuButton.FocusMode = Control.FocusModeEnum.All;
RestartButton.Pressed += OnRestartClicked; RestartButton.Pressed += OnRestartClicked;
MainMenuButton.Pressed += OnMainMenuClicked; MainMenuButton.Pressed += OnMainMenuClicked;
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && GameOverPanel.IsVisibleInTree())
RestartButton.GrabFocus();
} }
private void OnMainMenuClicked() private void OnMainMenuClicked()
@@ -33,5 +52,7 @@ public partial class GameOverScreen : Control
if (GameStateStore.Instance?.Player.Lives != 0) return; if (GameStateStore.Instance?.Player.Lives != 0) return;
GameOverPanel.Show(); GameOverPanel.Show();
if (InputDeviceManager.Instance?.IsPointerless == true)
RestartButton.GrabFocus();
} }
} }

View File

@@ -0,0 +1,97 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.UI;
public partial class GameplaySettings : Control
{
[Export] public HSlider DeadzoneSlider { get; set; }
[Export] public Label DeadzoneValueLabel { get; set; }
[Export] public HSlider SensitivitySlider { get; set; }
[Export] public Label SensitivityValueLabel { get; set; }
[Export] public Control GameplaySettingsControl { get; set; }
private UIManager UIManager => UIManager.Instance;
public override void _Ready()
{
DeadzoneSlider.FocusMode = Control.FocusModeEnum.All;
SensitivitySlider.FocusMode = Control.FocusModeEnum.All;
DeadzoneSlider.MinValue = 0.05;
DeadzoneSlider.MaxValue = 0.5;
DeadzoneSlider.Step = 0.05;
DeadzoneSlider.Value = 0.2;
SensitivitySlider.MinValue = 0.5;
SensitivitySlider.MaxValue = 2.0;
SensitivitySlider.Step = 0.1;
SensitivitySlider.Value = 1.0;
LoadSettings();
DeadzoneSlider.ValueChanged += OnDeadzoneChanged;
SensitivitySlider.ValueChanged += OnSensitivityChanged;
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
GameplaySettingsControl.VisibilityChanged += OnVisibilityChanged;
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
GameplaySettingsControl.VisibilityChanged -= OnVisibilityChanged;
SaveSettings();
}
public override void _UnhandledInput(InputEvent @event)
{
if (!@event.IsActionReleased("ui_cancel")) return;
if (!UIManager.IsScreenOnTop(GameplaySettingsControl)) return;
SaveSettings();
UIManager.PopScreen();
}
private void OnVisibilityChanged()
{
if (GameplaySettingsControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && GameplaySettingsControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => DeadzoneSlider.GrabFocus();
private void OnDeadzoneChanged(double value)
{
SettingsManager.Instance.GamepadDeadzone = (float)value;
SettingsManager.Instance.ApplyGamepadDeadzone();
DeadzoneValueLabel.Text = $"{value:F2}";
SaveSettings();
}
private void OnSensitivityChanged(double value)
{
SettingsManager.Instance.GamepadSensitivity = (float)value;
SensitivityValueLabel.Text = $"{value:F2}";
SaveSettings();
}
private void LoadSettings()
{
DeadzoneSlider.Value = SettingsManager.Instance.GamepadDeadzone;
SensitivitySlider.Value = SettingsManager.Instance.GamepadSensitivity;
DeadzoneValueLabel.Text = $"{SettingsManager.Instance.GamepadDeadzone:F2}";
SensitivityValueLabel.Text = $"{SettingsManager.Instance.GamepadSensitivity:F2}";
}
private void SaveSettings() => SettingsManager.Instance.SaveGameplaySettings();
}

View File

@@ -0,0 +1 @@
uid://18e3imrmq1u6

201
scripts/UI/InputSettings.cs Normal file
View File

@@ -0,0 +1,201 @@
using Godot;
using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.UI;
public partial class InputSettings : Control
{
[Export] public VBoxContainer ActionsContainer { get; set; }
[Export] public Button ResetButton { get; set; }
[Export] public Control InputSettingsControl { get; set; }
[Export] public PackedScene InputButtonScene { get; set; }
// When adding new game actions, update this list to make them remappable in settings.
private static readonly string[] RemappableActions =
["left", "right", "jump", "attack", "pause", "show_marketplace"];
private UIManager UIManager => UIManager.Instance;
private ConfigFileHandler ConfigFileHandler => ConfigFileHandler.Instance;
private string _rebindingAction;
private Button _rebindingButton;
private Label _rebindingLabel;
public override void _Ready()
{
PopulateActions();
ResetButton.FocusMode = FocusModeEnum.All;
ResetButton.Pressed += OnResetPressed;
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
InputSettingsControl.VisibilityChanged += OnVisibilityChanged;
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
InputSettingsControl.VisibilityChanged -= OnVisibilityChanged;
}
public override void _UnhandledInput(InputEvent @event)
{
if (!IsVisibleInTree()) return;
if (_rebindingAction != null)
{
if (@event is InputEventKey keyEvent && keyEvent.Pressed && !keyEvent.Echo)
{
GetViewport().SetInputAsHandled();
TryBind(_rebindingAction, _rebindingButton, _rebindingLabel, keyEvent);
}
else if (@event.IsActionReleased("ui_cancel"))
{
GetViewport().SetInputAsHandled();
CancelRebind();
}
return;
}
if (!@event.IsActionReleased("ui_cancel")) return;
if (!UIManager.IsScreenOnTop(InputSettingsControl)) return;
UIManager.PopScreen();
}
private void PopulateActions()
{
foreach (Node child in ActionsContainer.GetChildren())
child.QueueFree();
foreach (var action in RemappableActions)
{
var row = InputButtonScene.Instantiate<Button>();
ActionsContainer.AddChild(row);
var labelAction = row.GetNode<Label>("MarginContainer/HBoxContainer/LabelAction");
var labelInput = row.GetNode<Label>("MarginContainer/HBoxContainer/LabelInput");
labelAction.Text = HumanizeAction(action);
labelInput.Text = GetKeyName(action);
row.FocusMode = FocusModeEnum.All;
var capturedAction = action;
var capturedLabel = labelInput;
var capturedRow = row;
row.Pressed += () => OnRowPressed(capturedAction, capturedRow, capturedLabel);
}
}
private void OnRowPressed(string action, Button row, Label labelInput)
{
if (_rebindingAction != null)
CancelRebind();
_rebindingAction = action;
_rebindingButton = row;
_rebindingLabel = labelInput;
labelInput.Text = "Press a key...";
}
private void TryBind(string action, Button row, Label labelInput, InputEventKey keyEvent)
{
var newKey = keyEvent.PhysicalKeycode;
// Conflict check
foreach (var other in RemappableActions)
{
if (other == action) continue;
var existing = GetCurrentKey(other);
if (existing == newKey)
{
labelInput.Text = $"Already used by {HumanizeAction(other)}!";
_rebindingAction = null;
_rebindingButton = null;
_rebindingLabel = null;
var capturedAction = action;
var capturedLabel = labelInput;
GetTree().CreateTimer(2.0).Timeout += () =>
{
if (IsInstanceValid(capturedLabel))
capturedLabel.Text = GetKeyName(capturedAction);
};
return;
}
}
// Apply
foreach (var ev in InputMap.ActionGetEvents(action))
{
if (ev is InputEventKey)
InputMap.ActionEraseEvent(action, ev);
}
InputMap.ActionAddEvent(action, new InputEventKey { PhysicalKeycode = keyEvent.PhysicalKeycode });
// Persist
SettingsManager.Instance.SaveInputSettings();
labelInput.Text = OS.GetKeycodeString(newKey);
_rebindingAction = null;
_rebindingButton = null;
_rebindingLabel = null;
}
private void CancelRebind()
{
if (_rebindingLabel != null)
_rebindingLabel.Text = GetKeyName(_rebindingAction);
_rebindingAction = null;
_rebindingButton = null;
_rebindingLabel = null;
}
private void OnResetPressed()
{
InputMap.LoadFromProjectSettings();
ConfigFileHandler.SettingsConfig.EraseSection("input_settings");
ConfigFileHandler.SettingsConfig.Save(ConfigFileHandler.SettingsPath);
PopulateActions();
}
private void OnVisibilityChanged()
{
if (InputSettingsControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && InputSettingsControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus()
{
var children = ActionsContainer.GetChildren();
if (children.Count > 0 && children[0] is Button btn)
btn.GrabFocus();
}
private static Key GetCurrentKey(string action)
{
foreach (var ev in InputMap.ActionGetEvents(action))
{
if (ev is InputEventKey key)
return key.PhysicalKeycode;
}
return Key.None;
}
private static string GetKeyName(string action)
{
var key = GetCurrentKey(action);
return key == Key.None ? "---" : OS.GetKeycodeString(key);
}
private static string HumanizeAction(string action)
=> action.Replace("_", " ").ToUpper();
}

View File

@@ -0,0 +1 @@
uid://dqefxy5hke5a

View File

@@ -21,6 +21,11 @@ public partial class MainMenu : Control
public override void _Ready() public override void _Ready()
{ {
NewGameButton.FocusMode = Control.FocusModeEnum.All;
ContinueButton.FocusMode = Control.FocusModeEnum.All;
SettingsButton.FocusMode = Control.FocusModeEnum.All;
CreditsButton.FocusMode = Control.FocusModeEnum.All;
ExitButton.FocusMode = Control.FocusModeEnum.All;
NewGameButton.Pressed += OnNewGamePressed; NewGameButton.Pressed += OnNewGamePressed;
ContinueButton.Pressed += OnContinuePressed; ContinueButton.Pressed += OnContinuePressed;
@@ -31,6 +36,36 @@ public partial class MainMenu : Control
VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}"; VersionLabel.Text = $"v. {ProjectSettings.GetSetting("application/config/version")}";
ContinueButton.Disabled = !SaveSystem.CheckSaveExists(); ContinueButton.Disabled = !SaveSystem.CheckSaveExists();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
VisibilityChanged += OnVisibilityChanged;
if (InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
VisibilityChanged -= OnVisibilityChanged;
}
private void OnVisibilityChanged()
{
if (IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus()
{
if (SaveSystem.CheckSaveExists()) if (SaveSystem.CheckSaveExists())
ContinueButton.GrabFocus(); ContinueButton.GrabFocus();
else else

View File

@@ -38,6 +38,9 @@ public partial class Marketplace : Control
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked; SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
EventBus.Instance.SkillCollected += OnGlobalSkillCollected; EventBus.Instance.SkillCollected += OnGlobalSkillCollected;
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
} }
public override void _ExitTree() public override void _ExitTree()
@@ -47,10 +50,21 @@ public partial class Marketplace : Control
{ {
EventBus.Instance.SkillCollected -= OnGlobalSkillCollected; EventBus.Instance.SkillCollected -= OnGlobalSkillCollected;
} }
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
} }
public override void _Input(InputEvent @event) public override void _Input(InputEvent @event)
{ {
if (@event.IsActionReleased("ui_cancel") && IsVisible())
{
Hide();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Inherit;
GetViewport().SetInputAsHandled();
return;
}
if (!@event.IsActionPressed("show_marketplace")) return; if (!@event.IsActionPressed("show_marketplace")) return;
if (IsVisible()) if (IsVisible())
@@ -62,6 +76,35 @@ public partial class Marketplace : Control
{ {
Show(); Show();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled; foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled;
if (InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && IsVisible())
GrabFirstFocus();
}
private void GrabFirstFocus()
{
foreach (var btn in _unlockButtons)
{
if (btn.Visible && !btn.Disabled)
{
btn.GrabFocus();
return;
}
}
foreach (var btn in _skillButtons)
{
if (btn.Visible)
{
btn.GrabFocus();
return;
}
} }
} }

View File

@@ -18,6 +18,10 @@ public partial class PauseMenu : Control
public override void _Ready() public override void _Ready()
{ {
ResumeButton.FocusMode = Control.FocusModeEnum.All;
MainMenuButton.FocusMode = Control.FocusModeEnum.All;
QuitButton.FocusMode = Control.FocusModeEnum.All;
SettingsButton.FocusMode = Control.FocusModeEnum.All;
ResumeButton.Pressed += OnResumePressed; ResumeButton.Pressed += OnResumePressed;
MainMenuButton.Pressed += OnMainMenuPressed; MainMenuButton.Pressed += OnMainMenuPressed;
@@ -25,8 +29,34 @@ public partial class PauseMenu : Control
SettingsButton.Pressed += OnSettingsPressed; SettingsButton.Pressed += OnSettingsPressed;
PauseMenuControl.Hide(); PauseMenuControl.Hide();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
PauseMenuControl.VisibilityChanged += OnVisibilityChanged;
} }
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
PauseMenuControl.VisibilityChanged -= OnVisibilityChanged;
}
private void OnVisibilityChanged()
{
if (PauseMenuControl.IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && PauseMenuControl.IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => ResumeButton.GrabFocus();
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {
if (!@event.IsActionPressed("pause")) return; if (!@event.IsActionPressed("pause")) return;

View File

@@ -19,6 +19,10 @@ public partial class SettingsMenu : Control
public override void _Ready() public override void _Ready()
{ {
InputSettingsButton.FocusMode = FocusModeEnum.All;
AudioSettingsButton.FocusMode = FocusModeEnum.All;
DisplaySettingsButton.FocusMode = FocusModeEnum.All;
GameplaySettingsButton.FocusMode = FocusModeEnum.All;
InputSettingsButton.Pressed += OnInputSettingsPressed; InputSettingsButton.Pressed += OnInputSettingsPressed;
AudioSettingsButton.Pressed += OnAudioSettingsPressed; AudioSettingsButton.Pressed += OnAudioSettingsPressed;
@@ -29,11 +33,37 @@ public partial class SettingsMenu : Control
AudioSettingsControl?.Hide(); AudioSettingsControl?.Hide();
DisplaySettingsControl?.Hide(); DisplaySettingsControl?.Hide();
GameplaySettingsControl?.Hide(); GameplaySettingsControl?.Hide();
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged;
VisibilityChanged += OnVisibilityChanged;
} }
public override void _ExitTree()
{
if (InputDeviceManager.Instance != null)
InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged;
VisibilityChanged -= OnVisibilityChanged;
}
private void OnVisibilityChanged()
{
if (IsVisibleInTree() && InputDeviceManager.Instance?.IsPointerless == true)
GrabFirstFocus();
}
private void OnDeviceChanged(int device)
{
var d = (InputDeviceManager.InputDevice)device;
if (d != InputDeviceManager.InputDevice.Mouse && IsVisibleInTree())
GrabFirstFocus();
}
private void GrabFirstFocus() => InputSettingsButton.GrabFocus();
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {
if (!@event.IsActionPressed("ui_cancel")) return; if (!@event.IsActionReleased("ui_cancel")) return;
if (UIManager.IsScreenOnTop(SettingsMenuControl)) UIManager.PopScreen(); if (UIManager.IsScreenOnTop(SettingsMenuControl)) UIManager.PopScreen();
} }

View File

@@ -1,4 +1,5 @@
using Godot; using Godot;
using Mr.BrickAdventures.Autoloads;
namespace Mr.BrickAdventures.scripts.components; namespace Mr.BrickAdventures.scripts.components;
@@ -15,7 +16,11 @@ public partial class PlayerInputHandler : Node
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
{ {
MoveDirection = Input.GetVector("left", "right", "up", "down"); var rawInput = Input.GetVector("left", "right", "up", "down");
var sensitivity = SettingsManager.Instance?.GamepadSensitivity ?? 1.0f;
MoveDirection = rawInput.Length() > 0
? rawInput.Normalized() * Mathf.Min(rawInput.Length() * sensitivity, 1.0f)
: Vector2.Zero;
JumpPressed = Input.IsActionJustPressed("jump"); JumpPressed = Input.IsActionJustPressed("jump");
JumpReleased = Input.IsActionJustReleased("jump"); JumpReleased = Input.IsActionJustReleased("jump");