diff --git a/client/src/main/java/ru/trader/controllers/RouteTrackController.java b/client/src/main/java/ru/trader/controllers/RouteTrackController.java index cf37b05..f5c58f3 100644 --- a/client/src/main/java/ru/trader/controllers/RouteTrackController.java +++ b/client/src/main/java/ru/trader/controllers/RouteTrackController.java @@ -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 newEntrySystem; + @FXML + private ComboBox 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 currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setIndex(n.intValue())); private final InvalidationListener activeEntryListener = ov -> ViewUtils.doFX(this::update); private final ChangeListener routeListener = (ov, o, n) -> ViewUtils.doFX(() -> setRoute(n)); diff --git a/client/src/main/java/ru/trader/model/RouteModel.java b/client/src/main/java/ru/trader/model/RouteModel.java index 7a4aaac..58989fe 100644 --- a/client/src/main/java/ru/trader/model/RouteModel.java +++ b/client/src/main/java/ru/trader/model/RouteModel.java @@ -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()); + } + } diff --git a/client/src/main/java/ru/trader/model/StationModel.java b/client/src/main/java/ru/trader/model/StationModel.java index 437afba..716845f 100644 --- a/client/src/main/java/ru/trader/model/StationModel.java +++ b/client/src/main/java/ru/trader/model/StationModel.java @@ -35,6 +35,10 @@ public class StationModel { return station; } + MarketModel getMarket(){ + return market; + } + public String getName() {return station.getName();} public void setName(String value) { diff --git a/client/src/main/java/ru/trader/model/SystemModel.java b/client/src/main/java/ru/trader/model/SystemModel.java index 6fb9f45..dbe1425 100644 --- a/client/src/main/java/ru/trader/model/SystemModel.java +++ b/client/src/main/java/ru/trader/model/SystemModel.java @@ -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) { diff --git a/client/src/main/resources/view/routeTrack.fxml b/client/src/main/resources/view/routeTrack.fxml index 6cc4cc9..1f0186f 100644 --- a/client/src/main/resources/view/routeTrack.fxml +++ b/client/src/main/resources/view/routeTrack.fxml @@ -46,6 +46,17 @@ - + + + + + + + + + + + + diff --git a/core/src/main/java/ru/trader/analysis/RouteSearcher.java b/core/src/main/java/ru/trader/analysis/RouteSearcher.java index 0eb2329..85443be 100644 --- a/core/src/main/java/ru/trader/analysis/RouteSearcher.java +++ b/core/src/main/java/ru/trader/analysis/RouteSearcher.java @@ -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> getPath(Place from, Place to, Collection places){ List>> res = search(from, to, places, 1, null); - return res.isEmpty() ? null : res.get(0); + return res.isEmpty() ? Collections.emptyList() : res.get(0); } public List>> getPaths(Place from, Collection places){ @@ -43,6 +44,7 @@ public class RouteSearcher { private List>> search(Place source, Place target, Collection places, int count, RouteSpecification specification){ Profile profile = scorer.getProfile(); + //TODO: fast search if source equals target LOG.trace("Start search path from {} to {} ", source, target); ConnectibleGraph graph = new ConnectibleGraph<>(profile, callback); LOG.trace("Build connectible graph");