|
|
@@ -1,7 +1,6 @@
|
|
|
using System;
|
|
|
using TMPro;
|
|
|
using UnityEngine;
|
|
|
-using UnityEngine.SceneManagement;
|
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
public class MainMenuController : MonoBehaviour
|
|
|
@@ -17,9 +16,26 @@ public class MainMenuController : MonoBehaviour
|
|
|
[SerializeField] ToastView toastView;
|
|
|
[SerializeField] StoryDialogView storyView;
|
|
|
|
|
|
+ [Header("Game")]
|
|
|
+ [SerializeField] GameObject gamePrefab;
|
|
|
+ [SerializeField] Material gameSelectedGlowMaterial;
|
|
|
+ [SerializeField] GameObject pausePanelPrefab;
|
|
|
+ [SerializeField] GameObject winPanelPrefab;
|
|
|
+ [SerializeField] GameObject losePanelPrefab;
|
|
|
+ [SerializeField] GameObject popViewPanelPrefab;
|
|
|
+
|
|
|
+ [Header("Overlay Prefabs")]
|
|
|
+ [SerializeField] GameObject settingsPrefab;
|
|
|
+ [SerializeField] GameObject helpPrefab;
|
|
|
+ [SerializeField] GameObject storyPrefab;
|
|
|
+
|
|
|
public bool LobbyVisible => lobbyView != null && lobbyView.gameObject.activeSelf;
|
|
|
public string OpenOverlay { get; private set; } = "";
|
|
|
|
|
|
+ GameScreenView gameView;
|
|
|
+ string gameMode = GameDefinitions.ClassicMode;
|
|
|
+ int gameLevel = 1;
|
|
|
+
|
|
|
void OnEnable()
|
|
|
{
|
|
|
LocaleService.Changed += HandleLocaleChanged;
|
|
|
@@ -315,7 +331,7 @@ public class MainMenuController : MonoBehaviour
|
|
|
|
|
|
SettingsScreenView CreateSettingsView()
|
|
|
{
|
|
|
- GameObject prefab = Resources.Load<GameObject>("Prefab/11_setting");
|
|
|
+ GameObject prefab = settingsPrefab != null ? settingsPrefab : Resources.Load<GameObject>("Prefab/11_setting");
|
|
|
if (prefab == null)
|
|
|
{
|
|
|
Debug.LogWarning("[MainMenu] Could not load Prefab/11_setting.");
|
|
|
@@ -348,7 +364,7 @@ public class MainMenuController : MonoBehaviour
|
|
|
|
|
|
HelpScreenView CreateHelpView()
|
|
|
{
|
|
|
- GameObject prefab = Resources.Load<GameObject>("Prefab/06_help");
|
|
|
+ GameObject prefab = helpPrefab != null ? helpPrefab : Resources.Load<GameObject>("Prefab/06_help");
|
|
|
if (prefab == null)
|
|
|
{
|
|
|
Debug.LogWarning("[MainMenu] Could not load Prefab/06_help.");
|
|
|
@@ -381,7 +397,7 @@ public class MainMenuController : MonoBehaviour
|
|
|
|
|
|
StoryDialogView CreateStoryView()
|
|
|
{
|
|
|
- GameObject prefab = Resources.Load<GameObject>("Prefab/UI_StoryDialogPopup");
|
|
|
+ GameObject prefab = storyPrefab != null ? storyPrefab : Resources.Load<GameObject>("Prefab/UI_StoryDialogPopup");
|
|
|
if (prefab == null)
|
|
|
{
|
|
|
Debug.LogWarning("[MainMenu] Could not load Prefab/UI_StoryDialogPopup.");
|
|
|
@@ -402,11 +418,87 @@ public class MainMenuController : MonoBehaviour
|
|
|
void HandlePlayRequested()
|
|
|
{
|
|
|
SaveService.EnsureLoaded();
|
|
|
- string mode = SaveService.Data.selectedMode;
|
|
|
- int nextLevel = Mathf.Clamp(SaveService.Data.cleared.Get(mode) + 1, 1, GameDefinitions.MaxLevel);
|
|
|
- GameFlowState.PrepareLaunch(mode, nextLevel);
|
|
|
+ gameMode = SaveService.Data.selectedMode;
|
|
|
+ gameLevel = Mathf.Clamp(SaveService.Data.cleared.Get(gameMode) + 1, 1, GameDefinitions.MaxLevel);
|
|
|
+ GameFlowState.PrepareLaunch(gameMode, gameLevel);
|
|
|
AdMobService.HideBottomBanner();
|
|
|
- SceneManager.LoadScene("GameScene");
|
|
|
+ OpenGame();
|
|
|
+ }
|
|
|
+
|
|
|
+ GameScreenView OpenGame()
|
|
|
+ {
|
|
|
+ if (gameView != null)
|
|
|
+ return gameView;
|
|
|
+
|
|
|
+ if (gamePrefab == null)
|
|
|
+ {
|
|
|
+ Debug.LogError("[MainMenu] Game prefab is not assigned.");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ HideOverlays();
|
|
|
+ if (lobbyView != null)
|
|
|
+ lobbyView.Hide();
|
|
|
+
|
|
|
+ GameObject root = Instantiate(gamePrefab, transform, false);
|
|
|
+ root.name = "02_game";
|
|
|
+ var rect = root.GetComponent<RectTransform>();
|
|
|
+ if (rect != null)
|
|
|
+ {
|
|
|
+ rect.anchorMin = Vector2.zero;
|
|
|
+ rect.anchorMax = Vector2.one;
|
|
|
+ rect.pivot = new Vector2(0.5f, 0.5f);
|
|
|
+ rect.anchoredPosition = Vector2.zero;
|
|
|
+ rect.sizeDelta = Vector2.zero;
|
|
|
+ rect.localScale = Vector3.one;
|
|
|
+ }
|
|
|
+ root.transform.SetAsLastSibling();
|
|
|
+
|
|
|
+ gameView = root.GetComponent<GameScreenView>();
|
|
|
+ if (gameView == null)
|
|
|
+ gameView = root.AddComponent<GameScreenView>();
|
|
|
+
|
|
|
+ gameView.SetSelectedGlowMaterial(gameSelectedGlowMaterial);
|
|
|
+ gameView.SetPanelPrefabs(pausePanelPrefab, winPanelPrefab, losePanelPrefab, popViewPanelPrefab);
|
|
|
+ gameView.ExitRequested += HandleGameExitRequested;
|
|
|
+ gameView.NextLevelRequested += HandleGameNextLevelRequested;
|
|
|
+ gameView.Initialize(gameMode, gameLevel);
|
|
|
+
|
|
|
+ AdMobService.PreloadLevelAds();
|
|
|
+ AdMobService.HideBottomBanner();
|
|
|
+ AdMobService.ShowBottomBanner();
|
|
|
+ return gameView;
|
|
|
+ }
|
|
|
+
|
|
|
+ void HandleGameExitRequested()
|
|
|
+ {
|
|
|
+ AdMobService.TryShowInterstitialLevel(() =>
|
|
|
+ {
|
|
|
+ CloseGame();
|
|
|
+ ShowLobby();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void HandleGameNextLevelRequested(int nextLevel)
|
|
|
+ {
|
|
|
+ if (gameView == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ gameLevel = Mathf.Clamp(nextLevel, 1, GameDefinitions.MaxLevel);
|
|
|
+ GameFlowState.PrepareLaunch(gameMode, gameLevel);
|
|
|
+ gameView.Initialize(gameMode, gameLevel);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CloseGame()
|
|
|
+ {
|
|
|
+ if (gameView == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ gameView.ExitRequested -= HandleGameExitRequested;
|
|
|
+ gameView.NextLevelRequested -= HandleGameNextLevelRequested;
|
|
|
+ gameView.gameObject.SetActive(false);
|
|
|
+ Destroy(gameView.gameObject);
|
|
|
+ gameView = null;
|
|
|
}
|
|
|
|
|
|
void HandleHelpRequested()
|