ObtainUI.ts 3.9 KB

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