TingCtrl.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_Layout:cc.Layout,
  5. m_TingItemPrefab:cc.Prefab,
  6. m_ScrollView:cc.Node,
  7. },
  8. ctor:function(){
  9. this.m_TingTipData = new Array();
  10. },
  11. GetTingTipItem:function(index){
  12. if (this.m_TingTipData[index] == null ) {
  13. //创建新节点
  14. var OptPrefab = cc.instantiate(this.m_TingItemPrefab);
  15. OptPrefab.active = true;
  16. this.m_TingTipData[this.m_TingTipData.length] = OptPrefab.getComponent('TingItem');
  17. this.m_Layout.node.addChild(OptPrefab);
  18. return this.GetTingTipItem(index);
  19. }
  20. return this.m_TingTipData[index];
  21. },
  22. SetTingTip:function(cbOutData, pData){
  23. for (var i = 0; i < this.m_TingTipData.length; i++) {
  24. this.m_TingTipData[i].node.active = false;
  25. }
  26. if (pData == null) {
  27. this.HideView();
  28. }
  29. var bShowLayout = pData != null && pData.length > 0 && cbOutData != 0;
  30. if( !bShowLayout ){
  31. this.HideView();
  32. return;
  33. }
  34. this.ShowView();
  35. var index = 0;
  36. for (var i = 0; i < pData.length; i++) {
  37. if( pData[i].cbOutCardData == cbOutData ){
  38. var item = this.GetTingTipItem(index);
  39. item.node.active = true;
  40. item.SetData(pData[i]);
  41. index++;
  42. }
  43. }
  44. if(index == 0)
  45. {
  46. this.HideView();
  47. return;
  48. }
  49. if(this.m_TingTipData[0].node.width*index>1280){
  50. this.m_Layout.parent = this.m_ScrollView;
  51. this.m_ScrollView.parent.active = true;
  52. }
  53. else{
  54. this.m_ScrollView.parent.active = false;
  55. this.m_Layout.parent = this.node;
  56. }
  57. },
  58. ShowTingTip:function(pData)
  59. {
  60. for (var i = 0; i < this.m_TingTipData.length; i++) {
  61. this.m_TingTipData[i].node.active = false;
  62. }
  63. if (pData == null)
  64. {
  65. this.HideView();
  66. return;
  67. }
  68. var bShowLayout = pData != null && pData.length > 0;
  69. if( !bShowLayout ){
  70. this.HideView();
  71. return;
  72. }
  73. this.ShowView();
  74. var index = 0;
  75. for (var i = 0; i < pData.length; i++)
  76. {
  77. var item = this.GetTingTipItem(index);
  78. item.node.active = true;
  79. item.SetData(pData[i]);
  80. index++;
  81. }
  82. if(index > 0 )
  83. {
  84. this.node.active = true;
  85. if(this.m_TingTipData[0].node.width*index>window.SCENE_WIGHT){
  86. this.m_Layout.node.parent = this.m_ScrollView;
  87. this.m_ScrollView.parent.active = true;
  88. this.m_Layout.node.x = 0;
  89. }
  90. else{
  91. this.m_ScrollView.parent.active = false;
  92. this.m_Layout.node.parent = this.node;
  93. this.m_Layout.node.x = 0;
  94. }
  95. }
  96. else
  97. {
  98. this.HideView();
  99. }
  100. },
  101. //设置可选择胡口
  102. SetSelectTingTip:function(cbOutData,pData){
  103. for (var i = 0; i < this.m_TingTipData.length; i++) {
  104. this.m_TingTipData[i].node.active = false;
  105. }
  106. if (pData == null) {
  107. this.HideView();
  108. }
  109. var bShowLayout = pData != null && pData.length > 0;
  110. if( !bShowLayout ){
  111. this.HideView();
  112. return;
  113. }
  114. this.ShowView();
  115. this.index = 0;
  116. for (var i = 0; i < pData.length; i++) {
  117. if( pData[i].cbOutCardData == cbOutData||cbOutData==null ){
  118. var item = this.GetTingTipItem(this.index);
  119. item.node.active = true;
  120. item.SetData(pData[i]);
  121. item.OnSetEnable(false);
  122. item.OnCheck(true);
  123. this.index++;
  124. }
  125. }
  126. if(this.index > 0 && this.m_TingTipData[0].node.width*this.index>1280){
  127. if(this.m_ScrollView){
  128. this.m_Layout.parent = this.m_ScrollView;
  129. this.m_ScrollView.parent.active = true;
  130. }
  131. }
  132. else{
  133. if(this.m_ScrollView)this.m_ScrollView.parent.active = false;
  134. this.m_Layout.parent = this.node;
  135. }
  136. },
  137. //获取选择的胡口
  138. GetHuKou:function(){
  139. var cbCardData = new Array();
  140. for(var i in this.m_TingTipData){
  141. var Data = this.m_TingTipData[i].GetData();
  142. if(Data){
  143. cbCardData.push(Data);
  144. }
  145. }
  146. return cbCardData;
  147. }
  148. });