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

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-11-29 12:51:58 +08:00
import Group from 'zrender/src/container/Group';
import Text from 'zrender/src/graphic/Text';
class ELevel extends Group {
constructor(model) {
super();
this.model = model;
2020-03-27 10:17:24 +08:00
this.level = null;
this.isNew = false;
}
create() {
if (!this.isNew) {
2020-09-09 13:55:42 +08:00
const model = this.model.modelData;
const style = this.model.style;
this.isNew = true;
2020-09-09 13:55:42 +08:00
const levelDrict = model.right ? 1 : -1;
const levelX = model.position.x - levelDrict * (style.StationStand.level.offset.x - model.width / 2);
const levelY = model.position.y + levelDrict * (style.StationStand.level.offset.y);
this.level = new Text({
2020-09-09 13:55:42 +08:00
zlevel: this.model.zlevel,
z: this.model.z,
style: {
2020-09-09 13:55:42 +08:00
x: levelX,
y: levelY,
2020-03-27 10:17:24 +08:00
fontWeight: style.textStyle.fontWeight,
2020-09-09 13:55:42 +08:00
fontSize: style.StationStand.level.textFontSize,
fontFamily: style.fontFamily,
2020-09-09 13:55:42 +08:00
text: model.runLevelTime || '5',
textFill: style.StationStand.level.textColor,
2020-03-27 10:17:24 +08:00
textAlign: style.textStyle.textAlign,
textVerticalAlign: style.textStyle.textVerticalAlign
}
});
this.add(this.level);
}
}
setName(val) {
this.level.setStyle('text', val);
}
setColor(color) {
this.create();
this.level.setStyle('textFill', color);
}
2020-03-27 17:26:17 +08:00
hideMode() {
2020-03-27 10:17:24 +08:00
this.level && this.level.hide();
}
2020-03-27 17:26:17 +08:00
showMode() {
this.create();
this.level.show();
}
2020-09-09 13:55:42 +08:00
recover() {
this.hideMode();
}
2020-09-15 17:08:28 +08:00
setState(model) {
2020-09-15 18:28:32 +08:00
// 运行等级
2020-09-15 17:08:28 +08:00
if (Number(model.runLevelTime) > 0) {
this.showMode();
this.setName(model.runLevelTime);
}
}
2019-11-29 12:51:58 +08:00
}
export default ELevel;