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

108 lines
2.6 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 CommunityGiveFlowerLogic : UIControllerBase<CommunityGiveFlowerLogic>
{
#region static
public static void GiveFlower(ulong targetGuid, string targetName)
{
UIManager.ShowUI(UIInfo.GiveFlowerPanel, (bool bSuccess, object param)=>
{
CommunityGiveFlowerLogic.Instance().ShowWindow(targetGuid, targetName);
});
}
#endregion
private ulong _TargetGuid;
private string _TargetName;
void OnEnable ()
{
SetInstance(this);
}
void OnDisable()
{
SetInstance(null);
}
public void ShowWindow(ulong targetGuid, string targetName)
{
gameObject.SetActive(true);
_TargetGuid = targetGuid;
_TargetName = targetName;
InitGiveFlower();
}
public void CloseWindow()
{
gameObject.SetActive(false);
}
#region
public const int PresentPrice = 2000;
public UINumBoardInput _PresentCnt;
public UIContainerSelect _FlowerContainer;
private int _FlowerID;
public void InitGiveFlower()
{
_PresentCnt.Init(1, 1, 999);
List<int> flowerDatas = CommunityFlowerInfo.FlowerDataID;
_FlowerContainer.InitSelectContent(flowerDatas, new List<int>() { flowerDatas[0]}, SelectFlower);
}
public void SelectFlower(object flowerObj)
{
_FlowerID = (int)flowerObj;
var itemCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_FlowerID);
_PresentCnt.Init(itemCnt,1 , itemCnt);
}
public void UpdateFlower()
{
}
public void OnBtnGetMore()
{
ItemGetPathPopRoot.Show(_FlowerID, GetComponent<RectTransform>().anchoredPosition);
}
public void OnBtnGive()
{
var itemCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_FlowerID);
if (itemCount < _PresentCnt.Value)
{
ItemGetPathPopRoot.Show(_FlowerID, GetComponent<RectTransform>().anchoredPosition);
return;
}
CG_REQ_GIVE_FLOWER packet = (CG_REQ_GIVE_FLOWER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_GIVE_FLOWER);
packet.Roleguid = _TargetGuid;
packet.Itemid = _FlowerID;
packet.Itemcount = _PresentCnt.Value;
packet.Name = _TargetName;
packet.SendPacket();
LogModule.DebugLog("send cnt:" + _PresentCnt.Value + " dataID:" + _FlowerID + " targetName;" + packet.Name);
CloseWindow();
}
#endregion
}