Add other player interact options
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0e02be030755ab4a917523764fe4eef
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -47,3 +47,5 @@ MonoBehaviour:
|
||||
prefab: {fileID: 6830833846243993097, guid: 97dd1de3aba08a04980849e40d5c1ea4, type: 3}
|
||||
- id: MagicProgress1
|
||||
prefab: {fileID: 1126053271199039253, guid: 526d462bd8c87b74c9e461e80d028cb2, type: 3}
|
||||
- id: DlgPlayerOptions
|
||||
prefab: {fileID: 1813565726936289741, guid: a0e02be030755ab4a917523764fe4eef, type: 3}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
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)
|
||||
{
|
||||
var list = new List<int> { characterId };
|
||||
UnityGameSession.GetRoleBaseInfo(1, list);
|
||||
}
|
||||
|
||||
void OnTeamInvite(int characterId)
|
||||
{
|
||||
UnityGameSession.c2s_CmdTeamInvite(characterId);
|
||||
}
|
||||
|
||||
void OnTrade(int characterId)
|
||||
{
|
||||
// TODO: c2s trade request when available
|
||||
}
|
||||
|
||||
void OnAddFriend(int characterId)
|
||||
{
|
||||
// TODO: c2s add friend when available
|
||||
}
|
||||
|
||||
void OnDuel(int characterId)
|
||||
{
|
||||
UnityGameSession.c2s_CmdDuelRequest(characterId);
|
||||
}
|
||||
|
||||
void OnWhisper(int characterId)
|
||||
{
|
||||
// TODO: open whisper/chat input with target when available
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!m_bShow) return;
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
Show(false);
|
||||
return;
|
||||
}
|
||||
if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && panelRoot != null)
|
||||
{
|
||||
var canvas = panelRoot.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 542735a99dfd07e4481469ec48ea05eb
|
||||
Reference in New Issue
Block a user