Browse Source

GUI improvements

master
Stephan Richter 4 years ago
parent
commit
005ff02646
  1. 2
      pom.xml
  2. 1
      resources/js/plan.js
  3. 2
      resources/translations/Application.de.translation
  4. 2
      src/main/java/de/srsoftware/web4rail/Plan.java
  5. 53
      src/main/java/de/srsoftware/web4rail/moving/Train.java
  6. 18
      src/main/java/de/srsoftware/web4rail/tiles/Tile.java

2
pom.xml

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.5.24</version>
<version>1.5.25</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

1
resources/js/plan.js

@ -310,6 +310,7 @@ function runAction(ev){ @@ -310,6 +310,7 @@ function runAction(ev){
function stream(ev){
var data = ev.data;
data = data.replace(/%newline%/g,"\n");
console.log("received: ",data);
if (data.startsWith('<svg')) return place(data);
if (data.startsWith("heartbeat")) return heartbeat(data);

2
resources/translations/Application.de.translation

@ -421,7 +421,7 @@ Swap order : Reihenfolge umkehren @@ -421,7 +421,7 @@ Swap order : Reihenfolge umkehren
Swap order of trains : Reihenfolge der Züge tauschen
Switch : Schalter
SwitchFunction : Funktion schalten
SwitchIsOn : Schalter is an
SwitchIsOn : Schalter ist an
Switch power off : Strom ausschalten
Switch power on : Strom anschalten
SYSTEM : Betriebssystem

2
src/main/java/de/srsoftware/web4rail/Plan.java

@ -976,7 +976,7 @@ public class Plan extends BaseClass{ @@ -976,7 +976,7 @@ public class Plan extends BaseClass{
* @param data
*/
public synchronized void stream(String data) {
String fixedData = data.replaceAll("\n", "").replaceAll("\r", "");
String fixedData = data.replaceAll("\n", "%newline%").replaceAll("\r", "");
new Thread("Plan") {
@Override
public void run() {

53
src/main/java/de/srsoftware/web4rail/moving/Train.java

@ -319,6 +319,7 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -319,6 +319,7 @@ public class Train extends BaseClass implements Comparable<Train> {
public void coupleWith(Train parkingTrain,boolean swap) {
if (isSet(direction) && isSet(parkingTrain.direction) && parkingTrain.direction != direction) parkingTrain.turn();
boolean locoOnly = !cars.stream().anyMatch(car -> !(car instanceof Locomotive));
if (swap) {
Vector<Car> dummy = new Vector<Car>();
for (Car car : parkingTrain.cars) dummy.add(car.train(this));
@ -329,9 +330,9 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -329,9 +330,9 @@ public class Train extends BaseClass implements Comparable<Train> {
cars.add(car.train(this));
}
}
if (locoOnly && isSet(parkingTrain.name)) name = parkingTrain.name;
parkingTrain.remove();
updateEnds();
updateEnds();
if (isSet(currentBlock)) currentBlock.setTrain(this);
}
@ -411,6 +412,10 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -411,6 +412,10 @@ public class Train extends BaseClass implements Comparable<Train> {
public Direction direction() {
return direction;
}
public void disableShunting() {
shunting = false;
}
private Object dropCar(Params params) {
String carId = params.getString(CAR_ID);
@ -457,7 +462,8 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -457,7 +462,8 @@ public class Train extends BaseClass implements Comparable<Train> {
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
Block endBlock = endedRoute.endBlock();
Block startBlock = endedRoute.startBlock();
if (endBlock == destination) {
boolean resetDest = endBlock == destination;
if (resetDest){
destination = null;
String destTag = destinationTag();
@ -507,7 +513,8 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -507,7 +513,8 @@ public class Train extends BaseClass implements Comparable<Train> {
if ((!autopilot) || isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
route = null;
endBlock.setTrain(this);
shunting = false; // wird in setTrain verwendet, muss also danach stehen
shunting = false; // is used in endBlock.setTrain(…), this it must be set thereafter
if (resetDest) destination = null; // destination is called during endBlock.setTrain(…)
currentBlock = endBlock;
trace.add(endBlock);
if (!trace.contains(startBlock)) startBlock.dropTrain(this);
@ -724,13 +731,27 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -724,13 +731,27 @@ public class Train extends BaseClass implements Comparable<Train> {
public String name() {
if (isSet(name)) return name;
if (isSet(name) && !name.isEmpty()) return name;
if (cars.isEmpty()) return t("emtpy train");
StringBuffer sb = new StringBuffer();
String lastName = null;
int count = 0;
for (Car car : cars) {
String name = car.name();
if (isSet(name)) return name;
String carName = car.name();
if (isNull(carName)) continue;
if (carName.equals(lastName)) {
count++;
} else {
if (count>1) sb.append("x").append(count);
count = 1;
lastName = carName;
sb.append(", ").append(carName);
}
}
return t("empty train");
if (count>1) sb.append("x").append(count);
if (sb.length()>2) sb.delete(0, 2);
return sb.toString();
//return t("empty train");
}
private Train name(String newName) {
@ -955,17 +976,13 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -955,17 +976,13 @@ public class Train extends BaseClass implements Comparable<Train> {
public boolean splitAfter(int position) {
if (isNull(currentBlock)) return false; // can only split within blocks!
Train remaining = new Train();
remaining.name = name;
int len = cars.size();
for (int i=0; i<len; i++) {
if (i>=position) {
Car car = cars.remove(position);
LOG.debug("Moving {} from {} to {}",car,this,remaining);
remaining.add(car);
if (isNull(remaining.name)) {
remaining.name = car.name();
} else if (remaining.name.length()+car.name().length()<30){
remaining.name += ", "+car.name();
}
} else LOG.debug("Skipping {}",cars.get(i));
}
if (remaining.cars.isEmpty()) return false;
@ -1159,23 +1176,23 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -1159,23 +1176,23 @@ public class Train extends BaseClass implements Comparable<Train> {
for (Tile tile : reversedPath) {
if (isNull(remainingLength) && onTrace(tile)) remainingLength = length();
if (remainingLength == null) { // ahead of train
LOG.debug("{} is ahead of train and will not be touched.",tile);
//LOG.debug("{} is ahead of train and will not be touched.",tile);
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
} else if (remainingLength > 0) { // within train
LOG.debug("{} is occupied by train and will be marked as \"occupied\"",tile);
//LOG.debug("{} is occupied by train and will be marked as \"occupied\"",tile);
remainingLength -= tile.length();
newTrace.add(tile);
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
tile.setTrain(this);
LOG.debug("remaining length: {}",remainingLength);
//LOG.debug("remaining length: {}",remainingLength);
} else { // behind train
if (Route.freeBehindTrain) {
LOG.debug("{} is behind train and will be freed in the next step",tile);
//LOG.debug("{} is behind train and will be freed in the next step",tile);
if (tile != route.endBlock()) { // if train is shorter than contact after endblock, the endblock would be cleared…
trace.add(tile); // old trace will be cleared afterwards
}
} else {
LOG.debug("{} is behind train and will be reset to \"locked\" state",tile);
//LOG.debug("{} is behind train and will be reset to \"locked\" state",tile);
tile.lockFor(context,true);
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
}

18
src/main/java/de/srsoftware/web4rail/tiles/Tile.java

@ -468,7 +468,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> { @@ -468,7 +468,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
if (isSet(reservingTrain) && newTrain != reservingTrain) return false;
if (isSet(lockingTrain) && newTrain != lockingTrain) return false;
if (isSet(occupyingTrain) && (newTrain != occupyingTrain) && !newTrain.isShunting()) return false;
reservingTrain = lockingTrain = null;
lockingTrain = reservingTrain = null;
if (occupyingTrain == newTrain) return true;
occupyingTrain = newTrain;
plan.place(this);
@ -539,12 +539,9 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> { @@ -539,12 +539,9 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
sb.append(", ");
sb.append(y);
sb.append(")");
if (isSet(occupyingTrain)) {
sb.append("\n");
sb.append(occupyingTrain);
sb.append(":\n");
occupyingTrain.cars().forEach(car -> sb.append("\t"+car+"\n"));
}
if (isSet(occupyingTrain))
sb.append(title(occupyingTrain));
return sb.toString();
}
@ -555,8 +552,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> { @@ -555,8 +552,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
sb.append(train.length());
sb.append(" ");
sb.append(t(lengthUnit));
sb.append("):\n");
train.cars().forEach(car -> sb.append("\t"+car+"\n"));
sb.append(")");
Block dest = train.destination();
if (isSet(dest)) sb.append(" → ").append(dest);
sb.append(":\n");
train.cars().forEach(car -> sb.append("\t- ").append(car).append("\n"));
return sb.toString();
}

Loading…
Cancel
Save