146 lines
5.4 KiB
C#
146 lines
5.4 KiB
C#
using BrewMonster.Managers;
|
|
using BrewMonster.Network;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster.UI
|
|
{
|
|
/// <summary>Popup menu for selected else player. Use your own prefab: add it to DialogScriptTableObject with id "DlgPlayerOptions", then assign Panel Root and buttons below.</summary>
|
|
public class DlgPlayerOptions : AUIDialog
|
|
{
|
|
[Header("Prefab references")]
|
|
[Tooltip("Panel to position at mouse when opened. If null, panel stays at prefab position.")]
|
|
[SerializeField] private RectTransform panelRoot;
|
|
|
|
[SerializeField] private Button btnViewInfo;
|
|
[SerializeField] private Button btnTeamInvite;
|
|
[SerializeField] private Button btnTrade;
|
|
[SerializeField] private Button btnAddFriend;
|
|
[SerializeField] private Button btnDuel;
|
|
[SerializeField] private Button btnWhisper;
|
|
[SerializeField] private Button btnClose;
|
|
|
|
int _currentTargetId;
|
|
|
|
void Awake()
|
|
{
|
|
if (btnViewInfo != null) btnViewInfo.onClick.AddListener(() => OnOptionClicked(0));
|
|
if (btnTeamInvite != null) btnTeamInvite.onClick.AddListener(() => OnOptionClicked(1));
|
|
if (btnTrade != null) btnTrade.onClick.AddListener(() => OnOptionClicked(2));
|
|
if (btnAddFriend != null) btnAddFriend.onClick.AddListener(() => OnOptionClicked(3));
|
|
if (btnDuel != null) btnDuel.onClick.AddListener(() => OnOptionClicked(4));
|
|
if (btnWhisper != null) btnWhisper.onClick.AddListener(() => OnOptionClicked(5));
|
|
if (btnClose != null) btnClose.onClick.AddListener(() => OnOptionClicked(-1));
|
|
}
|
|
|
|
void OnOptionClicked(int actionIndex)
|
|
{
|
|
int characterId = _currentTargetId;
|
|
if (actionIndex < 0)
|
|
{
|
|
Show(false);
|
|
return;
|
|
}
|
|
|
|
switch (actionIndex)
|
|
{
|
|
case 0: OnViewInfo(characterId); break;
|
|
case 1: OnTeamInvite(characterId); break;
|
|
case 2: OnTrade(characterId); break;
|
|
case 3: OnAddFriend(characterId); break;
|
|
case 4: OnDuel(characterId); break;
|
|
case 5: OnWhisper(characterId); break;
|
|
}
|
|
_currentTargetId = 0;
|
|
Show(false);
|
|
}
|
|
|
|
void OnViewInfo(int characterId)
|
|
{
|
|
Debug.Log("OnViewInfo: " + characterId);
|
|
var list = new List<int> { characterId };
|
|
//UnityGameSession.GetRoleBaseInfo(1, list);
|
|
UnityGameSession.c2s_SendCmdGetOtherEquipDetail(characterId);
|
|
}
|
|
|
|
void OnTeamInvite(int characterId)
|
|
{
|
|
Debug.Log("OnTeamInvite: " + characterId);
|
|
UnityGameSession.c2s_CmdTeamInvite(characterId);
|
|
}
|
|
|
|
void OnTrade(int characterId)
|
|
{
|
|
Debug.Log("OnTrade: " + characterId);
|
|
// TODO: c2s trade request when availableP
|
|
}
|
|
|
|
void OnAddFriend(int characterId)
|
|
{
|
|
string name = EC_ManMessageMono.Instance?.GetECManPlayer?.GetElsePlayer(characterId)?.GetName() ?? "";
|
|
UnityGameSession.Friend_Add(characterId, name);
|
|
}
|
|
|
|
void OnDuel(int characterId)
|
|
{
|
|
Debug.Log("OnDuel: " + characterId);
|
|
UnityGameSession.c2s_CmdDuelRequest(characterId);
|
|
}
|
|
|
|
void OnWhisper(int characterId)
|
|
{
|
|
string name = EC_ManMessageMono.Instance?.GetECManPlayer?.GetElsePlayer(characterId)?.GetName() ?? "";
|
|
Debug.Log("[Cuong] OnWhisper: " + characterId + " name: " + name);
|
|
|
|
EventBus.Publish(new Scripts.ChatUI.WhisperPlayerEvent(name));
|
|
}
|
|
|
|
void PositionAtMouse()
|
|
{
|
|
if (panelRoot == null) return;
|
|
var canvas = GetComponentInParent<Canvas>();
|
|
if (canvas == null) return;
|
|
Camera cam = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera;
|
|
RectTransform rootRt = transform as RectTransform;
|
|
if (rootRt == null) return;
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(rootRt, Input.mousePosition, cam, out Vector2 local);
|
|
panelRoot.anchoredPosition = local;
|
|
panelRoot.anchorMin = panelRoot.anchorMax = new Vector2(0.5f, 0.5f);
|
|
panelRoot.pivot = new Vector2(0, 1);
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
base.Update();
|
|
if (!m_bShow) return;
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
Show(false);
|
|
return;
|
|
}
|
|
if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && panelRoot != null)
|
|
{
|
|
var canvas = GetComponentInParent<Canvas>();
|
|
Camera cam = canvas != null && canvas.renderMode == RenderMode.ScreenSpaceCamera ? canvas.worldCamera : null;
|
|
if (!RectTransformUtility.RectangleContainsScreenPoint(panelRoot, Input.mousePosition, cam))
|
|
Show(false);
|
|
}
|
|
}
|
|
|
|
public override void ShowForPlayer(int characterId)
|
|
{
|
|
_currentTargetId = characterId;
|
|
PositionAtMouse();
|
|
Show(true);
|
|
}
|
|
|
|
public override void Show(bool value)
|
|
{
|
|
base.Show(value);
|
|
if (panelRoot != null)
|
|
panelRoot.gameObject.SetActive(value);
|
|
}
|
|
}
|
|
}
|