using BrewMonster.Network; 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(); } Vector3 _hostPlayerPosition; Quaternion _hostPlayerRotation; private void UpdateHostPlayerPositionImage() { if (_hostPlayerPositionImage == null) { return; } if (!TryGetHostPlayerPosition(out _hostPlayerPosition, out _hostPlayerRotation)) { _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( _hostPlayerPosition.x / _positionFactor, _hostPlayerPosition.z / _positionFactor); hostPlayerRectTransform.localRotation = Quaternion.Euler(0, 0, -_hostPlayerRotation.eulerAngles.y); } private bool TryGetHostPlayerPosition(out Vector3 hostPlayerPosition, out Quaternion hostPlayerRotation) { hostPlayerPosition = Vector3.zero; hostPlayerRotation = Quaternion.identity; CECHostPlayer hostPlayer = GetHostPlayer(); if (hostPlayer == null || hostPlayer.transform == null) { return false; } hostPlayerPosition = hostPlayer.transform.position; hostPlayerRotation = hostPlayer.transform.rotation; 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}"); } } /// /// When user click on the map texture. /// We will calculate the world coordinates from the local cursor position. Then move the host player to the world coordinates. /// /// public void OnMapClicked(Vector2 localCursorPosition) { var worldCoordinates = localCursorPosition * _positionFactor; UnityGameSession.c2s_CmdGoto(worldCoordinates.x, 1.0f, worldCoordinates.y); // close the map OnCloseButtonClicked(); } private void OnCloseButtonClicked() { CloseDialogue(); } } }