Refaktro funguje lol
This commit is contained in:
@@ -26,8 +26,6 @@ namespace MegaKoop.UI
|
||||
private GameObject panelLobby;
|
||||
|
||||
[Header("Manual Wiring - Main Menu Buttons")]
|
||||
[SerializeField] private Button btnNewGame;
|
||||
[SerializeField] private Button btnContinue;
|
||||
[SerializeField] private Button btnMultiplayer;
|
||||
[SerializeField] private Button btnSettings;
|
||||
[SerializeField] private Button btnQuit;
|
||||
@@ -41,8 +39,6 @@ namespace MegaKoop.UI
|
||||
[SerializeField] private Slider slMaster;
|
||||
[SerializeField] private Slider slMusic;
|
||||
[SerializeField] private Slider slSFX;
|
||||
[SerializeField] private Dropdown ddQualityUI;
|
||||
[SerializeField] private Dropdown ddResolutionUI;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -50,18 +46,14 @@ namespace MegaKoop.UI
|
||||
RefreshPanelReferences();
|
||||
|
||||
// Buttons
|
||||
btnNewGame = EnsureButton(btnNewGame, "Button_NewGame", panelMain ? panelMain.transform : this.transform);
|
||||
btnContinue = EnsureButton(btnContinue, "Button_Continue", panelMain ? panelMain.transform : this.transform);
|
||||
btnMultiplayer = EnsureButton(btnMultiplayer, "Button_Multiplayer", panelMain ? panelMain.transform : this.transform);
|
||||
btnSettings = EnsureButton(btnSettings, "Button_Settings", panelMain ? panelMain.transform : this.transform);
|
||||
btnQuit = EnsureButton(btnQuit, "Button_Quit", panelMain ? panelMain.transform : this.transform);
|
||||
|
||||
// Settings
|
||||
ddQuality = EnsureDropdown(ddQuality, "Dropdown_Quality", panelSettings ? panelSettings.transform : this.transform);
|
||||
ddQualityUI = EnsureUIDropdown(ddQualityUI, "Dropdown_Quality", panelSettings ? panelSettings.transform : this.transform);
|
||||
tgFullscreen = EnsureToggle(tgFullscreen, "Toggle_Fullscreen", panelSettings ? panelSettings.transform : this.transform);
|
||||
ddResolution = EnsureDropdown(ddResolution, "Dropdown_Resolution", panelSettings ? panelSettings.transform : this.transform);
|
||||
ddResolutionUI = EnsureUIDropdown(ddResolutionUI, "Dropdown_Resolution", panelSettings ? panelSettings.transform : this.transform);
|
||||
btnApplySettings = EnsureButton(btnApplySettings, "Button_ApplySettings", panelSettings ? panelSettings.transform : this.transform);
|
||||
btnBackFromSettings = EnsureButton(btnBackFromSettings, "Button_BackFromSettings", panelSettings ? panelSettings.transform : this.transform);
|
||||
slMaster = EnsureSlider(slMaster, "Slider_MasterVolume", panelSettings ? panelSettings.transform : this.transform);
|
||||
@@ -79,31 +71,6 @@ namespace MegaKoop.UI
|
||||
ShowMainMenu();
|
||||
}
|
||||
|
||||
private Dropdown EnsureUIDropdown(Dropdown existing, string name, Transform scope)
|
||||
{
|
||||
if (existing) return existing;
|
||||
return FindUIDropdown(name, scope);
|
||||
}
|
||||
|
||||
private Dropdown FindUIDropdown(string name, Transform scope = null)
|
||||
{
|
||||
if (scope != null)
|
||||
{
|
||||
var comps = scope.GetComponentsInChildren<Dropdown>(true);
|
||||
foreach (var c in comps)
|
||||
{
|
||||
if (c && c.name == name) return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var all = Resources.FindObjectsOfTypeAll<Dropdown>();
|
||||
foreach (var c in all)
|
||||
{
|
||||
if (c && c.name == name && c.gameObject.scene.IsValid() && c.gameObject.scene.isLoaded) return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Allow UGUIMenuBuilder to inject panel refs directly
|
||||
public void SetPanels(GameObject main, GameObject settings, GameObject lobby)
|
||||
{
|
||||
@@ -113,24 +80,20 @@ namespace MegaKoop.UI
|
||||
RefreshPanelReferences();
|
||||
}
|
||||
|
||||
public void SetMainMenuButtons(Button newGame, Button continueButton, Button multiplayerButton, Button settingsButton, Button quitButton)
|
||||
public void SetMainMenuButtons(Button multiplayerButton, Button settingsButton, Button quitButton)
|
||||
{
|
||||
btnNewGame = newGame;
|
||||
btnContinue = continueButton;
|
||||
btnMultiplayer = multiplayerButton;
|
||||
btnSettings = settingsButton;
|
||||
btnQuit = quitButton;
|
||||
}
|
||||
|
||||
public void SetSettingsControls(TMP_Dropdown qualityDropdown, Dropdown legacyQualityDropdown, Toggle fullscreenToggle,
|
||||
TMP_Dropdown resolutionDropdown, Dropdown legacyResolutionDropdown, Slider masterVolume, Slider musicVolume, Slider sfxVolume,
|
||||
public void SetSettingsControls(TMP_Dropdown qualityDropdown, Toggle fullscreenToggle,
|
||||
TMP_Dropdown resolutionDropdown, Slider masterVolume, Slider musicVolume, Slider sfxVolume,
|
||||
Button applyButton, Button backButton)
|
||||
{
|
||||
ddQuality = qualityDropdown;
|
||||
ddQualityUI = legacyQualityDropdown;
|
||||
tgFullscreen = fullscreenToggle;
|
||||
ddResolution = resolutionDropdown;
|
||||
ddResolutionUI = legacyResolutionDropdown;
|
||||
slMaster = masterVolume;
|
||||
slMusic = musicVolume;
|
||||
slSFX = sfxVolume;
|
||||
@@ -272,8 +235,6 @@ namespace MegaKoop.UI
|
||||
|
||||
private void WireEvents()
|
||||
{
|
||||
if (btnNewGame) btnNewGame.onClick.AddListener(OnNewGame); else Debug.LogWarning("[UGUIMainMenu] Button_NewGame not found");
|
||||
if (btnContinue) btnContinue.onClick.AddListener(OnContinue); else Debug.LogWarning("[UGUIMainMenu] Button_Continue not found");
|
||||
if (btnMultiplayer) btnMultiplayer.onClick.AddListener(OnOpenMultiplayer); else Debug.LogWarning("[UGUIMainMenu] Button_Multiplayer not found");
|
||||
if (btnSettings) btnSettings.onClick.AddListener(OnOpenSettings); else Debug.LogWarning("[UGUIMainMenu] Button_Settings not found");
|
||||
if (btnQuit) btnQuit.onClick.AddListener(OnQuit); else Debug.LogWarning("[UGUIMainMenu] Button_Quit not found");
|
||||
@@ -283,8 +244,6 @@ namespace MegaKoop.UI
|
||||
|
||||
if (ddQuality) ddQuality.onValueChanged.AddListener(i => { Debug.Log("[UGUIMainMenu] Quality changed to index " + i); ddQuality.RefreshShownValue(); });
|
||||
if (ddResolution) ddResolution.onValueChanged.AddListener(i => { Debug.Log("[UGUIMainMenu] Resolution changed to index " + i); ddResolution.RefreshShownValue(); });
|
||||
if (ddQualityUI) ddQualityUI.onValueChanged.AddListener(i => { Debug.Log("[UGUIMainMenu] UI Quality changed to index " + i); ddQualityUI.RefreshShownValue(); });
|
||||
if (ddResolutionUI) ddResolutionUI.onValueChanged.AddListener(i => { Debug.Log("[UGUIMainMenu] UI Resolution changed to index " + i); ddResolutionUI.RefreshShownValue(); });
|
||||
if (tgFullscreen) tgFullscreen.onValueChanged.AddListener(v => { Debug.Log("[UGUIMainMenu] Fullscreen " + v); });
|
||||
if (slMaster) slMaster.onValueChanged.AddListener(v => { AudioListener.volume = v / 100f; });
|
||||
}
|
||||
@@ -329,42 +288,6 @@ namespace MegaKoop.UI
|
||||
Debug.Log("[UGUIMainMenu] Open Settings");
|
||||
}
|
||||
|
||||
private void OnNewGame()
|
||||
{
|
||||
// Co-op only: quick host path
|
||||
UGUIMultiplayerLobbyController lobby;
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
lobby = Object.FindFirstObjectByType<UGUIMultiplayerLobbyController>();
|
||||
#else
|
||||
lobby = Object.FindObjectOfType<UGUIMultiplayerLobbyController>();
|
||||
#endif
|
||||
if (lobby)
|
||||
{
|
||||
if (panelMain) panelMain.SetActive(false);
|
||||
if (panelSettings) panelSettings.SetActive(false);
|
||||
if (panelLobby) panelLobby.SetActive(true);
|
||||
lobby.QuickHost(4, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnContinue()
|
||||
{
|
||||
// Co-op only: join path
|
||||
UGUIMultiplayerLobbyController lobby;
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
lobby = Object.FindFirstObjectByType<UGUIMultiplayerLobbyController>();
|
||||
#else
|
||||
lobby = Object.FindObjectOfType<UGUIMultiplayerLobbyController>();
|
||||
#endif
|
||||
if (lobby)
|
||||
{
|
||||
if (panelMain) panelMain.SetActive(false);
|
||||
if (panelSettings) panelSettings.SetActive(false);
|
||||
if (panelLobby) panelLobby.SetActive(true);
|
||||
lobby.ShowJoinTabPublic();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnQuit()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -380,10 +303,6 @@ namespace MegaKoop.UI
|
||||
{
|
||||
QualitySettings.SetQualityLevel(ddQuality.value, true);
|
||||
}
|
||||
else if (ddQualityUI)
|
||||
{
|
||||
QualitySettings.SetQualityLevel(ddQualityUI.value, true);
|
||||
}
|
||||
if (tgFullscreen)
|
||||
{
|
||||
Screen.fullScreen = tgFullscreen.isOn;
|
||||
@@ -400,18 +319,6 @@ namespace MegaKoop.UI
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ddResolutionUI)
|
||||
{
|
||||
if (ddResolutionUI.options != null && ddResolutionUI.options.Count > 0 && ddResolutionUI.value >= 0 && ddResolutionUI.value < ddResolutionUI.options.Count)
|
||||
{
|
||||
var opt = ddResolutionUI.options[ddResolutionUI.value].text;
|
||||
var parts = opt.ToLower().Split('x');
|
||||
if (parts.Length == 2 && int.TryParse(parts[0], out int w) && int.TryParse(parts[1], out int h))
|
||||
{
|
||||
Screen.SetResolution(w, h, Screen.fullScreenMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slMaster)
|
||||
{
|
||||
AudioListener.volume = slMaster.value / 100f;
|
||||
@@ -442,35 +349,6 @@ namespace MegaKoop.UI
|
||||
FixDropdownRaycasts(ddQuality);
|
||||
SetupDropdownTemplateCanvas(ddQuality);
|
||||
}
|
||||
else if (ddQualityUI)
|
||||
{
|
||||
var names = QualitySettings.names;
|
||||
if (names != null && names.Length > 0)
|
||||
{
|
||||
ddQualityUI.ClearOptions();
|
||||
ddQualityUI.AddOptions(new List<Dropdown.OptionData>(System.Array.ConvertAll(names, s => new Dropdown.OptionData(s))));
|
||||
ddQualityUI.value = Mathf.Clamp(QualitySettings.GetQualityLevel(), 0, ddQualityUI.options.Count - 1);
|
||||
ddQualityUI.RefreshShownValue();
|
||||
}
|
||||
if (ddQualityUI.captionText == null)
|
||||
{
|
||||
var cap = ddQualityUI.transform.Find("Label");
|
||||
if (cap) ddQualityUI.captionText = cap.GetComponent<Text>();
|
||||
}
|
||||
if (ddQualityUI.itemText == null && ddQualityUI.template)
|
||||
{
|
||||
var it = ddQualityUI.template.Find("Item");
|
||||
if (it)
|
||||
{
|
||||
var lbl = it.Find("Item Label");
|
||||
if (lbl) ddQualityUI.itemText = lbl.GetComponent<Text>();
|
||||
}
|
||||
}
|
||||
ddQualityUI.interactable = true;
|
||||
FixDropdownRaycasts(ddQualityUI);
|
||||
SetupDropdownTemplateCanvas(ddQualityUI);
|
||||
Debug.Log("[UGUIMainMenu] UI Quality options=" + (ddQualityUI.options != null ? ddQualityUI.options.Count : 0));
|
||||
}
|
||||
|
||||
if (ddResolution)
|
||||
{
|
||||
@@ -500,49 +378,6 @@ namespace MegaKoop.UI
|
||||
FixDropdownRaycasts(ddResolution);
|
||||
SetupDropdownTemplateCanvas(ddResolution);
|
||||
}
|
||||
else if (ddResolutionUI)
|
||||
{
|
||||
var seen = new HashSet<string>();
|
||||
var opts = new List<string>();
|
||||
string cur = Screen.currentResolution.width + "x" + Screen.currentResolution.height;
|
||||
int curIdx = 0;
|
||||
foreach (var r in Screen.resolutions)
|
||||
{
|
||||
string s = r.width + "x" + r.height;
|
||||
if (seen.Add(s))
|
||||
{
|
||||
if (s == cur) curIdx = opts.Count;
|
||||
opts.Add(s);
|
||||
}
|
||||
}
|
||||
if (opts.Count == 0)
|
||||
{
|
||||
opts.Add(cur);
|
||||
curIdx = 0;
|
||||
}
|
||||
ddResolutionUI.ClearOptions();
|
||||
ddResolutionUI.AddOptions(opts.ConvertAll(o => new Dropdown.OptionData(o)));
|
||||
ddResolutionUI.value = Mathf.Clamp(curIdx, 0, ddResolutionUI.options.Count - 1);
|
||||
ddResolutionUI.RefreshShownValue();
|
||||
ddResolutionUI.interactable = true;
|
||||
FixDropdownRaycasts(ddResolutionUI);
|
||||
SetupDropdownTemplateCanvas(ddResolutionUI);
|
||||
if (ddResolutionUI.captionText == null)
|
||||
{
|
||||
var cap = ddResolutionUI.transform.Find("Label");
|
||||
if (cap) ddResolutionUI.captionText = cap.GetComponent<Text>();
|
||||
}
|
||||
if (ddResolutionUI.itemText == null && ddResolutionUI.template)
|
||||
{
|
||||
var it = ddResolutionUI.template.Find("Item");
|
||||
if (it)
|
||||
{
|
||||
var lbl = it.Find("Item Label");
|
||||
if (lbl) ddResolutionUI.itemText = lbl.GetComponent<Text>();
|
||||
}
|
||||
}
|
||||
Debug.Log("[UGUIMainMenu] UI Resolution options=" + (ddResolutionUI.options != null ? ddResolutionUI.options.Count : 0));
|
||||
}
|
||||
|
||||
if (tgFullscreen)
|
||||
{
|
||||
@@ -581,12 +416,6 @@ namespace MegaKoop.UI
|
||||
ddQuality.value = Mathf.Clamp(q, 0, ddQuality.options.Count - 1);
|
||||
ddQuality.RefreshShownValue();
|
||||
}
|
||||
else if (ddQualityUI && ddQualityUI.options.Count > 0)
|
||||
{
|
||||
int q = PlayerPrefs.GetInt("QualityLevel", QualitySettings.GetQualityLevel());
|
||||
ddQualityUI.value = Mathf.Clamp(q, 0, ddQualityUI.options.Count - 1);
|
||||
ddQualityUI.RefreshShownValue();
|
||||
}
|
||||
if (tgFullscreen)
|
||||
{
|
||||
bool full = PlayerPrefs.GetInt("Fullscreen", Screen.fullScreen ? 1 : 0) == 1;
|
||||
@@ -604,18 +433,6 @@ namespace MegaKoop.UI
|
||||
ddResolution.RefreshShownValue();
|
||||
}
|
||||
}
|
||||
else if (ddResolutionUI && ddResolutionUI.options.Count > 0)
|
||||
{
|
||||
int w = PlayerPrefs.GetInt("ResolutionWidth", Screen.currentResolution.width);
|
||||
int h = PlayerPrefs.GetInt("ResolutionHeight", Screen.currentResolution.height);
|
||||
string key = w + "x" + h;
|
||||
int idx = ddResolutionUI.options.FindIndex(o => o.text == key);
|
||||
if (idx >= 0)
|
||||
{
|
||||
ddResolutionUI.value = idx;
|
||||
ddResolutionUI.RefreshShownValue();
|
||||
}
|
||||
}
|
||||
if (slMaster)
|
||||
{
|
||||
var mv = PlayerPrefs.GetFloat("MasterVolume", 100f);
|
||||
|
||||
Reference in New Issue
Block a user