MagicBoxView.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { GameViewType } from "../../../main/ViewManage";
  2. import ViewObject from "../../../main/ViewObject";
  3. import MagicBoxInfoView from "./MagicBoxInfoView";
  4. import MagicBoxItem from "./MagicBoxItem";
  5. /**
  6. * 魔盒
  7. */
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class MagicBoxView extends ViewObject {
  11. @property(cc.Node)
  12. mLine1: cc.Node = null;
  13. @property(cc.Node)
  14. mLine2: cc.Node = null;
  15. @property(cc.Prefab)
  16. mBoxItem: cc.Prefab = null;
  17. start(){
  18. this.init(1)
  19. }
  20. public init(type){
  21. let magicBoxs = this.main.sManage.magicBoxs
  22. this.mLine1.destroyAllChildren()
  23. this.mLine2.destroyAllChildren()
  24. let count = 0
  25. for (let i = 0; i < magicBoxs.length; i++) {
  26. const element = magicBoxs[i];
  27. if(element.type == type){
  28. let node = cc.instantiate(this.mBoxItem)
  29. let boxItem = node.getComponent(MagicBoxItem)
  30. boxItem.init(this.main,element)
  31. if(count < 2){
  32. node.parent = this.mLine1
  33. }else{
  34. node.parent = this.mLine2
  35. }
  36. boxItem.setCallback((item)=>{
  37. this.openMagicBox(item)
  38. })
  39. count ++
  40. }
  41. }
  42. }
  43. public openMagicBox(boxItem:MagicBoxItem){
  44. this.main.viewManage.loadFunc(GameViewType.moheInfo,(viewObject:ViewObject)=>{
  45. let magicBoxInfo = viewObject as MagicBoxInfoView;
  46. magicBoxInfo.init(boxItem)
  47. viewObject.show();
  48. });
  49. }
  50. }