From 0dcabd50a320a44d866450231669f349bcaf03f0 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Fri, 9 Oct 2015 13:53:29 +0300 Subject: [PATCH] modify profile screen --- .../trader/controllers/HelperController.java | 9 +++- .../trader/controllers/ProfileController.java | 45 +++++++++++++--- .../controllers/RouteSearchController.java | 2 +- .../trader/controllers/RouterController.java | 2 +- .../java/ru/trader/controllers/Screeners.java | 4 +- .../java/ru/trader/model/ProfileModel.java | 51 ++++++++---------- client/src/main/resources/view/profile.fxml | 53 ++++++++++--------- 7 files changed, 98 insertions(+), 68 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/HelperController.java b/client/src/main/java/ru/trader/controllers/HelperController.java index 3cdc50a..f732acc 100644 --- a/client/src/main/java/ru/trader/controllers/HelperController.java +++ b/client/src/main/java/ru/trader/controllers/HelperController.java @@ -95,6 +95,7 @@ public class HelperController { } private void setDocked(boolean docked){ + if (route == null) return; if (docked && MainController.getProfile().getStation().equals(entry.getStation())){ showStationInfo(); } else { @@ -127,7 +128,7 @@ public class HelperController { resize(); } - public void show(Parent content) { + public void show(Parent content, boolean toggle) { if (stage == null){ stage = new Stage(); stage.setScene(new Scene(content)); @@ -136,7 +137,11 @@ public class HelperController { addDragListeners(content); stage.show(); } else { - stage.show(); + if (toggle && stage.isShowing()){ + stage.hide(); + } else { + stage.show(); + } } } diff --git a/client/src/main/java/ru/trader/controllers/ProfileController.java b/client/src/main/java/ru/trader/controllers/ProfileController.java index 04f13f1..91d54b0 100644 --- a/client/src/main/java/ru/trader/controllers/ProfileController.java +++ b/client/src/main/java/ru/trader/controllers/ProfileController.java @@ -1,13 +1,12 @@ package ru.trader.controllers; +import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.TextField; +import javafx.scene.control.*; +import javafx.scene.layout.Pane; import javafx.util.StringConverter; import ru.trader.core.Engine; import ru.trader.model.*; @@ -39,6 +38,12 @@ public class ProfileController { @FXML private ComboBox engine; @FXML + private Label jumpRange; + @FXML + private Pane profileInfo; + @FXML + private Pane shipInfo; + @FXML private Button btnAddSystem; @FXML private Button btnAddStation; @@ -55,14 +60,32 @@ public class ProfileController { system = new AutoCompletion<>(systemText, provider, ModelFabric.NONE_SYSTEM, provider.getConverter()); engine.setItems(FXCollections.observableList(Engine.getEngines())); engine.setConverter(new EngineStringConverter()); - btnAddSystem.setOnAction(e -> Screeners.showSystemsEditor(null)); - btnAddStation.setOnAction(e -> Screeners.showAddStation(profile.getSystem())); + btnAddSystem.setOnAction(e -> { + if (ModelFabric.isFake(profile.getSystem())) Screeners.showSystemsEditor(null); + else Screeners.showSystemsEditor(profile.getSystem()); + }); + btnAddStation.setOnAction(e -> { + if (ModelFabric.isFake(profile.getStation())) Screeners.showAddStation(profile.getSystem()); + else Screeners.showEditStation(profile.getStation()); + }); + shipInfo.setVisible(false); initListeners(); } @FXML - private void showHelper(){ - Screeners.showHelper(); + private void toggleShipInfo(){ + if (shipInfo.isVisible()){ + profileInfo.setVisible(true); + shipInfo.setVisible(false); + } else { + profileInfo.setVisible(false); + shipInfo.setVisible(true); + } + } + + @FXML + private void toggleHelper(){ + Screeners.toggleHelper(); } private void consumeChanges(Runnable runnable){ @@ -123,6 +146,11 @@ public class ProfileController { profile.shipTankProperty().addListener(tankListener); profile.shipCargoProperty().addListener(cargoListener); profile.shipEngineProperty().addListener(engineListener); + jumpRange.textProperty().bind(Bindings.createStringBinding(()-> { + return String.format("%.1f - %.1f", profile.getShipJumpRange(), profile.getMaxShipJumpRange()); + }, + profile.shipMassProperty(), profile.shipCargoProperty(), profile.shipTankProperty(), profile.shipEngineProperty() + )); } private void unbind(){ @@ -135,6 +163,7 @@ public class ProfileController { profile.shipTankProperty().removeListener(tankListener); profile.shipCargoProperty().removeListener(cargoListener); profile.shipEngineProperty().removeListener(engineListener); + jumpRange.textProperty().unbind(); } diff --git a/client/src/main/java/ru/trader/controllers/RouteSearchController.java b/client/src/main/java/ru/trader/controllers/RouteSearchController.java index 325c216..2d33460 100644 --- a/client/src/main/java/ru/trader/controllers/RouteSearchController.java +++ b/client/src/main/java/ru/trader/controllers/RouteSearchController.java @@ -84,7 +84,7 @@ public class RouteSearchController { RouteModel route = path.get(); route.addAll(0, missionsList.getItems()); profile.setRoute(route); - Screeners.showHelper(); + Screeners.toggleHelper(); } }); } diff --git a/client/src/main/java/ru/trader/controllers/RouterController.java b/client/src/main/java/ru/trader/controllers/RouterController.java index a77d34f..5e266bd 100644 --- a/client/src/main/java/ru/trader/controllers/RouterController.java +++ b/client/src/main/java/ru/trader/controllers/RouterController.java @@ -279,7 +279,7 @@ public class RouterController { if (path.isPresent()){ orders.addAll(path.get().getOrders()); addRouteToPath(path.get()); - Screeners.showHelper(); + Screeners.toggleHelper(); } }); } diff --git a/client/src/main/java/ru/trader/controllers/Screeners.java b/client/src/main/java/ru/trader/controllers/Screeners.java index 6fd7afc..d0f8532 100644 --- a/client/src/main/java/ru/trader/controllers/Screeners.java +++ b/client/src/main/java/ru/trader/controllers/Screeners.java @@ -247,8 +247,8 @@ public class Screeners { return dialog.showAndWait(); } - public static void showHelper(){ - helperController.show(helperScreen); + public static void toggleHelper(){ + helperController.show(helperScreen, true); } public static void reinitAll() { diff --git a/client/src/main/java/ru/trader/model/ProfileModel.java b/client/src/main/java/ru/trader/model/ProfileModel.java index c14eac4..0ee81c4 100644 --- a/client/src/main/java/ru/trader/model/ProfileModel.java +++ b/client/src/main/java/ru/trader/model/ProfileModel.java @@ -41,46 +41,24 @@ public class ProfileModel { } private void initListeners() { - name.addListener((ov, o, n) -> { - LOG.debug("Change name, old: {}, new: {}", o, n); - profile.setName(n); - }); - balance.addListener((ov, o, n) -> { - LOG.debug("Change balance, old: {}, new: {}", o, n); - profile.setBalance(n.doubleValue()); - }); + name.addListener((ov, o, n) -> LOG.debug("Change name, old: {}, new: {}", o, n)); + 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); - profile.setSystem(n != null && n != ModelFabric.NONE_SYSTEM ? n.getSystem() : null); if (route.getValue() != null) {getRoute().updateCurrentEntry(n);} }); station.addListener((ov, o, n) -> { LOG.debug("Change station, old: {}, new: {}", o, n); - profile.setStation(n != null && n != ModelFabric.NONE_STATION ? n.getStation() : null); if (route.getValue() != null) {getRoute().updateCurrentEntry(getSystem(), n);} }); docked.addListener((ov, o, n) -> { LOG.debug("Change docked, old: {}, new: {}", o, n); - profile.setDocked(n); if (!n && route.getValue() != null) {getRoute().updateCurrentEntry(getSystem(), getStation(), true);} }); - shipMass.addListener((ov, o, n) -> { - LOG.debug("Change ship mass, old: {}, new: {}", o, n); - profile.getShip().setMass(n.doubleValue()); - }); - shipTank.addListener((ov, o, n) -> { - LOG.debug("Change ship tank, old: {}, new: {}", o, n); - profile.getShip().setTank(n.doubleValue()); - }); - shipCargo.addListener((ov, o, n) -> { - LOG.debug("Change ship cargo, old: {}, new: {}", o, n); - profile.getShip().setCargo(n.intValue()); - }); - shipEngine.addListener((ov, o, n) -> { - LOG.debug("Change ship engine, old: {}, new: {}", o, n); - profile.getShip().setEngine(n); - }); - + shipMass.addListener((ov, o, n) -> LOG.debug("Change ship mass, old: {}, new: {}", o, n)); + shipTank.addListener((ov, o, n) -> LOG.debug("Change ship tank, old: {}, new: {}", o, n)); + shipCargo.addListener((ov, o, n) -> LOG.debug("Change ship cargo, old: {}, new: {}", o, n)); + shipEngine.addListener((ov, o, n) -> LOG.debug("Change ship engine, old: {}, new: {}", o, n)); route.addListener((ov, o, n) -> LOG.debug("Change route, old: {}, new: {}", o, n)); } @@ -101,6 +79,7 @@ public class ProfileModel { } public void setName(String name) { + profile.setName(name); this.name.set(name); } @@ -113,6 +92,7 @@ public class ProfileModel { } public void setBalance(double balance) { + profile.setBalance(balance); this.balance.set(balance); } @@ -125,6 +105,7 @@ public class ProfileModel { } public void setSystem(SystemModel system) { + profile.setSystem(ModelFabric.isFake(system) ? null : system.getSystem()); this.system.set(system); } @@ -137,6 +118,7 @@ public class ProfileModel { } public void setStation(StationModel station) { + profile.setStation(ModelFabric.isFake(station) ? null : station.getStation()); this.station.set(station); } @@ -149,6 +131,7 @@ public class ProfileModel { } public void setDocked(boolean docked) { + profile.setDocked(docked); this.docked.set(docked); } @@ -161,6 +144,7 @@ public class ProfileModel { } public void setShipMass(double shipMass) { + profile.getShip().setMass(shipMass); this.shipMass.set(shipMass); } @@ -173,6 +157,7 @@ public class ProfileModel { } public void setShipTank(double shipTank) { + profile.getShip().setTank(shipTank); this.shipTank.set(shipTank); } @@ -185,6 +170,7 @@ public class ProfileModel { } public void setShipCargo(int shipCargo) { + profile.getShip().setCargo(shipCargo); this.shipCargo.set(shipCargo); } @@ -197,6 +183,7 @@ public class ProfileModel { } public void setShipEngine(Engine engine) { + profile.getShip().setEngine(engine); this.shipEngine.set(engine); } @@ -212,6 +199,14 @@ public class ProfileModel { this.route.set(route); } + public double getShipJumpRange(){ + return profile.getShip().getJumpRange(); + } + + public double getMaxShipJumpRange(){ + return profile.getShip().getMaxJumpRange(); + } + private void refresh(){ name.setValue(profile.getName()); balance.setValue(profile.getBalance()); diff --git a/client/src/main/resources/view/profile.fxml b/client/src/main/resources/view/profile.fxml index 16f783a..0a6df5a 100644 --- a/client/src/main/resources/view/profile.fxml +++ b/client/src/main/resources/view/profile.fxml @@ -12,35 +12,36 @@ spacing="4" >