119 lines
4.2 KiB
C#
119 lines
4.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Google;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
public class MainMenu : MonoBehaviour
|
|
{
|
|
|
|
public GameObject MainMenuPanel;
|
|
public GameObject SettingsPanel;
|
|
public GameObject LeaderboarPanel;
|
|
public Transform LeaderboardItemsParent;
|
|
public float transitionTime;
|
|
public LeanTweenType transitionEffect;
|
|
|
|
private Vector2 defaultCenter;
|
|
public Button copyBtn, muteBtn;
|
|
public Button signoutBtn;
|
|
public Sprite muteIcon, unmuteIcon;
|
|
|
|
|
|
public Text txtUserId;
|
|
|
|
void Awake(){
|
|
if(!DataManager.isLogged){
|
|
SceneManager.LoadScene(0);
|
|
return;
|
|
}
|
|
defaultCenter = MainMenuPanel.transform.position;
|
|
SettingsPanel.transform.position = MainMenuPanel.transform.position - new Vector3(10000,0);
|
|
SettingsPanel.SetActive(true);
|
|
LeaderboarPanel.SetActive(true);
|
|
LeaderboarPanel.transform.position = MainMenuPanel.transform.position + new Vector3(10000,0);
|
|
|
|
muteBtn.onClick.AddListener(ToggleMute);
|
|
copyBtn.onClick.AddListener(CopyId);
|
|
signoutBtn.onClick.AddListener(SignOut);
|
|
|
|
DataManager.RefreshLeaderboard();
|
|
}
|
|
public void Leave(){
|
|
Application.Quit();
|
|
}
|
|
|
|
void Start(){
|
|
Refresh();
|
|
// MessageBox.ShowMessage("Welcome to Infinite Golf 2D.\nThis is a slow paced 2d endless golf game, All the levels are proceduraly generated and you will be rewarded for putting the ball in every and each hole.\n\nGood Luck","Welcome");
|
|
}
|
|
|
|
|
|
void Refresh(){
|
|
txtUserId.text = Encryptor.intToString(DataManager.userData.id);
|
|
if(AudioManager.isMute){
|
|
muteBtn.transform.GetChild(0).GetComponent<Image>().sprite = muteIcon;
|
|
}else{
|
|
muteBtn.transform.GetChild(0).GetComponent<Image>().sprite = unmuteIcon;
|
|
}
|
|
}
|
|
|
|
public void SettingsPage(){
|
|
LeanTween.moveX(MainMenuPanel, 10000, transitionTime).setEase(transitionEffect);
|
|
LeanTween.moveX(SettingsPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
|
}
|
|
|
|
public void LeaderboarPage(){
|
|
LeanTween.moveX(MainMenuPanel, -10000, transitionTime).setEase(transitionEffect);
|
|
LeanTween.moveX(LeaderboarPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
|
RefreshLeaderboard();
|
|
}
|
|
|
|
public void MainPage(){
|
|
LeanTween.moveX(MainMenuPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
|
LeanTween.moveX(SettingsPanel, -10000, transitionTime).setEase(transitionEffect);
|
|
LeanTween.moveX(LeaderboarPanel, 10000, transitionTime).setEase(transitionEffect);
|
|
}
|
|
|
|
public void CopyId(){
|
|
GUIUtility.systemCopyBuffer = txtUserId.text;
|
|
copyBtn.transform.Find("lbl").GetComponent<Text>().text = "Copied";
|
|
}
|
|
|
|
public void ToggleMute(){
|
|
AudioManager.ToggleMute();
|
|
Refresh();
|
|
}
|
|
|
|
public void Info(){
|
|
MessageBox.ShowMessage(@"This is a game where you can relax while playing,
|
|
Listen to a podcast or to music while playing this to get the best out of it!
|
|
|
|
Any feedback or suggestion can be directed to us via this email
|
|
sewmina7@gmail.com","About");
|
|
}
|
|
|
|
async void RefreshLeaderboard(){
|
|
UpdateLeaderboardUI();
|
|
await DataManager.RefreshLeaderboard();
|
|
UpdateLeaderboardUI();
|
|
}
|
|
|
|
void UpdateLeaderboardUI(){
|
|
for(int i =0; i < DataManager.Leaderboard.Count; i++){
|
|
LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].DisplayName;
|
|
// LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].name;
|
|
LeaderboardItemsParent.GetChild(i).GetChild(1).GetComponent<Text>().text = DataManager.Leaderboard[i].topScore.ToString();
|
|
|
|
LeaderboardItemsParent.GetChild(i).GetComponent<Image>().CrossFadeAlpha((DataManager.Leaderboard[i].name == DataManager.userData.username) ? 0.9f : 0,0.5f,true);
|
|
}
|
|
}
|
|
|
|
void SignOut(){
|
|
|
|
|
|
DataManager.Signout();
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
}
|