Files
JJBB/Assets/Project/Script/GUI/Map/CopyInUpRight.cs

394 lines
12 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using GCGame.Table;
public class CopyInUpRight : MonoBehaviour {
private static CopyInUpRight m_Instance = null;
public static CopyInUpRight Instance()
{
return m_Instance;
}
public GameObject killParent;
public GameObject _NextRefeshObj;
public Text _NextRefreshTime;
public Text kills; //杀怪数
public Text timeDownText; //副本剩余时间倒计时
public Text AwardType; //副本奖励获得方式
public GameObject AwardTypeObj;
public GameObject LeaveBtn;
public GameObject killGameObj;
public GameObject timeDownGameObj;
public GameObject AwardItemObj;
public static void ClearData()
{
killMonsterCount = 0;
killBossCount = 0;
}
private int killMonsters;
private static int killMonsterCount;
private int killBosss;
private static int killBossCount;
private int _CDStart;
public void Awake()
{
Hashtable add = new Hashtable();
add["name"] = "CopyRightOpen";
Games.Events.MessageEventCallBack call = OnOpenWndOver;
add["callFun"] = call;
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.CopyRightOpen, add);
Hashtable add1 = new Hashtable();
add1["name"] = "CopyRightRefresh";
Games.Events.MessageEventCallBack call1 = ReFreshKills;
add1["callFun"] = call1;
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.CopyRightFresh, add1);
}
public void InitRefeshTime(int remainTime)
{
if(remainTime > 0)
{
_NextRefreshTime.text = (remainTime / 60).ToString().PadLeft(2, '0') + ":" + (remainTime % 60).ToString().PadLeft(2, '0');
_NextRefeshObj.SetActive(true);
StartCoroutine(CountNextRereshTime(remainTime));
}
else
{
_NextRefeshObj.SetActive(false);
}
}
IEnumerator CountNextRereshTime(int remainTime)
{
while(true)
{
yield return new WaitForSeconds(1.0f);
remainTime--;
if(remainTime <= 0)
{
_NextRefeshObj.SetActive(false);
yield break;
}
_NextRefreshTime.text = (remainTime / 60).ToString().PadLeft(2, '0') + ":" + (remainTime % 60).ToString().PadLeft(2, '0');
}
}
public void OnOpenWndOver(Hashtable addparam, Hashtable sendparam)
{
if (sendparam.ContainsKey("operator"))
{
GC_NOTIFY_COPYINFO packet = (GC_NOTIFY_COPYINFO)sendparam["operator"];
if (packet == null)
return;
InitInfo(packet);
}
LeaveBtn.SetActive(sendparam.ContainsKey("IsCanLeave"));
}
public void ReFreshKills(Hashtable addparam, Hashtable sendparam)
{
if (sendparam.ContainsKey("packet"))
{
GC_NOTIFY_COPY_MONSTER_INFO packet = (GC_NOTIFY_COPY_MONSTER_INFO)sendparam["packet"];
RefreshKills(packet);
}
}
void Start()
{
RectTransform rect = transform as RectTransform;
if(rect!=null)
{
rect.anchoredPosition = new Vector2(0, rect.anchoredPosition.y);
}
transform.SetSiblingIndex(0);
InvokeRepeating("RemainTimeDown", 0, 1);
}
void OnEnable()
{
m_Instance = this;
//if (MissionDialogAndLeftTabsLogic.Instance() != null)
// MissionDialogAndLeftTabsLogic.Instance().HideMissionDialog(false);
//MissionDialogAndLeftTabsLogic.SetSwitch(UIInfo.CopyInfoUpRight);
Tab_Fuben fuben = TableManager.GetFubenByID(GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterCopySceneID, 0);
if (fuben == null)
{
UIManager.CloseUI(UIInfo.CopyInfoUpRight);
return;
}
if (fuben.ShowTimeDown != 1)
{
timeDownText.text = "--/--";
}
ShowAwardItem(fuben);
if (GameManager.gameManager.RunningScene == Games.GlobeDefine.GlobeVar.BANQUETSCENEID)
OnBtnHide();
else
OnBtnShow();
}
List<GameObject> Items = new List<GameObject>();
void ShowAwardItem(Tab_Fuben fuben)
{
for (int i = 0; i < Items.Count; i++)
Items[i].SetActive(false);
for(int i=0;i<fuben.getAwardItemIDCount();i++)
{
int awardID = fuben.GetAwardItemIDbyIndex(i);
int awardCount = fuben.GetAwardItemCountbyIndex(i);
if (awardID == -1)
continue;
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(awardID, 0);
if (commonItem == null)
continue;
GameObject newObj = null;
if (Items.Count > i && Items[i]!=null)
newObj = Items[i];
else
{
newObj = GameObject.Instantiate(AwardItemObj);
Items.Add(newObj);
}
if (newObj == null)
continue;
newObj.SetActive(true);
newObj.transform.SetParent(AwardItemObj.transform.parent);
newObj.transform.localPosition = Vector3.zero;
newObj.transform.localScale = Vector3.one;
Text numText = newObj.GetComponentInChildren<Text>();
Transform count = newObj.transform.Find("Count");
if(awardCount<=1)
{
if (count != null)
count.gameObject.SetActive(false);
}
else
{
if (numText != null)
numText.text = awardCount.ToString();
}
Button btn = newObj.GetComponent<Button>();
if (btn != null)
{
btn.onClick.AddListener(delegate ()
{
ItemTooltipsLogic.ShowItemTooltip(awardID, ItemTooltipsLogic.ShowType.Info, newObj.transform.position);
});
}
Transform Quility = newObj.transform.Find("Quility");
if (Quility != null)
{
Image QuilityImage = Quility.GetComponent<Image>();
if (QuilityImage != null)
{
LoadAssetBundle.Instance.SetImageSprite(QuilityImage, GCGame.Utils.GetItemQualityFrame(commonItem));
}
}
Transform Icon = newObj.transform.Find("Icon");
if (Icon != null)
{
Image IconImage = Icon.GetComponent<Image>();
if (IconImage != null)
{
LoadAssetBundle.Instance.SetImageSprite(IconImage, commonItem.Icon);
if (commonItem.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, IconImage.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, IconImage.transform);
}
}
}
}
AwardTypeObj.gameObject.SetActive(true);
if (fuben.AwardItemType == 1)
AwardType.text = StrDictionary.GetClientDictionaryString("#{9015}");
if (fuben.AwardItemType == 0)
AwardType.text = StrDictionary.GetClientDictionaryString("#{9014}");
if (fuben.AwardItemType == -1)
AwardTypeObj.SetActive(false);
}
void OnDestroy()
{
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.CopyRightFresh, "CopyRightRefresh");
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.CopyRightOpen, "CopyRightOpen");
CancelInvoke();
}
void OnDisable()
{
if (!GameManager.applicationQuit)
{
m_Instance = null;
if (MissionDialogAndLeftTabsLogic.Instance() != null)
MissionDialogAndLeftTabsLogic.Instance().HideMissionDialog(true);
}
}
public void RemainTimeDown()
{
if (Time.realtimeSinceStartup - _CDStart > 0)
return;
timeDownText.text = GCGame.Utils.GetTimeStr(_CDStart - Time.realtimeSinceStartup);
}
public void RefreshKills(GC_NOTIFY_COPY_MONSTER_INFO packet)
{
if (kills == null || killGameObj.activeInHierarchy == false)
return;
if (killMonsters > killMonsterCount)
return;
killBosss = packet.BossKilledCount;
killMonsters = packet.NoBossKilledCount;
FreshKills();
}
void FreshKills()
{
Tab_Fuben fuben = TableManager.GetFubenByID(GameManager.gameManager.PlayerDataPool.EnterSceneCache.EnterCopySceneID, 0);
if (fuben == null || (fuben.Type == 2 &&fuben.SuccessRule == -1) )
{
killParent.SetActive(false);
return;
}
killParent.SetActive(true);
if (fuben.SuccConditionType == 0)
{
string tip = string.Format("<color=#72fe72ff>{0}/{1}</color>", killMonsters+killBosss, killBossCount+killMonsterCount);
kills.text = StrDictionary.GetClientDictionaryString("#{9012}", tip);
}
else if(fuben.SuccConditionType >1)
{
Tab_RoleBaseAttr role = TableManager.GetRoleBaseAttrByID(fuben.SuccConditionType, 0);
if(role!=null)
{
string tip = string.Format("<color=#72fe72ff>{0}/{1}</color>",killBosss, killBossCount);
kills.text = StrDictionary.GetClientDictionaryString("#{9013}",role.Name, tip);
}
}
else if(fuben.SuccConditionType < 0)
{
int StrID = fuben.SuccConditionType * -1;
kills.text = StrDictionary.GetClientDictionaryString("#{" + StrID + "}");
}
}
public void InitInfo(GC_NOTIFY_COPYINFO packet)
{
killBossCount = packet.BossCount;
killBosss = packet.BossKilledCount;
killMonsterCount = packet.NoBossCount;
killMonsters = packet.NoBossKilledCount;
_CDStart = packet.TimeRemain;
FreshKills();
}
public void Click_LeaveCopy()
{
if(Singleton<ObjManager>.Instance.MainPlayer!=null)
{
Singleton<ObjManager>.Instance.MainPlayer.AskLeaveCopy();
}
}
public void SwitchAutoFight()
{
var mainPlayer = ObjManager.Instance.MainPlayer;
mainPlayer.EnterAutoCombat();
}
public void OpenMissionLeftTab()
{
if(MissionDialogAndLeftTabsLogic.Instance()==null)
{
UIManager.ShowUI(UIInfo.MissionInfoController,delegate(bool bSuccess, object param)
{
if (bSuccess == false)
return;
MissionDialogAndLeftTabsLogic.SetSwitch(UIInfo.CopyInfoUpRight);
MissionDialogAndLeftTabsLogic.Instance().SetSwitchBtn();
UIManager.CloseUI(UIInfo.CopyInfoUpRight);
});
}
else
{
MissionDialogAndLeftTabsLogic.Instance().HideMissionDialog(true);
MissionDialogAndLeftTabsLogic.SetSwitch(UIInfo.CopyInfoUpRight);
MissionDialogAndLeftTabsLogic.Instance().SetSwitchBtn();
UIManager.CloseUI(UIInfo.CopyInfoUpRight);
}
}
public ObjectTween _MoveTo;
public RectTransform _TitleBGRec;
public GameObject _ShowBtn;
public GameObject _HideBtn;
public GameObject _InfoPanel;
private bool isShow = false;
public void OnBtnShow()
{
ShowPanel();
_ShowBtn.SetActive(false);
_HideBtn.SetActive(true);
isShow = true;
}
public void OnBtnHide()
{
HidePanel();
_ShowBtn.SetActive(true);
_HideBtn.SetActive(false);
isShow = false;
}
public void OnTitleBtn()
{
if (isShow)
{
OnBtnHide();
}
else
{
OnBtnShow();
}
}
public void ShowPanel()
{
_MoveTo.Reset();
_MoveTo.destantPos = new Vector3(0, 0, 0);
GCGame.Utils.HideMainTopRightUI();
_TitleBGRec.sizeDelta = new Vector2(300, _TitleBGRec.sizeDelta.y);
_InfoPanel.gameObject.SetActive(true);
}
public void HidePanel()
{
_MoveTo.Reset();
_MoveTo.destantPos = new Vector3(0, -192, 0);
GCGame.Utils.ShowMainTopRightUI();
_TitleBGRec.sizeDelta = new Vector2(240, _TitleBGRec.sizeDelta.y);
_InfoPanel.gameObject.SetActive(false);
}
}