Skip to content

Commit

Permalink
Add MainMenuUI to client
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Oct 14, 2024
1 parent 26d2776 commit a3c2d35
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 42 deletions.
Binary file added Fika.Core/Bundles/Files/mainmenuui.bundle
Binary file not shown.
4 changes: 3 additions & 1 deletion Fika.Core/Fika.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

<ItemGroup>
<!-- hide files in vs2022 -->
<None Remove="Bundles\Files\mainmenuui.bundle" />
<None Remove="Bundles\Files\newmatchmakerui.bundle" />
<None Remove="Bundles\Files\playerui.bundle" />
<None Remove="Bundles\Files\ping.bundle" />
<None Remove="Bundles\Files\senditemmenu.bundle" />
</ItemGroup>

<ItemGroup>
<!-- embedded resources -->
<EmbeddedResource Include="Bundles\Files\mainmenuui.bundle" />
<EmbeddedResource Include="Bundles\Files\newmatchmakerui.bundle" />
<EmbeddedResource Include="Bundles\Files\playerui.bundle" />
<None Remove="Bundles\Files\ping.bundle" />
<EmbeddedResource Include="Bundles\Files\ping.bundle" />
<EmbeddedResource Include="Bundles\Files\senditemmenu.bundle" />
</ItemGroup>
Expand Down
66 changes: 35 additions & 31 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,41 @@ protected void Awake()

GetNatPunchServerConfig();
SetupConfig();
EnableFikaPatches();
gameObject.AddComponent<MainThreadDispatcher>();

#if GOLDMASTER
new TOS_Patch().Enable();
#endif
OfficialVersion.SettingChanged += OfficialVersion_SettingChanged;

DisableSPTPatches();
EnableOverridePatches();

GetClientConfig();

string fikaVersion = Assembly.GetAssembly(typeof(FikaPlugin)).GetName().Version.ToString();

Logger.LogInfo($"Fika is loaded! Running version: " + fikaVersion);

BundleLoaderPlugin = new();
BundleLoaderPlugin.Create();

BotSettingsRepoAbstractClass.Init();

BotDifficulties = FikaRequestHandler.GetBotDifficulties();
ConsoleScreen.Processor.RegisterCommandGroup<FikaCommands>();

if (AllowItemSending)
{
new ItemContext_Patch().Enable();
}

StartCoroutine(RunChecks());
}

private static void EnableFikaPatches()
{
new FikaVersionLabel_Patch().Enable();
new TarkovApplication_method_18_Patch().Enable();
new DisableReadyButton_Patch().Enable();
Expand Down Expand Up @@ -283,42 +317,12 @@ protected void Awake()
new SessionResultExitStatus_Show_Patch().Enable();
new PlayUISound_Patch().Enable();
new PlayEndGameSound_Patch().Enable();
new MenuScreen_Awake_Patch().Enable();

#if DEBUG
TasksExtensions_HandleFinishedTask_Patches.Enable();
new GClass1615_method_0_Patch().Enable();
#endif

gameObject.AddComponent<MainThreadDispatcher>();

#if GOLDMASTER
new TOS_Patch().Enable();
#endif
OfficialVersion.SettingChanged += OfficialVersion_SettingChanged;

DisableSPTPatches();
EnableOverridePatches();

GetClientConfig();

string fikaVersion = Assembly.GetAssembly(typeof(FikaPlugin)).GetName().Version.ToString();

Logger.LogInfo($"Fika is loaded! Running version: " + fikaVersion);

BundleLoaderPlugin = new();
BundleLoaderPlugin.Create();

BotSettingsRepoAbstractClass.Init();

BotDifficulties = FikaRequestHandler.GetBotDifficulties();
ConsoleScreen.Processor.RegisterCommandGroup<FikaCommands>();

if (AllowItemSending)
{
new ItemContext_Patch().Enable();
}

StartCoroutine(RunChecks());
}

private void VerifyServerVersion()
Expand Down
5 changes: 5 additions & 0 deletions Fika.Core/Networking/Http/FikaRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,10 @@ public static CheckVersionResponse CheckServerVersion()
{
return GetJson<CheckVersionResponse>("/fika/client/check/version");
}

public static FikaPlayerPresence[] GetPlayerPresences()
{
return GetJson<FikaPlayerPresence[]>("/fika/presence/get");
}
}
}
45 changes: 45 additions & 0 deletions Fika.Core/Networking/Models/FikaPlayerPresenceResponse.cs
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;
}
}
}
18 changes: 18 additions & 0 deletions Fika.Core/UI/Custom/MainMenuUI.cs
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}";
}
}
19 changes: 19 additions & 0 deletions Fika.Core/UI/Custom/MainMenuUIPlayer.cs
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";
}
}
111 changes: 111 additions & 0 deletions Fika.Core/UI/Custom/MainMenuUIScript.cs
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);
}
}
}
}
12 changes: 2 additions & 10 deletions Fika.Core/UI/Custom/MatchMakerUIScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static Fika.Core.UI.FikaUIUtils;

namespace Fika.Core.UI.Custom
{
Expand Down Expand Up @@ -730,16 +731,7 @@ private void RefreshUI()
break;
}
}
}

public class TooltipTextGetter
{
public string GetText()
{
return TooltipText;
}
public string TooltipText;
}
}

public IEnumerator ServerQuery()
{
Expand Down
9 changes: 9 additions & 0 deletions Fika.Core/UI/FikaUIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,14 @@ public static GClass3388 ShowFikaMessage(this ErrorScreen errorScreen, string ti
}
return errorScreenHandler.context;
}

public class TooltipTextGetter
{
public string GetText()
{
return TooltipText;
}
public string TooltipText;
}
}
}
21 changes: 21 additions & 0 deletions Fika.Core/UI/Patches/MenuScreen_Awake_Patch.cs
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>();
}
}
}

0 comments on commit a3c2d35

Please sign in to comment.