Archived
0

select next entry on undocked and jump to transit entry

This commit is contained in:
iMoHax
2015-10-01 14:02:48 +03:00
parent 99c8e42f44
commit 44f6dd67cf
5 changed files with 56 additions and 23 deletions

View File

@@ -11,10 +11,7 @@ import org.controlsfx.control.SegmentedButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.SERVICE_TYPE;
import ru.trader.model.MarketModel;
import ru.trader.model.OfferModel;
import ru.trader.model.StationModel;
import ru.trader.model.SystemModel;
import ru.trader.model.*;
import ru.trader.model.support.BindingsHelper;
import ru.trader.model.support.ChangeMarketListener;
import ru.trader.view.support.FactionStringConverter;
@@ -83,7 +80,7 @@ public class OffersController {
if (n != null){
fillTables((StationModel) n.getUserData());
} else {
fillTables(null);
fillTables(ModelFabric.NONE_STATION);
}
});
stationsBar.setToggleGroup(stationsGrp);
@@ -126,9 +123,9 @@ public class OffersController {
stations.forEach(s -> stationsBar.getButtons().add(buildStationNode(s)));
if (!stations.isEmpty()){
stationsBar.getButtons().get(0).setSelected(true);
} else {
fillTables(ModelFabric.NONE_STATION);
}
fillTables(stations.isEmpty() ? null : stations.get(0));
}
private ToggleButton buildStationNode(StationModel station){
@@ -153,7 +150,7 @@ public class OffersController {
cbShipyard.setSelected(false);
cbMediumLandpad.setSelected(false);
cbLargeLandpad.setSelected(false);
if (station != null){
if (station != ModelFabric.NONE_STATION){
faction.setText(FactionStringConverter.toLocalizationString(station.getFaction()));
government.setText(GovernmentStringConverter.toLocalizationString(station.getGovernment()));
distance.setText(String.valueOf(station.getDistance()));

View File

@@ -5,6 +5,7 @@ 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.util.StringConverter;
@@ -28,6 +29,8 @@ public class ProfileController {
@FXML
private ComboBox<StationModel> station;
@FXML
private CheckBox docked;
@FXML
private NumberField mass;
@FXML
private NumberField tank;
@@ -79,6 +82,7 @@ public class ProfileController {
consumeChanges(() -> {profile.setSystem(n); profile.setStation(ModelFabric.NONE_STATION);});
});
station.valueProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setStation(n)));
docked.selectedProperty().addListener((ov, o, n) -> consumeChanges(() -> profile.setDocked(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())));
@@ -90,14 +94,17 @@ public class ProfileController {
unbind();
}
this.profile = profile;
ignoreChanges = true;
name.setText(profile.getName());
balance.setValue(profile.getBalance());
system.setValue(profile.getSystem());
station.setValue(profile.getStation());
docked.setSelected(profile.isDocked());
mass.setValue(profile.getShipMass());
tank.setValue(profile.getShipTank());
cargo.setValue(profile.getShipCargo());
engine.setValue(profile.getShipEngine());
ignoreChanges = false;
bind();
}
@@ -106,6 +113,7 @@ public class ProfileController {
profile.balanceProperty().addListener(balanceListener);
profile.systemProperty().addListener(systemListener);
profile.stationProperty().addListener(stationListener);
profile.dockedProperty().addListener(dockedListener);
profile.shipMassProperty().addListener(massListener);
profile.shipTankProperty().addListener(tankListener);
profile.shipCargoProperty().addListener(cargoListener);
@@ -117,6 +125,7 @@ public class ProfileController {
profile.balanceProperty().removeListener(balanceListener);
profile.systemProperty().removeListener(systemListener);
profile.stationProperty().removeListener(stationListener);
profile.dockedProperty().removeListener(dockedListener);
profile.shipMassProperty().removeListener(massListener);
profile.shipTankProperty().removeListener(tankListener);
profile.shipCargoProperty().removeListener(cargoListener);
@@ -128,6 +137,7 @@ public class ProfileController {
private final ChangeListener<Number> balanceListener = (ov, o, n) -> consumeChanges(() -> balance.setValue(n));
private final ChangeListener<SystemModel> systemListener = (ov, o, n) -> consumeChanges(() -> system.setValue(n));
private final ChangeListener<StationModel> stationListener = (ov, o, n) -> consumeChanges(() -> station.setValue(n));
private final ChangeListener<Boolean> dockedListener = (ov, o, n) -> consumeChanges(() -> docked.setSelected(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<Number> cargoListener = (ov, o, n) -> consumeChanges(() -> cargo.setValue(n));

View File

@@ -52,7 +52,7 @@ public class ProfileModel {
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, null);}
if (route.getValue() != null) {getRoute().updateCurrentEntry(n);}
});
station.addListener((ov, o, n) -> {
LOG.debug("Change station, old: {}, new: {}", o, n);
@@ -62,6 +62,7 @@ public class ProfileModel {
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);

View File

@@ -226,9 +226,31 @@ public class RouteModel {
this.currentEntry.set(currentEntry);
}
public void updateCurrentEntry(SystemModel system) {
updateCurrentEntry(system, null, false);
}
public void updateCurrentEntry(SystemModel system, StationModel station) {
for (int i = getCurrentEntry()+1; i < entries.size(); i++) {
RouteEntryModel entry = entries.get(i);
updateCurrentEntry(system, station, false);
}
public void updateCurrentEntry(SystemModel system, StationModel station, boolean undock) {
if (undock){
int index = getCurrentEntry();
RouteEntryModel entry = entries.get(index);
if (index < entries.size()-1 && system.equals(entry.getStation().getSystem()) && entry.getStation().equals(station)){
setCurrentEntry(index+1);
}
} else {
int index = getCurrentEntry();
RouteEntryModel entry = entries.get(index);
if (entry.isTransit() && index < entries.size()-1 && system.equals(entry.getStation().getSystem())){
setCurrentEntry(index+1);
return;
}
for (int i = index+1; i < entries.size(); i++) {
entry = entries.get(i);
if (system.equals(entry.getStation().getSystem())
&& (station == null || station == ModelFabric.NONE_STATION ||
station.equals(entry.getStation()))
@@ -240,8 +262,8 @@ public class RouteModel {
if (!entry.isTransit()) return;
}
if (isLoop()){
for (int i = 0; i < getCurrentEntry()-1; i++) {
RouteEntryModel entry = entries.get(i);
for (int i = 0; i < index-1; i++) {
entry = entries.get(i);
if (system.equals(entry.getStation().getSystem())
&& (station == null || station == ModelFabric.NONE_STATION ||
station.equals(entry.getStation()))
@@ -254,4 +276,5 @@ public class RouteModel {
}
}
}
}
}

View File

@@ -19,6 +19,8 @@
<Label text="Станция:" />
<ComboBox fx:id="station" />
<Button fx:id="btnAddStation"/>
<Label text="В доке:" />
<CheckBox fx:id="docked" />
<VBox>
<HBox>
<Label text="Трюм:" />