UIShop.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import UIBase from "../fgui/core/UIBase";
  2. import ui_BallRodDisplay from "../fgui/res/game/ui_BallRodDisplay";
  3. import ui_daoJuDisplay from "../fgui/res/game/ui_daoJuDisplay";
  4. import ui_UIShop from "../fgui/res/game/ui_UIShop";
  5. import { xGame } from "../xGame";
  6. import BallRodDisplay from "./item/BallRodDisplay";
  7. import DaoJuDisplay from "./item/DaoJuDisplay";
  8. import MoneyNode from "./item/MoneyNode";
  9. export default class UIShop extends UIBase {
  10. protected ui: ui_UIShop;
  11. public moneyNode: MoneyNode;
  12. public ballRodArr: Array<BallRodDisplay>;
  13. public daoJuArr: Array<DaoJuDisplay>;
  14. public itemNums: number = 0;
  15. public itemNumsForDj: number = 0;
  16. public curType: string = "";
  17. public constructor() {
  18. super();
  19. }
  20. protected onConstructor(): void {
  21. this.ui = ui_UIShop.createInstance();
  22. this.contentPane = this.ui;
  23. this.isEject = false;
  24. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  25. //
  26. this.addUIClick(this.ui.closeNode.closeBtn, this.closeSelf);
  27. this.addUIClick(this.ui.myNode.n_qiuGan, () => this.switchBtn("qiugan"));
  28. this.addUIClick(this.ui.myNode.n_daoju, () => this.switchBtn("daoju"));
  29. // this.addUIClick(this.ui.btn_qiugan, this.test123);
  30. // this.addUIClick(this.ui.btn_daoju, this.test123);
  31. this.addUIClick(this.ui, this.interuptSecretary);
  32. // console.log('zh:this.renderBallRodthis.renderBallRodthis.renderBallRodthis.renderBallRod = ' + this.renderBallRod)
  33. this.ui.myNode.myList.itemRenderer = Laya.Handler.create(this, this.renderBallRod, null, false);
  34. this.ballRodArr = [];
  35. this.itemNums = Object.keys(cfgTable.ballrodData).length;
  36. this.ui.myNode.myList.numItems = this.itemNums;
  37. // if (Moyu.isKs)
  38. // this.ui.closeNode.closeBtn.x += 100;
  39. //道具数据----------------start
  40. this.ui.myNode.djList.itemRenderer = Laya.Handler.create(this, this.renderDaoJu, null, false);
  41. this.daoJuArr = [];
  42. this.itemNumsForDj = Object.keys(cfgTable.daoJuData).length;
  43. this.ui.myNode.djList.numItems = this.itemNumsForDj;
  44. //道具数据----------------end
  45. }
  46. public show(type): void {
  47. super.show();
  48. console.log('zh:show type = ' + type)
  49. //type,0-球杆,1-道具
  50. this.curType = type == 0 ? "qiugan" : "daoju";
  51. this.switchBtn("qiugan");
  52. this.playSecretaryIdle();
  53. this.updateBallRod();
  54. }
  55. test123() {
  56. console.log('zh:test123 ')
  57. }
  58. switchBtn(type: string) {
  59. console.log('zh:1111切換 sel type=' + type)
  60. if (type == "") {
  61. type = this.curType;
  62. }
  63. else {
  64. if (this.curType == type) {
  65. return;
  66. }
  67. else {
  68. this.curType = type;
  69. }
  70. }
  71. if (type == "qiugan") {
  72. this.ui.myNode.n_qiuGan.c1.selectedIndex = 0;
  73. this.ui.myNode.n_daoju.c1.selectedIndex = 1;
  74. this.ui.myNode.myList.visible = true;
  75. this.ui.myNode.djList.visible = false;
  76. }
  77. else {
  78. this.ui.myNode.n_qiuGan.c1.selectedIndex = 1;
  79. this.ui.myNode.n_daoju.c1.selectedIndex = 0;
  80. this.ui.myNode.myList.visible = false;
  81. this.ui.myNode.djList.visible = true;
  82. }
  83. }
  84. updateBallRod() {
  85. for (let index = 0; index < this.ballRodArr.length; index++) {
  86. this.ballRodArr[index].updateSelf();
  87. }
  88. }
  89. renderBallRod(sort, obj: ui_BallRodDisplay) {
  90. let index = this.getIndexBySort(sort + 1) - 1;
  91. let ballRod = new BallRodDisplay(obj, index);
  92. this.ballRodArr.push(ballRod);
  93. }
  94. renderDaoJu(sort, obj: ui_daoJuDisplay) {
  95. let index = this.getIndexBySortForDj(sort + 1) - 1;
  96. let b = new DaoJuDisplay(obj, index);
  97. this.daoJuArr.push(b);
  98. }
  99. getIndexBySort(sort) {
  100. let object = cfgTable.ballrodData;
  101. for (const key in object) {
  102. if (object[key].sort == sort) {
  103. return parseInt(key);
  104. }
  105. }
  106. }
  107. getIndexBySortForDj(sort) {
  108. let object = cfgTable.daoJuData;
  109. for (const key in object) {
  110. if (object[key].sort == sort) {
  111. return parseInt(key);
  112. }
  113. }
  114. }
  115. playSecretaryIdle() {
  116. let parent = this.ui.secretary.displayObject;
  117. parent.destroyChildren();
  118. let xx = this.ui.secretary.width / 2
  119. let yy = this.ui.secretary.height;
  120. let scale = xGame.common.getSecretaryScale();
  121. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  122. // xGame.common.secretary.play(data, 1, true, parent);
  123. xGame.common.secretary.play(data, 0, true, parent);
  124. }
  125. interuptSecretary() {
  126. Laya.timer.clearAll(this);
  127. this.playSecretaryRandomSound();
  128. }
  129. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  130. playSecretaryRandomSound() {
  131. if (this.isHide) return;
  132. let time = xGame.common.randomNum(45000, 60000);
  133. Laya.timer.once(time, this, () => {
  134. if (this.isHide) return;
  135. let index = xGame.common.randomNum(4, 7);
  136. xGame.soundMgr.playSound("s_main0" + index);
  137. let words = 1;
  138. switch (index) {
  139. case 4:
  140. words = 5;
  141. break;
  142. case 5:
  143. words = 3;
  144. break;
  145. case 6:
  146. words = 6;
  147. break;
  148. case 7:
  149. words = 7;
  150. break;
  151. default:
  152. break;
  153. }
  154. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  155. //
  156. this.playSecretaryRandomSound();
  157. })
  158. }
  159. closeSelf() {
  160. this.hide();
  161. }
  162. }
  163. UIShop.uiName = "UIShop";