protected override void OnViewPartLoaded() { m_Container = FindComponent <Transform>("MODList"); m_ModCellList = new List <WarshipModPanelElement>(); UIManager.Instance.GetUIElement("Assets/Artwork/UI/Prefabs/Element/WarShipMessageElement.prefab", (cell) => { m_ModTips = cell.Spawn(m_Container); m_ModTips.SetActive(false); m_ModTips.transform.localScale = Vector3.one; } ); UIManager.Instance.GetUIElement("Assets/Artwork/UI/Prefabs/Element/WarShipModElement.prefab", (cell) => { m_ModItemPrefab = cell; } ); m_CurrentSelectedCell = null; OnRefresh(m_Msg); WarshipModPanel warshipModPanel = OwnerView as WarshipModPanel; warshipModPanel.OnEscClick = OnEscClick; State.GetAction(UIAction.Common_Select).Callback += OnModSelected; State.GetAction(UIAction.Common_Select).Enabled = false; ShowCharacter(); }
/// <summary> /// 获取单个物体 /// </summary> /// <returns></returns> private WarshipModPanelElement GetCell() { WarshipModPanelElement cell = m_ModItemPrefab.Spawn(m_Container).GetOrAddComponent <WarshipModPanelElement>(); cell.transform.localScale = Vector3.one; cell.OnSelected = ModCellOnSelected; cell.OnDeselected = ModCellOnDeselected; cell.OnDoubleClicked = ModCellOnDoubleClick; return(cell); }
/// <summary> /// mod选中 /// </summary> /// <param name="cell"></param> private void ModCellOnSelected(WarshipModPanelElement cell) { if (cell == m_CurrentSelectedCell) { return; } if (!EventSystem.current.alreadySelecting) { //FocusTo(cell.gameObject); EventSystem.current.SetSelectedGameObject(cell.gameObject); } m_CurrentSelectedCell = cell; State.GetAction(UIAction.Common_Select).Enabled = true; ShowModMessageTips(cell); State.SetTipData(m_CurrentSelectedCell.GetData()); }
/// <summary> /// mod取消选中 /// </summary> /// <param name="cell"></param> private void ModCellOnDeselected(WarshipModPanelElement cell) { if (cell) { cell.GetComponent <Toggle>().isOn = false; if (!EventSystem.current.alreadySelecting) { // FocusTo((GameObject)null); EventSystem.current.SetSelectedGameObject(null); } } if (m_CurrentSelectedCell == cell) { m_CurrentSelectedCell = null; State.GetAction(UIAction.Common_Select).Enabled = false; m_ModTips?.gameObject.SetActive(false); } }
private void ShowModMessageTips(WarshipModPanelElement cell) { m_ModTips.transform.localPosition = cell.transform.localPosition; m_ModTips.gameObject.SetActive(true); TransformUtil.FindUIObject <Transform>(m_ModTips.transform, "Content").gameObject.SetActive(cell.HasData()); TransformUtil.FindUIObject <Transform>(m_ModTips.transform, "Empty").gameObject.SetActive(!cell.HasData()); if (cell.HasData()) { UIUtil.SetIconImage( TransformUtil.FindUIObject <Image>(m_ModTips.transform, "Content/Image_Icon"), TableUtil.GetItemIconBundle(cell.GetModTid()), TableUtil.GetItemIconImage(cell.GetModTid()), autoSetNativeSize: true); TransformUtil.FindUIObject <Image>(m_ModTips.transform, "Content/Image_Quality").color = ColorUtil.GetColorByItemQuality(m_CfgEternityProxy.GetItemByKey(cell.GetModTid()).Quality); //数字不足3位,补0 ,并将补充的颜色置灰 int lv = cell.GetLv(); int index = 0; char[] charArray = lv.ToString().PadLeft(3, '0').ToCharArray(); for (int i = 0; i < charArray.Length; i++) { char cc = charArray[i]; if (cc != '0') { index = i; break; } } string sstr = lv.ToString().PadLeft(3, '0'); if (index != 0) { sstr = sstr.Insert(index, "</color>"); sstr = sstr.Insert(0, "<color=#808080>"); } TransformUtil.FindUIObject <TMP_Text>(m_ModTips.transform, "Content/Label_Lv").text = sstr; TransformUtil.FindUIObject <TMP_Text>(m_ModTips.transform, "Content/Label_Name").text = TableUtil.GetItemName(cell.GetModTid()); } }
/// <summary> /// 检查mod按钮数量 /// </summary> /// <param name="count">数量</param> /// <param name="modPosId">mod位置标记</param> private void CheckModBtnCount(uint count, uint modPosId) { if (m_ModCellList.Count == count) { SetModBtnListData(); } else if (m_ModCellList.Count < count) { while (m_ModCellList.Count < count) { m_ModCellList.Add(GetCell()); } } else { while (m_ModCellList.Count > count) { WarshipModPanelElement item = m_ModCellList[0]; m_ModCellList.RemoveAt(0); item.gameObject.Recycle(); } } ModPosition modPosCfg = m_CfgEternityProxy.GetModPosition(modPosId); ModPositionAttr modPosAttr; for (int i = 0; i < m_ModCellList.Count; i++) { modPosAttr = modPosCfg.Positions(i).Value; m_ModCellList[i].transform.localPosition = new Vector3(modPosAttr.X, modPosAttr.Y, 0); m_ModCellList[i].GetComponent <Toggle>().isOn = false; m_ModCellList[i].name = i.ToString(); } SetModBtnListData(); }
public override void OnHide() { m_CurrentSelectedCell = null; base.OnHide(); }
/// <summary> /// mod被双击 /// </summary> /// <param name="cell"></param> private void ModCellOnDoubleClick(WarshipModPanelElement cell) { m_CurrentSelectedCell = cell; OpenModList(); }
/// <summary> /// 选择Mod 重载方法 /// </summary> /// <param name="cell">内容Element</param> private void SelectMod(WarshipModPanelElement cell) { m_CurrentSelectedCell = null; cell.GetComponent <Toggle>().isOn = true; ModCellOnSelected(cell); }