From 78fc54f5fb84d3b4f6973b45eb029ac73c114383 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Fri, 16 Oct 2015 14:00:01 +0300 Subject: [PATCH] automate select near land marks on edit system --- .../trader/controllers/ProfileController.java | 2 +- .../controllers/SystemsEditorController.java | 47 +++++++++++++++++++ .../java/ru/trader/model/MarketModel.java | 8 ++++ .../java/ru/trader/model/ProfileModel.java | 19 +++++++- client/src/main/resources/view/sEditor.fxml | 30 +++++++++--- core/src/main/java/ru/trader/core/Market.java | 43 ++++++++++++++++- 6 files changed, 139 insertions(+), 10 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/ProfileController.java b/client/src/main/java/ru/trader/controllers/ProfileController.java index e312e6b..a1e3e05 100644 --- a/client/src/main/java/ru/trader/controllers/ProfileController.java +++ b/client/src/main/java/ru/trader/controllers/ProfileController.java @@ -164,7 +164,7 @@ public class ProfileController { profile.shipTankProperty().addListener(tankListener); profile.shipCargoProperty().addListener(cargoListener); profile.shipEngineProperty().addListener(engineListener); - jumpRange.textProperty().bind(Bindings.createStringBinding(()-> String.format("%.1f - %.1f", profile.getShipJumpRange(), profile.getMaxShipJumpRange()), + jumpRange.textProperty().bind(Bindings.createStringBinding(()-> String.format("%.1f - %.1f - %.1f", profile.getShipJumpRange(), profile.getMaxShipJumpRange(), profile.getEmptyMaxShipJumpRange()), profile.shipMassProperty(), profile.shipCargoProperty(), profile.shipTankProperty(), profile.shipEngineProperty() )); } diff --git a/client/src/main/java/ru/trader/controllers/SystemsEditorController.java b/client/src/main/java/ru/trader/controllers/SystemsEditorController.java index 37667bc..bd34aa7 100644 --- a/client/src/main/java/ru/trader/controllers/SystemsEditorController.java +++ b/client/src/main/java/ru/trader/controllers/SystemsEditorController.java @@ -12,8 +12,10 @@ import javafx.util.converter.DefaultStringConverter; import javafx.util.converter.DoubleStringConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ru.trader.Main; import ru.trader.model.MarketModel; import ru.trader.model.ModelFabric; +import ru.trader.model.ProfileModel; import ru.trader.model.SystemModel; import ru.trader.model.support.PositionComputer; import ru.trader.view.support.Localization; @@ -168,12 +170,27 @@ public class SystemsEditorController { private void fill(SystemModel system){ if (system != null){ tblSystems.getItems().add(new SystemData(system)); + ProfileModel profile = MainController.getProfile(); + SystemModel s = profile.getPrevSystem(); + if (!ModelFabric.isFake(s)){ + searchLandMark(s, profile.getEmptyMaxShipJumpRange()*1.5); + } } for (int i = 0; i < 10; i++) { add(); } } + private void searchLandMark(SystemModel system, double maxDistance){ + double x = system.getX(), y = system.getY(), z = system.getZ(), e = 6; + system1.setValue(market.getNear(x + maxDistance, y, z, Double.POSITIVE_INFINITY, e, e)); + system2.setValue(market.getNear(x - maxDistance, y, z, Double.NEGATIVE_INFINITY, e, e)); + system3.setValue(market.getNear(x, y + maxDistance, z, e, Double.POSITIVE_INFINITY, e)); + system4.setValue(market.getNear(x, y - maxDistance, z, e, Double.NEGATIVE_INFINITY, e)); + system5.setValue(market.getNear(x, y, z + maxDistance, e, e, Double.POSITIVE_INFINITY)); + system6.setValue(market.getNear(x, y, z - maxDistance, e, e, Double.NEGATIVE_INFINITY)); + } + public void add(){ tblSystems.getItems().add(new SystemData()); } @@ -202,6 +219,36 @@ public class SystemsEditorController { } } + @FXML + private void copySys1(){ + Main.copyToClipboard(system1Text.getText()); + } + + @FXML + private void copySys2(){ + Main.copyToClipboard(system2Text.getText()); + } + + @FXML + private void copySys3(){ + Main.copyToClipboard(system3Text.getText()); + } + + @FXML + private void copySys4(){ + Main.copyToClipboard(system4Text.getText()); + } + + @FXML + private void copySys5(){ + Main.copyToClipboard(system5Text.getText()); + } + + @FXML + private void copySys6(){ + Main.copyToClipboard(system6Text.getText()); + } + private void commit(){ for (SystemData systemData : tblSystems.getItems()) { systemData.commit(); diff --git a/client/src/main/java/ru/trader/model/MarketModel.java b/client/src/main/java/ru/trader/model/MarketModel.java index b0c59cb..2eea5a5 100644 --- a/client/src/main/java/ru/trader/model/MarketModel.java +++ b/client/src/main/java/ru/trader/model/MarketModel.java @@ -92,6 +92,14 @@ public class MarketModel { return modeler.get(s); } + public SystemModel getNear(double x, double y, double z, double xlimit, double ylimit, double zlimit){ + Place s = market.getNear(x, y, z, xlimit, ylimit, zlimit); + if (s == null){ + return ModelFabric.NONE_SYSTEM; + } + return modeler.get(s); + } + public SystemModel add(String name, double x, double y, double z) { SystemModel system = modeler.get(market.addPlace(name, x, y, z)); LOG.info("Add system {} to market {}", system, this); diff --git a/client/src/main/java/ru/trader/model/ProfileModel.java b/client/src/main/java/ru/trader/model/ProfileModel.java index 0ee81c4..125463f 100644 --- a/client/src/main/java/ru/trader/model/ProfileModel.java +++ b/client/src/main/java/ru/trader/model/ProfileModel.java @@ -14,6 +14,7 @@ public class ProfileModel { private final MarketModel market; private final StringProperty name; private final DoubleProperty balance; + private final ObjectProperty prevSystem; private final ObjectProperty system; private final ObjectProperty station; private final BooleanProperty docked; @@ -29,6 +30,7 @@ public class ProfileModel { name = new SimpleStringProperty(); balance = new SimpleDoubleProperty(); system = new SimpleObjectProperty<>(); + prevSystem = new SimpleObjectProperty<>(); station = new SimpleObjectProperty<>(); docked = new SimpleBooleanProperty(); shipMass = new SimpleDoubleProperty(); @@ -45,7 +47,10 @@ public class ProfileModel { balance.addListener((ov, o, n) -> LOG.debug("Change balance, old: {}, new: {}", o, n)); system.addListener((ov, o, n) -> { LOG.debug("Change system, old: {}, new: {}", o, n); - if (route.getValue() != null) {getRoute().updateCurrentEntry(n);} + if (!ModelFabric.isFake(o)) prevSystem.setValue(o); + if (!ModelFabric.isFake(n)){ + if (route.getValue() != null) {getRoute().updateCurrentEntry(n);} + } }); station.addListener((ov, o, n) -> { LOG.debug("Change station, old: {}, new: {}", o, n); @@ -96,6 +101,14 @@ public class ProfileModel { this.balance.set(balance); } + public SystemModel getPrevSystem() { + return prevSystem.get(); + } + + public ReadOnlyObjectProperty prevSystemProperty() { + return prevSystem; + } + public SystemModel getSystem() { return system.get(); } @@ -207,6 +220,10 @@ public class ProfileModel { return profile.getShip().getMaxJumpRange(); } + public double getEmptyMaxShipJumpRange(){ + return profile.getShip().getEmptyMaxJumpRange(); + } + private void refresh(){ name.setValue(profile.getName()); balance.setValue(profile.getBalance()); diff --git a/client/src/main/resources/view/sEditor.fxml b/client/src/main/resources/view/sEditor.fxml index eb74fd3..b81ccd8 100644 --- a/client/src/main/resources/view/sEditor.fxml +++ b/client/src/main/resources/view/sEditor.fxml @@ -23,12 +23,30 @@