MagicBoxInfoView.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import i18n from "../../../i18n/i18n";
  2. import { GameViewType } from "../../../main/ViewManage";
  3. import ViewObject from "../../../main/ViewObject";
  4. import { HttpStateType, ReveData } from "../../../util/CHttp";
  5. import GoodItem from "../../common/GoodItem";
  6. import MagicBoxItem from "./MagicBoxItem";
  7. import MagicBoxRewardView from "./MagicBoxRewardView";
  8. /**
  9. * 魔盒详细说明查看
  10. */
  11. const {ccclass, property} = cc._decorator;
  12. @ccclass
  13. export default class MagicBoxInfoView extends ViewObject {
  14. @property(cc.Label)
  15. mName: cc.Label = null;
  16. @property(cc.Label)
  17. mAbout: cc.Label = null;
  18. @property(cc.Node)
  19. mContent: cc.Node = null;
  20. @property(cc.Prefab)
  21. mGoodItem: cc.Prefab = null;
  22. @property(cc.Sprite)
  23. mIcon: cc.Sprite = null;
  24. @property(cc.Label)
  25. mCount: cc.Label = null;
  26. public boxItem:MagicBoxItem
  27. public init(boxItem:MagicBoxItem){
  28. this.boxItem = boxItem
  29. let _magicBox = boxItem._magicBox
  30. this.mName.string = i18n.t(_magicBox.name)
  31. this.mAbout.string = i18n.t(_magicBox.about)
  32. cc.resources.load('icon/magic_box/'+_magicBox.icon,
  33. cc.SpriteFrame,
  34. (err, spriteFrame:cc.SpriteFrame) =>{
  35. if(err){
  36. cc.error(err);
  37. }else{
  38. this.mIcon.spriteFrame = spriteFrame;
  39. }
  40. });
  41. let rewardList = this.main.sManage.getRewardViews(_magicBox.list)
  42. for (let i = 0; i < rewardList.length && i < 5; i++) {
  43. const element = rewardList[i];
  44. let node = cc.instantiate(this.mGoodItem)
  45. let goodItem:GoodItem = node.getComponent(GoodItem)
  46. goodItem.initReward(this.main,element)
  47. node.parent = this.mContent
  48. }
  49. this.flush()
  50. }
  51. public flush(){
  52. let _magicBox = this.boxItem._magicBox
  53. let count = this.main.player.getGoodCount(_magicBox.goodId)
  54. this.mCount.string = count+'/'+_magicBox.goodCount
  55. }
  56. public onclickInfo(){
  57. this.main.viewManage.loadFunc(GameViewType.moheReward,(viewObject:ViewObject)=>{
  58. let magicBoxInfo = viewObject as MagicBoxRewardView;
  59. magicBoxInfo.init(this.boxItem)
  60. viewObject.show();
  61. });
  62. }
  63. public onclickOpen(){
  64. let msg = {
  65. id:this.boxItem._magicBox.id
  66. }
  67. this.main.gameHttp.sendJson('magicBox/v1/open',msg,(state,reve:ReveData)=>{
  68. this.main.stopLoad();
  69. if(state == HttpStateType.SUCCESS){
  70. if(reve.retCode == 0){
  71. this.boxItem.flush()
  72. this.flush()
  73. this.main.showReward(reve)
  74. }else{
  75. this.main.showTips(reve.message);
  76. }
  77. }else{
  78. this.main.showTips('网络异常');
  79. }
  80. });
  81. }
  82. }