Skip to content

Commit 90d7176

Browse files
committed
WIP fixing volume distortion issue and trying to debug failing of UIQuitPanel
ConnectionManager does not get injected successfully
1 parent 5ae1ba8 commit 90d7176

File tree

4 files changed

+206
-17
lines changed

4 files changed

+206
-17
lines changed

Assets/Prefabs/UI/UIToolkit/UIDocumentSettingsPanel.prefab

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GameObject:
1010
m_Component:
1111
- component: {fileID: 4254012999359068869}
1212
- component: {fileID: 4096003274560183257}
13+
- component: {fileID: 1425188790653231607}
1314
m_Layer: 5
1415
m_Name: UIDocumentSettingsPanel
1516
m_TagString: Untagged
@@ -29,7 +30,8 @@ Transform:
2930
m_LocalPosition: {x: 0, y: 0, z: 0}
3031
m_LocalScale: {x: 1, y: 1, z: 1}
3132
m_ConstrainProportionsScale: 0
32-
m_Children: []
33+
m_Children:
34+
- {fileID: 8673277459071735180}
3335
m_Father: {fileID: 0}
3436
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3537
--- !u!114 &4096003274560183257
@@ -51,3 +53,78 @@ MonoBehaviour:
5153
m_WorldSpaceSizeMode: 1
5254
m_WorldSpaceWidth: 1920
5355
m_WorldSpaceHeight: 1080
56+
--- !u!114 &1425188790653231607
57+
MonoBehaviour:
58+
m_ObjectHideFlags: 0
59+
m_CorrespondingSourceObject: {fileID: 0}
60+
m_PrefabInstance: {fileID: 0}
61+
m_PrefabAsset: {fileID: 0}
62+
m_GameObject: {fileID: 387230424975246262}
63+
m_Enabled: 1
64+
m_EditorHideFlags: 0
65+
m_Script: {fileID: 11500000, guid: 190bc18b6f6f06340acb887d88806593, type: 3}
66+
m_Name:
67+
m_EditorClassIdentifier:
68+
uiDocument: {fileID: 4096003274560183257}
69+
--- !u!1 &4153888348426691229
70+
GameObject:
71+
m_ObjectHideFlags: 0
72+
m_CorrespondingSourceObject: {fileID: 0}
73+
m_PrefabInstance: {fileID: 0}
74+
m_PrefabAsset: {fileID: 0}
75+
serializedVersion: 6
76+
m_Component:
77+
- component: {fileID: 8673277459071735180}
78+
- component: {fileID: 8607712241056528212}
79+
- component: {fileID: 4923764729715591813}
80+
m_Layer: 5
81+
m_Name: UIQuitPanel
82+
m_TagString: Untagged
83+
m_Icon: {fileID: 0}
84+
m_NavMeshLayer: 0
85+
m_StaticEditorFlags: 0
86+
m_IsActive: 1
87+
--- !u!4 &8673277459071735180
88+
Transform:
89+
m_ObjectHideFlags: 0
90+
m_CorrespondingSourceObject: {fileID: 0}
91+
m_PrefabInstance: {fileID: 0}
92+
m_PrefabAsset: {fileID: 0}
93+
m_GameObject: {fileID: 4153888348426691229}
94+
serializedVersion: 2
95+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
96+
m_LocalPosition: {x: 0, y: 0, z: 0}
97+
m_LocalScale: {x: 1, y: 1, z: 1}
98+
m_ConstrainProportionsScale: 0
99+
m_Children: []
100+
m_Father: {fileID: 4254012999359068869}
101+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
102+
--- !u!114 &8607712241056528212
103+
MonoBehaviour:
104+
m_ObjectHideFlags: 0
105+
m_CorrespondingSourceObject: {fileID: 0}
106+
m_PrefabInstance: {fileID: 0}
107+
m_PrefabAsset: {fileID: 0}
108+
m_GameObject: {fileID: 4153888348426691229}
109+
m_Enabled: 1
110+
m_EditorHideFlags: 0
111+
m_Script: {fileID: 11500000, guid: 063abc7eeacd3df4db23e185d26aab43, type: 3}
112+
m_Name:
113+
m_EditorClassIdentifier:
114+
m_QuitMode: 0
115+
--- !u!114 &4923764729715591813
116+
MonoBehaviour:
117+
m_ObjectHideFlags: 0
118+
m_CorrespondingSourceObject: {fileID: 0}
119+
m_PrefabInstance: {fileID: 0}
120+
m_PrefabAsset: {fileID: 0}
121+
m_GameObject: {fileID: 4153888348426691229}
122+
m_Enabled: 1
123+
m_EditorHideFlags: 0
124+
m_Script: {fileID: 11500000, guid: 1b2c62ac3bcd44fb9e09835581422057, type: 3}
125+
m_Name:
126+
m_EditorClassIdentifier:
127+
parentReference:
128+
TypeName: Unity.BossRoom.ApplicationLifecycle.ApplicationController
129+
autoRun: 1
130+
autoInjectGameObjects: []

