소스 검색

拒绝邀请

lvjincheng 4 년 전
부모
커밋
d48cc893f2

+ 7 - 2
Assets/BowArrow/Scripts/Manager/PopupMgr.cs

@@ -77,7 +77,10 @@ public class PopupMgr : MonoBehaviour
         });
     }
 
-    public void ShowPKInviteNotice(int avatarID, string nickname, string tip, System.Action cb) {
+    public void ShowPKInviteNotice(
+        int avatarID, string nickname, string tip, 
+        System.Action cbYes, System.Action cbNo, System.Action cbAutoCancel
+    ) {
         GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Popups/PKInviteNotice"));
         Transform item = o.transform.Find("Item");
         RectTransform itemRTF = item.GetComponent<RectTransform>();
@@ -87,11 +90,12 @@ public class PopupMgr : MonoBehaviour
         item.Find("BtnYes").GetComponent<Button>().onClick.AddListener(() => {
             AudioMgr.ins.PlayBtn();
             Destroy(o);
-            if (cb != null) cb();
+            if (cbYes != null) cbYes();
         });
         item.Find("BtnNo").GetComponent<Button>().onClick.AddListener(() => {
             AudioMgr.ins.PlayBtn();
             Destroy(o);
+            if (cbNo != null) cbNo();
         });
         Sequence seq = DOTween.Sequence();
         seq.Append(itemRTF.DOLocalMoveX(itemRTF.localPosition.x + itemRTF.sizeDelta.x, 0.6f));
@@ -99,6 +103,7 @@ public class PopupMgr : MonoBehaviour
         seq.AppendCallback(() => {
             if (o) {
                 Destroy(o);
+                if (cbAutoCancel != null) cbAutoCancel();
             }
         });
         seq.SetUpdate(true);

+ 25 - 6
Assets/BowArrow/Scripts/Network/SocketComp/PKComp.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using UnityEngine;
 
 
 public class PKComp : Singleton<PKComp>
@@ -12,9 +13,9 @@ public class PKComp : Singleton<PKComp>
         UserPlayer.ins.call("pkComp.cancelRandomMatch", LoginMgr.myUserInfo.id);
     }
 
-    public void inviteFriendGamePK(int targetID) {
+    public void inviteFriendGamePK(int targetID, string inviterViewUUID) {
         MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
-        UserPlayer.ins.call("pkComp.inviteFriendGamePK", playerInfo, GlobalData.matchGameType, targetID);
+        UserPlayer.ins.call("pkComp.inviteFriendGamePK", playerInfo, GlobalData.matchGameType, targetID, inviterViewUUID);
     }
 
     public void acceptFriendGamePK(string roomKey) {
@@ -22,12 +23,16 @@ public class PKComp : Singleton<PKComp>
         UserPlayer.ins.call("pkComp.acceptFriendGamePK", playerInfo, roomKey);
     }
 
-    public void inviteOtherTryAgainGamePK() {
+    public void inviteOtherTryAgainGamePK(string inviterViewUUID) {
         //get other info
         int otherIndex = (GlobalData.playerIndexInRoom + 1) % 2;
         MatchPlayerInfo ohterInfo = GlobalData.matchPlayerInfos[otherIndex];
         MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
-        UserPlayer.ins.call("pkComp.inviteOtherTryAgainGamePK", playerInfo, GlobalData.matchGameType, ohterInfo.playerID);
+        UserPlayer.ins.call("pkComp.inviteOtherTryAgainGamePK", playerInfo, GlobalData.matchGameType, ohterInfo.playerID, inviterViewUUID);
+    }
+
+    public void rejectPKInvite(string roomKey) {
+        UserPlayer.ins.call("pkComp.rejectPKInvite", roomKey);
     }
 
     public void acceptOtherTryAgainGamePK(string roomKey) {
@@ -65,8 +70,11 @@ public class PKComp : Singleton<PKComp>
                 PopupMgr.ins.ShowTip("当前正处于匹配状态,无法接受好友PK邀请!");
             }
         };
+        System.Action cbCancel = delegate() {
+            rejectPKInvite(roomKey);
+        };
         if (CanShowFriendInviteOrMatch()) {
-            PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb);
+            PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb, cbCancel, cbCancel);
         }
     }
     public void onInviteOtherTryAgainGamePK(MatchPlayerInfo matchPlayerInfo, int gameType, string roomKey) {
@@ -84,11 +92,22 @@ public class PKComp : Singleton<PKComp>
                 PopupMgr.ins.ShowTip("目前状态下,无法接受该邀请!");
             }
         };
+        System.Action cbCancel = delegate() {
+            rejectPKInvite(roomKey);
+        };
         if (CanShowTryAgainInviteOrMatch(matchPlayerInfo)) {
-            PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb);
+            PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb, cbCancel, cbCancel);
         }
     }
 
+    public void onRejectPKInvite(string inviterViewUUID) {
+        PopupMgr.ins.ShowTip("对方拒绝了你的邀请");
+        PKMatchingView view = PKMatchingView.ins;
+        if (!view) return;
+        if (view.viewUUID != inviterViewUUID) return;
+        view.eventOnRejectPKInvite?.Invoke();
+    }
+
     //内部方法
     private string GetPKTypeName(int gameType) {
         string pkTypeName = null;

+ 6 - 2
Assets/BowArrow/Scripts/View/PKMatchingView.cs

@@ -11,6 +11,8 @@ public class PKMatchingView : MonoBehaviour
 
     float waitingTime = 0;
 
+    //viewUUID
+    [NonSerialized] public string viewUUID = System.Guid.NewGuid().ToString(); 
     //邀请者需要输入的信息-好友PK
     [NonSerialized] public int targetInvitePlayerID;
     [NonSerialized] public bool isFriendPKInviter;
@@ -64,11 +66,11 @@ public class PKMatchingView : MonoBehaviour
         }
         
         if (isFriendPKInviter) {
-            PKComp.ins.inviteFriendGamePK(targetInvitePlayerID);
+            PKComp.ins.inviteFriendGamePK(targetInvitePlayerID, viewUUID);
         } else if (isFriendPKInvitee) {
             PKComp.ins.acceptFriendGamePK(targetJoinRoomKey);
         } else if (isTryAgainInviter) {
-            PKComp.ins.inviteOtherTryAgainGamePK();
+            PKComp.ins.inviteOtherTryAgainGamePK(viewUUID);
         } else if (isTryAgainInvitee) {
             PKComp.ins.acceptOtherTryAgainGamePK(targetJoinTryAgainRoomKey);
         } else {
@@ -133,4 +135,6 @@ public class PKMatchingView : MonoBehaviour
         AudioMgr.ins.PlayBtn();
         Destroy(this.gameObject);
     }
+
+    [NonSerialized] public System.Action eventOnRejectPKInvite;
 }