From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/UICommon/ResizeCanvas.cs | 22 + .../Assets/Scripts/UICommon/ResizeCanvas.cs.meta | 8 + Client/Assets/Scripts/UICommon/XDlgControler.cs | 110 ++ .../Assets/Scripts/UICommon/XDlgControler.cs.meta | 8 + Client/Assets/Scripts/UICommon/XRadarMap.cs | 145 +++ Client/Assets/Scripts/UICommon/XRadarMap.cs.meta | 8 + Client/Assets/Scripts/UICommon/XSthCollector.cs | 351 +++++++ .../Assets/Scripts/UICommon/XSthCollector.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIAtlas.cs | 27 + Client/Assets/Scripts/UICommon/XUIAtlas.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs | 99 ++ .../Scripts/UICommon/XUIAtlasSelector.cs.meta | 12 + .../Assets/Scripts/UICommon/XUIBillBoardCompRef.cs | 19 + .../Scripts/UICommon/XUIBillBoardCompRef.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIButton.cs | 440 ++++++++ Client/Assets/Scripts/UICommon/XUIButton.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUICenterOnClick.cs | 25 + .../Scripts/UICommon/XUICenterOnClick.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUICheckBox.cs | 173 +++ Client/Assets/Scripts/UICommon/XUICheckBox.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIComboBox.cs | 124 +++ Client/Assets/Scripts/UICommon/XUIComboBox.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUICommon.cs | 63 ++ Client/Assets/Scripts/UICommon/XUICommon.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIDragDropItem.cs | 103 ++ .../Scripts/UICommon/XUIDragDropItem.cs.meta | 8 + .../Scripts/UICommon/XUIGenericEventHandle.cs | 19 + .../Scripts/UICommon/XUIGenericEventHandle.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIInput.cs | 106 ++ Client/Assets/Scripts/UICommon/XUIInput.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUILabel.cs | 262 +++++ Client/Assets/Scripts/UICommon/XUILabel.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUILabelSymbol.cs | 1111 ++++++++++++++++++++ .../Assets/Scripts/UICommon/XUILabelSymbol.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIList.cs | 57 + Client/Assets/Scripts/UICommon/XUIList.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUILongPress.cs | 75 ++ .../Assets/Scripts/UICommon/XUILongPress.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIObject.cs | 89 ++ Client/Assets/Scripts/UICommon/XUIObject.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIPanel.cs | 124 +++ Client/Assets/Scripts/UICommon/XUIPanel.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIPlayTween.cs | 153 +++ .../Assets/Scripts/UICommon/XUIPlayTween.cs.meta | 8 + .../Assets/Scripts/UICommon/XUIPlayTweenGroup.cs | 43 + .../Scripts/UICommon/XUIPlayTweenGroup.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIPopupList.cs | 47 + .../Assets/Scripts/UICommon/XUIPopupList.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIPressTips.cs | 18 + .../Assets/Scripts/UICommon/XUIPressTips.cs.meta | 12 + Client/Assets/Scripts/UICommon/XUIProgress.cs | 301 ++++++ Client/Assets/Scripts/UICommon/XUIProgress.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIScript.cs | 31 + Client/Assets/Scripts/UICommon/XUIScript.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIScrollBar.cs | 42 + .../Assets/Scripts/UICommon/XUIScrollBar.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIScrollView.cs | 84 ++ .../Assets/Scripts/UICommon/XUIScrollView.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUISimpleList.cs | 85 ++ .../Assets/Scripts/UICommon/XUISimpleList.cs.meta | 12 + Client/Assets/Scripts/UICommon/XUISlider.cs | 52 + Client/Assets/Scripts/UICommon/XUISlider.cs.meta | 8 + .../Assets/Scripts/UICommon/XUISpecLabelSymbol.cs | 131 +++ .../Scripts/UICommon/XUISpecLabelSymbol.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUISprite.cs | 495 +++++++++ Client/Assets/Scripts/UICommon/XUISprite.cs.meta | 8 + .../Assets/Scripts/UICommon/XUISpriteAnimation.cs | 74 ++ .../Scripts/UICommon/XUISpriteAnimation.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUITable.cs | 32 + Client/Assets/Scripts/UICommon/XUITable.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUITexture.cs | 203 ++++ Client/Assets/Scripts/UICommon/XUITexture.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUITool.cs | 279 +++++ Client/Assets/Scripts/UICommon/XUITool.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUITweener.cs | 33 + Client/Assets/Scripts/UICommon/XUITweener.cs.meta | 8 + Client/Assets/Scripts/UICommon/XUIWrapContent.cs | 201 ++++ .../Assets/Scripts/UICommon/XUIWrapContent.cs.meta | 8 + 78 files changed, 6172 insertions(+) create mode 100644 Client/Assets/Scripts/UICommon/ResizeCanvas.cs create mode 100644 Client/Assets/Scripts/UICommon/ResizeCanvas.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XDlgControler.cs create mode 100644 Client/Assets/Scripts/UICommon/XDlgControler.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XRadarMap.cs create mode 100644 Client/Assets/Scripts/UICommon/XRadarMap.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XSthCollector.cs create mode 100644 Client/Assets/Scripts/UICommon/XSthCollector.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIAtlas.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIAtlas.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIButton.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIButton.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUICenterOnClick.cs create mode 100644 Client/Assets/Scripts/UICommon/XUICenterOnClick.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUICheckBox.cs create mode 100644 Client/Assets/Scripts/UICommon/XUICheckBox.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIComboBox.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIComboBox.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUICommon.cs create mode 100644 Client/Assets/Scripts/UICommon/XUICommon.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIDragDropItem.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIDragDropItem.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIInput.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIInput.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUILabel.cs create mode 100644 Client/Assets/Scripts/UICommon/XUILabel.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUILabelSymbol.cs create mode 100644 Client/Assets/Scripts/UICommon/XUILabelSymbol.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIList.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIList.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUILongPress.cs create mode 100644 Client/Assets/Scripts/UICommon/XUILongPress.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIObject.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIObject.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIPanel.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIPanel.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIPlayTween.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIPlayTween.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIPopupList.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIPopupList.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIPressTips.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIPressTips.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIProgress.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIProgress.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIScript.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIScript.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIScrollBar.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIScrollBar.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIScrollView.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIScrollView.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUISimpleList.cs create mode 100644 Client/Assets/Scripts/UICommon/XUISimpleList.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUISlider.cs create mode 100644 Client/Assets/Scripts/UICommon/XUISlider.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs create mode 100644 Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUISprite.cs create mode 100644 Client/Assets/Scripts/UICommon/XUISprite.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs create mode 100644 Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUITable.cs create mode 100644 Client/Assets/Scripts/UICommon/XUITable.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUITexture.cs create mode 100644 Client/Assets/Scripts/UICommon/XUITexture.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUITool.cs create mode 100644 Client/Assets/Scripts/UICommon/XUITool.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUITweener.cs create mode 100644 Client/Assets/Scripts/UICommon/XUITweener.cs.meta create mode 100644 Client/Assets/Scripts/UICommon/XUIWrapContent.cs create mode 100644 Client/Assets/Scripts/UICommon/XUIWrapContent.cs.meta (limited to 'Client/Assets/Scripts/UICommon') diff --git a/Client/Assets/Scripts/UICommon/ResizeCanvas.cs b/Client/Assets/Scripts/UICommon/ResizeCanvas.cs new file mode 100644 index 00000000..fd99e646 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/ResizeCanvas.cs @@ -0,0 +1,22 @@ +using System; +using UnityEngine; + +[RequireComponent(typeof(UISprite))] +public class ResizeCanvas : MonoBehaviour { + + // Use this for initialization + public void Awake () { + + } + + public void Start() + { + UIRoot rt = NGUITools.FindInParents(gameObject); + + UISprite sp = GetComponent(); + + sp.height = Math.Min(rt.base_ui_height, rt.manualHeight); + } + + +} diff --git a/Client/Assets/Scripts/UICommon/ResizeCanvas.cs.meta b/Client/Assets/Scripts/UICommon/ResizeCanvas.cs.meta new file mode 100644 index 00000000..28fee499 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/ResizeCanvas.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67337bbfa0260204a868d53b6875c205 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XDlgControler.cs b/Client/Assets/Scripts/UICommon/XDlgControler.cs new file mode 100644 index 00000000..66f55207 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XDlgControler.cs @@ -0,0 +1,110 @@ +using UnityEngine; +using System.Collections; +using XUtliPoolLib; + +public class XDlgControler : MonoBehaviour +{ + public GameObject m_CachedDlg; + + private IXGameUI m_gameui = null; + //private bool bFirstFrame; + void Awake() + { + if (m_CachedDlg == null) + { + m_CachedDlg = gameObject; + } + + if(m_CachedDlg.GetComponent() == null) + { + m_CachedDlg.AddComponent(); + } + + transform.GetComponent().tweenTarget = m_CachedDlg; + + m_gameui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + GameObject tpl = m_gameui.DlgControllerTpl; + + bool group1 = false; + bool group2 = false; + + TweenScale[] scales = m_CachedDlg.GetComponents(); + for (int i = 0; i < scales.Length; ++i) + { + if (scales[i].tweenGroup == 1) group1 = true; + if (scales[i].tweenGroup == 2) group2 = true; + } + + scales = tpl.GetComponents(); + for (int i = 0; i < scales.Length; ++i) + { + if (group1 && scales[i].tweenGroup == 1) continue; + if (group2 && scales[i].tweenGroup == 2) continue; + TweenScale s = m_CachedDlg.AddComponent(); + s.from = scales[i].from; + s.to = scales[i].to; + s.style = scales[i].style; + s.animationCurve = scales[i].animationCurve; + s.duration = scales[i].duration; + s.delay = scales[i].delay; + s.tweenGroup = scales[i].tweenGroup; + s.ignoreTimeScale = scales[i].ignoreTimeScale; + + s.enabled = false; + } + + group1 = false; + group2 = false; + TweenPosition[] positions = m_CachedDlg.GetComponents(); + for (int i = 0; i < positions.Length; ++i) + { + if (positions[i].tweenGroup == 1) group1 = true; + if (positions[i].tweenGroup == 2) group2 = true; + } + + positions = tpl.GetComponents(); + for (int i = 0; i < positions.Length; ++i) + { + if (group1 && positions[i].tweenGroup == 1) continue; + if (group2 && positions[i].tweenGroup == 2) continue; + TweenPosition p = m_CachedDlg.AddComponent(); + p.from = positions[i].from; + p.to = positions[i].to; + p.style = positions[i].style; + p.animationCurve = positions[i].animationCurve; + p.duration = positions[i].duration; + p.delay = positions[i].delay; + p.tweenGroup = positions[i].tweenGroup; + p.ignoreTimeScale = positions[i].ignoreTimeScale; + + p.enabled = false; + } + + group1 = false; + group2 = false; + TweenAlpha[] alphas = m_CachedDlg.GetComponents(); + for (int i = 0; i < alphas.Length; ++i) + { + if (alphas[i].tweenGroup == 1) group1 = true; + if (alphas[i].tweenGroup == 2) group2 = true; + } + + alphas = tpl.GetComponents(); + for (int i = 0; i < alphas.Length; ++i) + { + if (group1 && alphas[i].tweenGroup == 1) continue; + if (group2 && alphas[i].tweenGroup == 2) continue; + TweenAlpha a = m_CachedDlg.AddComponent(); + a.from = alphas[i].from; + a.to = alphas[i].to; + a.style = alphas[i].style; + a.animationCurve = alphas[i].animationCurve; + a.duration = alphas[i].duration; + a.delay = alphas[i].delay; + a.tweenGroup = alphas[i].tweenGroup; + a.ignoreTimeScale = alphas[i].ignoreTimeScale; + + a.enabled = false; + } + } +} diff --git a/Client/Assets/Scripts/UICommon/XDlgControler.cs.meta b/Client/Assets/Scripts/UICommon/XDlgControler.cs.meta new file mode 100644 index 00000000..021a48cd --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XDlgControler.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8ef81dd183f2e8b4f90c02355149da6a +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XRadarMap.cs b/Client/Assets/Scripts/UICommon/XRadarMap.cs new file mode 100644 index 00000000..87fff5f6 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XRadarMap.cs @@ -0,0 +1,145 @@ +using UnityEngine; +using System.Collections; +using UILib; + +public class XRadarMap : MonoBehaviour,IXRadarMap { + + // Use this for initialization + public Vector3[] m_vertices; + public Vector2[] m_uv; + public Color[] m_color; + public Vector3[] m_normals; + public int[] m_triangles; + private Mesh m_mesh; + private MeshFilter m_meshFilter; + private bool m_reposition = true; + //private float m_verticeValue = 1.0f; + void Awake() + { + m_mesh = new Mesh(); + m_meshFilter = GetComponent(); + m_vertices = new Vector3[4] + { + new Vector3(0,0,0), + new Vector3(1,0,0), + new Vector3(0,1,0), + new Vector3(1,1,0) + }; + m_uv = new Vector2[4] + { + new Vector2(0,0), + new Vector2(1,0), + new Vector2(0,1), + new Vector2(1,1) + }; + + m_triangles = new int[6] // 两个三角面的连接 + { + 0,1,2,// 通过顶点012连接形成的三角面 + 1,3,2,// 通过顶点132连接形成的三角面 + }; + } + + + + public void SetSite(int pos , float value ) + { + switch (pos) + { + case 2: + SetLeftSite(value); + break; + case 1: + SetRightSite(value); + break; + case 3: + SetUpSite(value); + break; + case 0: + SetBottomSite(value); + break; + } + repositionNow = true; + } + + private void SetLeftSite(float value) + { + value *= 0.25f; + m_vertices[2].y = 0.75f+value; + m_vertices[2].x = 0.25f-value; + } + + /// + /// 下 + /// + /// + private void SetBottomSite(float value) + { + value *= 0.25f; + m_vertices[0].x = 0.25f - value; + m_vertices[0].y = 0.25f - value; + } + + private void SetRightSite(float value) + { + value *= 0.25f; + m_vertices[1].x = 0.75f + value; + m_vertices[1].y = 0.25f - value; + } + /// + /// 上边 + /// + /// + private void SetUpSite(float value) + { + value *= 0.25f; + m_vertices[3].x = 0.75f + value; ; + m_vertices[3].y = 0.75f + value; + } + public bool repositionNow + { + set { m_reposition = value; } + } + + + void Update() + { + if (!m_reposition) return; + Reposition(); + + } + + // Update is called once per frame + [ContextMenu("Execute")] + private void Reposition() + { + + m_reposition = false; + + m_mesh.Clear(); + + + m_mesh.vertices = m_vertices; + + + m_mesh.uv = m_uv; + + + m_mesh.colors = m_color; + + + m_mesh.normals = m_normals; + + + m_mesh.triangles = m_triangles; + + + m_mesh.RecalculateNormals(); + m_meshFilter.mesh = m_mesh; + } + + public void Refresh() + { + repositionNow = true; + } +} diff --git a/Client/Assets/Scripts/UICommon/XRadarMap.cs.meta b/Client/Assets/Scripts/UICommon/XRadarMap.cs.meta new file mode 100644 index 00000000..aa3ca1cc --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XRadarMap.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0e297897de0e8a3449874bf0ce7782f8 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XSthCollector.cs b/Client/Assets/Scripts/UICommon/XSthCollector.cs new file mode 100644 index 00000000..df3b7a12 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XSthCollector.cs @@ -0,0 +1,351 @@ +using UILib; +using UnityEngine; +using System.Collections.Generic; +using XUtliPoolLib; + +public class XSthCollector : XUIObject, IXUISthCollector +{ + public List SthList = new List(); + + public Vector3 Src = new Vector3(0, 0, 0); + public Vector3 Des = new Vector3(-450, -280, 0); + + public int Count = 15; + public float EmitInterval = 0.01f; + + public int EmitDegreeRange = 300; + public float MinEmitSpeed = 1900; + public float MaxEmitSpeed = 2100; + + public float SrcAcceleration = 20000; + public float DesAcceleration = 8000; + public float SthAcceleration = 10000; + + public float MinStartFindDesTime = 0.3f; + public float MaxStartFindDesTime = 0.6f; + + public float MinIdleSpeed = 30; + List m_SthList = null; + bool m_bActive; + + //string m_CurName; + GameObject m_CurSthGo; + + //Dictionary> m_SthListMap = new Dictionary>(); + Dictionary m_SthTplMap = new Dictionary(); + List m_ExternalSthList = new List(); + + Vector3 m_Direction; + SthArrivedEventHandler m_SthArrivedEventHandler; + CollectFinishEventHandler m_CollectFinishEventHandler; + + int m_ArrivedCount; + void Awake() + { + for (int i = 0; i < SthList.Count; ++i) + { + m_SthTplMap.Add(SthList[i].name, SthList[i]); + SthList[i].SetActive(false); + } + m_Direction = (Des - Src).normalized; + } + void OnEnable() + { + m_bActive = false; + + if (m_SthList != null) + { + for (int i = 0; i < m_SthList.Count; ++i) + { + m_SthList[i].bEnable = false; + } + } + } + + public void SetPosition(Vector3 srcGlobalPos, Vector3 desGlobalPos) + { + Src = transform.worldToLocalMatrix * srcGlobalPos; + Des = transform.worldToLocalMatrix * desGlobalPos; + m_Direction = (Des - Src).normalized; + } + + public void SetSth(List goes) + { + for (int i = m_ExternalSthList.Count; i < goes.Count; ++i) + { + XSth sth = new XSth(); + m_ExternalSthList.Add(sth); + } + for (int i = m_ExternalSthList.Count - 1; i >= goes.Count; --i) + { + m_ExternalSthList.RemoveAt(i); + } + m_SthList = m_ExternalSthList; + + for (int i = 0; i < m_ExternalSthList.Count; ++i) + { + m_SthList[i].Go = goes[i]; + goes[i].SetActive(false); + m_SthList[i].bEnable = false; + } + } + + public void SetSth(string name) + { + //if (m_SthList != null && m_CurName != name) + //{ + // for (int i = 0; i < m_SthList.Count; ++i) + // { + // m_SthList[i].bEnable = false; + // } + //} + //if (!m_SthTplMap.TryGetValue(name, out m_CurSthGo)) + //{ + // Debug.LogError("Cant find tpl name: " + name); + // return; + //} + + //if (!m_SthListMap.TryGetValue(name, out m_SthList)) + //{ + // m_SthList = new List(); + // m_SthListMap.Add(name, m_SthList); + //} + + //_GenerateSth(); + } + + private void _GenerateSth() + { + if (m_SthList.Count != Count) + { + m_CurSthGo.SetActive(true); + for (int i = m_SthList.Count; i < Count; ++i) + { + XSth sth = new XSth(); + GameObject go = UnityEngine.Object.Instantiate(m_CurSthGo) as GameObject; + go.transform.parent = transform; + go.transform.localScale = Vector3.one; + sth.Go = go; + go.SetActive(false); + m_SthList.Add(sth); + } + m_CurSthGo.SetActive(false); + + for (int i = m_SthList.Count - 1; i >= Count; --i) + { + m_SthList[i].Destroy(); + m_SthList.RemoveAt(i); + } + } + + for (int i = 0; i < m_SthList.Count; ++i) + { + m_SthList[i].bEnable = false; + } + } + + [ContextMenu("Emit")] + public void Emit() + { + float fDelayTime = 0.0f; + for (int i = 0; i < m_SthList.Count; ++i, fDelayTime += EmitInterval) + { + XSth sth = m_SthList[i]; + sth.DelayTime = fDelayTime; + + sth.Speed = XCommon.singleton.RandomFloat(MinEmitSpeed, MaxEmitSpeed) * _RandEmitDir(); + sth.StartFindDesTime = XCommon.singleton.RandomFloat(MinStartFindDesTime, MaxStartFindDesTime); + sth.Time = 0.0f; + sth.MinIdleSpeed = MinIdleSpeed; + sth.Go.transform.localPosition = Src;// transform.worldToLocalMatrix* Src; + sth.Des = Des;// transform.worldToLocalMatrix* Des; + sth.bEnable = true; + } + m_bActive = true; + m_ArrivedCount = 0; + } + + Vector3 _RandEmitDir() + { + float radRange = EmitDegreeRange * Mathf.Deg2Rad; + float rad = XCommon.singleton.RandomFloat(radRange) - radRange / 2; + float sinA = Mathf.Sin(rad); + float cosA = Mathf.Cos(rad); + + Vector3 vec = m_Direction; + vec.x = m_Direction.x * cosA - m_Direction.y * sinA; + vec.y = m_Direction.x * sinA + m_Direction.y * cosA; + + return vec; + } + + Vector3 _GetAcceleration(XSth sth, float t) + { + Vector3 curPos = sth.Go.transform.localPosition; + Vector3 acc = Vector3.zero; + + Vector3 gDes = (Des - curPos).normalized; + if (sth.State == XSth.SthState.FLAME_OUT) + { + acc += gDes * DesAcceleration; + } + + Vector3 gSrc = (Src - curPos).normalized; + if (sth.State == XSth.SthState.IDLE) + { + acc += gSrc * SrcAcceleration; + } + + if (sth.State == XSth.SthState.DIRECTION_ADJUSTING) + { + float desCross = gDes.x * sth.Speed.y - gDes.y * sth.Speed.x; + + Vector3 perpendicular = new Vector3(-sth.Speed.y, sth.Speed.x, sth.Speed.z); + if ((perpendicular.x * sth.Speed.y - perpendicular.y * sth.Speed.x) * desCross < 0) + { + perpendicular.x = -perpendicular.x; + perpendicular.y = -perpendicular.y; + } + perpendicular = perpendicular.normalized * SthAcceleration; + acc += perpendicular; + } + + return acc; + } + + void Update() + { + if (!m_bActive) + return; + + m_bActive = false; + for (int i = 0; i < m_SthList.Count; ++i) + { + XSth sth = m_SthList[i]; + if (!sth.bEnable) + continue; + m_bActive = true; + + if (!sth.Update(Time.deltaTime)) + { + if (m_SthArrivedEventHandler != null) + m_SthArrivedEventHandler(m_ArrivedCount++); + } + + if (sth.DelayTime <= 0.0f) + sth.Acceleration = _GetAcceleration(sth, Time.deltaTime); + } + + if (!m_bActive && m_CollectFinishEventHandler != null) + m_CollectFinishEventHandler(); + } + + public void RegisterSthArrivedEventHandler(SthArrivedEventHandler eventHandler) + { + m_SthArrivedEventHandler = eventHandler; + } + + public void RegisterCollectFinishEventHandler(CollectFinishEventHandler eventHandler) + { + m_CollectFinishEventHandler = eventHandler; + } +} + +public class XSth +{ + public enum SthState + { + IDLE, + DIRECTION_ADJUSTING, + FLAME_OUT + } + public GameObject Go; + public Vector3 Speed; + public float MinIdleSpeed; + public Vector3 Acceleration; + public float Time; + public float DelayTime; + public float StartFindDesTime; + public Vector3 Des; + public SthState State; + + private bool m_bEnable = false; + public bool bEnable + { + get { return m_bEnable; } + set + { + m_bEnable = value; + Acceleration = Vector3.zero; + State = SthState.IDLE; + if (!m_bEnable) + { + Go.SetActive(false); + } + } + } + + public void Destroy() + { + UnityEngine.Object.Destroy(Go); + } + + public bool Update(float t) + { + if (!bEnable) + return bEnable; + + if (DelayTime > 0.0f) + { + DelayTime -= t; + if (DelayTime > 0.0f) + return true; + t = -DelayTime; + } + + Time += t; + + Vector3 newSpeed = Speed + (Acceleration * t); + + Vector3 pos = Go.transform.localPosition; + + if (State == SthState.IDLE) + { + if (newSpeed.x * Speed.x + newSpeed.y * Speed.y <= 0) + { + // ٶȼˣԼٶ + newSpeed = Speed.normalized * MinIdleSpeed; + } + + if (Time > StartFindDesTime) + { + State = SthState.DIRECTION_ADJUSTING; + } + } + if (State == SthState.DIRECTION_ADJUSTING) + { + Vector3 desDir = Des - pos; + float crossProduct0 = Speed.x * desDir.y - Speed.y * desDir.x; + float crossProduct1 = desDir.x * newSpeed.y - desDir.y * newSpeed.x; + + if (crossProduct0 * crossProduct1 > 0) + { + newSpeed = newSpeed.magnitude * desDir.normalized; + State = SthState.FLAME_OUT; + } + } + if (!Go.activeSelf) + Go.SetActive(true); + + Speed = newSpeed; + + Vector3 newPos = pos + Speed * t; + if ((newPos - pos).sqrMagnitude >= (Des - pos).sqrMagnitude) + bEnable = false; + else + Go.transform.localPosition = newPos; + + return bEnable; + } +} + diff --git a/Client/Assets/Scripts/UICommon/XSthCollector.cs.meta b/Client/Assets/Scripts/UICommon/XSthCollector.cs.meta new file mode 100644 index 00000000..af068e8b --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XSthCollector.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3267a6768fdee564ba55d89193a84ef3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIAtlas.cs b/Client/Assets/Scripts/UICommon/XUIAtlas.cs new file mode 100644 index 00000000..d7291535 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIAtlas.cs @@ -0,0 +1,27 @@ +using UILib; +using UnityEngine; + + +public class XUIAtlas : MonoBehaviour, IXUIAtlas +{ + public UIAtlas atlas + { + get { return m_uiAtlas; } + } + + void Awake() + { + m_uiAtlas = GetComponent(); + if (null == m_uiAtlas) + { + Debug.LogError("null == m_uiAtlas"); + } + } + + void OnDisable() + { + m_uiAtlas = null; + } + private UIAtlas m_uiAtlas = null; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIAtlas.cs.meta b/Client/Assets/Scripts/UICommon/XUIAtlas.cs.meta new file mode 100644 index 00000000..b260bd2c --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIAtlas.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5806b63d4fab4704a862c57eac7d523d +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs new file mode 100644 index 00000000..81ecac3d --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using UnityEngine; +using System; +[ExecuteInEditMode] +public class XUIAtlasSelector : MonoBehaviour { + + [Serializable] + public class AtlasInfo + { + [SerializeField] + public string atlasName; + [SerializeField] + public int startDepth = 0; + [SerializeField] + public List list = new List(); + } + + [SerializeField] + public Dictionary atlasInfos; + [SerializeField] + public int widgetSize = 0; + + // Use this for initialization + void Start () { + Setup(); + } + [ContextMenu("Execute")] + public void Excute() + { + Setup(); + } + + private void Setup() + { + if (atlasInfos == null) atlasInfos = new Dictionary(); + UISprite[] uiSprites = transform.GetComponentsInChildren(); + widgetSize = uiSprites.Length; + UISprite widget; + string nullAtlas = "NullAtlas"; + int i, length; + for (i = 0,length = uiSprites.Length; i < length; i++) + { + widget = uiSprites[i]; + if (widget.atlas != null) + { + Insert(atlasInfos, widget.atlas.name, widget); + } + else + { + Insert(atlasInfos, nullAtlas, widget); + } + } + string fontName = "Font"; + UILabel[] fonts = transform.GetComponentsInChildren(); + widgetSize += fonts.Length; + for (i = 0, length = fonts.Length; i < length; i++) + { + if(fonts[i].bitmapFont != null) + { + Insert(atlasInfos, "bitmapFont:" + fontName, fonts[i]); + } + else + { + Insert(atlasInfos, fontName, fonts[i]); + } + + } + foreach (KeyValuePair info in atlasInfos) + { + info.Value.list.Sort(SortCompare); + if (info.Value.list.Count > 0) + { + info.Value.startDepth = info.Value.list[0].depth; + } + } + } + + private int SortCompare(UIWidget widget1, UIWidget widget2 ) + { + return widget1.depth - widget2.depth; + } + + private void Insert(Dictionary infos ,string atlasName , UIWidget widget) + { + AtlasInfo info; + if(!infos.TryGetValue(atlasName,out info)) + { + info = new AtlasInfo(); + info.atlasName = atlasName; + infos.Add(atlasName,info); + } + info.list.Add(widget); + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs.meta b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs.meta new file mode 100644 index 00000000..56da2e02 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIAtlasSelector.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b6c750633a4b15048ba7d4c1a49ebb4a +timeCreated: 1501654533 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs b/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs new file mode 100644 index 00000000..dafd0193 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs @@ -0,0 +1,19 @@ +using UILib; +using UnityEngine; +using System.Collections; +using XUtliPoolLib; + +public class XUIBillBoardCompRef : MonoBehaviour, IXUIBillBoardCompRef +{ + public XUISpecLabelSymbol _NameSpecLabelSymbol; + public XUISpecLabelSymbol _GuildSpecLabelSymbol; + public XUISpecLabelSymbol _DesiSpecLabelSymbol; + public XUIProgress _BloodBar; + public XUIProgress _IndureBar; + + public IXUISpecLabelSymbol NameSpecLabelSymbol { get { return _NameSpecLabelSymbol; } } + public IXUISpecLabelSymbol GuildSpecLabelSymbol { get { return _GuildSpecLabelSymbol; } } + public IXUISpecLabelSymbol DesiSpecLabelSymbol { get { return _DesiSpecLabelSymbol; } } + public IXUIProgress BloodBar { get { return _BloodBar; } } + public IXUIProgress IndureBar { get { return _IndureBar; } } +} diff --git a/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs.meta b/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs.meta new file mode 100644 index 00000000..41da427d --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIBillBoardCompRef.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6c57f16d3fa0d1b4ba10189a04559568 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIButton.cs b/Client/Assets/Scripts/UICommon/XUIButton.cs new file mode 100644 index 00000000..5a10bf09 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIButton.cs @@ -0,0 +1,440 @@ +using UILib; +using XUtliPoolLib; +using UnityEngine; +using System.Collections.Generic; + +public class XUIButton : XUIObject, IXUIButton +{ + private static List tmpLabel = new List(); + private static List tmpXLabel = new List(); + private static List tmpSprite = new List(); + private static Color black = new Color(0.0f, 0.0f, 0.0f, 1.0f); + + private UIEventListener eventListenerCache = null; + public int spriteWidth + { + get + { + return m_uiSpriteBG.width; + } + } + + public int spriteHeight + { + get + { + return m_uiSpriteBG.height; + } + } + + public int spriteDepth + { + get + { + return m_uiSpriteBG.depth; + } + set + { + m_uiSpriteBG.depth = value; + } + } + + public void SetSpriteWithPrefix(string prefix) + { + m_uiButton.normalSprite = prefix + "_0"; + m_uiButton.hoverSprite = prefix + "_0"; + m_uiButton.pressedSprite = prefix + "_1"; + } + + public void SetSprites(string normal, string hover, string press) + { + m_uiButton.normalSprite = normal; + m_uiButton.hoverSprite = hover; + m_uiButton.pressedSprite = press; + } + + public void SetCaption(string strText) + { + GetComponentsInChildren(true, tmpLabel); + if (tmpLabel.Count > 0) + { + tmpLabel[0].text = strText; + } + tmpLabel.Clear(); + } + + public void SetEnable(bool bEnable, bool withcollider = false) + { + if (m_bEnabled!=bEnable) + { + if (!bEnable) + { + if (m_state) + _ButtonPress(gameObject, false); + + m_bEnabled = bEnable; + } + else + { + m_bEnabled = bEnable; + + if (m_state) + _ButtonPress(gameObject, true); + } + } + + + if (null != m_colliderCached) + { + m_colliderCached.enabled = bEnable || withcollider; + } + + if (null != m_uiButtonColor) + { + m_uiButtonColor.enabled = bEnable || withcollider; + } + + if (null != m_uiButtonScale) + { + m_uiButtonScale.enabled = bEnable; + } + + if (null != m_uiButtonOffset) + { + m_uiButtonOffset.enabled = bEnable; + } + if (null != m_uiSpriteBG) + { + m_uiSpriteBG.color = bEnable ? Color.white : XUISprite.GREY_COLOR; + + gameObject.GetComponentsInChildren(true, tmpSprite); + + for (int i = 0; i < tmpSprite.Count; i++) + { + tmpSprite[i].color = bEnable ? Color.white : XUISprite.GREY_COLOR; + } + tmpSprite.Clear(); + } + + gameObject.GetComponentsInChildren(tmpXLabel); + for (int i = 0; i < tmpXLabel.Count; i++) + { + tmpXLabel[i].SetEnabled(bEnable); + } + tmpXLabel.Clear(); + } + + public void SetGrey(bool bGrey) + { + if (null != m_uiSpriteBG) + { + m_uiSpriteBG.color = bGrey ? Color.white : new Color(0.0f, 0.0f, 0.0f, 1); + + m_uiButtonColor.defaultColor = bGrey ? Color.white : black; + m_uiButtonColor.hover = bGrey ? Color.white : black; + m_uiButtonColor.pressed = bGrey ? Color.white : black; + + gameObject.GetComponentsInChildren(tmpSprite); + + for (int i = 0; i < tmpSprite.Count; i++) + { + tmpSprite[i].color = bGrey ? Color.white : black; + } + tmpSprite.Clear(); + } + } + + public void CloseScrollView() + { + UIDragScrollView m_ScrollView = GetComponent(); + if (m_ScrollView != null) + { + m_ScrollView.enabled = false; + } + } + + public void ResetPanel() + { + m_uiSpriteBG.panel = null; + } + + private UIEventListener GetUIEventListener() + { + if (eventListenerCache == null) + { + eventListenerCache = UIEventListener.Get(this.gameObject); + } + return eventListenerCache; + } + public void RegisterClickEventHandler(ButtonClickEventHandler eventHandler) + { + //UIButtonMessage uiButtonMessage = GetComponent(); + //if (null == uiButtonMessage) + //{ + // uiButtonMessage = gameObject.AddComponent(); + //} + //uiButtonMessage.functionName = "OnButtonClick"; + + GetUIEventListener().onClick -= OnButtonClick; + GetUIEventListener().onClick += OnButtonClick; + + m_buttonClickEventHandler = eventHandler; + } + + public ButtonClickEventHandler GetClickEventHandler() + { + return m_buttonClickEventHandler; + } + + public ButtonPressEventHandler GetPressEventHandler() + { + return m_buttonPressEventHandler; + } + + public void ResetState() + { + m_state = false; + } + + public void RegisterPressEventHandler(ButtonPressEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onPress = OnButtonPressed; + m_buttonPressEventHandler = eventHandler; + } + + public void RegisterDragEventHandler(ButtonDragEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onDrag = OnButtonDrag; + m_buttonDragEventHandler = eventHandler; + } + + void OnButtonPressed(GameObject button, bool state) + { + m_state = state; + + if (!m_bEnabled) return; + + _ButtonPress(button, state); + } + + void OnButtonDrag(GameObject button, Vector2 delta) + { + if (!m_bEnabled) return; + + if (m_buttonDragEventHandler != null) + m_buttonDragEventHandler(this, delta); + } + + private void _ButtonPress(GameObject button, bool state) + { + if (m_tutorial != null && m_tutorial.NoforceClick && Exculsive) + { + if (null != m_buttonPressEventHandler) + { + //if (m_operation != null) m_operation.FindRecordID(button.transform); + m_buttonPressEventHandler(this, state); + + if (state) + m_tutorial.OnTutorialClicked(); + } + } + if (m_tutorial == null || !m_tutorial.Exculsive) + { + if (null != m_buttonPressEventHandler) + { + //if (m_operation != null && state) m_operation.FindRecordID(button.transform); + m_buttonPressEventHandler(this, state); + + } + } + else if (m_tutorial.Exculsive && Exculsive) + { + if (null != m_buttonPressEventHandler) + { + m_buttonPressEventHandler(this, state); + //if (m_operation != null && state) m_operation.FindRecordID(button.transform); + + if (state) m_tutorial.OnTutorialClicked(); + } + } + else + { + XDebug.singleton.AddLog("Exculsive block"); + } + } + + void OnButtonClick(GameObject button) + { + if (!m_bEnabled) return; + + if (m_CD.IsInCD()) + return; + + if (m_tutorial != null && m_tutorial.NoforceClick && Exculsive) + { + if (null != m_buttonClickEventHandler) + { + m_buttonClickEventHandler(this); + m_tutorial.OnTutorialClicked(); + } + } + else if (m_tutorial == null || !m_tutorial.Exculsive) + { + if (null != m_buttonClickEventHandler) + { + m_buttonClickEventHandler(this); + //if (m_operation != null) m_operation.FindRecordID(button.transform); + } + } + else if (m_tutorial.Exculsive && Exculsive) + { + if (null != m_buttonClickEventHandler) + { + m_buttonClickEventHandler(this); + //if (m_operation != null) m_operation.FindRecordID(button.transform); + + m_tutorial.OnTutorialClicked(); + } + } + else + { + XDebug.singleton.AddLog("Exculsive block"); + } + + if (m_NeedAudio && !string.IsNullOrEmpty(audioClip)) + NGUITools.PlayFmod("event:/" + audioClip); + } + + public void SetAlpha(float f) + { + m_uiSpriteBG.alpha = f; + m_uiButtonColor.defaultColor = new Color(m_uiButtonColor.defaultColor.r, m_uiButtonColor.defaultColor.g, m_uiButtonColor.defaultColor.b, f); + m_uiButtonColor.hover.a = f; + m_uiButtonColor.pressed.a = f; + } + + protected override void OnAwake() + { + base.OnAwake(); + + m_gameui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + m_tutorial = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XTutorial")); + //m_operation = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XOperationRecord")); + m_uiButton = GetComponent(); + + m_uiButtonColor = m_uiButton as UIButtonColor;// GetComponent(); + + m_uiButtonScale = GetComponent(); + + m_uiButtonOffset = GetComponent(); + + + m_uiSpriteBG = GetComponentInChildren(); +#if UNITY_EDITOR + if (null == m_uiSpriteBG) + { + XDebug.singleton.AddLog("null == m_uiSpriteBG"); + } +#endif + if (m_uiButton!=null) + m_colliderCached = m_uiButton.cacheCol; + else + m_colliderCached = GetComponent(); +#if UNITY_EDITOR + if (null == m_colliderCached) + { + XDebug.singleton.AddLog("null == m_colliderCached:", gameObject.name); + } +#endif + CloneFromTpl(); + + if (m_NeedAudio && (string.IsNullOrEmpty(audioClip) || !audioClip.StartsWith("Audio"))) + SetAudioClip("Audio/UI/UI_Button_ok"); + + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + + if (m_uiButton != null) + m_uiButton.changeStateSprite = ChangeStateSprite; + } + + protected void CloneFromTpl() + { + if (m_ButtonAnimationType <= 0) return; + + GameObject tpl = m_gameui.buttonTpl[m_ButtonAnimationType - 1]; + + XUICommon.CloneTplTweens(tpl, gameObject); + + if (m_useSprite) + { + UISprite srcSp = tpl.GetComponent(); + UIButton srcBtn = tpl.GetComponent(); + + UISprite dstSp = gameObject.GetComponent(); + UIButton dstBtn = gameObject.GetComponent(); + + dstSp.spriteName = srcSp.spriteName; + dstBtn.normalSprite = srcBtn.normalSprite; + dstBtn.hoverSprite = srcBtn.hoverSprite; + dstBtn.pressedSprite = srcBtn.pressedSprite; + } + } + + public void SetAudioClip(string name) + { + if (m_NeedAudio == false) + return; + + audioClip = name; + } + + public void SetClickCD(float cd) + { + CustomClickCD = cd; + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + } + + public void ResetCD() + { + m_CD.Reset(); + } + + public void SetUnavailableCD(int cd) + { + m_CD.SetUnavailableCD(cd); + } + + public int m_ButtonAnimationType = 0; + public bool ChangeStateSprite = false; + public bool m_useSprite = false; + public string audioClip; + public bool m_NeedAudio = true; + + public float CustomClickCD = -1f; + public int CustomClickCDGroup = 0; + + private XUICD m_CD = new XUICD(); + + [Range(0f, 1f)] + public float volume = 1f; + [Range(0f, 2f)] + public float pitch = 1f; + + private UIButtonOffset m_uiButtonOffset = null; + private UIButtonScale m_uiButtonScale = null; + private UIButtonColor m_uiButtonColor = null; + private UIButton m_uiButton = null; + private Collider m_colliderCached = null; + private UISprite m_uiSpriteBG = null; + private bool m_bEnabled = true; + + private IXTutorial m_tutorial = null; + private IXGameUI m_gameui = null; + //private IXOperationRecord m_operation = null; + + private ButtonClickEventHandler m_buttonClickEventHandler = null; + private ButtonPressEventHandler m_buttonPressEventHandler = null; + private ButtonDragEventHandler m_buttonDragEventHandler = null; + private bool m_state = false; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIButton.cs.meta b/Client/Assets/Scripts/UICommon/XUIButton.cs.meta new file mode 100644 index 00000000..6873de60 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIButton.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 683bb104c89ce8149a8a5723bd770432 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs b/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs new file mode 100644 index 00000000..a1f7cffc --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs @@ -0,0 +1,25 @@ +using System; +using UILib; +using UnityEngine; + +public class XUICenterOnClick : XUIObject, IXUICenterOnClick +{ + + protected override void OnAwake() + { + base.OnAwake(); + m_uiCenterOnClick = GetComponent(); + if (null == m_uiCenterOnClick) + { + Debug.LogError("null == m_uiCenterOnClick"); + } + } + + public void OnClick() + { + m_uiCenterOnClick.OnClick(); + } + + private UICenterOnClick m_uiCenterOnClick = null; +} + diff --git a/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs.meta b/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs.meta new file mode 100644 index 00000000..8a93a6e9 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICenterOnClick.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0244d8e66861f4247870d92d667d4758 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUICheckBox.cs b/Client/Assets/Scripts/UICommon/XUICheckBox.cs new file mode 100644 index 00000000..f9e6de78 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICheckBox.cs @@ -0,0 +1,173 @@ +using System; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUICheckBox : XUIObject, IXUICheckBox +{ + public bool bChecked + { + get { return m_uiToggle.value; } + set + { + m_uiToggle.value = value; + } + } + + public int spriteHeight + { + get + { + return m_uiSpriteBG.height; + } + set + { + m_uiSpriteBG.height = value; + } + } + + public int spriteWidth + { + get + { + return m_uiSpriteBG.width; + } + set + { + m_uiSpriteBG.width = value; + } + } + + public bool bInstantTween + { + get { return m_uiToggle.instantTween; } + set { m_uiToggle.instantTween = value; } + } + + public void ForceSetFlag(bool bCheckd) + { + m_uiToggle.ForceSetActive(bCheckd); + } + + public void RegisterOnCheckEventHandler(CheckBoxOnCheckEventHandler eventHandler) + { + m_stateChangeHandler = eventHandler; + + EventDelegate.Add(m_uiToggle.onChange, OnStateChange); + + UIEventListener.Get(this.gameObject).onClick -= OnTabClick; + UIEventListener.Get(this.gameObject).onClick += OnTabClick; + } + + public CheckBoxOnCheckEventHandler GetCheckEventHandler() + { + return m_stateChangeHandler; + } + + public void SetEnable(bool bEnable) + { + if (null != m_colliderCached) + { + m_colliderCached.enabled = bEnable; + } + if (null != m_uiSpriteBG) + { + m_uiSpriteBG.color = bEnable ? Color.white : new Color(0.3f, 0.3f, 0.3f, 1); + } + + } + + public void OnStateChange() + { + if (m_stateChangeHandler != null) + { + m_stateChangeHandler(this); + } + } + + public void SetAlpha(float f) + { + m_uiSpriteBG.alpha = f; + } + + private void OnTabClick(GameObject button) + { + if (m_tutorial!=null&&m_tutorial.Exculsive && Exculsive) + { + m_tutorial.OnTutorialClicked(); + } + + if (m_NeedAudio && !string.IsNullOrEmpty(audioClip)) + NGUITools.PlayFmod("event:/" + audioClip); + } + + protected override void OnAwake() + { + base.OnAwake(); + + m_tutorial = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XTutorial")); + m_gameui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + + m_colliderCached = GetComponent(); + if (null == m_colliderCached) + { + Debug.Log("null == m_colliderCached"); + } + m_uiToggle = GetComponent(); + if (null == m_uiToggle) + { + Debug.Log("null == m_uiToggle"); + } + m_uiSpriteBG = GetComponentInChildren(); + if (null == m_uiSpriteBG) + { + Debug.Log("null == m_uiSpriteBG"); + } + + CloneFromTpl(); + + if (m_NeedAudio && (string.IsNullOrEmpty(audioClip) || !audioClip.StartsWith("Audio"))) + SetAudioClip("Audio/UI/UI_Button_ok"); + } + + protected void CloneFromTpl() + { + if (m_SpriteAnimationType <= 0) return; + + GameObject tpl = m_gameui.spriteTpl[m_SpriteAnimationType - 1]; + + XUICommon.CloneTplTweens(tpl, gameObject); + } + + public void SetAudioClip(string name) + { + if (m_NeedAudio == false) + return; + + audioClip = name; + } + + public void SetGroup(int group) + { + m_uiToggle.group = group; + } + + public string audioClip; + public bool m_NeedAudio = true; + + [Range(0f, 1f)] + public float volume = 1f; + [Range(0f, 2f)] + public float pitch = 1f; + + public int m_SpriteAnimationType = 0; + + private IXTutorial m_tutorial = null; + private IXGameUI m_gameui = null; + + private Collider m_colliderCached = null; + private UISprite m_uiSpriteBG = null; + private UIToggle m_uiToggle; + private CheckBoxOnCheckEventHandler m_stateChangeHandler; +} + diff --git a/Client/Assets/Scripts/UICommon/XUICheckBox.cs.meta b/Client/Assets/Scripts/UICommon/XUICheckBox.cs.meta new file mode 100644 index 00000000..7cfc9e51 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICheckBox.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c6988b8266797a44c8861778f4f2f9d9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIComboBox.cs b/Client/Assets/Scripts/UICommon/XUIComboBox.cs new file mode 100644 index 00000000..8aedb176 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIComboBox.cs @@ -0,0 +1,124 @@ +using System.Collections.Generic; +using UILib; +using UnityEngine; + +public class XUIComboBox : XUIObject, IXUIComboBox +{ + Dictionary items = new Dictionary(); + Dictionary itemObjects = new Dictionary(); + + public void ModuleInit() + { + itemtpl = transform.Find("Difficulty/DropList/ItemTpl").GetComponent(); + itemtpl.gameObject.SetActive(false); + + droplist = transform.Find("Difficulty/DropList"); + droplist.gameObject.SetActive(false); + + selecttext = transform.Find("Difficulty/SelectedText").GetComponent(); + + Transform t = transform.Find("Difficulty/DropList/Close"); + + if (t != null) close = t.GetComponent(); + + count = 0; + } + + public void AddItem(string text, int value) + { + GameObject newItem = Instantiate(itemtpl.gameObject) as GameObject; + newItem.SetActive(true); + newItem.name = value.ToString(); + + newItem.transform.parent = droplist; + newItem.transform.localPosition = new Vector3(0, -count * itemtpl.height); + newItem.transform.localScale = Vector3.one; + + count ++; + + UILabel lb = newItem.transform.Find("ItemText").GetComponent(); + lb.text = text; + + items.Add(value, text); + itemObjects.Add(value, newItem); + + XUISprite sp = newItem.GetComponent(); + sp.ID = (ulong)value; + sp.RegisterSpriteClickEventHandler(OnItemSelect); + } + + public GameObject GetItem(int value) + { + GameObject go = null; + itemObjects.TryGetValue(value, out go); + return go; + } + + public void ClearItems() + { + foreach (KeyValuePair pair in itemObjects) + { + Destroy(pair.Value); + } + items.Clear(); + itemObjects.Clear(); + count = 0; + } + + protected void OnItemSelect(IXUISprite sp) + { + if (_callback != null) + _callback((int) sp.ID); + + if (close != null) close.Play(true); + + selecttext.text = items[(int) sp.ID]; + } + + public bool SelectItem(int value, bool withCallback) + { + string _text = null; + if(items.TryGetValue(value, out _text)) + { + selecttext.text = _text; + if(withCallback && null != _callback) + { + _callback(value); + } + return true; + } + return false; + } + + public void RegisterSpriteClickEventHandler(ComboboxClickEventHandler eventHandler) + { + _callback = eventHandler; + } + + public void ResetState() + { + if(items.Count == 0) + { + selecttext.text = ""; + } + + droplist.gameObject.SetActive(false); + + foreach (KeyValuePair pair in items) + { + selecttext.text = pair.Value; + + if (_callback != null) _callback(pair.Key); + + break; + } + } + + + private UISprite itemtpl = null; + private int count = 0; + private Transform droplist = null; + private UIPlayTween close = null; + private UILabel selecttext = null; + private ComboboxClickEventHandler _callback = null; +} diff --git a/Client/Assets/Scripts/UICommon/XUIComboBox.cs.meta b/Client/Assets/Scripts/UICommon/XUIComboBox.cs.meta new file mode 100644 index 00000000..2e809244 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIComboBox.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1e57c6edc4ce374caeefcbd3f792a73 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUICommon.cs b/Client/Assets/Scripts/UICommon/XUICommon.cs new file mode 100644 index 00000000..09ffcc97 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICommon.cs @@ -0,0 +1,63 @@ +using UnityEngine; +using XUtliPoolLib; + +public class XUICommon : XSingleton +{ + public UIPanel m_uiRootPanel; + public UIPanel m_inVisiablePanel; + public void Init(Transform uiRoot) + { + m_uiRootPanel = uiRoot.GetComponent(); + m_uiRootPanel.updateFrame = 3; + + m_inVisiablePanel = null; + Transform inVisablePanel = m_uiRootPanel != null ? m_uiRootPanel.transform.Find("InVisiblePanel") : null; + if (inVisablePanel != null) + { + m_inVisiablePanel = inVisablePanel.GetComponent(); + } + } + public void SetRootPanelUpdateFreq(int count) + { + m_uiRootPanel.updateFrame = count; + } + public static void CloneTplTweens(GameObject tpl, GameObject clone) + { + if (clone.GetComponent() != null) return; + + UIPlayTween[] tweens = tpl.GetComponents(); + + for (int i=0;i(); + t.tweenGroup = tween.tweenGroup; + t.trigger = tween.trigger; + t.playDirection = tween.playDirection; + t.resetIfDisabled = tween.resetIfDisabled; + t.resetOnPlay = tween.resetOnPlay; + t.ifDisabledOnPlay = tween.ifDisabledOnPlay; + t.disableWhenFinished = tween.disableWhenFinished; + } + + TweenScale[] scales = tpl.GetComponents(); + + for (int i = 0; i < scales.Length; ++i) + { + TweenScale tweenScale = scales[i]; + TweenScale s = clone.AddComponent(); + s.from = tweenScale.from; + s.to = tweenScale.to; + s.style = tweenScale.style; + s.animationCurve = tweenScale.animationCurve; + s.duration = tweenScale.duration; + s.delay = tweenScale.delay; + s.tweenGroup = tweenScale.tweenGroup; + s.ignoreTimeScale = tweenScale.ignoreTimeScale; + + s.enabled = false; + } + } + + +} diff --git a/Client/Assets/Scripts/UICommon/XUICommon.cs.meta b/Client/Assets/Scripts/UICommon/XUICommon.cs.meta new file mode 100644 index 00000000..7b4c9525 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUICommon.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 12b256b75d3684946a6ad74964ff8bcb +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs new file mode 100644 index 00000000..07a4d103 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs @@ -0,0 +1,103 @@ +using UILib; +using UnityEngine; +using System; + +public class XUIDragDropItem : XUIObject, IXUIDragDropItem +{ + + private UIPanel m_panel; + private void Awake() + { + m_dragdrop = GetComponent(); + + if (null == m_dragdrop) + { + Debug.LogError("null == m_dragdrop"); + } + } + + public void SetCloneOnDrag(bool cloneOnDrag) + { + m_dragdrop.cloneOnDrag = cloneOnDrag; + } + + public void SetRestriction(int restriction) + { + m_dragdrop.restriction = (UIDragDropItem.Restriction)Enum.ToObject(typeof(UIDragDropItem.Restriction), restriction); + } + + + public void SetActive(bool active) + { + m_dragdrop.enabled = active; + enabled = active; + } + + + public void SetParent(Transform parent , bool addPanel = false, int depth = 0) + { + transform.parent = parent; + m_panel = gameObject.GetComponent(); + if (addPanel) + { + m_panel = gameObject.GetComponent(); + if (m_panel == null) m_panel = gameObject.AddComponent(); + m_panel.depth = depth; + m_panel.enabled = true; + } + else + { + if (m_panel != null) m_panel.enabled = false; + } + } + + public void RegisterOnFinishEventHandler(OnDropReleaseEventHandler eventHandler) + { + m_OnFinishHandler = eventHandler; + + //m_uiPlayTween.customFinishCallback = OnFinish; + m_dragdrop.onFinished.Clear(); + EventDelegate.Add(m_dragdrop.onFinished, OnFinish); + } + + public void RegisterOnStartEventHandler(OnDropStartEventHandler eventHandler) + { + m_OnStartHandler = eventHandler; + m_dragdrop.onStart.Clear(); + EventDelegate.Add(m_dragdrop.onStart, OnStart); + } + + public OnDropStartEventHandler GetStartEventHandler() + { + return m_OnStartHandler; + } + + public OnDropReleaseEventHandler GetReleaseEventHandler() + { + return m_OnFinishHandler; + } + + + void OnFinish() + { + if (m_OnFinishHandler != null) + { + m_OnFinishHandler(gameObject, UICamera.hoveredObject); + } + } + + new void OnStart() + { + if (m_OnStartHandler != null) + { + m_OnStartHandler(gameObject); + } + } + + public UIDragDropItem m_dragdrop; + + public OnDropReleaseEventHandler m_OnFinishHandler = null; + public OnDropStartEventHandler m_OnStartHandler = null; + + +} diff --git a/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs.meta b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs.meta new file mode 100644 index 00000000..e8d37aba --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f888635c7fd27cc4fbfc6ea3b9e3c4fe +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs b/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs new file mode 100644 index 00000000..68a14998 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using System.Collections; +using XUtliPoolLib; + +public class XUIGenericEventHandle : MonoBehaviour +{ + private IXGameUI m_game_ui = null; + + void Awake() + { + m_game_ui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + } + + // Use this for initialization + void OnClick () + { + m_game_ui.OnGenericClick(); + } +} diff --git a/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs.meta b/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs.meta new file mode 100644 index 00000000..4e44bddf --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIGenericEventHandle.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 25cf45ac677ea9f419f10c65def3547e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIInput.cs b/Client/Assets/Scripts/UICommon/XUIInput.cs new file mode 100644 index 00000000..45f23042 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIInput.cs @@ -0,0 +1,106 @@ +using UILib; +using UnityEngine; + +public class XUIInput : XUIObject, IXUIInput +{ + protected override void OnAwake() + { + base.OnAwake(); + m_uiInput = GetComponent(); + if (null == m_uiInput) + { + Debug.LogError("null == m_uiInput"); + } + } + + public void selected(bool value) + { + m_uiInput.isSelected = value; + } + public string GetText() + { + if (null != m_uiInput) + { + return m_uiInput.value; + } + return ""; + } + + public void SetText(string strText) + { + if (null != m_uiInput) + { + m_uiInput.value = strText; + } + } + + + public void SetDefault(string strText) + { + if(null != m_uiInput) + { + m_uiInput.defaultText = strText; + } + } + + public string GetDefault() + { + if (null != m_uiInput) + { + return m_uiInput.defaultText; + } + + return ""; + } + + public void RegisterKeyTriggeredEventHandler(InputKeyTriggeredEventHandler eventHandler) + { + //UIEventListener.Get(this.gameObject).onKey = OnKeyHehe; + EventDelegate.Add(m_uiInput.onKeyTriggered, OnKeyTriggered); + + m_keyTriggerEventHandler = eventHandler; + } + + public void OnKeyTriggered() + { + if (m_keyTriggerEventHandler != null) + m_keyTriggerEventHandler(this, UIInput.current.recentKey); + } + + public void RegisterSubmitEventHandler(InputSubmitEventHandler eventHandler) + { + //UIEventListener.Get(this.gameObject).onKey = OnKeyHehe; + EventDelegate.Add(m_uiInput.onSubmit, OnSubmit); + + m_submitEventHandler = eventHandler; + } + + public void OnSubmit() + { + if (m_submitEventHandler != null) + m_submitEventHandler(this); + } + + public void RegisterChangeEventHandler(InputChangeEventHandler eventHandler) + { + EventDelegate.Add(m_uiInput.onChange, OnChange); + + m_changeEventHandler = eventHandler; + } + + public void OnChange() + { + if(m_changeEventHandler != null) + m_changeEventHandler(this); + } + + public void SetCharacterLimit(int num) + { + m_uiInput.characterLimit = num; + } + UIInput m_uiInput = null; + InputKeyTriggeredEventHandler m_keyTriggerEventHandler; + InputSubmitEventHandler m_submitEventHandler; + InputChangeEventHandler m_changeEventHandler; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIInput.cs.meta b/Client/Assets/Scripts/UICommon/XUIInput.cs.meta new file mode 100644 index 00000000..2eae3837 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIInput.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2733d5ea3f4a7c84caaa2c9b5c1ed19c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUILabel.cs b/Client/Assets/Scripts/UICommon/XUILabel.cs new file mode 100644 index 00000000..7db4da9e --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILabel.cs @@ -0,0 +1,262 @@ +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUILabel : XUIObject, IXUILabel +{ + public float m_fAlphaVar; + [System.NonSerialized] + private int m_id = 0; + public float AlphaVar + { + get { return m_fAlphaVar; } + } + + + public float Alpha + { + get + { + if (null != m_uiLabel) + { + return m_uiLabel.alpha; + } + return 1; + } + set + { + if (null != m_uiLabel) + { + m_uiLabel.alpha = value; + } + } + } + + public int spriteWidth + { + get + { + return m_uiLabel.width; + } + set + { + m_uiLabel.width = value; + } + } + + public int spriteHeight + { + get + { + return m_uiLabel.height; + } + } + + public int spriteDepth + { + get + { + return m_uiLabel.depth; + } + set + { + m_uiLabel.depth = value; + } + } + + public int fontSize + { + get + { + return m_uiLabel.fontSize; + } + set + { + m_uiLabel.fontSize = value; + } + } + + public string fontPath = ""; + public string fontSuffix = ""; + + public string GetText() + { + return m_uiLabel.text; + } + + public Color GetColor() + { + return m_uiLabel.color; + } + + public void SetText(string strText) + { + if(m_uiLabel != null) + { + m_uiLabel.text = Localization.Get(strText); + } + } + + public void SetColor(Color c) + { + m_uiLabel.color = c; + } + + public void SetEffectColor(Color c) + { + m_uiLabel.effectColor = c; + } + + public void SetGradient(bool bEnable, Color top, Color bottom) + { + m_uiLabel.applyGradient = bEnable; + m_uiLabel.gradientTop = top; + m_uiLabel.gradientBottom = bottom; + } + + public void ToggleGradient(bool bEnable) + { + m_uiLabel.applyGradient = bEnable; + } + + public void SetRootAsUIPanel(bool bFlg) + { + if (bFlg) + { + m_uiLabel.SetPanel(XUICommon.singleton.m_uiRootPanel); + } + else + { + m_uiLabel.SetPanel(null); + } + } + + public void SetEnabled(bool bEnabled) + { + m_bEnabled = bEnabled; + + if (m_bEnabled) + { + m_uiLabel.color = m_sourceColor; + m_uiLabel.gradientTop = m_sourceTop; + m_uiLabel.gradientBottom = m_sourceBottom; + m_uiLabel.effectColor = m_effectColor; + } + else + { + m_uiLabel.color = new Color(1.0f, 1.0f, 1.0f, 1); + float grey = m_sourceTop.r*0.3f + m_sourceTop.g*0.587f + m_sourceTop.b*0.114f; + m_uiLabel.gradientTop = new Color(grey, grey, grey); + grey = m_sourceBottom.r*0.3f + m_sourceBottom.g*0.587f + m_sourceBottom.b*0.114f; + m_uiLabel.gradientBottom = new Color(grey, grey, grey); + grey = m_effectColor.r * 0.3f + m_effectColor.g * 0.587f + m_effectColor.b * 0.114f; + m_uiLabel.effectColor = new Color(grey, grey, grey); + } + } + public void RegisterLabelClickEventHandler(LabelClickEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onClick = OnLabelClick; + m_labelClickEventHandler = eventHandler; + } + public void SetIdentity(int i) + { + m_id = i; + } + public bool HasIdentityChanged(int i) + { + return m_id != i; + } + void OnLabelClick(GameObject button) + { + if (m_tutorial != null && m_tutorial.NoforceClick && Exculsive) + { + if (null != m_labelClickEventHandler) + { + m_labelClickEventHandler(this); + m_tutorial.OnTutorialClicked(); + } + } + else if (m_tutorial == null || !m_tutorial.Exculsive) + { + if (null != m_labelClickEventHandler) + { + m_labelClickEventHandler(this); + } + } + else if (m_tutorial.Exculsive && Exculsive) + { + if (null != m_labelClickEventHandler) + { + m_labelClickEventHandler(this); + + m_tutorial.OnTutorialClicked(); + } + } + else + { + XDebug.singleton.AddLog("Exculsive block"); + } + + } + + public Vector2 GetPrintSize() + { + return m_uiLabel.printedSize; + } + + public void SetDepthOffset(int d) + { + UIWidget[] w = gameObject.GetComponentsInChildren(); + + for (int i = 0; i < w.Length; i++) + { + w[i].depth += d; + } + } + + public void MakePixelPerfect() + { + if (m_uiLabel == null) + { + return; + } + + m_uiLabel.MakePixelPerfect(); + } + + protected override void OnAwake() + { + base.OnAwake(); + m_tutorial = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XTutorial")); + + m_uiLabel = GetComponent(); + if (null == m_uiLabel) + { + Debug.LogError("null == m_uiLabel"); + } + + if (fontPath != "") + { + m_uiLabel.SetFont(fontPath, fontSuffix); + fontPath = ""; + fontSuffix = ""; + } + + m_sourceColor = m_uiLabel.color; + m_sourceTop = m_uiLabel.gradientTop; + m_sourceBottom = m_uiLabel.gradientBottom; + m_effectColor = m_uiLabel.effectColor; + } + + private UILabel m_uiLabel = null; + private LabelClickEventHandler m_labelClickEventHandler = null; + private bool m_bEnabled = true; + private Color m_sourceColor; + private Color m_sourceTop; + private Color m_sourceBottom; + private Color m_effectColor; + + private IXTutorial m_tutorial = null; + +} + diff --git a/Client/Assets/Scripts/UICommon/XUILabel.cs.meta b/Client/Assets/Scripts/UICommon/XUILabel.cs.meta new file mode 100644 index 00000000..3897dd39 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILabel.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6eb031b6ab24d424da6fd40cad123ac4 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs b/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs new file mode 100644 index 00000000..d005350b --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs @@ -0,0 +1,1111 @@ +using UILib; +using UnityEngine; +using System.Collections.Generic; +using System.Text; +using XUtliPoolLib; + +public abstract class XDataBase +{ + public virtual void Recycle() + { + } + + public virtual void Init() + { + } +} +public class XDataPool where T : XDataBase, new() +{ + private static Queue _pool = new Queue(); + + public static T GetData() + { + if (_pool.Count > 0) + { + T t = _pool.Dequeue(); + + t.Init(); + return t; + } + else + { + T t = new T(); + t.Init(); + return t; + } + } + + public static void Recycle(T data) + { + _pool.Enqueue(data); + } +} + +public class XUILabelSymbol : XUIObject, IXUILabelSymbol +{ + HyperLinkClickEventHandler GuildClickHandler; + HyperLinkClickEventHandler DragonGuildClickHandler; + HyperLinkClickEventHandler TeamClickHandler; + HyperLinkClickEventHandler ItemClickHandler; + HyperLinkClickEventHandler NameClickHandler; + HyperLinkClickEventHandler PkClickHandler; + HyperLinkClickEventHandler SpectateHandler; + HyperLinkClickEventHandler UIClickHandler; + HyperLinkClickEventHandler DefaultClickHandler; + LabelSymbolClickEventHandler SymbolClickHandler; + + enum Type + { + LST_NONE = -1, + LST_IMAGE, + LST_GUILD, + LST_TEAM, + LST_ITEM, + LST_NAME, + LST_PK, + LST_UI, + LST_SPECTATE, + LST_ANIMATION, + LST_DRAGON_GUILD + } + + class StringData : XDataBase + { + public Type type { get; set; } + public int startIndex { get { return m_StartIndex; } } + public int length { get { return m_Length; } } + public string str { get { return m_Str; } } + + private int m_StartIndex; + private int m_Length; + private string m_Str; + + public bool Set(string s, int start_index, int len) + { + m_Str = s; + m_StartIndex = start_index; + m_Length = len; + + if (type == Type.LST_NONE) + return true; + int paramCount = 1; + int index = s.IndexOf(_EscapedSeparator, start_index, len); + while (index != -1) + { + ++paramCount; + index = s.IndexOf(_EscapedSeparator, index + 1, start_index + len - index - 1); + } + if (type == Type.LST_IMAGE && paramCount == 2) // atlas + sprite + return true; + if ((type == Type.LST_GUILD || type == Type.LST_PK || type == Type.LST_DRAGON_GUILD) && paramCount == 2) // name + id + return true; + if ((type == Type.LST_TEAM) && paramCount == 3) // name + teamid + expid + return true; + if ((type == Type.LST_UI) && paramCount >= 2) // name + sysid + [param, param, ...] + return true; + if ((type == Type.LST_SPECTATE) && paramCount == 3)//name + liveid + type + return true; + if ((type == Type.LST_ITEM || type == Type.LST_NAME) && paramCount == 3) // name + color + id + return true; + if (type == Type.LST_ANIMATION && paramCount == 3) //atlas + sprite + frame rate + return true; + return false; + } + + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + + class SymbolData : XDataBase + { + public Type type; + public int startIndex; + public int endIndex; + public virtual bool OnClick(int hitIndex, XUILabelSymbol labelSymbol) { return false; } + public static bool IsImage(Type type) { return type == Type.LST_IMAGE; } + public static bool IsAnimation(Type type) { return type == Type.LST_ANIMATION; } + public static bool IsHyperLink(Type type) { return type != Type.LST_NONE && type != Type.LST_IMAGE; } + } + + class ImageSymbolData : SymbolData + { + public UISprite sprite; + public ImageSymbolData() + { + type = Type.LST_IMAGE; + } + + // return symbolstring + public string SetSprite(XUILabelSymbol labelSymbol, string str, int startIndex, int length, ref int usedSprite) + { + int separate = str.IndexOf(_EscapedSeparator, startIndex, length); + if (separate != -1) + { + string atlasName = str.Substring(startIndex, separate - startIndex); + string spriteName = str.Substring(separate + 1, length - (separate - startIndex) - 1); + if (usedSprite >= labelSymbol.SpriteList.Count) + { + sprite = NGUITools.AddChild(labelSymbol.gameObject); + //sprite.autoFindPanel = false; + sprite.gameObject.AddComponent(); + sprite.depth = labelSymbol.m_Label.depth; + sprite.gameObject.layer = labelSymbol.gameObject.layer; + sprite.pivot = UIWidget.Pivot.Left; + labelSymbol.SpriteList.Add(sprite); + ++usedSprite; + //sprite.panel = m_Label.panel; + } + else + { + sprite = labelSymbol.SpriteList[usedSprite++]; + sprite.gameObject.SetActive(true); + } + + GameObject obj = XResourceLoaderMgr.singleton.GetSharedResource("atlas/UI/" + atlasName, ".prefab"); + sprite.atlas = obj == null ? null : obj.GetComponent(); + + sprite.spriteName = spriteName; + sprite.MakePixelPerfect(); + // 调整图片,不超过上限 + if (labelSymbol.MaxImageHeight > 0 && sprite.height > labelSymbol.MaxImageHeight) + { + int w = sprite.width * labelSymbol.MaxImageHeight / sprite.height; + int h = labelSymbol.MaxImageHeight; + + if ((w & 1) == 1) ++w; + if ((h & 1) == 1) ++h; + + sprite.width = w; + sprite.height = h; + } + + int width = sprite.width; + + return labelSymbol._GetSpaceWithSameWidth(width); + } + return null; + } + + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + + class AnimationSymbolData : SymbolData + { + public UISprite sprite; + public UISpriteAnimation animation; + public AnimationSymbolData() + { + type = Type.LST_ANIMATION; + } + + public string SetSprite(XUILabelSymbol labelSymbol, string str, int startIndex, int length, ref int usedAnimation) + { + int separate = str.IndexOf(_EscapedSeparator, startIndex, length); + int separate2 = str.IndexOf(_EscapedSeparator, separate + 1, length + startIndex - separate); + if (separate != -1) + { + string atlasName = str.Substring(startIndex, separate - startIndex); + string spriteName = str.Substring(separate + 1, separate2 - separate - 1); + int frameRate = int.Parse(str.Substring(separate2 + 1, length + startIndex - separate2 - 1)); + if (usedAnimation >= labelSymbol.AnimationList.Count) + { + sprite = NGUITools.AddChild(labelSymbol.gameObject); + animation = sprite.gameObject.AddComponent(); + sprite.gameObject.AddComponent(); + //sprite.autoFindPanel = false; + sprite.depth = labelSymbol.m_Label.depth; + sprite.gameObject.layer = labelSymbol.gameObject.layer; + sprite.pivot = UIWidget.Pivot.Left; + labelSymbol.AnimationList.Add(sprite); + ++usedAnimation; + //sprite.panel = m_Label.panel; + } + else + { + sprite = labelSymbol.AnimationList[usedAnimation++]; + animation = sprite.gameObject.GetComponent(); + sprite.gameObject.SetActive(true); + } + + GameObject obj = XResourceLoaderMgr.singleton.GetSharedResource("atlas/UI/" + atlasName, ".prefab"); + sprite.atlas = obj == null ? null : obj.GetComponent(); + + //sprite.spriteName = spriteName; + animation.namePrefix = spriteName; + animation.framesPerSecond = frameRate; + animation.Reset(); + sprite.MakePixelPerfect(); + // 调整图片,不超过上限 + int targetHeight = 0; + + if (labelSymbol.MaxImageHeight > 0 && sprite.height > labelSymbol.MaxImageHeight) + targetHeight = labelSymbol.MaxImageHeight; + else if (labelSymbol.MinImageHeight > 0 && sprite.height < labelSymbol.MinImageHeight) + targetHeight = labelSymbol.MinImageHeight; + + if(targetHeight != 0) + { + int w = sprite.width * targetHeight / sprite.height; + int h = targetHeight; + + if ((w & 1) == 1) ++w; + if ((h & 1) == 1) ++h; + + sprite.width = w; + sprite.height = h; + } + + int width = sprite.width; + + return labelSymbol._GetSpaceWithSameWidth(width); + } + return null; + } + + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + + abstract class HyperLinkSymbolData : SymbolData + { + public string param; + public virtual string Set(string wholeStr, int startIndex, int length, int separateIndex) { return null; } + + protected virtual bool OnClick(XUILabelSymbol labelSymbol) { return false; } + public override bool OnClick(int hitIndex, XUILabelSymbol labelSymbol) + { + if (startIndex < hitIndex && endIndex > hitIndex) + { + XDebug.singleton.AddLog(param); + return OnClick(labelSymbol); + } + return false; + } + + protected static string _MakeHyperLinkString(string mainStr, Type type, string color = "61eee6") + { + return string.Format(" [{0}][u]{1}[/u][-] ", color, mainStr); + } + + public static bool CreateHyperLinkSymbolData(StringData input, out SymbolData data, out string symbolString) + { + int separate = input.str.IndexOf(_EscapedSeparator, input.startIndex, input.length); + + if (separate == -1) + { + data = null; + symbolString = null; + return false; + } + + HyperLinkSymbolData hyperLinkSymbolData = null; + switch (input.type) + { + case Type.LST_GUILD: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_DRAGON_GUILD: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_TEAM: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_ITEM: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_NAME: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_PK: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_UI: + hyperLinkSymbolData = XDataPool.GetData(); + break; + case Type.LST_SPECTATE: + hyperLinkSymbolData = XDataPool.GetData(); + break; + } + symbolString = hyperLinkSymbolData.Set(input.str, input.startIndex, input.length, separate); + if (symbolString == null) + { + data = null; + return false; + } + data = hyperLinkSymbolData; + return true; + } + } + abstract class NormalHyperLinkSymbolData : HyperLinkSymbolData + { + public override string Set(string wholeStr, int startIndex, int length, int separateIndex) + { + param = wholeStr.Substring(separateIndex + 1, startIndex + length - separateIndex - 1); + return _MakeHyperLinkString(wholeStr.Substring(startIndex, separateIndex - startIndex), type); + } + } + + abstract class ColorHyperLinkSymbolData : HyperLinkSymbolData + { + public override string Set(string wholeStr, int startIndex, int length, int separateIndex) + { + int separate2 = wholeStr.IndexOf(_EscapedSeparator, separateIndex + 1, startIndex + length - separateIndex - 1); + if (separate2 == -1) + { + XDebug.singleton.AddErrorLog("The second separator is missing: ", wholeStr); + return null; + } + string color = wholeStr.Substring(separateIndex + 1, separate2 - separateIndex - 1); + string normalStr = wholeStr.Substring(startIndex, separateIndex - startIndex); + + s_TempSB.Length = 0; + s_TempSB.Append(wholeStr, separate2 + 1, startIndex + length - separate2 - 1); + s_TempSB.Append(_EscapedSeparator); + s_TempSB.Append(normalStr); + param = s_TempSB.ToString(); + return _MakeHyperLinkString(normalStr, type, color); + } + } + + class GuildHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public GuildHyperLinkSymbolData() + { + type = Type.LST_GUILD; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.GuildClickHandler != null) + { + labelSymbol.GuildClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + + class DragonGuildHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public DragonGuildHyperLinkSymbolData() + { + type = Type.LST_DRAGON_GUILD; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.DragonGuildClickHandler != null) + { + labelSymbol.DragonGuildClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class TeamHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public TeamHyperLinkSymbolData() + { + type = Type.LST_TEAM; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.TeamClickHandler != null) + { + labelSymbol.TeamClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class ItemHyperLinkSymbolData : ColorHyperLinkSymbolData + { + public ItemHyperLinkSymbolData() + { + type = Type.LST_ITEM; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.ItemClickHandler != null) + { + labelSymbol.ItemClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class NameHyperLinkSymbolData : ColorHyperLinkSymbolData + { + public NameHyperLinkSymbolData() + { + type = Type.LST_NAME; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.NameClickHandler != null) + { + labelSymbol.NameClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class PkHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public PkHyperLinkSymbolData() + { + type = Type.LST_PK; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.PkClickHandler != null) + { + labelSymbol.PkClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class UIHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public UIHyperLinkSymbolData() + { + type = Type.LST_UI; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.UIClickHandler != null) + { + labelSymbol.UIClickHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + class SpectateHyperLinkSymbolData : NormalHyperLinkSymbolData + { + public SpectateHyperLinkSymbolData() + { + type = Type.LST_SPECTATE; + } + protected override bool OnClick(XUILabelSymbol labelSymbol) + { + if (labelSymbol.SpectateHandler != null) + { + labelSymbol.SpectateHandler(param); + return true; + } + return false; + } + public override void Recycle() + { + base.Recycle(); + XDataPool.Recycle(this); + } + } + + + protected UILabel m_Label; + protected BoxCollider m_collider; + + public int MaxImageHeight = 0; + public int MinImageHeight = 0; + public int ImageHeightAdjustment = 0; + public XUISprite BoardSprite; + public int MinBoardWidth; + public int MaxBoardWidth; + public int BoardHeightOffset = 0; + public int BoardWidthOffset = 0; + public bool bAutoDisableBoxCollider = false; + + StringBuilder m_OutputSB = new StringBuilder(); + //StringBuilder m_ResSB = new StringBuilder(); + + static StringBuilder s_TempSB = new StringBuilder(); + + List m_StringData = new List(); + List m_Symbols = new List(); + + List m_SpriteList = new List(); + List m_AnimationList = new List(); + public List SpriteList { get { return m_SpriteList; } } + public List AnimationList { get { return m_AnimationList; } } + + bool m_bBoxColliderCreator = false; + + private string _InputText; + public string InputText + { + set + { + _InputText = value; + if (_InputText == null) + _InputText = string.Empty; + Parse(); + SetBoard(); + } + } + + public IXUISprite IBoardSprite + { + get + { + return BoardSprite as IXUISprite; + } + } + + public void SetBoard() + { + //Vector3 size = m_Label.CalculateBounds().size; + //XDebug.singleton.AddLog("SetBoard"); + Vector2 textSize = NGUIText.CalculatePrintedSize(m_Label.text); + textSize.x += BoardWidthOffset; + + if (BoardSprite != null) + { + if (MinBoardWidth != 0 && MaxBoardWidth != 0 && MaxBoardWidth >= MinBoardWidth) + { + if (textSize.x <= MinBoardWidth) + BoardSprite.spriteWidth = MinBoardWidth; + else if (textSize.x > MaxBoardWidth) + BoardSprite.spriteWidth = MaxBoardWidth; + else + BoardSprite.spriteWidth = (int)textSize.x; + } + else + BoardSprite.spriteWidth = (int)textSize.x; + + BoardSprite.spriteHeight = (int)textSize.y + 20 + BoardHeightOffset; + } + } + + + protected override void OnAwake() + { + base.OnAwake(); + m_Label = GetComponent(); + m_Label.ProcessText(); + m_collider = m_Label.DefaultBoxCollider; + if (null == m_Label) + { + Debug.LogError("null == m_Label"); + } + if (m_collider != null) + { + UIEventListener listener = UIEventListener.Get(this.gameObject); + listener.onClick -= OnSymbolClick; + listener.onClick += OnSymbolClick; + } + } + + void _CheckAttachments() + { + for (int i = m_SpriteList.Count - 1; i >= 0; --i) + { + if (m_SpriteList[i] == null) + { + XDebug.singleton.AddErrorLog(string.Format("m_SpriteList[{0}] == null, while m_SpriteList.Count = {1}", i, m_SpriteList.Count)); + m_SpriteList.RemoveAt(i); + } + } + for (int i = m_AnimationList.Count - 1; i >= 0; --i) + { + if (m_AnimationList[i] == null) + { + XDebug.singleton.AddErrorLog(string.Format("m_AnimationList[{0}] == null, while m_AnimationList.Count = {1}", i, m_AnimationList.Count)); + m_AnimationList.RemoveAt(i); + } + } + } + + + public void UpdateDepth(int depth) + { + for(int i=0;i verts = new BetterList(); + static BetterList indices = new BetterList(); + public void Parse() + { + m_OutputSB.Length = 0; + _Separate(); + _Parse(); + + if (bAutoDisableBoxCollider && m_collider != null) + m_collider.enabled = false; + + if (m_Symbols.Count <= 0) + return; + + verts.Clear(); + indices.Clear(); + NGUIText.PrintCharacterPositions(m_Label.processedText, verts, indices); + + if (verts.size <= 0) + return; + m_Label.ApplyOffset(verts, 0); + int j = 0; + + for (int i = 0; i < m_Symbols.Count; ++i) + { + SymbolData data = m_Symbols[i]; + if (SymbolData.IsImage(data.type) || SymbolData.IsAnimation(data.type)) + { + UISprite sprite = null; + if (SymbolData.IsImage(data.type)) + { + ImageSymbolData imageData = data as ImageSymbolData; + sprite = imageData.sprite; + } + else + { + AnimationSymbolData animationData = data as AnimationSymbolData; + sprite = animationData.sprite; + } + + for (; j < indices.size; ++j) + { + if (indices[j] == data.startIndex) + { + sprite.transform.localPosition = verts[j] + new Vector3(0, ImageHeightAdjustment); + break; + } + } + if (j == indices.size && sprite != null) + { + sprite.gameObject.SetActive(false); + } + } + else if (SymbolData.IsHyperLink(data.type)) + { + if (m_collider == null) + { + m_collider = NGUITools.AddWidgetCollider(gameObject, m_Label, false); + UIEventListener listener = UIEventListener.Get(this.gameObject); + listener.onClick -= OnSymbolClick; + listener.onClick += OnSymbolClick; + m_bBoxColliderCreator = true; + } + else + { + m_collider.enabled = true; + if (m_bBoxColliderCreator) + { + NGUITools.UpdateWidgetCollider(m_Label, m_collider, false); + } + } + } + } + + } + + int _FindClosingBracket(string s, int startIndex) + { + int length = s.Length; + int stack = 0; + for (int i = startIndex; i < length; ++i) + { + if (s[i] == _EscapedLeftBracket) + ++stack; + else if (s[i] == _EscapedRightBracket) + { + if (--stack < 0) + return i; + } + } + return -1; + } + + private void _Parse() + { + for (int i = 0; i < m_Symbols.Count; ++i) + { + m_Symbols[i].Recycle(); + } + m_Symbols.Clear(); + + m_Label.text = ""; + m_Label.ProcessText(); + m_Label.UpdateDefaultPrintedSize(); + if (_UniSpaceWidth <= 0.0f) + { + //_UniSpaceWidth = NGUIText.CalculatePrintedSize(new string(_UniSpace, 1), 1000).x; + _UniSpaceWidth = NGUIText.CalculatePrintedSize(" ", 1000).x; + if (_UniSpaceWidth <= 0.0f) + { + XDebug.singleton.AddErrorLog("_SpaceWidth = ", _UniSpaceWidth.ToString(), " gameobject = ", gameObject.ToString(), "; Content: ", _InputText); + } + } + + _CheckAttachments(); + string res = ""; + int lineStartIndex = 0; + int usedSprite = 0; + int usedAnimation = 0; + int lineWidth = m_Label.width; + if (m_Label.overflowMethod == UILabel.Overflow.ResizeFreely) + lineWidth = 10000; + string symbolStr = null; + SymbolData symbolData = null; + StringData data; + for (int ii = 0; ii < m_StringData.Count; ++ii) + { + // 已超出文本框的范围,直接退出 + if (lineStartIndex != 0 && lineStartIndex >= res.Length) + break; + + data = m_StringData[ii]; + if (SymbolData.IsImage(data.type)) + { + ImageSymbolData imageData = XDataPool.GetData(); + symbolStr = imageData.SetSprite(this, data.str, data.startIndex, data.length, ref usedSprite); + if (symbolStr == null) + { + imageData.Recycle(); + continue; + } + else + { + symbolData = imageData; + } + } + else if(SymbolData.IsAnimation(data.type)) + { + AnimationSymbolData animationData = XDataPool.GetData(); + symbolStr = animationData.SetSprite(this, data.str, data.startIndex, data.length, ref usedAnimation); + if (symbolStr == null) + { + animationData.Recycle(); + continue; + } + else + { + symbolData = animationData; + } + } + // hyper links + else if (SymbolData.IsHyperLink(data.type)) + { + HyperLinkSymbolData.CreateHyperLinkSymbolData(data, out symbolData, out symbolStr); + } + + if (symbolStr != null) + { + s_TempSB.Length = 0; + s_TempSB.Append(res, lineStartIndex, res.Length - lineStartIndex); + s_TempSB.Append(symbolStr); + + int textWidth = Mathf.CeilToInt( + NGUIText.CalculatePrintedSize( + s_TempSB.ToString(), + lineWidth + 1000).x); + + if (textWidth > lineWidth) + { + symbolData.startIndex = res.Length + 1; + lineStartIndex = res.Length + 1; + s_TempSB.Length = 0; + s_TempSB.Append(res); + s_TempSB.Append('\n'); + s_TempSB.Append(symbolStr); + res = s_TempSB.ToString(); + } + else + { + symbolData.startIndex = res.Length; + s_TempSB.Length = 0; + s_TempSB.Append(res); + s_TempSB.Append(symbolStr); + res = s_TempSB.ToString(); + } + + symbolData.endIndex = symbolData.startIndex + symbolStr.Length; + + m_Symbols.Add(symbolData); + //m_Label.text = res; + //res = m_Label.processedText; + NGUIText.WrapText(res, out res, false); + symbolStr = null; + continue; + } + //m_Label.text = res + data.str; + //res = m_Label.processedText; + s_TempSB.Length = 0; + s_TempSB.Append(res); + s_TempSB.Append(data.str, data.startIndex, data.length); + NGUIText.WrapText(s_TempSB.ToString(), out res, false); + lineStartIndex = res.LastIndexOf('\n'); + if (lineStartIndex == -1) + lineStartIndex = 0; + else + ++lineStartIndex; + + } + for (; usedSprite < m_SpriteList.Count; ++usedSprite) + { + m_SpriteList[usedSprite].gameObject.SetActive(false); + } + + for (; usedAnimation < m_AnimationList.Count; ++usedAnimation ) + { + m_AnimationList[usedAnimation].gameObject.SetActive(false); + } + + m_Label.text = res; + } + + private void _Separate() + { + for (int i = 0; i < m_StringData.Count; ++i) + { + m_StringData[i].Recycle(); + } + m_StringData.Clear(); + + int lastPos = 0; + string s = string.IsNullOrEmpty(_InputText)?"":_InputText; + int count = s.Length; + Type type = Type.LST_NONE; + StringData data = null; + for (int i = 0; i < count; ++i) + { + if (_InputText[i] == _EscapedLeftBracket) + { + int closingBracket = _FindClosingBracket(s, i + 1); + if (closingBracket != -1 && closingBracket - i > 3) + { + int startIndex = i + 1; + type = _GetType(_InputText, startIndex); + } + if (type != Type.LST_NONE) + { + data = XDataPool.GetData(); + data.type = type; + if (data.Set(s, i + 4, closingBracket - i - 4)) + { + if (i > lastPos) + { + StringData noneData = XDataPool.GetData(); + noneData.type = Type.LST_NONE; + noneData.Set(s, lastPos, i - lastPos); + m_StringData.Add(noneData); + } + m_StringData.Add(data); + lastPos = closingBracket + 1; + i = closingBracket; + } + else + { + data.Recycle(); + } + type = Type.LST_NONE; + } + } + } + if (lastPos < count) + { + StringData noneData = XDataPool.GetData(); + noneData.type = Type.LST_NONE; + noneData.Set(s, lastPos, count - lastPos); + m_StringData.Add(noneData); + } + } + + Type _GetType(string s, int startIndex) + { + if (strcmp(s, "im=", startIndex) == 0) + return Type.LST_IMAGE; + if (strcmp(s, "gd=", startIndex) == 0) + return Type.LST_GUILD; + if (strcmp(s, "dg=", startIndex) == 0) + return Type.LST_DRAGON_GUILD; + if (strcmp(s, "tm=", startIndex) == 0) + return Type.LST_TEAM; + if (strcmp(s, "it=", startIndex) == 0) + return Type.LST_ITEM; + if (strcmp(s, "nm=", startIndex) == 0) + return Type.LST_NAME; + if (strcmp(s, "pk=", startIndex) == 0) + return Type.LST_PK; + if (strcmp(s, "ui=", startIndex) == 0) + return Type.LST_UI; + if (strcmp(s, "sp=", startIndex) == 0) + return Type.LST_SPECTATE; + if (strcmp(s, "an=", startIndex) == 0) + return Type.LST_ANIMATION; + return Type.LST_NONE; + } + static int strcmp(string left, string right, int leftStartIndex = 0, int rightStartIndex = 0) + { + int i; + int j; + for (i = leftStartIndex, j = rightStartIndex; i < left.Length && j < right.Length; ++i, ++j) + { + if (left[i] == right[j]) + continue; + if (left[i] < right[j]) + return -1; + return 1; + } + //if (i == left.Length && j == right.Length) + return 0; + //if (i == left.Length) + // return -1; + //return 1; + } + + string _GetSpaceWithSameWidth(int width) + { + if(_UniSpaceWidth <= 0.0f) + _UniSpaceWidth = 5f; + + if (width < _UniSpaceWidth) + return " "; + else if (width < 2 * _UniSpaceWidth) + return " "; + else + { + s_TempSB.Length = 0; + int count = Mathf.CeilToInt((width - 2 * _UniSpaceWidth) / _UniSpaceWidth); + s_TempSB.Append(" "); + s_TempSB.Append(_UniSpace, count); + s_TempSB.Append(" "); + return s_TempSB.ToString(); + } + } + + static char _UniSpace = ' ';//'\u2009'; + //static char _cSeparator = '|'; + static char _EscapedSeparator = (char)31; + //static char _cLeftBracket = '['; + static char _EscapedLeftBracket = (char)2; + //static char _cRightBracket = ']'; + static char _EscapedRightBracket = (char)3; + + float _UniSpaceWidth = -0.1f; + //float _SpaceWidth = -0.1f; + + public void RegisterTeamEventHandler(HyperLinkClickEventHandler eventHandler) + { + TeamClickHandler = eventHandler; + } + public void RegisterGuildEventHandler(HyperLinkClickEventHandler eventHandler) + { + GuildClickHandler = eventHandler; + } + public void RegisterDragonGuildEventHandler(HyperLinkClickEventHandler eventHandler) + { + DragonGuildClickHandler = eventHandler; + } + public void RegisterItemEventHandler(HyperLinkClickEventHandler eventHandler) + { + ItemClickHandler = eventHandler; + } + public void RegisterNameEventHandler(HyperLinkClickEventHandler eventHandler) + { + NameClickHandler = eventHandler; + } + public void RegisterPkEventHandler(HyperLinkClickEventHandler eventHandler) + { + PkClickHandler = eventHandler; + } + public void RegisterUIEventHandler(HyperLinkClickEventHandler eventHandler) + { + UIClickHandler = eventHandler; + } + + public void RegisterSpectateEventHandler(HyperLinkClickEventHandler eventHandler) + { + SpectateHandler = eventHandler; + } + + public void RegisterDefaultEventHandler(HyperLinkClickEventHandler eventHandler) + { + DefaultClickHandler = eventHandler; + } + + public void RegisterSymbolClickHandler(LabelSymbolClickEventHandler eventHandler) + { + SymbolClickHandler = eventHandler; + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs.meta b/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs.meta new file mode 100644 index 00000000..0a2f5346 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILabelSymbol.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 18117ef1c0410154eb42e557c46ba290 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIList.cs b/Client/Assets/Scripts/UICommon/XUIList.cs new file mode 100644 index 00000000..9c25f7df --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIList.cs @@ -0,0 +1,57 @@ +using UILib; +using UnityEngine; + +public class XUIList : XUIObject, IXUIList +{ + public UIRect _parent; + public void Refresh() + { + m_uiGrid.repositionNow = true; + //m_uiGrid.Reposition(); + } + + public void CloseList() + { + m_uiGrid.CloseList(); + } + + public void SetAnimateSmooth(bool b) + { + m_uiGrid.animateSmoothly = b; + } + public void RegisterRepositionHandle(OnAfterRepostion reposition) + { + onRepositionFinish = reposition; + } + + private void OnAfterReposition() + { + if (onRepositionFinish != null) + { + onRepositionFinish(); + } + } + public IUIRect GetParentUIRect() + { + return _parent; + } + public IUIPanel GetParentPanel() + { + return m_uiGrid.panel; + } + + protected override void OnAwake() + { + base.OnAwake(); + m_uiGrid = GetComponent(); + if (m_uiGrid != null) + m_uiGrid.onReposition = OnAfterReposition; + else + Debug.Log("no ngui grid component"); + } + + private UIGrid m_uiGrid; + + private OnAfterRepostion onRepositionFinish = null; + +} diff --git a/Client/Assets/Scripts/UICommon/XUIList.cs.meta b/Client/Assets/Scripts/UICommon/XUIList.cs.meta new file mode 100644 index 00000000..a64e6650 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIList.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 41e96d6c366311e49817a94469820951 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUILongPress.cs b/Client/Assets/Scripts/UICommon/XUILongPress.cs new file mode 100644 index 00000000..fa715e61 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILongPress.cs @@ -0,0 +1,75 @@ +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUILongPress : XUIObject, IXUILongPress +{ + public void RegisterSpriteLongPressEventHandler(SpriteClickEventHandler eventHandler) + { + if (eventHandler != null) + { + UIEventListener.Get(this.gameObject).onPress -= OnSpritePress; + UIEventListener.Get(this.gameObject).onPress += OnSpritePress; + UIEventListener.Get(this.gameObject).onDrag -= OnSpriteDrag; + UIEventListener.Get(this.gameObject).onDrag += OnSpriteDrag; + } + + m_spriteLongPressEventHandler = eventHandler; + } + + protected override void OnAwake() + { + base.OnAwake(); + m_XUISprite = GetComponent(); + if (null == m_XUISprite) + { + Debug.LogError("null == XUISprite, " + this.gameObject.name); + } + } + + void Update() + { + if (m_spriteLongPressEventHandler != null && _lastPress > 0.0f && Time.time - _lastPress > _longClickDuration) + { + m_spriteLongPressEventHandler(m_XUISprite); + _lastPress = -1.0f; + //bPressed = false; + m_XUISprite.ClickCanceled = true; + } + } + + void OnSpritePress(GameObject button, bool isPressed) + { + if (m_spriteLongPressEventHandler != null) + { + if (isPressed) + { + _lastPress = Time.time; + //bPressed = true; + } + if (!isPressed) + { + _lastPress = -1.0f; + } + } + } + void OnSpriteDrag(GameObject button, Vector2 delta) + { + if (m_spriteLongPressEventHandler != null) + { + if (_lastPress > 0) + { + //bPressed = false; + _lastPress = -1.0f; + } + } + } + + private SpriteClickEventHandler m_spriteLongPressEventHandler = null; + private XUISprite m_XUISprite = null; + + private static readonly float _longClickDuration = 0.5f; + float _lastPress = -1f; + //bool bPressed = false; +} + diff --git a/Client/Assets/Scripts/UICommon/XUILongPress.cs.meta b/Client/Assets/Scripts/UICommon/XUILongPress.cs.meta new file mode 100644 index 00000000..554ad34d --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUILongPress.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5e31112fb10935d4f9a118312665672d +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIObject.cs b/Client/Assets/Scripts/UICommon/XUIObject.cs new file mode 100644 index 00000000..667482eb --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIObject.cs @@ -0,0 +1,89 @@ +using System; + +public class XUIObject : XUIObjectBase +{ + protected override void OnAwake() + { + base.OnAwake(); + if (null == transform.parent) + { + parent = null; + return; + } + //XUIObjectBase uiObject = NGUITools.FindInParents(transform.parent.gameObject); + //if (null != uiObject) + //{ + // parent = uiObject; + //} + } + public override UILib.IXUIObject parent + { + get + { + if(!mParentCached) + { + XUIObjectBase uiObject = NGUITools.FindInParents(transform.parent.gameObject); + if (null != uiObject) + { + base.parent = uiObject; + } + mParentCached = true; + } + return base.parent; + } + set + { + base.parent = value; + mParentCached = true; + } + } + + private bool mParentCached = false; +} + +public class XUICD +{ + public static readonly float DEFAULT_CLICK_CD = 0.0f; + public static readonly float[] CLICK_CD_GROUPS = new float[] { 0.0f, 0.5f, 1.0f }; + + protected float m_ClickCD; + protected float m_ClickTime = 0f; + + public void SetClickCD(int customCDGroup, float customCD) + { + if (customCD >= 0) + { + m_ClickCD = customCD; + } + else if (customCDGroup < 0 || customCDGroup >= CLICK_CD_GROUPS.Length) + { + m_ClickCD = DEFAULT_CLICK_CD; + } + else + { + m_ClickCD = CLICK_CD_GROUPS[customCDGroup]; + } + } + + public bool IsInCD() + { + float time = UnityEngine.Time.realtimeSinceStartup; + if (time - m_ClickTime < m_ClickCD) + return true; + m_ClickTime = time; + return false; + } + + public void Reset() + { + m_ClickTime = 0; + } + + public void SetUnavailableCD(int cd) + { + float time = UnityEngine.Time.realtimeSinceStartup; + m_ClickTime = time; + + SetClickCD(0, cd); + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/UICommon/XUIObject.cs.meta b/Client/Assets/Scripts/UICommon/XUIObject.cs.meta new file mode 100644 index 00000000..a9f4fa06 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIObject.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6e7cae9718fad74d8729906055de071 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIPanel.cs b/Client/Assets/Scripts/UICommon/XUIPanel.cs new file mode 100644 index 00000000..dd2b0f28 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPanel.cs @@ -0,0 +1,124 @@ +using UILib; +using UnityEngine; +using System; + +public class XUIPanel : XUIObject, IXUIPanel +{ + protected override void OnAwake() + { + base.OnAwake(); + if (null == m_uiPanel) + { + m_uiPanel = GetComponent(); + if (null == m_uiPanel) + { + Debug.LogError("null == m_uiPanel"); + } + } + m_uiPanel.onClipMove += OnMove; + } + + public void OnMove(UIPanel panel) + { + if (onMoveDel != null) onMoveDel(); + } + + public void SetSize(float width, float height) + { + Vector4 origin = m_uiPanel.baseClipRegion; + m_uiPanel.baseClipRegion = new Vector4(origin.x, origin.y, width, height); + } + + public void SetCenter(float width, float height) + { + Vector4 origin = m_uiPanel.baseClipRegion; + m_uiPanel.baseClipRegion = new Vector4(width, height, origin.x, origin.y); + } + public Vector4 GetBaseRect() + { + return m_uiPanel.baseClipRegion; + } + + public void SetAlpha(float a) + { + m_uiPanel.alpha = a; + } + + public float GetAlpha() + { + return m_uiPanel.alpha; + } + + public void SetDepth(int d) + { + m_uiPanel.depth = d; + } + + public int GetDepth() + { + return m_uiPanel.depth; + } + + public Vector2 offset + { + get + { + return m_uiPanel.clipOffset; + } + set + { + m_uiPanel.clipOffset = value; + } + } + + public bool IsVisible(GameObject go) + { + return m_uiPanel.IsVisible(go.GetComponent()); + } + + public Vector4 ClipRange + { + get + { + return m_uiPanel.baseClipRegion; + } + set + { + m_uiPanel.baseClipRegion = value; + } + } + + public Vector2 softness + { + get + { + return m_uiPanel.clipSoftness; + } + set + { + m_uiPanel.clipSoftness = value; + } + } + + public UIPanel m_uiPanel = null; + + public Action onMoveDel { get; set; } + + public Component UIComponent { get { return m_uiPanel; } } + + + public static IXUIPanel GetPanel(UIPanel panel) + { + if (panel == null) + return null; + + XUIPanel xPanel = panel.GetComponent(); + if (xPanel == null) + { + xPanel = panel.gameObject.AddComponent(); + } + + return xPanel; + } +} + diff --git a/Client/Assets/Scripts/UICommon/XUIPanel.cs.meta b/Client/Assets/Scripts/UICommon/XUIPanel.cs.meta new file mode 100644 index 00000000..f1e05c6b --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPanel.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ef84b4a4e1ed13446acb100ba6b04a9a +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIPlayTween.cs b/Client/Assets/Scripts/UICommon/XUIPlayTween.cs new file mode 100644 index 00000000..2dd8da68 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPlayTween.cs @@ -0,0 +1,153 @@ +using AnimationOrTween; +using UILib; +using UnityEngine; + +public class XUIPlayTween : MonoBehaviour, IXUITweenTool +{ + private bool m_bPlayForward; + public bool bPlayForward { get { return m_bPlayForward; } } + public int TweenGroup { get { return m_uiPlayTween.tweenGroup; } } + + private void Awake() + { + m_uiPlayTween = GetComponent(); + + if (null == m_uiPlayTween) + { + Debug.LogError("null == m_uiPlayTween " + gameObject.name); + } + oneCycleFinish = new EventDelegate(OnOneCycleFinish); + } + + [ContextMenu("Execute")] + public void Excute() + { + ResetTween(true); + PlayTween(true); + } + + public void PlayTween(bool bForward, float duaration = -1.0f) + { + //if (null != m_objectToPlay) + // m_uiPlayTween.tweenTarget = m_objectToPlay; + + m_uiPlayTween.Play(bForward); + m_bPlayForward = bForward; + + if (duaration > 0.0f) + { + m_repeatStartTime = Time.time; + m_repeatDuaration = duaration; + EventDelegate.Add(m_uiPlayTween.onFinished, oneCycleFinish); + } + } + + public void ResetTween(bool bForward) + { + m_uiPlayTween.Reset(bForward); + } + + public void ResetTweenByGroup(bool bForward, int resetGroup) + { + m_uiPlayTween.ResetByGroup(bForward, resetGroup); + } + + public void ResetTweenByCurGroup(bool bForward) + { + m_uiPlayTween.ResetByGroup(bForward, m_uiPlayTween.tweenGroup); + } + + public void ResetTweenExceptGroup(bool bForward, int exceptGroup) + { + m_uiPlayTween.ResetExceptGroup(bForward, exceptGroup); + } + + public void StopTween() + { + m_uiPlayTween.Stop(); + } + + public void StopTweenByGroup(int resetGroup) + { + m_uiPlayTween.StopByGroup(resetGroup); + } + + public void StopTweenExceptGroup(int exceptGroup) + { + m_uiPlayTween.StopExceptGroup(exceptGroup); + } + + public void SetTargetGameObject(GameObject go) + { + //m_objectToPlay = go; + m_uiPlayTween.tweenTarget = go; + } + + public void SetPositionTweenPos(int group, Vector3 from, Vector3 to) + { + GameObject go = (m_uiPlayTween.tweenTarget == null) ? gameObject : m_uiPlayTween.tweenTarget; + TweenPosition[] _TweenPosition = go.GetComponents(); + + for (int i = 0; i < _TweenPosition.Length; i++) + { + if (_TweenPosition[i].tweenGroup == group) + { + _TweenPosition[i].from = from; + _TweenPosition[i].to = to; + } + } + } + + public void SetTweenGroup(int group) + { + m_uiPlayTween.tweenGroup = group; + } + + public void SetTweenEnabledWhenFinish(bool enabled) + { + if (enabled) + { + m_uiPlayTween.disableWhenFinished = DisableCondition.DoNotDisable; + } + else + { + m_uiPlayTween.disableWhenFinished = DisableCondition.DisableAfterForward; + } + } + + public void RegisterOnFinishEventHandler(OnTweenFinishEventHandler eventHandler) + { + m_OnFinishHandler = eventHandler; + + // m_uiPlayTween.customFinishCallback = OnFinish; + + EventDelegate.Add(m_uiPlayTween.onFinished, OnFinish); + } + + void OnFinish() + { + if (m_OnFinishHandler != null) + { + m_OnFinishHandler(this); + } + } + + // 指定tween的时间长度时,每播完一次,跑到这里,如果还有剩余时间,继续跑 + void OnOneCycleFinish() + { + if (Time.time - m_repeatStartTime < m_repeatDuaration) + m_uiPlayTween.Play(m_bPlayForward); + else + { + EventDelegate.Remove(m_uiPlayTween.onFinished, oneCycleFinish); + } + } + + private UIPlayTween m_uiPlayTween; + private GameObject m_objectToPlay; + private OnTweenFinishEventHandler m_OnFinishHandler = null; + + private EventDelegate oneCycleFinish; + private float m_repeatStartTime; // 重复播放的开始时间 + private float m_repeatDuaration; // 重复播放的时间长度 +} diff --git a/Client/Assets/Scripts/UICommon/XUIPlayTween.cs.meta b/Client/Assets/Scripts/UICommon/XUIPlayTween.cs.meta new file mode 100644 index 00000000..d7e33f5a --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPlayTween.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 545a4bd349ff6f542b1b7a08b4563f4c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs b/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs new file mode 100644 index 00000000..d2be095f --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs @@ -0,0 +1,43 @@ +using AnimationOrTween; +using UILib; +using UnityEngine; + +public class XUIPlayTweenGroup : MonoBehaviour,IXUIPlayTweenGroup +{ + public UIPlayTween[] m_tweenControls; + void Awake() + { + if(m_tweenControls == null || m_tweenControls.Length == 0) + m_tweenControls = GetComponentsInChildren(); + + } + + [ContextMenu("Execute")] + void Excute() + { + + ResetTween(true); + PlayTween(false); + } + + public void PlayTween(bool bForward) + { + if (m_tweenControls == null || m_tweenControls.Length == 0) return; + for (int i = 0, length = m_tweenControls.Length; i < length; i++) + m_tweenControls[i].Play(bForward); + } + + public void ResetTween(bool bForward) + { + if (m_tweenControls == null || m_tweenControls.Length == 0) return; + for (int i = 0, length = m_tweenControls.Length; i < length; i++) + m_tweenControls[i].Reset(bForward); + } + + public void StopTween() + { + if (m_tweenControls == null || m_tweenControls.Length == 0) return; + for (int i = 0, length = m_tweenControls.Length; i < length; i++) + m_tweenControls[i].Stop(); + } +} diff --git a/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs.meta b/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs.meta new file mode 100644 index 00000000..9769b864 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPlayTweenGroup.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b5d6afa5a7ab9d94483fb5ceebcc137e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIPopupList.cs b/Client/Assets/Scripts/UICommon/XUIPopupList.cs new file mode 100644 index 00000000..f78b6c01 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPopupList.cs @@ -0,0 +1,47 @@ +using UILib; +using UnityEngine; +using System.Collections.Generic; + +public class XUIPopupList : XUIObject, IXUIPopupList +{ + + protected override void OnAwake() + { + base.OnAwake(); + m_uiPopupList = GetComponent(); + if (null == m_uiPopupList) + { + Debug.LogError("null == m_uiPopupList"); + } + } + + public void SetOptionList(List options) + { + m_uiPopupList.items = options; + } + + public string value + { + get { return m_uiPopupList.value; } + set { m_uiPopupList.value = value; } + } + + public int currentIndex + { + get + { + return m_uiPopupList.items.IndexOf(m_uiPopupList.value); + } + set + { + if(value >= m_uiPopupList.items.Count) + { + Debug.LogError("Index out of range. " + value); + return; + } + m_uiPopupList.value = m_uiPopupList.items[value]; + } + } + private UIPopupList m_uiPopupList; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIPopupList.cs.meta b/Client/Assets/Scripts/UICommon/XUIPopupList.cs.meta new file mode 100644 index 00000000..7ed429e5 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPopupList.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 104538f24f5929640a2e356905cb3442 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIPressTips.cs b/Client/Assets/Scripts/UICommon/XUIPressTips.cs new file mode 100644 index 00000000..3bf12017 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPressTips.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using UILib; +using XUtliPoolLib; + +class XUIPressTips: XUIObject +{ + public string content; + public Vector3 offset = new Vector3(84,-21); + + protected override void OnPress(bool isPressed) + { + if (string.IsNullOrEmpty(content)) return; + IUiUtility entance = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("IUiUtility")); + if (entance != null) { + entance.ShowPressToolTips(isPressed, content , transform.position, offset); + } + } +} diff --git a/Client/Assets/Scripts/UICommon/XUIPressTips.cs.meta b/Client/Assets/Scripts/UICommon/XUIPressTips.cs.meta new file mode 100644 index 00000000..1ee57dae --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIPressTips.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ec3400e544fe2804cad3e994a947414a +timeCreated: 1508158541 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/UICommon/XUIProgress.cs b/Client/Assets/Scripts/UICommon/XUIProgress.cs new file mode 100644 index 00000000..15ef21fa --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIProgress.cs @@ -0,0 +1,301 @@ +using UILib; +using UnityEngine; +using System.Collections.Generic; + +public class XUIProgress : XUIObject, IXUIProgress +{ + protected float mTargetValue = -1f; + //protected bool bInAnimation = false; + + public uint totalSection = 1; + public List SectionColors; + + public UILabel sectionText; + + public float value + { + get + { + return m_uiSlider.value; + } + set + { + //if (!bInAnimation) + { + if (totalSection <= 1) + { + m_uiSlider.value = value; + + _SetSection((int)totalSection); + //if(sectionText != null) + // sectionText.alpha = 0.0f; + + if (value < logicalValue) + { + targetSection = 0; + targetValue = value; + + mDynamicVal = logicalValue; + mDynamicSection = 0; + mDynamicDelta = (mDynamicVal - value) / mDynamicStep; + } + } + else + { + int mySection = 0; + float v = 0; + GetSectionAndValue(value, ref mySection, ref v); + m_uiSlider.value = v; + + int preSection = 0; + float preV = 0; + GetSectionAndValue(logicalValue, ref preSection, ref preV); + + if (preSection == mySection && preV - v > mDynamicThreshold) + { + targetSection = mySection; + targetValue = v; + + mDynamicVal = preV; + mDynamicSection = preSection; + mDynamicDelta = (mDynamicVal - v) / mDynamicStep; + } + else if(mySection != preSection) + { + targetSection = mySection; + targetValue = v; + + mDynamicVal = preV; + mDynamicSection = preSection; + mDynamicDelta = (mDynamicVal - v + 1) / mDynamicStep; + + _SetSection(mySection); + //if (sectionText != null) + //{ + // sectionText.alpha = 1.0f; + // sectionText.text = "×" + mySection.ToString(); + //} + } + + if (SectionColors.Count > 0) + { + Color foreColor = SectionColors[mySection%SectionColors.Count]; + m_Fore.color = foreColor; + + if (mySection > 0) + { + Color backColor = SectionColors[(mySection - 1) % SectionColors.Count]; + m_Back.alpha = 1.0f; + m_Back.color = backColor; + } + else + { + m_Back.alpha = 0.0f; + } + } + + } + + logicalValue = value; + } + //else + //{ + // if (mTargetValue > m_uiSlider.value) + // {//正往上涨动画 + // if (value > m_uiSlider.value) + // { + // mTargetValue = value; + // } + // else + // { + // m_uiSlider.value = value; + // bInAnimation = false; + // } + // } + // else + // {//正往下跌动画 + // if (value < m_uiSlider.value) + // { + // mTargetValue = value; + // } + // else + // { + // m_uiSlider.value = value; + // bInAnimation = false; + // } + // } + //} + } + } + + void _SetSection(int sec) + { + if (sectionText != null) + { + if (totalSection <= 1) + { + sectionText.alpha = 0.0f; + } + else + { + sectionText.alpha = 1.0f; + //sectionText.text = "×" + sec.ToString(); + sectionText.text = "x" + sec.ToString(); + } + } + } + + void Update() + { + if (targetSection > -1 && targetValue > -1) + { + int depth = m_Fore.depth - 1; + if (mDynamicSection == targetSection) + { + if (mDynamicVal <= targetValue) + { + m_uiSlider.SetDynamicGround(0, depth); + targetSection = -1; + targetValue = -1; + + //if (logicalValue == 0) + //{ + // SetVisible(false); + //} + } + } + else if (mDynamicSection > targetSection) + { + depth = m_Fore.depth + 1; + if (mDynamicVal <= 0) + { + mDynamicSection = targetSection; + mDynamicVal = 1; + } + } + + m_uiSlider.SetDynamicGround(mDynamicVal, depth); + //mDynamicStartVal -= RealTime.deltaTime; + UpdateDynamicValue(); + + } + else + { + m_uiSlider.SetDynamicGround(0, m_Fore.depth - 1); + } + //if (bInAnimation) + //{ + // m_uiSlider.value += (mTargetValue - m_uiSlider.value)*0.02f; + + // if (Mathf.Abs(mTargetValue - m_uiSlider.value) < 0.02f) + // { + // bInAnimation = false; + // } + + //} + + } + + protected void UpdateDynamicValue() + { + mDynamicVal -= mDynamicDelta; + } + + public int width + { + get + { + return m_uiSlider.backgroundWidget.width; + } + set + { + m_uiSlider.backgroundWidget.width = value; + } + } + + public GameObject foreground + { + get + { + return m_uiSlider.mFG.gameObject; ; + } + } + + public void ForceUpdate() + { + //m_uiSlider.ForceUpdate(); + } + + public void SetDepthOffset(int d) + { + UIWidget[] w = gameObject.GetComponentsInChildren(); + + for (int i = 0; i < w.Length; i++) + { + w[i].depth += d; + } + } + + public void SetValueWithAnimation(float value) + { + //if (value != m_uiSlider.value) + //{ + // bInAnimation = true; + // mTargetValue = value; + //} + } + + public void SetTotalSection(uint section) + { + totalSection = section; + + perSection = 1.0f / totalSection; + } + + protected void GetSectionAndValue(float logicalValue, ref int section, ref float v) + { + section = (int)(logicalValue / perSection); + v = (logicalValue - section * perSection) / perSection; + } + + protected override void OnAwake() + { + base.OnAwake(); + m_uiSlider = GetComponent(); + if (null == m_uiSlider) + { + Debug.LogError("null == m_uiSlider"); + } + + m_Fore = m_uiSlider.mFG; + m_Back = m_uiSlider.mBG; + //m_Dynm= m_uiSlider.mDG; + + if (sectionText != null) + sectionText.text = (string.Empty); + } + + public void SetForegroundColor(Color c) + { + m_Fore.color = c; + } + private UISlider m_uiSlider = null; + private UIWidget m_Fore = null; + private UIWidget m_Back = null; + // private UIWidget m_Dynm = null; + + protected float perSection = 0; + protected float logicalValue = 0; + + protected float mDynamicThreshold = 0.01f; + protected float mDynamicVal = 0; + protected float mDynamicSection = 0; + protected float mDynamicDelta = 0; + protected int mDynamicStep = 12; + + protected int targetSection = -1; + protected float targetValue = -1; + + +} + diff --git a/Client/Assets/Scripts/UICommon/XUIProgress.cs.meta b/Client/Assets/Scripts/UICommon/XUIProgress.cs.meta new file mode 100644 index 00000000..f8cf9e01 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIProgress.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e76937f5afdb1964b8309cf3c8a81109 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIScript.cs b/Client/Assets/Scripts/UICommon/XUIScript.cs new file mode 100644 index 00000000..4886f7e4 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScript.cs @@ -0,0 +1,31 @@ +using UnityEngine; +using XUtliPoolLib; + +public class XUIScript : MonoBehaviour +{ + private IXGameUI _game_ui = null; + + void Awake () + { + _game_ui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + + _game_ui.UICamera = gameObject.GetComponent(); + + Transform uiRoot = transform.parent; + _game_ui.UIRoot = uiRoot; + + UIRoot nguiRoot = uiRoot.GetComponent(); + _game_ui.Base_UI_Width = nguiRoot.base_ui_width; + _game_ui.Base_UI_Height = nguiRoot.base_ui_height; + + XUICommon.singleton.Init(uiRoot); + } + + // Use this for initialization + void Start () { + } + + // Update is called once per frame + void Update () { + } +} diff --git a/Client/Assets/Scripts/UICommon/XUIScript.cs.meta b/Client/Assets/Scripts/UICommon/XUIScript.cs.meta new file mode 100644 index 00000000..e27ff81f --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScript.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 918a79f2eb17bf9489f3245c835541b3 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIScrollBar.cs b/Client/Assets/Scripts/UICommon/XUIScrollBar.cs new file mode 100644 index 00000000..5e328158 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScrollBar.cs @@ -0,0 +1,42 @@ +using UILib; +using UnityEngine; + +public class XUIScrollBar : XUIObject, IXUIScrollBar +{ + + public float value + { + get { return m_uiScrollBar.value; } + set { m_uiScrollBar.value = value; } + } + + public float size + { + get { return m_uiScrollBar.barSize; } + set { m_uiScrollBar.barSize = value; } + } + + public void RegisterScrollBarChangeEventHandler(ScrollBarChangeEventHandler eventHandler) + { + //m_scrollBarChangeEventHandler = eventHandler; + } + + public void RegisterScrollBarDragFinishedEventHandler(ScrollBarDragFinishedEventHandler eventHandler) + { + //m_scrollBarDragFinishedEventHandler = eventHandler; + } + + protected override void OnAwake() + { + base.OnAwake(); + m_uiScrollBar = GetComponent(); + if (null == m_uiScrollBar) + { + Debug.LogError("null == m_uiScrollBar"); + } + } + + private UIScrollBar m_uiScrollBar = null; + //private ScrollBarChangeEventHandler m_scrollBarChangeEventHandler = null; + //private ScrollBarDragFinishedEventHandler m_scrollBarDragFinishedEventHandler = null; +} \ No newline at end of file diff --git a/Client/Assets/Scripts/UICommon/XUIScrollBar.cs.meta b/Client/Assets/Scripts/UICommon/XUIScrollBar.cs.meta new file mode 100644 index 00000000..5f2d8248 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScrollBar.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4474d1127c619a6459eb92e6282613f6 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIScrollView.cs b/Client/Assets/Scripts/UICommon/XUIScrollView.cs new file mode 100644 index 00000000..fd301524 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScrollView.cs @@ -0,0 +1,84 @@ +using System; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUIScrollView : XUIObject, IXUIScrollView +{ + + protected override void OnAwake() + { + base.OnAwake(); + m_uiScrollView = GetComponent(); + if (null == m_uiScrollView) + { + XDebug.singleton.AddErrorLog("null == m_uiScrollView"); + } + } + + public void ResetPosition() + { + m_uiScrollView.ResetPosition(); + } + + public void UpdatePosition() + { + m_uiScrollView.UpdatePosition(); + } + + public void SetCustomMovement(Vector2 movment) + { + m_uiScrollView.customMovement = movment; + } + + public void SetPosition(float pos) + { + Vector2 pv = NGUIMath.GetPivotOffset(m_uiScrollView.contentPivot); + m_uiScrollView.SetDragAmount(pv.x, pos, false); + + // Next move the clipping area back and update the scroll bars + m_uiScrollView.SetDragAmount(pv.x, pos, true); + } + + public void SetDragPositionX(float pos) + { + Vector2 pv = NGUIMath.GetPivotOffset(m_uiScrollView.contentPivot); + m_uiScrollView.SetDragAmount(pos+pv.x, pv.y, false); + + // Next move the clipping area back and update the scroll bars + m_uiScrollView.SetDragAmount(pos + pv.x, pv.y, true); + } + + public void SetDragFinishDelegate(Delegate func) + { + m_uiScrollView.onDragFinished = (UIScrollView.OnDragFinished)func; + } + + public void SetAutoMove(float from, float to, float moveSpeed) + { + m_uiScrollView.SetAutoMove(from, to, moveSpeed); + } + + public bool RestrictWithinBounds(bool instant) + { + return m_uiScrollView.RestrictWithinBounds(instant); + } + + public void MoveAbsolute(Vector3 absolute) + { + m_uiScrollView.MoveAbsolute(absolute); + } + + public void MoveRelative(Vector3 relative) + { + m_uiScrollView.MoveRelative(relative); + } + + public void NeedRecalcBounds() + { + m_uiScrollView.NeedRecalcBounds(); + } + + private UIScrollView m_uiScrollView = null; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIScrollView.cs.meta b/Client/Assets/Scripts/UICommon/XUIScrollView.cs.meta new file mode 100644 index 00000000..974aa4b7 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIScrollView.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 900cb25e8e65a73438cf485080148d8d +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUISimpleList.cs b/Client/Assets/Scripts/UICommon/XUISimpleList.cs new file mode 100644 index 00000000..24b45137 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISimpleList.cs @@ -0,0 +1,85 @@ +using UILib; +using UnityEngine; +using System; +using System.Collections.Generic; + +public class XUISimpleList : XUIObject , IXUISimpleList +{ + public enum Sorting + { + Horizontal, + Vertical, + } + + struct SimpleNode : IComparable + { + public Transform t; + public Vector3 pos; + + public int CompareTo(SimpleNode other) + { + switch (sSorting) + { + case Sorting.Horizontal: + return sRevert * pos.x.CompareTo(other.pos.x); + case Sorting.Vertical: + return sRevert * pos.y.CompareTo(other.pos.y); + } + return 0; + } + + public static Sorting sSorting = Sorting.Horizontal; + public static int sRevert = -1; + + } + + SimpleNode[] m_OriginDatas; + + public Sorting sorting = Sorting.Horizontal; + public bool IsRevert = false; + + protected override void OnAwake() + { + base.OnAwake(); + + int count = 0; + for (int i = 0; i < transform.childCount; ++i) + { + Transform child = transform.GetChild(i); + if (child && child.gameObject) + { + ++count; + } + } + + m_OriginDatas = new SimpleNode[count]; + + for (int i = 0, j = 0; i < transform.childCount; ++i) + { + Transform child = transform.GetChild(i); + if (child && child.gameObject) + { + m_OriginDatas[j].pos = child.localPosition; + m_OriginDatas[j].t = child; + ++j; + } + } + + SimpleNode.sSorting = sorting; + SimpleNode.sRevert = IsRevert ? -1 : 1; + + Array.Sort(m_OriginDatas); + } + + public void Refresh() + { + int j = 0; + for (int i = 0; i < m_OriginDatas.Length; ++i) + { + if (m_OriginDatas[i].t == null || !m_OriginDatas[i].t.gameObject.activeSelf) + continue; + + m_OriginDatas[i].t.localPosition = m_OriginDatas[j++].pos; + } + } +} diff --git a/Client/Assets/Scripts/UICommon/XUISimpleList.cs.meta b/Client/Assets/Scripts/UICommon/XUISimpleList.cs.meta new file mode 100644 index 00000000..d10ac643 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISimpleList.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d4fa730f7281ad34eb3ac2b4de853e1a +timeCreated: 1500370749 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/UICommon/XUISlider.cs b/Client/Assets/Scripts/UICommon/XUISlider.cs new file mode 100644 index 00000000..bd81b9bd --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISlider.cs @@ -0,0 +1,52 @@ +using UILib; +using UnityEngine; + +public class XUISlider : XUIObject, IXUISlider +{ + public float Value + { + get + { + return m_uiSlider.value; + } + set + { + m_uiSlider.value = value; + } + } + + protected override void OnAwake() + { + base.OnAwake(); + m_uiSlider = GetComponent(); + if (null == m_uiSlider) + { + Debug.LogError("null == m_uiSlider"); + } + } + + public void RegisterValueChangeEventHandler(SliderValueChangeEventHandler eventHandler) + { + m_uiSlider.eventHandler = eventHandler; + } + + public void RegisterClickEventHandler(SliderClickEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onClick = OnSliderClick; + m_clickedEventHandler = eventHandler; + } + + void OnSliderClick(GameObject slider) + { + if (null != m_clickedEventHandler) + { + m_clickedEventHandler(slider); + } + } + + //private SliderValueChangeEventHandler m_valueChangeEventHandler = null; + private SliderClickEventHandler m_clickedEventHandler = null; + + private UISlider m_uiSlider = null; +} + diff --git a/Client/Assets/Scripts/UICommon/XUISlider.cs.meta b/Client/Assets/Scripts/UICommon/XUISlider.cs.meta new file mode 100644 index 00000000..7605695e --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISlider.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 965a5356607dc7c4a8062a6ed14bd37e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs b/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs new file mode 100644 index 00000000..c606ee1a --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs @@ -0,0 +1,131 @@ +using UILib; +using UnityEngine; +using XUtliPoolLib; +using System.Collections.Generic; + +public class XUISpecLabelSymbol: XUIObject, IXUISpecLabelSymbol +{ + public XUILabel _Label; + public XUISprite _Board; + public XUISprite[] _SpriteList; + public UISpriteAnimation[] _AnimationList; + public int BoardWidthOffset; + public int[] _SpriteMinHeight; + public int[] _SpriteMaxHeight; + + public IXUILabel Label { get { return _Label; } } + public IXUISprite Board { get { return _Board; } } + public IXUISprite[] SpriteList { get { return _SpriteList; } } + + public void SetColor(Color color) + { + _Label.SetColor(color); + } + + public Color GetColor() + { + return _Label.GetColor(); + } + + public void SetInputText(List sprite) // atlas null means is a label + { + int widthTol = 0; + int index = 0; + bool labelUsed = false; + List list = new List(); + List widthList = new List(); + for(int i = 0; i < sprite.Count; i++) // set ui and cal width + { + string[] strList = sprite[i].Split('|'); + if (strList.Length != 3) + continue; + if (string.IsNullOrEmpty(strList[0])) //label + { + _Label.SetVisible(true); + _Label.SetText(strList[1]); + labelUsed = true; + widthTol += _Label.spriteWidth; + list.Add(_Label.gameObject.transform); + widthList.Add(_Label.spriteWidth); + } + else + { + if (index < _SpriteList.Length && _SpriteList[index] != null) + { + _SpriteList[index].SetVisible(true); + _SpriteList[index].SetSprite(strList[1], strList[0]); + if (index < _AnimationList.Length && _AnimationList[index] != null) + { + if (strList[2] == "1") + { + _AnimationList[index].enabled = true; + _AnimationList[index].namePrefix = strList[1]; + _AnimationList[index].Reset(); + } + else + { + _AnimationList[index].enabled = false; + } + } + _SpriteList[index].MakePixelPerfect(); + int height = _SpriteList[index].spriteHeight; + int width = _SpriteList[index].spriteWidth; + int newHeight = _SpriteList[index].spriteHeight; + if (newHeight < _SpriteMinHeight[index]) + newHeight = _SpriteMinHeight[index]; + if (newHeight > _SpriteMaxHeight[index]) + newHeight = _SpriteMaxHeight[index]; + if (newHeight != height && height > 0) + { + _SpriteList[index].spriteWidth = width * newHeight / height; + _SpriteList[index].spriteHeight = newHeight; + } + widthTol += _SpriteList[index].spriteWidth; + list.Add(_SpriteList[index].gameObject.transform); + widthList.Add(_SpriteList[index].spriteWidth); + } + index++; + } + } + if(Board.IsVisible()) + Board.spriteWidth = widthTol + BoardWidthOffset; + _Label.SetVisible(labelUsed); + for (int i = index; i < _SpriteList.Length; i++) + SetSpriteVisibleFalse(i); + int startX = -widthTol / 2; + float y; + index = 0; + for(int i = 0; i < list.Count; i++) + { + y = list[i].localPosition.y; + list[i].localPosition = new Vector3(startX + widthList[i] / 2f, y); + startX += widthList[i]; + } + } + + public void SetSpriteVisibleFalse(int index) + { + _SpriteList[index].SetVisible(false); + if (index < _AnimationList.Length && _AnimationList[index] != null) + _AnimationList[index].enabled = false; + } + + public void Copy(IXUISpecLabelSymbol other) + { + gameObject.SetActive(other.IsVisible()); + _Label.SetVisible(other.IsVisible()); + _Label.SetText(other.Label.GetText()); + _Label.SetColor(other.Label.GetColor()); + _Label.transform.localPosition = other.Label.gameObject.transform.localPosition; + _Board.SetVisible(other.Board.IsVisible()); + _Board.spriteWidth = other.Board.spriteWidth; + for(int i = 0; i < _SpriteList.Length; i++) + { + _SpriteList[i].SetVisible(other.SpriteList[i].IsVisible()); + _SpriteList[i].SetSprite(other.SpriteList[i].spriteName, other.SpriteList[i].atlasPath, true); + _SpriteList[i].spriteWidth = other.SpriteList[i].spriteWidth; + _SpriteList[i].spriteHeight = other.SpriteList[i].spriteHeight; + _SpriteList[i].transform.localPosition = other.SpriteList[i].transform.localPosition; + } + } +} diff --git a/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs.meta b/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs.meta new file mode 100644 index 00000000..194e41a7 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISpecLabelSymbol.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7fa0be7bbb09d5f4aacdff8665fd0df5 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUISprite.cs b/Client/Assets/Scripts/UICommon/XUISprite.cs new file mode 100644 index 00000000..6dbd3b60 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISprite.cs @@ -0,0 +1,495 @@ +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUISprite : XUIObject, IXUISprite +{ + public IXUIAtlas uiAtlas + { + get + { + if (null != m_uiSprite) + { + if (null == m_uiSprite.atlas) + { + return null; + } + return m_uiSprite.atlas.GetComponent(); + } + else + { + return null; + } + } + } + + public string spriteName + { + get + { + if (null != m_uiSprite) + { + return m_uiSprite.spriteName; + } + else + { + return null; + } + } + + set + { + if (!SetSpriteByCode(value)) + { + m_uiSprite.spriteName = value; + } + } + } + + public int spriteWidth + { + get + { + return m_uiSprite.width; + } + set + { + m_uiSprite.width = value; + } + } + + public int spriteHeight { + get + { + return m_uiSprite.height; + } + set + { + m_uiSprite.height = value; + } + } + + public int spriteDepth + { + get + { + return m_uiSprite.depth; + } + set + { + m_uiSprite.depth = value; + } + } + + public string atlasPath + { + get + { + return m_uiSprite.atlasPath; + } + } + + public Vector4 drawRegion + { + get + { + return m_uiSprite.drawRegion; + } + set + { + m_uiSprite.drawRegion = value; + } + } + + + public bool SetSpriteByCode(string code) + { + if (!string.IsNullOrEmpty(code)) + { + if (code[0] == '|') + { + string[] str = code.Split('|'); + if (str.Length == 3) + { + SetSprite(str[1], str[2]); + } + return true; + } + } + return false; + } + + public bool SetSprite(string strSprite, string strAtlas, bool fullAtlasName = false) + { + if (null == m_uiSprite) + { + return false; + } + m_uiSprite.spriteName = strSprite; + if(string.IsNullOrEmpty(strAtlas)) + { + m_uiSprite.SetAtlas(""); + } + else + { + if(fullAtlasName) + m_uiSprite.SetAtlas(strAtlas); + else + m_uiSprite.SetAtlas("atlas/UI/" + strAtlas); + } + + + return true; + } + + public void MakePixelPerfect() + { + if (m_uiSprite == null) + { + XDebug.singleton.AddErrorLog("Sprite is Null"); + return; + } + m_uiSprite.MakePixelPerfect(); + } + + public void SetRootAsUIPanel(bool bFlg) + { + if (bFlg) + { + m_uiSprite.SetPanel(XUICommon.singleton.m_uiRootPanel); + } + else + { + m_uiSprite.SetPanel(null); + } + } + + public void SetColor(Color c) + { + m_uiSprite.color = c; + } + + private void OnLoadAtlasFinished(UnityEngine.Object obj) + { + UIAtlas uiAtlas = obj as UIAtlas; + if (null == uiAtlas) + { + Debug.LogError("null == uiAtlas"); + return; + } + m_uiSprite.spriteName = m_spriteNameCached; + m_uiSprite.atlas = uiAtlas; + + } + + public void ResetPanel() + { + m_uiSprite.panel = null; + } + + public bool SetSprite(string strSpriteName) + { + if (null == m_uiSprite) + { + return false; + } + if (!SetSpriteByCode(strSpriteName)) + { + m_uiSprite.spriteName = strSpriteName; + } + return true; + } + + public void SetEnabled(bool bEnabled) + { + m_bEnabled = bEnabled; + + SetGrey(bEnabled); + } + + public static Color GREY_COLOR = new Color(0, 0, 0, 0.7f); + public void SetGrey(bool bGrey) + { + if (bGrey) + { + m_uiSprite.color = m_sourceColor; + } + else + { + m_uiSprite.color = GREY_COLOR; + } + + UISprite[] sp = gameObject.GetComponentsInChildren(true); + + for (int i = 0; i < sp.Length; i++) + { + sp[i].color = bGrey ? Color.white : GREY_COLOR; + } + } + + public void SetAlpha(float alpha) + { + m_uiSprite.color = new Color(m_uiSprite.color.r, m_uiSprite.color.g, m_uiSprite.color.b, alpha); + } + + public float GetAlpha() + { + return m_uiSprite.alpha; + } + + public void SetAudioClip(string name) + { + audioClip = name; + } + + public void CloseScrollView() + { + UIDragScrollView m_ScrollView= GetComponent(); + if (m_ScrollView != null) + { + m_ScrollView.enabled = false; + } + } + + public void RegisterSpriteClickEventHandler(SpriteClickEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onClick -= OnSpriteClick; + UIEventListener.Get(this.gameObject).onClick += OnSpriteClick; + + m_spriteClickEventHandler = eventHandler; + } + + public void RegisterSpritePressEventHandler(SpritePressEventHandler eventHandler) + { + m_spritePressEventHandler = eventHandler; + } + + public void RegisterSpriteDragEventHandler(SpriteDragEventHandler eventHandler) + { + m_spriteDragEventHandler = eventHandler; + } + + protected override void OnAwake() + { + base.OnAwake(); + + m_gameui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + m_tutorial = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XTutorial")); + m_operation = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XOperationRecord")); + + m_uiSprite = GetComponent(); + if (!string.IsNullOrEmpty(SpriteAtlasPath)) + { + SetSprite(SPriteName, SpriteAtlasPath); + SPriteName = ""; + SpriteAtlasPath = ""; + } + if (null == m_uiSprite) + { + Debug.Log("null == m_uiSprite," + this.gameObject.name); + } + m_sourceColor = m_uiSprite.color; + + CloneFromTpl(); + + if (m_NeedAudio && (string.IsNullOrEmpty(audioClip) || !audioClip.StartsWith("Audio"))) + SetAudioClip("Audio/UI/UI_Button_ok"); + + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + + ClickCanceled = false; + } + + protected void CloneFromTpl() + { + if (m_SpriteAnimationType <= 0) return; + + GameObject tpl = m_gameui.spriteTpl[m_SpriteAnimationType - 1]; + + XUICommon.CloneTplTweens(tpl, gameObject); + } + + void OnSpriteClick(GameObject button) + { + if (!m_bEnabled) return; + if (ClickCanceled) + { + ClickCanceled = false; + return; + } + + if (m_CD.IsInCD()) + return; + + if (m_tutorial != null && m_tutorial.NoforceClick && Exculsive) + { + if (null != m_spriteClickEventHandler) + { + m_spriteClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + m_tutorial.OnTutorialClicked(); + Exculsive = false; + } + else if (m_tutorial == null || !m_tutorial.Exculsive) + { + if (null != m_spriteClickEventHandler) + { + m_spriteClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + } + else if (m_tutorial.Exculsive && Exculsive) + { + if (null != m_spriteClickEventHandler) + { + m_spriteClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + m_tutorial.OnTutorialClicked(); + Exculsive = false; + } + else + { + XDebug.singleton.AddLog("Exculsive block"); + } + if (m_NeedAudio && !string.IsNullOrEmpty(audioClip)) + NGUITools.PlayFmod("event:/" + audioClip); + } + + public SpriteClickEventHandler GetSpriteClickHandler() + { + return m_spriteClickEventHandler; + } + + public SpritePressEventHandler GetSpritePressHandler() + { + return m_spritePressEventHandler; + } + + protected override void OnPress(bool isPressed) + { + if (!m_bEnabled) return; + + if (null != m_spritePressEventHandler) + { + m_spritePressEventHandler(this, isPressed); + } + } + + protected override void OnDrag(Vector2 delta) + { + if (!m_bEnabled) return; + + if (null != m_spriteDragEventHandler && m_invalidDrag) + { + m_spriteDragEventHandler(delta); + } + } + + protected void OnDragOut(GameObject go) + { + m_invalidDrag = false; + } + + protected void OnDragOver(GameObject go) + { + m_invalidDrag = true; + } + + public void SetFillAmount(float val) + { + m_uiSprite.fillAmount = val; + } + + public void SetFlipHorizontal(bool bValue) + { + if(bValue) + m_uiSprite.flip = UISprite.Flip.Horizontally; + else + m_uiSprite.flip = UISprite.Flip.Nothing; + } + + public void SetFlipVertical(bool bValue) + { + if (bValue) + m_uiSprite.flip = UISprite.Flip.Vertically; + else + m_uiSprite.flip = UISprite.Flip.Nothing; + } + + public void ResetAnimationAndPlay() + { + m_Animation = GetComponent(); + + if (m_Animation == null) return; + + gameObject.SetActive(true); + + m_Animation.Reset(); + + m_Animation.LastLoopFinishTime = RealTime.time; + } + + public void UpdateAnchors() + { + m_uiSprite.UpdateAnchors(); + } + + public bool IsEnabled() + { + return m_bEnabled; + } + + public void SetClickCD(float cd) + { + CustomClickCD = cd; + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + } + + public void ResetCD() + { + m_CD.Reset(); + } + + public IXUIPanel GetPanel() + { + return XUIPanel.GetPanel(m_uiSprite.panel); + } + + public int m_SpriteAnimationType = 0; + private UISprite m_uiSprite = null; + public string audioClip; + public bool m_NeedAudio = true; + + public float CustomClickCD = -1f; + public int CustomClickCDGroup = 0; + + private XUICD m_CD = new XUICD(); + + [Range(0f, 1f)] + public float volume = 1f; + [Range(0f, 2f)] + public float pitch = 1f; + + public string SpriteAtlasPath = ""; + public string SPriteName = ""; + //private UIPanel m_uiRootPanel = null; + private UISpriteAnimation m_Animation = null; + private SpriteClickEventHandler m_spriteClickEventHandler = null; + //private SpriteClickEventHandler m_spriteLongPressEventHandler = null; + private SpritePressEventHandler m_spritePressEventHandler = null; + private SpriteDragEventHandler m_spriteDragEventHandler = null; + private string m_spriteNameCached = ""; + private bool m_bEnabled = true; + private Color m_sourceColor; + + private IXTutorial m_tutorial = null; + private IXGameUI m_gameui = null; + private IXOperationRecord m_operation = null; + + private bool m_invalidDrag = false; + + public bool ClickCanceled { get; set; } +} + diff --git a/Client/Assets/Scripts/UICommon/XUISprite.cs.meta b/Client/Assets/Scripts/UICommon/XUISprite.cs.meta new file mode 100644 index 00000000..acb3c7a0 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISprite.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e7fcc98968f02ce44b67e94f1124549e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs b/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs new file mode 100644 index 00000000..73b379b9 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs @@ -0,0 +1,74 @@ +using System; +using UILib; +using UnityEngine; + +public delegate void SpriteAnimationFinishEventHandler(); +public class XUISpriteAnimation : XUIObject, IXUISpriteAnimation +{ + protected override void OnAwake() + { + base.OnAwake(); + + m_Animation = GetComponent(); + if (m_Animation == null) + { + Debug.Log("no UISpriteAnimation component"); + } + } + + public void SetNamePrefix(string name) + { + m_Animation.namePrefix = name; + m_Animation.Reset(); + } + + public void SetNamePrefix(string atlas, string name) + { + m_Animation.sprite.SetAtlas("atlas/UI/" + atlas); + SetNamePrefix(name); + } + + public void SetFrameRate(int rate) + { + m_Animation.framesPerSecond = rate; + } + + public void Reset() + { + m_Animation.Reset(); + m_Animation.LastLoopFinishTime = RealTime.time; + } + + public void StopAndReset() + { + m_Animation.StopAndReset(); + } + + public void RegisterFinishCallback(SpriteAnimationFinishCallback callback) + { + if (callback != null) + { + m_FinishCallback = callback; + m_Animation.FinishHandler = _SpriteAnimationFinished; + } + } + + public void MakePixelPerfect() + { + if (m_Animation != null && m_Animation.sprite != null) + m_Animation.sprite.MakePixelPerfect(); + } + + public void _SpriteAnimationFinished() + { + if (m_FinishCallback != null) + m_FinishCallback(this); + } + + + + private UISpriteAnimation m_Animation; + SpriteAnimationFinishCallback m_FinishCallback; + + +} diff --git a/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs.meta b/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs.meta new file mode 100644 index 00000000..373bb216 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUISpriteAnimation.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b43c49c038d07af44b8de8eee9834a42 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUITable.cs b/Client/Assets/Scripts/UICommon/XUITable.cs new file mode 100644 index 00000000..dee9187f --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITable.cs @@ -0,0 +1,32 @@ +using UILib; +using UnityEngine; + +public class XUITable : MonoBehaviour, IXUITable +{ + private void Awake() + { + m_table = GetComponent(); + + if (null == m_table) + { + Debug.LogError("null == m_table"); + } + } + + public void RePositionNow() + { + m_table.repositionNow = true; + } + + public void Reposition() + { + m_table.Reposition(); + } + + public void RePositionOnlyOneLevel() + { + m_table.RepositionOnlyOneLevel(); + } + + private UITable m_table; +} diff --git a/Client/Assets/Scripts/UICommon/XUITable.cs.meta b/Client/Assets/Scripts/UICommon/XUITable.cs.meta new file mode 100644 index 00000000..6a7ea33e --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITable.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 035d5114ecd910d48af5761ae5bf46db +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUITexture.cs b/Client/Assets/Scripts/UICommon/XUITexture.cs new file mode 100644 index 00000000..65b0642f --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITexture.cs @@ -0,0 +1,203 @@ +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUITexture : XUIObject, IXUITexture +{ + public int spriteWidth + { + get + { + return m_uiTexture.width; + } + set + { + m_uiTexture.width = value; + } + } + + public int spriteHeight + { + get + { + return m_uiTexture.height; + } + set + { + m_uiTexture.height = value; + } + } + + public int spriteDepth + { + get + { + return m_uiTexture.depth; + } + set + { + m_uiTexture.depth = value; + } + } + + public int aspectRatioSource + { + get + { + return (int)m_uiTexture.keepAspectRatio; + } + set + { + m_uiTexture.keepAspectRatio = (UIWidget.AspectRatioSource)value; + } + } + public void SetRuntimeTex(Texture texture, bool autoDestroy = true) + { + if (null != m_uiTexture && !m_uiTexture.Equals(null) && (m_uiTexture is UITexture)) + { + (m_uiTexture as UITexture).SetRuntimeTexture(texture, autoDestroy); + } + } + + + public void SetTexturePath(string path) + { + if (null != m_uiTexture && !m_uiTexture.Equals(null)) + { + m_uiTexture.SetTexture(path/*, m_uiTexture.mtexType*/); + } + } + + //public Texture GetTexture() + //{ + // return m_uiTexture.mainTexture; + //} + public void SetUVRect(Rect rect) + { + if(m_uiTexture is UITexture) + (m_uiTexture as UITexture).uvRect = rect; + } + + public void SetEnabled(bool bEnabled) + { + if (bEnabled) + { + m_uiTexture.color = Color.white; + } + else + { + m_uiTexture.color = new Color(0, 0, 0, 1); + } + } + + public void SetColor(Color color) + { + m_uiTexture.color = color; + } + + public void SetAlpha(float alpha) + { + m_uiTexture.alpha = alpha; + } + + public void MakePixelPerfect() + { + m_uiTexture.MakePixelPerfect(); + } + + public void RegisterLabelClickEventHandler(TextureClickEventHandler eventHandler) + { + UIEventListener.Get(this.gameObject).onClick = OnTextureClick; + m_textureClickEventHandler = eventHandler; + } + + void OnTextureClick(GameObject button) + { + + if (m_CD.IsInCD()) + return; + + if (m_tutorial != null && m_tutorial.NoforceClick && Exculsive) + { + if (null != m_textureClickEventHandler) + { + m_textureClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + m_tutorial.OnTutorialClicked(); + Exculsive = false; + } + else if (m_tutorial == null || !m_tutorial.Exculsive) + { + if (null != m_textureClickEventHandler) + { + m_textureClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + } + else if (m_tutorial.Exculsive && Exculsive) + { + if (null != m_textureClickEventHandler) + { + m_textureClickEventHandler(this); + if (m_operation != null) m_operation.FindRecordID(button.transform); + } + m_tutorial.OnTutorialClicked(); + Exculsive = false; + } + else + { + XDebug.singleton.AddLog("Exculsive block"); + } + } + + protected override void OnAwake() + { + base.OnAwake(); + m_uiTexture = GetComponent(); + m_tutorial = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XTutorial")); + m_operation = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XOperationRecord")); + //if (!string.IsNullOrEmpty(TexturePath)) + //{ + // SetTexturePath("atlas/UI/" + TexturePath); + //} + //if (null == m_uiTexture) + //{ + // Debug.LogError("null == m_uiTexture"); + //} + + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + } + + public TextureClickEventHandler GetTextureClickHandler() + { + return m_textureClickEventHandler; + } + + public void CloseScrollView() + { + UIDragScrollView m_ScrollView = GetComponent(); + if (m_ScrollView != null) + { + m_ScrollView.enabled = false; + } + } + + public void SetClickCD(float cd) + { + CustomClickCD = cd; + m_CD.SetClickCD(CustomClickCDGroup, CustomClickCD); + } + + private IXTutorial m_tutorial = null; + private UITexture m_uiTexture = null; + private TextureClickEventHandler m_textureClickEventHandler; + private IXOperationRecord m_operation = null; + + public float CustomClickCD = -1f; + public int CustomClickCDGroup = 0; + + //public string TexturePath = ""; + + private XUICD m_CD = new XUICD(); +} diff --git a/Client/Assets/Scripts/UICommon/XUITexture.cs.meta b/Client/Assets/Scripts/UICommon/XUITexture.cs.meta new file mode 100644 index 00000000..7885bf7a --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITexture.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 90f12c5de0ce6fd4b8c96f3f3a68f97f +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUITool.cs b/Client/Assets/Scripts/UICommon/XUITool.cs new file mode 100644 index 00000000..50f9b6e0 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITool.cs @@ -0,0 +1,279 @@ +using UILib; +using UnityEngine; +using System.Collections.Generic; +using System.Collections; +using XUtliPoolLib; + +public class XUITool : MonoBehaviour, IXUITool +{ + public static XUITool Instance { get { return s_instance; } } + + private Dictionary _TweenFadeInGroupDelayNum = new Dictionary(); + private IXGameUI m_gameui = null; + private GameObject m_preloadBillboard = null; + private GameObject m_preloadTitle = null; + + public IXGameUI XGameUI + { + get + { + if (m_gameui == null) + { + m_gameui = XInterfaceMgr.singleton.GetInterface(XCommon.singleton.XHash("XGameUI")); + } + return m_gameui; + } + } + public Camera GetUICamera() + { + return UICamera.currentCamera; + } + + public void SetActive(GameObject obj, bool state) + { + NGUITools.SetActive(obj, state); + } + + public void SetLayer(GameObject go, int layer) + { + go.layer = layer; + Transform t = go.transform; + for (int i=0, imax = t.childCount; i(); + XUILabel[] la = go.GetComponentsInChildren(); + XUITexture[] te = go.GetComponentsInChildren(); + + for(int i = 0; i < sp.Length; ++i) + { + sp[i].spriteDepth += delta; + } + + for(int i = 0; i < la.Length; ++i) + { + la[i].spriteDepth += delta; + } + + for(int i = 0; i < te.Length; ++i) + { + te[i].spriteDepth += delta; + } + } + + public void SetUIEventFallThrough(GameObject obj) + { + UICamera.fallThrough = obj; + } + + public void SetUIGenericEventHandle(GameObject obj) + { + UICamera.genericEventHandler = obj; + } + + public void ShowTooltip(string str) + { + UITooltip.ShowText(str); + } + + public void RegisterLoadUIAsynEventHandler(LoadUIAsynEventHandler eventHandler) + { + m_loadUIAsynEventHandler = eventHandler; + } + + public void LoadResAsyn(string strFile, LoadUIFinishedEventHandler eventHandler) + { + if (null != m_loadUIAsynEventHandler) + { + //m_loadUIAsynEventHandler(strFile, eventHandler); + } + else + { + Debug.LogError("null == m_loadUIAsynEventHandler"); + } + + } + + public void SetCursor(string strSpriteName) + { + //UICursor.Set(strSpriteName); + } + + public void SetCursor(string strSprite, string strAtlas) + { +// if (null != UICursor.Instance) +// { +// } + } + + public void PlayAnim(Animation anim, string strClipName, AnimFinishedEventHandler eventHandler) + { + if (null == anim || null == strClipName || strClipName.Length == 0) + { + eventHandler(); + return; + } + //ActiveAnimation.Play(anim, strClipName, Direction.Forward, EnableCondition.DoNothing, DisableCondition.DoNotDisable, eventHandler); + } + + private void Awake() + { + s_instance = this; + } + + public void MarkParentAsChanged(GameObject go) + { + NGUITools.MarkParentAsChanged(go); + } + public void HideGameObject(GameObject go) + { + NGUITools.ParentPanelChanged(go, XUICommon.singleton.m_inVisiablePanel); + } + + public void ShowGameObject(GameObject go, IXUIPanel panel) + { + XUIPanel p = panel as XUIPanel; + if (p != null) + NGUITools.ParentPanelChanged(go, p.UIComponent as UIPanel); + else + NGUITools.MarkParentAsChanged(go); + } + + public void ChangePanel(GameObject go, IUIRect parent, IXUIPanel panel) + { + XUIPanel p = panel as XUIPanel; + UIRect pp = parent as UIRect; + if (p != null) + NGUITools.ParentPanelChanged(go, pp, p.UIComponent as UIPanel); + + } + public void ChangePanel(GameObject go, IUIRect parent, IUIPanel panel) + { + UIPanel p = panel as UIPanel; + UIRect pp = parent as UIRect; + if (p != null) + NGUITools.ParentPanelChanged(go, pp, p); + + } + public string GetLocalizedStr(string key) + { + return Localization.Get(key); + } + + void IXUITool.Destroy(UnityEngine.Object obj) + { + NGUITools.Destroy(obj); + } + + private LoadUIAsynEventHandler m_loadUIAsynEventHandler = null; + //private string m_spriteNameForCusorCached = ""; + static XUITool s_instance = null; + + public Vector2 CalculatePrintedSize(string text) + { + return NGUIText.CalculatePrintedSize(text); + } + + public void ReleaseAllDrawCall() + { + UIDrawCall.ReleaseInactive(); + } + + bool delayDealWith = false; + void LateUpdate() + { + if(delayDealWith) + { + delayDealWith = false; + ClearFadeInGroupDict(); + } + } + + public bool GetTweenFadeInDelayByGroup(int group, float interval, int max, out float addDelay) + { + addDelay = 0f; + + if(_TweenFadeInGroupDelayNum.Count == 0) + { + //StartCoroutine(ClearFadeInGroupDict()); + delayDealWith = true; + } + + uint num; + if (!_TweenFadeInGroupDelayNum.TryGetValue(group, out num)) + { + _TweenFadeInGroupDelayNum[group] = 0; + num = 0; + addDelay = 0; + return true; + } + else + { + _TweenFadeInGroupDelayNum[group] = num + 1; + num++; + if (num >= max) + return false; + addDelay = num * interval; + return true; + } + } + + void ClearFadeInGroupDict() + { + //yield return new WaitForEndOfFrame(); + _TweenFadeInGroupDelayNum.Clear(); + } + + public void ResetGroupDelay(int group) + { + if (_TweenFadeInGroupDelayNum.ContainsKey(group)) + _TweenFadeInGroupDelayNum.Remove(group); + } + + public void SetRootPanelUpdateFreq(int count) + { + XUICommon.singleton.SetRootPanelUpdateFreq(count); + } + + public void PreLoad(bool load) + { + if(load) + { + if (m_preloadBillboard == null) + m_preloadBillboard = XResourceLoaderMgr.singleton.GetSharedResource("atlas/UI/common/Billboard", ".prefab"); + if (m_preloadTitle == null) + m_preloadTitle = XResourceLoaderMgr.singleton.GetSharedResource("atlas/UI/common/Title", ".prefab"); + } + else + { + XResourceLoaderMgr.SafeDestroyShareResource("atlas/UI/common/Billboard", ref m_preloadBillboard); + XResourceLoaderMgr.SafeDestroyShareResource("atlas/UI/common/Title", ref m_preloadTitle); + } + } + + public void EnableUILoadingUpdate(bool enable) + { + NGUITools.mEnableLoadingUpdate = enable; + } + + public void SetUIOptOption(bool globalMerge,bool selectMerge,bool lowDeviceMerge) + { + //disable global ui merge if we are using low device + if ( XUpdater.XUpdater.singleton.XPlatform.GetQualityLevel () == 0 && !lowDeviceMerge) + { + UIPanel.GlobalUseMerge = false; + UIPanel.SelectUseMerge = selectMerge; + } else { + UIPanel.GlobalUseMerge = globalMerge; + UIPanel.SelectUseMerge = selectMerge; + } + + } +} + diff --git a/Client/Assets/Scripts/UICommon/XUITool.cs.meta b/Client/Assets/Scripts/UICommon/XUITool.cs.meta new file mode 100644 index 00000000..df5a5e3f --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITool.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4f76556fd996409439d25a037dffff20 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUITweener.cs b/Client/Assets/Scripts/UICommon/XUITweener.cs new file mode 100644 index 00000000..6249ec8d --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITweener.cs @@ -0,0 +1,33 @@ +using AnimationOrTween; +using UILib; +using UnityEngine; + +namespace Assets.Scripts.UICommon +{ + class XUITweener: MonoBehaviour, IXUITweener + { + public UITweener TargetTweener; + public float Duration + { + get + { + if (m_uiTweer != null) + { + return m_uiTweer.duration; + } + return 0; + } + } + private void Awake() + { + if (TargetTweener != null) m_uiTweer = TargetTweener; + else m_uiTweer = GetComponent(); + + if (null == m_uiTweer) + { + Debug.LogError("null == m_uiTweer " + gameObject.name); + } + } + private UITweener m_uiTweer; + } +} diff --git a/Client/Assets/Scripts/UICommon/XUITweener.cs.meta b/Client/Assets/Scripts/UICommon/XUITweener.cs.meta new file mode 100644 index 00000000..696fe5d5 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUITweener.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fefdd2e83626b8c42a7e9a1745baa74b +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/UICommon/XUIWrapContent.cs b/Client/Assets/Scripts/UICommon/XUIWrapContent.cs new file mode 100644 index 00000000..d167a64b --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIWrapContent.cs @@ -0,0 +1,201 @@ +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +public class XUIWrapContent : XUIObject, IXUIWrapContent +{ + + protected override void OnAwake() + { + base.OnAwake(); + m_uiWrapContent = GetComponent(); + if (null == m_uiWrapContent) + { + Debug.LogError("null == m_uiWrapContent"); + } + + m_uiWrapContent.updateHandler = OnItemUpdate; + + if (Tpl == null) + { + Debug.LogError("Tpl == null"); + } + + if (!m_uiWrapContent.Init()) + { + Debug.LogError("m_uiWrapContent.Init Failed"); + } + } + + protected override void OnStart() + { + base.OnStart(); + + if (!m_ItemPool.IsValid) + m_ItemPool.SetupPool(this.gameObject, Tpl, (uint)maxItemCount, false); + } + + public bool enableBounds + { + get + { + return m_uiWrapContent.bBounds; + } + set + { + m_uiWrapContent.bBounds = value; + } + } + + public Vector2 itemSize + { + get + { + return m_uiWrapContent.itemSize; + } + set + { + m_uiWrapContent.itemSize = value; + } + } + + public int widthDimension + { + get + { + return m_uiWrapContent.WidthDimension; + } + set + { + m_uiWrapContent.WidthDimension = value; + } + } + + public int heightDimensionMax + { + get + { + return m_uiWrapContent.HeightDimemsionMax; + } + } + public int maxItemCount + { + get + { + return (m_uiWrapContent.HeightDimemsionMax + 2) * m_uiWrapContent.WidthDimension; + } + } + + //public void SetBounds(int lowerBound, int upperBound) + //{ + // m_uiWrapContent.lowerBound = lowerBound; + // m_uiWrapContent.upperBound = upperBound; + // m_uiWrapContent.bBounds = true; + // m_uiWrapContent.AdjustContent(); + //} + + protected void _InitContent(int count, bool fadeIn = false) + { + int goCount = Mathf.Min(count, maxItemCount); + + if(!m_ItemPool.IsValid) + m_ItemPool.SetupPool(this.gameObject, Tpl, (uint)maxItemCount, false); + + if (fadeIn || goCount != m_ItemPool.ActiveCount) + { + BetterList itemList = m_uiWrapContent.ItemList; + itemList.Clear(); + if (fadeIn) + m_ItemPool.ReturnAll(); + else + m_ItemPool.FakeReturnAll(); + for (int i = 0; i < goCount; ++i) + { + GameObject go = m_ItemPool.FetchGameObject(fadeIn); + itemList.Add(go.transform); + OnItemInit(go.transform, i); + } + if(!fadeIn) + m_ItemPool.ActualReturnAll(); + + m_uiWrapContent.SetChildPositionOffset(0); + } + } + + private int _GetRowCount(int count, int columnCount) + { + if (count <= 0) + return 0; + return ((count - 1) / columnCount + 1); + } + + public void SetContentCount(int num, bool fadeIn = false) + { + if (m_uiWrapContent.WidthDimension != 1) + { + num = _GetRowCount(num, m_uiWrapContent.WidthDimension) * m_uiWrapContent.WidthDimension; + } + + m_uiWrapContent.SetContentCount(num); + _InitContent(num, fadeIn); + m_uiWrapContent.AdjustContent(); + } + + private void OnItemUpdate(Transform item, int index) + { + if (updateHandler != null) + updateHandler(item, index); + } + + private void OnItemInit(Transform item, int index) + { + if (initHandler != null) + initHandler(item, index); + } + + public void RegisterItemUpdateEventHandler(WrapItemUpdateEventHandler eventHandler) + { + updateHandler = eventHandler; + } + + public void RegisterItemInitEventHandler(WrapItemInitEventHandler eventHandler) + { + initHandler = eventHandler; + } + + public void ResetPosition() + { + SetOffset(0); + } + + public void SetOffset(int offset) + { + m_uiWrapContent.SetChildPositionOffset(offset); + m_uiWrapContent.WrapContent(); + } + + public void InitContent() + { + m_uiWrapContent.Init(); + } + + public void RefreshAllVisibleContents() + { + m_uiWrapContent.RefreshAllChildrenContent(); + } + + public void GetActiveList(List ret) + { + m_ItemPool.GetActiveList(ret); + } + + + private UIWrapContent m_uiWrapContent = null; + private WrapItemUpdateEventHandler updateHandler; + private WrapItemInitEventHandler initHandler; + private XUtliPoolLib.XUIPool m_ItemPool = new XUtliPoolLib.XUIPool(null); + + public GameObject Tpl; +} + diff --git a/Client/Assets/Scripts/UICommon/XUIWrapContent.cs.meta b/Client/Assets/Scripts/UICommon/XUIWrapContent.cs.meta new file mode 100644 index 00000000..52b1da13 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIWrapContent.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4e2b055c7cb516c449ba6c331aa36384 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0