移动脚本目录
This commit is contained in:
128
src/views/Block.ts
Normal file
128
src/views/Block.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import { G_ShowScoreTips } from "../views/GUITips";
|
||||
import { DOBlock } from "../models/DOBlock";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class Block extends Laya.Script {
|
||||
declare owner : Laya.Button;
|
||||
|
||||
@property(Number)
|
||||
public XIndex: number = 0;
|
||||
@property(Number)
|
||||
public YIndex: number = 0;
|
||||
@property(Number)
|
||||
public XGroup: number = 0;
|
||||
@property(Number)
|
||||
public YGroup: number = 0;
|
||||
|
||||
private label_show: Laya.Label;
|
||||
private tips_labels: Array<Laya.Label> = new Array();
|
||||
private animator: Laya.Animator2D
|
||||
|
||||
private selected: boolean = false
|
||||
private newSelect: boolean = false
|
||||
|
||||
private data: DOBlock
|
||||
|
||||
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, label_obj: Laya.Box, handler: any, func: any): void {
|
||||
this.XIndex = XIndex;
|
||||
this.YIndex = YIndex;
|
||||
this.XGroup = XGroup;
|
||||
this.YGroup = YGroup;
|
||||
|
||||
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
|
||||
var VBox = label_obj.getChildByName("VBox")
|
||||
for (var i=0; i<VBox.numChildren; i++) {
|
||||
var hbox = VBox.getChildAt(i);
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var Label = hbox.getChildAt(j) as Laya.Label
|
||||
Label.text = ""
|
||||
this.tips_labels.push(Label)
|
||||
}
|
||||
}
|
||||
this.owner.on(Laya.Event.CLICK, handler, func);
|
||||
this.animator = this.owner.getComponent(Laya.Animator2D)
|
||||
}
|
||||
|
||||
public setSelected(selected: boolean): void {
|
||||
this.selected = selected
|
||||
if (selected)
|
||||
this.newSelect = true
|
||||
this.updateBlock()
|
||||
}
|
||||
|
||||
public setButtonSkin(skin: string): void {
|
||||
this.owner.skin = skin
|
||||
}
|
||||
|
||||
public setFadeAnimation(): void {
|
||||
if (this.animator) {
|
||||
this.animator.play("fade_to_red")
|
||||
Laya.timer.frameOnce(40, this, ()=>{
|
||||
this.animator.stop()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public setBlock(data: DOBlock): void {
|
||||
this.data = data;
|
||||
this.updateBlock();
|
||||
}
|
||||
public getData(): DOBlock {
|
||||
return this.data
|
||||
}
|
||||
|
||||
public setShowNumber(showNumber: number): boolean {
|
||||
if (this.data.get_checked() == false) {
|
||||
this.data.set_show(showNumber)
|
||||
var score: number = 0
|
||||
if (this.newSelect) {
|
||||
this.newSelect = false
|
||||
if (this.data.get_checked()) {
|
||||
score = 150
|
||||
this.data.set_score(score)
|
||||
G_ShowScoreTips(score.toString(), this.owner)
|
||||
}
|
||||
}
|
||||
this.updateBlock()
|
||||
}
|
||||
return this.data.get_checked()
|
||||
}
|
||||
|
||||
public addNoteNumber(noteNumber: number): void {
|
||||
if (this.data.add_note(noteNumber)) {
|
||||
this.updateBlock()
|
||||
}
|
||||
}
|
||||
|
||||
updateBlock(): void {
|
||||
for (var i=0; i<this.tips_labels.length; i++)
|
||||
this.tips_labels[i].text = ""
|
||||
if (this.data.get_show() > 0) {
|
||||
this.label_show.text = this.data.get_show().toString()
|
||||
if (this.data.get_checked()) {
|
||||
this.label_show.color = "#000000"
|
||||
}
|
||||
else {
|
||||
this.label_show.color = "#ff0000"
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.label_show.text = "";
|
||||
var note_numbers = this.data.get_notes()
|
||||
for (var i=0; i<note_numbers.length; i++) {
|
||||
var value = note_numbers[i]
|
||||
var label = this.tips_labels[value-1]
|
||||
label.text = value.toString()
|
||||
if (this.selected) {
|
||||
label.color = "#ffffff"
|
||||
}
|
||||
else {
|
||||
label.color = "#000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user