UIShop.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. import UIMsg from "../ui/UIMsg";
  10. export default class UIShop extends UIBase {
  11. protected ui: ui_UIShop;
  12. public moneyNode: MoneyNode;
  13. public ballRodArr: Array<BallRodDisplay>;
  14. public daoJuArr: Array<DaoJuDisplay>;
  15. public itemNums: number = 0;
  16. public itemNumsForDj: number = 0;
  17. public curType: string = "";
  18. public constructor() {
  19. super();
  20. }
  21. protected onConstructor(): void {
  22. this.ui = ui_UIShop.createInstance();
  23. this.contentPane = this.ui;
  24. this.isEject = false;
  25. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  26. //
  27. this.addUIClick(this.ui.closeNode.closeBtn, this.closeSelf);
  28. this.addUIClick(this.ui.myNode.n_qiuGan, () => this.switchBtn("qiugan"));
  29. this.addUIClick(this.ui.myNode.n_daoju, () => this.switchBtn("daoju"));
  30. // this.addUIClick(this.ui.btn_qiugan, this.test123);
  31. this.addUIClick(this.ui, this.interuptSecretary);
  32. this.ui.myNode.myList.itemRenderer = Laya.Handler.create(this, this.renderBallRod, null, false);
  33. this.ballRodArr = [];
  34. this.itemNums = Object.keys(cfgTable.ballrodData).length;
  35. this.ui.myNode.myList.numItems = this.itemNums;
  36. // if (Moyu.isKs)
  37. // this.ui.closeNode.closeBtn.x += 100;
  38. this.loadDjdata_old();
  39. //this.getProductList();
  40. }
  41. private loadDjdata_old() {
  42. //道具数据----------------start
  43. let fff = cfgTable.daoJuData;
  44. // console.log('zh:fff=' + JSON.stringify(fff));
  45. //{"1":{"id":1,"spbt":"Gem50","spjg":0.99,"spms":"Gem50","img":"sp_zs1","sort":1},"2":{"id":1,"spbt":"Gem100","spjg":1.99,"spms":"Gem100","img":"sp_zs2","sort":2},"3":{"id":1,"spbt":"Gem150","spjg":3.99,"spms":"Gem150","img":"sp_zs3","sort":3}}
  46. this.ui.myNode.djList.itemRenderer = Laya.Handler.create(this, this.renderDaoJu, null, false);
  47. this.daoJuArr = [];
  48. this.itemNumsForDj = Object.keys(cfgTable.daoJuData).length;
  49. this.ui.myNode.djList.numItems = this.itemNumsForDj;
  50. //道具数据----------------end
  51. }
  52. public getProductList() {
  53. let reqData = xGame.httpMgr.getReqData();
  54. // 解析JSON字符串为JavaScript对象
  55. let pd: any = JSON.parse(reqData);
  56. pd.splx = "Consumable";//商城商品类型
  57. reqData = JSON.stringify(pd);
  58. xGame.httpMgr.sendPost2025('getProductList', reqData, (res) => {
  59. try {
  60. // console.log('zh:res = ' + JSON.stringify(res))
  61. let code = res.code;
  62. let msg = res.msg;
  63. if (code == 200) {
  64. let data = res.data;
  65. for (let index = 0; index < data.length; index++) {
  66. let element = data[index];
  67. cfgTable.daoJuData[element.spid] = element;
  68. }
  69. console.log("fffddd="+JSON.stringify(cfgTable.daoJuData))
  70. } else {
  71. xGame.uiMgr.Show(UIMsg, msg)
  72. }
  73. } catch (error) {
  74. console.log('error=' + error);
  75. alert(error);
  76. } finally {
  77. }
  78. });
  79. }
  80. public show(type): void {
  81. super.show();
  82. //type,0-球杆,1-道具
  83. this.curType = type == 0 ? "qiugan" : "daoju";
  84. this.switchBtn("qiugan");
  85. this.playSecretaryIdle();
  86. this.updateBallRod();
  87. }
  88. test123() {
  89. console.log('zh:test123 ')
  90. }
  91. switchBtn(type: string) {
  92. console.log('zh:1111切換 sel type=' + type)
  93. if (type == "") {
  94. type = this.curType;
  95. }
  96. else {
  97. if (this.curType == type) {
  98. return;
  99. }
  100. else {
  101. this.curType = type;
  102. }
  103. }
  104. if (type == "qiugan") {
  105. this.ui.myNode.n_qiuGan.c1.selectedIndex = 0;
  106. this.ui.myNode.n_daoju.c1.selectedIndex = 1;
  107. this.ui.myNode.c1.selectedIndex = 0;
  108. this.ui.myNode.myList.visible = true;
  109. this.ui.myNode.djList.visible = false;
  110. }
  111. else {
  112. this.ui.myNode.n_qiuGan.c1.selectedIndex = 1;
  113. this.ui.myNode.n_daoju.c1.selectedIndex = 0;
  114. this.ui.myNode.c1.selectedIndex = 1;
  115. this.ui.myNode.myList.visible = false;
  116. this.ui.myNode.djList.visible = true;
  117. }
  118. }
  119. updateBallRod() {
  120. for (let index = 0; index < this.ballRodArr.length; index++) {
  121. this.ballRodArr[index].updateSelf();
  122. }
  123. }
  124. renderBallRod(sort, obj: ui_BallRodDisplay) {
  125. let index = this.getIndexBySort(sort + 1) - 1;
  126. let ballRod = new BallRodDisplay(obj, index);
  127. this.ballRodArr.push(ballRod);
  128. }
  129. renderDaoJu(idx, obj: ui_daoJuDisplay) {
  130. let index = this.getIndexBySortForDj(idx + 1) - 1;
  131. let b = new DaoJuDisplay(obj, index);
  132. this.daoJuArr.push(b);
  133. }
  134. getIndexBySort(sort) {
  135. let object = cfgTable.ballrodData;
  136. for (const key in object) {
  137. if (object[key].sort == sort) {
  138. return parseInt(key);
  139. }
  140. }
  141. }
  142. getIndexBySortForDj(idx) {
  143. let object = cfgTable.daoJuData;
  144. for (const key in object) {
  145. if (object[key].idx == idx) {
  146. return parseInt(key);
  147. }
  148. }
  149. }
  150. playSecretaryIdle() {
  151. let parent = this.ui.secretary.displayObject;
  152. parent.destroyChildren();
  153. let xx = this.ui.secretary.width / 2
  154. let yy = this.ui.secretary.height;
  155. let scale = xGame.common.getSecretaryScale();
  156. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  157. // xGame.common.secretary.play(data, 1, true, parent);
  158. xGame.common.secretary.play(data, 0, true, parent);
  159. }
  160. interuptSecretary() {
  161. Laya.timer.clearAll(this);
  162. this.playSecretaryRandomSound();
  163. }
  164. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  165. playSecretaryRandomSound() {
  166. if (this.isHide) return;
  167. let time = xGame.common.randomNum(45000, 60000);
  168. Laya.timer.once(time, this, () => {
  169. if (this.isHide) return;
  170. let index = xGame.common.randomNum(4, 7);
  171. xGame.soundMgr.playSound("s_main0" + index);
  172. let words = 1;
  173. switch (index) {
  174. case 4:
  175. words = 5;
  176. break;
  177. case 5:
  178. words = 3;
  179. break;
  180. case 6:
  181. words = 6;
  182. break;
  183. case 7:
  184. words = 7;
  185. break;
  186. default:
  187. break;
  188. }
  189. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  190. //
  191. this.playSecretaryRandomSound();
  192. })
  193. }
  194. closeSelf() {
  195. this.hide();
  196. }
  197. }
  198. UIShop.uiName = "UIShop";