79 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
| /*
 | |
|  * @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';
 | |
| import { BaseButton, BaseButtonState } from '../../GlobalScript/CommonComponent/BaseButton';
 | |
| import { BaseButtonAction } from '../../GlobalScript/CommonComponent/BaseButtonAction';
 | |
| const { ccclass } = _decorator;
 | |
| 
 | |
| 
 | |
| /// 投骰子按钮的整个节点
 | |
| @ccclass('DiceButtonNode')
 | |
| export class DiceButtonNode extends Node {
 | |
| 
 | |
|     winButtonComponent: BaseButton;
 | |
|     spaceButtonComponent: BaseButton;
 | |
| 
 | |
|     winButtonBlock: Function;
 | |
|     spaceDownBlock: Function;
 | |
|     spaceUpBlock: Function;
 | |
| 
 | |
|     constructor(){
 | |
|         super();
 | |
| 
 | |
|         const backgroundNode = new Node();
 | |
|         const bs = backgroundNode.addComponent( BaseSprite );
 | |
|         bs.updateSpriteFrame(NpkImage.ingame,7);
 | |
|         this.addChild(backgroundNode);
 | |
| 
 | |
|         /// 其他获胜条件
 | |
|         const winButtonNode = new Node();
 | |
|         this.addChild(winButtonNode);
 | |
|         winButtonNode.setPosition(20.5,-123);
 | |
| 
 | |
|         const winBa = winButtonNode.addComponent(BaseButtonAction);
 | |
|         winBa.onMouseUp = this.winOnMouseUp.bind(this);
 | |
| 
 | |
|         this.winButtonComponent = winButtonNode.addComponent( BaseButton );
 | |
|         this.winButtonComponent.init(NpkImage.ingame,60)
 | |
| 
 | |
| 
 | |
|         /// space
 | |
|         const spaceButtonNode = new Node();
 | |
|         this.addChild(spaceButtonNode);
 | |
|         spaceButtonNode.setPosition(89,-57);
 | |
| 
 | |
|         const spaceBc = spaceButtonNode.addComponent( BaseButtonAction);
 | |
|         spaceBc.onMouseLeftDown = this.spaceOnMouseDown.bind(this);
 | |
|         spaceBc.onMouseLeftUp = this.spaceOnMouseUp.bind(this);
 | |
| 
 | |
|         this.spaceButtonComponent = spaceButtonNode.addComponent( BaseButton );
 | |
|         this.spaceButtonComponent.init(NpkImage.ingame,8);
 | |
|         this.spaceButtonComponent.ButtonState = BaseButtonState.Disable;
 | |
| 
 | |
|     }
 | |
| 
 | |
|     /// 其他获胜条件
 | |
|     private winOnMouseUp(event:EventMouse){
 | |
|         if (this.winButtonComponent.ButtonState == BaseButtonState.Disable ) return;
 | |
|         if (this.winButtonBlock) this.winButtonBlock();
 | |
|     }
 | |
| 
 | |
|     /// 投骰子
 | |
|     private spaceOnMouseDown(event:EventMouse){
 | |
|         if (this.spaceButtonComponent.ButtonState == BaseButtonState.Disable ) return;
 | |
|         if (this.spaceDownBlock) this.spaceDownBlock();
 | |
|     }
 | |
|     private spaceOnMouseUp(event: EventMouse){
 | |
|         if (this.spaceButtonComponent.ButtonState == BaseButtonState.Disable ) return;
 | |
|         if (this.spaceUpBlock) this.spaceUpBlock();
 | |
|     }
 | |
| 
 | |
| }
 |