SuccessUI.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { _decorator, Node, Label, Sprite, EventTouch, Tween, tween, Vec3} from 'cc';
  2. import { BaseExp } from '../core/base/BaseExp';
  3. import { autoBind } from '../extend/AutoBind';
  4. import { userIns } from '../data/UserData';
  5. import { Constants } from '../data/Constants';
  6. import { uiMgr } from '../core/manager/UIManager';
  7. import { ResUtil } from '../utils/ResUtil';
  8. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('SuccessUI')
  11. export class SuccessUI extends BaseExp {
  12. @autoBind({ type: Node, tooltip: "旋转光节点" })
  13. public rotation_light: Node;
  14. @autoBind({ type: Sprite, tooltip: "获得的物品图片" })
  15. public obtain_good: Sprite;
  16. @autoBind({ type: Sprite, tooltip: "获得的物品图片缩影" })
  17. public good_sy_sp: Sprite;
  18. @autoBind({ type: Label, tooltip: "获得的物品的名字" })
  19. public name_lable: Label;
  20. @autoBind({ type: Label, tooltip: "描述文字" })
  21. public dec_lable: Label;
  22. @autoBind({ type: Node, tooltip: "底部提交确认按钮" })
  23. public confim_btn: Node;
  24. @autoBind({ type: Node, tooltip: "拥有状态" })
  25. public owned_lable: Node;
  26. //奖励的数据
  27. private data: any = null;
  28. //奖励的id
  29. private id: string = '';
  30. //回调函数
  31. private cb:Function = null;
  32. start() {
  33. this.closeOnBlank = false;
  34. }
  35. public show(...args: any[]){
  36. this.id = args[0];
  37. this.cb = args[1];
  38. this.hasAnim = true;
  39. //加载数据ui
  40. this.ui();
  41. }
  42. /**
  43. * 加载数据ui
  44. */
  45. public ui(){
  46. //获得的光圈一直旋转
  47. Tween.stopAllByTarget(this.rotation_light);
  48. tween(this.rotation_light)
  49. .by(2, { eulerAngles: new Vec3(0, 0, -360) })
  50. .repeatForever()
  51. .start();
  52. this.data = userIns.boomerangTable.find(e=>e.id == this.id);
  53. //设置图片
  54. ResUtil.setSpriteFrame(this.data.icon,this.obtain_good);
  55. //设置图片缩影
  56. ResUtil.setSpriteFrame(this.data.s_icon,this.good_sy_sp);
  57. //设置名字
  58. this.name_lable.string = i18n.isZh ? this.data.name : this.data.name_lang;
  59. //设置描述
  60. this.dec_lable.string = i18n.isZh? this.data.description : this.data.dec_lang;
  61. const [gun_id,num] = this.data.quantity.split('_');
  62. if(gun_id == 1001 || gun_id == 1002){//金币和钻石
  63. this.owned_lable.active = false;
  64. this.confim_btn.active = false;
  65. //是金币和钻石自动关闭
  66. this.scheduleOnce(()=>{
  67. uiMgr.hide(Constants.popUIs.obtainUI,this.cb);
  68. },2);
  69. }else{
  70. this.confim_btn.active = true;
  71. //是解锁的枪 这儿需要判断是否已经拥有的了这把枪 如果已经拥有了这把枪 就转换成钻石和金币
  72. if(userIns.isHasGun(gun_id)){//拥有这把枪转换成金币
  73. this.owned_lable.active = true;
  74. const [good_id,amount] = this.data.value.split('_');
  75. const sData:any = userIns.itemTable.find(e=>e.id == good_id);
  76. this.dec_lable.string = `Already owned ${this.data.name_lang}, converted ${amount} ${sData.name_lang}`;
  77. }else{
  78. this.owned_lable.active = false;
  79. }
  80. }
  81. }
  82. /**
  83. * 按钮点击事件
  84. * @param event 事件
  85. * @param param 参数
  86. */
  87. override onBtnClicked(event:EventTouch, param:any) {
  88. super.onBtnClicked(event, param);
  89. let btnName = event.target.name;
  90. if(btnName === 'confim_btn'
  91. || btnName === 'close_btn'){
  92. this.unscheduleAllCallbacks();
  93. uiMgr.hide(Constants.popUIs.obtainUI,this.cb);
  94. }
  95. }
  96. }