Assets/Prefabs/UI/UIToolkit/UXML/SettingsPanelCanvas.uxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<engine:Button name="settingsButton" class="simpleButton settingsButton" style="background-size: 70% 70%; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
66
</engine:VisualElement>
77
<engine:VisualElement name="root" style="flex-grow: 1;">
8-
<engine:VisualElement name="settingsPanelRoot" class="panel">
8+
<engine:VisualElement name="settingsPanelRoot" class="panel" style="translate: -472px 0;">
99
<engine:Button name="closeButton" class="ExitButton" style="position: absolute; top: -10px; right: -64px; background-size: 90% 90%; visibility: visible; overflow: visible;" />
1010
<engine:Label text="Settings" name="settingsLabel" class="settingsLabel label" style="margin-bottom: 8px;" />
1111
<engine:Label text="Overall Volume" name="masterVolumeLabel" class="slider" style="translate: 7.5% 50%; transform-origin: center 40%;" />
12-
<engine:Slider high-value="100" name="masterVolume" fill="true" show-input-field="false" enabled="true" inverted="false" value="50" class="slider" style="-unity-background-image-tint-color: rgba(255, 4, 4, 0.96); width: 85%; translate: 7.5% 0; border-top-left-radius: 8px; border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px;" />
12+
<engine:Slider high-value="1" name="masterVolume" fill="true" show-input-field="false" enabled="true" inverted="false" value="0.8" class="slider" style="-unity-background-image-tint-color: rgba(255, 4, 4, 0.96); width: 85%; translate: 7.5% 0; border-top-left-radius: 8px; border-top-right-radius: 8px; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px;" />
1313
<engine:Label text="Music Volume" name="musicVolumeLabel" class="slider" style="translate: 7.5% 50%; transform-origin: center 40%;" />
14-
<engine:Slider high-value="100" name="musicVolume" enabled="true" show-input-field="false" fill="true" low-value="0" value="50" class="slider" style="width: 85%; translate: 7.5% 0;" />
15-
<engine:Button text="Low" name="settingPanelButton" class="menuButton" style="margin-top: 25px; background-size: 321px 65px;" />
14+
<engine:Slider high-value="1" name="musicVolume" enabled="true" show-input-field="false" fill="true" low-value="0" value="0.5" class="slider" style="width: 85%; translate: 7.5% 0;" />
15+
<engine:Button text="Low" name="qualityButton" class="menuButton" style="margin-top: 25px; background-size: 321px 65px;" />
1616
</engine:VisualElement>
1717
<engine:VisualElement name="quitPanelRoot" class="panel" style="flex-grow: 1; transform-origin: center;">
1818
<engine:Label text="Return To Menu?" name="returnLabel" class="settingsLabel label" />

Assets/Scripts/Gameplay/UI/UIQuitPanel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ enum QuitMode
2424
[Inject]
2525
IPublisher<QuitApplicationMessage> m_QuitApplicationPub;
2626

