HistoryArea.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Area, { Zone, History_Role } from "./Area";
  2. import AllArea from "./AllArea";
  3. import MyZoneItem from "./item/MyZoneItem";
  4. import ViewObject from "../main/ViewObject";
  5. import { GameViewType } from "../main/ViewManage";
  6. /**
  7. * 历史分区
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class HistoryArea extends ViewObject {
  12. public area:Area;
  13. @property(cc.Node)
  14. mContent: cc.Node = null;
  15. @property(cc.Prefab)
  16. mZoneItem: cc.Prefab = null;
  17. onLoad(){
  18. let zones = this.area.zones;
  19. for (let i = 0; i < zones.length; i++) {
  20. const element = zones[i];
  21. if(element.rec && !this.inRoles(element)){
  22. this.addItem(element,null);
  23. }
  24. }
  25. if(this.area.roles){
  26. for (let i = 0; i < this.area.roles.length; i++) {
  27. const element = this.area.roles[i];
  28. this.addItem(null,element);
  29. }
  30. }
  31. }
  32. public addItem(zone:Zone,role:History_Role){
  33. let node = cc.instantiate(this.mZoneItem);
  34. let item = node.getComponent(MyZoneItem);
  35. item.zone = zone;
  36. item.role = role;
  37. node.parent = this.mContent;
  38. item.setCallback((m:MyZoneItem)=>{
  39. this.area.setOptZone(m.zone);
  40. this.exitDistroy();
  41. });
  42. }
  43. public inRoles(zone:Zone):boolean{
  44. if(this.area.roles == null){
  45. return false;
  46. }
  47. for (let i = 0; i < this.area.roles.length; i++) {
  48. const element = this.area.roles[i];
  49. if(element.zoneId == zone.id){
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. /**
  56. * 打开所有分区
  57. */
  58. public openAllArea(){
  59. this.main.startLoad();
  60. this.main.viewManage.loadFunc(GameViewType.allArea,(viewObject:ViewObject)=>{
  61. let allArea = viewObject as AllArea;
  62. allArea.area = this.area;
  63. viewObject.show(this);
  64. this.main.stopLoad();
  65. });
  66. }
  67. }