summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Chat/ChatEmotionView.cs
blob: 0e8942aa946ef55f3cd720560ab3ef3221f1b92d (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
using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;

namespace XMainClient
{
	internal class ChatEmotionView : DlgBase<ChatEmotionView, ChatEmotionBehaviour>
	{
		public override string fileName
		{
			get
			{
				return "Common/ChatEmotion";
			}
		}

		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		private string m_Emotion = "fsbq_";

		private string m_EmotionText = "z";

		private const int CHAT_MAX_EMOTION_NUM = 24;

		private ChatSelectStringBack _func = null;

		private List<string> emotion = new List<string>();

		protected override void Init()
		{
			base.Init();
			string[] array = new string[]
			{
				"z",
				"g",
				"f"
			};
			this.m_Emotion = "@2x";
			this.m_EmotionText = array[0];
			for (int i = 0; i < 24; i++)
			{
				GameObject gameObject = base.uiBehaviour.m_ChatEmotionPool.FetchGameObject(false);
				gameObject.transform.localPosition = new Vector3(base.uiBehaviour.m_ChatEmotionPool.TplPos.x + (float)(i % 6 * base.uiBehaviour.m_ChatEmotionPool.TplWidth), base.uiBehaviour.m_ChatEmotionPool.TplPos.y - (float)(i / 6 * base.uiBehaviour.m_ChatEmotionPool.TplHeight), base.uiBehaviour.m_ChatEmotionPool.TplPos.z);
				IXUISprite ixuisprite = gameObject.transform.GetComponent("XUISprite") as IXUISprite;
				ixuisprite.SetSprite(string.Format("{0:D3}", i) + this.m_Emotion);
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnSelectEmotion));
				ixuisprite.ID = (ulong)((long)i);
			}
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			base.uiBehaviour.m_sprP.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.CloseEmotion));
		}

		public void ShowChatEmotion(ChatSelectStringBack func, Vector3 pos, int pivot)
		{
			this._func = func;
			this.SetVisible(true, true);
			base.uiBehaviour.m_sprEmotion.gameObject.transform.localPosition = pos;
			this.SetPivot(pivot);
		}

		public void SetPivot(int pivot)
		{
			bool flag = pivot == 0;
			if (flag)
			{
				this.m_uiBehaviour.m_sprEmotion.SetFlipVertical(false);
			}
			else
			{
				bool flag2 = pivot == 1;
				if (flag2)
				{
					this.m_uiBehaviour.m_sprEmotion.SetFlipHorizontal(true);
				}
				else
				{
					bool flag3 = pivot == 2;
					if (flag3)
					{
						this.m_uiBehaviour.m_sprEmotion.SetFlipVertical(true);
					}
				}
			}
		}

		private void CloseEmotion(IXUISprite spr)
		{
			this.SetVisible(false, true);
		}

		public void OnSelectEmotion(IXUISprite sp)
		{
			ulong id = sp.ID;
			string str = "/" + this.m_EmotionText + string.Format("{0:D2}", id);
			bool flag = this._func != null;
			if (flag)
			{
				this._func(str);
			}
			this.CloseEmotion(sp);
		}

		public string OnParseEmotion(string content)
		{
			this.emotion.Clear();
			for (int i = 0; i < content.Length; i++)
			{
				bool flag = content[i] == '/' && i + 4 <= content.Length;
				if (flag)
				{
					string s = content[i + 2].Equals('0') ? content.Substring(i + 3, 1) : content.Substring(i + 2, 2);
					int num = 0;
					bool flag2 = int.TryParse(s, out num);
					if (flag2)
					{
						bool flag3 = num < 24;
						if (flag3)
						{
							this.emotion.Add(content.Substring(i, 4));
						}
					}
				}
			}
			for (int j = 0; j < this.emotion.Count; j++)
			{
				string text = this.emotion[j];
				bool flag4 = text[1] == 'z' || text[1] == 'g' || text[1] == 'f';
				if (flag4)
				{
					string str = "@2x";
					string sprite = "0" + text.Substring(2, 2) + str;
					string newValue = XLabelSymbolHelper.FormatImage("Chat/Chat", sprite);
					content = content.Replace(text, newValue);
				}
			}
			return content;
		}

		public string OnRemoveEmotion(string content)
		{
			this.emotion.Clear();
			for (int i = 0; i < content.Length; i++)
			{
				bool flag = content[i] == '/' && i + 4 <= content.Length;
				if (flag)
				{
					string s = content[i + 2].Equals('0') ? content.Substring(i + 3, 1) : content.Substring(i + 2, 2);
					int num = 0;
					bool flag2 = int.TryParse(s, out num);
					if (flag2)
					{
						bool flag3 = num < 24;
						if (flag3)
						{
							this.emotion.Add(content.Substring(i, 4));
						}
					}
				}
			}
			for (int j = 0; j < this.emotion.Count; j++)
			{
				string text = this.emotion[j];
				bool flag4 = text[1] == 'z' || text[1] == 'g' || text[1] == 'f';
				if (flag4)
				{
					content = content.Replace(text, string.Empty);
				}
			}
			return content;
		}
	}
}