Archived
0

modify profile screen

This commit is contained in:
iMoHax
2015-10-09 13:53:29 +03:00
parent 4dfe2cf9b6
commit 0dcabd50a3
7 changed files with 98 additions and 68 deletions

View File

@@ -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();
}
}
}

View File

@@ -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> 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();
}

View File

@@ -84,7 +84,7 @@ public class RouteSearchController {
RouteModel route = path.get();
route.addAll(0, missionsList.getItems());
profile.setRoute(route);
Screeners.showHelper();
Screeners.toggleHelper();
}
});
}

View File

@@ -279,7 +279,7 @@ public class RouterController {
if (path.isPresent()){
orders.addAll(path.get().getOrders());
addRouteToPath(path.get());
Screeners.showHelper();
Screeners.toggleHelper();
}
});
}

View File

@@ -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() {

View File

@@ -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());

View File

@@ -12,35 +12,36 @@
spacing="4" >
<Label text="Имя:" />
<TextField fx:id="name" />
<Label text="Баланс:" />
<NumberField fx:id="balance" />
<Label text="Система:" />
<TextField fx:id="systemText" />
<Button fx:id="btnAddSystem"/>
<Label text="Станция:" />
<ComboBox fx:id="station" />
<Button fx:id="btnAddStation"/>
<Label text="В доке:" />
<CheckBox fx:id="docked" />
<Button prefWidth="30" onAction="#showHelper">
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
</Button>
<VBox>
<HBox>
<StackPane>
<HBox fx:id="profileInfo">
<Label text="Баланс:" />
<NumberField fx:id="balance" />
<Label text="Система:" />
<TextField fx:id="systemText" />
<Button fx:id="btnAddSystem"/>
<Label text="Станция:" />
<ComboBox fx:id="station" />
<Button fx:id="btnAddStation"/>
<Label text="В доке:" />
<CheckBox fx:id="docked" />
</HBox>
<HBox fx:id="shipInfo">
<Label text="Трюм:" />
<NumberField fx:id="cargo" />
</HBox>
<HBox>
<NumberField fx:id="cargo" maxWidth="60"/>
<Label text="Топливный бак:" />
<NumberField fx:id="tank" />
</HBox>
<HBox>
<NumberField fx:id="tank" maxWidth="60"/>
<Label text="Масса:" />
<NumberField fx:id="mass" />
</HBox>
<HBox>
<NumberField fx:id="mass" maxWidth="60"/>
<Label text="Двигатель:" />
<ComboBox fx:id="engine" />
<ComboBox fx:id="engine" maxWidth="60"/>
<Label text="Дальность прыжка, LY:" />
<Label fx:id="jumpRange"/>
</HBox>
</VBox>
</StackPane>
<ToggleButton prefWidth="30" onAction="#toggleShipInfo">
<graphic><Glyph text="FontAwesome|SPACE_SHUTTLE"/></graphic>
</ToggleButton>
<ToggleButton prefWidth="30" onAction="#toggleHelper">
<graphic><Glyph text="FontAwesome|ROCKET"/></graphic>
</ToggleButton>
</HBox>