/// <summary> /// 初始化所有船数据 /// </summary> /// <returns></returns> public void InitShipPackage() { PackageProxy m_PackageProxy = Facade.RetrieveProxy(ProxyName.PackageProxy) as PackageProxy; ItemContainer[] m_ShipByType = m_PackageProxy.GetItemList <ItemContainer>(Category.WarehousePackage, Category.Package); m_ShipPackage.Clear(); if (m_ShipByType != null) { foreach (ItemContainer package in m_ShipByType) { if (package.Items != null) { foreach (var item in package.Items.Values) { IShip m_WarShip = WarShipDataFactory.BuildShipData((ItemWarShipVO)item); m_ShipPackage.Add(m_WarShip.GetUID(), m_WarShip); } } } } IShip m_CurWarShip = GetAppointWarShip(); if (!m_ShipPackage.ContainsKey(m_CurWarShip.GetUID())) { m_ShipPackage.Add(m_CurWarShip.GetUID(), m_CurWarShip); } }
/// <summary> /// 刷新热键 /// </summary> private void RefreshHotKey() { if (m_CurrentShip.GetUID() == m_ShipProxy.GetAppointWarShip().GetUID()) { SetHotKeyEnabled(UIAction.Hangar_Appoint, false); } else { SetHotKeyEnabled(UIAction.Hangar_Appoint, true); } }
/// <summary> /// 修改船数据包 /// </summary> /// <param name="item"></param> /// <returns></returns> public void ChangeShipPackage(ulong id) { PackageProxy m_PackageProxy = Facade.RetrieveProxy(ProxyName.PackageProxy) as PackageProxy; ItemWarShipVO itemWarShipVO = m_PackageProxy.GetItem <ItemWarShipVO>(id); IShip m_Ship = null; m_Ship = WarShipDataFactory.BuildShipData(itemWarShipVO); m_ShipPackage.Add(m_Ship.GetUID(), m_Ship); IShip m_CurWarShip = GetAppointWarShip(); if (!m_ShipPackage.ContainsKey(m_CurWarShip.GetUID())) { m_ShipPackage.Add(m_CurWarShip.GetUID(), m_CurWarShip); } }
/// <summary> /// 获取当前任命出战船 /// </summary> /// <returns></returns> public IShip GetAppointWarShip() { PackageProxy m_PackageProxy = Facade.RetrieveProxy(ProxyName.PackageProxy) as PackageProxy; m_HeroItem = m_PackageProxy.GetHeroItem(); if (m_HeroItem != null && m_HeroItem.Items != null && m_HeroItem.Items.Count > 0) { ItemWarShipVO itemWarShip = null; foreach (ItemBase item in m_HeroItem.Items.Values) { if (item is ItemWarShipVO) { if (m_CurrentWarShip == null || m_CurrentWarShip.GetUID() != item.UID) { if (!m_ShipPackage.TryGetValue(item.UID, out m_CurrentWarShip)) { itemWarShip = item as ItemWarShipVO; m_CurrentWarShip = WarShipDataFactory.BuildShipData(itemWarShip); m_ShipPackage[m_CurrentWarShip.GetUID()] = m_CurrentWarShip; } } return(m_CurrentWarShip); } } } m_CurrentWarShip = null; return(null); }
/// <summary> /// 船坞item选中 /// </summary> /// <param name="groupIndex"></param> /// <param name="cellIndex"></param> /// <param name="cellData"></param> /// <param name="cellView"></param> /// <param name="selected"></param> protected override void OnCellRenderer(int groupIndex, int cellIndex, object cellData, RectTransform cellView, bool selected) { IShip ship = (IShip)cellData; Animator m_Animator = cellView.GetComponent <Animator>(); if (m_Animator) { m_Animator.SetBool("IsOn", selected); } ShipHangarItem m_ShipHangarItem = cellView.GetOrAddComponent <ShipHangarItem>(); UIViewListLayout style = State.GetPageLayoutStyle(State.GetPageIndex()); if (style == UIViewListLayout.Row) { m_ShipHangarItem.SetData(ship, true); } else { m_ShipHangarItem.SetData(ship, false); } if (selected) { m_Ship = ship; State.SetTipData(null); State.SetTipData(cellData); State.GetAction(UIAction.Hangar_Assemble).Enabled = true; State.GetAction(UIAction.Hangar_Appoint).Enabled = ship.GetUID() != m_ShipProxy.GetAppointWarShip().GetUID(); m_ShipHangarItem.RecordItemNew(); } }
/// <summary> /// 任命船 /// </summary> /// <param name="callback"></param> private void OnAppointShip(HotkeyCallback callback) { if (callback.performed) { NetworkManager.Instance.GetPackageController().ReqestMove( m_Ship.GetUID(), m_PackageProxy.GetHeroItem().UID, 1, 0); } }
/// <summary> /// 存储新船 /// </summary> public void SetNew(IShip ship) { if (!MarkNew(ship)) { ServerListProxy m_ServerListProxy = GameFacade.Instance.RetrieveProxy(ProxyName.ServerListProxy) as ServerListProxy; string key = m_ServerListProxy.GetCurrentCharacterVO().UId.ToString(); HistoryShip m_HistoryShip = new HistoryShip(); if (PlayerPrefs.HasKey(key)) { m_HistoryShip = JsonUtility.FromJson <HistoryShip>(PlayerPrefs.GetString(key)); m_HistoryShip.m_ShipList.Add(ship.GetUID()); PlayerPrefs.SetString(key, JsonUtility.ToJson(m_HistoryShip)); } else { m_HistoryShip.m_ShipList.Add(ship.GetUID()); PlayerPrefs.SetString(key, JsonUtility.ToJson(m_HistoryShip)); } } }
/// <summary> /// 设置船内容显示 /// </summary> /// <param name="ship"></param> public void SetData(IShip ship, bool isList) { Initialize(); m_Ship = ship; if (isList) { UIUtil.SetIconImage(m_IconImage, TableUtil.GetItemIconBundle(ship.GetTID()), TableUtil.GetItemIconImage(ship.GetTID())); } else { UIUtil.SetIconImage(m_IconImage, TableUtil.GetItemIconBundle(ship.GetTID()), TableUtil.GetItemSquareIconImage(ship.GetTID())); } m_OverlyingIcon.sprite = m_IconImage.sprite; m_NameLabel.text = TableUtil.GetItemName((int)ship.GetTID()); m_LvLabel.text = TableUtil.ShowLevel(ship.GetLv()); m_Appoint.gameObject.SetActive(ship.GetUID() == m_ShipProxy.GetAppointWarShip().GetUID()); m_New.gameObject.SetActive(!m_ShipProxy.MarkNew(ship)); }
/// <summary> /// 当前船是否为新船 /// </summary> /// <returns></returns> public bool MarkNew(IShip ship) { ServerListProxy m_ServerListProxy = GameFacade.Instance.RetrieveProxy(ProxyName.ServerListProxy) as ServerListProxy; string key = m_ServerListProxy.GetCurrentCharacterVO().UId.ToString(); HistoryShip m_HistoryShip = new HistoryShip(); if (PlayerPrefs.HasKey(key)) { m_HistoryShip = JsonUtility.FromJson <HistoryShip>(PlayerPrefs.GetString(key)); if (m_HistoryShip.m_ShipList.Contains(ship.GetUID())) { return(true); } else { return(false); } } return(false); }