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

133 lines
4.0 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 { fishCathOnline } from "../Model/ProxyClientDataMgr";
import earningFishModule from "../module/earningFishModule";
import venueUpgradeModule from "../module/venueUpgradeModule";
import ToolFunc from "../ToolFunc";
@ccclass
export default class UIFishEarningsLayer extends UIBaseEv {
panelType: PanelType = PanelType.PopUp;
@property(cc.ScrollView)
scrollview:cc.ScrollView = null;
@property(cc.Sprite)
earningsSpr:cc.Sprite = null;
@property(cc.Button)
cancleBtn:cc.Button = null;
@property(cc.Label)
earningsLabel:cc.Label = null;
@property(cc.Button)
confirmBtn:cc.Button = null;
//@property
spwanCount = 0;
//@property
spacing = 30;//升级组件之间的间隔
viewContent = null;//scroollview 的内容组件
maxCount = 16;
earningsItems:cc.Node[] = [];
singlePrefab= null;
fishEarningsData:composeObj = null;
tArrFishStatistics:Array<fishCathOnline>
// LIFE-CYCLE CALLBACKS:
onShow(tArrFishStatistics:Array<fishCathOnline>)
{
this.tArrFishStatistics = tArrFishStatistics;
this.maxCount = tArrFishStatistics.length;
this.initUI()
}
async initUI () {
this.viewContent = this.scrollview.content;
let PanelPath = "Prefabs/earningFishModule";
let startPos = this.earningsItems.length;
for (let i = startPos; i < this.maxCount; i++) {
let item: cc.Node = await this.addChildPerfab(PanelPath,this.viewContent);
let heightIndex = Math.ceil((i+1)/3) - 1;
let widthIndex = i % 3;
item.setPosition(cc.v2((widthIndex+1)*this.spacing+widthIndex*item.width + 0.5* item.width,-((heightIndex + 1)*this.spacing+heightIndex*item.height)));
item.active = true;
this.earningsItems.push(item);
}
//this.viewContent.height = this.maxCount*(this.earningsItems[0].height + this.spacing) + this.spacing;
this.updataUI();
}
onClickEvent(event,customEventData)
{
let node = event.target;
let button = node.getComponent(cc.Button);
switch (+customEventData) {
case 0:
this.cleanFish();
this.closeUIPanel();
break;
case 1:
this.cleanFish();
this.closeUIPanel();
break;
default:
break;
}
}
cleanFish()
{
for (let index = 0; index < this.earningsItems.length; index++) {
this.earningsItems[index].active = false;
}
}
updataUI():void
{
let heightIndex = Math.ceil(this.tArrFishStatistics.length/3);
//let heightIndex = Math.ceil(this.maxCount/3);
this.viewContent.height = heightIndex * (this.spacing+this.earningsItems[0].height) + this.spacing;
let earningsMoney = 0;
for (let i = 0; i < this.maxCount; i++) {
this.earningsItems[i].getComponent(earningFishModule).updataItem(this.tArrFishStatistics[i]);
earningsMoney = this.tArrFishStatistics[i].coinSale+earningsMoney;
}
this.earningsLabel.string = ""+earningsMoney;
}
start () {
}
// update (dt) {}
}