BlockListScreen.as 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import flash.external.*;
  2. import gfx.controls.TextInput;
  3. import gfx.controls.Button;
  4. import gfx.controls.ScrollBar;
  5. import mx.utils.Delegate;
  6. class Screens.BlockListScreen extends ScreenWithPageNavigator
  7. {
  8. private var ignoreUsernameEditBox:TextInput;
  9. private var startIgnoreButton:Button;
  10. private var btnBack:Button;
  11. private var tfUsername:TextField;
  12. private var mcProfileImage:MovieClip;
  13. private var mcScrollBar:ScrollBar
  14. private var mIsWaitingForResponseFromServer:Boolean; //true when user hit ignore or stop ignore to wait for server to verify the action
  15. private var mUsernameOnHold:String;
  16. public function BlockListScreen()
  17. {
  18. ConsoleWindow.Trace("Constructing BlockListScreen");
  19. mScreenId = ScreenID.BLOCK_LIST;
  20. mScreenTabId = ScreenTab.ID_PROFILE;
  21. mIsWaitingForResponseFromServer = false;
  22. mEntriesPerPage = 10;
  23. mFirstEntryX = 440;
  24. mFirstEntryY = -245;
  25. mDeltaY = 10;
  26. }
  27. public function VOnFinishedLoading():Void
  28. {
  29. //Add click event for buttons
  30. startIgnoreButton.addEventListener("click", this, "f2c_StartIgnore");
  31. //stopIgnoreButton.addEventListener("click", this, "f2c_StopIgnore");
  32. btnBack.addEventListener("click", this, "Back");
  33. mcScrollBar.addEventListener("scroll", this, "OnScroll");
  34. //Add callbacks for C++
  35. ExternalInterface.addCallback("c2f_StartIgnore", this, c2f_StartIgnore);
  36. ExternalInterface.addCallback("c2f_StopIgnore", this, c2f_StopIgnore);
  37. ExternalInterface.addCallback("c2f_GetIgnoreListResult", this, c2f_GetIgnoreListResult);
  38. super.VOnFinishedLoading();
  39. }
  40. public function OnShow():Void
  41. {
  42. super.OnShow();
  43. if ( !mcProfileImage.mcImageContainer.mcImage )
  44. {
  45. var imageIndex:Number = LobbyInterface.Instance.GetProfileImageIndex();
  46. mcProfileImage.attachMovie( "ProfileImage" + imageIndex, "mcImage", mcProfileImage.getNextHighestDepth() );
  47. }
  48. tfUsername.text = LobbyInterface.Instance.GetUsername();
  49. //ConsoleWindow.Trace("blocked user list length = " + mMovieClipList.length);
  50. if ( mMovieClipList.length > 0 )
  51. {
  52. CleanUpMoveClipList( mMovieClipList );
  53. }
  54. mMovieClipList = new Array();
  55. mCurrentPage = 0;
  56. GoToPage( 1 );
  57. f2c_GetIgnoreList();
  58. mIsWaitingForResponseFromServer = false;
  59. }
  60. public function OnScroll( position:Number ):Void
  61. {
  62. ConsoleWindow.Trace("scrolling pos: " + position);
  63. }
  64. public function Back():Void
  65. {
  66. LobbyInterface.Instance.ShowScreen( ScreenID.PROFILE );
  67. }
  68. public function f2c_StartIgnore():Void
  69. {
  70. if ( !mIsWaitingForResponseFromServer )
  71. {
  72. mIsWaitingForResponseFromServer = true;
  73. ExternalInterface.call("f2c_StartIgnore", ignoreUsernameEditBox.text);
  74. mUsernameOnHold = ignoreUsernameEditBox.text;
  75. }
  76. }
  77. public function c2f_StartIgnore(resultIdentifier:String):Void
  78. {
  79. switch (resultIdentifier)
  80. {
  81. case "Client_StartIgnore_UNKNOWN_TARGET_HANDLE":
  82. //ConsoleWindow.Trace("Client_StartIgnore_UNKNOWN_TARGET_HANDLE");
  83. break;
  84. case "Client_StartIgnore_CANNOT_PERFORM_ON_SELF":
  85. //ConsoleWindow.Trace("Client_StartIgnore_CANNOT_PERFORM_ON_SELF");
  86. break;
  87. case "Client_StartIgnore_ALREADY_IGNORED":
  88. //ConsoleWindow.Trace("Client_StartIgnore_ALREADY_IGNORED");
  89. break;
  90. case "SUCCESS":
  91. ConsoleWindow.Trace("start ignore SUCCESS");
  92. //IgnoreUser( mUsernameOnHold, 1 ); //TODO: uncomment this
  93. break;
  94. }
  95. mIsWaitingForResponseFromServer = false;
  96. //IgnoreUser( mUsernameOnHold, 1 ); //TODO: comment this out
  97. if ( resultIdentifier != "SUCCESS" )
  98. {
  99. LobbyInterface.Instance.CreateMessageBox( resultIdentifier );
  100. }
  101. }
  102. public function StopIgnore( blockedUserEntry:MovieClip ):Void
  103. {
  104. ConsoleWindow.Trace("StopIgnore: " + blockedUserEntry);
  105. f2c_StopIgnore( blockedUserEntry.tfUsername.text );
  106. RemoveEntryFromList( blockedUserEntry, mMovieClipList );
  107. }
  108. public function f2c_StopIgnore( _username:String ):Void
  109. {
  110. if ( !mIsWaitingForResponseFromServer )
  111. {
  112. ExternalInterface.call("f2c_StopIgnore", _username);
  113. }
  114. }
  115. public function c2f_StopIgnore(resultIdentifier:String):Void
  116. {
  117. switch (resultIdentifier)
  118. {
  119. case "Client_StopIgnore_UNKNOWN_TARGET_HANDLE":
  120. //ConsoleWindow.Trace("Client_StopIgnore_UNKNOWN_TARGET_HANDLE");
  121. break;
  122. case "Client_StopIgnore_CANNOT_PERFORM_ON_SELF":
  123. //ConsoleWindow.Trace("Client_StopIgnore_CANNOT_PERFORM_ON_SELF");
  124. break;
  125. case "SUCCESS":
  126. //ConsoleWindow.Trace("stop ignore success");
  127. break;
  128. }
  129. mIsWaitingForResponseFromServer = false;
  130. if ( resultIdentifier != "SUCCESS" )
  131. {
  132. LobbyInterface.Instance.CreateMessageBox( resultIdentifier );
  133. }
  134. }
  135. public function f2c_GetIgnoreList():Void
  136. {
  137. ExternalInterface.call("f2c_GetIgnoreList");
  138. }
  139. public function c2f_GetIgnoreListResult():Void
  140. {
  141. ConsoleWindow.Trace("c2f_GetIgnoreListResult...");
  142. for (var i:Number = 0; i < arguments.length; i++)
  143. {
  144. // Array of handles (string)
  145. ConsoleWindow.Trace(arguments[i]);
  146. }
  147. //TODO: remove this once c++ sends down proper data
  148. for ( var n:Number = 0; n < 25; n++ )
  149. {
  150. /*var userEntry:MovieClip = attachMovie("BlockListEntry", "blockedUser" + mMovieClipList.length, getNextHighestDepth() );
  151. userEntry._visible = false;
  152. userEntry.tfUsername.text = "testUser" + mMovieClipList.length;
  153. mMovieClipList.push( userEntry );
  154. var self:BlockListScreen = this;
  155. userEntry.mcDelete.onPress = function() { self.StopIgnore( this._parent ); }*/
  156. AddBlockListEntry( "testUser" + mMovieClipList.length );
  157. }
  158. OnMoveClipListUpdated();
  159. ShowPage(1);
  160. }
  161. public function IgnoreUser( _username:String, _profileImageIndex:Number ):Void
  162. {
  163. /* var userEntry:MovieClip = attachMovie("BlockListEntry", "blockedUser" + mMovieClipList.length, getNextHighestDepth() );
  164. userEntry._visible = false;
  165. userEntry.tfUsername.text = _username;
  166. mMovieClipList.push( userEntry );
  167. var self:BlockListScreen = this;
  168. userEntry.mcDelete.onPress = function() { self.StopIgnore( this._parent ); }*/
  169. AddBlockListEntry( _username );
  170. TogglePageVisibility(mCurrentPage, true );
  171. OnMoveClipListUpdated();
  172. }
  173. public function AddBlockListEntry( _username:String ):Void
  174. {
  175. var userEntry:MovieClip = attachMovie("BlockListEntry", "blockedUser" + mMovieClipList.length, getNextHighestDepth() );
  176. userEntry._visible = false;
  177. userEntry.tfUsername.text = _username;
  178. mMovieClipList.push( userEntry );
  179. ConsoleWindow.Trace("Ignoring user: " + userEntry);
  180. var self:BlockListScreen = this;
  181. userEntry.mcDelete.onPress = function() { self.StopIgnore( this._parent ); }
  182. }
  183. private function OnShowMovieClipEntry( mcEntry:MovieClip, index:Number ):Void
  184. {
  185. //ConsoleWindow.Trace("BlockList... OnShowMovieClipEntry: " + mcEntry.mcDelete.onPress);
  186. super.OnShowMovieClipEntry( mcEntry, index );
  187. }
  188. private function OnHideMovieClipEntry( mcEntry:MovieClip ):Void
  189. {
  190. //ConsoleWindow.Trace("BlockList... OnHideMovieClipEntry: " + mcEntry.mcDelete.onPress );
  191. mcEntry.mcDelete.onPress = null;
  192. }
  193. }
粤ICP备19079148号