route edit prototype
This commit is contained in:
@@ -6,13 +6,18 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.Pane;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Track;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
import ru.trader.view.support.autocomplete.AutoCompletion;
|
||||
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||
import ru.trader.view.support.autocomplete.SystemsProvider;
|
||||
import ru.trader.view.support.cells.OrderListCell;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
@@ -47,6 +52,11 @@ public class RouteTrackController {
|
||||
private MissionsController missionsController;
|
||||
@FXML
|
||||
private Pane track;
|
||||
@FXML
|
||||
private TextField newEntrySystemText;
|
||||
private AutoCompletion<SystemModel> newEntrySystem;
|
||||
@FXML
|
||||
private ComboBox<String> newEntryStation;
|
||||
|
||||
private RouteModel route;
|
||||
private Track trackNode;
|
||||
@@ -58,12 +68,25 @@ public class RouteTrackController {
|
||||
sellOrders.setCellFactory(new OrderListCell(true));
|
||||
editGroup.setVisible(false);
|
||||
init();
|
||||
newEntrySystem.valueProperty().addListener((ov, o , n) -> {
|
||||
newEntryStation.setItems(n.getStationNamesList());
|
||||
newEntryStation.getSelectionModel().selectFirst();
|
||||
});
|
||||
}
|
||||
|
||||
void init(){
|
||||
ProfileModel profile = MainController.getProfile();
|
||||
profile.routeProperty().addListener(routeListener);
|
||||
setRoute(profile.getRoute());
|
||||
MarketModel market = MainController.getMarket();
|
||||
SystemsProvider provider = market.getSystemsProvider();
|
||||
if (newEntrySystem == null){
|
||||
newEntrySystem = new AutoCompletion<>(newEntrySystemText, new CachedSuggestionProvider<>(provider), ModelFabric.NONE_SYSTEM, provider.getConverter());
|
||||
} else {
|
||||
newEntrySystem.setSuggestions(provider.getPossibleSuggestions());
|
||||
newEntrySystem.setConverter(provider.getConverter());
|
||||
}
|
||||
newEntryStation.setValue(ModelFabric.NONE_STATION.getName());
|
||||
}
|
||||
|
||||
void unbind(){
|
||||
@@ -173,6 +196,39 @@ public class RouteTrackController {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addEntry(){
|
||||
SystemModel toSystem = newEntrySystem.getValue();
|
||||
StationModel toStation = toSystem != null ? toSystem.get(newEntryStation.getValue()) : ModelFabric.NONE_STATION;
|
||||
if (!ModelFabric.isFake(toSystem)){
|
||||
if (route != null){
|
||||
if (!ModelFabric.isFake(toStation)){
|
||||
setRoute(route.add(toStation));
|
||||
} else {
|
||||
setRoute(route.add(toSystem));
|
||||
}
|
||||
} else {
|
||||
RouteModel r;
|
||||
if (!ModelFabric.isFake(toStation)){
|
||||
r = RouteModel.asRoute(toStation);
|
||||
} else {
|
||||
r = RouteModel.asRoute(toSystem);
|
||||
}
|
||||
setRoute(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void setActive(){
|
||||
MainController.getProfile().setRoute(route);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void clear(){
|
||||
setRoute(null);
|
||||
}
|
||||
|
||||
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setIndex(n.intValue()));
|
||||
private final InvalidationListener activeEntryListener = ov -> ViewUtils.doFX(this::update);
|
||||
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> ViewUtils.doFX(() -> setRoute(n));
|
||||
|
||||
@@ -129,6 +129,20 @@ public class RouteModel {
|
||||
return getCopy();
|
||||
}
|
||||
|
||||
public RouteModel add(SystemModel system){
|
||||
RouteEntryModel last = entries.get(entries.size()-1);
|
||||
StationModel fromStation = last.getStation();
|
||||
RouteModel path = market.getPath(fromStation.getSystem(), fromStation, system, ModelFabric.NONE_STATION);
|
||||
return add(path);
|
||||
}
|
||||
|
||||
public RouteModel add(StationModel station){
|
||||
RouteEntryModel last = entries.get(entries.size()-1);
|
||||
StationModel fromStation = last.getStation();
|
||||
RouteModel path = market.getPath(fromStation.getSystem(), fromStation, station.getSystem(), station);
|
||||
return add(path);
|
||||
}
|
||||
|
||||
public RouteModel add(RouteModel route){
|
||||
_route.join(route.getRoute());
|
||||
return getCopy();
|
||||
@@ -352,4 +366,15 @@ public class RouteModel {
|
||||
}
|
||||
fillSellOrders();
|
||||
}
|
||||
|
||||
public static RouteModel asRoute(SystemModel system){
|
||||
Route route = new Route(new RouteEntry(system.getSystem().asTransit(),0,0,0));
|
||||
return new RouteModel(route, system.getMarket());
|
||||
}
|
||||
|
||||
public static RouteModel asRoute(StationModel station){
|
||||
Route route = new Route(new RouteEntry(station.getStation(),0,0,0));
|
||||
return new RouteModel(route, station.getMarket());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ public class StationModel {
|
||||
return station;
|
||||
}
|
||||
|
||||
MarketModel getMarket(){
|
||||
return market;
|
||||
}
|
||||
|
||||
public String getName() {return station.getName();}
|
||||
|
||||
public void setName(String value) {
|
||||
|
||||
@@ -37,6 +37,10 @@ public class SystemModel {
|
||||
return system;
|
||||
}
|
||||
|
||||
MarketModel getMarket(){
|
||||
return market;
|
||||
}
|
||||
|
||||
public String getName() {return name != null ? name.get() : system.getName();}
|
||||
|
||||
public void setName(String value) {
|
||||
|
||||
@@ -46,6 +46,17 @@
|
||||
</VBox>
|
||||
</StackPane>
|
||||
</VBox>
|
||||
<VBox fx:id="track" minWidth="200"/>
|
||||
<VBox>
|
||||
<VBox fx:id="track" minWidth="200"/>
|
||||
<VBox>
|
||||
<HBox><TextField fx:id="newEntrySystemText"/></HBox>
|
||||
<HBox><ComboBox fx:id="newEntryStation"/></HBox>
|
||||
<HBox>
|
||||
<Button onAction="#addEntry"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
|
||||
<Button onAction="#setActive"><graphic><Glyph text="FontAwesome|MAP_MARKER"/></graphic></Button>
|
||||
<Button onAction="#clear"><graphic><Glyph text="FontAwesome|TRASH"/></graphic></Button>
|
||||
</HBox>
|
||||
</VBox>
|
||||
</VBox>
|
||||
|
||||
</HBox>
|
||||
|
||||
@@ -7,6 +7,7 @@ import ru.trader.core.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class RouteSearcher {
|
||||
|
||||
public List<Edge<Place>> getPath(Place from, Place to, Collection<Place> places){
|
||||
List<List<Edge<Place>>> res = search(from, to, places, 1, null);
|
||||
return res.isEmpty() ? null : res.get(0);
|
||||
return res.isEmpty() ? Collections.emptyList() : res.get(0);
|
||||
}
|
||||
|
||||
public List<List<Edge<Place>>> getPaths(Place from, Collection<Place> places){
|
||||
@@ -43,6 +44,7 @@ public class RouteSearcher {
|
||||
|
||||
private List<List<Edge<Place>>> search(Place source, Place target, Collection<Place> places, int count, RouteSpecification<Place> specification){
|
||||
Profile profile = scorer.getProfile();
|
||||
//TODO: fast search if source equals target
|
||||
LOG.trace("Start search path from {} to {} ", source, target);
|
||||
ConnectibleGraph<Place> graph = new ConnectibleGraph<>(profile, callback);
|
||||
LOG.trace("Build connectible graph");
|
||||
|
||||
Reference in New Issue
Block a user