mirror of
				https://github.com/Gongxh0901/kunpolibrary
				synced 2025-10-31 19:35:45 +00:00 
			
		
		
		
	仓库中添加内置的demo
This commit is contained in:
		
							
								
								
									
										126
									
								
								demo/assets/script/UI/Basics/Common/AlertWindow.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								demo/assets/script/UI/Basics/Common/AlertWindow.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,126 @@ | ||||
| import { cc, fgui, kunpo } from '../../../header'; | ||||
| const { uiclass, uiprop, uiclick } = kunpo._uidecorator; | ||||
|  | ||||
| interface WindowData { | ||||
|     content: string; | ||||
|     title?: string; | ||||
|     okTitle?: string; | ||||
|     cancelTitle?: string; | ||||
|     showClose?: boolean; // 显示关闭按钮 | ||||
|     emptyAreaClose?: boolean; // 点击空白区域关闭 | ||||
|     align?: cc.HorizontalTextAlignment; // 内容文本水平对齐方式  default:居中对齐 | ||||
|     leading?: number;//行距 | ||||
|     okNotClose?: boolean; // 点击OK按钮时不关闭本界面 | ||||
|     cancelNotClose?: boolean; // 点击取消按钮时不关闭本界面 | ||||
|     complete?: () => void; // 确定按钮的回调 | ||||
|     cancel?: () => void; // 取消按钮的回调 | ||||
|     close?: () => void; // 关闭界面的回调 (只有点击关闭按钮和空白位置关闭时才会触发) | ||||
| } | ||||
|  | ||||
|  | ||||
| @uiclass("Window", "Basics", "AlertWindow") | ||||
| export class AlertWindow extends kunpo.Window { | ||||
|     @uiprop private bg: fgui.GLoader; | ||||
|     @uiprop private lab_title: fgui.GTextField; | ||||
|     @uiprop private lab_content: fgui.GTextField; | ||||
|     @uiprop private btn_close: fgui.GButton; | ||||
|     @uiprop private btn_ok: fgui.GButton; | ||||
|     @uiprop private btn_cancel: fgui.GButton; | ||||
|  | ||||
|     private _isEmptyAreaClose: boolean = false; | ||||
|     private _window_data: WindowData = null; | ||||
|  | ||||
|     private _complete: () => void; | ||||
|     private _cancel: () => void; | ||||
|     private _closeFunc: () => void; | ||||
|  | ||||
|     protected onInit(): void { | ||||
|         this.adapterType = kunpo.AdapterType.Full; | ||||
|         this.type = kunpo.WindowType.Normal; | ||||
|     } | ||||
|  | ||||
|     protected onAdapted() { | ||||
|     } | ||||
|  | ||||
|     protected onShow(data: WindowData): void { | ||||
|         this._complete = data.complete; | ||||
|         this._cancel = data.cancel; | ||||
|         this._closeFunc = data.close; | ||||
|         this._window_data = data; | ||||
|  | ||||
|         // 标题 | ||||
|         if (data.title) { | ||||
|             this.lab_title.text = data.title; | ||||
|         } else { | ||||
|             this.lab_title.visible = false; | ||||
|         } | ||||
|  | ||||
|         // 关闭按钮 | ||||
|         this.btn_close.visible = !!data.showClose; | ||||
|  | ||||
|         // 空白位置关闭标记 | ||||
|         this._isEmptyAreaClose = !!data.emptyAreaClose; | ||||
|  | ||||
|         // 确定按钮 | ||||
|         if (data.okTitle) { | ||||
|             this.btn_ok.title = data.okTitle; | ||||
|         } else { | ||||
|             this.btn_ok.visible = false; | ||||
|         } | ||||
|  | ||||
|         // 取消按钮 | ||||
|         if (data.cancelTitle) { | ||||
|             this.btn_cancel.text = data.cancelTitle; | ||||
|         } else { | ||||
|             this.btn_cancel.visible = false; | ||||
|         } | ||||
|  | ||||
|         this.lab_content.text = data.content; | ||||
|         let align = typeof data.align == "number" ? data.align : cc.Label.HorizontalAlign.CENTER; | ||||
|         let leading = typeof data.leading == "number" ? data.leading : this.lab_content.leading; | ||||
|         this.lab_content.align = align; | ||||
|         this.lab_content.leading = leading; | ||||
|         this.lab_content.ensureSizeCorrect(); | ||||
|  | ||||
|         // 限制背景框高度 | ||||
|         if (this.bg.height < 500) { | ||||
|             this.bg.height = 500; | ||||
|         } | ||||
|  | ||||
|         // 确定取消按钮位置调整 | ||||
|         if (this.btn_ok.visible && !this.btn_cancel.visible) { | ||||
|             this.btn_ok.x = this.bg.x + (this.bg.width - this.btn_ok.width) * 0.5; | ||||
|         } else if (this.btn_cancel.visible && !this.btn_ok.visible) { | ||||
|             this.btn_cancel.x = this.bg.x + (this.bg.width - this.btn_cancel.width) * 0.5; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     protected onClose(): void { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected onEmptyAreaClick(): void { | ||||
|         if (this._isEmptyAreaClose) { | ||||
|             kunpo.WindowManager.closeWindow(this.name); | ||||
|             this._closeFunc && this._closeFunc(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @uiclick | ||||
|     private onClickBtnClose(): void { | ||||
|         kunpo.WindowManager.closeWindow(this.name); | ||||
|         this._closeFunc && this._closeFunc(); | ||||
|     } | ||||
|  | ||||
|     @uiclick | ||||
|     private onClickBtnOk(): void { | ||||
|         !this._window_data.okNotClose && kunpo.WindowManager.closeWindow(this.name); | ||||
|         this._complete && this._complete(); | ||||
|     } | ||||
|  | ||||
|     @uiclick | ||||
|     private onClickBtnCancel(): void { | ||||
|         !this._window_data.cancelNotClose && kunpo.WindowManager.closeWindow(this.name); | ||||
|         this._cancel && this._cancel(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										9
									
								
								demo/assets/script/UI/Basics/Common/AlertWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								demo/assets/script/UI/Basics/Common/AlertWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "ver": "4.0.24", | ||||
|   "importer": "typescript", | ||||
|   "imported": true, | ||||
|   "uuid": "434791ba-2680-4643-aea0-ecf8bebc2ff9", | ||||
|   "files": [], | ||||
|   "subMetas": {}, | ||||
|   "userData": {} | ||||
| } | ||||
							
								
								
									
										13
									
								
								demo/assets/script/UI/Basics/Common/LoadUIWindow.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								demo/assets/script/UI/Basics/Common/LoadUIWindow.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
|  | ||||
|  | ||||
| import { kunpo } from '../../../header'; | ||||
| const { uiclass, uiprop } = kunpo._uidecorator; | ||||
|  | ||||
| /** UI界面资源加载等待界面 */ | ||||
| @uiclass("Wait", "Basics", "LoadUIWindow") | ||||
| export class LoadUIWindow extends kunpo.Window { | ||||
|     protected onInit(): void { | ||||
|         this.adapterType = kunpo.AdapterType.Full; | ||||
|         this.type = kunpo.WindowType.Normal; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										9
									
								
								demo/assets/script/UI/Basics/Common/LoadUIWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								demo/assets/script/UI/Basics/Common/LoadUIWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "ver": "4.0.24", | ||||
|   "importer": "typescript", | ||||
|   "imported": true, | ||||
|   "uuid": "0b7e1ba3-9877-45ea-9d1b-71115f04744b", | ||||
|   "files": [], | ||||
|   "subMetas": {}, | ||||
|   "userData": {} | ||||
| } | ||||
							
								
								
									
										86
									
								
								demo/assets/script/UI/Basics/Common/ToastWindow.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								demo/assets/script/UI/Basics/Common/ToastWindow.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,86 @@ | ||||
| /* | ||||
|  * @Description: 通用Toast提示 | ||||
|  * @Author: Gongxh | ||||
|  * @Date: 2021-04-27 09:20:14 | ||||
|  */ | ||||
|  | ||||
| import { cc, fgui, kunpo } from "../../../header"; | ||||
| interface ToastData { | ||||
|     text: string, // 文本 | ||||
|     duration?: number, // 持续时间 | ||||
|     swallowTouch?: boolean, // 吞噬touch事件 | ||||
|     showMask?: boolean, // 显示遮罩 | ||||
|     align?: cc.HorizontalTextAlignment // 对齐方式 | ||||
| } | ||||
|  | ||||
| const { uiclass, uiprop } = kunpo._uidecorator; | ||||
| @uiclass("Toast", "Basics", "ToastWindow") | ||||
| export class ToastWindow extends kunpo.Window { | ||||
|     @uiprop private toast: fgui.GComponent; | ||||
|     @uiprop private labTips: fgui.GTextField; | ||||
|     @uiprop private bgMask: fgui.GGraph; | ||||
|  | ||||
|     private _showTransition: fgui.Transition; | ||||
|     private _hideTransition: fgui.Transition; | ||||
|  | ||||
|     private _swallowTouch: boolean = false; // 吞噬touch事件 | ||||
|     protected onInit(): void { | ||||
|         this.adapterType = kunpo.AdapterType.Full; | ||||
|         this.type = kunpo.WindowType.Normal; | ||||
|         this.bgAlpha = 0; | ||||
|  | ||||
|         this._showTransition = this.toast.getTransition("show"); | ||||
|         this._hideTransition = this.toast.getTransition("hide"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 参数说明 | ||||
|      * @param {string} data.text toast文本 | ||||
|      * @param {number} data.duration 存在时间( < 0)为常驻 default 2秒 | ||||
|      * @param {boolean} data.swallowTouch 吞噬touch事件 default 不吞噬 | ||||
|      * @param {boolean} data.showMask 是否显示半透明遮罩 (当显示遮罩时,必定吞噬touch事件) default 不显示 | ||||
|      * @param {cc.HorizontalTextAlignment} data.align 横向文本对齐方式 default 居中对齐 | ||||
|      */ | ||||
|     protected onShow(data: ToastData): void { | ||||
|         this.bgMask.visible = data.showMask; | ||||
|         this._swallowTouch = data.showMask ? true : (data.swallowTouch || false); | ||||
|         this.opaque = this._swallowTouch; | ||||
|         // if (this._swallowTouch) { | ||||
|         //     this.node.on(cc.Node.EventType.TOUCH_END, () => { }, this.node); | ||||
|         // } else { | ||||
|         //     this.node.targetOff(this.node); | ||||
|         // } | ||||
|  | ||||
|         this.labTips.text = data.text; | ||||
|  | ||||
|         let align = data.align || cc.HorizontalTextAlignment.CENTER; | ||||
|         this.labTips.align = align; | ||||
|         this.labTips.autoSize = fgui.AutoSizeType.Both; | ||||
|         this.labTips.ensureSizeCorrect(); | ||||
|         // 调整文本尺寸 | ||||
|         let maxWidht = 504; | ||||
|         if (this.labTips.width > maxWidht) { | ||||
|             this.labTips.autoSize = fgui.AutoSizeType.Height; | ||||
|             this.labTips.width = maxWidht; | ||||
|             this.labTips.ensureSizeCorrect(); | ||||
|         } else { | ||||
|             this.labTips.autoSize = fgui.AutoSizeType.Both; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         this._showTransition.stop(true); | ||||
|         this._hideTransition.stop(true); | ||||
|         this._showTransition.play(() => { | ||||
|             let duration = data.duration || 2.0 | ||||
|             if (duration > 0) { | ||||
|                 this._hideTransition.play(() => { | ||||
|                     kunpo.WindowManager.closeWindow(this.name); | ||||
|                 }, 1, duration); | ||||
|             } | ||||
|         }, 1, 0); | ||||
|     } | ||||
|  | ||||
|     protected onClose(): void { | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										9
									
								
								demo/assets/script/UI/Basics/Common/ToastWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								demo/assets/script/UI/Basics/Common/ToastWindow.ts.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "ver": "4.0.24", | ||||
|   "importer": "typescript", | ||||
|   "imported": true, | ||||
|   "uuid": "993ce544-0214-4132-ba2c-2d464aa39257", | ||||
|   "files": [], | ||||
|   "subMetas": {}, | ||||
|   "userData": {} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user