Archived
0

route edit prototype

This commit is contained in:
iMoHax
2015-11-06 16:44:08 +03:00
parent 36f9a34aa5
commit 24c0fb055e
6 changed files with 104 additions and 2 deletions

View File

@@ -6,13 +6,18 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import ru.trader.model.*;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.Track;
import ru.trader.view.support.ViewUtils;
import ru.trader.view.support.autocomplete.AutoCompletion;
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
import ru.trader.view.support.autocomplete.SystemsProvider;
import ru.trader.view.support.cells.OrderListCell;
import java.util.stream.Collectors;
@@ -47,6 +52,11 @@ public class RouteTrackController {
private MissionsController missionsController;
@FXML
private Pane track;
@FXML
private TextField newEntrySystemText;
private AutoCompletion<SystemModel> newEntrySystem;
@FXML
private ComboBox<String> newEntryStation;
private RouteModel route;
private Track trackNode;
@@ -58,12 +68,25 @@ public class RouteTrackController {
sellOrders.setCellFactory(new OrderListCell(true));
editGroup.setVisible(false);
init();
newEntrySystem.valueProperty().addListener((ov, o , n) -> {
newEntryStation.setItems(n.getStationNamesList());
newEntryStation.getSelectionModel().selectFirst();
});
}
void init(){
ProfileModel profile = MainController.getProfile();
profile.routeProperty().addListener(routeListener);
setRoute(profile.getRoute());
MarketModel market = MainController.getMarket();
SystemsProvider provider = market.getSystemsProvider();
if (newEntrySystem == null){
newEntrySystem = new AutoCompletion<>(newEntrySystemText, new CachedSuggestionProvider<>(provider), ModelFabric.NONE_SYSTEM, provider.getConverter());
} else {
newEntrySystem.setSuggestions(provider.getPossibleSuggestions());
newEntrySystem.setConverter(provider.getConverter());
}
newEntryStation.setValue(ModelFabric.NONE_STATION.getName());
}
void unbind(){
@@ -173,6 +196,39 @@ public class RouteTrackController {
}
@FXML
private void addEntry(){
SystemModel toSystem = newEntrySystem.getValue();
StationModel toStation = toSystem != null ? toSystem.get(newEntryStation.getValue()) : ModelFabric.NONE_STATION;
if (!ModelFabric.isFake(toSystem)){
if (route != null){
if (!ModelFabric.isFake(toStation)){
setRoute(route.add(toStation));
} else {
setRoute(route.add(toSystem));
}
} else {
RouteModel r;
if (!ModelFabric.isFake(toStation)){
r = RouteModel.asRoute(toStation);
} else {
r = RouteModel.asRoute(toSystem);
}
setRoute(r);
}
}
}
@FXML
private void setActive(){
MainController.getProfile().setRoute(route);
}
@FXML
private void clear(){
setRoute(null);
}
private final ChangeListener<? super Number> currentEntryListener = (ov, o, n) -> ViewUtils.doFX(() -> setIndex(n.intValue()));
private final InvalidationListener activeEntryListener = ov -> ViewUtils.doFX(this::update);
private final ChangeListener<RouteModel> routeListener = (ov, o, n) -> ViewUtils.doFX(() -> setRoute(n));

View File

@@ -129,6 +129,20 @@ public class RouteModel {
return getCopy();
}
public RouteModel add(SystemModel system){
RouteEntryModel last = entries.get(entries.size()-1);
StationModel fromStation = last.getStation();
RouteModel path = market.getPath(fromStation.getSystem(), fromStation, system, ModelFabric.NONE_STATION);
return add(path);
}
public RouteModel add(StationModel station){
RouteEntryModel last = entries.get(entries.size()-1);
StationModel fromStation = last.getStation();
RouteModel path = market.getPath(fromStation.getSystem(), fromStation, station.getSystem(), station);
return add(path);
}
public RouteModel add(RouteModel route){
_route.join(route.getRoute());
return getCopy();
@@ -352,4 +366,15 @@ public class RouteModel {
}
fillSellOrders();
}
public static RouteModel asRoute(SystemModel system){
Route route = new Route(new RouteEntry(system.getSystem().asTransit(),0,0,0));
return new RouteModel(route, system.getMarket());
}
public static RouteModel asRoute(StationModel station){
Route route = new Route(new RouteEntry(station.getStation(),0,0,0));
return new RouteModel(route, station.getMarket());
}
}

View File

@@ -35,6 +35,10 @@ public class StationModel {
return station;
}
MarketModel getMarket(){
return market;
}
public String getName() {return station.getName();}
public void setName(String value) {

View File

@@ -37,6 +37,10 @@ public class SystemModel {
return system;
}
MarketModel getMarket(){
return market;
}
public String getName() {return name != null ? name.get() : system.getName();}
public void setName(String value) {

View File

@@ -46,6 +46,17 @@
</VBox>
</StackPane>
</VBox>
<VBox fx:id="track" minWidth="200"/>
<VBox>
<VBox fx:id="track" minWidth="200"/>
<VBox>
<HBox><TextField fx:id="newEntrySystemText"/></HBox>
<HBox><ComboBox fx:id="newEntryStation"/></HBox>
<HBox>
<Button onAction="#addEntry"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
<Button onAction="#setActive"><graphic><Glyph text="FontAwesome|MAP_MARKER"/></graphic></Button>
<Button onAction="#clear"><graphic><Glyph text="FontAwesome|TRASH"/></graphic></Button>
</HBox>
</VBox>
</VBox>
</HBox>