145 lines
4.0 KiB
C#
145 lines
4.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MapCardInfo : MonoBehaviour
|
|
{
|
|
public Button btn_close;
|
|
public FishCardUI fish_card;
|
|
public MapFishAttribute mapFishAttribute;
|
|
public TMP_Text text_level_max;
|
|
public Button btn_upgrade;
|
|
public Button btn_upgrade_gray;
|
|
public GameObject max_level;
|
|
public GameObject arrow;
|
|
public TMP_Text text_level_num_before;
|
|
public TMP_Text text_level_num_after;
|
|
public Button btn_arrow_left;
|
|
public Button btn_arrow_right;
|
|
public int currentIndex;
|
|
public FishData data;
|
|
public List<FishData> dataList;
|
|
public List<GameObject> levelup;
|
|
private void Start()
|
|
{
|
|
btn_upgrade.onClick.AddListener(OnClickUp);
|
|
btn_arrow_left.onClick.AddListener(OnLeftClick);
|
|
btn_arrow_right.onClick.AddListener(OnRightClick);
|
|
}
|
|
void OnEnable()
|
|
{
|
|
for (int i = 0; i < levelup.Count; i++)
|
|
{
|
|
levelup[i].gameObject.SetActive(false);
|
|
}
|
|
SetData();
|
|
}
|
|
private void Update()
|
|
{
|
|
//左右滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
OnBeginDrag();
|
|
}
|
|
if (Input.GetMouseButtonUp(0))
|
|
{
|
|
OnEndDrag();
|
|
}
|
|
}
|
|
float beginDragPosX = 0;
|
|
void OnBeginDrag()
|
|
{
|
|
beginDragPosX = Input.mousePosition.x;
|
|
}
|
|
void OnEndDrag()
|
|
{
|
|
//滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
|
if (Mathf.Abs(Input.mousePosition.x - beginDragPosX) > Screen.width / 4)
|
|
{
|
|
if (Input.mousePosition.x > beginDragPosX)
|
|
{
|
|
OnLeftClick();
|
|
}
|
|
else
|
|
{
|
|
OnRightClick();
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnLeftClick()
|
|
{
|
|
currentIndex -= 1;
|
|
if (currentIndex < 0)
|
|
{
|
|
currentIndex = dataList.Count - 1;
|
|
}
|
|
SetData();
|
|
}
|
|
|
|
void OnRightClick()
|
|
{
|
|
currentIndex += 1;
|
|
if (currentIndex >= dataList.Count)
|
|
{
|
|
currentIndex = 0;
|
|
}
|
|
SetData();
|
|
}
|
|
void SetData()
|
|
{
|
|
if (dataList == null || dataList.Count <= currentIndex)
|
|
{
|
|
return;
|
|
}
|
|
data = dataList[currentIndex];
|
|
SetProficiency();
|
|
fish_card.data = data;
|
|
fish_card.Init();
|
|
}
|
|
void OnClickUp()
|
|
{
|
|
GContext.container.Resolve<PlayerFishData>().UpDateLevel(data.ID);
|
|
for (int i = 0; i < levelup.Count; i++)
|
|
{
|
|
levelup[i].gameObject.SetActive(false);
|
|
levelup[i].gameObject.SetActive(true);
|
|
}
|
|
SetProficiency();
|
|
fish_card.SetProficiency();
|
|
}
|
|
|
|
void SetProficiency()
|
|
{
|
|
int level = GContext.container.Resolve<PlayerFishData>().GetDataLevel(data.ID);
|
|
int curProficiency = GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(data.FishCardID);
|
|
cfg.FishCard fishCard = GContext.container.Resolve<Tables>().TbFishCard[data.FishCardID];
|
|
max_level.SetActive(level >= fishCard.MaxLevel);
|
|
text_level_max.gameObject.SetActive(level >= fishCard.MaxLevel);
|
|
arrow.SetActive(level < fishCard.MaxLevel);
|
|
if (level < fishCard.MaxLevel)
|
|
{
|
|
text_level_num_before.text = level.ToString();
|
|
text_level_num_after.text = $"{level + 1}";
|
|
int endWeight = fishCard.CardsRequiredList[level];
|
|
btn_upgrade.gameObject.SetActive(curProficiency >= endWeight);
|
|
btn_upgrade_gray.gameObject.SetActive(curProficiency < endWeight);
|
|
}
|
|
else
|
|
{
|
|
text_level_max.text = LocalizationMgr.GetFormatTextValue("UI_PlayerGradePopupPanel_1", fishCard.MaxLevel);
|
|
btn_upgrade.gameObject.SetActive(false);
|
|
btn_upgrade_gray.gameObject.SetActive(false);
|
|
}
|
|
SetFishAttribute();
|
|
}
|
|
void SetFishAttribute()
|
|
{
|
|
mapFishAttribute.SetFishAttribute(data);
|
|
}
|
|
}
|