Files
test/Assets/PerfectWorld/Scripts/UI/DlgWorldMap.cs
T
2026-04-20 17:08:04 +07:00

147 lines
4.4 KiB
C#

using CSNetwork.Common;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster.UI
{
public class DlgWorldMap : AUIDialog
{
[SerializeField] private Image mapImage;
[SerializeField] private Image _hostPlayerPositionImage;
[SerializeField] private float _positionFactor = 2f;
[SerializeField] private Button _closeButton;
// 世界 / World
const int MAJOR_MAP = 1;
// 仙魔 / Good Evil // Tiên Ma
static bool GOOD_EVIL_MAP(int id)
{
return id == 121 || id == 122;
}
// 城战 / Guild War // Thành Chiến
static bool GUILD_WAR_MAP(int id)
{
return id >= 230 && id <= 235;
}
// 蓬莱 / Penglai // Bồng Lai
static bool PENGLAI_MAP(int id)
{
return id == 137;
}
static bool IS_MAP_MARKABLE(int mapID)
{
return MAJOR_MAP == mapID || GOOD_EVIL_MAP(mapID) || GUILD_WAR_MAP(mapID) || PENGLAI_MAP(mapID);
}
public override void Awake()
{
base.Awake();
_closeButton.onClick.AddListener(OnCloseButtonClicked);
}
public override void Show(bool value)
{
base.Show(value);
if (value)
{
UpdateHostPlayerPositionImage();
}
}
public override bool Render()
{
// UpdateHostPlayerPositionImage();
return base.Render();
}
private void UpdateHostPlayerPositionImage()
{
if (_hostPlayerPositionImage == null)
{
return;
}
if (!TryGetHostPlayerPosition(out Vector3 hostPosition))
{
_hostPlayerPositionImage.enabled = false;
return;
}
if (Mathf.Approximately(_positionFactor, 0f))
{
BMLogger.LogError("DlgWorldMap _positionFactor cannot be zero.");
_hostPlayerPositionImage.enabled = false;
return;
}
_hostPlayerPositionImage.enabled = true;
RectTransform hostPlayerRectTransform = _hostPlayerPositionImage.rectTransform;
hostPlayerRectTransform.anchoredPosition = new Vector2(
hostPosition.x / _positionFactor,
hostPosition.z / _positionFactor);
}
private bool TryGetHostPlayerPosition(out Vector3 hostPlayerPosition)
{
hostPlayerPosition = Vector3.zero;
CECHostPlayer hostPlayer = GetHostPlayer();
if (hostPlayer == null || hostPlayer.transform == null)
{
return false;
}
hostPlayerPosition = hostPlayer.transform.position;
return true;
}
public void BuildTravelMap(uint dwType, object pData)
{
// default world id
int worldid = MAJOR_MAP;
// select the correct map background
// PAUIIMAGEPICTURE pImage = (PAUIIMAGEPICTURE)GetDlgItem("WorldMapTravel");
// prepare the necessary information
SetData(dwType);
// CECMapDlgsMgr *pMgr = GetGameUIMan()->GetMapDlgsMgr();
// ÖØÐ¿ªÊ¼¼ÆËã´«ËÍÏß·
// pMgr->ResetTransWay();
if(dwType == (uint)DATA_TYPE.DT_NPC_TRANSMIT_SERVICE)
{
// worldid = pMgr->FindTransmitWorldID((NPC_TRANSMIT_SERVICE*)pData);
// save the worldid
// SetDataPtr((void*)worldid, "WorldID");
// pMgr->LoadMapTexture(m_pA3DDevice, pImage, CECMapDlgsMgr::MAP_TYPE_TRANSMIT);
}
else if(dwType == (uint)DATA_TYPE.DT_TRANSMITSCROLL_ESSENCE)
{
// save the slot info
// SetDataPtr(pData, "ItemSlot");
// pMgr->LoadMapTexture(m_pA3DDevice, pImage, CECMapDlgsMgr::MAP_TYPE_SCROLL);
}
else
{
// invalid transmit type
BMLogger.LogError($"Invalid transmit type: {dwType}");
}
}
private void OnCloseButtonClicked()
{
CloseDialogue();
}
}
}