GodCardView.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { GameViewType } from "../../../main/ViewManage";
  2. import ViewObject from "../../../main/ViewObject";
  3. import { HttpStateType, ReveData } from "../../../util/CHttp";
  4. import CardInfoView from "./CardInfoView";
  5. import CardStarSuccessView from "./CardStarSuccessView";
  6. import CardItem from "./item/CardItem";
  7. /**
  8. * 神庙
  9. */
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class GodCardView extends ViewObject {
  13. @property(cc.Node)
  14. mContent: cc.Node = null;
  15. @property(cc.Prefab)
  16. mCardItem: cc.Prefab = null;
  17. public onLoad() {
  18. this.init(1)
  19. }
  20. public init(type:number){
  21. this.mContent.destroyAllChildren()
  22. let godCard = this.main.player.godCard
  23. let _godCards = this.main.sManage.godCards
  24. for (let i = 0; i < _godCards.length; i++) {
  25. const element = _godCards[i];
  26. if(element.type == type){
  27. let godCardAttr = godCard[element.id]
  28. let node = cc.instantiate(this.mCardItem)
  29. node.parent = this.mContent
  30. let cardItem = node.getComponent(CardItem)
  31. if(godCardAttr){
  32. cardItem.init(this.main,godCardAttr)
  33. cardItem.setCallback((item:CardItem)=>{
  34. this.openGodCard(item)
  35. })
  36. }else{
  37. cardItem.initNo(this.main,element)
  38. cardItem.setCallback((item:CardItem)=>{
  39. this.getGodCard(item)
  40. })
  41. }
  42. }
  43. }
  44. for (const id in godCard) {
  45. let godCardAttr = godCard[id]
  46. let _godCard = this.main.sManage.getGodCardById(godCardAttr.id)
  47. if(_godCard.type == type){
  48. }
  49. }
  50. }
  51. public onclickType(event,data){
  52. let type = parseInt(data)
  53. this.init(type)
  54. }
  55. /**
  56. * 神卡说明
  57. */
  58. public openGodCard(cardItem:CardItem){
  59. this.main.viewManage.loadFunc(GameViewType.god_card_info,(viewObject:ViewObject)=>{
  60. let cardInfoView = viewObject as CardInfoView
  61. cardInfoView.init(cardItem)
  62. viewObject.show();
  63. });
  64. }
  65. public getGodCard(cardItem:CardItem){
  66. let msg = {
  67. id:cardItem._godCard.id
  68. }
  69. this.main.gameHttp.sendJson('card/v1/exchange',msg,(state,reve:ReveData)=>{
  70. this.main.stopLoad();
  71. if(state == HttpStateType.SUCCESS){
  72. if(reve.retCode == 0){
  73. let godCard = reve.data._godCard[0]
  74. cardItem.init(this.main,godCard)
  75. this.main.showReward(reve)
  76. cardItem.setCallback((item)=>{
  77. this.openGodCard(item)
  78. })
  79. }else{
  80. this.main.showTips(reve.message);
  81. }
  82. }else{
  83. this.main.showTips('网络异常');
  84. }
  85. });
  86. }
  87. }