Files
MinFt/Client/Assets/Scripts/UI/Shop/ItemsShopPanel.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

253 lines
7.8 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// hasBought: 0 未购买 1 已购买
/// </summary>
public class ItemShopRecord
{
public int ItemID;
public float Discount;
public int hasBought;
public ItemShopRecord(int itemID, float discount, int hasBought)
{
ItemID = itemID;
this.Discount = discount;
this.hasBought = hasBought;
}
}
public class ItemsShopPanel : MonoBehaviour
{
#region Field&&Property
[SerializeField]
private GameObject
go_refreshFree,
go_refreshDiamonIcon,
go_fishCardSlot,
go_itemSlot;
[SerializeField]
private Transform
tran_fishCardParent,
tran_itemSlotParent;
[SerializeField]
private List<EnergyShopSlot> _energyShopSlots = new List<EnergyShopSlot>();
private List<ItemShopSlot> _itemShopSlots = new List<ItemShopSlot>();
[SerializeField]
private TMP_Text
txt_curMap,
txt_itemShopTimer,
txt_refreshCost;
[SerializeField]
private Button
btn_chagneMap,
btn_refreshGray,
btn_refresh;
private List<ItemStore> _itemStores;
private List<ResourceStore> _energySlotDatas;
private List<ResourceStore> _fishCardSlotDatas;
private PlayerShopData _shopData;
private int curSlelectingMapID;
private TimeSpan _autoRefreshTimer;
#endregion
IDisposable disposable;
#region Function
private void Awake()
{
go_itemSlot.SetActive(false);
go_fishCardSlot.SetActive(false);
var tables = GContext.container.Resolve<Tables>();
_itemStores = tables.TbItemStore.DataList;
_shopData = GContext.container.Resolve<PlayerShopData>();
_energySlotDatas = tables.TbResourceStore.DataList.Where(x => x.Type == 1 && x.IsShow == 1).ToList();
_fishCardSlotDatas = tables.TbResourceStore.DataList.Where(x => x.Type == 2).ToList();
disposable = GContext.OnEvent<FishCardShopSlot.SChangeFishCardMapEvent>().Where(x => x.IsConfirm).Subscribe(x => OnChangeMapID(x));
}
protected void Start()
{
btn_refresh.onClick.AddListener(OnRefresh);
btn_refreshGray.onClick.AddListener(OnCannotRefersh);
btn_chagneMap.onClick.AddListener(OnChagneFishCardMap);
RefreshView();
}
protected void OnDestroy()
{
disposable?.Dispose();
disposable = null;
btn_refresh.onClick.RemoveAllListeners();
}
private void OnEnable()
{
StopAllCoroutines();
StartCoroutine(IE_SetTimer());
}
private void RefreshView()
{
RefreshEnergySlots();
RefreshItemSlots();
RefreshRefreshInfo();
RefreshFishCardSlots();
StopAllCoroutines();
StartCoroutine(IE_SetTimer());
}
private void RefreshItemBars()
{
RefreshItemSlots();
RefreshRefreshInfo();
StopAllCoroutines();
StartCoroutine(IE_SetTimer());
}
private void RefreshFishCardSlots()
{
var curMapID = GContext.container.Resolve<PlayerData>().currentMapId;
var mapData = GContext.container.Resolve<Tables>().GetMapData(curMapID);
OnChangeMapID(new FishCardShopSlot.SChangeFishCardMapEvent { MapData = mapData });
for (int i = 0; i < _fishCardSlotDatas.Count; i++)
{
var fishCardSlot = Instantiate(go_fishCardSlot, tran_fishCardParent).GetComponent<FishCardShopSlot>();
fishCardSlot.SetData(_fishCardSlotDatas[i], curMapID);
}
}
private void OnChangeMapID(FishCardShopSlot.SChangeFishCardMapEvent data)
{
curSlelectingMapID = data.MapData.ID;
txt_curMap.text = LocalizationMgr.GetText(data.MapData.Name_l10n_key);
}
private void RefreshEnergySlots()
{
for (int i = 0; i < _energySlotDatas.Count; i++)
{
if (i >= _energyShopSlots.Count)
{
Debug.LogError("EnergySLot Not Enough!");
return;
}
_energyShopSlots[i].SetData(_energySlotDatas[i]);
}
}
private void RefreshItemSlots()
{
foreach (var slot in _itemShopSlots)
{
Destroy(slot.gameObject);
}
_itemShopSlots.Clear();
var shopDatas = _shopData.GetItemShopData();
foreach (var data in shopDatas)
{
var slot = Instantiate(go_itemSlot, tran_itemSlotParent).GetComponent<ItemShopSlot>();
slot.SetData(data);
_itemShopSlots.Add(slot);
}
}
private void RefreshRefreshInfo()
{
var cost = _shopData.GetDiamondShopRefreshCost();
if (cost == 0)
{
go_refreshFree.SetActive(true);
go_refreshDiamonIcon.SetActive(false);
txt_refreshCost.gameObject.SetActive(false);
}
else
{
go_refreshFree.SetActive(false);
go_refreshDiamonIcon.SetActive(true);
txt_refreshCost.gameObject.SetActive(true);
txt_refreshCost.text = cost.ToString();
}
var refreshInfo = _shopData.GetDiamondShopRefreshInfo();
if (refreshInfo.refresh <= 0)
{
btn_refreshGray.transform.parent.gameObject.SetActive(true);
btn_refresh.transform.parent.gameObject.SetActive(false);
}
else
{
btn_refreshGray.transform.parent.gameObject.SetActive(false);
btn_refresh.transform.parent.gameObject.SetActive(true);
}
}
private void OnRefresh()
{
var diamondCount = GContext.container.Resolve<PlayerData>().diamond;
var cost = _shopData.GetDiamondShopRefreshCost();
if (diamondCount >= cost)
{
GContext.container.Resolve<PlayerData>().AddDiamond(-cost);
_shopData.RefreshDiamondShop();
RefreshItemBars();
#if AGG
using (var e = GEvent.GameEvent("click_free_button"))
{
var refreshInfo = _shopData.GetDiamondShopRefreshInfo();
e.AddContent("cost_diamond_count", cost)
.AddContent("click_free_count", refreshInfo.refresh);
}
#endif
}
else
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
}
private void OnCannotRefersh()
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_64"));
}
private async void OnChagneFishCardMap()
{
var selectPanel = await UIManager.Instance.ShowUI(UITypes.FishingShopSelectMapPopupPanel);
selectPanel.GetComponent<FishingShopSelectMapPopupPanel>().Init(curSlelectingMapID);
}
private void OnTimerEnd()
{
GContext.container.Resolve<PlayerShopData>().AutoRefreshDiamonShop();
RefreshItemBars();
}
private IEnumerator IE_SetTimer()
{
_autoRefreshTimer = _shopData.GetDiamondShopRefreshTime();
var miliSeconds = _autoRefreshTimer.Milliseconds;
txt_itemShopTimer.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh", ConvertTools.ConvertTime2(_autoRefreshTimer));
yield return new WaitForSeconds(miliSeconds / 1000);
_autoRefreshTimer.Subtract(TimeSpan.FromMilliseconds(miliSeconds));
txt_itemShopTimer.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh", ConvertTools.ConvertTime2(_autoRefreshTimer));
while (_autoRefreshTimer.TotalSeconds > 0)
{
yield return new WaitForSeconds(1);
_autoRefreshTimer = _autoRefreshTimer.Subtract(TimeSpan.FromSeconds(1));
txt_itemShopTimer.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh", ConvertTools.ConvertTime2(_autoRefreshTimer));
}
OnTimerEnd();
}
#endregion
}