diff --git a/client/src/main/java/ru/trader/EDCE.java b/client/src/main/java/ru/trader/EDCE.java index 96cbd7e..ca9e3ea 100644 --- a/client/src/main/java/ru/trader/EDCE.java +++ b/client/src/main/java/ru/trader/EDCE.java @@ -49,7 +49,7 @@ public class EDCE { this.world = world; this.session = new EDSession(); this.updater = new StationUpdater(world); - this.settings = Main.SETTINGS.getEdce(); + this.settings = Main.SETTINGS.edce(); active = new SimpleBooleanProperty(settings.isActive()); settings.activeProperty().addListener((ov, o, n) -> { if (n) run(); diff --git a/client/src/main/java/ru/trader/Main.java b/client/src/main/java/ru/trader/Main.java index 67f3756..b144600 100644 --- a/client/src/main/java/ru/trader/Main.java +++ b/client/src/main/java/ru/trader/Main.java @@ -40,6 +40,9 @@ public class Main extends Application { loadMainScene(); loadResources(); primaryStage.show(); + if (Main.SETTINGS.helper().isVisible()){ + Screeners.showHelper(); + } ServicesManager.runAll(); } @@ -67,10 +70,14 @@ public class Main extends Application { public static void changeLocale(Locale locale) throws IOException { Localization.setLocale(locale); primaryStage.hide(); + Screeners.closeAll(); MainController.getWorld().refresh(); loadMainScene(); loadResources(); primaryStage.show(); + if (Main.SETTINGS.helper().isVisible()){ + Screeners.showHelper(); + } } private static void loadMainScene() throws IOException { diff --git a/client/src/main/java/ru/trader/Settings.java b/client/src/main/java/ru/trader/Settings.java index a9332b1..0f1b968 100644 --- a/client/src/main/java/ru/trader/Settings.java +++ b/client/src/main/java/ru/trader/Settings.java @@ -19,18 +19,21 @@ public class Settings { private final File file; private Profile profile; private final EDCESettings edce; + private final HelperSettings helper; public Settings() { this.file = null; profile = new Profile(new Ship()); edce = new EDCESettings(); + helper = new HelperSettings(); } public Settings(File file) { this.file = file; profile = new Profile(new Ship()); edce = new EDCESettings(); + helper = new HelperSettings(); } public void load(Market market) { @@ -43,12 +46,14 @@ public class Settings { } profile = Profile.readFrom(values, market); edce.readFrom(values); + helper.readFrom(values); } public void save(){ try (OutputStream os = new FileOutputStream(file)) { profile.writeTo(values); edce.writeTo(values); + helper.writeTo(values); values.store(os, "settings"); } catch (IOException e) { LOG.error("Error on load settings", e); @@ -148,10 +153,14 @@ public class Settings { return profile; } - public EDCESettings getEdce(){ + public EDCESettings edce(){ return edce; } + public HelperSettings helper(){ + return helper; + } + public final class EDCESettings { private final BooleanProperty active; private final StringProperty email; @@ -213,4 +222,65 @@ public class Settings { } + + public final class HelperSettings { + private final IntegerProperty x; + private final IntegerProperty y; + private final BooleanProperty visible; + + public HelperSettings() { + x = new SimpleIntegerProperty(); + y = new SimpleIntegerProperty(); + visible = new SimpleBooleanProperty(); + } + + public int getX() { + return x.get(); + } + + public IntegerProperty xProperty() { + return x; + } + + public void setX(int x) { + this.x.set(x); + } + + public int getY() { + return y.get(); + } + + public IntegerProperty yProperty() { + return y; + } + + public void setY(int y) { + this.y.set(y); + } + + public boolean isVisible() { + return visible.get(); + } + + public BooleanProperty visibleProperty() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible.set(visible); + } + + public void readFrom(Properties values){ + setVisible(!"0".equals(values.getProperty("helper.visible", "0"))); + setX(Integer.valueOf(values.getProperty("helper.x", "100"))); + setY(Integer.valueOf(values.getProperty("helper.y", "100"))); + } + + public void writeTo(Properties values){ + values.setProperty("helper.visible", isVisible() ? "1":"0"); + values.setProperty("helper.x", String.valueOf(getX())); + values.setProperty("helper.y", String.valueOf(getY())); + } + } + } diff --git a/client/src/main/java/ru/trader/controllers/HelperController.java b/client/src/main/java/ru/trader/controllers/HelperController.java index 40c2018..de66e22 100644 --- a/client/src/main/java/ru/trader/controllers/HelperController.java +++ b/client/src/main/java/ru/trader/controllers/HelperController.java @@ -66,9 +66,6 @@ public class HelperController { @FXML private void initialize(){ - ProfileModel profile = MainController.getProfile(); - profile.routeProperty().addListener(routeListener); - profile.dockedProperty().addListener(dockedListener); buyOrders.setCellFactory(new OrderListCell(false)); sellOrders.setCellFactory(new OrderListCell(true)); sellOffers.setCellFactory(new OfferListCell(true)); @@ -83,7 +80,6 @@ public class HelperController { infoGroup.managedProperty().bind(infoGroup.visibleProperty()); hideInfo(); hideStationInfo(); - bindKeys(); } private void resize(){ @@ -138,11 +134,18 @@ public class HelperController { scene.setFill(Color.TRANSPARENT); stage.setAlwaysOnTop(true); addDragListeners(content); + stage.setX(Main.SETTINGS.helper().getX()); + stage.setY(Main.SETTINGS.helper().getY()); + bind(); + Main.SETTINGS.helper().setVisible(true); stage.show(); + setRoute(MainController.getProfile().getRoute()); } else { if (toggle && stage.isShowing()){ + Main.SETTINGS.helper().setVisible(false); stage.hide(); } else { + Main.SETTINGS.helper().setVisible(true); stage.show(); } } @@ -151,9 +154,28 @@ public class HelperController { public void close(){ if (stage != null){ stage.close(); + unbind(); + stage = null; } } + private void bind(){ + ProfileModel profile = MainController.getProfile(); + profile.routeProperty().addListener(routeListener); + profile.dockedProperty().addListener(dockedListener); + Main.SETTINGS.helper().xProperty().bind(stage.xProperty()); + Main.SETTINGS.helper().yProperty().bind(stage.yProperty()); + bindKeys(); + } + + private void unbind(){ + ProfileModel profile = MainController.getProfile(); + profile.routeProperty().removeListener(routeListener); + profile.dockedProperty().removeListener(dockedListener); + Main.SETTINGS.helper().xProperty().unbind(); + Main.SETTINGS.helper().yProperty().unbind(); + } + private void setRoute(RouteModel route){ if (this.route != null){ this.route.currentEntryProperty().removeListener(currentEntryListener); @@ -246,8 +268,7 @@ public class HelperController { } private void bindKeys(){ - KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD4, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::previous)); - KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::next)); + KeyBinding.bind(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK), k -> ViewUtils.doFX(this::complete)); } private final ChangeListener currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue())); diff --git a/client/src/main/java/ru/trader/controllers/LoginController.java b/client/src/main/java/ru/trader/controllers/LoginController.java index d775b05..ec38ac7 100644 --- a/client/src/main/java/ru/trader/controllers/LoginController.java +++ b/client/src/main/java/ru/trader/controllers/LoginController.java @@ -36,7 +36,7 @@ public class LoginController { loginButton.setDisable(true); email.textProperty().addListener((observable, oldValue, newValue) -> { loginButton.setDisable(newValue.trim().isEmpty()); - Main.SETTINGS.getEdce().setEmail(newValue); + Main.SETTINGS.edce().setEmail(newValue); }); dialog.setResultConverter(dialogButton -> { if (dialogButton == loginButtonType) { diff --git a/client/src/main/java/ru/trader/controllers/MainController.java b/client/src/main/java/ru/trader/controllers/MainController.java index e470bdd..18d5bda 100644 --- a/client/src/main/java/ru/trader/controllers/MainController.java +++ b/client/src/main/java/ru/trader/controllers/MainController.java @@ -110,6 +110,7 @@ public class MainController { itemsController.init(); offersController.init(); routerController.init(); + //TODO: add init all controllers } public void initEDCE(){ diff --git a/client/src/main/java/ru/trader/controllers/ProfileController.java b/client/src/main/java/ru/trader/controllers/ProfileController.java index 6905734..dcd5b59 100644 --- a/client/src/main/java/ru/trader/controllers/ProfileController.java +++ b/client/src/main/java/ru/trader/controllers/ProfileController.java @@ -51,6 +51,8 @@ public class ProfileController { @FXML private Button btnAddStation; @FXML + private ToggleButton btnHelper; + @FXML private ToggleButton btnEDCE; private AutoCompletion system; @@ -81,6 +83,8 @@ public class ProfileController { if (ModelFabric.isFake(profile.getStation())) Screeners.showAddStation(profile.getSystem()); else Screeners.showEditStation(profile.getStation()); }); + btnHelper.setOnAction(e -> toggleHelper()); + btnHelper.setSelected(Main.SETTINGS.helper().isVisible()); shipInfo.setVisible(false); initListeners(); } @@ -138,7 +142,7 @@ public class ProfileController { } public void initEDCEBtn(){ - btnEDCE.selectedProperty().bindBidirectional(Main.SETTINGS.getEdce().activeProperty()); + btnEDCE.selectedProperty().bindBidirectional(Main.SETTINGS.edce().activeProperty()); setEDCEBtnStyles(btnEDCE.isSelected()); ServicesManager.getEdce().activeProperty().addListener((ov, o, n) -> { setEDCEBtnStyles(n); diff --git a/client/src/main/java/ru/trader/controllers/Screeners.java b/client/src/main/java/ru/trader/controllers/Screeners.java index adb4032..65a6e42 100644 --- a/client/src/main/java/ru/trader/controllers/Screeners.java +++ b/client/src/main/java/ru/trader/controllers/Screeners.java @@ -238,7 +238,7 @@ public class Screeners { return showTextDialog(Localization.getString("verify.title"), Localization.getString("verify.header"), Localization.getString("verify.content") - ); + ); } public static Optional showTextDialog(String title, String header, String content){ @@ -249,6 +249,10 @@ public class Screeners { return dialog.showAndWait(); } + public static void showHelper(){ + helperController.show(helperScreen, false); + } + public static void toggleHelper(){ helperController.show(helperScreen, true); } diff --git a/client/src/main/resources/view/profile.fxml b/client/src/main/resources/view/profile.fxml index 639b763..5682890 100644 --- a/client/src/main/resources/view/profile.fxml +++ b/client/src/main/resources/view/profile.fxml @@ -39,7 +39,7 @@ - +