blob: ed0ab8d1fb5693479835e7eb746dd14c281aff3e (
plain)
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
|
using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XUtliPoolLib;
namespace XMainClient.UI
{
internal class FashionComboBox
{
private ComboboxClickEventHandler _handler;
private IXUISprite selector = null;
private Transform droplist = null;
private IXUISprite close = null;
private IXUILabel selecttext = null;
private XUIPool itempool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);
private int itemPerRow = 0;
private int itemcount = 0;
private Dictionary<int, string> value2string = new Dictionary<int, string>();
public FashionComboBox(GameObject go, ComboboxClickEventHandler handler, int PerRow = 2)
{
this._handler = handler;
this.itemPerRow = PerRow;
this.selector = (go.transform.Find("Difficulty").GetComponent("XUISprite") as IXUISprite);
this.close = (go.transform.Find("Difficulty/DropList/Close").GetComponent("XUISprite") as IXUISprite);
this.selecttext = (go.transform.Find("Difficulty/SelectedText").GetComponent("XUILabel") as IXUILabel);
this.droplist = go.transform.Find("Difficulty/DropList");
Transform transform = go.transform.Find("Difficulty/DropList/ItemTpl");
this.itempool.SetupPool(this.droplist.gameObject, transform.gameObject, 6u, false);
this.droplist.gameObject.SetActive(false);
this.selector.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnSelectorClick));
this.close.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnCloseClick));
}
private void OnSelectorClick(IXUISprite sp)
{
this.droplist.gameObject.SetActive(true);
}
private void OnCloseClick(IXUISprite sp)
{
this.droplist.gameObject.SetActive(false);
}
public void AddItem(string text, int value)
{
GameObject gameObject = this.itempool.FetchGameObject(false);
int num = this.itemcount % this.itemPerRow;
int num2 = this.itemcount / this.itemPerRow;
gameObject.transform.localPosition = this.itempool.TplPos + new Vector3((float)(num * this.itempool.TplWidth), (float)(-(float)num2 * this.itempool.TplHeight));
IXUISprite ixuisprite = gameObject.GetComponent("XUISprite") as IXUISprite;
ixuisprite.ID = (ulong)((long)value);
ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnItemClick));
IXUILabel ixuilabel = gameObject.transform.Find("ItemText").GetComponent("XUILabel") as IXUILabel;
ixuilabel.SetText(text);
this.value2string.Add(value, text);
this.itemcount++;
}
private void OnItemClick(IXUISprite sp)
{
this.selecttext.SetText(this.value2string[(int)sp.ID]);
this.droplist.gameObject.SetActive(false);
this._handler((int)sp.ID);
}
public void SetSelect(int value)
{
string text;
bool flag = this.value2string.TryGetValue(value, out text);
if (flag)
{
this.selecttext.SetText(text);
this.droplist.gameObject.SetActive(false);
this._handler(value);
}
}
}
}
|