123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- /****************************************************************************
- * 2024.7 LXD
- ****************************************************************************/
- using System.Collections;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using I2.Loc;
- using DG.Tweening;
- using UniRx.Triggers;
- using UnityEngine.EventSystems;
- namespace QFramework
- {
- public partial class ToolItemPrefab : UIElement
- {
- public GameObject m_NormalState;
- public GameObject m_HighterState;
- public GameObject m_SelectState;
- public GameObject m_PromptState;
- public ToolConfigInfo m_ToolConfigInfo;
- private UnityEngine.Coroutine m_Coroutine;
- private BtnState m_CurrentBtnState;
- private void Start()
- {
- GetComponent<Button>().onClick.AddListener(OnToolButtonClick);
- }
- private IObservable<BaseEventData> OnSelect()
- {
- throw new NotImplementedException();
- }
- public void SetData(ToolConfigInfo toolConfigInfo)
- {
- m_ToolConfigInfo = toolConfigInfo;
- ToolLibraryForm toolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
- if (toolLibraryForm.m_CurrentSelectToolIDs.Contains(int.Parse(m_ToolConfigInfo.id)))
- {
- SetButtonState(BtnState.select);
- }
- else
- {
- SetButtonState(BtnState.normal);
- }
- SetToolIcon();
- ToolName.text = toolConfigInfo.toolName;
- #region 多语言
- if (LocalizationConfig.localization && LocalizationManager.CurrentLanguage == "English")
- {
- ToolName.text = toolConfigInfo.en_toolName;
- }
- #endregion
- //如果已经选择
- if (toolLibraryForm.m_CurrentSelectToolIDs.Contains(int.Parse(m_ToolConfigInfo.id)))
- {
- SetButtonState(BtnState.select);
- }
- //如果打开提示
- if (OperateSetting.Instance.ToolPackUILogic.GetHint())
- {
- if (GetIsNeedHighter() && m_CurrentBtnState != BtnState.select)
- {
- ShowHighter(true);
- }
- }
- }
- /// <summary>
- /// 工具点击
- /// </summary>
- public void OnToolButtonClick()
- {
- ToolLibraryForm toolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
- toolLibraryForm?.ToolMessageElement.ShowToolInfo(m_ToolConfigInfo);
- if (toolLibraryForm.m_CurrentSelectToolIDs.Contains(int.Parse(m_ToolConfigInfo.id)))
- {
- toolLibraryForm.m_CurrentSelectToolIDs.Remove(int.Parse(m_ToolConfigInfo.id));
- SetButtonState(BtnState.normal);
- if (OperateSetting.Instance.ToolPackUILogic.GetHint())
- {
- if (GetIsNeedHighter())
- {
- ShowHighter(true);
- }
- }
- }
- else
- {
- toolLibraryForm.m_CurrentSelectToolIDs.Add(int.Parse(m_ToolConfigInfo.id));
- if (OperateSetting.Instance.ToolPackUILogic.GetHint())
- {
- ShowHighter(false);
- }
- SetButtonState(BtnState.select);
- }
- }
- public void SetShowToolInfo()
- {
- ToolLibraryForm toolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
- toolLibraryForm?.ToolMessageElement.ShowToolInfo(m_ToolConfigInfo);
- }
- /// <summary>
- /// 设置工具Icon
- /// </summary>
- private void SetToolIcon()
- {
- ToolConfigProxy toolConfigProxy = DAL.Instance.Get<ToolConfigProxy>();
- ToolIcon.sprite = toolConfigProxy.GetSpriteByToolName(m_ToolConfigInfo.toolName);
- }
- public void OnPointEnter()
- {
- if (SelectState.gameObject.activeSelf) return;
- SetButtonState(BtnState.highter);
- }
- public void OnPointExit()
- {
- if (SelectState.gameObject.activeSelf) return;
- SetButtonState(BtnState.normal);
- }
- public void SetButtonState(BtnState btnState)
- {
- switch (btnState)
- {
- case BtnState.normal:
- NormalState.gameObject.SetActive(true);
- SelectState.gameObject.SetActive(false);
- HighterState.gameObject.SetActive(false);
- break;
- case BtnState.highter:
- NormalState.gameObject.SetActive(false);
- SelectState.gameObject.SetActive(false);
- HighterState.gameObject.SetActive(true);
- break;
- case BtnState.select:
- NormalState.gameObject.SetActive(false);
- SelectState.gameObject.SetActive(true);
- HighterState.gameObject.SetActive(false);
- break;
- default:
- break;
- }
- m_CurrentBtnState = btnState;
- }
- public void ShowHighter(bool highter, Action callBack = null)
- {
- if (highter)
- {
- PromptIcon.gameObject.SetActive(true);
- PromptIcon.rectTransform.DOSizeDelta(new Vector2(201, 220), 1).SetLoops(-1, LoopType.Yoyo);
- }
- else
- {
- PromptIcon.gameObject.SetActive(false);
- PromptIcon.rectTransform.sizeDelta = new Vector2(193, 213);
- PromptIcon.rectTransform.DOKill();
- }
- }
- private bool GetIsNeedHighter()
- {
- ToolLibraryForm tmpToolLibraryForm = UIKit.GetPanel<ToolLibraryForm>();
- return tmpToolLibraryForm.ToolLibrarySelectElement.ToolItemIsNeedShowHighter(m_ToolConfigInfo.id);
- }
- IEnumerator IEShowHighter(Action callBack = null)
- {
- while (true)
- {
- yield return new WaitForSeconds(0.5f);
- SetButtonState(BtnState.highter);
- yield return new WaitForSeconds(0.5f);
- SetButtonState(BtnState.normal);
- callBack?.Invoke();
- }
- }
- }
- }
|