备份CatanBuilding瘦身独立工程
This commit is contained in:
136
Assets/Scripts/UI/Grade/GradeItem.cs
Normal file
136
Assets/Scripts/UI/Grade/GradeItem.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GradeItem : PanelItemBase<GradeItemData>
|
||||
{
|
||||
GameObject bar_root;
|
||||
Image bar;
|
||||
GameObject bg_normal;
|
||||
GameObject bg_gray;
|
||||
GameObject bg_next;
|
||||
RewardItemNew[] rewardItems;
|
||||
Image[] rewardBg;
|
||||
TMP_Text text_grade;
|
||||
IUIService uiService;
|
||||
private void Awake()
|
||||
{
|
||||
uiService = GContext.container.Resolve<IUIService>();
|
||||
bar_root = transform.Find("bg_bar").gameObject;
|
||||
bar = transform.Find("bg_bar/bar").GetComponent<Image>();
|
||||
bg_normal = transform.Find("bg_normal").gameObject;
|
||||
bg_gray = transform.Find("bg_gray").gameObject;
|
||||
bg_next = transform.Find("bg_next").gameObject;
|
||||
rewardItems = transform.Find("reward").GetComponentsInChildren<RewardItemNew>();
|
||||
rewardBg = new Image[rewardItems.Length];
|
||||
for (int i = 0; i < rewardItems.Length; i++)
|
||||
{
|
||||
rewardBg[i] = rewardItems[i].transform.Find("bg").GetComponent<Image>();
|
||||
}
|
||||
text_grade = transform.Find("text_grade").GetComponent<TMP_Text>();
|
||||
}
|
||||
public void SetData(AccountMM account)
|
||||
{
|
||||
text_grade.text = account.ID.ToString();
|
||||
int len = 0;
|
||||
if (!string.IsNullOrEmpty(account.Icon))
|
||||
{
|
||||
uiService.SetImageSprite(rewardBg[len], "bg_shop_gift1");
|
||||
rewardItems[len].SetData(account.Icon, LocalizationMgr.GetText(account.Title_l10n_key), LocalizationMgr.GetText("UI_PlayerGradePanel_1"));
|
||||
len++;
|
||||
}
|
||||
var DisplaySwitch = account.DisplaySwitch;
|
||||
|
||||
|
||||
var levels = new List<int>
|
||||
{
|
||||
account.CashMag,
|
||||
account.CashMagLimited,
|
||||
account.EnergyLimit,
|
||||
account.EnergyRecover,
|
||||
account.EventFishCashMag,
|
||||
account.EventFishDamage,
|
||||
account.AquariumLimit,
|
||||
account.AquariumCashMag,
|
||||
};
|
||||
|
||||
var table = GContext.container.Resolve<cfg.Tables>();
|
||||
int id;
|
||||
Item item;
|
||||
for (int i = 0; i < DisplaySwitch.Count; i++)
|
||||
{
|
||||
if (len >= rewardItems.Length || i >= levels.Count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (DisplaySwitch[i] > 0)
|
||||
{
|
||||
id = 12001 + i;
|
||||
item = table.TbItem.GetOrDefault(id);
|
||||
uiService.SetImageSprite(rewardBg[len], "bg_grade_benefit");
|
||||
rewardItems[len].SetData(item, levels[i], true);
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if (account.Rewards > 0)
|
||||
{
|
||||
var itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(account.Rewards);
|
||||
if (itemDatas != null)
|
||||
{
|
||||
for (int i = 0; i < itemDatas.Count; i++)
|
||||
{
|
||||
if (len >= rewardItems.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uiService.SetImageSprite(rewardBg[len], "bg_shop_gift1");
|
||||
rewardItems[len].SetData(itemDatas[i]);
|
||||
len++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = len; i < rewardItems.Length; i++)
|
||||
{
|
||||
rewardItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
bg_next.SetActive(data.next);
|
||||
if (GContext.container.Resolve<PlayerData>().lv >= account.ID)
|
||||
{
|
||||
bar.fillAmount = 1;
|
||||
bg_gray.SetActive(true);
|
||||
bg_normal.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
bar.fillAmount = 0;
|
||||
bg_gray.SetActive(false);
|
||||
bg_normal.SetActive(!data.next);
|
||||
}
|
||||
for (int i = 0; i < rewardItems.Length; i++)
|
||||
{
|
||||
rewardItems[i].SetReceived(GContext.container.Resolve<PlayerData>().lv >= account.ID);
|
||||
}
|
||||
if (data.nextIndex - 1 == index)
|
||||
{
|
||||
bar.fillAmount = data.fillAmount;
|
||||
}
|
||||
bar_root.SetActive(data.bar);
|
||||
}
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
SetData(data.account);
|
||||
}
|
||||
}
|
||||
public class GradeItemData
|
||||
{
|
||||
public AccountMM account;
|
||||
public int nextIndex;
|
||||
public float fillAmount;
|
||||
public bool next;
|
||||
public bool bar = true;
|
||||
}
|
||||
Reference in New Issue
Block a user