diff --git a/client/src/main/java/ru/trader/controllers/RouterController.java b/client/src/main/java/ru/trader/controllers/RouterController.java index cbaa886..55152e3 100644 --- a/client/src/main/java/ru/trader/controllers/RouterController.java +++ b/client/src/main/java/ru/trader/controllers/RouterController.java @@ -1,7 +1,6 @@ package ru.trader.controllers; -import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; @@ -35,6 +34,9 @@ public class RouterController { @FXML private ScrollPane path; + @FXML + private Button addBtn; + @FXML private Button editBtn; @@ -117,6 +119,11 @@ public class RouterController { distance.setValue(Main.SETTINGS.getDistance()); jumps.setValue(Main.SETTINGS.getJumps()); + addBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> { + StationModel st = tStation.getValue(); + return st == null || st == ModelFabric.NONE_STATION; + }, tStation.valueProperty())); + editBtn.disableProperty().bind(tblOrders.getSelectionModel().selectedIndexProperty().isEqualTo(-1)); removeBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> { int sel = tblOrders.getSelectionModel().getSelectedIndex(); @@ -155,6 +162,7 @@ public class RouterController { totalBalance.add(order.getProfit()); source.setValue(order.getBuyer().getSystem()); sStation.setValue(order.getBuyer()); + target.setValue(ModelFabric.NONE_SYSTEM); balance.setDisable(true); } @@ -163,12 +171,27 @@ public class RouterController { totalBalance.sub(order.getProfit()); source.setValue(order.getSystem()); sStation.setValue(order.getStation()); + target.setValue(ModelFabric.NONE_SYSTEM); if (orders.isEmpty()) { balance.setDisable(false); source.setDisable(false); } } + public void addStationToRoute(){ + StationModel sS = sStation.getValue(); + StationModel tS = tStation.getValue(); + PathRouteModel r = market.getPath(sS, tS); + if (route != null){ + route = route.add(r); + } else { + route = r; + } + refreshPath(); + source.setValue(tS.getSystem()); + sStation.setValue(tS); + } + public void editOrders(){ OrderModel sel = tblOrders.getSelectionModel().getSelectedItem(); int index = tblOrders.getSelectionModel().getSelectedIndex(); @@ -195,6 +218,29 @@ public class RouterController { } } + public void recompute(){ + if (route != null){ + route.recompute(balance.getValue().doubleValue(), cargo.getValue().longValue()); + orders.clear(); + orders.addAll(route.getOrders()); + refreshPath(); + } + } + + public void rebuild(){ + if (route != null){ + PathRouteModel r = market.getRoute(route, balance.getValue().doubleValue()); + if (r != null){ + route = r; + orders.clear(); + orders.addAll(route.getOrders()); + refreshPath(); + } else { + recompute(); + } + } + } + public void removeAll(){ orders.clear(); totalBalance.setValue(balance.getValue()); @@ -256,14 +302,14 @@ public class RouterController { if (this.route == null){ this.route = route; } else { - this.route.add(route.getPath()); + this.route = this.route.add(route); } refreshPath(); } private void addOrderToPath(OrderModel order){ if (route != null){ - route.add(order); + route = route.add(order); } else { route = market.getPath(order); } diff --git a/client/src/main/java/ru/trader/model/MarketModel.java b/client/src/main/java/ru/trader/model/MarketModel.java index 0737e56..79e1d45 100644 --- a/client/src/main/java/ru/trader/model/MarketModel.java +++ b/client/src/main/java/ru/trader/model/MarketModel.java @@ -20,8 +20,6 @@ import ru.trader.services.OrdersSearchTask; import ru.trader.services.RoutesSearchTask; import ru.trader.view.support.Localization; -import java.util.Collection; -import java.util.concurrent.*; import java.util.function.Consumer; @@ -192,10 +190,22 @@ public class MarketModel { getRoutes(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result); } - PathRoute getPath(StationModel from, StationModel to) { + public PathRouteModel getRoute(PathRouteModel path, double balance) { + PathRoute p = analyzer.getPath(path.getPath().getEntries(), balance); + if (p == null) return null; + return modeler.get(p); + } + + PathRoute _getPath(StationModel from, StationModel to) { return analyzer.getPath(from.getStation(), to.getStation()); } + public PathRouteModel getPath(StationModel from, StationModel to) { + PathRoute p = analyzer.getPath(from.getStation(), to.getStation()); + if (p == null) return null; + return modeler.get(p); + } + public PathRouteModel getPath(OrderModel order) { PathRoute p = analyzer.getPath(order.getStation().getStation(), order.getBuyer().getStation()); if (p == null) return null; diff --git a/client/src/main/java/ru/trader/model/PathRouteModel.java b/client/src/main/java/ru/trader/model/PathRouteModel.java index 4df92c7..df7cc05 100644 --- a/client/src/main/java/ru/trader/model/PathRouteModel.java +++ b/client/src/main/java/ru/trader/model/PathRouteModel.java @@ -14,11 +14,11 @@ public class PathRouteModel { private final int refuels; private final int lands; - private final PathRoute path; + private final PathRoute _path; PathRouteModel(PathRoute path, MarketModel market) { this.market = market; - this.path = path; + this._path = path; PathRoute p = path.getRoot(); totalProfit = p.getProfit(); lands = p.getLandsCount(); @@ -51,7 +51,7 @@ public class PathRouteModel { } public PathRoute getPath() { - return path; + return _path; } public int getLands() { @@ -64,37 +64,48 @@ public class PathRouteModel { public Collection getOrders(){ Collection res = new ArrayList<>(lands); - PathRoute p = path.getRoot(); + PathRoute path = _path.getRoot(); Order cargo = null; - while (p.hasNext()){ - p = p.getNext(); - if (cargo == null && p.getBest()!=null){ - cargo = p.getBest(); + while (path.hasNext()){ + path = path.getNext(); + if (cargo == null && path.getBest()!=null){ + cargo = path.getBest(); OrderModel order = market.getModeler().get(cargo); - order.setPath(p); + order.setPath(path); res.add(order); } - if (cargo!=null && cargo.isBuyer(p.get())){ + if (cargo!=null && cargo.isBuyer(path.get())){ cargo = null; } } return res; } - public void add(OrderModel order){ - PathRoute p = market.getPath(order.getStation(), order.getBuyer()); - if (p == null) return; - p.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount())); - PathRoute head = path.getEnd(); - add(p); - order.setPath(head); + PathRoute _add(PathRoute route){ + return _path.add(route, true); } - public void add(PathRoute route){ - path.getEnd().add(route, true); + public PathRouteModel add(OrderModel order){ + PathRoute path = market._getPath(order.getStation(), order.getBuyer()); + if (path == null) return this; + path.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount())); + PathRoute head = _path.getEnd(); + PathRouteModel res = new PathRouteModel(_add(path), market); + order.setPath(head); + return res; + } + + public PathRouteModel add(PathRouteModel route){ + return new PathRouteModel(_add(route.getPath()), market); } public PathRouteModel remove(OrderModel order) { - return new PathRouteModel(path.dropTo(order.getStation().getStation()), market); + return new PathRouteModel(_path.dropTo(order.getStation().getStation()), market); } + + public void recompute(double balance, long cargo) { + _path.refresh(); + _path.sort(balance, cargo); + } + } diff --git a/client/src/main/resources/lang/locale_en_US.properties b/client/src/main/resources/lang/locale_en_US.properties index 434c311..272c67d 100644 --- a/client/src/main/resources/lang/locale_en_US.properties +++ b/client/src/main/resources/lang/locale_en_US.properties @@ -38,6 +38,7 @@ routes.lands=Landings # Dialog dialog.confirm.save=Changes were not saved, save changes? dialog.confirm.remove=Are you sure you want to delete %s? +dialog.button.add=Add dialog.button.save=Save dialog.button.edit=Edit dialog.button.remove=Remove @@ -115,6 +116,8 @@ router.pane.route=Route parameters router.pane.route.from=From: router.pane.route.to=To: router.pane.route.jumps=Jumps: +router.button.recompute=Recompute +router.button.rebuild=Rebuild router.button.top=TOP 100 router.pane.total=Total router.pane.total.profit=Profit: diff --git a/client/src/main/resources/lang/locale_ru_RU.properties b/client/src/main/resources/lang/locale_ru_RU.properties index bd786ff..6740a50 100644 --- a/client/src/main/resources/lang/locale_ru_RU.properties +++ b/client/src/main/resources/lang/locale_ru_RU.properties @@ -38,6 +38,7 @@ routes.lands=\u041F\u043E\u0441\u0430\u0434\u043E\u043A # Dialog dialog.confirm.save=\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u043D\u0435 \u0431\u044B\u043B\u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C? dialog.confirm.remove=\u0412\u044B \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C %s? +dialog.button.add=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C dialog.button.save=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C dialog.button.edit=\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C dialog.button.remove=\u0423\u0434\u0430\u043B\u0438\u0442\u044C @@ -115,6 +116,8 @@ router.pane.route=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u043C\ router.pane.route.from=\u041E\u0442: router.pane.route.to=\u0414\u043E: router.pane.route.jumps=\u041F\u0440\u044B\u0436\u043A\u043E\u0432: +router.button.recompute=\u041F\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u0442\u044C +router.button.rebuild=\u041F\u0435\u0440\u0435\u0441\u0442\u0440\u043E\u0438\u0442\u044C router.button.top=TOP 100 router.pane.total=\u0418\u0442\u043E\u0433\u043E router.pane.total.profit=\u041F\u0440\u0438\u0431\u044B\u043B\u044C: diff --git a/client/src/main/resources/view/items.fxml b/client/src/main/resources/view/items.fxml index 0f51c73..1ff791a 100644 --- a/client/src/main/resources/view/items.fxml +++ b/client/src/main/resources/view/items.fxml @@ -10,35 +10,35 @@ - + - + - + - + - + diff --git a/client/src/main/resources/view/offers.fxml b/client/src/main/resources/view/offers.fxml index a439ee3..c5db73a 100644 --- a/client/src/main/resources/view/offers.fxml +++ b/client/src/main/resources/view/offers.fxml @@ -18,11 +18,11 @@ - + - + diff --git a/client/src/main/resources/view/router.fxml b/client/src/main/resources/view/router.fxml index c24936c..3e655f0 100644 --- a/client/src/main/resources/view/router.fxml +++ b/client/src/main/resources/view/router.fxml @@ -15,12 +15,12 @@ - + - - + + - + - - + +