Files
JJBB/Assets/Project/Script/GUI/Community/CommunityWriteMsgLogic.cs
2024-08-23 15:49:34 +08:00

140 lines
3.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Item;
using System.Collections.Generic;
using GCGame.Table;
using Games.GlobeDefine;
using Module.Log;
public class CommunityWriteMsgLogic : UIControllerBase<CommunityWriteMsgLogic>
{
void OnEnable ()
{
SetInstance(this);
}
void OnDisable()
{
SetInstance(null);
}
public void ShowWindow()
{
gameObject.SetActive(true);
InitMsg();
}
public void CloseWindow()
{
gameObject.SetActive(false);
}
#region
public ChatInputLogic _ChatInputLogic;
public List<NetDoubleImage> _NetImages;
public UIButtonTime _SendBtnTime;
private string _SendStr;
private List<NetDoubleImage> _ShowedNetImages = new List<NetDoubleImage>();
private int _SelectedImageIdx = -1;
public void InitMsg()
{
foreach (var netImage in _NetImages)
{
netImage.CleanUpImage();
netImage.gameObject.SetActive(false);
}
_ShowedNetImages.Clear();
_SendStr = "";
}
public void OnLoadImage(int selectedImage)
{
_SelectedImageIdx = selectedImage;
CommunityLogic.Instance()._ImageTool.SetImageCallBack(OnSetImage, StrDictionary.GetClientDictionaryString("#{39028}"));
}
public void OnSetImage(Texture2D cuttedImg)
{
if (_SelectedImageIdx < 0)
return;
NetDoubleImage selectedNetImage = _NetImages[_SelectedImageIdx];
_SelectedImageIdx = -1;
selectedNetImage.gameObject.SetActive(true);
selectedNetImage.SetNetImage(cuttedImg, IMAGE_CHECK_STATE.PASS);
}
public void OnSendStr(string sendStr)
{
//if (string.IsNullOrEmpty(sendStr))
//{
// return;
//}
if (GCGame.Utils.IsStrFilter_Chat(sendStr))
{
GUIData.AddNotifyData("#{39025}");
return;
}
_SendStr = sendStr;
_ShowedNetImages.Clear();
for (int i = 0; i < _NetImages.Count; ++i)
{
if (_NetImages[i].LargeTexture != null)
{
_ShowedNetImages.Add(_NetImages[i]);
}
}
if (string.IsNullOrEmpty(_SendStr) && _ShowedNetImages.Count == 0)
{//没有文字和图片,不需要提示
GUIData.AddNotifyData("#{41324}");
return;
}
_SendBtnTime.SetBtnDisableTime(3);
if (_ShowedNetImages.Count > 0)
{
NetDoubleImage.UploadBlogPic(_ShowedNetImages, OnUploadImageSucess, OnUploadImageFail);
}
else
{
OnUploadImageSucess(null);
}
//Community.Instance.TestSendBlog(_SendStr, _ShowedNetImages);
//Community.Instance.ReLoadMoreMyBlog();
}
public void OnUploadImageSucess(List<string> imgNames)
{
CG_REQ_SAVE_BLOG packet = (CG_REQ_SAVE_BLOG)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SAVE_BLOG);
packet.Context = _SendStr;
if (imgNames != null)
{
for (int i = 0; i < _ShowedNetImages.Count; ++i)
{
packet.AddImgnames(imgNames[i * 2]);
packet.AddImgnames(imgNames[i * 2 + 1]);
}
}
packet.SendPacket();
CloseWindow();
}
public void OnUploadImageFail(List<string> imgNames)
{
LogModule.ErrorLog("Upload image fail!!");
CloseWindow();
}
#endregion
}