feedback report 3 done
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using Mirror;
|
||||
public class GameOverCanvas : MonoBehaviour
|
||||
{
|
||||
public bool showOnLoad = false;
|
||||
@@ -61,6 +62,9 @@ public class GameOverCanvas : MonoBehaviour
|
||||
const int BetLimitUnlimited = 500;
|
||||
|
||||
int rematchOpponentBetLimitCoins = BetLimitUnlimited;
|
||||
bool opponentLeftDuringRematch;
|
||||
bool gameOverVisible;
|
||||
bool rematchRequestLocalPending;
|
||||
|
||||
[Header("Rematch panel")]
|
||||
public CanvasGroup rematchPanel;
|
||||
@@ -258,21 +262,78 @@ public class GameOverCanvas : MonoBehaviour
|
||||
return;
|
||||
if (txtBetLimitWarning != null)
|
||||
txtBetLimitWarning.gameObject.SetActive(false);
|
||||
NetPlayer.localPlayer.RequestRematch();
|
||||
SetRematchPendingState(true);
|
||||
NetPlayer.localPlayer.RequestRematch();
|
||||
}
|
||||
|
||||
public void OnRematchRequested(int opponentMaxBetLimitCoins){
|
||||
if (opponentLeftDuringRematch || AloneInRoom())
|
||||
{
|
||||
OnRematchCancelled(NetPlayer.OpponentLeftRematchMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
rematchOpponentBetLimitCoins = opponentMaxBetLimitCoins;
|
||||
if(winningTeam == myTeam){
|
||||
//Only the loser can initiate the rematch; winner sets the stake
|
||||
ShowRematchPanel();
|
||||
}else{
|
||||
rematchWarningLoser.text = "Waiting for opponent to accept";
|
||||
StartCoroutine(CoroutineWaitForOpponentToAcceptRematch());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opponent's player object was destroyed while this client is still in the match.
|
||||
/// </summary>
|
||||
public void NotifyOpponentDisconnected()
|
||||
{
|
||||
if (!gameOverVisible || opponentLeftDuringRematch || !NetworkClient.isConnected)
|
||||
return;
|
||||
|
||||
if (rematchRequestLocalPending || IsWaitingForOpponent() || IsRematchPanelOpen())
|
||||
{
|
||||
OnRematchCancelled(NetPlayer.OpponentLeftRematchMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
opponentLeftDuringRematch = true;
|
||||
UpdateRematchAvailability();
|
||||
}
|
||||
|
||||
IEnumerator CoroutineWaitForOpponentToAcceptRematch(){
|
||||
var wait = new WaitForSeconds(0.5f);
|
||||
while(IsWaitingForOpponent()){
|
||||
if (AloneInRoom())
|
||||
{
|
||||
OnRematchCancelled(NetPlayer.OpponentLeftRematchMessage);
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return wait;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsWaitingForOpponent()
|
||||
{
|
||||
return rematchWarningLoser != null
|
||||
&& rematchWarningLoser.text.ToLowerInvariant().Contains("waiting");
|
||||
}
|
||||
|
||||
bool IsRematchPanelOpen()
|
||||
{
|
||||
return rematchPanel != null && rematchPanel.alpha > 0.01f;
|
||||
}
|
||||
|
||||
bool AloneInRoom()
|
||||
{
|
||||
if (!NetworkClient.isConnected)
|
||||
return false;
|
||||
return FindObjectsByType<NetPlayer>(FindObjectsSortMode.None).Length <= 1;
|
||||
}
|
||||
|
||||
void SetRematchPendingState(bool val){
|
||||
rematchRequestLocalPending = val;
|
||||
btnRematch.interactable = false;
|
||||
btnLeave.interactable = !val;
|
||||
if(val){
|
||||
@@ -386,6 +447,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
float rcPrize = 0;
|
||||
public void Show(Team winningTeam, Team myTeam, int redScore, int blueScore){
|
||||
gameOverVisible = true;
|
||||
Setup(winningTeam, myTeam, redScore, blueScore);
|
||||
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
@@ -525,18 +587,29 @@ public class GameOverCanvas : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
public void OnRematchCancelled(){
|
||||
public void OnRematchCancelled(string message = NetPlayer.RematchDeclinedMessage){
|
||||
if (message == NetPlayer.OpponentLeftRematchMessage && opponentLeftDuringRematch)
|
||||
return;
|
||||
|
||||
rematchRequestLocalPending = false;
|
||||
if (message == NetPlayer.OpponentLeftRematchMessage)
|
||||
opponentLeftDuringRematch = true;
|
||||
|
||||
btnRematch.interactable=false;
|
||||
btnLeave.interactable=true;
|
||||
|
||||
rematchWarningLoser.text = "Rematch declined.";
|
||||
if (rematchWarningLoser != null)
|
||||
rematchWarningLoser.text = string.IsNullOrEmpty(message) ? NetPlayer.RematchDeclinedMessage : message;
|
||||
StartCoroutine(CoroutineHideRematchPanel());
|
||||
|
||||
if (countdownCoroutine != null)
|
||||
StopCoroutine(countdownCoroutine);
|
||||
countdownCoroutine = StartCoroutine(CoroutineCountdown());
|
||||
}
|
||||
|
||||
public void OnRematchFailed(string errorMessage)
|
||||
{
|
||||
rematchRequestLocalPending = false;
|
||||
btnRematch.interactable = true;
|
||||
btnLeave.interactable = true;
|
||||
if (rematchWarningLoser != null)
|
||||
@@ -611,6 +684,14 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
void UpdateRematchAvailability()
|
||||
{
|
||||
if (opponentLeftDuringRematch)
|
||||
{
|
||||
btnRematch.interactable = false;
|
||||
if (rematchWarningLoser != null)
|
||||
rematchWarningLoser.text = NetPlayer.OpponentLeftRematchMessage;
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameTutorialManager.tutorialModeEnabled)
|
||||
{
|
||||
btnRematch.interactable = false;
|
||||
|
||||
Reference in New Issue
Block a user