173 lines
4.0 KiB
C#
173 lines
4.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Collections;
|
|
|
|
public class StorySelectManager : MonoBehaviour
|
|
{
|
|
[Header("Setting")]
|
|
public int unlockBab2Point = 100;
|
|
|
|
[Header("UI")]
|
|
public Button bab2Button;
|
|
public GameObject lockIcon;
|
|
public CanvasGroup bab2Canvas;
|
|
public CanvasGroup bab3Canvas;
|
|
|
|
public Button bab3Button;
|
|
public GameObject lockBab3;
|
|
public Button bab4Button;
|
|
public GameObject lockBab4;
|
|
public CanvasGroup bab4Canvas;
|
|
public Button bab5Button;
|
|
public GameObject lockBab5;
|
|
public CanvasGroup bab5Canvas;
|
|
|
|
int totalPoints;
|
|
|
|
void Start()
|
|
{
|
|
Time.timeScale = 1f; // reset kalau sebelumnya pause
|
|
LoadData();
|
|
|
|
if (ManagerGame.instance != null)
|
|
{
|
|
if (ManagerGame.instance != null && ManagerGame.instance.isNewGame)
|
|
{
|
|
GameProgress.Reset();
|
|
Debug.Log("MODE: NEW GAME");
|
|
Debug.Log("CH2: " + PlayerPrefs.GetInt("CHAPTER_2", -1));
|
|
Debug.Log("CH3: " + PlayerPrefs.GetInt("CHAPTER_3", -1));
|
|
Debug.Log("CH4: " + PlayerPrefs.GetInt("CHAPTER_4", -1));
|
|
}
|
|
else if (ManagerGame.instance.isContinue)
|
|
{
|
|
Debug.Log("MODE: CONTINUE");
|
|
// 🔥 RESET FLAG SETELAH DIPAKAI
|
|
ManagerGame.instance.isContinue = false;
|
|
LoadData();
|
|
UpdateUI();
|
|
Debug.Log("MODE: CONTINUE");
|
|
Debug.Log("FORCE CHECK CH2 RAW: " + PlayerPrefs.GetInt("CHAPTER_2"));
|
|
}
|
|
}
|
|
|
|
UpdateUI();
|
|
}
|
|
|
|
void LoadData()
|
|
{
|
|
totalPoints = PlayerPrefs.GetInt("TOTAL_POINTS", 0);
|
|
Debug.Log("TOTAL POINTS: " + totalPoints);
|
|
}
|
|
|
|
void UpdateUI()
|
|
{
|
|
int totalPoints = GameProgress.GetTotalPoints();
|
|
|
|
bool bab2Unlocked = GameProgress.IsChapterUnlocked(2);
|
|
bool bab3Unlocked = GameProgress.IsChapterUnlocked(3);
|
|
bool bab4Unlocked = GameProgress.IsChapterUnlocked(4);
|
|
bool bab5Unlocked = GameProgress.IsChapterUnlocked(5);
|
|
|
|
Debug.Log("TOTAL POINTS: " + totalPoints);
|
|
Debug.Log("Bab2: " + bab2Unlocked);
|
|
Debug.Log("Bab3: " + bab3Unlocked);
|
|
Debug.Log("Bab4: " + bab4Unlocked);
|
|
Debug.Log("Bab5: " + bab5Unlocked);
|
|
|
|
SetButton(bab2Button, bab2Canvas, lockIcon, bab2Unlocked);
|
|
SetButton(bab3Button, bab3Canvas, lockBab3, bab3Unlocked);
|
|
SetButton(bab4Button, bab4Canvas, lockBab4, bab4Unlocked);
|
|
SetButton(bab5Button, bab5Canvas, lockBab5, bab5Unlocked);
|
|
}
|
|
|
|
void SetButton(Button btn, CanvasGroup canvas, GameObject lockObj, bool unlocked)
|
|
{
|
|
btn.interactable = unlocked;
|
|
|
|
canvas.interactable = unlocked;
|
|
canvas.blocksRaycasts = unlocked; // 🔥 jangan true terus
|
|
|
|
lockObj.SetActive(!unlocked);
|
|
}
|
|
|
|
|
|
// ================= BUTTON =================
|
|
|
|
public void GoToBab2()
|
|
{
|
|
if (!GameProgress.IsChapterUnlocked(2))
|
|
{
|
|
Debug.Log("Bab 2 masih terkunci!");
|
|
return;
|
|
}
|
|
|
|
SceneManager.LoadScene("Bab_2");
|
|
}
|
|
|
|
public void GoToBab3()
|
|
{
|
|
if (!GameProgress.IsChapterUnlocked(3))
|
|
{
|
|
Debug.Log("Bab 3 masih terkunci!");
|
|
return;
|
|
}
|
|
|
|
SceneManager.LoadScene("Bab_3");
|
|
}
|
|
|
|
public void GoToBab4()
|
|
{
|
|
if (!GameProgress.IsChapterUnlocked(4))
|
|
{
|
|
Debug.Log("Bab 4 masih terkunci!");
|
|
return;
|
|
}
|
|
|
|
SceneManager.LoadScene("Bab_4");
|
|
}
|
|
|
|
public void GoToBab5()
|
|
{
|
|
if (!GameProgress.IsChapterUnlocked(5))
|
|
{
|
|
Debug.Log("Bab 5 masih terkunci!");
|
|
return;
|
|
}
|
|
|
|
SceneManager.LoadScene("Bab_5");
|
|
}
|
|
|
|
public void NewGame()
|
|
{
|
|
Debug.Log("NEW GAME: RESET SEMUA");
|
|
|
|
GameProgress.Reset();
|
|
VN_SaveSystem.DeleteAllSave();
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
SceneManager.LoadScene("Bab_1");
|
|
}
|
|
|
|
public void BackToMainMenu()
|
|
{
|
|
Debug.Log("Kembali ke Main Menu");
|
|
|
|
if (ManagerGame.instance != null)
|
|
{
|
|
ManagerGame.instance.isContinue = false; // 🔥 RESET
|
|
ManagerGame.instance.isNewGame = false;
|
|
ManagerGame.instance.isDirectChapter = false;
|
|
}
|
|
|
|
SceneManager.LoadScene("MainMenu");
|
|
}
|
|
|
|
IEnumerator LoadMenu()
|
|
{
|
|
yield return new WaitForSeconds(0.3f);
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
|
|
}
|
|
} |