Skip to content

Commit

Permalink
Continuing to update server browser
Browse files Browse the repository at this point in the history
  • Loading branch information
morm075 committed Jun 16, 2024
1 parent a6ab704 commit a4c8453
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 111 deletions.
25 changes: 25 additions & 0 deletions Multiplayer/Components/MainMenu/IServerBrowserGameDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using Newtonsoft.Json.Linq;
using UnityEngine;

namespace Multiplayer.Components.MainMenu
{
//
public interface IServerBrowserGameDetails : IDisposable
{
//
//
int ServerID { get; }

//
//
//
string Name { get; set; }

}
}
54 changes: 48 additions & 6 deletions Multiplayer/Components/MainMenu/MultiplayerPane.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Net;
using System.Text.RegularExpressions;
using DV.Common;
using DV.Localization;
using DV.UI;
using DV.UIFramework;
using DV.Util;
using DV.Utils;
using Multiplayer.Components.MainMenu;
using Multiplayer;
using Multiplayer.Components.Networking;
using Multiplayer.Patches.MainMenu;
using Multiplayer.Utils;
using TMPro;
using UnityEngine;
Expand All @@ -24,12 +22,16 @@ public class MultiplayerPane : MonoBehaviour

private string ipAddress;
private ushort portNumber;
private ButtonDV directButton;
//private ButtonDV directButton;

private ObservableCollectionExt<IServerBrowserGameDetails> gridViewModel = new ObservableCollectionExt<IServerBrowserGameDetails>();
private ServerBrowserGridView gridView;

private void Awake()
{
Multiplayer.Log("MultiplayerPane Awake()");
SetupMultiplayerButtons();
SetupServerBrowser();
}

private void SetupMultiplayerButtons()
Expand Down Expand Up @@ -75,8 +77,41 @@ private void SetupMultiplayerButtons()
//buttonRefresh.SetActive(true);
}

private void SetupServerBrowser()
{
/*GameObject.Destroy(this.FindChildByName("GRID VIEW"));
GameObject Viewport = GameObject.Find("Viewport");
GameObject serverBrowserGridView = new GameObject("GRID VIEW", typeof (ServerBrowserGridView));
serverBrowserGridView.transform.SetParent(Viewport.transform);
gridView = serverBrowserGridView.GetComponent<ServerBrowserGridView>();
Debug.Log("found Grid View");
RectTransform rt = serverBrowserGridView.GetComponent<RectTransform>();
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 5292);
rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 662);
*/
GameObject GridviewGO = this.FindChildByName("GRID VIEW");
SaveLoadGridView slgv = GridviewGO.GetComponent<SaveLoadGridView>();
GridviewGO.SetActive(false);

gridView = GridviewGO.AddComponent<ServerBrowserGridView>();
gridView.dummyElementPrefab = Instantiate(slgv.viewElementPrefab);
gridView.dummyElementPrefab.name = "prefabServerBrowser";
GameObject.Destroy(slgv);
GridviewGO.SetActive(true);


//gridView.dummyElementPrefab = null;
//gridViewModel.Add();



}

private GameObject FindButton(string name)
{

return GameObject.Find(name);
}

Expand Down Expand Up @@ -178,7 +213,7 @@ private void ShowPasswordPopup()
{
if (result.closedBy == PopupClosedByAction.Abortion) return;

directButton.enabled = false;
//directButton.enabled = false;
SingletonBehaviour<NetworkLifecycle>.Instance.StartClient(ipAddress, portNumber, result.data);

Multiplayer.Settings.LastRemoteIP = ipAddress;
Expand Down Expand Up @@ -237,6 +272,13 @@ private void HostAction()
// Implement host action logic here
Debug.Log("Host button clicked.");
// Add your code to handle hosting a game
gridView.showDummyElement = true;
gridViewModel.Clear();
//gridView.dummyElementPrefab = ;

Debug.Log($"gridViewPrefab exists : {gridView.dummyElementPrefab != null} showDummyElement : {gridView.showDummyElement}");
gridView.SetModel(gridViewModel);

}

private void JoinAction()
Expand Down
56 changes: 56 additions & 0 deletions Multiplayer/Components/MainMenu/ServerBrowserElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using DV.Common;
using DV.Localization;
using DV.UIFramework;
using Multiplayer.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;

namespace Multiplayer.Components.MainMenu;


//
public class ServerBrowserElement : AViewElement<IServerBrowserGameDetails>
{
private TextMeshProUGUI networkName;
private TextMeshProUGUI playerCount;
private TextMeshProUGUI ping;
private IServerBrowserGameDetails data;

private void Awake()
{
//Find existing fields to duplicate
networkName = this.FindChildByName("name [noloc]").GetComponent<TextMeshProUGUI>();
playerCount = this.FindChildByName("date [noloc]").GetComponent<TextMeshProUGUI>();
ping = this.FindChildByName("time [noloc]").GetComponent<TextMeshProUGUI>();

networkName.text = "Test Network";
playerCount.text = "1/4";
ping.text = "102";
}

public override void SetData(IServerBrowserGameDetails data, AGridView<IServerBrowserGameDetails> _)
{
if (this.data != null)
{
this.data = null;
}
if (data != null)
{
this.data = data;
}
UpdateView(null, null);
}

//
private void UpdateView(object sender = null, PropertyChangedEventArgs e = null)
{
networkName.text = data.Name;
}

}
32 changes: 32 additions & 0 deletions Multiplayer/Components/MainMenu/ServerBrowserGridView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DV.Common;
using DV.UI;
using DV.UIFramework;
using UnityEngine;
using UnityEngine.UI;

