Untitled
unknown
plain_text
a year ago
27 kB
0
Indexable
Never
using System.Collections; using UnityEngine; using UnityEngine.UIElements; using DG.Tweening; using System.Collections.Generic; using UnityEngine.SceneManagement; using Unity.Services.Authentication; using Unity.Services.Core; using Unity.Services.Core.Environments; public class controller_mainmenu : controller_ui_ad { private readonly string environment = "production"; private Label m_lb_welcome, _lbl_online_count; private Button m_btn_play, m_btn_highscore, _btn_yes, _btn_no, _btn_en, _btn_mm, _btn_homequarter, _btn_shop; private VisualElement _frame_yesno, _frame_lg; private const string STR_WELCOME = "ေလးစားပါတယ္ ... "; private const string STR_LOADING = "ဆက္သြယ္ေဆာင္ရြက္ေန ... "; private const string STR_LOADING_EN = "Connecting ... "; private const string STR_RETRY = "အင္တာနက္ ႏွင့္ ဗီပီအမ္ ဖြင့္ထားျပီးပါသလား?\nျပန္ၾကိဳးစားေနပါတယ္ ..."; private const string STR_ONLINE_COUNT = "အြန္လိုင္း ကစားေန - "; private const string STR_DONATION_TOTAL = "စုေပါင္း လႉေငြ - "; private const string STR_YOUR_DONATION = "သင့္ လႉေငြ - "; private const string STR_ONLINE_COUNT_EN = "Online Players - "; [Header("Foreground Player Avatar")] public UnityEngine.UI.Image _Aavatar; public pdf_avatar_list m_Avatars; [Header("AdManager Obj")] public GameObject _AdManagerObj; private float _1DayIncome = 5000000; private readonly float SEC_IN_1DAY = 86400; private float _OneSecondIncome; private float _UpdateIncomeCounter = 1f; private float _EstimateAddedIncome; private float _RandomUpdateScale = 1f; private bool _ToQuit = false; protected override void Start() { base.Start(); //FirebaseInit(); //Debug.Log("test1"); _Aavatar.gameObject.SetActive(false); var root = GetComponent<UIDocument>().rootVisualElement; m_btn_play = root.Q<Button>("btn_play"); m_btn_play.clicked += OnBtnPlay; _btn_homequarter = root.Q<Button>("btn_homequarter"); _btn_homequarter.clicked += OnBtnHomeQuarter; _btn_shop = root.Q<Button>("btn_shop"); _btn_shop.clicked += OnBtnShop; root.Q<Button>("btn_exit").clicked += OnBtnExit; Button btn_change_language = root.Q<Button>("btn_change_english"); btn_change_language.style.display = DisplayStyle.None; m_btn_highscore = root.Q<Button>("btn_highscores"); m_btn_highscore.clicked += OnButtonHighScores; //Debug.Log("test2"); m_lb_welcome = root.Q<Label>("label_welcome"); _lbl_online_count = root.Q<Label>("lbl_online_count"); _frame_yesno = root.Q<VisualElement>("frame_yesno"); _btn_yes = root.Q<Button>("btn_yes"); _btn_no = root.Q<Button>("btn_no"); _frame_lg = root.Q<VisualElement>("frame_lg"); _btn_mm = root.Q<Button>("btn_myanmar"); _btn_en = root.Q<Button>("btn_english"); _btn_yes.clicked += OnBtnYes; _btn_no.clicked += OnBtnNo; _btn_mm.clicked += OnBtnMM; _btn_en.clicked += OnBtnEn; root.Q<Button>("btn_multi").clicked += OnBtnMulti; root.Q<Button>("btn_single").clicked += OnBtnSingle; root.Q<Button>("btn_back").clicked += OnBtnBack; _frame_yesno.style.display = DisplayStyle.None; _frame_lg.style.display = DisplayStyle.None; if(_lbl_online_count != null) _lbl_online_count.style.display = DisplayStyle.None; m_btn_play.style.display = DisplayStyle.None; m_btn_highscore.style.display = DisplayStyle.None; _btn_homequarter.style.display = DisplayStyle.None; _btn_shop.style.display = DisplayStyle.None; if(PlayerData.SerialNo == 0 ) { if(PlayerData.LanguageEn == false) m_lb_welcome.text = STR_LOADING; else m_lb_welcome.text = STR_LOADING_EN; m_btn_play.style.display = DisplayStyle.None; m_btn_highscore.style.display = DisplayStyle.None; } _OneSecondIncome = _1DayIncome / SEC_IN_1DAY; root.Q<Label>("lbl_version").text = "v - " + Application.version.ToString(); if(PlayerData.KillCount == 0 && PlayerData.MaxLevel == 0 && PlayerData.Donation == 0 ) { _ = LoadStart(); } else { OnCloudLoadFinish(true, false, ""); } //if(Application.) InitUnityServices(); } private void OnBtnToggleLanguage() { PlayerData.LanguageEn = !PlayerData.LanguageEn; HandleLanguage(); } private async void InitUnityServices() { if( UnityServices.State == ServicesInitializationState.Uninitialized) { InitializationOptions options = new InitializationOptions() .SetEnvironmentName(environment); if( UnityServices.State == ServicesInitializationState.Uninitialized) { await UnityServices.InitializeAsync(); } } try { if (AuthenticationService.Instance.IsSignedIn == false) { await AuthenticationService.Instance.SignInAnonymouslyAsync(); } } catch {} Debug.Log("Finish InitUnityServices"); } private void OnBtnMulti() { ChangeScene("sc_coop_ad"); } private void OnBtnSingle() { SinglePlayer(); } private void OnBtnBack() { PlayClickSound(); ShowStep1(); } private void ShowStep1() { var root = GetComponent<UIDocument>().rootVisualElement; root.Q<Button>("btn_play").style.display = DisplayStyle.Flex; ShowBtnHighScore(); ShowBtnShop(); root.Q<Button>("btn_homequarter").style.display = DisplayStyle.Flex; root.Q<Button>("btn_multi").style.display = DisplayStyle.None; root.Q<Button>("btn_single").style.display = DisplayStyle.None; root.Q<Button>("btn_back").style.display = DisplayStyle.None; } private void ShowBtnHighScore() { if(PlayerData.LastLevel > 4 && PlayerData.DailyLogin > 3 && PlayerData.Donation > 900 && ToHideFromAppReviewer() == false) { if(m_btn_highscore != null) m_btn_highscore.style.display = DisplayStyle.Flex; } else { if(m_btn_highscore != null) m_btn_highscore.style.display = DisplayStyle.None; } } private void ShowStep2() { var root = GetComponent<UIDocument>().rootVisualElement; root.Q<Button>("btn_play").style.display = DisplayStyle.None; if(m_btn_highscore != null) m_btn_highscore.style.display = DisplayStyle.None; root.Q<Button>("btn_shop").style.display = DisplayStyle.None; root.Q<Button>("btn_homequarter").style.display = DisplayStyle.None; root.Q<Button>("btn_multi").style.display = DisplayStyle.Flex; root.Q<Button>("btn_single").style.display = DisplayStyle.Flex; root.Q<Button>("btn_back").style.display = DisplayStyle.Flex; } /* private void FirebaseInit() { if(_FireBaseInit) return; _FireBaseInit = true; Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith( task => { var dependencyStatus = task.Result; if (dependencyStatus == Firebase.DependencyStatus.Available) { // Create and hold a reference to your FirebaseApp, // where app is a Firebase.FirebaseApp property of your application class. //app = Firebase.FirebaseApp.DefaultInstance; // Set a flag here to indicate whether Firebase is ready to use by your app. Debug.Log("Firebase ok"); if(PlayerData.LanguageEn == false && game_const.PAID_VERSION == false) { Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived; Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived; Firebase.Messaging.FirebaseMessaging.SubscribeAsync("/topics/mm"); } } else { UnityEngine.Debug.LogError(System.String.Format( "Could not resolve all Firebase dependencies: {0}", dependencyStatus)); // Firebase Unity SDK is not safe to use here. } } ); } public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) { Debug.Log("Received Registration Token: " + token.Token); } public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) { Debug.Log("Received a new message from: " + e.Message.From); } */ private void HandleLanguage() { var root = GetComponent<UIDocument>().rootVisualElement; if(PlayerData.LanguageEn == false) { m_btn_play.text = "ကစားမယ္"; _btn_homequarter.text = "စခန္း"; m_btn_highscore.text = "အမွတ္အျမင့္"; m_btn_highscore.style.display = DisplayStyle.None; root.Q<Button>("btn_multi").text = "အမ်ားနဲ႔ ကစား"; root.Q<Button>("btn_single").text = "ဇာတ္လမ္းသြား"; root.Q<Button>("btn_back").text = "ျပန္ထြက္"; root.Q<Button>("btn_change_english").text = "English | <color=green>ျမန္မာစာ</color>"; string StrGreeting = STR_WELCOME; if(PlayerData.LanguageEn) StrGreeting = ""; m_lb_welcome.text = StrGreeting + rank_fact.GetPDFRankStr(PlayerData.LanguageEn) + " " + PlayerData.Name; } else { m_btn_play.text = "Play"; _btn_homequarter.text = "Settings"; m_btn_highscore.text = "Highscores"; m_btn_highscore.style.display = DisplayStyle.None; _btn_shop.style.display = DisplayStyle.None; root.Q<Button>("btn_multi").text = "Online Coop"; root.Q<Button>("btn_single").text = "Missions"; root.Q<Button>("btn_back").text = "Back"; root.Q<Button>("btn_change_english").text = "<color=green>English</color> | ျမန္မာစာ"; m_lb_welcome.text = "Welcome! " + rank_fact.GetPDFRankStr(PlayerData.LanguageEn) + " " + PlayerData.Name; } } protected override void Update() { base.Update(); if(_UpdateIncomeCounter > 0) { _UpdateIncomeCounter-= Time.deltaTime; if( _UpdateIncomeCounter <= 0) { _EstimateAddedIncome += (_OneSecondIncome * _RandomUpdateScale); ShowIncomeInfos(_EstimateAddedIncome); _RandomUpdateScale = UnityEngine.Random.Range(0.1f,2.0f); _UpdateIncomeCounter = 1.0f * _RandomUpdateScale; } } if (Application.platform == RuntimePlatform.Android) { if (Input.GetKeyDown(KeyCode.Escape)) { OnBtnExit(); } } } private async System.Threading.Tasks.Task LoadStart() { while(PDFCloudSave.Instance == null) { await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(0.001f)); } pdf_file_save.Load ( () => { LoadDataFromCloud(); } ); } private void LoadDataFromCloud() { //Debug.Log("PASSCODE " + PlayerData.c_passcode.ToString()); if(PlayerData.c_passcode > 0 && pdf_game_settings.PassCodeChecked == false) { pdf_game_settings.CallBackModelClose = LoadDataFromCloudPrcoess; SceneManager.LoadScene(pdf_game_settings.SC_PASSCODE, LoadSceneMode.Additive); return; } LoadDataFromCloudPrcoess(); } private void LoadDataFromCloudPrcoess() { PDFCloudSave.Instance.SetUI(this); PDFCloudSave.Instance.Load(); } private void OnBtnYes() { _frame_yesno.style.display = DisplayStyle.None; ShowButtons(); } private void OnBtnMM() { PlayerData.LanguageEn = false; PlayClickSound(); _frame_lg.style.display = DisplayStyle.None; ShowButtons(); } private void OnBtnEn() { PlayerData.LanguageEn = true; PlayClickSound(); _frame_lg.style.display = DisplayStyle.None; ShowButtons(); } private void GotoPlayStore() { Debug.Log("redirecting to playstore..."); //Application.OpenURL ("market://details?id=" + Application.identifier); //Application.OpenURL ("https://gzentertainment.org/download"); Application.OpenURL ("https://thepdfgame.com/download"); } private void GotoAppStore() { Application.OpenURL ("https://apps.apple.com/us/app/the-pdf-game/id1619523469"); } private void OnBtnNo() { _frame_yesno.style.display = DisplayStyle.None; ShowButtons(); } private void OnBtnPlay() { PlayClickSound(); if(Application.identifier == pdf_game_settings.GAME_COOP) { OnBtnMulti(); return; } else { if( (Application.platform == RuntimePlatform.IPhonePlayer #if UNITY_IPHONE || (Application.isEditor) #endif ) && PlayerData.MaxLevel >= 11 && ToHideFromAppReviewer() == false ) { ShowStep2(); return; } OnBtnSingle(); return; } //ShowStep2(); //return; } private void SinglePlayer() { PlayClickSound(); //Debug.Log("clicked"); if(PlayerData.LastLevel == 31 ) { //if(Application.platform != RuntimePlatform.Android) // this.ChangeScene(pdf_game_settings.SC_CUTSCENE_2_PRE); //else this.ChangeScene(pdf_game_settings.SC_CUTSCENE_2); } else if(PlayerData.LastLevel == 0) this.ChangeScene(pdf_game_settings.SC_CUTSCENE); else this.ChangeScene(pdf_game_settings.SC_MISSION_OBJECTIVE); } private void OnBtnHomeQuarter() { this.ChangeScene(pdf_game_settings.SC_SETTINGS); } private void OnBtnShop() { this.ChangeScene(pdf_game_settings.sc_SHOP_FREE); } private void OnBtnExit() { var root = GetComponent<UIDocument>().rootVisualElement; root.Q<Button>("btn_exit").SetEnabled(false); if(PlayerData.KillCount == 0 && PlayerData.MaxLevel == 0 && PlayerData.Donation == 0 ) { Application.Quit(); } else if(PDFCloudSave.Instance != null) { if(PlayerData.LanguageEn) m_lb_welcome.text = "Saving..."; else m_lb_welcome.text = "မွတ္ေနသည္..."; m_btn_play.style.display = DisplayStyle.None; m_btn_highscore.style.display = DisplayStyle.None; _btn_homequarter.style.display = DisplayStyle.None; _btn_shop.style.display = DisplayStyle.None; _ToQuit = true; PDFCloudSave.Instance.SetUI(this); PDFCloudSave.Instance.Save(true); } } private void OnButtonHighScores() { PlayClickSound(); this.ChangeScene(pdf_game_settings.SC_HIGHSCORES); } private void ShowButtons() { HandleLanguage(); m_btn_play.style.display = DisplayStyle.Flex; //m_btn_highscore.visible = true; //_btn_homequarter.visible = true; ShowBtnHighScore(); if(PlayerData.LastLevel > 4) { string StrGreeting = STR_WELCOME; if(PlayerData.LanguageEn) StrGreeting = ""; m_lb_welcome.text = StrGreeting + rank_fact.GetPDFRankStr(PlayerData.LanguageEn) + " " + PlayerData.Name; } else { m_lb_welcome.text = ""; } // testing //PlayerData.AvatarIndex = 5; _Aavatar.sprite = m_Avatars.GetAvatar(PlayerData.AvatarIndex, PlayerData.IsMale); _Aavatar.gameObject.SetActive(true); //m_FrameButtons.transform.scale = new Vector3(0.5f, 0.5f, 0.5f); DOTween.To( () => 0.5f, x => m_btn_play.transform.scale = new Vector3(x, x, x), 1.0f, 0.25f ).SetEase(Ease.OutBack); // testing //pdf_game_settings.c_total_click = 10; //pdf_game_settings.donate_amount = 1000000; //PlayerData.TotalClick = 100; ShowIncomeInfos(); ShowBtnSettings(); ShowBtnShop(); } private void ShowBtnSettings() { if(ToHideFromAppReviewer() == false) _btn_homequarter.style.display = DisplayStyle.Flex; } private void ShowBtnShop() { if( PlayerData.LanguageEn == false && PlayerData.MaxLevel > 10 && Application.identifier != pdf_game_settings.GAME_COOP && PlayerData.DailyLogin >= 7 ) { _btn_shop.style.display = DisplayStyle.Flex; } else { _btn_shop.style.display = DisplayStyle.None; } if(PlayerData.Donation < 2000) _btn_shop.style.display = DisplayStyle.None; } private void ShowLgChoice() { m_lb_welcome.text = ""; _frame_lg.style.display = DisplayStyle.Flex; DOTween.To( () => 0.5f, x => _frame_lg.transform.scale = new Vector3(x, x, x), 1.0f, 0.25f ).SetEase(Ease.OutBack); PlayClickSound(); } private void ShowIncomeInfos(float EstimateAdded = 0) { if(_lbl_online_count != null && pdf_game_settings.to_show_online_count && PlayerData.LanguageEn == false && PlayerData.LastLevel > 2 && PlayerData.Donation > 2000 ) { _lbl_online_count.style.display = DisplayStyle.Flex; if(PlayerData.LanguageEn == false) _lbl_online_count.text = STR_ONLINE_COUNT; else _lbl_online_count.text = STR_ONLINE_COUNT_EN; _lbl_online_count.text += string.Format("{0:n0}", pdf_game_settings.online_count); _lbl_online_count.text += "/"; _lbl_online_count.text += string.Format("{0:n0}",pdf_game_settings.total_player_count); if(pdf_game_settings.to_show_donate_amount && pdf_game_settings.donate_amount > 0 ) { _lbl_online_count.text += "\n"; _lbl_online_count.text += STR_DONATION_TOTAL; _lbl_online_count.text += string.Format("{0:n0}", pdf_game_settings.donate_amount + (int)EstimateAdded); if(PlayerData.Donation > 0) { _lbl_online_count.text += "\n"; _lbl_online_count.text += STR_YOUR_DONATION; _lbl_online_count.text += string.Format("{0:n0}",PlayerData.Donation); } } _lbl_online_count.text += "\n"; _lbl_online_count.text += "သင္ေန႕စဥ္ဝင္: " + (PlayerData.DailyLogin + 1) + " ရက္"; System.TimeSpan t = System.TimeSpan.FromSeconds(PlayerData.c_screen_time + pdf_game_settings._ScreenTimeUnsave ); string TimeStr = string.Format("{0:D2}:{1:D2}:{2:D2}", (int)(t.TotalHours), t.Minutes, t.Seconds); _lbl_online_count.text += "\n"; _lbl_online_count.text += "အသုံးျပဳခ်ိန္: (နာရီ:မိနစ္:စကၠန႔္) - " + TimeStr; } else { _lbl_online_count.text = ""; } } public override void OnCloudLoadFinish(bool IsSucess, bool IsConnectionError, string ErrorMsg) { if(IsConnectionError) { m_lb_welcome.text = STR_RETRY + "\n" + ErrorMsg; return; } else if(IsSucess == false) { m_lb_welcome.text = ErrorMsg; return; } if(ToHideFromAppReviewer() && (Application.platform == RuntimePlatform.IPhonePlayer #if UNITY_IOS || Application.isEditor #endif ) ) { OnBtnMulti(); return; } m_lb_welcome.text = ""; //_UmpController.gameObject.SetActive(true); AfterUMP(); if(pdf_game_settings.to_offer_english_ios == false && ( Application.platform == RuntimePlatform.IPhonePlayer #if UNITY_IPHONE || (Application.isEditor) #endif ) ) { } else { var root = GetComponent<UIDocument>().rootVisualElement; Button btn_change_language = root.Q<Button>("btn_change_english"); if(btn_change_language != null) { if(ToHideFromAppReviewer()) { btn_change_language.style.display = DisplayStyle.None; } else { btn_change_language.clicked += OnBtnToggleLanguage; btn_change_language.style.display = DisplayStyle.Flex; } } } } public void AfterUMP() { if(PlayerData.LastLevel == 0 && PlayerData.LanguageEn && PlayerData.KillCount == 0 && PlayerData.Donation == 0 && PlayerData.EXP == 0 && ToHideFromAppReviewer() == false ) { this.ShowLgChoice(); } // any message to show before main menu??? else if(CheckMessages() == false) { this.ShowButtons(); } if(PlayerData.c_passcode > 0 && pdf_game_settings.PassCodeChecked == false) { SceneManager.LoadScene(pdf_game_settings.SC_PASSCODE, LoadSceneMode.Additive); } _AdManagerObj.SetActive(true); } public override void OnCloudSaveFinish(bool IsScuess) { if(IsScuess && _ToQuit) { m_lb_welcome.text = ""; Application.Quit(); } } private bool CheckMessages() { int current_verion = 0; try { current_verion = int.Parse(Application.version); } catch {} int server_version = pdf_game_settings.version_android; if(Application.platform == RuntimePlatform.IPhonePlayer) server_version = pdf_game_settings.version_ios; if(server_version > current_verion) { m_lb_welcome.text = ""; _frame_yesno.style.display = DisplayStyle.Flex; if (Application.platform == RuntimePlatform.Android) _btn_yes.clicked += GotoPlayStore; else if(Application.platform == RuntimePlatform.IPhonePlayer) _btn_yes.clicked += GotoAppStore; DOTween.To( () => 0.5f, x => _frame_yesno.transform.scale = new Vector3(x, x, x), 1.0f, 0.25f ).SetEase(Ease.OutBack); PlayClickSound(); return true; } //Debug.Log(Application.version); //Debug.Log(Application.absoluteURL); return false; } public void OnGeoLookupFinish() { if(PDFIPLocation._GeoData.countryName == null) return; if(PDFIPLocation._GeoData.countryName == "Myanmar") { m_lb_welcome.text = "ဗီပီအမ္ (VPN) သုံးရန္ လိုအပ္ပါသည္။"; } } }