//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, October 16, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
//关于日常和地图
|
namespace vnxbqy.UI
|
{
|
|
public class TopRightTip : MonoBehaviour
|
{
|
public Button m_Map;
|
public Button m_Daily;
|
public Button m_BackPack;
|
public Image m_MapImage;
|
public Image m_MapHero;
|
public Text m_MapName;
|
public Button m_ServerRank;
|
public Button m_SuperUPGift;
|
|
LocalMap mapMatrix;
|
Vector3 heroPrePosition = new Vector3(-999, -8888, 0);
|
int dataMapId = 0;
|
int lineId = 0;
|
bool isShow = false;
|
|
MapModel model { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
SuperUPGiftModel giftModel { get { return ModelCenter.Instance.GetModel<SuperUPGiftModel>(); } }
|
|
public void Init()
|
{
|
isShow = true;
|
m_Map.SetListener(OpenMapWin);
|
m_Daily.SetListener(OpenDailyQuestWin);
|
m_BackPack.SetListener(OpenBackpack);
|
m_ServerRank.SetListener(OpenRank);
|
OpenServerActivityCenter.Instance.openServerActivityStateChange += OpenServerActivityStateChange;
|
m_ServerRank.SetActive(OpenServerActivityCenter.Instance.IsActivityOpen(0));
|
m_SuperUPGift.SetListener(()=>{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.OpenServer_SuperUP);
|
});
|
|
WindowCenter.Instance.windowAfterOpenEvent += WindowAfterEvent;
|
SuperUPGiftModel.OnSuperUPGiftRefresh += OnGiftChange;
|
}
|
|
public void UnInit()
|
{
|
isShow = false;
|
m_Map.RemoveAllListeners();
|
m_Daily.RemoveAllListeners();
|
m_BackPack.RemoveAllListeners();
|
m_ServerRank.RemoveAllListeners();
|
OpenServerActivityCenter.Instance.openServerActivityStateChange -= OpenServerActivityStateChange;
|
WindowCenter.Instance.windowAfterOpenEvent -= WindowAfterEvent;
|
SuperUPGiftModel.OnSuperUPGiftRefresh -= OnGiftChange;
|
}
|
|
private void WindowAfterEvent(Window _win) {
|
|
if (_win is MainInterfaceWin)
|
{
|
if (CrossServerUtility.IsCrossServerOneVsOne() || ArenaManager.isArenaClient)
|
{
|
m_SuperUPGift.SetActive(false);
|
m_BackPack.SetActive(false);
|
return;
|
}
|
m_SuperUPGift.SetActive(giftModel.IsOpen && giftModel.hasNewGift);
|
m_BackPack.SetActive(true);
|
}
|
}
|
|
private void OnGiftChange()
|
{
|
if (CrossServerUtility.IsCrossServerOneVsOne() || ArenaManager.isArenaClient)
|
{
|
m_SuperUPGift.SetActive(false);
|
return;
|
}
|
m_SuperUPGift.SetActive(giftModel.IsOpen && giftModel.hasNewGift);
|
}
|
|
private void OpenServerActivityStateChange()
|
{
|
m_ServerRank.SetActive(OpenServerActivityCenter.Instance.IsActivityOpen(0));
|
}
|
|
private void OpenRank()
|
{
|
WindowCenter.Instance.Open<OpenServerActivityRankWin>();
|
}
|
|
private void OpenMapWin()
|
{
|
var canOpen = ModelCenter.Instance.GetModel<MapModel>().CanOpenLocalMapWin(PlayerDatas.Instance.baseData.MapID);
|
if (!canOpen)
|
{
|
SysNotifyMgr.Instance.ShowTip("MapInfo1");
|
}
|
else
|
{
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
WindowCenter.Instance.Open<LocalMapWin>();
|
}
|
}
|
|
private void OpenDailyQuestWin()
|
{
|
if (NewBieCenter.Instance.inGuiding && NewBieCenter.Instance.currentGuide == 89)//仙界秘境购买引导
|
{
|
ModelCenter.Instance.GetModel<DailyQuestModel>().wannaLookDailyQuest = (int)DailyQuestType.FairyLand;
|
}
|
if (NewBieCenter.Instance.inGuiding && NewBieCenter.Instance.currentGuide == TrialDungeonModel.TRIALEXCHANGE_GUIDE)
|
{
|
ModelCenter.Instance.GetModel<DailyQuestModel>().wannaLookDailyQuest = (int)DailyQuestType.Trial;
|
}
|
if (NewBieCenter.Instance.inGuiding && NewBieCenter.Instance.currentGuide == 29)//仙界秘境功能开启引导
|
{
|
ModelCenter.Instance.GetModel<DailyQuestModel>().wannaLookDailyQuest = (int)DailyQuestType.FairyLand;
|
}
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
WindowCenter.Instance.Open<DailyQuestWin>();
|
}
|
|
private void OpenBackpack()
|
{
|
KnapSackWin.jumpByRedpoint = true;
|
WindowCenter.Instance.Open<KnapSackWin>();
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
}
|
|
|
public void Update()
|
{
|
if (!isShow) return;
|
if (PlayerDatas.Instance == null) return;
|
if (model == null) return;
|
// 更新地图
|
int curMapID = model.wannaLookLocalMap == 0 ? MapUtility.GetDataMapId() : model.wannaLookLocalMap;
|
if (curMapID != 0 && curMapID != dataMapId)
|
{
|
dataMapId = curMapID;
|
lineId = MapUtility.GetDataMapId() == dataMapId ? PlayerDatas.Instance.baseData.dungeonLineId : 0;
|
var mapResConfig = MapResourcesConfig.GetConfig(this.dataMapId, this.lineId);
|
var mapWidth = mapResConfig.MapScale.x;
|
var mapHeight = mapResConfig.MapScale.y;
|
var uiMapWidth = mapWidth * mapResConfig.MapShowScale;
|
var uiMapHeight = mapHeight * mapResConfig.MapShowScale;
|
m_MapName.text = mapResConfig.Name;
|
|
this.mapMatrix = new LocalMap(this.dataMapId, mapWidth, mapHeight, uiMapWidth, uiMapHeight);
|
m_MapImage.SetSprite(mapResConfig.BigMap);
|
m_MapImage.SetNativeSize();
|
|
if (mapWidth == 0)
|
{
|
heroPrePosition = Vector3.zero;
|
}
|
else
|
{
|
var hPos = mapMatrix.WorldToLocalPosition(PlayerDatas.Instance.hero.Pos);
|
heroPrePosition = hPos;
|
}
|
}
|
|
//更新坐标
|
if (heroPrePosition != Vector3.zero && dataMapId == PlayerDatas.Instance.baseData.MapID &&
|
PlayerDatas.Instance.hero != null && PlayerDatas.Instance.hero.IsRun())
|
{
|
var heroPos = mapMatrix.WorldToLocalPosition(PlayerDatas.Instance.hero.Pos);
|
if (Vector3.Distance(heroPrePosition, heroPos) > 1f)
|
{
|
heroPrePosition = heroPos;
|
|
var _eular = PlayerDatas.Instance.hero.Root.eulerAngles;
|
var _mapHeroEular = m_MapHero.transform.eulerAngles;
|
_mapHeroEular.z = -_eular.y;
|
m_MapHero.transform.eulerAngles = _mapHeroEular;
|
}
|
}
|
if (heroPrePosition != m_MapImage.transform.localPosition)
|
m_MapImage.transform.localPosition = heroPrePosition;
|
|
}
|
|
|
public struct LocalMap
|
{
|
public int mapId;
|
public float worldMapWidth;
|
public float worldMapHeight;
|
public float localMapWidth;
|
public float localMapHeight;
|
|
public LocalMap(int mapId, float mWidth, float mHeigth, float mSpriteWidth, float mSpriteHeight)
|
{
|
this.mapId = mapId;
|
worldMapWidth = mWidth;
|
worldMapHeight = mHeigth;
|
localMapWidth = mSpriteWidth;
|
localMapHeight = mSpriteHeight;
|
}
|
|
public Vector3 WorldToLocalPosition(Vector3 _worldPosition)
|
{
|
var x = ((worldMapWidth * 0.5f - _worldPosition.x) / worldMapWidth) * localMapWidth;
|
var y = ((worldMapHeight * 0.5f - _worldPosition.z) / worldMapHeight) * localMapHeight;
|
return new Vector3(x, y, 0);
|
}
|
|
}
|
|
public void ShowMiniMap(bool show)
|
{
|
m_Map.SetActive(show);
|
}
|
}
|
|
}
|
|
|
|