UIPopupList.cs 20 KB

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