rt-sim-training-client/src/jmapNew/shape/StationStand/ETrainDepart.js

96 lines
2.9 KiB
JavaScript
Raw Normal View History

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;
2020-03-02 16:54:36 +08:00
const gag = 22;
this.isNew = true;
2020-03-02 16:54:36 +08:00
let cy = model.inside ? model.y + gag : model.y - gag;
2020-02-04 11:25:21 +08:00
let cx = model.inside ? model.x - model.width / 4 - model.width / 8 : model.x + model.width / 4 + model.width / 8;
if (model.right) {
if (model.inside) {
2020-03-02 16:54:36 +08:00
cy = model.y - gag;
2020-02-04 11:25:21 +08:00
cx = model.x + model.width / 4 + model.width / 8;
} else {
2020-03-02 16:54:36 +08:00
cy = model.y + gag;
2020-02-04 11:25:21 +08:00
cx = model.x - model.width / 4 - model.width / 8;
}
} else {
if (model.inside) {
2020-03-02 16:54:36 +08:00
cy = model.y + gag;
2020-02-04 11:25:21 +08:00
cx = model.x - model.width / 4 - model.width / 8;
} else {
2020-03-02 16:54:36 +08:00
cy = model.y - gag;
2020-02-04 11:25:21 +08:00
cx = model.x + model.width / 4 + model.width / 8;
}
}
this.trainDepart = new Text({
zlevel: model.zlevel,
z: model.z,
position: [0, 0],
style: {
x: cx,
y: cy,
text: text,
textAlign: 'middle',
fontSize: `${style.StationStand.detainCar.fontSize} px ${style.fontFamily}`,
textFill: 'green',
textVerticalAlign: 'middle',
textBorderColor: 'green',
textPadding: 2,
textBorderWidth: 1
}
});
this.add(this.trainDepart);
}
}
setColor(color) {
this.create();
this.trainDepart.setStyle('textFill', color);
}
hide() {
this.create();
this.trainDepart.hide();
this.time && clearInterval(this.time);
}
show() {
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;