80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
// Attach to your team list item prefab. Has a text component and stores character ID for selection.
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using BrewMonster.Network;
|
|
|
|
namespace BrewMonster.UI
|
|
{
|
|
public class DlgArrangeTeamListItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text m_TextLabel;
|
|
[SerializeField] private Text m_TextLabelLegacy;
|
|
[SerializeField] private TMP_Text m_TextDetail;
|
|
[SerializeField] private Toggle m_Toggle;
|
|
[SerializeField] private Button m_InviteButton;
|
|
[SerializeField] private GameObject m_SelectedHighlight;
|
|
|
|
public int CharacterId { get; private set; }
|
|
public string DisplayName { get; private set; }
|
|
|
|
public void Set(string displayName, int characterId)
|
|
{
|
|
CharacterId = characterId;
|
|
DisplayName = displayName ?? "";
|
|
if (m_TextLabel != null)
|
|
m_TextLabel.text = displayName;
|
|
else if (m_TextLabelLegacy != null)
|
|
m_TextLabelLegacy.text = displayName;
|
|
SetSelected(false);
|
|
}
|
|
|
|
public void SetDetail(int profession)
|
|
{
|
|
if (m_TextDetail != null)
|
|
{
|
|
var gameRun = EC_Game.GetGameRun();
|
|
string profName = gameRun?.GetProfName(profession);
|
|
if(string.IsNullOrEmpty(profName))
|
|
profName = $"{profession}";
|
|
m_TextDetail.text = $"{profName}";
|
|
}
|
|
}
|
|
|
|
public void SetSelected(bool selected)
|
|
{
|
|
if (m_SelectedHighlight != null)
|
|
m_SelectedHighlight.SetActive(selected);
|
|
if (m_Toggle != null)
|
|
m_Toggle.SetIsOnWithoutNotify(selected);
|
|
}
|
|
|
|
public void SetClickCallback(System.Action<DlgArrangeTeamListItem> onSelect)
|
|
{
|
|
if (m_Toggle != null)
|
|
{
|
|
m_Toggle.onValueChanged.RemoveAllListeners();
|
|
m_Toggle.onValueChanged.AddListener((on) => { if (on) onSelect?.Invoke(this); });
|
|
}
|
|
}
|
|
|
|
/// <summary>Assign for nearby-player items: Invite button on the prefab invites this player.</summary>
|
|
public void SetInviteCallback(System.Action<DlgArrangeTeamListItem> onInvite)
|
|
{
|
|
if (m_InviteButton != null)
|
|
{
|
|
m_InviteButton.onClick.RemoveAllListeners();
|
|
m_InviteButton.onClick.AddListener(() => onInvite?.Invoke(this));
|
|
}
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
if (m_TextLabel == null) m_TextLabel = GetComponentInChildren<TMP_Text>();
|
|
if (m_TextLabelLegacy == null) m_TextLabelLegacy = GetComponentInChildren<Text>();
|
|
if (m_Toggle == null) m_Toggle = GetComponent<Toggle>();
|
|
}
|
|
}
|
|
}
|