sync
This commit is contained in:
@@ -45,6 +45,20 @@ public class GameOverCanvas : MonoBehaviour
|
||||
/// <summary>Each player needs at least 2.0 RC (20 coin units) to rematch.</summary>
|
||||
const int MinimumRematchRcCoins = 20;
|
||||
|
||||
[Header("Bet Limit")]
|
||||
public TMP_Text txtBetLimitWarning;
|
||||
public CanvasGroup betLimitAdjustPanel;
|
||||
//minVal: 2, max Val 500, when its 500, show ∞ on the text
|
||||
public Slider betLimitSlider;
|
||||
public TMP_Text txtBetLimitSliderValue;
|
||||
public Button btnBetLimitAdjustAccept;
|
||||
public Button btnBetLimitAdjustCancel;
|
||||
|
||||
const string PersonalBetLimitPrefsKey = "WalkInvest.PersonalBetLimit";
|
||||
const int BetLimitMin = 2;
|
||||
const int BetLimitMax = 500;
|
||||
const int BetLimitUnlimited = 500;
|
||||
|
||||
[Header("Rematch panel")]
|
||||
public CanvasGroup rematchPanel;
|
||||
public RectTransform rematchPopup;
|
||||
@@ -85,6 +99,107 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
btnConfirmBet.onClick.AddListener(OnBetAccepted);
|
||||
btnCancelBet.onClick.AddListener(OnBetCancelled);
|
||||
|
||||
SetupBetLimitUi();
|
||||
}
|
||||
|
||||
void SetupBetLimitUi()
|
||||
{
|
||||
if (betLimitSlider != null)
|
||||
{
|
||||
betLimitSlider.minValue = BetLimitMin;
|
||||
betLimitSlider.maxValue = BetLimitMax;
|
||||
betLimitSlider.wholeNumbers = true;
|
||||
betLimitSlider.onValueChanged.AddListener(OnBetLimitSliderValueChanged);
|
||||
}
|
||||
|
||||
if (btnBetLimitAdjustAccept != null)
|
||||
btnBetLimitAdjustAccept.onClick.AddListener(OnBetLimitAdjustAccepted);
|
||||
if (btnBetLimitAdjustCancel != null)
|
||||
btnBetLimitAdjustCancel.onClick.AddListener(CloseBetLimitAdjuster);
|
||||
|
||||
var warningButton = txtBetLimitWarning != null
|
||||
? txtBetLimitWarning.GetComponentInChildren<Button>()
|
||||
: null;
|
||||
if (warningButton != null)
|
||||
warningButton.onClick.AddListener(OpenBetLimitAdjuster);
|
||||
}
|
||||
|
||||
public static int GetPersonalBetLimit()
|
||||
{
|
||||
return PlayerPrefs.GetInt(PersonalBetLimitPrefsKey, BetLimitUnlimited);
|
||||
}
|
||||
|
||||
static void SetPersonalBetLimit(int limitCoins)
|
||||
{
|
||||
limitCoins = Mathf.Clamp(limitCoins, BetLimitMin, BetLimitMax);
|
||||
PlayerPrefs.SetInt(PersonalBetLimitPrefsKey, limitCoins);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
static string FormatBetLimitLabel(int limitCoins)
|
||||
{
|
||||
if (limitCoins >= BetLimitUnlimited)
|
||||
return "∞";
|
||||
return CoinHelper.FormatString(limitCoins) + " RC";
|
||||
}
|
||||
|
||||
static string FormatBetLimitWarningText(int limitCoins) =>
|
||||
"Max Bet : " + FormatBetLimitLabel(limitCoins);
|
||||
|
||||
void UpdateBetLimitWarningText()
|
||||
{
|
||||
if (txtBetLimitWarning != null)
|
||||
txtBetLimitWarning.text = FormatBetLimitWarningText(GetPersonalBetLimit());
|
||||
}
|
||||
|
||||
void OnBetLimitSliderValueChanged(float value)
|
||||
{
|
||||
if (txtBetLimitSliderValue != null)
|
||||
txtBetLimitSliderValue.text = FormatBetLimitLabel(Mathf.RoundToInt(value));
|
||||
}
|
||||
|
||||
void ApplyBetLimitVisibility()
|
||||
{
|
||||
bool isLoser = myTeam != winningTeam;
|
||||
if (txtBetLimitWarning != null)
|
||||
txtBetLimitWarning.gameObject.SetActive(isLoser);
|
||||
if (!isLoser)
|
||||
return;
|
||||
UpdateBetLimitWarningText();
|
||||
}
|
||||
|
||||
public void OpenBetLimitAdjuster()
|
||||
{
|
||||
if (betLimitAdjustPanel == null)
|
||||
return;
|
||||
|
||||
int limit = GetPersonalBetLimit();
|
||||
if (betLimitSlider != null)
|
||||
betLimitSlider.SetValueWithoutNotify(limit);
|
||||
OnBetLimitSliderValueChanged(limit);
|
||||
|
||||
betLimitAdjustPanel.DOFade(1, 0.25f);
|
||||
betLimitAdjustPanel.blocksRaycasts = true;
|
||||
betLimitAdjustPanel.interactable = true;
|
||||
}
|
||||
|
||||
public void CloseBetLimitAdjuster()
|
||||
{
|
||||
if (betLimitAdjustPanel == null)
|
||||
return;
|
||||
|
||||
betLimitAdjustPanel.DOFade(0, 0.25f);
|
||||
betLimitAdjustPanel.blocksRaycasts = false;
|
||||
betLimitAdjustPanel.interactable = false;
|
||||
}
|
||||
|
||||
void OnBetLimitAdjustAccepted()
|
||||
{
|
||||
if (betLimitSlider != null)
|
||||
SetPersonalBetLimit(Mathf.RoundToInt(betLimitSlider.value));
|
||||
UpdateBetLimitWarningText();
|
||||
CloseBetLimitAdjuster();
|
||||
}
|
||||
|
||||
void OnBetAccepted(){
|
||||
@@ -181,6 +296,13 @@ public class GameOverCanvas : MonoBehaviour
|
||||
rematchPanel.alpha=0;
|
||||
rematchPanel.blocksRaycasts = false;
|
||||
rematchPanel.interactable = false;
|
||||
|
||||
if (betLimitAdjustPanel != null)
|
||||
{
|
||||
betLimitAdjustPanel.alpha = 0;
|
||||
betLimitAdjustPanel.blocksRaycasts = false;
|
||||
betLimitAdjustPanel.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
Team winningTeam;
|
||||
@@ -220,6 +342,8 @@ public class GameOverCanvas : MonoBehaviour
|
||||
p1_winner.gameObject.SetActive(false);
|
||||
p2_winner.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
ApplyBetLimitVisibility();
|
||||
}
|
||||
|
||||
float rcPrize = 0;
|
||||
|
||||
Reference in New Issue
Block a user