27+
void Awake()
28+
{
29+
if (m_ConnectionManager == null)
30+
{
31+
Debug.LogError("ConnectionManager is null! Ensure that dependency injection is set up correctly.");
32+
}
33+
else
34+
{
35+
Debug.Log("ConnectionManager successfully injected into UIQuitPanel.");
36+
}
37+
}
38+
2739
public void Quit()
2840
{
2941
switch (m_QuitMode)

Assets/Scripts/Gameplay/UI/UISettingsCanvas.cs

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using UnityEngine.UIElements;
33
using Unity.BossRoom.Utils;
44
using Unity.BossRoom.Audio;
5+
using Unity.BossRoom.Gameplay.UI; // Reference for UIQuitPanel
6+
using VContainer; // Needed for the dependency injection setup
57

68
namespace Unity.BossRoom.Gameplay.UI
79
{
@@ -14,23 +16,34 @@ public class UISettingsCanvas : MonoBehaviour
1416
[SerializeField]
1517
UIDocument uiDocument; // Reference to the UIDocument asset
1618

19+
// Panels and Buttons
1720
VisualElement settingsPanelRoot;
1821
VisualElement quitPanelRoot;
1922
Button settingsButton;
2023
Button quitButton;
24+
Button qualityButton;
25+
Button confirmQuitButton;
26+
Button closeButton;
27+
Button cancelButton;
2128
Slider masterVolumeSlider;
2229
Slider musicVolumeSlider;
30+
UIQuitPanel uiQuitPanel;
2331

2432
void Awake()
2533
{
2634
// Retrieve the root VisualElement from the UIDocument
2735
var root = uiDocument.rootVisualElement;
28-
36+
// get UIQuitPanel component which is attached to the same GameObject
37+
uiQuitPanel = GetComponent<UIQuitPanel>();
2938
// Query the panels by their names or assigned USS classes
3039
settingsPanelRoot = root.Q<VisualElement>("settingsPanelRoot");
3140
quitPanelRoot = root.Q<VisualElement>("quitPanelRoot");
3241
quitButton = root.Q<Button>("quitButton");
3342
settingsButton = root.Q<Button>("settingsButton");
43+
qualityButton = root.Q<Button>("qualityButton");
44+
closeButton = root.Q<Button>("closeButton");
45+
cancelButton = root.Q<Button>("cancelButton");
46+
confirmQuitButton = root.Q<Button>("confirmButton");
3447
masterVolumeSlider = root.Q<Slider>("masterVolume");
3548
musicVolumeSlider = root.Q<Slider>("musicVolume");
3649

@@ -39,32 +52,45 @@ void Awake()
3952

4053
settingsButton.SetEnabled(true);
4154
quitButton.SetEnabled(true);
42-
// Bind the buttons to their respective method using new input system
55+
qualityButton.SetEnabled(true);
56+
confirmQuitButton.SetEnabled(true);
57+
closeButton.SetEnabled(true);
58+
cancelButton.SetEnabled(true);
59+
masterVolumeSlider.SetEnabled(true);
60+
musicVolumeSlider.SetEnabled(true);
61+
62+
musicVolumeSlider.value = ClientPrefs.GetMusicVolume();
63+
masterVolumeSlider.value = ClientPrefs.GetMasterVolume();
64+
65+
// Bind buttons to their respective methods
4366
settingsButton.clicked += OnClickSettingsButton;
4467
quitButton.clicked += OnClickQuitButton;
45-
46-
// Bind the sliders to their respective methods
68+
qualityButton.clicked += SetQualitySettings;
69+
confirmQuitButton.clicked += ExecuteQuitAction;
70+
closeButton.clicked += OnClickCloseButton;
71+
cancelButton.clicked += OnClickCancelButton;
72+
73+
// Bind sliders to their respective methods
4774
masterVolumeSlider.value = ClientPrefs.GetMasterVolume();
4875
masterVolumeSlider.RegisterValueChangedCallback(evt => OnMasterVolumeSliderChanged(evt.newValue));
4976
musicVolumeSlider.value = ClientPrefs.GetMusicVolume();
5077
musicVolumeSlider.RegisterValueChangedCallback(evt => OnMusicVolumeSliderChanged(evt.newValue));
51-
52-
5378
}
5479

80+
/// <summary>
81+
/// Ensures all panels are hidden when this component is initialized.
82+
/// </summary>
5583
void DisablePanels()
5684
{
5785
settingsPanelRoot.style.display = DisplayStyle.None;
5886
quitPanelRoot.style.display = DisplayStyle.None;
5987
}
6088

6189
/// <summary>
62-
/// Called directly by the settings button in the UI Through a manual event binding
90+
/// Called when the Settings button is pressed. Toggles the display of the settings panel.
6391
/// </summary>
6492
public void OnClickSettingsButton()
6593
{
66-
Debug.Log("Settings button pressed");
67-
// settingsButton is pressed
6894
if (settingsPanelRoot != null)
6995
{
7096
bool isVisible = settingsPanelRoot.style.display == DisplayStyle.Flex;
@@ -78,7 +104,7 @@ public void OnClickSettingsButton()
78104
}
79105

80106
/// <summary>
81-
/// Called directly by the quit button in the UI manual button here
107+
/// Called when the Quit button is pressed. Toggles the display of the quit panel.
82108
/// </summary>
83109
public void OnClickQuitButton()
84110
{
@@ -94,17 +120,91 @@ public void OnClickQuitButton()
94120
}
95121
}
96122

97-
private void OnMasterVolumeSliderChanged(float newValue)
123+
float SliderToDecibel(float sliderValue)
124+
{
125+
float minDB = -40f; // Silent floor
126+
float maxDB = 0f; // Maximum volume
127+
sliderValue = Mathf.Pow(Mathf.Clamp(sliderValue, 0.0001f, 1f), 2.0f); // Exponential curve
128+
return Mathf.Lerp(minDB, maxDB, sliderValue);
129+
}
130+
131+
/// <summary>
132+
/// Called when the Master Volume slider's value is adjusted.
133+
/// </summary>
134+
/// <param name="newValue">New slider value.</param>
135+
void OnMasterVolumeSliderChanged(float newValue)
98136
{
137+
// newValue = Mathf.Clamp(newValue, 0, 100);
99138
ClientPrefs.SetMasterVolume(newValue);
100139
AudioMixerConfigurator.Instance.Configure();
140+
Debug.Log("Master Volume set to: " + newValue);
101141
}
102142

103-
private void OnMusicVolumeSliderChanged(float newValue)
143+
/// <summary>
144+
/// Called when the Music Volume slider's value is adjusted.
145+
/// </summary>
146+
/// <param name="newValue">New slider value.</param>
147+
void OnMusicVolumeSliderChanged(float newValue)
104148
{
149+
//float dB= SliderToDecibel(newValue);
150+
// clamp the value to the range [0, 1]
151+
//newValue = Mathf.Clamp(newValue, 0, 1);
105152
ClientPrefs.SetMusicVolume(newValue);
106153
AudioMixerConfigurator.Instance.Configure();
154+
Debug.Log("Music Volume set to: " + newValue);
155+
}
156+
157+
/// <summary>
158+
/// Called when the Quality Settings button is pressed. Updates the quality level.
159+
/// </summary>
160+
public void SetQualitySettings()
161+
{
162+
var qualityLevels = QualitySettings.names.Length - 1;
163+
var currentLevel = QualitySettings.GetQualityLevel();
164+
165+
if (currentLevel < qualityLevels)
166+
{
167+
QualitySettings.IncreaseLevel();
168+
}
169+
else
170+
{
171+
QualitySettings.SetQualityLevel(0);
172+
}
173+
174+
// Dynamically update the button text with the current quality level
175+
qualityButton.text = QualitySettings.names[QualitySettings.GetQualityLevel()];
176+
}
177+
178+
/// <summary>
179+
/// Hook for the Quit Panel's Quit functionality. Delegates actions to UIQuitPanel.
180+
/// </summary>
181+
void ExecuteQuitAction()
182+
{
183+
Debug.Log("Confirm button pressed");
184+
185+
if (uiQuitPanel != null)
186+
{
187+
uiQuitPanel.Quit();
188+
Debug.Log("Quit executed.");
189+
}
190+
else
191+
{
192+
Debug.LogError("UIQuitPanel is not assigned!");
193+
}
194+
}
195+
196+
void OnClickCloseButton()
197+
{
198+
// Close the settings panel
199+
settingsPanelRoot.style.display = DisplayStyle.None;
200+
}
201+
202+
void OnClickCancelButton()
203+
{
204+
// Close the quit panel
205+
quitPanelRoot.style.display = DisplayStyle.None;
107206
}
108207
}
109208
}
110209

210+

0 commit comments

Comments
 (0)