namespace Multiplayer.Components.MainMenu
{
[RequireComponent(typeof(ContentSizeFitter))]
[RequireComponent(typeof(VerticalLayoutGroup))]
//
public class ServerBrowserGridView : AGridView<IServerBrowserGameDetails>
{

private void Awake()
{
Debug.Log("serverBrowserGridview Awake");
this.dummyElementPrefab.SetActive(false);
GameObject.Destroy(this.dummyElementPrefab.GetComponent<SaveLoadViewElement>());
this.dummyElementPrefab.AddComponent<ServerBrowserElement>();

this.dummyElementPrefab.SetActive(true);
// GameObject defaultPrefab = GameObject.Find("SaveLoadViewElement");
// this.dummyElementPrefab = Instantiate(defaultPrefab);
}
}
}
1 change: 1 addition & 0 deletions Multiplayer/Multiplayer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using HarmonyLib;
using JetBrains.Annotations;
Expand Down
6 changes: 1 addition & 5 deletions Multiplayer/Multiplayer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -78,10 +78,6 @@
<Reference Include="UnityEngine.PhysicsModule" />
<Reference Include="UnityEngine.UI" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Patches\World\WorldStreamingInitPatch.cs" />
<Compile Remove="Utils\Csvnew.cs" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- Copy to build folder -->
Expand Down
12 changes: 6 additions & 6 deletions Multiplayer/Patches/MainMenu/RightPaneControllerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private static void Prefix(RightPaneController __instance)

// Find the base pane for Load/Save
GameObject basePane = __instance.FindChildByName("PaneRight Load/Save");
//GameObject basePane = __instance.FindChildByName("PaneRight Launcher");
if (basePane == null)
{
Multiplayer.LogError("Failed to find Launcher pane!");
Expand All @@ -39,19 +40,18 @@ private static void Prefix(RightPaneController __instance)

multiplayerPane.name = "PaneRight Multiplayer";

multiplayerPane.AddComponent<MultiplayerPane>();
//multiplayerPane.AddComponent<MultiplayerPane>();

__instance.menuController.controlledMenus.Add(multiplayerPane.GetComponent<UIMenu>());
MainMenuController_Awake_Patch.multiplayerButton.GetComponent<UIMenuRequester>().requestedMenuIndex = __instance.menuController.controlledMenus.Count - 1;

Multiplayer.LogError("before Past Destroyed stuff!");
// Clean up unnecessary components and child objects
GameObject.Destroy(multiplayerPane.GetComponent<SaveLoadController>());
GameObject.Destroy(multiplayerPane.GetComponent<SettingsController>());
GameObject.Destroy(multiplayerPane.GetComponent<PlatformSpecificElements>());
GameObject.Destroy(multiplayerPane.FindChildByName("ButtonIcon OpenFolder"));
GameObject.Destroy(multiplayerPane.FindChildByName("ButtonIcon Rename"));
GameObject.Destroy(multiplayerPane.FindChildByName("Text Content"));

Multiplayer.LogError("Past Destroyed stuff!");

// Update UI elements
GameObject titleObj = multiplayerPane.FindChildByName("Title");
Expand All @@ -68,7 +68,7 @@ private static void Prefix(RightPaneController __instance)
UpdateButton(multiplayerPane, "ButtonTextIcon Load", "ButtonTextIcon Host", Locale.SERVER_BROWSER__HOST_KEY, null, Multiplayer.AssetIndex.multiplayerIcon);
UpdateButton(multiplayerPane, "ButtonTextIcon Save", "ButtonTextIcon Join", Locale.SERVER_BROWSER__JOIN_KEY, null, null);
UpdateButton(multiplayerPane, "ButtonIcon Delete", "ButtonTextIcon Refresh", Locale.SERVER_BROWSER__REFRESH, null, null);

multiplayerPane.AddComponent<MultiplayerPane>();

MainMenuThingsAndStuff.Create(manager =>
Expand All @@ -82,7 +82,7 @@ private static void Prefix(RightPaneController __instance)
});

MainMenuController_Awake_Patch.multiplayerButton.SetActive(true);

Multiplayer.LogError("At end!");
}

private static void UpdateButton(GameObject pane, string oldButtonName, string newButtonName, string localeKey, string toolTipKey, Sprite icon)
Expand Down
94 changes: 0 additions & 94 deletions Multiplayer/Utils/Csvnew.cs

This file was deleted.

0 comments on commit a4c8453

Please sign in to comment.