PageRenderTime 164ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/com/clink/main/UserList.as

https://bitbucket.org/nidinthb/clink_virtual_classroom
ActionScript | 497 lines | 393 code | 80 blank | 24 comment | 37 complexity | d478256aeade3fab2177850f6364480c MD5 | raw file
  1. package com.clink.main
  2. {
  3. import com.clink.controllers.Controller_Dragable;
  4. import com.clink.events.SharedObjectEvent;
  5. import com.clink.events.UserListItemEvent;
  6. import com.clink.factories.Factory_prettyBox;
  7. import com.clink.factories.Factory_triangle;
  8. import com.clink.managers.Manager_remoteCommonSharedObject;
  9. import com.clink.managers.Manager_remoteUserSharedObject;
  10. import com.clink.ui.LayoutBox;
  11. import com.clink.ui.ScrollList;
  12. import com.clink.ui.SortingScrollList;
  13. import com.clink.ui.UserListButton;
  14. import com.clink.ui.UserListItem;
  15. import com.clink.utils.DrawingUtils;
  16. import com.clink.valueObjects.VO_Settings;
  17. import flash.display.DisplayObject;
  18. import flash.display.DisplayObjectContainer;
  19. import flash.display.Sprite;
  20. import flash.events.MouseEvent;
  21. import flash.geom.Orientation3D;
  22. import flash.geom.Point;
  23. import org.osmf.net.StreamingURLResource;
  24. import org.osmf.proxies.ListenerProxyElement;
  25. [Event(name="breakOut", type="com.clink.events.UserListItemEvent")]
  26. [Event(name="breakIn", type="com.clink.events.UserListItemEvent")]
  27. public class UserList extends Sprite
  28. {
  29. private var _configInfo:VO_Settings;
  30. private var _userSO:Manager_remoteUserSharedObject;
  31. private var _btnLB:LayoutBox;
  32. private var _mainLB:LayoutBox;
  33. private var _awayBtn:UserListButton;
  34. private var _bg:Sprite;
  35. private var _btn_handRaised:UserListButton;
  36. private var _originalX:Number;
  37. private var _originalY:Number;
  38. private var _breakOutBtn:Sprite;
  39. private var _userScrollList:SortingScrollList;
  40. private var _usernameList:Array;
  41. private var _listItemList:Array;
  42. private var _isHandRaised:Boolean;
  43. private var _isThumbUp:Boolean;
  44. private var _isThumbDown:Boolean;
  45. private var _isLaughing:Boolean;
  46. private var _isAway:Boolean;
  47. private var _originalParent:DisplayObjectContainer;
  48. private var _originalHeight:Number;
  49. private var _userListDragger:Controller_Dragable;
  50. public function UserList(configInfo:VO_Settings, userSO:Manager_remoteUserSharedObject)
  51. {
  52. super();
  53. _configInfo = configInfo;
  54. _userSO = userSO;
  55. init();
  56. }
  57. private function init():void
  58. {
  59. UserListItem.init();
  60. _isHandRaised = false;
  61. _isThumbUp = false;
  62. _isThumbDown = false;
  63. _isLaughing = false;
  64. _isAway = false;
  65. _listItemList = [];
  66. _originalX = this.x;
  67. _originalY = this.y;
  68. UserListButton.init(_configInfo.userListButton_upStateColor,_configInfo.userListButton_downStateColor,_configInfo.userListButton_overStateColor);
  69. UserListButton.isGradient = _configInfo.userListButton_isGradient;
  70. //add event listners to the sharedObject
  71. _userSO.addEventListener(SharedObjectEvent.CHANGED,onSoChanged);
  72. _userSO.addEventListener(SharedObjectEvent.CLIENT_CHANGED,onSoChanged);
  73. _userSO.addEventListener(SharedObjectEvent.CONNECTED,onSoConnected);
  74. _userSO.addEventListener(SharedObjectEvent.DELETED,onSoDelete);
  75. drawUI();
  76. }
  77. private function drawBg(height:Number):void
  78. {
  79. if(_bg)
  80. {
  81. this.removeChild(_bg);
  82. _bg = null;
  83. }
  84. _bg = Factory_prettyBox.drawPrettyBox(232,height,uint(DrawingUtils.fixColorCode(_configInfo.userList_backgroundColor)),0,_configInfo.userList_backgroundIsGradient);
  85. this.addChildAt(_bg,0);
  86. }
  87. private function drawUI():void
  88. {
  89. //draw bg
  90. _originalHeight = 206;
  91. drawBg(_originalHeight);
  92. //draw header handle
  93. var header:Sprite = Factory_prettyBox.drawPrettyBox(232,16, uint(DrawingUtils.fixColorCode(_configInfo.userList_headerColor)),0,_configInfo.userList_headerIsGradient);
  94. this.addChild(header);
  95. //add the drag controller than disable it until its ready to be used
  96. _userListDragger = new Controller_Dragable(this,header);
  97. _userListDragger.disable();
  98. //draw arrow button for panel breakout
  99. _breakOutBtn = new Sprite();
  100. _breakOutBtn.graphics.beginFill(uint(DrawingUtils.fixColorCode(_configInfo.userList_headerArrowColor)));
  101. _breakOutBtn.graphics.drawRect(0,0,7,4);
  102. _breakOutBtn.graphics.endFill();
  103. //for transparent hitbox
  104. _breakOutBtn.graphics.beginFill(0xffffff,0);
  105. _breakOutBtn.graphics.drawRect(-6,-6,16,16);
  106. _breakOutBtn.graphics.endFill();
  107. var arrowHead:Sprite = Factory_triangle.drawEqTriangle(11,5,uint(DrawingUtils.fixColorCode(_configInfo.userList_headerArrowColor)),"left",false);
  108. arrowHead.x = -2;
  109. arrowHead.y = 2;
  110. _breakOutBtn.addChild(arrowHead);
  111. _breakOutBtn.x = 10;
  112. _breakOutBtn.y = 6;
  113. header.addChild(_breakOutBtn);
  114. _breakOutBtn.buttonMode = true;
  115. _breakOutBtn.mouseChildren = false;
  116. _breakOutBtn.addEventListener(MouseEvent.CLICK,unDockPanel);
  117. //add and position main layout box
  118. _mainLB = new LayoutBox(false,6);
  119. _mainLB.x = 6;
  120. _mainLB.y = header.height+6;
  121. this.addChild(_mainLB);
  122. //user scroll list;
  123. _userScrollList = new SortingScrollList(186,177,_configInfo.userList_scrollListBackgroundColor);
  124. _mainLB.addChild(_userScrollList);
  125. //btn group
  126. _btnLB = new LayoutBox();
  127. //raiseHandButton
  128. _btn_handRaised = new UserListButton(28,28,true);
  129. _btn_handRaised.upIcon = _configInfo.raiseHandBtn_upIcon;
  130. _btn_handRaised.downIcon = _configInfo.raiseHandBtn_downIcon;
  131. _btn_handRaised.overIcon = _configInfo.raiseHandBtn_overIcon;
  132. _btn_handRaised.enableToggle();
  133. _btn_handRaised.message = _configInfo.raiseHandBtn_toolTip;
  134. _btn_handRaised.addEventListener(MouseEvent.CLICK,onRaiseHand);
  135. _btnLB.addChild(_btn_handRaised);
  136. //thumbUpButton
  137. var tu:UserListButton = new UserListButton(28,28,true);
  138. tu.upIcon = _configInfo.thumbUpBtn_upIcon;
  139. tu.downIcon = _configInfo.thumbUpBtn_downIcon;
  140. tu.overIcon = _configInfo.thumbUpBtn_overIcon;
  141. tu.message = _configInfo.thumbUpBtn_toolTip;
  142. tu.addEventListener(MouseEvent.CLICK,onThumbUp);
  143. _btnLB.addChild(tu);
  144. //thumbDownButton
  145. var td:UserListButton = new UserListButton(28,28,true);
  146. td.upIcon = _configInfo.thumbDownBtn_upIcon;
  147. td.downIcon = _configInfo.thumbDownBtn_downIcon;
  148. td.overIcon = _configInfo.thumbDownBtn_overIcon;
  149. td.message = _configInfo.thumbDownBtn_toolTip;
  150. td.addEventListener(MouseEvent.CLICK,onThumbDown);
  151. _btnLB.addChild(td);
  152. //laughingButton
  153. var la:UserListButton = new UserListButton(28,28,true);
  154. la.upIcon = _configInfo.laughBtn_upIcon;
  155. la.downIcon = _configInfo.laughBtn_downIcon;
  156. la.overIcon = _configInfo.laughBtn_overIcon;
  157. la.message = _configInfo.laughBtn_toolTip;
  158. la.addEventListener(MouseEvent.CLICK,onLaugh);
  159. _btnLB.addChild(la);
  160. //awayButton
  161. _awayBtn = new UserListButton(28,28,true);
  162. _awayBtn.upIcon = _configInfo.awayBtn_upIcon;
  163. _awayBtn.downIcon = _configInfo.awayBtn_downIcon;
  164. _awayBtn.overIcon = _configInfo.awayBtn_overIcon;
  165. _awayBtn.message = _configInfo.awayBtn_toolTip;
  166. _awayBtn.addEventListener(MouseEvent.CLICK,onAway);
  167. _awayBtn.enableToggle();
  168. _btnLB.addChild(_awayBtn);
  169. _mainLB.addChild(_btnLB);
  170. }
  171. private function populateList(slot:int):void
  172. {
  173. var username:String = _userSO.getProperty("username",slot) as String;
  174. var permission:String = _userSO.getProperty("userPermission",slot) as String
  175. //remove the slot.toString() back to only username after testing is complete
  176. var uli:UserListItem = new UserListItem(username/* +slot.toString()*/,_configInfo,_userSO,_configInfo.userPermission,slot,true);
  177. //create the label using the username and slot number so we always have a unique label
  178. _userScrollList.addListItem(uli,username + slot.toString());
  179. _userScrollList.update();
  180. }
  181. private function findItem(slot:int):UserListItem
  182. {
  183. for each(var obj:Object in _userScrollList.items)
  184. {
  185. if(obj["item"].userID == slot)
  186. {
  187. return obj["item"];
  188. break;
  189. }
  190. }
  191. for each(var item:UserListItem in _userScrollList.topItems)
  192. {
  193. if(item.userID == slot)
  194. {
  195. return item;
  196. break;
  197. }
  198. }
  199. return null;
  200. }
  201. private function removeFromSort(slot:String):void
  202. {
  203. for(var i:int = 0; i < _userScrollList.items.length; i++)
  204. {
  205. if(_userScrollList.items[i]["item"].userID == slot)
  206. {
  207. _userScrollList.removeListItem(_userScrollList.items[i]["item"],_userScrollList.items[i]["label"]);
  208. break;
  209. }
  210. }
  211. _userScrollList.update();
  212. }
  213. private function removeFromTop(slot:String):void
  214. {
  215. for each(var k:UserListItem in _userScrollList.topItems)
  216. {
  217. if(k.userID == int(slot))
  218. {
  219. _userScrollList.removeTopItem(k);
  220. }
  221. }
  222. _userScrollList.update();
  223. }
  224. private function raiseHandOrganize(slot:String):void
  225. {
  226. var handRaisedItem:UserListItem = findItem(int(slot))
  227. handRaisedItem.raiseHandEnable();
  228. removeFromSort(slot);
  229. _userScrollList.addTopItem(handRaisedItem);
  230. _userScrollList.update();
  231. }
  232. private function isAway(isAway:Boolean):void
  233. {
  234. if(isAway)
  235. {
  236. _userSO.setProperty("isAway",true);
  237. _isAway = true;
  238. _awayBtn.down();
  239. }else{
  240. _userSO.setProperty("isAway",false);
  241. _isAway = false;
  242. _awayBtn.up();
  243. }
  244. }
  245. //////////////////////////CallBacks////////////////////////////
  246. //header arrow button is clicked
  247. private function unDockPanel(e:MouseEvent):void
  248. {
  249. if(this.parent != this.stage)
  250. {
  251. _originalParent = this.parent;
  252. _originalX = this.x;
  253. _originalY = this.y;
  254. this.stage.addChild(this);
  255. this.x = _originalParent.x - this.width - 10;
  256. this.y = _originalParent.y;
  257. drawBg(605);
  258. _breakOutBtn.rotation = 180;
  259. _breakOutBtn.y += 4;
  260. _userScrollList.height = 575;
  261. _userListDragger.enable();
  262. _userScrollList.update();
  263. this.dispatchEvent(new UserListItemEvent(UserListItemEvent.BREAK_OUT));
  264. }else{
  265. _originalParent.addChildAt(this,1);
  266. this.x = _originalX;
  267. this.y = _originalY;
  268. _breakOutBtn.rotation = 0;
  269. _breakOutBtn.y-= 4;
  270. _userScrollList.height = 177;
  271. _userListDragger.disable();
  272. drawBg(_originalHeight);
  273. _userScrollList.update();
  274. this.dispatchEvent(new UserListItemEvent(UserListItemEvent.BREAK_IN));
  275. }
  276. }
  277. //thumbDown button pressed
  278. private function onLaugh(e:MouseEvent):void
  279. {
  280. isAway(false);
  281. if(_isLaughing == false)
  282. {
  283. _userSO.setProperty("isLaughing",true);
  284. }
  285. }
  286. //thumbDown button pressed
  287. private function onThumbDown(e:MouseEvent):void
  288. {
  289. isAway(false);
  290. if(_isThumbDown == false)
  291. {
  292. _userSO.setProperty("isThumbDown",true);
  293. }
  294. }
  295. //thumbUp button pressed
  296. private function onThumbUp(e:MouseEvent):void
  297. {
  298. isAway(false);
  299. if(_isThumbUp == false)
  300. {
  301. _userSO.setProperty("isThumbUp",true);
  302. }
  303. }
  304. //raised hand button pressed
  305. private function onRaiseHand(e:MouseEvent):void
  306. {
  307. isAway(false);
  308. if(_isHandRaised)
  309. {
  310. _userSO.setProperty("isHandRaised",false);
  311. _isHandRaised = false;
  312. }else{
  313. _userSO.setProperty("isHandRaised",true);
  314. _isHandRaised = true;
  315. }
  316. }
  317. private function onAway(e:MouseEvent):void
  318. {
  319. if(_isAway)
  320. {
  321. _userSO.setProperty("isAway",false);
  322. _isAway = false;
  323. }else{
  324. _userSO.setProperty("isAway",true);
  325. _isAway = true;
  326. _userSO.setProperty("isHandRaised",false);
  327. _isHandRaised = false;
  328. _btn_handRaised.up();
  329. }
  330. }
  331. private function onSoChanged(e:SharedObjectEvent):void
  332. {
  333. switch(e.propertyName)
  334. {
  335. case "connected":
  336. if(e.propertyValue == true && e.sharedObjectSlot != (_configInfo.userID).toString())
  337. {
  338. if(_userSO.sharedObject.data[e.sharedObjectSlot]["isHandRaised"])
  339. {
  340. raiseHandOrganize(e.sharedObjectSlot);
  341. }else{
  342. populateList(int(e.sharedObjectSlot));
  343. }
  344. }
  345. break;
  346. case "isHandRaised":
  347. if(e.propertyValue)
  348. {//true
  349. raiseHandOrganize(e.sharedObjectSlot);
  350. }else{//false
  351. removeFromTop(e.sharedObjectSlot);
  352. populateList(int(e.sharedObjectSlot));
  353. _userScrollList.update();
  354. }
  355. break;
  356. case "isThumbUp":
  357. if(e.propertyValue)
  358. {//true
  359. _isThumbUp = true;
  360. findItem(int(e.sharedObjectSlot)).thumbUp(int(e.sharedObjectSlot));
  361. }else{//false
  362. _isThumbUp = false;
  363. }
  364. break;
  365. case "isThumbDown":
  366. if(e.propertyValue)
  367. {//true
  368. _isThumbDown = true;
  369. findItem(int(e.sharedObjectSlot)).thumbDown(int(e.sharedObjectSlot));
  370. }else{//false
  371. _isThumbDown = false;
  372. }
  373. break;
  374. case "isLaughing":
  375. if(e.propertyValue)
  376. {//true
  377. _isLaughing = true;
  378. findItem(int(e.sharedObjectSlot)).laugh(int(e.sharedObjectSlot));
  379. }else{//false
  380. _isLaughing = false;
  381. }
  382. break;
  383. case "isAway":
  384. if(e.propertyValue)
  385. {//true
  386. findItem(int(e.sharedObjectSlot)).awayEnable();
  387. }else{//false
  388. findItem(int(e.sharedObjectSlot)).awayDisable();
  389. }
  390. break;
  391. case "isTalking":
  392. findItem(int(e.sharedObjectSlot)).talking();
  393. break;
  394. }
  395. }
  396. private function onSoConnected(e:SharedObjectEvent):void
  397. {
  398. var data:Object = _userSO.sharedObject.data;
  399. for(var k:String in data)
  400. {
  401. //add to the list
  402. populateList(int(k));
  403. //check if any have their hands raised
  404. if(data[k]["isHandRaised"] == true)
  405. {
  406. raiseHandOrganize(k);
  407. }
  408. }
  409. _userSO.setProperty("connected",true);
  410. }
  411. private function onSoDelete(e:SharedObjectEvent):void
  412. {
  413. removeFromSort(e.sharedObjectSlot);
  414. removeFromTop(e.sharedObjectSlot);
  415. }
  416. }
  417. }