rt-sim-training-client/src/jmapNew/shape/StationStand/ETrainDepart.js
2020-03-30 14:22:57 +08:00

76 lines
2.2 KiB
JavaScript

import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';
class ETrainDepart extends Group {
constructor(model) {
super();
this.model = model;
this.isNew = false;
this.timeStart = 30;
this.time = null;
}
create(text) {
if (!this.isNew) {
const model = this.model;
const style = this.model.style;
this.isNew = true;
this.trainDepart = new Text({
zlevel: model.zlevel,
z: model.z,
position: [0, 0],
style: {
x: model.x,
y: model.y,
text: text,
textAlign: style.textStyle.textAlign,
fontSize: style.StationStand.trainDepart.fontSize,
fontFamily: style.fontFamily,
textFill: style.StationStand.trainDepart.textFill,
textVerticalAlign: style.textStyle.textVerticalAlign,
textBorderColor: style.StationStand.trainDepart.textBorderColor,
textPadding: 2,
textBorderWidth: 1
}
});
this.add(this.trainDepart);
}
}
setColor(color) {
this.create();
this.trainDepart.setStyle('textFill', color);
}
hideMode() {
this.trainDepart && this.trainDepart.hide();
this.time && clearInterval(this.time);
}
showMode() {
this.timeStart = 30;
this.create(`0${this.timeStart}`);
this.trainDepart.show();
setTimeout(() => {
this.animition();
}, 1000);
}
animition() {
this.time && clearInterval(this.time);
this.time = setInterval(() => {
this.timeStart--;
if (this.timeStart >= 0) {
if (this.timeStart < 10) {
this.trainDepart.setStyle('text', `00${this.timeStart}`);
} else {
this.trainDepart.setStyle('text', `0${this.timeStart}`);
}
} else {
clearInterval(this.time);
}
}, 1000);
}
}
export default ETrainDepart;