implemented selection of train destination
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>0.11.2</version>
|
<version>0.11.3</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ var selected = null;
|
|||||||
var mode = null;
|
var mode = null;
|
||||||
var messageTimer = null;
|
var messageTimer = null;
|
||||||
var messageOpacity = 0;
|
var messageOpacity = 0;
|
||||||
|
var trainAwaitingDestination = null;
|
||||||
|
|
||||||
function addClass(data){
|
function addClass(data){
|
||||||
parts = data.split(" ");
|
parts = data.split(" ");
|
||||||
@@ -32,7 +33,16 @@ function addTile(x,y){
|
|||||||
|
|
||||||
function clickTile(x,y){
|
function clickTile(x,y){
|
||||||
var id = x+"-"+y;
|
var id = x+"-"+y;
|
||||||
if ($('#'+id).length > 0) request({realm:'plan',action:'click',id:id});
|
var tiles = $('#'+id);
|
||||||
|
if (tiles.length > 0) {
|
||||||
|
if (trainAwaitingDestination != null && tiles.hasClass("Block")) {
|
||||||
|
request({realm:'train',id:trainAwaitingDestination,action:MOVE,destination:id});
|
||||||
|
trainAwaitingDestination = null;
|
||||||
|
$(PLAN).css('cursor','');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
request({realm:'plan',action:'click',id:id});
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +189,13 @@ function runAction(ev){
|
|||||||
} else return request({action:ev.target.id,realm:realm}); // TODO: ask for name
|
} else return request({action:ev.target.id,realm:realm}); // TODO: ask for name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectDest(trainId){
|
||||||
|
trainAwaitingDestination = trainId;
|
||||||
|
closeWindows();
|
||||||
|
$(PLAN).css('cursor','help');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function stream(ev){
|
function stream(ev){
|
||||||
var data = ev.data;
|
var data = ev.data;
|
||||||
console.log("received: ",data);
|
console.log("received: ",data);
|
||||||
|
|||||||
@@ -71,10 +71,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
||||||
|
|
||||||
private static final String TAGS = "tags";
|
private static final String TAGS = "tags";
|
||||||
|
|
||||||
|
private static final String DESTINATION = "destination";
|
||||||
|
|
||||||
private HashSet<String> tags = new HashSet<String>();
|
private HashSet<String> tags = new HashSet<String>();
|
||||||
|
|
||||||
private Block block = null;
|
private Block block,destination = null;
|
||||||
LinkedList<Tile> trace = new LinkedList<Tile>();
|
LinkedList<Tile> trace = new LinkedList<Tile>();
|
||||||
|
|
||||||
private class Autopilot extends Thread{
|
private class Autopilot extends Thread{
|
||||||
@@ -139,6 +141,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return train.automatic();
|
return train.automatic();
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
return train.dropCar(params);
|
return train.dropCar(params);
|
||||||
|
case ACTION_MOVE:
|
||||||
|
return train.setDestination(params);
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return train.props();
|
return train.props();
|
||||||
case ACTION_QUIT:
|
case ACTION_QUIT:
|
||||||
@@ -154,7 +158,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToTrace(Vector<Tile> newTiles) {
|
public void addToTrace(Vector<Tile> newTiles) {
|
||||||
boolean active = trace.isEmpty();
|
boolean active = trace.isEmpty();
|
||||||
for (Tile tile : newTiles) {
|
for (Tile tile : newTiles) {
|
||||||
@@ -239,7 +243,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private Tag carList() {
|
private Tag carList() {
|
||||||
Tag locoProp = new Tag("li").content(t("Cars:"));
|
Tag locoProp = new Tag("li").content(t("Cars:"));
|
||||||
Tag locoList = new Tag("ul").clazz("carlist");
|
Tag locoList = new Tag("ul").clazz("carlist").content("");
|
||||||
|
|
||||||
for (Car car : this.cars) {
|
for (Car car : this.cars) {
|
||||||
Tag li = new Tag("li");
|
Tag li = new Tag("li");
|
||||||
@@ -482,6 +486,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
ul.addTo(li).addTo(propList);
|
ul.addTo(li).addTo(propList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tag dest = new Tag("li").content(t("Destination: "));
|
||||||
|
if (isNull(destination)) {
|
||||||
|
new Button(t("Select from plan"),"return selectDest("+id+");").addTo(dest);
|
||||||
|
} else {
|
||||||
|
link("span",Map.of(REALM,REALM_PLAN,ID,destination.id(),ACTION,ACTION_CLICK),destination.toString()).addTo(dest);
|
||||||
|
}
|
||||||
|
dest.addTo(propList);
|
||||||
|
|
||||||
if (isSet(block)) {
|
if (isSet(block)) {
|
||||||
link("li",Map.of(REALM,REALM_PLAN,ID,block.id(),ACTION,ACTION_CLICK),t("Current location: {}",block)).addTo(propList);
|
link("li",Map.of(REALM,REALM_PLAN,ID,block.id(),ACTION,ACTION_CLICK),t("Current location: {}",block)).addTo(propList);
|
||||||
Tag actions = new Tag("li").clazz().content(t("Actions:")+NBSP);
|
Tag actions = new Tag("li").clazz().content(t("Actions:")+NBSP);
|
||||||
@@ -548,6 +560,18 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (isSet(block)) block.set(this);
|
if (isSet(block)) block.set(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String setDestination(HashMap<String, String> params) {
|
||||||
|
String dest = params.get(DESTINATION);
|
||||||
|
if (isNull(dest)) return t("No destination supplied!");
|
||||||
|
Tile tile = plan.get(dest, true);
|
||||||
|
if (isNull(tile)) return t("Tile {} not known!",dest);
|
||||||
|
if (tile instanceof Block) {
|
||||||
|
destination = (Block) tile;
|
||||||
|
return t("{} now heading for {}",this,destination);
|
||||||
|
}
|
||||||
|
return t("{} is not a block!",tile);
|
||||||
|
}
|
||||||
|
|
||||||
public void setSpeed(int v) {
|
public void setSpeed(int v) {
|
||||||
for (Locomotive loco : locos) loco.setSpeed(v);
|
for (Locomotive loco : locos) loco.setSpeed(v);
|
||||||
this.speed = v;
|
this.speed = v;
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ public abstract class Block extends StretchableTile{
|
|||||||
replacements.put("%text%",name);
|
replacements.put("%text%",name);
|
||||||
if (isSet(train)) replacements.put("%text%",train.directedName());
|
if (isSet(train)) replacements.put("%text%",train.directedName());
|
||||||
Tag tag = super.tag(replacements);
|
Tag tag = super.tag(replacements);
|
||||||
if (isSet(train)) tag.clazz(tag.get("class")+" occupied");
|
tag.clazz(tag.get("class")+" Block");
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,4 +355,4 @@ public abstract class Block extends StretchableTile{
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
import de.srsoftware.web4rail.tiles.Turnout.State;
|
import de.srsoftware.web4rail.tiles.Turnout.State;
|
||||||
@@ -25,4 +27,11 @@ public class Shadow extends Tile{
|
|||||||
public Tile overlay() {
|
public Tile overlay() {
|
||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
Tag tag = super.tag(replacements);
|
||||||
|
if (overlay instanceof Block) tag.attr("class", tag.get("class")+" Block");
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user