read1
This commit is contained in:
@@ -24,7 +24,11 @@ public class FriendsManager : MonoBehaviour
|
||||
[SerializeField]private TMP_InputField AddFriendUsernameInput;
|
||||
[SerializeField]private TMP_Text AddFriendErrorTxt;
|
||||
[SerializeField]private Button AddFriendBtn;
|
||||
|
||||
|
||||
public static FriendsManager instance;
|
||||
void Awake(){
|
||||
instance = this;
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
|
||||
AddFriendBtn.onClick.AddListener(AddFriend);
|
||||
@@ -54,8 +58,12 @@ public class FriendsManager : MonoBehaviour
|
||||
}
|
||||
|
||||
StartCoroutine(CoroutineAddFriend(AddFriendUsernameInput.text));
|
||||
AddFriendUsernameInput.text = "";
|
||||
}
|
||||
|
||||
public void OnPlayersChanged(){
|
||||
PopulateFriendList();
|
||||
}
|
||||
|
||||
void PopulateFriendList(){
|
||||
foreach(Photon.Realtime.Player player in PhotonNetwork.PlayerList){
|
||||
@@ -92,6 +100,9 @@ public class FriendsManager : MonoBehaviour
|
||||
|
||||
newFriendListItem.transform.GetChild(1).gameObject.SetActive(isOnline);
|
||||
newFriendListItem.transform.GetChild(1).GetComponent<Button>().onClick.AddListener(()=>{StartCoroutine(CoroutineInviteFriend(fid));});
|
||||
|
||||
newFriendListItem.transform.GetChild(1).GetComponent<Button>().interactable = PhotonNetwork.CurrentRoom.PlayerCount < 3;
|
||||
|
||||
newFriendListItem.transform.GetChild(2).gameObject.SetActive(!isOnline);
|
||||
newFriendListItem.transform.GetChild(2).GetComponent<TMP_Text>().text = "Last seen " + (last_seen_diff.Hours <=0 ? $"{(last_seen_diff.Minutes == 0 ? 1 : last_seen_diff.Minutes)} Mins" : $"{last_seen_diff.Hours} hours") + " Ago";
|
||||
}
|
||||
@@ -107,11 +118,25 @@ public class FriendsManager : MonoBehaviour
|
||||
|
||||
WWW req= new(UserDataManager.GetApiUrl("friend_request"), form);
|
||||
yield return req;
|
||||
AddFriendErrorTxt.text =req.text;
|
||||
string pureq = req.text.Replace(" ", "");
|
||||
if(pureq == "0" || pureq == "1"){
|
||||
//Success
|
||||
AddFriendPanel.SetActive(false);
|
||||
mainPanel.SetActive(true);
|
||||
}else if(pureq == "7"){
|
||||
AddFriendErrorTxt.text ="Invalid username";
|
||||
}else if(pureq == "5"){
|
||||
AddFriendErrorTxt.text ="You guys are already friends!";
|
||||
}else if(pureq == "4"){
|
||||
AddFriendErrorTxt.text ="You've already sent a friend request to this user";
|
||||
}else{
|
||||
AddFriendErrorTxt.text ="Something went wrong";
|
||||
}
|
||||
|
||||
if(req.text.Length <=0){
|
||||
AddFriendErrorTxt.text ="Server 500";
|
||||
}
|
||||
|
||||
canvasGroup.interactable = true;
|
||||
}
|
||||
|
||||
@@ -121,6 +146,7 @@ public class FriendsManager : MonoBehaviour
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("uid", UserDataManager.instance.UserID);
|
||||
form.AddField("fid", fid);
|
||||
form.AddField("lobby", PhotonNetwork.CurrentRoom.Name);
|
||||
Debug.Log("inviting " + fid + " to this session");
|
||||
WWW req = new WWW(UserDataManager.GetApiUrl("invite_lobby"),form);
|
||||
yield return req;
|
||||
|
||||
@@ -288,7 +288,7 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
|
||||
|
||||
|
||||
localPlayer = PhotonNetwork.Instantiate("Player", GetRandomSpawnPoint().position, Quaternion.identity).GetComponentInChildren<PlayerController>();
|
||||
localPlayer = PhotonNetwork.Instantiate("Player", SpawnPositions[customPlayerId].position, Quaternion.identity).GetComponentInChildren<PlayerController>();
|
||||
// localPlayer.GetComponent<PlayerNetwork>().SetPartyName(partyName,partyId);
|
||||
UIManager.instance.RoundLength = DeathmatchRoundLength;
|
||||
localPlayer.GetComponent<PlayerNetwork>().AutoAssignParty();
|
||||
@@ -365,7 +365,7 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
StartCoroutine(HideRoomIn((float)DeathmatchRoundLength /2f));
|
||||
}
|
||||
InventoryManager.ResetStocks();
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString() || desiredGameMode == GameModes.TeamDeathmatch.ToString()){
|
||||
InventoryManager.instance.GiveDefaultLoots(DeathmatchDefaultInventory);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,9 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
}
|
||||
|
||||
IEnumerator HideRoomIn(float length){
|
||||
yield return new WaitForSeconds(length);
|
||||
yield return new WaitForSeconds(length);
|
||||
|
||||
Debug.Log("Hiding this room");
|
||||
|
||||
PhotonNetwork.CurrentRoom.IsOpen = false;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
base.OnJoinedRoom();
|
||||
|
||||
Debug.Log("Connected to new room : " + PhotonNetwork.CurrentRoom.Name);
|
||||
if(PhotonNetwork.CurrentRoom.PlayerCount >3 ){
|
||||
Debug.Log("NO room for me!");
|
||||
JoinAnotherRoom(myRoomname);
|
||||
}
|
||||
loadingPanel.SetActive(false);
|
||||
|
||||
UpdateLobbyPlayers();
|
||||
@@ -136,10 +140,10 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
if(val.ToLower()== "tdm"){gameMode = GameModes.TeamDeathmatch;}
|
||||
if(val.ToLower() == "br"){gameMode = GameModes.BattleRoyale;}
|
||||
|
||||
btnPlay.interactable = gameMode != GameModes.BattleRoyale;
|
||||
|
||||
Debug.Log("Set game mode to : " + gameMode.ToString() + $" ({val})");
|
||||
GameManager.desiredGameMode = gameMode.ToString();
|
||||
UpdatePlayBtnInteractability();
|
||||
}
|
||||
|
||||
void OnInvitesUpdated(){
|
||||
@@ -154,7 +158,7 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
GameObject newInviteItem = Instantiate(InviteListItemPrefab, InviteListParent);
|
||||
newInviteItem.transform.GetChild(0).GetComponent<TMP_Text>().text = $"Lobby Invite from <color=green>{invite.host}";
|
||||
|
||||
newInviteItem.transform.GetChild(1).GetComponent<Button>().onClick.AddListener(()=>{ JoinFriendsLobby(invite.host, invite.host_id,invite.id); });
|
||||
newInviteItem.transform.GetChild(1).GetComponent<Button>().onClick.AddListener(()=>{ JoinFriendsLobby(invite.host, invite.lobby,invite.id); });
|
||||
newInviteItem.transform.GetChild(2).GetComponent<Button>().onClick.AddListener(()=>{ StartCoroutine(CoroutineDeleteInvite(invite.id)); });
|
||||
}
|
||||
}
|
||||
@@ -172,12 +176,10 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
|
||||
|
||||
|
||||
void JoinFriendsLobby(string hostname, int hostid, int inviteid){
|
||||
void JoinFriendsLobby(string hostname, string lobby, int inviteid){
|
||||
StartCoroutine(CoroutineDeleteInvite(inviteid));
|
||||
|
||||
string roomName = hostname+"#"+hostid;
|
||||
|
||||
JoinAnotherRoom(roomName);
|
||||
JoinAnotherRoom(lobby);
|
||||
}
|
||||
public void JoinAnotherRoom(string roomname){
|
||||
if(PhotonNetwork.InRoom){
|
||||
@@ -192,7 +194,7 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
void JoinQueuedRoom(){
|
||||
loadingPanel.SetActive(true);
|
||||
if(queuedRoomname.Length >0){
|
||||
PhotonNetwork.JoinOrCreateRoom(queuedRoomname, new RoomOptions(){IsOpen=true, IsVisible=true}, TypedLobby.Default);
|
||||
PhotonNetwork.JoinOrCreateRoom(queuedRoomname, new RoomOptions(){IsOpen=true, IsVisible=true, MaxPlayers = 8}, TypedLobby.Default);
|
||||
}
|
||||
|
||||
queuedRoomname="";
|
||||
@@ -234,8 +236,14 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
|
||||
//Uodate cotrols
|
||||
|
||||
btnPlay.interactable=PhotonNetwork.IsMasterClient;
|
||||
UpdatePlayBtnInteractability();
|
||||
GameModeSelector.SetInteractable(PhotonNetwork.IsMasterClient);
|
||||
|
||||
FriendsManager.instance.OnPlayersChanged();
|
||||
}
|
||||
|
||||
void UpdatePlayBtnInteractability(){
|
||||
btnPlay.interactable = PhotonNetwork.IsMasterClient && GameManager.desiredGameMode != GameModes.BattleRoyale.ToString();
|
||||
}
|
||||
|
||||
IEnumerator CoroutineDeleteInvite(int inviteId){
|
||||
@@ -316,6 +324,7 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
bool foundRoom =false;
|
||||
List<string> suitableRooms = new List<string>();
|
||||
foreach(RoomInfo room in RoomList){
|
||||
Debug.Log($"roomname : {room.Name}, players: {room.PlayerCount}" );
|
||||
if(room.Name.Contains(roomnameBase)){
|
||||
//Suitable Room
|
||||
suitableRooms.Add(room.Name);
|
||||
|
||||
@@ -79,13 +79,15 @@ public class UserDataManager : MonoBehaviour
|
||||
Invites = new List<Invite>();
|
||||
try{
|
||||
Invites = JsonConvert.DeserializeObject<List<Invite>>(response);
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
Debug.LogError("Couldn't parse invites");
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
|
||||
foreach(Invite invite in Invites){
|
||||
Debug.Log($"invite id {invite.id} is {DateTime.Now.Subtract(invite.time).TotalMinutes} old");
|
||||
}
|
||||
|
||||
OnInvitesUpdated.Invoke();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user