少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-14 7a606044e748707b10da259a84009cf38d93275b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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);
            }
        }
 
    }
}