123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { _decorator, Component, Node, Prefab, LayoutComponent, instantiate, ScrollViewComponent } from 'cc';
- import { GUIManager } from '../../../engines/gui/GUIManager';
- import { GUIMediator } from '../../../engines/gui/GUIMediator';
- import GameConfigManager from '../../models/GameConfigManager';
- import { UIConst } from '../UIConst';
- import { ShopItemRenderScript } from './ShopItemRenderScript';
- const { ccclass, property } = _decorator;
- @ccclass('ShopMediator')
- export class ShopMediator extends GUIMediator {
- @property({
- type:Prefab
- })
- ListItemRenderPrefab:Prefab=null;
- @property({
- type:LayoutComponent
- })
- ListContext:LayoutComponent=null;
- @property({
- type:ScrollViewComponent
- })
- List:ScrollViewComponent=null;
- OnShow(data?:any):void{
- super.OnShow(data);
- this.RefreshList(true);
- this.AddEvent();
- }
- OnHide():void{
- this.RemoveEvent();
- }
- /**
- * 返回按钮点击
- */
- public BackButtonClick():void{
- GUIManager.single.Show(UIConst.PREPARE_UI);
- this.HideSelf();
- }
- private AddEvent():void{
- }
- private RemoveEvent():void{
- }
- private RefreshList(srollToZ:boolean):void{
- let itemView:Node;
- if(GameConfigManager.ShopList.length!=this.ListContext.node.children.length){
- if(GameConfigManager.ShopList.length<this.ListContext.node.children.length){
- //删除多余的
- while(GameConfigManager.ShopList.length<this.ListContext.node.children.length){
- this.ListContext.node.removeChild(this.ListContext.node.children[0]);
- }
- }else{
- //添加缺少的
- while(GameConfigManager.ShopList.length>this.ListContext.node.children.length){
- itemView=instantiate(this.ListItemRenderPrefab);
- this.ListContext.node.addChild(itemView);
- }
- }
- }
- let itemScript:ShopItemRenderScript;
- let count:number=GameConfigManager.ShopList.length;
- for (let index = 0; index < count; index++) {
- itemView=this.ListContext.node.children[index];
- itemScript=itemView.getComponent(ShopItemRenderScript);
- if(itemScript==null){
- throw new Error("商城列表项未挂载ShopItemRenderScript脚本!");
- }
- itemScript.UpdateItemRender(GameConfigManager.ShopList[index]);
- }
- if(srollToZ){
- this.List.scrollToTop(0.1);
- }
- }
- start () {
- // Your initialization goes here.
- }
- // update (deltaTime: number) {
- // // Your update function goes here.
- // }
- }
|