///// Popup updater functions and generators ///// private bool NewMatchRequestUpdater(MatchRequestEventArgs matchRequest) { if (matchRequest.Status == MatchRequestEventArgs.EStatus.New) { // Set popup var popup = PopupPanel.InstanciateTimeoutPopup(); popup.Text = "New match request from \n<color=#66FFD9><b>" + matchRequest.User.UserName + "</b></color>"; popup.AcceptButton.onClick.AddListener(() => { popup.StatorAnimation.Interrupt(); popup.AcceptButton.interactable = false; popup.DeclineButton.interactable = false; popup.StatorAnimation.StartPulse(Color.green, 0.5f, 4); popup.StatorAnimation.Finished.UnsubscribeAll(); popup.StatorAnimation.Finished.Subscribe((sender, e) => { Destroy(popup.gameObject); UIController.RaiseReadyToGame(); }); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Accepted)); popupUpdaters.Add(MatchRequestEchoHandlerGen(matchRequest.User)); }); popup.DeclineButton.onClick.AddListener(() => { Destroy(popup.gameObject); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Declined)); popupUpdaters.Add(MatchRequestEchoHandlerGen(matchRequest.User)); }); popup.StatorAnimation.StartTimeout(5); popup.StatorAnimation.Finished.Subscribe((sender, e) => { Destroy(popup.gameObject); Debug.Log("Sending automatic decline answer [TIMEOUT]"); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Declined)); }); // Set popup updater function var popupUpdater = NewMatchRequestCanceledUpdaterGen(popup, matchRequest.User); popupUpdaters.Add(popupUpdater); popup.Disabled += (sender, e) => popupUpdaters.Remove(popupUpdater); return(true); } return(false); }
public void SimulateRequestFromOpponent(int msFromStart, bool cancelRequest = false) { Debug.Log("Incoming match request in " + msFromStart + " ms!"); var th = new Thread(() => { User opponent = new User(654321, "CeriseDeGroupama"); Thread.Sleep(msFromStart); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(opponent, MatchRequestEventArgs.EStatus.New)); if (cancelRequest) { Thread.Sleep(100); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(opponent, MatchRequestEventArgs.EStatus.Canceled)); } }); th.Start(); }
///// Event handlers ///// private void OnSendingMatchRequest(object sender, MatchRequestEventArgs e) { // Set popup var popup = PopupPanel.InstanciateWaitingPopupCancelButton(); popup.Text = "Waiting for \n<color=#66FFD9><b>" + e.User.UserName + "</b></color>"; popup.CancelButton.onClick.AddListener(() => { Destroy(popup.gameObject); Debug.Log("CancelButton clicked"); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(e.User, MatchRequestEventArgs.EStatus.Canceled)); }); popup.StatorAnimation.StartRotate(1); // Set popup updater function var popupUpdater = MatchRequestResponseUpdaterGen(popup, e.User); popupUpdaters.Add(popupUpdater); popup.Disabled += (sender_, e_) => popupUpdaters.Remove(popupUpdater); // Notify web client MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(e.User, MatchRequestEventArgs.EStatus.New)); }
public void OnMatchRequestUpdated(object sender, MatchRequestEventArgs e) { switch (e.Status) { case MatchRequestEventArgs.EStatus.New: // Simulate opponent respoonse var eCopy = e; listeningThread = new Thread(() => { try { Thread.Sleep(2000); MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(eCopy.User, MatchRequestEventArgs.EStatus.Accepted)); } catch (ThreadInterruptedException) {} }); listeningThread.Start(); break; case MatchRequestEventArgs.EStatus.Canceled: // Notifyy opponent listeningThread.Interrupt(); break; case MatchRequestEventArgs.EStatus.Accepted: // Notify opponent break; case MatchRequestEventArgs.EStatus.Declined: // Notify opponent break; default: break; } }