1 baseButton 增加一个方便的初始化状态的方法

2 修改原有使用baseButton 的代码
This commit is contained in:
WoNiu 2024-03-22 22:56:08 +08:00
parent d94ea3f4a9
commit b5158644d3
4 changed files with 45 additions and 28 deletions

View File

@ -53,6 +53,32 @@ export class BaseButton extends Component {
//按钮状态
ButtonState = BaseButtonState.Normal; // 0 普通 1悬停 2按下 8失效
/**
* @description: BaseButton初始化设置
* @param {string} ImgPath: npk中的路径
* @param {number} NormalIndex: 普通 npk.img idnex +1
*/
init(ImgPath:string,NormalIndex:number): void;
init(ImgPath:string,NormalIndex:number,HoverIndex:number,PressIndex:number,DisableIndex:number,auto:boolean): void;
/**
* @description: BaseButton初始化设置
* @param {string} ImgPath: npk中的路径
* @param {number} NormalIndex: 普通 npk.img idnex
* @param {number} HoverIndex: 悬停
* @param {number} PressIndex
* @param {number} DisableIndex
* @param {number} Disable
* @return {*}
*/
init(ImgPath:string,NormalIndex:number,HoverIndex?:number,PressIndex?:number,DisableIndex?:number,Disable:boolean = true): void{
this.ImgPath = ImgPath;
this.NormalImgIndex = NormalIndex;
this.HoverImgIndex = HoverIndex ? HoverIndex : NormalIndex + 1;
this.PressImgIndex = PressIndex ? PressIndex : NormalIndex + 2;
if (Disable){ this.DisableImgIndex = DisableIndex ? DisableIndex : NormalIndex + 3; }
}
start() {
//判断是否有精灵 如果没有 就给他搞一个

View File

@ -60,11 +60,12 @@ export class StartGameUINode extends Node {
/// 给节点添加 button 组件
const buttonComponent = startButtonNode.addComponent( BaseButton );
buttonComponent.ImgPath = NpkImage.main;
buttonComponent.NormalImgIndex = 1;
buttonComponent.HoverImgIndex = 2;
buttonComponent.PressImgIndex = 3;
buttonComponent.DisableImgIndex = 4;
buttonComponent.init(NpkImage.main,1);
// buttonComponent.ImgPath = NpkImage.main;
// buttonComponent.NormalImgIndex = 1;
// buttonComponent.HoverImgIndex = 2;
// buttonComponent.PressImgIndex = 3;
// buttonComponent.DisableImgIndex = 4;
startButtonNode.addComponent( Button)
startButtonNode.on(Button.EventType.CLICK,this.startOnTouchEnd,this);
@ -93,11 +94,7 @@ export class StartGameUINode extends Node {
/// 给节点添加 button 组件
const buttonComponent = pressenButtonNode.addComponent( BaseButton );
buttonComponent.ImgPath = NpkImage.main;
buttonComponent.NormalImgIndex = 9;
buttonComponent.HoverImgIndex = 10;
buttonComponent.PressImgIndex = 11;
buttonComponent.DisableImgIndex = 12;
buttonComponent.init(NpkImage.main,9);
pressenButtonNode.on(Node.EventType.MOUSE_UP,this.pressenOnTouchEnd,this);

View File

@ -1,3 +1,10 @@
/*
* @Author: WoNiu
* @Date: 2024-03-13 12:19:50
* @LastEditTime: 2024-03-22 22:49:20
* @LastEditors: WoNiu
* @Description:
*/
import { _decorator, EventMouse, Node } from 'cc';
import { BaseSprite } from '../../GlobalScript/CommonComponent/BaseSprite';
import { NpkImage } from '../../Tool/NPKImage';
@ -34,12 +41,7 @@ export class DiceButtonNode extends Node {
winBa.onMouseUp = this.winOnMouseUp.bind(this);
this.winButtonComponent = winButtonNode.addComponent( BaseButton );
this.winButtonComponent.ButtonState = BaseButtonState.Disable;
this.winButtonComponent.ImgPath = NpkImage.ingame;
this.winButtonComponent.NormalImgIndex = 60;
this.winButtonComponent.HoverImgIndex = 61;
this.winButtonComponent.PressImgIndex = 62;
this.winButtonComponent.DisableImgIndex = 63;
this.winButtonComponent.init(NpkImage.ingame,60)
/// space
@ -52,12 +54,8 @@ export class DiceButtonNode extends Node {
spaceBc.onMouseLeftUp = this.spaceOnMouseUp.bind(this);
this.spaceButtonComponent = spaceButtonNode.addComponent( BaseButton );
this.spaceButtonComponent.init(NpkImage.ingame,8);
this.spaceButtonComponent.ButtonState = BaseButtonState.Disable;
this.spaceButtonComponent.ImgPath = NpkImage.ingame;
this.spaceButtonComponent.NormalImgIndex = 8;
this.spaceButtonComponent.HoverImgIndex = 9;
this.spaceButtonComponent.PressImgIndex = 10;
this.spaceButtonComponent.DisableImgIndex = 11;
}

View File

@ -12,11 +12,7 @@ export class CloseButtonNode extends Node {
/// 给节点添加 button 组件
const buttonComponent = this.addComponent( BaseButton );
buttonComponent.ImgPath = NpkImage.ingame;
buttonComponent.NormalImgIndex = 39;
buttonComponent.HoverImgIndex = 40;
buttonComponent.PressImgIndex = 41;
buttonComponent.DisableImgIndex = 42;
buttonComponent.init(NpkImage.ingame,39);
/// 添加点击事件
const bba = this.addComponent( BaseButtonAction );
@ -24,5 +20,5 @@ export class CloseButtonNode extends Node {
}
}
}