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

127 lines
3.9 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
const {ccclass, property} = cc._decorator;
import ResManager from "../../common/res/ResManager";
import UIBase from "../../common/ui/base/UIBase";
import { PanelType } from "../../common/ui/config/SysDefine";
import UIBaseEv from "../../common/ui/uiEv/UIBaseEv";
import { composeObj, valueObj } from "../Model/data/baseObject";
import venueUpgradeModule from "../module/venueUpgradeModule";
import ToolFunc from "../ToolFunc";
@ccclass
export default class UIUpgradeVenueLayer extends UIBaseEv {
panelType: PanelType = PanelType.PopUp;
@property(cc.ScrollView)
scrollview:cc.ScrollView = null;
@property(cc.Sprite)
venueNameSpr:cc.Sprite = null;
@property(cc.Button)
cancleBtn:cc.Button = null;
//@property
spwanCount = 0;
//@property
spacing = 10;//升级组件之间的间隔
viewContent = null;//scroollview 的内容组件
lastContentPos = null;
maxCount = 7;
upgradeItems:cc.Node[] = [];
singlePrefab= null;
venueData:composeObj = null;
arrUpgradeData:valueObj[] = [];
// LIFE-CYCLE CALLBACKS:
async initUI () {
this.viewContent = this.scrollview.content;
this.lastContentPos = this.viewContent.position;
// let self = this;
// cc.resources.load("prefab/venueElementModule",function(err,prefab:cc.Prefab){
// self.singlePrefab = prefab;
// if(self.singlePrefab)
// {
// for (let i = 0; i < 7; i++) {
// let item = cc.instantiate(self.singlePrefab);
// self._content.addChild(item);
// item.setPosition(0,- item.height * i - self.spacing*(i + 1));
// self._items.push(item);
// }
// }
// self._content.height = self._maxCount*(self._items[0].height + self.spacing) + self.spacing;
// })
let PanelPath = "Prefabs/venueUpgradeModule";
let startPos = this.upgradeItems.length;
for (let i = startPos; i < this.maxCount; i++) {
let item: cc.Node = await this.addChildPerfab(PanelPath,this.viewContent);
item.setPosition(0,- item.height * i - this.spacing*(i + 1));
item.active = false;
this.upgradeItems.push(item);
}
this.viewContent.height = this.maxCount*(this.upgradeItems[0].height + this.spacing) + this.spacing;
let arrTempVenue = [];
let tempObj = this.venueData.getMemberMap();
for (let i of tempObj.values()) {
arrTempVenue.push(i);
}
this.arrUpgradeData = [];
for (let i = 0; i < 7; i++) {
this.arrUpgradeData.push(arrTempVenue[i]);
}
this.updataUI();
}
onClickEvent(event,customEventData)
{
let node = event.target;
let button = node.getComponent(cc.Button);
switch (+customEventData) {
case 0:
//ToolFunc.ins.closeAction(this.node);
UIUpgradeVenueLayer.closeView();
break;
default:
break;
}
}
onShow(venueData:composeObj)
{
this.venueData = venueData;
this.initUI()
}
updataUI():void
{
for (let i = 0; i < this.maxCount; i++) {
this.upgradeItems[i].getComponent(venueUpgradeModule).updataItem(this.arrUpgradeData[i]);
}
}
start () {
}
// update (dt) {}
}