PageRenderTime 32ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/as3/src/com/poliroid/gui/lobby/battleHits/components/BatHitsHeader.as

https://gitlab.com/yinx2002/battle-hits
ActionScript | 117 lines | 101 code | 16 blank | 0 comment | 1 complexity | 449069bb288d2dc9eae4e0825144c1a2 MD5 | raw file
  1. package com.poliroid.gui.lobby.battleHits.components
  2. {
  3. import flash.display.Sprite;
  4. import flash.text.TextField;
  5. import scaleform.clik.constants.InvalidationType;
  6. import scaleform.clik.events.ButtonEvent;
  7. import net.wg.gui.components.controls.CloseButtonText;
  8. import net.wg.infrastructure.base.UIComponentEx;
  9. import net.wg.infrastructure.interfaces.IPopOverCaller;
  10. import com.poliroid.gui.lobby.battleHits.controls.HitTypeButton;
  11. import com.poliroid.gui.lobby.battleHits.controls.PopoverCallerButton;
  12. import com.poliroid.gui.lobby.battleHits.data.BatHitsHeaderVO;
  13. import com.poliroid.gui.lobby.battleHits.events.BatHitsEvent;
  14. import com.poliroid.gui.lobby.battleHits.interfaces.IBatHitsHeader;
  15. public class BatHitsHeader extends UIComponentEx implements IBatHitsHeader
  16. {
  17. private static const CLOSE_BTN_OFFSET:int = 15;
  18. private static const HIT_TYPE_BTN_OFFSET:int = 127;
  19. public var background:Sprite;
  20. public var titleTF:TextField;
  21. public var closeBtn:CloseButtonText;
  22. public var settingsBtn:PopoverCallerButton;
  23. public var hitsTypeToPlayer:HitTypeButton;
  24. public var hitsTypeFromPlayer:HitTypeButton;
  25. override protected function onDispose(): void
  26. {
  27. closeBtn.removeEventListener(ButtonEvent.CLICK, onCloseBtnClickHandler);
  28. settingsBtn.removeEventListener(ButtonEvent.CLICK, onPreferencesClickHandler);
  29. hitsTypeToPlayer.removeEventListener(ButtonEvent.CLICK, onToPlayerClickHandler);
  30. hitsTypeFromPlayer.removeEventListener(ButtonEvent.CLICK, onFromPlayerClickHandler);
  31. closeBtn.dispose();
  32. settingsBtn.dispose();
  33. hitsTypeToPlayer.dispose();
  34. hitsTypeFromPlayer.dispose();
  35. closeBtn = null;
  36. settingsBtn = null;
  37. hitsTypeToPlayer = null;
  38. hitsTypeFromPlayer = null;
  39. background = null;
  40. titleTF = null;
  41. super.onDispose();
  42. }
  43. override protected function configUI(): void
  44. {
  45. super.configUI();
  46. closeBtn.addEventListener(ButtonEvent.CLICK, onCloseBtnClickHandler);
  47. settingsBtn.addEventListener(ButtonEvent.CLICK, onPreferencesClickHandler);
  48. hitsTypeToPlayer.addEventListener(ButtonEvent.CLICK, onToPlayerClickHandler);
  49. hitsTypeFromPlayer.addEventListener(ButtonEvent.CLICK, onFromPlayerClickHandler);
  50. }
  51. override protected function draw(): void
  52. {
  53. super.draw();
  54. if(isInvalid(InvalidationType.SIZE))
  55. {
  56. var screenWidth:int = App.appWidth;
  57. background.width = int(screenWidth);
  58. titleTF.x = int((screenWidth - titleTF.width) / 2);
  59. closeBtn.x = int(screenWidth - closeBtn.width - CLOSE_BTN_OFFSET);
  60. settingsBtn.x = int(closeBtn.x - settingsBtn.width);
  61. hitsTypeToPlayer.x = int((screenWidth - HIT_TYPE_BTN_OFFSET * 2) / 2);
  62. hitsTypeFromPlayer.x = int(hitsTypeToPlayer.x + HIT_TYPE_BTN_OFFSET);
  63. }
  64. }
  65. public function get preferenceButton(): IPopOverCaller
  66. {
  67. return settingsBtn as IPopOverCaller;
  68. }
  69. public function updateDP(model:BatHitsHeaderVO): void
  70. {
  71. closeBtn.label = model.closeBtnLabel;
  72. settingsBtn.label = model.settingsLabel;
  73. titleTF.text = model.titleLabel;
  74. hitsTypeToPlayer.label = model.typeBtnMe;
  75. hitsTypeFromPlayer.label = model.typeBtnEnemys;
  76. hitsTypeToPlayer.isActive = model.typeBtnMeActive;
  77. hitsTypeFromPlayer.isActive = model.typeBtnEnemysActive;
  78. invalidateSize();
  79. }
  80. private function onCloseBtnClickHandler(e:ButtonEvent): void
  81. {
  82. dispatchEvent(new BatHitsEvent(BatHitsEvent.CLOSE_CLICK, true));
  83. }
  84. private function onPreferencesClickHandler(e:ButtonEvent): void
  85. {
  86. dispatchEvent(new BatHitsEvent(BatHitsEvent.PREFERENCES_CLICK, true));
  87. }
  88. private function onToPlayerClickHandler(e:ButtonEvent): void
  89. {
  90. dispatchEvent(new BatHitsEvent(BatHitsEvent.TO_PLAYER_CLICK, true));
  91. hitsTypeToPlayer.isActive = true;
  92. hitsTypeFromPlayer.isActive = false;
  93. }
  94. private function onFromPlayerClickHandler(e:ButtonEvent): void
  95. {
  96. dispatchEvent(new BatHitsEvent(BatHitsEvent.FROM_PLAYER_CLICK, true));
  97. hitsTypeToPlayer.isActive = false;
  98. hitsTypeFromPlayer.isActive = true;
  99. }
  100. }
  101. }