PayCustom.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const { ccclass } = _decorator;
  5. @ccclass('PayCustom')
  6. export class PayCustom extends Component {
  7. private lb_gold: Label = null;
  8. private edit_money: EditBox = null;
  9. private money = 0;
  10. protected onLoad(){
  11. UtilsPanel.getAllNeedCom(this, this.node, false);
  12. let handler = new EventHandler();
  13. handler.target = this.node;
  14. handler.component = js.getClassName(this);
  15. handler.handler = "checkNum";
  16. this.edit_money.textChanged.push(handler)
  17. }
  18. protected start(): void {
  19. this.money = Pay.data_shop.MinMoney;
  20. this.edit_money.string = this.money + "";
  21. this.refreshGold();
  22. }
  23. private checkNum(text: string){
  24. let index = text.indexOf(".");
  25. let revise = false;
  26. if(index > -1){
  27. revise = true;
  28. text = text.replace(".", "");
  29. }
  30. let num = parseInt(text);
  31. if(num < Pay.data_shop.MinMoney){
  32. revise = true;
  33. num = Pay.data_shop.MinMoney
  34. text = "" + num;
  35. }
  36. if(revise){
  37. //@ts-ignore
  38. this.edit_money._impl._edTxt.value = text;
  39. this.edit_money.string = text;
  40. }
  41. if(num != this.money){
  42. this.money = num;
  43. this.refreshGold();
  44. }
  45. }
  46. private refreshGold(){
  47. this.lb_gold.string = Pay.clacGold(this.money) + "";
  48. }
  49. private onCloseClick(){
  50. this.node.destroy();
  51. }
  52. private onBuyClick(){
  53. Pay.buy(this.money);
  54. }
  55. }