move current route to profile model. Autochange current entry if change starsystem/station
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.IntegerProperty;
|
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@@ -12,11 +11,9 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import ru.trader.KeyBinding;
|
import ru.trader.KeyBinding;
|
||||||
import ru.trader.model.MissionModel;
|
import ru.trader.model.*;
|
||||||
import ru.trader.model.OrderModel;
|
|
||||||
import ru.trader.model.RouteEntryModel;
|
|
||||||
import ru.trader.model.RouteModel;
|
|
||||||
import ru.trader.view.support.ViewUtils;
|
import ru.trader.view.support.ViewUtils;
|
||||||
|
import ru.trader.view.support.cells.OfferListCell;
|
||||||
import ru.trader.view.support.cells.OrderListCell;
|
import ru.trader.view.support.cells.OrderListCell;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -39,28 +36,29 @@ public class HelperController {
|
|||||||
private ListView<OrderModel> sellOrders;
|
private ListView<OrderModel> sellOrders;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<MissionModel> missions;
|
private ListView<MissionModel> missions;
|
||||||
|
@FXML
|
||||||
|
private ListView<StationModel> stations;
|
||||||
|
@FXML
|
||||||
|
private ListView<OfferModel> sellOffers;
|
||||||
|
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
private RouteModel route;
|
private RouteModel route;
|
||||||
private final BooleanProperty docked;
|
private final BooleanProperty docked;
|
||||||
private final IntegerProperty currentEntry;
|
|
||||||
|
|
||||||
public HelperController() {
|
public HelperController() {
|
||||||
currentEntry = new SimpleIntegerProperty(-1);
|
|
||||||
docked = new SimpleBooleanProperty(true);
|
docked = new SimpleBooleanProperty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize(){
|
private void initialize(){
|
||||||
currentEntry.addListener(routeEntryListener);
|
MainController.getProfile().routeProperty().addListener(routeListener);
|
||||||
buyOrders.setCellFactory(new OrderListCell(false));
|
buyOrders.setCellFactory(new OrderListCell(false));
|
||||||
sellOrders.setCellFactory(new OrderListCell(true));
|
sellOrders.setCellFactory(new OrderListCell(true));
|
||||||
|
sellOffers.setCellFactory(new OfferListCell(true));
|
||||||
bindKeys();
|
bindKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(Parent content, RouteModel route) {
|
public void show(Parent content) {
|
||||||
this.route = route;
|
|
||||||
currentEntry.setValue(0);
|
|
||||||
if (stage == null){
|
if (stage == null){
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
stage.setScene(new Scene(content));
|
stage.setScene(new Scene(content));
|
||||||
@@ -76,6 +74,15 @@ public class HelperController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRoute(RouteModel route){
|
||||||
|
if (this.route != null){
|
||||||
|
this.route.currentEntryProperty().removeListener(currentEntryListener);
|
||||||
|
}
|
||||||
|
this.route = route;
|
||||||
|
setRouteEntry(route.getCurrentEntry());
|
||||||
|
this.route.currentEntryProperty().addListener(currentEntryListener);
|
||||||
|
}
|
||||||
|
|
||||||
private void setRouteEntry(int index){
|
private void setRouteEntry(int index){
|
||||||
RouteEntryModel entry = route.get(index);
|
RouteEntryModel entry = route.get(index);
|
||||||
station.setText(entry.getStation().getName());
|
station.setText(entry.getStation().getName());
|
||||||
@@ -85,13 +92,19 @@ public class HelperController {
|
|||||||
buyOrders.setItems(entry.orders());
|
buyOrders.setItems(entry.orders());
|
||||||
sellOrders.setItems(entry.sellOrders());
|
sellOrders.setItems(entry.sellOrders());
|
||||||
missions.setItems(entry.missions());
|
missions.setItems(entry.missions());
|
||||||
|
stations.setItems(FXCollections.observableArrayList(route.getStations(index)));
|
||||||
|
sellOffers.setItems(FXCollections.observableArrayList(route.getSellOffers(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void next(){
|
private void next(){
|
||||||
int index = currentEntry.get();
|
int index = route.getCurrentEntry();
|
||||||
if (index < route.getJumps() - 1){
|
if (index < route.getJumps() - 1){
|
||||||
currentEntry.setValue(index+1);
|
route.setCurrentEntry(index+1);
|
||||||
|
} else {
|
||||||
|
if (route.isLoop()){
|
||||||
|
route.setCurrentEntry(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,16 +115,19 @@ public class HelperController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void previous(){
|
private void previous(){
|
||||||
int index = currentEntry.get();
|
int index = route.getCurrentEntry();
|
||||||
if (index > 0){
|
if (index > 0){
|
||||||
currentEntry.setValue(index-1);
|
route.setCurrentEntry(index-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ChangeListener<Number> routeEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
|
||||||
|
|
||||||
private void bindKeys(){
|
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_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_NUMPAD6, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK), k -> ViewUtils.doFX(this::next));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setRouteEntry(n.intValue()));
|
||||||
|
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> ViewUtils.doFX(() -> setRoute(n));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,43 +57,32 @@ public class ProfileController {
|
|||||||
initListeners();
|
initListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void consumeChanges(Runnable runnable){
|
||||||
|
if (ignoreChanges) return;
|
||||||
|
ignoreChanges = true;
|
||||||
|
ViewUtils.doFX(runnable);
|
||||||
|
ignoreChanges = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doAndConsumeChanges(Runnable runnable){
|
||||||
|
boolean old = ignoreChanges;
|
||||||
|
ignoreChanges = true;
|
||||||
|
ViewUtils.doFX(runnable);
|
||||||
|
ignoreChanges = old;
|
||||||
|
}
|
||||||
|
|
||||||
private void initListeners(){
|
private void initListeners(){
|
||||||
name.textProperty().addListener((ov, o, n) -> {
|
name.textProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setName(n)));
|
||||||
if (!ignoreChanges)
|
balance.numberProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setBalance(n.doubleValue())));
|
||||||
profile.setName(n);
|
|
||||||
});
|
|
||||||
balance.numberProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setBalance(n.doubleValue());
|
|
||||||
});
|
|
||||||
system.completionProperty().addListener((ov, o , n) -> {
|
system.completionProperty().addListener((ov, o , n) -> {
|
||||||
if (!ignoreChanges){
|
doAndConsumeChanges(() -> station.setItems(n.getStationsList()));
|
||||||
ignoreChanges = true;
|
consumeChanges(() -> {profile.setSystem(n); profile.setStation(ModelFabric.NONE_STATION);});
|
||||||
profile.setSystem(n);
|
|
||||||
}
|
|
||||||
station.setItems(n.getStationsList());
|
|
||||||
ignoreChanges = false;
|
|
||||||
});
|
|
||||||
station.valueProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setStation(n);
|
|
||||||
});
|
|
||||||
mass.numberProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setShipMass(n.doubleValue());
|
|
||||||
});
|
|
||||||
tank.numberProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setShipTank(n.doubleValue());
|
|
||||||
});
|
|
||||||
cargo.numberProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setShipCargo(n.intValue());
|
|
||||||
});
|
|
||||||
engine.valueProperty().addListener((ov, o, n) -> {
|
|
||||||
if (!ignoreChanges)
|
|
||||||
profile.setShipEngine(n);
|
|
||||||
});
|
});
|
||||||
|
station.valueProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setStation(n)));
|
||||||
|
mass.numberProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipMass(n.doubleValue())));
|
||||||
|
tank.numberProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipTank(n.doubleValue())));
|
||||||
|
cargo.numberProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipCargo(n.intValue())));
|
||||||
|
engine.valueProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setShipEngine(n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProfile(ProfileModel profile){
|
public void setProfile(ProfileModel profile){
|
||||||
@@ -101,7 +90,6 @@ public class ProfileController {
|
|||||||
unbind();
|
unbind();
|
||||||
}
|
}
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
ignoreChanges = true;
|
|
||||||
name.setText(profile.getName());
|
name.setText(profile.getName());
|
||||||
balance.setValue(profile.getBalance());
|
balance.setValue(profile.getBalance());
|
||||||
system.setValue(profile.getSystem());
|
system.setValue(profile.getSystem());
|
||||||
@@ -111,7 +99,6 @@ public class ProfileController {
|
|||||||
cargo.setValue(profile.getShipCargo());
|
cargo.setValue(profile.getShipCargo());
|
||||||
engine.setValue(profile.getShipEngine());
|
engine.setValue(profile.getShipEngine());
|
||||||
bind();
|
bind();
|
||||||
ignoreChanges = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind(){
|
private void bind(){
|
||||||
@@ -137,17 +124,14 @@ public class ProfileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final ChangeListener<String> nameListener = (ov, o, n) -> ViewUtils.doFX(() -> name.setText(n));
|
private final ChangeListener<String> nameListener = (ov, o, n) -> consumeChanges(() -> name.setText(n));
|
||||||
private final ChangeListener<Number> balanceListener = (ov, o, n) -> ViewUtils.doFX(() -> balance.setValue(n));
|
private final ChangeListener<Number> balanceListener = (ov, o, n) -> consumeChanges(() -> balance.setValue(n));
|
||||||
private final ChangeListener<SystemModel> systemListener = (ov, o, n) -> {
|
private final ChangeListener<SystemModel> systemListener = (ov, o, n) -> consumeChanges(() -> system.setValue(n));
|
||||||
if (!ignoreChanges)
|
private final ChangeListener<StationModel> stationListener = (ov, o, n) -> consumeChanges(() -> station.setValue(n));
|
||||||
ViewUtils.doFX(() -> system.setValue(n));
|
private final ChangeListener<Number> massListener = (ov, o, n) -> consumeChanges(() -> mass.setValue(n));
|
||||||
};
|
private final ChangeListener<Number> tankListener = (ov, o, n) -> consumeChanges(() -> tank.setValue(n));
|
||||||
private final ChangeListener<StationModel> stationListener = (ov, o, n) -> ViewUtils.doFX(() -> station.setValue(n));
|
private final ChangeListener<Number> cargoListener = (ov, o, n) -> consumeChanges(() -> cargo.setValue(n));
|
||||||
private final ChangeListener<Number> massListener = (ov, o, n) -> ViewUtils.doFX(() -> mass.setValue(n));
|
private final ChangeListener<Engine> engineListener = (ov, o, n) -> consumeChanges(() -> engine.setValue(n));
|
||||||
private final ChangeListener<Number> tankListener = (ov, o, n) -> ViewUtils.doFX(() -> tank.setValue(n));
|
|
||||||
private final ChangeListener<Number> cargoListener = (ov, o, n) -> ViewUtils.doFX(() -> cargo.setValue(n));
|
|
||||||
private final ChangeListener<Engine> engineListener = (ov, o, n) -> ViewUtils.doFX(() -> engine.setValue(n));
|
|
||||||
|
|
||||||
private class EngineStringConverter extends StringConverter<Engine> {
|
private class EngineStringConverter extends StringConverter<Engine> {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ public class RouteSearchController {
|
|||||||
if (path.isPresent()){
|
if (path.isPresent()){
|
||||||
RouteModel route = path.get();
|
RouteModel route = path.get();
|
||||||
route.addAll(0, missionsList.getItems());
|
route.addAll(0, missionsList.getItems());
|
||||||
Screeners.showHelper(route);
|
profile.setRoute(route);
|
||||||
|
Screeners.showHelper();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,7 +275,8 @@ public class RouterController {
|
|||||||
if (path.isPresent()){
|
if (path.isPresent()){
|
||||||
orders.addAll(path.get().getOrders());
|
orders.addAll(path.get().getOrders());
|
||||||
addRouteToPath(path.get());
|
addRouteToPath(path.get());
|
||||||
Screeners.showHelper(path.get());
|
MainController.getProfile().setRoute(path.get());
|
||||||
|
Screeners.showHelper();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,8 +247,8 @@ public class Screeners {
|
|||||||
return dialog.showAndWait();
|
return dialog.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showHelper(RouteModel route){
|
public static void showHelper(){
|
||||||
helperController.show(helperScreen, route);
|
helperController.show(helperScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reinitAll() {
|
public static void reinitAll() {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class ProfileModel {
|
|||||||
private final DoubleProperty shipTank;
|
private final DoubleProperty shipTank;
|
||||||
private final IntegerProperty shipCargo;
|
private final IntegerProperty shipCargo;
|
||||||
private final ObjectProperty<Engine> shipEngine;
|
private final ObjectProperty<Engine> shipEngine;
|
||||||
|
private final ObjectProperty<RouteModel> route;
|
||||||
|
|
||||||
public ProfileModel(Profile profile, MarketModel market) {
|
public ProfileModel(Profile profile, MarketModel market) {
|
||||||
this.market = market;
|
this.market = market;
|
||||||
@@ -34,6 +35,7 @@ public class ProfileModel {
|
|||||||
shipTank = new SimpleDoubleProperty();
|
shipTank = new SimpleDoubleProperty();
|
||||||
shipCargo = new SimpleIntegerProperty();
|
shipCargo = new SimpleIntegerProperty();
|
||||||
shipEngine = new SimpleObjectProperty<>();
|
shipEngine = new SimpleObjectProperty<>();
|
||||||
|
route = new SimpleObjectProperty<>();
|
||||||
refresh();
|
refresh();
|
||||||
initListeners();
|
initListeners();
|
||||||
}
|
}
|
||||||
@@ -50,10 +52,12 @@ public class ProfileModel {
|
|||||||
system.addListener((ov, o, n) -> {
|
system.addListener((ov, o, n) -> {
|
||||||
LOG.debug("Change system, old: {}, new: {}", o, n);
|
LOG.debug("Change system, old: {}, new: {}", o, n);
|
||||||
profile.setSystem(n != null && n != ModelFabric.NONE_SYSTEM ? n.getSystem() : null);
|
profile.setSystem(n != null && n != ModelFabric.NONE_SYSTEM ? n.getSystem() : null);
|
||||||
|
if (route.getValue() != null) {getRoute().updateCurrentEntry(n, null);}
|
||||||
});
|
});
|
||||||
station.addListener((ov, o, n) -> {
|
station.addListener((ov, o, n) -> {
|
||||||
LOG.debug("Change station, old: {}, new: {}", o, n);
|
LOG.debug("Change station, old: {}, new: {}", o, n);
|
||||||
profile.setStation(n != null && n != ModelFabric.NONE_STATION ? n.getStation() : null);
|
profile.setStation(n != null && n != ModelFabric.NONE_STATION ? n.getStation() : null);
|
||||||
|
if (route.getValue() != null) {getRoute().updateCurrentEntry(getSystem(), n);}
|
||||||
});
|
});
|
||||||
docked.addListener((ov, o, n) -> {
|
docked.addListener((ov, o, n) -> {
|
||||||
LOG.debug("Change docked, old: {}, new: {}", o, n);
|
LOG.debug("Change docked, old: {}, new: {}", o, n);
|
||||||
@@ -195,6 +199,18 @@ public class ProfileModel {
|
|||||||
this.shipEngine.set(engine);
|
this.shipEngine.set(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RouteModel getRoute() {
|
||||||
|
return route.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<RouteModel> routeProperty() {
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoute(RouteModel route) {
|
||||||
|
this.route.set(route);
|
||||||
|
}
|
||||||
|
|
||||||
private void refresh(){
|
private void refresh(){
|
||||||
name.setValue(profile.getName());
|
name.setValue(profile.getName());
|
||||||
balance.setValue(profile.getBalance());
|
balance.setValue(profile.getBalance());
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ public class RouteEntryModel {
|
|||||||
return entry.getRefill();
|
return entry.getRefill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTransit(){
|
||||||
|
return entry.isTransit();
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableList<OrderModel> orders() {
|
public ObservableList<OrderModel> orders() {
|
||||||
return orders;
|
return orders;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ru.trader.model;
|
package ru.trader.model;
|
||||||
|
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.*;
|
||||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
|
||||||
import javafx.beans.property.SimpleDoubleProperty;
|
|
||||||
import ru.trader.analysis.Route;
|
import ru.trader.analysis.Route;
|
||||||
import ru.trader.analysis.RouteEntry;
|
import ru.trader.analysis.RouteEntry;
|
||||||
import ru.trader.analysis.RouteFiller;
|
import ru.trader.analysis.RouteFiller;
|
||||||
@@ -11,9 +9,7 @@ import ru.trader.core.Offer;
|
|||||||
import ru.trader.core.Order;
|
import ru.trader.core.Order;
|
||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RouteModel {
|
public class RouteModel {
|
||||||
@@ -22,6 +18,7 @@ public class RouteModel {
|
|||||||
private final DoubleProperty profit;
|
private final DoubleProperty profit;
|
||||||
private final DoubleProperty profitByTime;
|
private final DoubleProperty profitByTime;
|
||||||
private final List<RouteEntryModel> entries;
|
private final List<RouteEntryModel> entries;
|
||||||
|
private final IntegerProperty currentEntry;
|
||||||
|
|
||||||
RouteModel(Route route, MarketModel market) {
|
RouteModel(Route route, MarketModel market) {
|
||||||
this.market = market;
|
this.market = market;
|
||||||
@@ -32,6 +29,7 @@ public class RouteModel {
|
|||||||
profitByTime = new SimpleDoubleProperty();
|
profitByTime = new SimpleDoubleProperty();
|
||||||
profitByTime.bind(profit.divide(_route.getTime()));
|
profitByTime.bind(profit.divide(_route.getTime()));
|
||||||
fillSellOrders();
|
fillSellOrders();
|
||||||
|
currentEntry = new SimpleIntegerProperty(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillSellOrders(){
|
private void fillSellOrders(){
|
||||||
@@ -73,6 +71,10 @@ public class RouteModel {
|
|||||||
return _route;
|
return _route;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLoop(){
|
||||||
|
return _route.isLoop();
|
||||||
|
}
|
||||||
|
|
||||||
public int getLands() {
|
public int getLands() {
|
||||||
return _route.getLands();
|
return _route.getLands();
|
||||||
}
|
}
|
||||||
@@ -187,4 +189,69 @@ public class RouteModel {
|
|||||||
fillSellOrders();
|
fillSellOrders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<StationModel> getStations(int offset){
|
||||||
|
Collection<StationModel> res = new HashSet<>();
|
||||||
|
int startIndex = _route.isLoop() ? 1 : offset+1;
|
||||||
|
if (startIndex >= entries.size()) return res;
|
||||||
|
entries.subList(startIndex, entries.size()).stream().map(RouteEntryModel::getStation)
|
||||||
|
.filter(station -> station != ModelFabric.NONE_STATION)
|
||||||
|
.forEach(res::add);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<OfferModel> getSellOffers(int offset){
|
||||||
|
Map<ItemModel, OfferModel> res = new HashMap<>();
|
||||||
|
for (StationModel station : getStations(offset)) {
|
||||||
|
for (OfferModel offer : station.getSells()) {
|
||||||
|
if (offer.getItem().isMarketItem()){
|
||||||
|
OfferModel old = res.get(offer.getItem());
|
||||||
|
if (old == null || old.getPrice() > offer.getPrice()){
|
||||||
|
res.put(offer.getItem(), offer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentEntry() {
|
||||||
|
return currentEntry.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerProperty currentEntryProperty() {
|
||||||
|
return currentEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentEntry(int currentEntry) {
|
||||||
|
this.currentEntry.set(currentEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateCurrentEntry(SystemModel system, StationModel station) {
|
||||||
|
for (int i = getCurrentEntry()+1; i < entries.size(); i++) {
|
||||||
|
RouteEntryModel entry = entries.get(i);
|
||||||
|
if (system.equals(entry.getStation().getSystem())
|
||||||
|
&& (station == null || station == ModelFabric.NONE_STATION ||
|
||||||
|
station.equals(entry.getStation()))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
setCurrentEntry(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!entry.isTransit()) return;
|
||||||
|
}
|
||||||
|
if (isLoop()){
|
||||||
|
for (int i = 0; i < getCurrentEntry()-1; i++) {
|
||||||
|
RouteEntryModel entry = entries.get(i);
|
||||||
|
if (system.equals(entry.getStation().getSystem())
|
||||||
|
&& (station == null || station == ModelFabric.NONE_STATION ||
|
||||||
|
station.equals(entry.getStation()))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
setCurrentEntry(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!entry.isTransit()) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ import ru.trader.model.OfferModel;
|
|||||||
import ru.trader.model.support.ModelBindings;
|
import ru.trader.model.support.ModelBindings;
|
||||||
|
|
||||||
public class OfferListCell implements Callback<ListView<OfferModel>, ListCell<OfferModel>> {
|
public class OfferListCell implements Callback<ListView<OfferModel>, ListCell<OfferModel>> {
|
||||||
|
private final boolean asItem;
|
||||||
|
|
||||||
|
public OfferListCell(){
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OfferListCell(boolean toItemString){
|
||||||
|
asItem = toItemString;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListCell<OfferModel> call(ListView<OfferModel> param){
|
public ListCell<OfferModel> call(ListView<OfferModel> param){
|
||||||
@@ -19,7 +28,7 @@ public class OfferListCell implements Callback<ListView<OfferModel>, ListCell<Of
|
|||||||
if (!empty){
|
if (!empty){
|
||||||
if (o != offer){
|
if (o != offer){
|
||||||
textProperty().unbind();
|
textProperty().unbind();
|
||||||
textProperty().bind(ModelBindings.asString(offer));
|
textProperty().bind(asItem ? ModelBindings.asItemString(offer) : ModelBindings.asString(offer));
|
||||||
o = offer;
|
o = offer;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<HBox><Label text="Станция:" /><Label fx:id="station" /></HBox>
|
<HBox><Label text="Станция:" /><Label fx:id="station" /></HBox>
|
||||||
<HBox><Label text="Время:" /><Label fx:id="time" /></HBox>
|
<HBox><Label text="Время:" /><Label fx:id="time" /></HBox>
|
||||||
<HBox><Label text="Заправить:" /><Label fx:id="refuel" /></HBox>
|
<HBox><Label text="Заправить:" /><Label fx:id="refuel" /></HBox>
|
||||||
<HBox maxHeight="200">
|
<HBox maxHeight="100">
|
||||||
<VBox>
|
<VBox>
|
||||||
<Label text="Продать:" />
|
<Label text="Продать:" />
|
||||||
<ListView fx:id="sellOrders"/>
|
<ListView fx:id="sellOrders"/>
|
||||||
@@ -24,10 +24,20 @@
|
|||||||
<ListView fx:id="buyOrders"/>
|
<ListView fx:id="buyOrders"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
</HBox>
|
</HBox>
|
||||||
<VBox>
|
<VBox maxHeight="100">
|
||||||
<Label text="Сдать миссии:" />
|
<Label text="Сдать миссии:" />
|
||||||
<ListView fx:id="missions"/>
|
<ListView fx:id="missions"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
<HBox>
|
||||||
|
<VBox maxHeight="100">
|
||||||
|
<Label text="Станции:" />
|
||||||
|
<ListView fx:id="stations"/>
|
||||||
|
</VBox>
|
||||||
|
<VBox maxHeight="100">
|
||||||
|
<Label text="Товары:" />
|
||||||
|
<ListView fx:id="sellOffers"/>
|
||||||
|
</VBox>
|
||||||
|
</HBox>
|
||||||
<HBox>
|
<HBox>
|
||||||
<Button prefWidth="30" onAction="#previous">
|
<Button prefWidth="30" onAction="#previous">
|
||||||
<graphic><Glyph text="FontAwesome|ARROW_LEFT"/></graphic>
|
<graphic><Glyph text="FontAwesome|ARROW_LEFT"/></graphic>
|
||||||
|
|||||||
Reference in New Issue
Block a user