ObtainUI.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 { ITEM_TYPE, ResUtil } from '../utils/ResUtil';
  8. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('ObtainUI')
  11. export class ObtainUI 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. //是否需要把枪转换成金币和钻石
  33. private isConvert:boolean = false;
  34. start() {
  35. this.closeOnBlank = false;
  36. }
  37. public show(...args: any[]){
  38. this.id = args[0];
  39. this.cb = args[1];
  40. this.hasAnim = true;
  41. //加载数据ui
  42. this.ui();
  43. }
  44. /**
  45. * 加载数据ui
  46. */
  47. public ui(){
  48. //获得的光圈一直旋转
  49. Tween.stopAllByTarget(this.rotation_light);
  50. tween(this.rotation_light)
  51. .by(2, { eulerAngles: new Vec3(0, 0, -360) })
  52. .repeatForever()
  53. .start();
  54. this.data = userIns.boomerangTable.find(e=>e.id == this.id);
  55. //设置图片
  56. ResUtil.setSpriteFrame(this.data.icon,this.obtain_good);
  57. //设置图片缩影
  58. ResUtil.setSpriteFrame(this.data.s_icon,this.good_sy_sp);
  59. //设置名字
  60. this.name_lable.string = i18n.isZh ? this.data.name : this.data.name_lang;
  61. //设置描述
  62. this.dec_lable.string = i18n.isZh? this.data.description : this.data.dec_lang;
  63. const [gun_id,num] = this.data.quantity.split('_');
  64. if(gun_id == 1001 || gun_id == 1002){//金币和钻石
  65. this.owned_lable.active = false;
  66. this.confim_btn.active = false;
  67. //是金币和钻石自动关闭
  68. this.scheduleOnce(()=>{
  69. uiMgr.hide(Constants.popUIs.obtainUI,this.cb);
  70. },1.5);
  71. }else{
  72. this.confim_btn.active = true;
  73. //是解锁的枪 这儿需要判断是否已经拥有的了这把枪 如果已经拥有了这把枪 就转换成钻石和金币
  74. if(userIns.isHasGun(gun_id)){//拥有这把枪转换成金币
  75. this.owned_lable.active = true;
  76. const [good_id,amount] = this.data.value.split('_');
  77. const sData:any = userIns.itemTable.find(e=>e.id == good_id);
  78. this.dec_lable.string = `Already owned ${this.data.name_lang}, converted ${amount} ${sData.name_lang}`;
  79. this.isConvert = true;
  80. }else{//没有拥有这把枪 直接解锁
  81. userIns.unlockGun(gun_id);
  82. this.owned_lable.active = false;
  83. this.isConvert = false;
  84. }
  85. }
  86. }
  87. /**
  88. * 按钮点击事件
  89. * @param event 事件
  90. * @param param 参数
  91. */
  92. override onBtnClicked(event:EventTouch, param:any) {
  93. super.onBtnClicked(event, param);
  94. let btnName = event.target.name;
  95. if(btnName === 'confim_btn'
  96. || btnName === 'close_btn'){
  97. this.unscheduleAllCallbacks();
  98. uiMgr.hide(Constants.popUIs.obtainUI,()=>{
  99. this.cb?.(this.isConvert);
  100. });
  101. }
  102. }
  103. }