248 lines
8.5 KiB
C#
248 lines
8.5 KiB
C#
using System;
|
|
using cfg;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI.PartnerGather.Mining
|
|
{
|
|
public class EventPartnerSpinItemView: EnhancedScrollerCellView
|
|
{
|
|
private Transform highlight;
|
|
private Transform prize_nml;
|
|
private Transform prize_medium;
|
|
private Transform prize_super;
|
|
private Transform prize_free;
|
|
private Transform prize_more;
|
|
|
|
|
|
// 调试
|
|
private TMP_Text _textId;
|
|
private TMP_Text _textIndex;
|
|
|
|
//
|
|
private EventPartnerMineSpinPoint _spinPoint;
|
|
private int _dataId;
|
|
private float _moreValue = 0F;
|
|
private int _multiple = 1;
|
|
|
|
private void Awake()
|
|
{
|
|
prize_nml = transform.Find("prize/prize_nml");
|
|
prize_medium = transform.Find("prize/prize_medium");
|
|
prize_super = transform.Find("prize/prize_super");
|
|
prize_free = transform.Find("prize/prize_free");
|
|
prize_more = transform.Find("prize/prize_more");
|
|
highlight = transform.Find("prize/height");
|
|
|
|
_textId = transform.Find("prize/text_id").GetComponent<TMP_Text>();
|
|
_textIndex = transform.Find("prize/text_index").GetComponent<TMP_Text>();
|
|
}
|
|
|
|
// public void SetData(SpinItemData data, int index)
|
|
// {
|
|
// Bind(data.spinPoint,index);
|
|
// // _moreValue = data._moreValue;
|
|
// // _multiple = data._multiple;
|
|
//
|
|
// UpdateMore(_moreValue);
|
|
// UpdateMultiple(_multiple);
|
|
// // UpdateSelected(data.isSelected);
|
|
//
|
|
// }
|
|
|
|
public void Bind(EventPartnerMineSpinPoint data,int index)
|
|
{
|
|
ELog($"BindSpinItem index={index} spinId={data?.ID}");
|
|
|
|
_spinPoint = data;
|
|
// data.ShowType
|
|
var showType = data.ShowType;
|
|
// Log($"OldId :{_dataId} : new {data.ID}");
|
|
var param = data.SpinPointParam;
|
|
_dataId = data.ID;
|
|
_textId.text = _dataId.ToString();
|
|
_textIndex.text = index.ToString();
|
|
#if UNITY_EDITOR
|
|
gameObject.name = _textId.text;
|
|
#endif
|
|
switch (param)
|
|
{
|
|
case FreeSpinPoint point:
|
|
// prize_nml.gameObject.SetActive(false);
|
|
// prize_medium.gameObject.SetActive(false);
|
|
// prize_super.gameObject.SetActive(false);
|
|
// prize_more.gameObject.SetActive(false);
|
|
// prize_free.gameObject.SetActive(true);
|
|
// UpdateText(prize_free,point.SpinPoints.ToString());
|
|
|
|
UpdateFreeSpin(point,showType);
|
|
|
|
break;
|
|
case MoreSpinPoint point:
|
|
prize_nml.gameObject.SetActive(false);
|
|
prize_medium.gameObject.SetActive(false);
|
|
prize_super.gameObject.SetActive(false);
|
|
prize_free.gameObject.SetActive(false);
|
|
prize_more.gameObject.SetActive(true);
|
|
UpdateText(prize_more,Mathf.Round(point.BonusPercent * 100) + "%");
|
|
break;
|
|
case NormalSpinPoint point:
|
|
|
|
UpdateNormal(point,showType);
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public override void RefreshCellView()
|
|
{
|
|
ELog("RefreshCellView");
|
|
}
|
|
private void UpdateFreeSpin(FreeSpinPoint point, string showType,bool isPlayAnim = false)
|
|
{
|
|
ELog($"UpdateFreeSpin showType={showType}");
|
|
prize_nml.gameObject.SetActive(false);
|
|
prize_medium.gameObject.SetActive(false);
|
|
prize_super.gameObject.SetActive(false);
|
|
prize_free.gameObject.SetActive(true);
|
|
prize_more.gameObject.SetActive(false);
|
|
UpdateText(prize_free,point.SpinPoints,isPlayAnim);
|
|
}
|
|
|
|
private void UpdateMoreSpin(MoreSpinPoint point,bool isPlayAnim = false)
|
|
{
|
|
// throw new NotImplementedException();
|
|
UpdateText(prize_more,Mathf.Round(point.BonusPercent * 100) + "%",isPlayAnim);
|
|
}
|
|
|
|
|
|
private void UpdateNormal(NormalSpinPoint point,string showType,bool playAnim = false)
|
|
{
|
|
prize_nml.gameObject.SetActive(false);
|
|
prize_medium.gameObject.SetActive(false);
|
|
prize_super.gameObject.SetActive(false);
|
|
prize_free.gameObject.SetActive(false);
|
|
prize_more.gameObject.SetActive(false);
|
|
ELog($"UpdateNormalSpin showType={showType}");
|
|
switch (showType)
|
|
{
|
|
case "Basic":
|
|
prize_nml.gameObject.SetActive(true);
|
|
// prize_nml.GetComponent<Animation>().Play("text_change");
|
|
UpdateText(prize_nml,point.SpinPoints,playAnim);
|
|
break;
|
|
case "Advanced":
|
|
prize_medium.gameObject.SetActive(true);
|
|
// prize_nml.GetComponent<Animation>().Play("text_change");
|
|
UpdateText(prize_medium,point.SpinPoints,playAnim);
|
|
break;
|
|
case "Master":
|
|
prize_super.gameObject.SetActive(true);
|
|
// prize_nml.GetComponent<Animation>().Play("text_change");
|
|
UpdateText(prize_super,point.SpinPoints,playAnim);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void UpdateText(Transform rootUI, string context,bool isPlayAni = false)
|
|
{
|
|
var label = rootUI.GetComponentInChildren<TMP_Text>(true);
|
|
if (label)
|
|
{
|
|
label.text = context;
|
|
}
|
|
|
|
if (isPlayAni)
|
|
{
|
|
var anim = rootUI.GetComponent<Animation>();
|
|
if (anim)
|
|
{
|
|
anim.Play("text_change");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateText(Transform rootUI,int points,bool isPlayAni =false)
|
|
{
|
|
var value = GetMorePoints(points);
|
|
|
|
UpdateText(rootUI, value.ToString(),isPlayAni);
|
|
}
|
|
public void SetSelected(bool on)
|
|
{
|
|
// ELog($"SetSelected-> {on}");
|
|
if (highlight)
|
|
{
|
|
highlight.gameObject.SetActive(on);
|
|
}
|
|
}
|
|
|
|
private static void ELog(object t)
|
|
{
|
|
#if UNITY_EDITOR
|
|
Debug.Log($"<color=cyan>EventPartnerSpinItemView -> {t} </color>");
|
|
#endif
|
|
}
|
|
|
|
public void UpdateSelected(int index )
|
|
{
|
|
if (highlight)
|
|
{
|
|
highlight.gameObject.SetActive(_dataId == index);
|
|
}
|
|
}
|
|
|
|
public int GetMorePoints(int spinPoints)
|
|
{
|
|
var multiple = _multiple;
|
|
return (int)(spinPoints * (1F + _moreValue) * multiple);
|
|
}
|
|
|
|
public void UpdateMultiple(int multiple)
|
|
{
|
|
var param = _spinPoint.SpinPointParam;
|
|
_multiple = multiple;
|
|
switch (param)
|
|
{
|
|
case NormalSpinPoint point:
|
|
// UpdateText(prize_nml,GetMorePoints(point.SpinPoints).ToString());
|
|
UpdateNormal(point, _spinPoint.ShowType,true );
|
|
break;
|
|
case FreeSpinPoint point:
|
|
UpdateFreeSpin(point,_spinPoint.ShowType,true );
|
|
break;
|
|
case MoreSpinPoint point:
|
|
UpdateMoreSpin(point,true );
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
public void UpdateMore(float moreValue )
|
|
{
|
|
_moreValue = moreValue;
|
|
|
|
var param = _spinPoint.SpinPointParam;
|
|
switch (param)
|
|
{
|
|
case NormalSpinPoint point:
|
|
// UpdateText(prize_nml,GetMorePoints(point.SpinPoints).ToString());
|
|
UpdateNormal(point, _spinPoint.ShowType,true);
|
|
break;
|
|
case FreeSpinPoint point:
|
|
UpdateFreeSpin(point,_spinPoint.ShowType,true );
|
|
break;
|
|
case MoreSpinPoint point:
|
|
UpdateMoreSpin(point,true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |