rc 1.0
This commit is contained in:
@@ -5,6 +5,12 @@ using UnityEngine.UI;
|
||||
|
||||
public class MainMenuManager : MonoBehaviour
|
||||
{
|
||||
const string CryptoAddressPrefsKey = "MainMenu.CryptoAddress";
|
||||
/// <summary>500 CC fee to process a withdrawal.</summary>
|
||||
const int WithdrawalFeeCc = 500;
|
||||
/// <summary>$20 USD = 20.0 RC, stored in DB as 80 rc coins (4 coins per 1.0 RC).</summary>
|
||||
const int MinimumWithdrawalRcCoins = 80;
|
||||
|
||||
[Header("Stats")]
|
||||
[SerializeField] private GameObject statsPanel;
|
||||
[SerializeField] private TMP_Text usernameText;
|
||||
@@ -15,12 +21,22 @@ public class MainMenuManager : MonoBehaviour
|
||||
public GameObject mainMenuScreen;
|
||||
public GameObject gameModesScreen;
|
||||
public GameObject dummyBuyScreen;
|
||||
public GameObject withdrawalScreen;
|
||||
[Header("Play")]
|
||||
public Button btnPlay;
|
||||
public TMP_Text rcPlayText;
|
||||
|
||||
[Header("Dummy Buy")]
|
||||
public Button btnBuyUsd5;
|
||||
public Button btnBuyUsd20;
|
||||
public Button btnBuyUsd50;
|
||||
|
||||
[Header("Withdrawal")]
|
||||
public Button btnWithdrawal;
|
||||
public Button btnPaste;
|
||||
public TMP_InputField inputCryptoAddress;
|
||||
public TMP_Text txtWithdrawStatus;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(LoginManager.instance==null){
|
||||
@@ -45,12 +61,75 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnBuyUsd20.onClick.AddListener(() => OnBuy(RcPack.Usd20));
|
||||
btnBuyUsd50.onClick.AddListener(() => OnBuy(RcPack.Usd50));
|
||||
|
||||
if (inputCryptoAddress != null)
|
||||
{
|
||||
inputCryptoAddress.text = PlayerPrefs.GetString(CryptoAddressPrefsKey, string.Empty);
|
||||
inputCryptoAddress.onValueChanged.AddListener(OnCryptoAddressChanged);
|
||||
}
|
||||
|
||||
UpdateWithdrawalStatus();
|
||||
|
||||
if (btnPaste != null)
|
||||
btnPaste.onClick.AddListener(OnPasteFromClipboard);
|
||||
|
||||
btnPlay.onClick.AddListener(OnPlay);
|
||||
}
|
||||
|
||||
void OnPlay(){
|
||||
if(LoginManager.CurrentUser.rc < 21){
|
||||
Debug.LogError("Not enough RC to play");
|
||||
return;
|
||||
}
|
||||
CupidLobby.instance.Matchmake();
|
||||
}
|
||||
|
||||
void OnCryptoAddressChanged(string value)
|
||||
{
|
||||
PlayerPrefs.SetString(CryptoAddressPrefsKey, value ?? string.Empty);
|
||||
PlayerPrefs.Save();
|
||||
UpdateWithdrawalStatus();
|
||||
}
|
||||
|
||||
void UpdateWithdrawalStatus(UserData user = null)
|
||||
{
|
||||
if (txtWithdrawStatus == null)
|
||||
return;
|
||||
UserData u = user ?? LoginManager.CurrentUser;
|
||||
if (u == null)
|
||||
return;
|
||||
|
||||
if (inputCryptoAddress != null && string.IsNullOrWhiteSpace(inputCryptoAddress.text))
|
||||
{
|
||||
txtWithdrawStatus.text = "Enter a valid wallet address to withdraw safely.";
|
||||
return;
|
||||
}
|
||||
if (u.rc < MinimumWithdrawalRcCoins)
|
||||
{
|
||||
txtWithdrawStatus.text = "Your RC balance is below the minimum withdrawal amount ($20 USD / 20.0 RC).";
|
||||
return;
|
||||
}
|
||||
if (u.cc < WithdrawalFeeCc)
|
||||
{
|
||||
txtWithdrawStatus.text = "Withdrawal costs 500 CC. Your CC balance is below 500 CC.";
|
||||
return;
|
||||
}
|
||||
txtWithdrawStatus.text = string.Empty;
|
||||
}
|
||||
|
||||
void OnPasteFromClipboard()
|
||||
{
|
||||
if (inputCryptoAddress == null)
|
||||
return;
|
||||
string clip = GUIUtility.systemCopyBuffer;
|
||||
if (!string.IsNullOrEmpty(clip))
|
||||
inputCryptoAddress.text = clip;
|
||||
}
|
||||
|
||||
void OnBuy(string packId){
|
||||
LoginManager.instance.PurchaseRcPack(packId, (success, error) => {
|
||||
if(success){
|
||||
OnUserUpdated(LoginManager.CurrentUser);
|
||||
AudioManager.instance.PlayCoinsSfx();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -68,8 +147,18 @@ public class MainMenuManager : MonoBehaviour
|
||||
|
||||
void OnUserUpdated(UserData user){
|
||||
usernameText.text = user.username;
|
||||
ccText.text = CoinHelper.FormatString(user.cc) + " CC";
|
||||
ccText.text = user.cc.ToString("N0") + " CC";
|
||||
rcText.text = CoinHelper.FormatString(user.rc) + " RC";
|
||||
|
||||
if(LoginManager.CurrentUser.rc < 21){
|
||||
rcPlayText.text = "Not enough RC to play";
|
||||
btnPlay.interactable = false;
|
||||
}else{
|
||||
rcPlayText.text = "";
|
||||
btnPlay.interactable = true;
|
||||
}
|
||||
|
||||
UpdateWithdrawalStatus(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +167,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
mainMenuScreen.SetActive(true);
|
||||
gameModesScreen.SetActive(false);
|
||||
dummyBuyScreen.SetActive(false);
|
||||
withdrawalScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowGameModesScreen(){
|
||||
@@ -85,6 +175,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
mainMenuScreen.SetActive(false);
|
||||
gameModesScreen.SetActive(true);
|
||||
dummyBuyScreen.SetActive(false);
|
||||
withdrawalScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowDummyBuyScreen(){
|
||||
@@ -92,5 +183,16 @@ public class MainMenuManager : MonoBehaviour
|
||||
mainMenuScreen.SetActive(false);
|
||||
gameModesScreen.SetActive(false);
|
||||
dummyBuyScreen.SetActive(true);
|
||||
withdrawalScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowWithdrawalScreen(){
|
||||
statsPanel.SetActive(false);
|
||||
mainMenuScreen.SetActive(false);
|
||||
gameModesScreen.SetActive(false);
|
||||
dummyBuyScreen.SetActive(false);
|
||||
withdrawalScreen.SetActive(true);
|
||||
UpdateWithdrawalStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user