PayCustom.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { _decorator, Component, EditBox, EventHandle, EventHandler, js, Label, Node, utils } from 'cc';
  2. import { UtilsPanel } from '../../scene/script/UtilsPanel';
  3. import { Pay } from './Pay';
  4. import { UtilsFormat } from '../../scene/script/UtilsFormat';
  5. const { ccclass } = _decorator;
  6. @ccclass('PayCustom')
  7. export class PayCustom extends Component {
  8. private lb_gold: Label = null;
  9. private edit_money: EditBox = null;
  10. private money = 0;
  11. protected onLoad(){
  12. UtilsPanel.getAllNeedCom(this, this.node, false);
  13. let handler = new EventHandler();
  14. handler.target = this.node;
  15. handler.component = js.getClassName(this);
  16. handler.handler = "onInputEnd";
  17. this.edit_money.editingDidEnded.push(handler);
  18. // this.edit_money.textChanged.push(handler)
  19. }
  20. protected start(): void {
  21. this.money = Pay.data_shop.MinMoney;
  22. this.edit_money.string = this.money + "";
  23. this.refreshGold();
  24. }
  25. // private checkNum(text: string){
  26. // let index = text.indexOf(".");
  27. // let revise = false;
  28. // if(index > -1){
  29. // revise = true;
  30. // text = text.replace(".", "");
  31. // }
  32. // let num = parseInt(text);
  33. // if(num < Pay.data_shop.MinMoney){
  34. // revise = true;
  35. // num = Pay.data_shop.MinMoney
  36. // text = "" + num;
  37. // }
  38. // if(revise){
  39. // //@ts-ignore
  40. // this.edit_money._impl._edTxt.value = text;
  41. // this.edit_money.string = text;
  42. // }
  43. // if(num != this.money){
  44. // this.money = num;
  45. // this.refreshGold();
  46. // }
  47. // }
  48. private onInputEnd(){
  49. let text = this.edit_money.string;
  50. let index = text.indexOf(".");
  51. let revise = false;
  52. if(index > -1){
  53. revise = true;
  54. text = text.replace(".", "");
  55. }
  56. let num = parseInt(text);
  57. if(num < Pay.data_shop.MinMoney){
  58. revise = true;
  59. num = Pay.data_shop.MinMoney
  60. text = "" + num;
  61. }
  62. if(revise){
  63. this.edit_money.string = text;
  64. }
  65. if(num != this.money){
  66. this.money = num;
  67. this.refreshGold();
  68. }
  69. }
  70. private refreshGold(){
  71. this.lb_gold.string = "" + (Pay.clacGold(this.money));
  72. }
  73. private onCloseClick(){
  74. this.node.destroy();
  75. }
  76. private onBuyClick(){
  77. Pay.buy(this.money);
  78. }
  79. }