summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/UICommon/XUIInput.cs
blob: 45f23042b17ab5a2f1a8c3bd90c9a5d4a8ac35bb (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
using UILib;
using UnityEngine;

public class XUIInput : XUIObject, IXUIInput
{
    protected override void OnAwake()
    {
		base.OnAwake();
        m_uiInput = GetComponent<UIInput>();
        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;
}