summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/UICommon/XUITexture.cs
blob: 65b0642f9d7c3be9013ee9a8264145767607f073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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<UITexture>();
        m_tutorial = XInterfaceMgr.singleton.GetInterface<IXTutorial>(XCommon.singleton.XHash("XTutorial"));
        m_operation = XInterfaceMgr.singleton.GetInterface<IXOperationRecord>(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<UIDragScrollView>();
        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();
}