using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class ChatFaceItemCell : CellView
|
{
|
[SerializeField] List<ImageEx> imgFaceList;
|
[SerializeField] HorizontalLayoutGroup horizontalLayoutGroup;
|
[SerializeField] RectTransform rectTransform;
|
int rowIndex;
|
PhantasmPavilionModel model { get { return ModelCenter.Instance.GetModel<PhantasmPavilionModel>(); } }
|
ChatCenter chatCenter { get { return ModelCenter.Instance.GetModel<ChatCenter>(); } }
|
public void Display(int rowIndex)
|
{
|
this.rowIndex = rowIndex;
|
int id = model.selectEmojiPackID;
|
model.GetShowEmojiInfo(this.rectTransform.rect.width, id, out int rowCount, out int emojiCount, out int space);
|
model.GetEmojiShowSize(id, out int emojiWidth, out int emojiHeight);
|
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, emojiHeight);
|
horizontalLayoutGroup.spacing = space;
|
List<string> emojiList = model.GetEmojiList(id);
|
for (int i = 0; i < model.MaxEmojiCount; i++)
|
{
|
if (i < emojiCount)
|
{
|
imgFaceList[i].rectTransform.sizeDelta = new Vector2(emojiWidth, emojiHeight);
|
int index = rowIndex * emojiCount + i;
|
if (index < emojiList.Count)
|
{
|
string name = emojiList[index];
|
imgFaceList[i].SetActive(true);
|
if (!FaceConfig.Has(name))
|
continue;
|
FaceConfig config = FaceConfig.Get(name);
|
UIFrame frame = imgFaceList[i].GetComponent<UIFrame>();
|
if (UIFrameMgr.Inst.ContainsDynamicImage(config.name))
|
{
|
if (frame == null)
|
frame = imgFaceList[i].gameObject.AddComponent<UIFrame>();
|
frame.ResetFrame(config.name);
|
frame.enabled = true;
|
}
|
else
|
{
|
if (frame != null)
|
frame.enabled = false;
|
imgFaceList[i].SetSprite(config.name);
|
}
|
|
ButtonEx buttonEx = imgFaceList[i].GetComponent<ButtonEx>();
|
if (buttonEx != null)
|
{
|
buttonEx.SetListener(() => OnFaceClick(name));
|
}
|
}
|
else
|
{
|
imgFaceList[i].SetActive(false);
|
}
|
}
|
else
|
{
|
imgFaceList[i].SetActive(false);
|
}
|
|
}
|
|
}
|
|
|
private void OnFaceClick(string index)
|
{
|
List<string> emojiList = model.GetEmojiList(model.selectEmojiPackID);
|
|
if (!FaceConfig.Has(index))
|
return;
|
FaceConfig config = FaceConfig.Get(index);
|
|
if (config.EmojiPackID == 1)
|
{
|
if (chatCenter.chatInputLength + 5 > chatCenter.chatCharacterLimit)
|
{
|
return;
|
}
|
string facename = config.name;
|
if (facename.Length == 1)
|
{
|
facename = "00" + facename;
|
}
|
else if (facename.Length == 2)
|
{
|
facename = "0" + facename;
|
}
|
chatCenter.ChangeChatValue(string.Format("#~{0}", facename), true, true);
|
}
|
else
|
{
|
|
string msg = config.name;
|
if (msg.Length == 1)
|
{
|
msg = "00" + msg;
|
}
|
else if (msg.Length == 2)
|
{
|
msg = "0" + msg;
|
}
|
//ChatCtrl.Inst.SendChatInfo(ChatCtrl.Inst.presentChatType, string.Format("#~{0}", msg));
|
model.SendChatAction?.Invoke(string.Format("#~{0}", msg));
|
}
|
|
}
|
|
|
}
|
}
|