UIPopupList.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. [ExecuteInEditMode]
  6. [AddComponentMenu("NGUI/Interaction/Popup List")]
  7. public class UIPopupList : UIWidgetContainer
  8. {
  9. public UnityEngine.Object ambigiousFont
  10. {
  11. get
  12. {
  13. if (this.trueTypeFont != null)
  14. {
  15. return this.trueTypeFont;
  16. }
  17. if (this.bitmapFont != null)
  18. {
  19. return this.bitmapFont;
  20. }
  21. return this.font;
  22. }
  23. set
  24. {
  25. if (value is Font)
  26. {
  27. this.trueTypeFont = (value as Font);
  28. this.bitmapFont = null;
  29. this.font = null;
  30. }
  31. else if (value is UIFont)
  32. {
  33. this.bitmapFont = (value as UIFont);
  34. this.trueTypeFont = null;
  35. this.font = null;
  36. }
  37. }
  38. }
  39. [Obsolete("Use EventDelegate.Add(popup.onChange, YourCallback) instead, and UIPopupList.current.value to determine the state")]
  40. public UIPopupList.LegacyEvent onSelectionChange
  41. {
  42. get
  43. {
  44. return this.mLegacyEvent;
  45. }
  46. set
  47. {
  48. this.mLegacyEvent = value;
  49. }
  50. }
  51. public bool isOpen
  52. {
  53. get
  54. {
  55. return this.mChild != null;
  56. }
  57. }
  58. public string value
  59. {
  60. get
  61. {
  62. return this.mSelectedItem;
  63. }
  64. set
  65. {
  66. this.mSelectedItem = value;
  67. if (this.mSelectedItem == null)
  68. {
  69. return;
  70. }
  71. if (this.mSelectedItem != null)
  72. {
  73. this.TriggerCallbacks();
  74. }
  75. }
  76. }
  77. public object data
  78. {
  79. get
  80. {
  81. int num = this.items.IndexOf(this.mSelectedItem);
  82. return (num <= -1 || num >= this.itemData.Count) ? null : this.itemData[num];
  83. }
  84. }
  85. [Obsolete("Use 'value' instead")]
  86. public string selection
  87. {
  88. get
  89. {
  90. return this.value;
  91. }
  92. set
  93. {
  94. this.value = value;
  95. }
  96. }
  97. private bool handleEvents
  98. {
  99. get
  100. {
  101. UIKeyNavigation component = base.GetComponent<UIKeyNavigation>();
  102. return component == null || !component.enabled;
  103. }
  104. set
  105. {
  106. UIKeyNavigation component = base.GetComponent<UIKeyNavigation>();
  107. if (component != null)
  108. {
  109. component.enabled = !value;
  110. }
  111. }
  112. }
  113. private bool isValid
  114. {
  115. get
  116. {
  117. return this.bitmapFont != null || this.trueTypeFont != null;
  118. }
  119. }
  120. private int activeFontSize
  121. {
  122. get
  123. {
  124. return (!(this.trueTypeFont != null) && !(this.bitmapFont == null)) ? this.bitmapFont.defaultSize : this.fontSize;
  125. }
  126. }
  127. private float activeFontScale
  128. {
  129. get
  130. {
  131. return (!(this.trueTypeFont != null) && !(this.bitmapFont == null)) ? ((float)this.fontSize / (float)this.bitmapFont.defaultSize) : 1f;
  132. }
  133. }
  134. public void Clear()
  135. {
  136. this.items.Clear();
  137. this.itemData.Clear();
  138. }
  139. public void AddItem(string text)
  140. {
  141. this.items.Add(text);
  142. this.itemData.Add(null);
  143. }
  144. public void AddItem(string text, object data)
  145. {
  146. this.items.Add(text);
  147. this.itemData.Add(data);
  148. }
  149. protected void TriggerCallbacks()
  150. {
  151. if (UIPopupList.current != this)
  152. {
  153. UIPopupList uipopupList = UIPopupList.current;
  154. UIPopupList.current = this;
  155. if (this.mLegacyEvent != null)
  156. {
  157. this.mLegacyEvent(this.mSelectedItem);
  158. }
  159. if (EventDelegate.IsValid(this.onChange))
  160. {
  161. EventDelegate.Execute(this.onChange);
  162. }
  163. else if (this.eventReceiver != null && !string.IsNullOrEmpty(this.functionName))
  164. {
  165. this.eventReceiver.SendMessage(this.functionName, this.mSelectedItem, SendMessageOptions.DontRequireReceiver);
  166. }
  167. UIPopupList.current = uipopupList;
  168. }
  169. }
  170. private void OnEnable()
  171. {
  172. if (EventDelegate.IsValid(this.onChange))
  173. {
  174. this.eventReceiver = null;
  175. this.functionName = null;
  176. }
  177. if (this.font != null)
  178. {
  179. if (this.font.isDynamic)
  180. {
  181. this.trueTypeFont = this.font.dynamicFont;
  182. this.fontStyle = this.font.dynamicFontStyle;
  183. this.mUseDynamicFont = true;
  184. }
  185. else if (this.bitmapFont == null)
  186. {
  187. this.bitmapFont = this.font;
  188. this.mUseDynamicFont = false;
  189. }
  190. this.font = null;
  191. }
  192. if (this.textScale != 0f)
  193. {
  194. this.fontSize = ((!(this.bitmapFont != null)) ? 16 : Mathf.RoundToInt((float)this.bitmapFont.defaultSize * this.textScale));
  195. this.textScale = 0f;
  196. }
  197. if (this.trueTypeFont == null && this.bitmapFont != null && this.bitmapFont.isDynamic)
  198. {
  199. this.trueTypeFont = this.bitmapFont.dynamicFont;
  200. this.bitmapFont = null;
  201. }
  202. }
  203. private void OnValidate()
  204. {
  205. Font x = this.trueTypeFont;
  206. UIFont uifont = this.bitmapFont;
  207. this.bitmapFont = null;
  208. this.trueTypeFont = null;
  209. if (x != null && (uifont == null || !this.mUseDynamicFont))
  210. {
  211. this.bitmapFont = null;
  212. this.trueTypeFont = x;
  213. this.mUseDynamicFont = true;
  214. }
  215. else if (uifont != null)
  216. {
  217. if (uifont.isDynamic)
  218. {
  219. this.trueTypeFont = uifont.dynamicFont;
  220. this.fontStyle = uifont.dynamicFontStyle;
  221. this.fontSize = uifont.defaultSize;
  222. this.mUseDynamicFont = true;
  223. }
  224. else
  225. {
  226. this.bitmapFont = uifont;
  227. this.mUseDynamicFont = false;
  228. }
  229. }
  230. else
  231. {
  232. this.trueTypeFont = x;
  233. this.mUseDynamicFont = true;
  234. }
  235. }
  236. private void Start()
  237. {
  238. if (this.textLabel != null)
  239. {
  240. EventDelegate.Add(this.onChange, new EventDelegate.Callback(this.textLabel.SetCurrentSelection));
  241. this.textLabel = null;
  242. }
  243. if (Application.isPlaying)
  244. {
  245. if (string.IsNullOrEmpty(this.mSelectedItem))
  246. {
  247. if (this.items.Count > 0)
  248. {
  249. this.value = this.items[0];
  250. }
  251. }
  252. else
  253. {
  254. string value = this.mSelectedItem;
  255. this.mSelectedItem = null;
  256. this.value = value;
  257. }
  258. }
  259. }
  260. private void OnLocalize()
  261. {
  262. if (this.isLocalized)
  263. {
  264. this.TriggerCallbacks();
  265. }
  266. }
  267. private void Highlight(UILabel lbl, bool instant)
  268. {
  269. if (this.mHighlight != null)
  270. {
  271. this.mHighlightedLabel = lbl;
  272. if (this.mHighlight.GetAtlasSprite() == null)
  273. {
  274. return;
  275. }
  276. Vector3 highlightPosition = this.GetHighlightPosition();
  277. if (instant || !this.isAnimated)
  278. {
  279. this.mHighlight.cachedTransform.localPosition = highlightPosition;
  280. }
  281. else
  282. {
  283. TweenPosition.Begin(this.mHighlight.gameObject, 0.1f, highlightPosition).method = UITweener.Method.EaseOut;
  284. if (!this.mTweening)
  285. {
  286. this.mTweening = true;
  287. base.StartCoroutine("UpdateTweenPosition");
  288. }
  289. }
  290. }
  291. }
  292. private Vector3 GetHighlightPosition()
  293. {
  294. if (this.mHighlightedLabel == null || this.mHighlight == null)
  295. {
  296. return Vector3.zero;
  297. }
  298. UISpriteData atlasSprite = this.mHighlight.GetAtlasSprite();
  299. if (atlasSprite == null)
  300. {
  301. return Vector3.zero;
  302. }
  303. float pixelSize = this.atlas.pixelSize;
  304. float num = (float)atlasSprite.borderLeft * pixelSize;
  305. float y = (float)atlasSprite.borderTop * pixelSize;
  306. return this.mHighlightedLabel.cachedTransform.localPosition + new Vector3(-num, y, 1f);
  307. }
  308. private IEnumerator UpdateTweenPosition()
  309. {
  310. if (this.mHighlight != null && this.mHighlightedLabel != null)
  311. {
  312. TweenPosition tp = this.mHighlight.GetComponent<TweenPosition>();
  313. while (tp != null && tp.enabled)
  314. {
  315. tp.to = this.GetHighlightPosition();
  316. yield return null;
  317. }
  318. }
  319. this.mTweening = false;
  320. yield break;
  321. }
  322. private void OnItemHover(GameObject go, bool isOver)
  323. {
  324. if (isOver)
  325. {
  326. UILabel component = go.GetComponent<UILabel>();
  327. this.Highlight(component, false);
  328. }
  329. }
  330. private void Select(UILabel lbl, bool instant)
  331. {
  332. this.Highlight(lbl, instant);
  333. UIEventListener component = lbl.gameObject.GetComponent<UIEventListener>();
  334. this.value = (component.parameter as string);
  335. UIPlaySound[] components = base.GetComponents<UIPlaySound>();
  336. int i = 0;
  337. int num = components.Length;
  338. while (i < num)
  339. {
  340. UIPlaySound uiplaySound = components[i];
  341. if (uiplaySound.trigger == UIPlaySound.Trigger.OnClick)
  342. {
  343. NGUITools.PlaySound(uiplaySound.audioClip, uiplaySound.volume, 1f);
  344. }
  345. i++;
  346. }
  347. }
  348. private void OnItemPress(GameObject go, bool isPressed)
  349. {
  350. if (isPressed)
  351. {
  352. this.Select(go.GetComponent<UILabel>(), true);
  353. }
  354. }
  355. private void OnItemClick(GameObject go)
  356. {
  357. this.Close();
  358. }
  359. private void OnKey(KeyCode key)
  360. {
  361. if (base.enabled && NGUITools.GetActive(base.gameObject) && this.handleEvents)
  362. {
  363. int num = this.mLabelList.IndexOf(this.mHighlightedLabel);
  364. if (num == -1)
  365. {
  366. num = 0;
  367. }
  368. if (key == KeyCode.UpArrow)
  369. {
  370. if (num > 0)
  371. {
  372. this.Select(this.mLabelList[num - 1], false);
  373. }
  374. }
  375. else if (key == KeyCode.DownArrow)
  376. {
  377. if (num + 1 < this.mLabelList.Count)
  378. {
  379. this.Select(this.mLabelList[num + 1], false);
  380. }
  381. }
  382. else if (key == KeyCode.Escape)
  383. {
  384. this.OnSelect(false);
  385. }
  386. }
  387. }
  388. private void OnDisable()
  389. {
  390. this.Close();
  391. }
  392. private void OnSelect(bool isSelected)
  393. {
  394. if (!isSelected)
  395. {
  396. this.Close();
  397. }
  398. }
  399. public void Close()
  400. {
  401. if (this.mChild != null)
  402. {
  403. this.mLabelList.Clear();
  404. this.handleEvents = false;
  405. if (this.isAnimated)
  406. {
  407. UIWidget[] componentsInChildren = this.mChild.GetComponentsInChildren<UIWidget>();
  408. int i = 0;
  409. int num = componentsInChildren.Length;
  410. while (i < num)
  411. {
  412. UIWidget uiwidget = componentsInChildren[i];
  413. Color color = uiwidget.color;
  414. color.a = 0f;
  415. TweenColor.Begin(uiwidget.gameObject, 0.15f, color).method = UITweener.Method.EaseOut;
  416. i++;
  417. }
  418. Collider[] componentsInChildren2 = this.mChild.GetComponentsInChildren<Collider>();
  419. int j = 0;
  420. int num2 = componentsInChildren2.Length;
  421. while (j < num2)
  422. {
  423. componentsInChildren2[j].enabled = false;
  424. j++;
  425. }
  426. UnityEngine.Object.Destroy(this.mChild, 0.15f);
  427. }
  428. else
  429. {
  430. UnityEngine.Object.Destroy(this.mChild);
  431. }
  432. this.mBackground = null;
  433. this.mHighlight = null;
  434. this.mChild = null;
  435. }
  436. }
  437. private void AnimateColor(UIWidget widget)
  438. {
  439. Color color = widget.color;
  440. widget.color = new Color(color.r, color.g, color.b, 0f);
  441. TweenColor.Begin(widget.gameObject, 0.15f, color).method = UITweener.Method.EaseOut;
  442. }
  443. private void AnimatePosition(UIWidget widget, bool placeAbove, float bottom)
  444. {
  445. Vector3 localPosition = widget.cachedTransform.localPosition;
  446. Vector3 localPosition2 = (!placeAbove) ? new Vector3(localPosition.x, 0f, localPosition.z) : new Vector3(localPosition.x, bottom, localPosition.z);
  447. widget.cachedTransform.localPosition = localPosition2;
  448. GameObject gameObject = widget.gameObject;
  449. TweenPosition.Begin(gameObject, 0.15f, localPosition).method = UITweener.Method.EaseOut;
  450. }
  451. private void AnimateScale(UIWidget widget, bool placeAbove, float bottom)
  452. {
  453. GameObject gameObject = widget.gameObject;
  454. Transform cachedTransform = widget.cachedTransform;
  455. float num = (float)this.activeFontSize * this.activeFontScale + this.mBgBorder * 2f;
  456. cachedTransform.localScale = new Vector3(1f, num / (float)widget.height, 1f);
  457. TweenScale.Begin(gameObject, 0.15f, Vector3.one).method = UITweener.Method.EaseOut;
  458. if (placeAbove)
  459. {
  460. Vector3 localPosition = cachedTransform.localPosition;
  461. cachedTransform.localPosition = new Vector3(localPosition.x, localPosition.y - (float)widget.height + num, localPosition.z);
  462. TweenPosition.Begin(gameObject, 0.15f, localPosition).method = UITweener.Method.EaseOut;
  463. }
  464. }
  465. private void Animate(UIWidget widget, bool placeAbove, float bottom)
  466. {
  467. this.AnimateColor(widget);
  468. this.AnimatePosition(widget, placeAbove, bottom);
  469. }
  470. private void OnClick()
  471. {
  472. if (this.openOn == UIPopupList.OpenOn.DoubleClick || this.openOn == UIPopupList.OpenOn.Manual)
  473. {
  474. return;
  475. }
  476. if (this.openOn == UIPopupList.OpenOn.RightClick && UICamera.currentTouchID != -2)
  477. {
  478. return;
  479. }
  480. this.Show();
  481. }
  482. private void OnDoubleClick()
  483. {
  484. if (this.openOn == UIPopupList.OpenOn.DoubleClick)
  485. {
  486. this.Show();
  487. }
  488. }
  489. private IEnumerator CloseIfUnselected()
  490. {
  491. GameObject go = UICamera.selectedObject;
  492. do
  493. {
  494. yield return null;
  495. }
  496. while (!(UICamera.selectedObject != go));
  497. this.Close();
  498. yield break;
  499. }
  500. public void Show()
  501. {
  502. if (base.enabled && NGUITools.GetActive(base.gameObject) && this.mChild == null && this.atlas != null && this.isValid && this.items.Count > 0)
  503. {
  504. this.mLabelList.Clear();
  505. if (this.mPanel == null)
  506. {
  507. this.mPanel = UIPanel.Find(base.transform);
  508. if (this.mPanel == null)
  509. {
  510. return;
  511. }
  512. }
  513. this.handleEvents = true;
  514. Transform transform = base.transform;
  515. this.mChild = new GameObject("Drop-down List");
  516. this.mChild.layer = base.gameObject.layer;
  517. Transform transform2 = this.mChild.transform;
  518. transform2.parent = transform.parent;
  519. Vector3 vector;
  520. Vector3 v;
  521. Vector3 vector2;
  522. if (this.openOn == UIPopupList.OpenOn.Manual && UICamera.selectedObject != base.gameObject)
  523. {
  524. base.StopCoroutine("CloseIfUnselected");
  525. vector = transform2.parent.InverseTransformPoint(this.mPanel.anchorCamera.ScreenToWorldPoint(UICamera.lastTouchPosition));
  526. v = vector;
  527. transform2.localPosition = vector;
  528. vector2 = transform2.position;
  529. base.StartCoroutine("CloseIfUnselected");
  530. }
  531. else
  532. {
  533. Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform, false, false);
  534. vector = bounds.min;
  535. v = bounds.max;
  536. transform2.localPosition = vector;
  537. vector2 = transform.position;
  538. }
  539. transform2.localRotation = Quaternion.identity;
  540. transform2.localScale = Vector3.one;
  541. this.mBackground = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite);
  542. this.mBackground.pivot = UIWidget.Pivot.TopLeft;
  543. this.mBackground.depth = NGUITools.CalculateNextDepth(this.mPanel.gameObject);
  544. this.mBackground.color = this.backgroundColor;
  545. Vector4 border = this.mBackground.border;
  546. this.mBgBorder = border.y;
  547. this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
  548. this.mHighlight = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite);
  549. this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
  550. this.mHighlight.color = this.highlightColor;
  551. UISpriteData atlasSprite = this.mHighlight.GetAtlasSprite();
  552. if (atlasSprite == null)
  553. {
  554. return;
  555. }
  556. float num = (float)atlasSprite.borderTop;
  557. float num2 = (float)this.activeFontSize;
  558. float activeFontScale = this.activeFontScale;
  559. float num3 = num2 * activeFontScale;
  560. float num4 = 0f;
  561. float num5 = -this.padding.y;
  562. List<UILabel> list = new List<UILabel>();
  563. if (!this.items.Contains(this.mSelectedItem))
  564. {
  565. this.mSelectedItem = null;
  566. }
  567. int i = 0;
  568. int count = this.items.Count;
  569. while (i < count)
  570. {
  571. string text = this.items[i];
  572. UILabel uilabel = NGUITools.AddWidget<UILabel>(this.mChild);
  573. uilabel.name = i.ToString();
  574. uilabel.pivot = UIWidget.Pivot.TopLeft;
  575. uilabel.bitmapFont = this.bitmapFont;
  576. uilabel.trueTypeFont = this.trueTypeFont;
  577. uilabel.fontSize = this.fontSize;
  578. uilabel.fontStyle = this.fontStyle;
  579. uilabel.text = ((!this.isLocalized) ? text : Localization.Get(text));
  580. uilabel.color = this.textColor;
  581. uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x - uilabel.pivotOffset.x, num5, -1f);
  582. uilabel.overflowMethod = UILabel.Overflow.ResizeFreely;
  583. uilabel.alignment = this.alignment;
  584. list.Add(uilabel);
  585. num5 -= num3;
  586. num5 -= this.padding.y;
  587. num4 = Mathf.Max(num4, uilabel.printedSize.x);
  588. UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject);
  589. uieventListener.onHover = new UIEventListener.BoolDelegate(this.OnItemHover);
  590. uieventListener.onPress = new UIEventListener.BoolDelegate(this.OnItemPress);
  591. uieventListener.onClick = new UIEventListener.VoidDelegate(this.OnItemClick);
  592. uieventListener.parameter = text;
  593. if (this.mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(this.mSelectedItem)))
  594. {
  595. this.Highlight(uilabel, true);
  596. }
  597. this.mLabelList.Add(uilabel);
  598. i++;
  599. }
  600. num4 = Mathf.Max(num4, (v.x - vector.x) * activeFontScale - (border.x + this.padding.x) * 2f);
  601. float num6 = num4;
  602. Vector3 vector3 = new Vector3(num6 * 0.5f, -num3 * 0.5f, 0f);
  603. Vector3 vector4 = new Vector3(num6, num3 + this.padding.y, 1f);
  604. int j = 0;
  605. int count2 = list.Count;
  606. while (j < count2)
  607. {
  608. UILabel uilabel2 = list[j];
  609. NGUITools.AddWidgetCollider(uilabel2.gameObject);
  610. uilabel2.autoResizeBoxCollider = false;
  611. BoxCollider component = uilabel2.GetComponent<BoxCollider>();
  612. if (component != null)
  613. {
  614. vector3.z = component.center.z;
  615. component.center = vector3;
  616. component.size = vector4;
  617. }
  618. else
  619. {
  620. BoxCollider2D component2 = uilabel2.GetComponent<BoxCollider2D>();
  621. component2.offset = vector3;
  622. component2.size = vector4;
  623. }
  624. j++;
  625. }
  626. int width = Mathf.RoundToInt(num4);
  627. num4 += (border.x + this.padding.x) * 2f;
  628. num5 -= border.y;
  629. this.mBackground.width = Mathf.RoundToInt(num4);
  630. this.mBackground.height = Mathf.RoundToInt(-num5 + border.y);
  631. int k = 0;
  632. int count3 = list.Count;
  633. while (k < count3)
  634. {
  635. UILabel uilabel3 = list[k];
  636. uilabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
  637. uilabel3.width = width;
  638. k++;
  639. }
  640. float num7 = 2f * this.atlas.pixelSize;
  641. float f = num4 - (border.x + this.padding.x) * 2f + (float)atlasSprite.borderLeft * num7;
  642. float f2 = num3 + num * num7;
  643. this.mHighlight.width = Mathf.RoundToInt(f);
  644. this.mHighlight.height = Mathf.RoundToInt(f2);
  645. bool flag = this.position == UIPopupList.Position.Above;
  646. if (this.position == UIPopupList.Position.Auto)
  647. {
  648. UICamera uicamera = UICamera.FindCameraForLayer((UICamera.selectedObject ?? base.gameObject).layer);
  649. if (uicamera != null)
  650. {
  651. flag = (uicamera.cachedCamera.WorldToViewportPoint(vector2).y < 0.5f);
  652. }
  653. }
  654. if (this.isAnimated)
  655. {
  656. float bottom = num5 + num3;
  657. this.Animate(this.mHighlight, flag, bottom);
  658. int l = 0;
  659. int count4 = list.Count;
  660. while (l < count4)
  661. {
  662. this.Animate(list[l], flag, bottom);
  663. l++;
  664. }
  665. this.AnimateColor(this.mBackground);
  666. this.AnimateScale(this.mBackground, flag, bottom);
  667. }
  668. if (flag)
  669. {
  670. transform2.localPosition = new Vector3(vector.x, v.y - num5 - border.y, vector.z);
  671. }
  672. vector = transform2.localPosition;
  673. v.x = vector.x + (float)this.mBackground.width;
  674. v.y = vector.y - (float)this.mBackground.height;
  675. v.z = vector.z;
  676. Vector3 b = this.mPanel.CalculateConstrainOffset(vector, v);
  677. transform2.localPosition += b;
  678. }
  679. else
  680. {
  681. this.OnSelect(false);
  682. }
  683. }
  684. public static UIPopupList current;
  685. private const float animSpeed = 0.15f;
  686. public UIAtlas atlas;
  687. public UIFont bitmapFont;
  688. public Font trueTypeFont;
  689. public int fontSize = 16;
  690. public FontStyle fontStyle;
  691. public string backgroundSprite;
  692. public string highlightSprite;
  693. public UIPopupList.Position position;
  694. public NGUIText.Alignment alignment = NGUIText.Alignment.Left;
  695. public List<string> items = new List<string>();
  696. public List<object> itemData = new List<object>();
  697. public Vector2 padding = new Vector3(4f, 4f);
  698. public Color textColor = Color.white;
  699. public Color backgroundColor = Color.white;
  700. public Color highlightColor = new Color(0.882352948f, 0.784313738f, 0.5882353f, 1f);
  701. public bool isAnimated = true;
  702. public bool isLocalized;
  703. public UIPopupList.OpenOn openOn;
  704. public List<EventDelegate> onChange = new List<EventDelegate>();
  705. [HideInInspector]
  706. [SerializeField]
  707. private string mSelectedItem;
  708. [HideInInspector]
  709. [SerializeField]
  710. private UIPanel mPanel;
  711. [HideInInspector]
  712. [SerializeField]
  713. private GameObject mChild;
  714. [HideInInspector]
  715. [SerializeField]
  716. private UISprite mBackground;
  717. [HideInInspector]
  718. [SerializeField]
  719. private UISprite mHighlight;
  720. [HideInInspector]
  721. [SerializeField]
  722. private UILabel mHighlightedLabel;
  723. [HideInInspector]
  724. [SerializeField]
  725. private List<UILabel> mLabelList = new List<UILabel>();
  726. [HideInInspector]
  727. [SerializeField]
  728. private float mBgBorder;
  729. [HideInInspector]
  730. [SerializeField]
  731. private GameObject eventReceiver;
  732. [HideInInspector]
  733. [SerializeField]
  734. private string functionName = "OnSelectionChange";
  735. [HideInInspector]
  736. [SerializeField]
  737. private float textScale;
  738. [HideInInspector]
  739. [SerializeField]
  740. private UIFont font;
  741. [HideInInspector]
  742. [SerializeField]
  743. private UILabel textLabel;
  744. private UIPopupList.LegacyEvent mLegacyEvent;
  745. private bool mUseDynamicFont;
  746. private bool mTweening;
  747. public enum Position
  748. {
  749. Auto,
  750. Above,
  751. Below
  752. }
  753. public enum OpenOn
  754. {
  755. ClickOrTap,
  756. RightClick,
  757. DoubleClick,
  758. Manual
  759. }
  760. public delegate void LegacyEvent(string val);
  761. }