forked from Insprill/dv-multiplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed main menu highlight bug added random server generation for testing fixed gridview element layout implemented a server data object
- Loading branch information
Showing
16 changed files
with
937 additions
and
270 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Multiplayer/Components/MainMenu/IServerBrowserGameDetails.cs
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,29 @@ | ||
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; } | ||
int MaxPlayers { get; set; } | ||
int CurrentPlayers { get; set; } | ||
int Ping { get; set; } | ||
bool HasPassword { get; set; } | ||
|
||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
Multiplayer/Components/MainMenu/PopupTextInputFieldControllerNoValidation.cs
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,93 @@ | ||
using System; | ||
using System.Reflection; | ||
using DV.UIFramework; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
namespace Multiplayer.Components.MainMenu | ||
{ | ||
public class PopupTextInputFieldControllerNoValidation : MonoBehaviour, IPopupSubmitHandler | ||
{ | ||
public Popup popup; | ||
public TMP_InputField field; | ||
public ButtonDV confirmButton; | ||
|
||
private void Awake() | ||
{ | ||
// Find the components | ||
popup = this.GetComponentInParent<Popup>(); | ||
field = popup.GetComponentInChildren<TMP_InputField>(); | ||
|
||
foreach (ButtonDV btn in popup.GetComponentsInChildren<ButtonDV>()) | ||
{ | ||
if (btn.name == "ButtonYes") | ||
{ | ||
confirmButton = btn; | ||
} | ||
} | ||
|
||
// Set this instance as the new handler for the dialog | ||
typeof(Popup).GetField("handler", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(popup, this); | ||
} | ||
|
||
private void Start() | ||
{ | ||
// Add listener for input field value changes | ||
field.onValueChanged.AddListener(new UnityAction<string>(OnInputValueChanged)); | ||
OnInputValueChanged(field.text); | ||
field.Select(); | ||
field.ActivateInputField(); | ||
} | ||
|
||
private void OnInputValueChanged(string value) | ||
{ | ||
// Toggle confirm button interactability based on input validity | ||
confirmButton.ToggleInteractable(IsInputValid(value)); | ||
} | ||
|
||
public void HandleAction(PopupClosedByAction action) | ||
{ | ||
switch (action) | ||
{ | ||
case PopupClosedByAction.Positive: | ||
if (IsInputValid(field.text)) | ||
{ | ||
RequestPositive(); | ||
return; | ||
} | ||
break; | ||
case PopupClosedByAction.Negative: | ||
RequestNegative(); | ||
return; | ||
case PopupClosedByAction.Abortion: | ||
RequestAbortion(); | ||
return; | ||
default: | ||
Debug.LogError(string.Format("Unhandled action {0}", action), this); | ||
break; | ||
} | ||
} | ||
|
||
private bool IsInputValid(string value) | ||
{ | ||
// Always return true to disable validation | ||
return true; | ||
} | ||
|
||
private void RequestPositive() | ||
{ | ||
this.popup.RequestClose(PopupClosedByAction.Positive, this.field.text); | ||
} | ||
|
||
private void RequestNegative() | ||
{ | ||
this.popup.RequestClose(PopupClosedByAction.Negative, null); | ||
} | ||
|
||
private void RequestAbortion() | ||
{ | ||
this.popup.RequestClose(PopupClosedByAction.Abortion, null); | ||
} | ||
} | ||
} |
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,90 @@ | ||
using DV.UIFramework; | ||
using Multiplayer.Utils; | ||
using System.ComponentModel; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace Multiplayer.Components.MainMenu; | ||
|
||
|
||
// | ||
public class ServerBrowserElement : AViewElement<IServerBrowserGameDetails> | ||
{ | ||
private TextMeshProUGUI networkName; | ||
private TextMeshProUGUI playerCount; | ||
private TextMeshProUGUI ping; | ||
private GameObject goIcon; | ||
private Image icon; | ||
private IServerBrowserGameDetails data; | ||
|
||
private const int PING_WIDTH = 62 * 2; | ||
private const int PING_POS_X = 650; | ||
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>(); | ||
goIcon = this.FindChildByName("autosave icon"); | ||
icon = goIcon.GetComponent<Image>(); | ||
|
||
//Fix alignment | ||
Vector3 namePos = networkName.transform.position; | ||
Vector2 nameSize = networkName.rectTransform.sizeDelta; | ||
|
||
playerCount.transform.position = new Vector3(namePos.x + nameSize.x, namePos.y, namePos.z); | ||
|
||
|
||
Vector2 rowSize = this.transform.GetComponentInParent<RectTransform>().sizeDelta; | ||
Vector3 pingPos = ping.transform.position; | ||
Vector2 pingSize = ping.rectTransform.sizeDelta; | ||
|
||
|
||
ping.rectTransform.sizeDelta = new Vector2(PING_WIDTH, pingSize.y); | ||
pingSize = ping.rectTransform.sizeDelta; | ||
|
||
ping.transform.position = new Vector3(PING_POS_X, pingPos.y, pingPos.z); | ||
|
||
ping.alignment = TextAlignmentOptions.Right; | ||
|
||
|
||
//Update clock Icon | ||
icon.sprite = Sprites.Padlock; | ||
|
||
|
||
|
||
/* | ||
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; | ||
playerCount.text = $"{data.CurrentPlayers} / {data.MaxPlayers}"; | ||
ping.text = $"{data.Ping} ms"; | ||
|
||
if (!data.HasPassword) | ||
{ | ||
goIcon.SetActive(false); | ||
} | ||
} | ||
|
||
} |
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,36 @@ | ||
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); | ||
|
||
//swap controller | ||
GameObject.Destroy(this.dummyElementPrefab.GetComponent<SaveLoadViewElement>()); | ||
this.dummyElementPrefab.AddComponent<ServerBrowserElement>(); | ||
|
||
this.dummyElementPrefab.SetActive(true); | ||
this.viewElementPrefab = this.dummyElementPrefab; | ||
// GameObject defaultPrefab = GameObject.Find("SaveLoadViewElement"); | ||
// this.dummyElementPrefab = Instantiate(defaultPrefab); | ||
} | ||
} | ||
} |
Oops, something went wrong.