81 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
| 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.ButtonState = BaseButtonState.Disable;
 | |
|         this.winButtonComponent.ImgPath = NpkImage.ingame;
 | |
|         this.winButtonComponent.NormalImgIndex = 60;
 | |
|         this.winButtonComponent.HoverImgIndex = 61;
 | |
|         this.winButtonComponent.PressImgIndex = 62;
 | |
|         this.winButtonComponent.DisableImgIndex = 63;
 | |
| 
 | |
| 
 | |
|         /// 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.ButtonState = BaseButtonState.Disable;
 | |
|         this.spaceButtonComponent.ImgPath = NpkImage.ingame;
 | |
|         this.spaceButtonComponent.NormalImgIndex = 8;
 | |
|         this.spaceButtonComponent.HoverImgIndex = 9;
 | |
|         this.spaceButtonComponent.PressImgIndex = 10;
 | |
|         this.spaceButtonComponent.DisableImgIndex = 11;
 | |
| 
 | |
|     }
 | |
| 
 | |
|     /// 其他获胜条件
 | |
|     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();
 | |
|     }
 | |
| 
 | |
| }
 |