123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /// #pkgName FGUI包名
- /// #prefabName ui预制名字
- /// #viewName uiview名字
- /// #UIName ui的名字,prefabName首字母转大写
- /// ui逻辑处理类
- /// created by chenwb 2024
- import { gameMethod } from "../../../../common/gameMethod";
- import { FguiEvent } from "../../../../data/const/EventConst";
- import FguiMgr from "../../../../frameWork/fgui/FguiMgr";
- import { FguiViewCtrl } from "../../../../frameWork/fgui/mvc/FguiViewCtrl";
- import EventMng from "../../../../manager/EventMng";
- import {ShowTipsItem} from "./ShowTipsItem";
- import { ShowTipsVM } from "./ShowTipsVM";
- import { ShowTipsView } from "./ShowTipsView";
- export class ShowTipsCtrl extends FguiViewCtrl<ShowTipsVM> {
- private delayList:string[];
- private delayShow:number; // 0.2秒内重复触发的,过滤掉
- private showTipsList:ShowTipsItem[];
- OnInited(): void {
- this.delayShow = 0;
- this.delayList = new Array();
- this.showTipsList = new Array();
- }
- OnShow(intent?: any): void {
- this.AddListeners();
- this.delayShow = 0.2;
- this.AddDelayMessage(intent);
- this.ShowTipsUI();
- }
- OnHide(): void {
- this.RemoveListeners();
- for (let index = 0; index < this.showTipsList.length; index++) {
- const element = this.showTipsList[index];
- if (element.IsUsing()){
- element.ResetUI();
- }
- }
- }
- //#region UI事件
- private AddListeners() : void {
- this.initEvent(FguiEvent.SHOWTIPS, this.AddDelayMessage)
- }
- private RemoveListeners() : void {
- }
- private GetShowTipsItem(){
- if (gameMethod.isEmpty(this.showTipsList)){
- return this.CreateShowTipsItem();
- }
- let count = this.showTipsList.length;
- for (let index = 0; index < count; index++) {
- const element = this.showTipsList[index];
- if (!element.IsUsing()){
- return element;
- }
- }
- return this.CreateShowTipsItem();
- }
- private CreateShowTipsItem(){
- let tipsItem = fgui.UIPackage.createObject("Common","TipsItem", ShowTipsItem) as ShowTipsItem;;
- this.showTipsList.push(tipsItem);
- if (gameMethod.isEmpty(this.VM.Panel) || gameMethod.isEmpty(tipsItem)) {
- //还未初始化完成
- return null
- }
- this.VM.Panel.addChild(tipsItem);
- tipsItem.x = this.VM.Panel.width/2;
- tipsItem.touchable = false;
- return tipsItem;
- }
- private ShowTipsUI(){
- if (gameMethod.isEmpty(this.delayList)){
- return;
- }
- let tipsItem = this.GetShowTipsItem();
- if (gameMethod.isEmpty(tipsItem)) {
- return
- }
- this.delayShow = 0.2;
- tipsItem.setData({tips:this.delayList.pop(), callback:()=>{
- if (this.IsHideUI()){
- this.Close();
- }
- }});
- }
- // 是否关闭界面
- private IsHideUI(){
- if (!gameMethod.isEmpty(this.delayList)){
- return false;
- }
- let count = this.showTipsList.length;
- for (let index = 0; index < count; index++) {
- if (this.showTipsList[index].IsUsing()){
- return false;
- }
- }
- return true;
- }
-
- private AddDelayMessage(tips:string) {
- if (gameMethod.isEmpty(tips)) {
- return
- }
- this.delayShow = 0.2;
- if (this.delayShow > 0) {
- this.delayList.push(tips)
- return
- }
- }
- OnUpdate(dt:number): void {
- if (this.delayShow > 0) {
- this.delayShow -= dt
- if (!gameMethod.isEmpty(this.delayList)) {
- this.ShowTipsUI();
- }
- }
- }
- private Close(): void{
- FguiMgr.Instance.closeUI(ShowTipsView);
- }
- //#endregion
- }
|