marineparkclient/assets/script/ui/UISingleVenueLayer.ts
2023-08-15 11:09:12 +08:00

189 lines
5.5 KiB
TypeScript

// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import ResManager from "../../common/res/ResManager";
import UIBaseEv from "../../common/ui/uiEv/UIBaseEv";
import { composeObj } from "../Model/data/baseObject";
import { IDDef } from "../Model/data/excelDefine";
import { propType, PropUnlock } from "../Model/data/propObject";
import ProxyClientDataMgr from "../Model/ProxyClientDataMgr";
import touristModule from "../module/touristModule";
import UIUnlockVenueLayer from "./UIUnlockVenueLayer";
import UIUpgradeVenueLayer from "./UIUpgradeVenueLayer";
//import gameinfo from "./data/gameInfo"
//import UIBase from "./common/ui/base/UIBase";
const {ccclass, property} = cc._decorator;
@ccclass
export default class UISingleVenueLayer extends UIBaseEv {
@property(cc.Button)
singleAreaBtnArr:cc.Button[] = [];
@property(cc.Prefab)
touristPf:cc.Prefab = null;
nodePools:cc.NodePool = new cc.NodePool;
maxVenueCount = 4;
startPos = cc.v2(0,-510);
endPos = cc.v2(0,510);
newPos = cc.v2(0,-510);
arrVenueData:composeObj[] = [];
onLoad()
{
//this._Buttons["singleArea_1"];
//let objectData = new gameinfo(111);
//let gold = objectData.getMeans(0);
//objectData.
for (let i = 0; i < this.singleAreaBtnArr.length; i++) {
let clickEventHander = new cc.Component.EventHandler();
clickEventHander.target = this.node;
clickEventHander.component = "UISingleVenueLayer";
clickEventHander.handler = "onClickEvent";
clickEventHander.customEventData = ""+i;
this.singleAreaBtnArr[i].clickEvents.push(clickEventHander)
this.singleAreaBtnArr[i].node.zIndex = 1;
}
}
onClickEvent(event,customEventData){
let node = event.target;
let button = node.getComponent(cc.Button);
let index = +customEventData;
switch (index) {
default:
this.checkLockVenue(index);
break;
}
}
openPerConfig(data)
{
}
checkAreaOpen(sender)
{
for (let i = 0; i < sender.length; i++) {
sender[i]["isOpen"] = true;
}
}
async createTourist()
{
if (this.nodePools.size() === 0) {
let PanelPath = "Prefabs/touristModule";
let pre = await ResManager.inst.loadPrefab(PanelPath);
if(!pre) {
cc.warn(`${PanelPath} 资源加载失败, 请确认路径是否正确`);
return ;
}
let tempTourist:cc.Node = cc.instantiate(pre);
this.nodePools.put(tempTourist)
}
let touristTemp = this.nodePools.get();
let touristTempTs = touristTemp.getComponent(touristModule);
this.node.addChild(touristTemp)
touristTemp.zIndex = 0;
touristTemp.setPosition(this.startPos)
touristTempTs.init(this.node);
}
recycleTourist(sender)
{
sender.getComponent(touristModule).reset();
this.nodePools.put(sender);
}
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
onEnable(){
//this.createTourist();
this.schedule(this.createTourist,(2+Math.random()*3));
}
onDisable(){
this.unschedule(this.createTourist);
}
checkLockVenue(idx):void //检查解锁
{
let tempObj = this.arrVenueData[idx].getPropByType(propType.unlock) as PropUnlock
if(tempObj &&!tempObj.getUnLock())
{
UIUnlockVenueLayer.openView(this.arrVenueData[idx]);
}
else
{
UIUpgradeVenueLayer.openView(this.arrVenueData[idx]);
}
}
onShow(pageIdex:number):void
{
let venueObj = ProxyClientDataMgr.ins().getComposeObj(IDDef.PARK)
let arrTempVenue = [];
let tempObj = venueObj.getMemberMap();
for (let i of tempObj.values()) {
arrTempVenue.push(i);
}
let endCount = (pageIdex + 1)*this.maxVenueCount;
let startCount = this.maxVenueCount * pageIdex;
for (let i = startCount; i < endCount; i++) {
this.arrVenueData.push(arrTempVenue[i]);
}
this.updateBtnUi();
}
updateBtnUi():void
{
for (let i = 0; i < this.maxVenueCount; i++) {
let btn = this.singleAreaBtnArr[i];
let label = btn.getComponentInChildren(cc.Label);
let tempObj = this.arrVenueData[i]
//文字显示 后续应该是图片
let str = tempObj.getName();
label.string = str;
}
}
start () {
//this.planRoad()
// if (this.nodePools.size() === 0) {
// let tempTourist = cc.instantiate(this.touristPf);
// this.nodePools.put(tempTourist)
// }
// let touristTemp = this.nodePools.get();
// let touristTempTs = touristTemp.getComponent("touristModule");
// this.node.addChild(touristTemp)
// touristTemp.zIndex = 0;
// touristTemp.setPosition(cc.v2(210,350));
// touristTemp.setScale(4);
}
onDestroy()
{
this.nodePools.clear();
}
// update (dt) {}
}