- modify station editor
- add system editor - show services in station tab
This commit is contained in:
@@ -92,6 +92,7 @@ public class Main extends Application {
|
||||
Screeners.loadTopOrdersStage(getUrl(("topOrders.fxml")));
|
||||
Screeners.loadPathsStage(getUrl(("paths.fxml")));
|
||||
Screeners.loadSettingsStage(getUrl(("settings.fxml")));
|
||||
Screeners.loadSEditorStage(getUrl(("sEditor.fxml")));
|
||||
}
|
||||
|
||||
private static URL getUrl(String filename) throws MalformedURLException {
|
||||
|
||||
@@ -17,6 +17,7 @@ import ru.trader.World;
|
||||
import ru.trader.model.ItemModel;
|
||||
import ru.trader.model.MarketModel;
|
||||
import ru.trader.model.StationModel;
|
||||
import ru.trader.model.SystemModel;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
@@ -141,11 +142,12 @@ public class MainController {
|
||||
|
||||
|
||||
public void addSystem(ActionEvent actionEvent){
|
||||
//TODO: implement
|
||||
Screeners.showSystemsEditor(null);
|
||||
}
|
||||
|
||||
public void editSystem(ActionEvent actionEvent){
|
||||
//TODO: implement
|
||||
SystemModel system = offersController.getSystem();
|
||||
Screeners.showSystemsEditor(system);
|
||||
}
|
||||
|
||||
public void removeSystem(ActionEvent actionEvent){
|
||||
@@ -153,7 +155,10 @@ public class MainController {
|
||||
}
|
||||
|
||||
public void addStation(ActionEvent actionEvent) {
|
||||
Screeners.showAddStation(offersController.getSystem());
|
||||
SystemModel system = offersController.getSystem();
|
||||
if (system != null){
|
||||
Screeners.showAddStation(offersController.getSystem());
|
||||
}
|
||||
}
|
||||
|
||||
public void editStation(ActionEvent actionEvent) {
|
||||
|
||||
@@ -14,9 +14,11 @@ import org.controlsfx.control.SegmentedButton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javafx.fxml.FXML;
|
||||
import ru.trader.core.SERVICE_TYPE;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.model.support.ChangeMarketListener;
|
||||
import ru.trader.view.support.NumberField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,18 +31,28 @@ public class OffersController {
|
||||
|
||||
@FXML
|
||||
private Insets stationsMargin;
|
||||
|
||||
@FXML
|
||||
private ListView<SystemModel> systems;
|
||||
|
||||
@FXML
|
||||
private SegmentedButton stationsBar;
|
||||
|
||||
@FXML
|
||||
private TableView<OfferModel> tblSell;
|
||||
|
||||
@FXML
|
||||
private TableView<OfferModel> tblBuy;
|
||||
@FXML
|
||||
private Label distance;
|
||||
@FXML
|
||||
private CheckBox cbMarket;
|
||||
@FXML
|
||||
private CheckBox cbBlackMarket;
|
||||
@FXML
|
||||
private CheckBox cbRepair;
|
||||
@FXML
|
||||
private CheckBox cbMunition;
|
||||
@FXML
|
||||
private CheckBox cbOutfit;
|
||||
@FXML
|
||||
private CheckBox cbShipyard;
|
||||
|
||||
private final List<OfferModel> sells = FXCollections.observableArrayList();
|
||||
private final List<OfferModel> buys = FXCollections.observableArrayList();
|
||||
@@ -106,7 +118,6 @@ public class OffersController {
|
||||
}
|
||||
|
||||
station = stations.isEmpty() ? null : stations.get(0);
|
||||
LOG.info("Change station to {}", station);
|
||||
fillTables(station);
|
||||
}
|
||||
|
||||
@@ -117,9 +128,24 @@ public class OffersController {
|
||||
}
|
||||
|
||||
private void fillTables(StationModel station){
|
||||
LOG.info("Change station to {}", station);
|
||||
sells.clear();
|
||||
buys.clear();
|
||||
distance.setText("");
|
||||
cbMarket.setSelected(false);
|
||||
cbBlackMarket.setSelected(false);
|
||||
cbMunition.setSelected(false);
|
||||
cbRepair.setSelected(false);
|
||||
cbOutfit.setSelected(false);
|
||||
cbShipyard.setSelected(false);
|
||||
if (station != null){
|
||||
distance.setText(String.valueOf(station.getDistance()));
|
||||
cbMarket.setSelected(station.hasService(SERVICE_TYPE.MARKET));
|
||||
cbBlackMarket.setSelected(station.hasService(SERVICE_TYPE.BLACK_MARKET));
|
||||
cbMunition.setSelected(station.hasService(SERVICE_TYPE.MUNITION));
|
||||
cbRepair.setSelected(station.hasService(SERVICE_TYPE.REPAIR));
|
||||
cbOutfit.setSelected(station.hasService(SERVICE_TYPE.OUTFIT));
|
||||
cbShipyard.setSelected(station.hasService(SERVICE_TYPE.SHIPYARD));
|
||||
sells.addAll(station.getSells());
|
||||
buys.addAll(station.getBuys());
|
||||
}
|
||||
@@ -202,6 +228,7 @@ public class OffersController {
|
||||
|
||||
@Override
|
||||
public void add(StationModel station) {
|
||||
stationsBar.getButtons().add(buildStationNode(station));
|
||||
refresh();
|
||||
sort();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Screeners {
|
||||
private static Parent topOrdersScreen;
|
||||
private static Parent pathsScreen;
|
||||
private static Parent settingsScreen;
|
||||
private static Parent sEditorScreen;
|
||||
|
||||
private static MainController mainController;
|
||||
private static ItemDescController itemDescController;
|
||||
@@ -37,6 +38,7 @@ public class Screeners {
|
||||
private static TopOrdersController topOrdersController;
|
||||
private static PathsController pathsController;
|
||||
private static SettingsController settingsController;
|
||||
private static SystemsEditorController systemsEditorController;
|
||||
|
||||
private static FXMLLoader initLoader(URL url){
|
||||
FXMLLoader loader = new FXMLLoader(url, Localization.getResources());
|
||||
@@ -118,6 +120,14 @@ public class Screeners {
|
||||
stage.setScene(new Scene(settingsScreen));
|
||||
}
|
||||
|
||||
public static void loadSEditorStage(URL fxml) throws IOException {
|
||||
FXMLLoader loader = initLoader(fxml);
|
||||
sEditorScreen = loader.load();
|
||||
addStylesheet(sEditorScreen);
|
||||
systemsEditorController = loader.getController();
|
||||
}
|
||||
|
||||
|
||||
public static void show(Node node){
|
||||
mainController.getMainPane().setCenter(node);
|
||||
}
|
||||
@@ -131,6 +141,10 @@ public class Screeners {
|
||||
return Dialogs.create().owner(mainScreen).message(text).showConfirm();
|
||||
}
|
||||
|
||||
public static void showSystemsEditor(SystemModel system){
|
||||
systemsEditorController.showDialog(mainScreen, sEditorScreen, system);
|
||||
}
|
||||
|
||||
public static void showAddStation(SystemModel system){
|
||||
vEditorController.showDialog(mainScreen, vEditorScreen, system, null);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package ru.trader.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.util.converter.LongStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
@@ -12,6 +14,7 @@ import org.controlsfx.dialog.DialogAction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.EMDNUpdater;
|
||||
import ru.trader.core.SERVICE_TYPE;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.model.support.StationUpdater;
|
||||
import ru.trader.view.support.Localization;
|
||||
@@ -19,6 +22,7 @@ import ru.trader.view.support.NumberField;
|
||||
import ru.trader.view.support.PriceStringConverter;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
import ru.trader.view.support.cells.EditOfferCell;
|
||||
import ru.trader.view.support.cells.TextFieldCell;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -35,13 +39,25 @@ public class StationEditorController {
|
||||
private TableColumn<StationUpdater.FakeOffer, Double> buy;
|
||||
@FXML
|
||||
private TableColumn<StationUpdater.FakeOffer, Double> sell;
|
||||
@FXML
|
||||
private TableColumn<StationUpdater.FakeOffer, Long> supply;
|
||||
@FXML
|
||||
private TableColumn<StationUpdater.FakeOffer, Long> demand;
|
||||
|
||||
@FXML
|
||||
private NumberField x;
|
||||
private NumberField distance;
|
||||
@FXML
|
||||
private NumberField y;
|
||||
private CheckBox cbMarket;
|
||||
@FXML
|
||||
private NumberField z;
|
||||
private CheckBox cbBlackMarket;
|
||||
@FXML
|
||||
private CheckBox cbRepair;
|
||||
@FXML
|
||||
private CheckBox cbMunition;
|
||||
@FXML
|
||||
private CheckBox cbOutfit;
|
||||
@FXML
|
||||
private CheckBox cbShipyard;
|
||||
|
||||
private StationUpdater updater;
|
||||
|
||||
@@ -61,11 +77,11 @@ public class StationEditorController {
|
||||
items.getSelectionModel().setCellSelectionEnabled(true);
|
||||
buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false));
|
||||
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
||||
actSave.disabledProperty().bind(x.wrongProperty().or(y.wrongProperty().or(z.wrongProperty())));
|
||||
name.setOnAction((v)->x.requestFocus());
|
||||
x.setOnAction((v) -> z.requestFocus());
|
||||
z.setOnAction((v) -> y.requestFocus());
|
||||
y.setOnAction((v) -> {
|
||||
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||
supply.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||
actSave.disabledProperty().bind(distance.wrongProperty());
|
||||
name.setOnAction((v)->distance.requestFocus());
|
||||
distance.setOnAction((v) -> {
|
||||
items.requestFocus();
|
||||
items.getSelectionModel().select(0, buy);
|
||||
});
|
||||
@@ -73,11 +89,19 @@ public class StationEditorController {
|
||||
}
|
||||
|
||||
private void init(){
|
||||
if (updater != null){
|
||||
name.textProperty().unbindBidirectional(updater.nameProperty());
|
||||
distance.numberProperty().unbindBidirectional(updater.distanceProperty());
|
||||
}
|
||||
updater = new StationUpdater(MainController.getMarket());
|
||||
name.textProperty().bindBidirectional(updater.nameProperty());
|
||||
x.numberProperty().bindBidirectional(updater.xProperty());
|
||||
y.numberProperty().bindBidirectional(updater.yProperty());
|
||||
z.numberProperty().bindBidirectional(updater.zProperty());
|
||||
distance.numberProperty().bindBidirectional(updater.distanceProperty());
|
||||
cbMarket.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.MARKET));
|
||||
cbBlackMarket.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.BLACK_MARKET));
|
||||
cbMunition.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.MUNITION));
|
||||
cbRepair.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.REPAIR));
|
||||
cbOutfit.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.OUTFIT));
|
||||
cbShipyard.selectedProperty().bindBidirectional(updater.serviceProperty(SERVICE_TYPE.SHIPYARD));
|
||||
items.setItems(updater.getOffers());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.util.converter.DefaultStringConverter;
|
||||
import javafx.util.converter.DoubleStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.model.MarketModel;
|
||||
import ru.trader.model.SystemModel;
|
||||
import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.cells.TextFieldCell;
|
||||
|
||||
public class SystemsEditorController {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(SystemsEditorController.class);
|
||||
|
||||
|
||||
@FXML
|
||||
private TableView<SystemData> tblSystems;
|
||||
@FXML
|
||||
private TableColumn<SystemData, String> clnName;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnX;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnY;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnZ;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS1;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS2;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS3;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS4;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS5;
|
||||
@FXML
|
||||
private TableColumn<SystemData, Double> clnS6;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system1;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system2;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system3;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system4;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system5;
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system6;
|
||||
|
||||
private MarketModel market;
|
||||
|
||||
private final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> {
|
||||
tblSystems.getSelectionModel().selectFirst();
|
||||
commit();
|
||||
});
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
clnName.setCellFactory(TextFieldCell.forTableColumn(new DefaultStringConverter()));
|
||||
clnX.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnY.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnZ.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS1.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS2.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS3.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS4.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS5.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
clnS6.setCellFactory(TextFieldCell.forTableColumn(new DoubleStringConverter()));
|
||||
tblSystems.setItems(FXCollections.observableArrayList());
|
||||
tblSystems.getSelectionModel().setCellSelectionEnabled(true);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
market = MainController.getMarket();
|
||||
system1.setItems(market.systemsProperty());
|
||||
system2.setItems(market.systemsProperty());
|
||||
system3.setItems(market.systemsProperty());
|
||||
system4.setItems(market.systemsProperty());
|
||||
system5.setItems(market.systemsProperty());
|
||||
system6.setItems(market.systemsProperty());
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content, SystemModel system){
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("sEditor.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
||||
dlg.setResizable(false);
|
||||
if (system != null){
|
||||
tblSystems.getItems().add(new SystemData(system));
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
add();
|
||||
}
|
||||
dlg.show();
|
||||
reset();
|
||||
}
|
||||
|
||||
public void add() {
|
||||
tblSystems.getItems().add(new SystemData());
|
||||
}
|
||||
|
||||
|
||||
private void commit(){
|
||||
for (SystemData systemData : tblSystems.getItems()) {
|
||||
systemData.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private void reset(){
|
||||
tblSystems.getItems().clear();
|
||||
}
|
||||
|
||||
public class SystemData {
|
||||
private final StringProperty name;
|
||||
private final DoubleProperty x;
|
||||
private final DoubleProperty y;
|
||||
private final DoubleProperty z;
|
||||
|
||||
private final DoubleProperty s1 = new SimpleDoubleProperty();
|
||||
private final DoubleProperty s2 = new SimpleDoubleProperty();
|
||||
private final DoubleProperty s3 = new SimpleDoubleProperty();
|
||||
private final DoubleProperty s4 = new SimpleDoubleProperty();
|
||||
private final DoubleProperty s5 = new SimpleDoubleProperty();
|
||||
private final DoubleProperty s6 = new SimpleDoubleProperty();
|
||||
private final SystemModel system;
|
||||
|
||||
private SystemData() {
|
||||
system = null;
|
||||
name = new SimpleStringProperty("");
|
||||
x = new SimpleDoubleProperty(Double.NaN);
|
||||
y = new SimpleDoubleProperty(Double.NaN);
|
||||
z = new SimpleDoubleProperty(Double.NaN);
|
||||
}
|
||||
|
||||
private SystemData(SystemModel system) {
|
||||
this.system = system;
|
||||
name = new SimpleStringProperty(system.getName());
|
||||
x = new SimpleDoubleProperty(system.getX());
|
||||
y = new SimpleDoubleProperty(system.getY());
|
||||
z = new SimpleDoubleProperty(system.getZ());
|
||||
}
|
||||
|
||||
public StringProperty nameProperty() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DoubleProperty xProperty() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public DoubleProperty yProperty() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public DoubleProperty zProperty() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public DoubleProperty s1Property() {
|
||||
return s1;
|
||||
}
|
||||
|
||||
public DoubleProperty s2Property() {
|
||||
return s2;
|
||||
}
|
||||
|
||||
public DoubleProperty s3Property() {
|
||||
return s3;
|
||||
}
|
||||
|
||||
public DoubleProperty s4Property() {
|
||||
return s4;
|
||||
}
|
||||
|
||||
public DoubleProperty s5Property() {
|
||||
return s5;
|
||||
}
|
||||
|
||||
public DoubleProperty s6Property() {
|
||||
return s6;
|
||||
}
|
||||
|
||||
private void commit(){
|
||||
if (!name.get().isEmpty() && !Double.isNaN(x.get()) && !Double.isNaN(y.get()) && !Double.isNaN(z.get())){
|
||||
if (system != null){
|
||||
system.setName(name.get());
|
||||
system.setPosition(x.get(), y.get(), z.get());
|
||||
} else {
|
||||
market.add(name.get(), x.get(), y.get(), z.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.core.OFFER_TYPE;
|
||||
import ru.trader.core.Offer;
|
||||
import ru.trader.core.SERVICE_TYPE;
|
||||
import ru.trader.core.Vendor;
|
||||
|
||||
import java.util.*;
|
||||
@@ -49,6 +50,26 @@ public class StationModel {
|
||||
station.setDistance(value);
|
||||
}
|
||||
|
||||
public boolean hasService(SERVICE_TYPE service){
|
||||
return station.has(service);
|
||||
}
|
||||
|
||||
public Collection<SERVICE_TYPE> getServices(){
|
||||
return station.getServices();
|
||||
}
|
||||
|
||||
public void addService(SERVICE_TYPE service){
|
||||
if (station.has(service)) return;
|
||||
LOG.info("Add service {} to station {}", service, station);
|
||||
station.add(service);
|
||||
}
|
||||
|
||||
public void removeService(SERVICE_TYPE service){
|
||||
if (!station.has(service)) return;
|
||||
LOG.info("Remove service {} from station {}", service, station);
|
||||
station.remove(service);
|
||||
}
|
||||
|
||||
public SystemModel getSystem(){
|
||||
return market.getModeler().get(station.getPlace());
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ public class SystemModel {
|
||||
return system.getDistance(other.getSystem());
|
||||
}
|
||||
|
||||
public double getDistance(double x, double y, double z){
|
||||
return system.getDistance(x, y, z);
|
||||
}
|
||||
|
||||
public List<StationModel> getStations() {
|
||||
return system.get().stream().map(this::asModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -6,17 +6,19 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.controllers.MainController;
|
||||
import ru.trader.core.OFFER_TYPE;
|
||||
import ru.trader.core.SERVICE_TYPE;
|
||||
import ru.trader.model.*;
|
||||
|
||||
|
||||
public class StationUpdater {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(StationUpdater.class);
|
||||
private final static SERVICE_TYPE[] SERVICE_TYPES = SERVICE_TYPE.values();
|
||||
private final ObservableList<FakeOffer> offers;
|
||||
private final StringProperty name;
|
||||
private final DoubleProperty x;
|
||||
private final DoubleProperty y;
|
||||
private final DoubleProperty z;
|
||||
private final DoubleProperty distance;
|
||||
private final BooleanProperty[] services;
|
||||
private final MarketModel market;
|
||||
|
||||
private SystemModel system;
|
||||
private StationModel station;
|
||||
private boolean updateOnly;
|
||||
@@ -25,9 +27,11 @@ public class StationUpdater {
|
||||
this.market = market;
|
||||
this.offers = BindingsHelper.observableList(MainController.getMarket().itemsProperty(), FakeOffer::new);
|
||||
this.name = new SimpleStringProperty();
|
||||
this.x = new SimpleDoubleProperty(0);
|
||||
this.y = new SimpleDoubleProperty(0);
|
||||
this.z = new SimpleDoubleProperty(0);
|
||||
this.distance = new SimpleDoubleProperty(0);
|
||||
this.services = new BooleanProperty[SERVICE_TYPES.length];
|
||||
for (int i = 0; i < services.length; i++) {
|
||||
services[i] = new SimpleBooleanProperty();
|
||||
}
|
||||
this.updateOnly = false;
|
||||
}
|
||||
|
||||
@@ -35,18 +39,20 @@ public class StationUpdater {
|
||||
LOG.debug("Init update of {}", station);
|
||||
this.station = station;
|
||||
this.system = system;
|
||||
for (BooleanProperty service : services) {
|
||||
service.set(false);
|
||||
}
|
||||
if (station != null){
|
||||
name.setValue(station.getName());
|
||||
x.setValue(system.getX());
|
||||
y.setValue(system.getY());
|
||||
z.setValue(system.getZ());
|
||||
distance.setValue(station.getDistance());
|
||||
for (SERVICE_TYPE service : station.getServices()) {
|
||||
serviceProperty(service).set(true);
|
||||
}
|
||||
station.getSells().forEach(this::fillOffer);
|
||||
station.getBuys().forEach(this::fillOffer);
|
||||
} else {
|
||||
name.setValue("");
|
||||
x.setValue(0);
|
||||
y.setValue(0);
|
||||
z.setValue(0);
|
||||
distance.setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,28 +88,16 @@ public class StationUpdater {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x.get();
|
||||
public double getDistance() {
|
||||
return distance.get();
|
||||
}
|
||||
|
||||
public DoubleProperty xProperty() {
|
||||
return x;
|
||||
public DoubleProperty distanceProperty() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y.get();
|
||||
}
|
||||
|
||||
public DoubleProperty yProperty() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z.get();
|
||||
}
|
||||
|
||||
public DoubleProperty zProperty() {
|
||||
return z;
|
||||
public BooleanProperty serviceProperty(SERVICE_TYPE service){
|
||||
return services[service.ordinal()];
|
||||
}
|
||||
|
||||
public void add(int index, ItemModel item){
|
||||
@@ -112,16 +106,29 @@ public class StationUpdater {
|
||||
|
||||
public void commit(){
|
||||
LOG.debug("Save changes of {}", station);
|
||||
system.setPosition(x.get(), y.get(), z.get());
|
||||
if (isNew()) {
|
||||
Notificator notificator = market.getNotificator();
|
||||
notificator.setAlert(false);
|
||||
station = system.add(name.get());
|
||||
station.setDistance(distance.get());
|
||||
for (int i = 0; i < services.length; i++) {
|
||||
if (services[i].get()){
|
||||
station.addService(SERVICE_TYPES[i]);
|
||||
}
|
||||
}
|
||||
offers.forEach(FakeOffer::commit);
|
||||
notificator.setAlert(true);
|
||||
notificator.sendAdd(station);
|
||||
} else {
|
||||
station.setName(name.get());
|
||||
station.setDistance(distance.get());
|
||||
for (int i = 0; i < services.length; i++) {
|
||||
if (services[i].get()){
|
||||
station.addService(SERVICE_TYPES[i]);
|
||||
} else {
|
||||
station.removeService(SERVICE_TYPES[i]);
|
||||
}
|
||||
}
|
||||
offers.forEach(FakeOffer::commit);
|
||||
}
|
||||
}
|
||||
@@ -268,11 +275,13 @@ public class StationUpdater {
|
||||
public void setSell(OfferModel sell) {
|
||||
this.sell = sell;
|
||||
sprice.set(sell.getPrice());
|
||||
supply.set(sell.getCount());
|
||||
}
|
||||
|
||||
public void setBuy(OfferModel buy) {
|
||||
this.buy = buy;
|
||||
bprice.set(buy.getPrice());
|
||||
demand.set(buy.getCount());
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
|
||||
@@ -19,6 +19,7 @@ public class ViewUtils {
|
||||
// Edit next cell
|
||||
public static <S> void editNext(TableView<S> tableView){
|
||||
TableView.TableViewSelectionModel<S> sm = tableView.getSelectionModel();
|
||||
if (!sm.isCellSelectionEnabled()) return;
|
||||
sm.selectNext();
|
||||
ObservableList<TablePosition> pos = sm.getSelectedCells();
|
||||
for (TablePosition p : pos) {
|
||||
|
||||
Reference in New Issue
Block a user