using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
public class AutomaticTreasureWin : Window
|
{
|
[SerializeField] Button closeBtn;
|
[SerializeField] Button treasureBtn;
|
[SerializeField] Text treasureBtn_Text;
|
[SerializeField] Transform container_Awards;
|
[SerializeField] AutoTreasureAwardsRow awardsRow;
|
|
LuckyTreasureModel luckyTreasureModel { get { return ModelCenter.Instance.GetModel<LuckyTreasureModel>(); } }
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
List<AutoTreasureAwardsRow> awardsRows = new List<AutoTreasureAwardsRow>();
|
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
luckyTreasureModel.UpdateLuckyResultEvent += UpdateLuckyResult;
|
SetDisplay();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
luckyTreasureModel.isAutoLuckyTreasure = false;
|
luckyTreasureModel.UpdateLuckyResultEvent -= UpdateLuckyResult;
|
OnDestroyAwardsRow();
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void SetDisplay()
|
{
|
awardsRows.Clear();
|
UpdateAwardsItem();
|
UpdateLuckyTreasureState();
|
}
|
|
private void UpdateLuckyResult()
|
{
|
UpdateAwardsItem();
|
}
|
|
private void UpdateLuckyTreasureState()
|
{
|
treasureBtn.RemoveAllListeners();
|
if (luckyTreasureModel.isAutoLuckyTreasure)
|
{
|
treasureBtn_Text.text = Language.Get("LuckyTreasure104");
|
treasureBtn.AddListener(ClickStopLuckyTreasure);
|
}
|
else
|
{
|
treasureBtn_Text.text = Language.Get("LuckyTreasure105");
|
treasureBtn.AddListener(ClickLuckyTreasure);
|
}
|
}
|
|
private void ClickStopLuckyTreasure()
|
{
|
luckyTreasureModel.isAutoLuckyTreasure = false;
|
UpdateLuckyTreasureState();
|
}
|
|
private void ClickLuckyTreasure()
|
{
|
luckyTreasureModel.isAutoLuckyTreasure = true;
|
luckyTreasureModel.SendStartLuckyTreasure();
|
UpdateLuckyTreasureState();
|
}
|
|
private void UpdateAwardsItem()
|
{
|
CreateAwardsRow();
|
for(int i = 0; i < awardsRows.Count; i++)
|
{
|
var treasureAwardsRow = awardsRows[i];
|
treasureAwardsRow.SetDisplay(i);
|
}
|
}
|
|
private void CreateAwardsRow()
|
{
|
var autoLuckyItems = luckyTreasureModel.autoLuckyItems;
|
int row = autoLuckyItems.Count / 10;
|
if(autoLuckyItems.Count % 10 > 0)
|
{
|
row += 1;
|
}
|
int startRow = awardsRows.Count;
|
for(int i = startRow; i < row; i++)
|
{
|
AutoTreasureAwardsRow treasureAwardsRow = Instantiate(awardsRow, Vector3.zero, Quaternion.identity, container_Awards);
|
treasureAwardsRow.transform.localScale = Vector3.one;
|
treasureAwardsRow.gameObject.SetActive(true);
|
awardsRows.Add(treasureAwardsRow);
|
}
|
awardsRow.gameObject.SetActive(false);
|
}
|
|
private void OnDestroyAwardsRow()
|
{
|
for(int i = 0; i < awardsRows.Count;i++)
|
{
|
DestroyObject(awardsRows[i].gameObject);
|
}
|
}
|
|
}
|
}
|