先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
576 lines
20 KiB
C#
576 lines
20 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using asap.core;
|
||
using cfg;
|
||
using DG.Tweening;
|
||
using Game;
|
||
using GameCore;
|
||
using TMPro;
|
||
using UniRx;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
public class FishingMapPanel : BasePanel
|
||
{
|
||
Tables _tables;
|
||
CanvasGroup canvasGroup;
|
||
GameObject root;
|
||
MapCardInfo root_card;
|
||
private Button btn_close;
|
||
private Button btn_enter;
|
||
private Button btn_upgradeAll;
|
||
private GameObject current_map;
|
||
private Transform fishContent;
|
||
private GameObject fishItem;
|
||
private GameObject mapItem;
|
||
private RectTransform mapContent, panel_card;
|
||
private PanelScroll mapScrollRect;
|
||
private TMP_Text text_map_name;
|
||
private List<FishItem> fishItems = new List<FishItem>();
|
||
public List<FishData> fishDatas = new List<FishData>();
|
||
FishMapItem curMapItem;
|
||
List<FishMapItem> fishMapItem;
|
||
private List<FishMapItemData> fishMapItemDatas = new List<FishMapItemData>();
|
||
|
||
private int mapID = 0;
|
||
|
||
float itemWidth = 0;
|
||
|
||
private Button btn_slider_right;
|
||
private Button btn_slider_left;
|
||
|
||
private int nextRightIndex = 0;
|
||
private int nextLeftIndex = 0;
|
||
Coroutine fish_coroutine;
|
||
int mapNameIndex = -1;
|
||
|
||
public AnimationCurve easeCurve;
|
||
public AnimationCurve FadeEaseCurve;
|
||
[SerializeField]
|
||
private CanvasGroup cg;
|
||
MapBtnMiniBP mapBtnMiniBP;
|
||
Button btn_close_upgrade;
|
||
void Awake()
|
||
{
|
||
root = transform.Find("root").gameObject;
|
||
root_card = transform.Find("root_card").GetComponent<MapCardInfo>();
|
||
canvasGroup = GetComponent<CanvasGroup>();
|
||
panel_card = transform.Find("root/panel_card").GetComponent<RectTransform>();
|
||
mapItem = transform.Find("root/Scroll item/Viewport/item").gameObject;
|
||
mapContent = transform.Find("root/Scroll item/Viewport/Content").GetComponent<RectTransform>();
|
||
|
||
fishContent = transform.Find("root/panel_card/ScrollView/Viewport/Content");
|
||
fishItem = transform.Find("root/panel_card/ScrollView/Viewport/Content/Item").gameObject;
|
||
fishItem.SetActive(false);
|
||
mapScrollRect = transform.Find("root/Scroll item").GetComponent<PanelScroll>();
|
||
mapItem.SetActive(false);
|
||
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
||
btn_enter = transform.Find("root/btn_enter/btn_green").GetComponent<Button>();
|
||
btn_upgradeAll = transform.Find("root/btn_levelup_all/btn_green").GetComponent<Button>();
|
||
|
||
text_map_name = transform.Find("root/text_map_name").GetComponent<TMP_Text>();
|
||
itemWidth = mapItem.GetComponent<RectTransform>().rect.width;
|
||
btn_slider_right = transform.Find("root/btn_slider_right").GetComponent<Button>();
|
||
btn_slider_left = transform.Find("root/btn_slider_left").GetComponent<Button>();
|
||
|
||
current_map = transform.Find("root/current_map").gameObject;
|
||
_tables = GContext.container.Resolve<Tables>();
|
||
var miniBPTransform = transform.Find("root/MiniBP");
|
||
if (miniBPTransform != null) mapBtnMiniBP = miniBPTransform.GetComponent<MapBtnMiniBP>();
|
||
|
||
btn_close_upgrade = transform.Find("reward_fishcard_upgrade/reward/btn_play/btn_green").GetComponent<Button>();
|
||
}
|
||
|
||
protected override void Start()
|
||
{
|
||
base.Start();
|
||
btn_close.onClick.AddListener(OnClosePanel);
|
||
btn_enter.onClick.AddListener(OnClickEnter);
|
||
btn_upgradeAll.onClick.AddListener(OnClickUpgradeAll);
|
||
btn_slider_right.onClick.AddListener(() => { mapScrollRect.JumpToTarget(nextRightIndex); });
|
||
btn_slider_left.onClick.AddListener(() => { mapScrollRect.JumpToTarget(nextLeftIndex); });
|
||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide(panelName);
|
||
root_card.btn_close.onClick.AddListener(OnClickCloseCard);
|
||
btn_close_upgrade.onClick.AddListener(() =>
|
||
{
|
||
RefreshFishCardUI(false);
|
||
ShowReward();
|
||
RefreshUpgradeAllBtn(mapID);
|
||
RefreshRed();
|
||
});
|
||
InitMap();
|
||
OpenCard(false);
|
||
//设置panel_card.top
|
||
if (mapBtnMiniBP != null && mapBtnMiniBP.gameObject.activeSelf)
|
||
{
|
||
panel_card.offsetMax = new Vector2(panel_card.offsetMax.x, -320);
|
||
|
||
}
|
||
else
|
||
{
|
||
panel_card.offsetMax = new Vector2(panel_card.offsetMax.x, -110);
|
||
}
|
||
}
|
||
|
||
void RefreshRed()
|
||
{
|
||
for (int i = 0; i < fishMapItemDatas.Count; i++)
|
||
{
|
||
fishMapItemDatas[i].isRedPoint = GContext.container.Resolve<PlayerFishData>().GetMapRed(fishMapItemDatas[i].fishList);
|
||
}
|
||
if (fishMapItem != null && fishMapItem.Count > 0)
|
||
{
|
||
for (int i = 0; i < fishMapItem.Count; i++)
|
||
{
|
||
fishMapItem[i].SetRed();
|
||
}
|
||
}
|
||
}
|
||
|
||
void OnClickCloseCard()
|
||
{
|
||
Reordering(false);
|
||
ShowReward();
|
||
curMapItem.data.isRedPoint = GContext.container.Resolve<PlayerFishData>().GetMapRed(curMapItem.data.fishList);
|
||
curMapItem.SetRed();
|
||
OpenCard(false);
|
||
RefreshUpgradeAllBtn(mapID);
|
||
}
|
||
void OpenCard(bool isShow)
|
||
{
|
||
root_card.gameObject.SetActive(isShow);
|
||
root.SetActive(!isShow);
|
||
}
|
||
|
||
void ChangeMapName(int index, string mapName)
|
||
{
|
||
if (mapNameIndex != index)
|
||
{
|
||
GContext.Publish(new EventUISound(SoundType.audio_ui_fishingmap));
|
||
mapNameIndex = index;
|
||
text_map_name.text = $"{index + 1}.{mapName}";
|
||
}
|
||
}
|
||
void InitMap()
|
||
{
|
||
fishMapItemDatas.Clear();
|
||
int curMapIndex = 0;
|
||
var dataList = _tables.TbMapData.DataList;
|
||
int count = dataList.Count;
|
||
const int maxDemoMapId = 102;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
if (dataList[i].ID > maxDemoMapId) break;
|
||
FishMapItemData data = new FishMapItemData()
|
||
{
|
||
ID = dataList[i].ID,
|
||
fishList = dataList[i].FishList,
|
||
name = LocalizationMgr.GetText(dataList[i].Name_l10n_key),
|
||
progress = 0f,
|
||
progressText = "0%",
|
||
icon = dataList[i].Bg,
|
||
isNew = GContext.container.Resolve<PlayerData>().IsNewMap(i),
|
||
unLock = false,
|
||
isRedPoint = GContext.container.Resolve<PlayerFishData>().GetMapRed(dataList[i].FishList),
|
||
index = i,
|
||
levelRequired = dataList[i].LevelRequired,
|
||
ChangeMapName = ChangeMapName,
|
||
};
|
||
if (i == 0)
|
||
{
|
||
data.levelRequired = 0;
|
||
}
|
||
else
|
||
{
|
||
data.levelRequired = dataList[i - 1].LevelRequired;
|
||
}
|
||
|
||
if (GContext.container.Resolve<PlayerData>().lv >= data.levelRequired)
|
||
{
|
||
data.unLock = true;
|
||
}
|
||
else if (dataList[i - 1].ID == GContext.container.Resolve<PlayerData>().lastMapId)
|
||
{
|
||
data.progress = (float)(GContext.container.Resolve<PlayerData>().lv - fishMapItemDatas[i - 1].levelRequired) / (data.levelRequired - fishMapItemDatas[i - 1].levelRequired);
|
||
data.progressText = $"{Mathf.Round(data.progress * 100)}%";
|
||
}
|
||
var fishingData = GContext.container.Resolve<FishingData>();
|
||
if (data.ID == fishingData.MapId)
|
||
{
|
||
curMapIndex = i;
|
||
}
|
||
|
||
fishMapItemDatas.Add(data);
|
||
}
|
||
|
||
SetMapList(fishMapItemDatas[curMapIndex]);
|
||
mapScrollRect.loop = true;
|
||
fishMapItem = mapScrollRect.Init<FishMapItem, FishMapItemData>(itemWidth, mapItem, OnClickMapItem, fishMapItemDatas, true, curMapIndex, 4);
|
||
}
|
||
|
||
void SetBtnSliderRight()
|
||
{
|
||
btn_slider_right.gameObject.SetActive(false);
|
||
btn_slider_left.gameObject.SetActive(false);
|
||
if (curMapItem && fishMapItemDatas.Count > 5)
|
||
{
|
||
int curIndex = curMapItem.data.index;
|
||
int count = fishMapItemDatas.Count;
|
||
int index;
|
||
for (int i = 0; i < count / 2 - 1; i++)
|
||
{
|
||
nextRightIndex = curIndex + i + 2;
|
||
index = nextRightIndex % count;
|
||
if ((fishMapItemDatas[index].isNew || fishMapItemDatas[index].isRedPoint) &&
|
||
btn_slider_right.gameObject.activeSelf == false)
|
||
{
|
||
btn_slider_right.gameObject.SetActive(true);
|
||
break;
|
||
}
|
||
|
||
nextLeftIndex = curIndex - i - 2;
|
||
index = nextLeftIndex % count;
|
||
if (index < 0)
|
||
{
|
||
index += count;
|
||
}
|
||
if ((fishMapItemDatas[index].isNew || fishMapItemDatas[index].isRedPoint) &&
|
||
btn_slider_left.gameObject.activeSelf == false)
|
||
{
|
||
btn_slider_left.gameObject.SetActive(true);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
void OnClickFishItem(FishItem fishItem)
|
||
{
|
||
root_card.currentIndex = fishItem.index;
|
||
root_card.dataList = fishItems.Where(_ => _.IsHas()).Select(_ => _.data).ToList();
|
||
OpenCard(true);
|
||
}
|
||
void OnClickMapItem(FishMapItem item)
|
||
{
|
||
FishMapItemData data = item.data;
|
||
if (data.isNew)
|
||
{
|
||
data.isNew = false;
|
||
GContext.container.Resolve<PlayerData>().RewardNewMap(data.index);
|
||
item.SetIsNew();
|
||
}
|
||
|
||
curMapItem = item;
|
||
mapContent.DOLocalMoveX(-item.transform.localPosition.x, 0.2f).OnComplete(() => { SetMapList(data); });
|
||
}
|
||
|
||
void RefreshUpgradeAllBtn(int mapID)
|
||
{
|
||
btn_upgradeAll.transform.parent.gameObject.SetActive(GContext.container.Resolve<PlayerFishData>().GetFishCanLevel());
|
||
}
|
||
void SetMapList(FishMapItemData data)
|
||
{
|
||
if (mapID != data.ID)
|
||
{
|
||
int mapId = GContext.container.Resolve<PlayerData>().currentMapId;
|
||
btn_enter.gameObject.SetActive(mapId != data.ID); //interactable
|
||
current_map.SetActive(mapId == data.ID);
|
||
SetBtnSliderRight();
|
||
RefreshUpgradeAllBtn(data.ID);
|
||
mapID = data.ID;
|
||
RefreshFishCardUI(true);
|
||
|
||
|
||
text_map_name.text = $"{data.index + 1}.{data.name}";
|
||
}
|
||
}
|
||
|
||
void RefreshFishCardUI(bool isOneByOne)
|
||
{
|
||
//显示当前地图的鱼
|
||
var fishes = _tables.GetMapData(mapID).FishList;
|
||
var count = fishes.Count;
|
||
int length = fishItems.Count;
|
||
for (int i = 0; i < length; i++)
|
||
{
|
||
fishItems[i].gameObject.SetActive(false);
|
||
}
|
||
|
||
fishDatas.Clear();
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
fishDatas.Add(_tables.TbFishData.DataMap[fishes[i]]);
|
||
if (i >= length)
|
||
{
|
||
FishItem fishItemB = Instantiate(fishItem, fishContent).AddComponent<FishItem>();
|
||
fishItemB.index = i;
|
||
fishItems.Add(fishItemB);
|
||
fishItems[i].OnClickAction = OnClickFishItem;
|
||
}
|
||
}
|
||
|
||
Reordering(isOneByOne);
|
||
}
|
||
|
||
//重新排序
|
||
void Reordering(bool isOneByOne)
|
||
{
|
||
fishDatas.Reverse();
|
||
//fishDatas排序按照能否升级
|
||
fishDatas.Sort((a, b) =>
|
||
{
|
||
int acurProficiency = GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(a.FishCardID);
|
||
int bcurProficiency = GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(b.FishCardID);
|
||
|
||
if (acurProficiency > 0 && bcurProficiency > 0)
|
||
{
|
||
// if b能升级:不动 else if a能升级:a在前 else 同品质按等级比
|
||
int bLevel = GContext.container.Resolve<PlayerFishData>().GetDataLevel(b.ID);
|
||
cfg.FishCard bfishMastery = _tables.TbFishCard[b.FishCardID];
|
||
if (bLevel < bfishMastery.MaxLevel)
|
||
{
|
||
int endWeight = bfishMastery.CardsRequiredList[bLevel];
|
||
if (bcurProficiency >= endWeight)
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
int aLevel = GContext.container.Resolve<PlayerFishData>().GetDataLevel(a.ID);
|
||
cfg.FishCard afishMastery = _tables.TbFishCard[a.FishCardID];
|
||
if (aLevel < afishMastery.MaxLevel)
|
||
{
|
||
int endWeight = afishMastery.CardsRequiredList[aLevel];
|
||
if (acurProficiency >= endWeight)
|
||
{
|
||
return -1;
|
||
}
|
||
}
|
||
if (bfishMastery.Quality == afishMastery.Quality)
|
||
{
|
||
return bLevel.CompareTo(aLevel);
|
||
}
|
||
}
|
||
else if (acurProficiency > 0)
|
||
{
|
||
return -1;
|
||
}
|
||
return 1;
|
||
});
|
||
|
||
for (int i = 0; i < fishDatas.Count; i++)
|
||
{
|
||
fishItems[i].data = fishDatas[i];
|
||
fishItems[i].OnInit();
|
||
}
|
||
if (fish_coroutine != null)
|
||
{
|
||
StopCoroutine(fish_coroutine);
|
||
}
|
||
fish_coroutine = StartCoroutine(ShowFish(isOneByOne));
|
||
}
|
||
|
||
Tween fadeTween;
|
||
IEnumerator ShowFish(bool isOneByOne)
|
||
{
|
||
if (isOneByOne)
|
||
{
|
||
fadeTween.Kill();
|
||
cg.alpha = 0f;
|
||
fadeTween = cg.DOFadeAlpha(1f, 0.5f).SetEase(FadeEaseCurve);
|
||
}
|
||
else
|
||
{
|
||
cg.alpha = 1f;
|
||
}
|
||
for (int i = 0; i < fishDatas.Count; i++)
|
||
{
|
||
fishItems[i].gameObject.SetActive(true);
|
||
if (isOneByOne)
|
||
{
|
||
fishItems[i].transform.localScale = Vector3.zero;
|
||
fishItems[i].transform.DOScale(Vector3.one, 0.2f).SetEase(easeCurve);
|
||
}
|
||
else
|
||
{
|
||
fishItems[i].transform.localScale = Vector3.one;
|
||
}
|
||
//fishItems[i].transform.DOScale(Vector3.one,0.1f);
|
||
if (isOneByOne)
|
||
{
|
||
if (i <= 3)
|
||
{
|
||
yield return new WaitForSeconds(0.01f * i);
|
||
}
|
||
else
|
||
yield return new WaitForSeconds(0.04f);
|
||
}
|
||
}
|
||
}
|
||
void OnClickEnter()
|
||
{
|
||
if (mapID != 0 && curMapItem.data.unLock)
|
||
{
|
||
int curmapID = GContext.container.Resolve<PlayerData>().currentMapId;
|
||
|
||
FishBuff mapBuff = GContext.container.Resolve<BuffDataCenter>().IsMapBuff(curmapID);
|
||
if (mapBuff != null)
|
||
{
|
||
CheckMapBuff(mapBuff);
|
||
}
|
||
else
|
||
{
|
||
OnEnterNewMap();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var mapdata = _tables.TbMapData.GetOrDefault(mapID - 1);
|
||
if (mapdata != null)
|
||
{
|
||
ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_4", mapdata.LevelRequired));
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
//检查mapBuff
|
||
async void CheckMapBuff(FishBuff mapBuff)
|
||
{
|
||
FishingData fishingData = GContext.container.Resolve<FishingData>();
|
||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||
var noticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||
string mapName = LocalizationMgr.GetText(_tables.TbMapData.DataMap[fishingData.MapId].Name_l10n_key);
|
||
string buffName = LocalizationMgr.GetText(mapBuff.Title_l10n_key);
|
||
if (mapBuff.BuffParam is CollectionTargetWeight)
|
||
{
|
||
string str = "";
|
||
//新目标奖励活动 Todo
|
||
CollectionTargetWeight collectionTargetWeight = mapBuff.BuffParam as CollectionTargetWeight;
|
||
CollectingTargetInit collectingTargetInit = GContext.container.Resolve<FishingEventData>().collectingTargetInit;
|
||
if (collectingTargetInit != null)
|
||
{
|
||
EventTargetExtraDrop eventTargetExtraDrop = collectingTargetInit.FishingExtraDrop;
|
||
if (eventTargetExtraDrop is ETKeepsake)
|
||
{
|
||
ETKeepsake eTKeepsake = eventTargetExtraDrop as ETKeepsake;
|
||
int fishItemId = eTKeepsake.FishIDList[collectionTargetWeight.TargetFishIndex - 1];
|
||
Item item = GContext.container.Resolve<Tables>().TbItem.GetOrDefault(fishItemId);
|
||
str = LocalizationMgr.GetText(item.Name_l10n_key);
|
||
}
|
||
}
|
||
buffName = LocalizationMgr.GetFormatTextValue(mapBuff.Title_l10n_key, str);
|
||
}
|
||
string info = LocalizationMgr.GetFormatTextValue("UI_FishingTargetPopupPanel_Advanced_7", buffName, mapName);
|
||
noticeConfirmPopupPanel.Init(2, "", info, OnEnterNewMap, btn_left_text: LocalizationMgr.GetText("UI_FishingTargetPopupPanel_Advanced_8"));
|
||
}
|
||
async void OnEnterNewMap()
|
||
{
|
||
canvasGroup.blocksRaycasts = false;
|
||
var mapData = _tables.TbMapData.DataMap[mapID];
|
||
|
||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||
bool isCanEnter = await loadResourceService.Load(mapData.EnvName);
|
||
if (isCanEnter)
|
||
{
|
||
//GContext.Publish(new VibrationData(HapticTypes.Selection));
|
||
EnterNewMap();
|
||
}
|
||
else
|
||
{
|
||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, EnterNewMap);
|
||
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
||
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, EnterNewMap);
|
||
canvasGroup.blocksRaycasts = true;
|
||
}
|
||
}
|
||
async void EnterNewMap()
|
||
{
|
||
canvasGroup.blocksRaycasts = false;
|
||
ChangeMapDataAsyncEvent changeMapDataAsyncEvent = new ChangeMapDataAsyncEvent(mapID);
|
||
GContext.Publish(changeMapDataAsyncEvent);
|
||
await changeMapDataAsyncEvent.source.Task;
|
||
OnClosePanel();
|
||
GContext.Publish(new EndTransition());
|
||
}
|
||
void OnClosePanel()
|
||
{
|
||
ShowNewMapEvent restartShowHomeUIEvent = new ShowNewMapEvent();
|
||
GContext.Publish(restartShowHomeUIEvent);
|
||
UIManager.Instance.DestroyUI(UITypes.FishingMapPanel);
|
||
}
|
||
|
||
|
||
void OnClickUpgradeAll()
|
||
{
|
||
RewardFishCardUpgrade rewardFishCardUpgrade;
|
||
rewardFishCardUpgrade = transform.Find("reward_fishcard_upgrade").GetComponent<RewardFishCardUpgrade>();
|
||
rewardFishCardUpgrade.InitAsync();
|
||
}
|
||
|
||
|
||
void ShowReward()
|
||
{
|
||
if (mapBtnMiniBP != null) mapBtnMiniBP.PlayUpBar();
|
||
}
|
||
}
|
||
|
||
class FishItem : MonoBehaviour
|
||
{
|
||
FishCardUI fishCard;
|
||
Button btn_item;
|
||
public FishData data;
|
||
public Action<FishItem> OnClickAction;
|
||
public int index;
|
||
bool isStart = false;
|
||
private void Awake()
|
||
{
|
||
if (isStart)
|
||
{
|
||
return;
|
||
}
|
||
fishCard = transform.Find("fish_card").GetComponent<FishCardUI>();
|
||
btn_item = transform.GetComponent<Button>();
|
||
isStart = true;
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
btn_item.onClick.AddListener(OnClickItem);
|
||
}
|
||
|
||
void OnClickItem()
|
||
{
|
||
if (fishCard.curProficiency > 0)
|
||
{
|
||
OnClickAction(this);
|
||
|
||
}
|
||
else
|
||
{
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_49"));
|
||
}
|
||
}
|
||
public bool IsHas()
|
||
{
|
||
return fishCard.curProficiency > 0;
|
||
}
|
||
public void OnInit()
|
||
{
|
||
if (data != null)
|
||
{
|
||
if (!isStart)
|
||
{
|
||
Awake();
|
||
isStart = true;
|
||
}
|
||
fishCard.data = data;
|
||
fishCard.Init();
|
||
fishCard.curProficiency = GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(data.FishCardID);
|
||
GContext.container.Resolve<PlayerFishData>().SetDataNewFish(data.ID);
|
||
}
|
||
}
|
||
}
|