diff --git a/Multiplayer/Components/MainMenu/IServerBrowserGameDetails.cs b/Multiplayer/Components/MainMenu/IServerBrowserGameDetails.cs new file mode 100644 index 0000000..f199c7c --- /dev/null +++ b/Multiplayer/Components/MainMenu/IServerBrowserGameDetails.cs @@ -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; } + + } +} diff --git a/Multiplayer/Components/MainMenu/MultiplayerPane.cs b/Multiplayer/Components/MainMenu/MultiplayerPane.cs index a3d2f16..c75a9b4 100644 --- a/Multiplayer/Components/MainMenu/MultiplayerPane.cs +++ b/Multiplayer/Components/MainMenu/MultiplayerPane.cs @@ -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; @@ -24,12 +22,16 @@ public class MultiplayerPane : MonoBehaviour private string ipAddress; private ushort portNumber; - private ButtonDV directButton; + //private ButtonDV directButton; + + private ObservableCollectionExt gridViewModel = new ObservableCollectionExt(); + private ServerBrowserGridView gridView; private void Awake() { Multiplayer.Log("MultiplayerPane Awake()"); SetupMultiplayerButtons(); + SetupServerBrowser(); } private void SetupMultiplayerButtons() @@ -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(); + Debug.Log("found Grid View"); + + RectTransform rt = serverBrowserGridView.GetComponent(); + rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 5292); + rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 662); + */ + GameObject GridviewGO = this.FindChildByName("GRID VIEW"); + SaveLoadGridView slgv = GridviewGO.GetComponent(); + GridviewGO.SetActive(false); + + gridView = GridviewGO.AddComponent(); + 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); } @@ -178,7 +213,7 @@ private void ShowPasswordPopup() { if (result.closedBy == PopupClosedByAction.Abortion) return; - directButton.enabled = false; + //directButton.enabled = false; SingletonBehaviour.Instance.StartClient(ipAddress, portNumber, result.data); Multiplayer.Settings.LastRemoteIP = ipAddress; @@ -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() diff --git a/Multiplayer/Components/MainMenu/ServerBrowserElement.cs b/Multiplayer/Components/MainMenu/ServerBrowserElement.cs new file mode 100644 index 0000000..9aa7154 --- /dev/null +++ b/Multiplayer/Components/MainMenu/ServerBrowserElement.cs @@ -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 +{ + 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(); + playerCount = this.FindChildByName("date [noloc]").GetComponent(); + ping = this.FindChildByName("time [noloc]").GetComponent(); + + networkName.text = "Test Network"; + playerCount.text = "1/4"; + ping.text = "102"; + } + + public override void SetData(IServerBrowserGameDetails data, AGridView _) + { + 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; + } + +} diff --git a/Multiplayer/Components/MainMenu/ServerBrowserGridView.cs b/Multiplayer/Components/MainMenu/ServerBrowserGridView.cs new file mode 100644 index 0000000..ba61ae2 --- /dev/null +++ b/Multiplayer/Components/MainMenu/ServerBrowserGridView.cs @@ -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 + { + + private void Awake() + { + Debug.Log("serverBrowserGridview Awake"); + this.dummyElementPrefab.SetActive(false); + GameObject.Destroy(this.dummyElementPrefab.GetComponent()); + this.dummyElementPrefab.AddComponent(); + + this.dummyElementPrefab.SetActive(true); + // GameObject defaultPrefab = GameObject.Find("SaveLoadViewElement"); + // this.dummyElementPrefab = Instantiate(defaultPrefab); + } + } +} diff --git a/Multiplayer/Multiplayer.cs b/Multiplayer/Multiplayer.cs index 04af71f..cdbc6cb 100644 --- a/Multiplayer/Multiplayer.cs +++ b/Multiplayer/Multiplayer.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using HarmonyLib; using JetBrains.Annotations; diff --git a/Multiplayer/Multiplayer.csproj b/Multiplayer/Multiplayer.csproj index e9b86a6..42304b6 100644 --- a/Multiplayer/Multiplayer.csproj +++ b/Multiplayer/Multiplayer.csproj @@ -1,4 +1,4 @@ - + net48 latest @@ -78,10 +78,6 @@ - - - - diff --git a/Multiplayer/Patches/MainMenu/RightPaneControllerPatch.cs b/Multiplayer/Patches/MainMenu/RightPaneControllerPatch.cs index 7f27547..bf7d62f 100644 --- a/Multiplayer/Patches/MainMenu/RightPaneControllerPatch.cs +++ b/Multiplayer/Patches/MainMenu/RightPaneControllerPatch.cs @@ -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!"); @@ -39,19 +40,18 @@ private static void Prefix(RightPaneController __instance) multiplayerPane.name = "PaneRight Multiplayer"; - multiplayerPane.AddComponent(); + //multiplayerPane.AddComponent(); __instance.menuController.controlledMenus.Add(multiplayerPane.GetComponent()); MainMenuController_Awake_Patch.multiplayerButton.GetComponent().requestedMenuIndex = __instance.menuController.controlledMenus.Count - 1; - + Multiplayer.LogError("before Past Destroyed stuff!"); // Clean up unnecessary components and child objects GameObject.Destroy(multiplayerPane.GetComponent()); - GameObject.Destroy(multiplayerPane.GetComponent()); GameObject.Destroy(multiplayerPane.GetComponent()); 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"); @@ -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(); MainMenuThingsAndStuff.Create(manager => @@ -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) diff --git a/Multiplayer/Utils/Csvnew.cs b/Multiplayer/Utils/Csvnew.cs deleted file mode 100644 index ef66263..0000000 --- a/Multiplayer/Utils/Csvnew.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; - -namespace Multiplayer.Utils -{ - public static class Csv - { - public static ReadOnlyDictionary> Parse(string data) - { - var columns = new Dictionary>(); - var lines = data.Split('\n'); - - var keys = ParseLine(lines[0]); - foreach (var key in keys) - columns[key] = new Dictionary(); - - for (int i = 0; i < lines.Length; i++) - { - var values = ParseLine(lines[i]); - if (values.Count == 0 || string.IsNullOrWhiteSpace(values[0])) - continue; - - string key = values[0]; - for (int j = 0; j < values.Count; j++) - columns[keys[j]][key] = values[j]; - } - - return new ReadOnlyDictionary>(columns); - } - - private static List ParseLine(string line) - { - var values = new List(); - var builder = new StringBuilder(); - - bool inQuotes = false; - foreach (char c in line) - { - if (c == ',' && !inQuotes) - { - values.Add(builder.ToString()); - builder.Clear(); - } - else if (c == '"') - { - inQuotes = !inQuotes; - } - else - { - builder.Append(c); - } - } - - values.Add(builder.ToString()); - return values; - } - - public static string Dump(ReadOnlyDictionary> data) - { - var result = new StringBuilder(); - - foreach (var column in data) - result.Append($"{column.Key},"); - - result.Length--; - result.Append('\n'); - - int rowCount = data.Values.FirstOrDefault()?.Count ?? 0; - - for (int i = 0; i < rowCount; i++) - { - foreach (var column in data) - { - if (column.Value.Count > i) - { - string value = column.Value.ElementAt(i).Value.Replace("\n", "\\n"); - result.Append(value.Contains(',') ? $"\"{value}\"," : $"{value},"); - } - else - { - result.Append(','); - } - } - - result.Length--; - result.Append('\n'); - } - - return result.ToString(); - } - } -}