-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
268 additions
and
42 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using EFT; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fika.Core.Networking.Http | ||
{ | ||
[DataContract] | ||
public struct FikaPlayerPresence | ||
{ | ||
[DataMember(Name = "nickname")] | ||
public string Nickname; | ||
|
||
[DataMember(Name = "level")] | ||
public int Level; | ||
|
||
[DataMember(Name = "inRaid")] | ||
public bool InRaid; | ||
|
||
[DataMember(Name = "raidInformation")] | ||
public RaidInformation RaidInformation; | ||
|
||
public FikaPlayerPresence(string nickname, int level, bool inRaid, RaidInformation raidInformation) | ||
{ | ||
Nickname = nickname; | ||
Level = level; | ||
InRaid = inRaid; | ||
RaidInformation = raidInformation; | ||
} | ||
} | ||
|
||
[DataContract] | ||
public struct RaidInformation | ||
{ | ||
[DataMember(Name = "location")] | ||
public string Location; | ||
|
||
[DataMember(Name = "side")] | ||
public ESideType Side; | ||
|
||
public RaidInformation(string location, ESideType side) | ||
{ | ||
Location = location; | ||
Side = side; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class MainMenuUI : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
public Button RefreshButton; | ||
[SerializeField] | ||
public TextMeshProUGUI Label; | ||
[SerializeField] | ||
public GameObject PlayerTemplate; | ||
|
||
public void UpdateLabel(int amount) | ||
{ | ||
Label.text = $"ONLINE PLAYERS: {amount}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using TMPro; | ||
using UnityEngine; | ||
|
||
public class MainMenuUIPlayer : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
public TextMeshProUGUI PlayerName; | ||
[SerializeField] | ||
public TextMeshProUGUI PlayerLevel; | ||
[SerializeField] | ||
public TextMeshProUGUI PlayerStatus; | ||
|
||
public void SetStatus(string name, int level, bool inRaid) | ||
{ | ||
PlayerName.text = name; | ||
PlayerLevel.text = $"({level})"; | ||
PlayerStatus.text = inRaid ? "In Raid" : "In Menu"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Comfort.Common; | ||
using EFT.UI; | ||
using Fika.Core.Bundles; | ||
using Fika.Core.Networking.Http; | ||
using Fika.Core.Utils; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using static Fika.Core.UI.FikaUIUtils; | ||
|
||
namespace Fika.Core.UI.Custom | ||
{ | ||
public class MainMenuUIScript : MonoBehaviour | ||
{ | ||
private Coroutine queryRoutine; | ||
private MainMenuUI mainMenuUI; | ||
private GameObject playerTemplate; | ||
private List<GameObject> players; | ||
private DateTime lastRefresh; | ||
|
||
private void Start() | ||
{ | ||
players = []; | ||
lastRefresh = DateTime.Now; | ||
CreateMainMenuUI(); | ||
} | ||
|
||
private void OnEnable() | ||
{ | ||
queryRoutine = StartCoroutine(QueryPlayers()); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
if (queryRoutine != null) | ||
{ | ||
StopCoroutine(queryRoutine); | ||
} | ||
} | ||
|
||
private void CreateMainMenuUI() | ||
{ | ||
GameObject mainMenuUIPrefab = InternalBundleLoader.Instance.GetAssetBundle("mainmenuui").LoadAsset<GameObject>("MainMenuUI"); | ||
GameObject mainMenuUI = GameObject.Instantiate(mainMenuUIPrefab); | ||
this.mainMenuUI = mainMenuUI.GetComponent<MainMenuUI>(); | ||
playerTemplate = this.mainMenuUI.PlayerTemplate; | ||
playerTemplate.SetActive(false); | ||
Transform newParent = Singleton<CommonUI>.Instance.MenuScreen.gameObject.transform; | ||
mainMenuUI.transform.SetParent(newParent); | ||
gameObject.transform.SetParent(newParent); | ||
|
||
this.mainMenuUI.RefreshButton.onClick.AddListener(ManualRefresh); | ||
} | ||
|
||
private void ManualRefresh() | ||
{ | ||
if ((DateTime.Now - lastRefresh).TotalSeconds >= 5) | ||
{ | ||
lastRefresh = DateTime.Now; | ||
ClearAndQueryPlayers(); | ||
} | ||
} | ||
|
||
private IEnumerator QueryPlayers() | ||
{ | ||
while (true) | ||
{ | ||
yield return new WaitForSeconds(1); | ||
ClearAndQueryPlayers(); | ||
yield return new WaitForSeconds(10); | ||
} | ||
} | ||
|
||
private void ClearAndQueryPlayers() | ||
{ | ||
foreach (GameObject item in players) | ||
{ | ||
GameObject.Destroy(item); | ||
} | ||
players.Clear(); | ||
|
||
FikaPlayerPresence[] response = FikaRequestHandler.GetPlayerPresences(); | ||
mainMenuUI.UpdateLabel(response.Length); | ||
SetupPlayers(ref response); | ||
} | ||
|
||
private void SetupPlayers(ref FikaPlayerPresence[] responses) | ||
{ | ||
foreach (FikaPlayerPresence presence in responses) | ||
{ | ||
GameObject newPlayer = GameObject.Instantiate(playerTemplate, playerTemplate.transform.parent); | ||
MainMenuUIPlayer mainMenuUIPlayer = newPlayer.GetComponent<MainMenuUIPlayer>(); | ||
mainMenuUIPlayer.SetStatus(presence.Nickname, presence.Level, presence.InRaid); | ||
if (presence.InRaid) | ||
{ | ||
string side = presence.RaidInformation.Side == EFT.ESideType.Pmc ? "PMC" : "Scav"; | ||
TooltipTextGetter tooltipTextGetter = new() | ||
{ | ||
TooltipText = $"Playing as a {side} on {ColorUtils.ColorizeText(Colors.BLUE, presence.RaidInformation.Location.Localized())}" | ||
}; | ||
HoverTooltipArea tooltip = newPlayer.AddComponent<HoverTooltipArea>(); | ||
tooltip.enabled = true; | ||
tooltip.SetMessageText(tooltipTextGetter.GetText); | ||
} | ||
newPlayer.SetActive(true); | ||
players.Add(newPlayer); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using EFT.UI; | ||
using Fika.Core.UI.Custom; | ||
using SPT.Reflection.Patching; | ||
using System.Reflection; | ||
|
||
namespace Fika.Core.UI.Patches | ||
{ | ||
public class MenuScreen_Awake_Patch : ModulePatch | ||
{ | ||
protected override MethodBase GetTargetMethod() | ||
{ | ||
return typeof(MenuScreen).GetMethod(nameof(MenuScreen.Awake)); | ||
} | ||
|
||
[PatchPostfix] | ||
public static void Postfix(MenuScreen __instance) | ||
{ | ||
__instance.gameObject.AddComponent<MainMenuUIScript>(); | ||
} | ||
} | ||
} |