Archived
0

automate select near land marks on edit system

This commit is contained in:
iMoHax
2015-10-16 14:00:01 +03:00
parent fa58d08c1e
commit 78fc54f5fb
6 changed files with 139 additions and 10 deletions

View File

@@ -164,7 +164,7 @@ public class ProfileController {
profile.shipTankProperty().addListener(tankListener); profile.shipTankProperty().addListener(tankListener);
profile.shipCargoProperty().addListener(cargoListener); profile.shipCargoProperty().addListener(cargoListener);
profile.shipEngineProperty().addListener(engineListener); profile.shipEngineProperty().addListener(engineListener);
jumpRange.textProperty().bind(Bindings.createStringBinding(()-> String.format("%.1f - %.1f", profile.getShipJumpRange(), profile.getMaxShipJumpRange()), jumpRange.textProperty().bind(Bindings.createStringBinding(()-> String.format("%.1f - %.1f - %.1f", profile.getShipJumpRange(), profile.getMaxShipJumpRange(), profile.getEmptyMaxShipJumpRange()),
profile.shipMassProperty(), profile.shipCargoProperty(), profile.shipTankProperty(), profile.shipEngineProperty() profile.shipMassProperty(), profile.shipCargoProperty(), profile.shipTankProperty(), profile.shipEngineProperty()
)); ));
} }

View File

@@ -12,8 +12,10 @@ import javafx.util.converter.DefaultStringConverter;
import javafx.util.converter.DoubleStringConverter; import javafx.util.converter.DoubleStringConverter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ru.trader.Main;
import ru.trader.model.MarketModel; import ru.trader.model.MarketModel;
import ru.trader.model.ModelFabric; import ru.trader.model.ModelFabric;
import ru.trader.model.ProfileModel;
import ru.trader.model.SystemModel; import ru.trader.model.SystemModel;
import ru.trader.model.support.PositionComputer; import ru.trader.model.support.PositionComputer;
import ru.trader.view.support.Localization; import ru.trader.view.support.Localization;
@@ -168,12 +170,27 @@ public class SystemsEditorController {
private void fill(SystemModel system){ private void fill(SystemModel system){
if (system != null){ if (system != null){
tblSystems.getItems().add(new SystemData(system)); tblSystems.getItems().add(new SystemData(system));
ProfileModel profile = MainController.getProfile();
SystemModel s = profile.getPrevSystem();
if (!ModelFabric.isFake(s)){
searchLandMark(s, profile.getEmptyMaxShipJumpRange()*1.5);
}
} }
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
add(); add();
} }
} }
private void searchLandMark(SystemModel system, double maxDistance){
double x = system.getX(), y = system.getY(), z = system.getZ(), e = 6;
system1.setValue(market.getNear(x + maxDistance, y, z, Double.POSITIVE_INFINITY, e, e));
system2.setValue(market.getNear(x - maxDistance, y, z, Double.NEGATIVE_INFINITY, e, e));
system3.setValue(market.getNear(x, y + maxDistance, z, e, Double.POSITIVE_INFINITY, e));
system4.setValue(market.getNear(x, y - maxDistance, z, e, Double.NEGATIVE_INFINITY, e));
system5.setValue(market.getNear(x, y, z + maxDistance, e, e, Double.POSITIVE_INFINITY));
system6.setValue(market.getNear(x, y, z - maxDistance, e, e, Double.NEGATIVE_INFINITY));
}
public void add(){ public void add(){
tblSystems.getItems().add(new SystemData()); tblSystems.getItems().add(new SystemData());
} }
@@ -202,6 +219,36 @@ public class SystemsEditorController {
} }
} }
@FXML
private void copySys1(){
Main.copyToClipboard(system1Text.getText());
}
@FXML
private void copySys2(){
Main.copyToClipboard(system2Text.getText());
}
@FXML
private void copySys3(){
Main.copyToClipboard(system3Text.getText());
}
@FXML
private void copySys4(){
Main.copyToClipboard(system4Text.getText());
}
@FXML
private void copySys5(){
Main.copyToClipboard(system5Text.getText());
}
@FXML
private void copySys6(){
Main.copyToClipboard(system6Text.getText());
}
private void commit(){ private void commit(){
for (SystemData systemData : tblSystems.getItems()) { for (SystemData systemData : tblSystems.getItems()) {
systemData.commit(); systemData.commit();

View File

@@ -92,6 +92,14 @@ public class MarketModel {
return modeler.get(s); return modeler.get(s);
} }
public SystemModel getNear(double x, double y, double z, double xlimit, double ylimit, double zlimit){
Place s = market.getNear(x, y, z, xlimit, ylimit, zlimit);
if (s == null){
return ModelFabric.NONE_SYSTEM;
}
return modeler.get(s);
}
public SystemModel add(String name, double x, double y, double z) { public SystemModel add(String name, double x, double y, double z) {
SystemModel system = modeler.get(market.addPlace(name, x, y, z)); SystemModel system = modeler.get(market.addPlace(name, x, y, z));
LOG.info("Add system {} to market {}", system, this); LOG.info("Add system {} to market {}", system, this);

View File

@@ -14,6 +14,7 @@ public class ProfileModel {
private final MarketModel market; private final MarketModel market;
private final StringProperty name; private final StringProperty name;
private final DoubleProperty balance; private final DoubleProperty balance;
private final ObjectProperty<SystemModel> prevSystem;
private final ObjectProperty<SystemModel> system; private final ObjectProperty<SystemModel> system;
private final ObjectProperty<StationModel> station; private final ObjectProperty<StationModel> station;
private final BooleanProperty docked; private final BooleanProperty docked;
@@ -29,6 +30,7 @@ public class ProfileModel {
name = new SimpleStringProperty(); name = new SimpleStringProperty();
balance = new SimpleDoubleProperty(); balance = new SimpleDoubleProperty();
system = new SimpleObjectProperty<>(); system = new SimpleObjectProperty<>();
prevSystem = new SimpleObjectProperty<>();
station = new SimpleObjectProperty<>(); station = new SimpleObjectProperty<>();
docked = new SimpleBooleanProperty(); docked = new SimpleBooleanProperty();
shipMass = new SimpleDoubleProperty(); shipMass = new SimpleDoubleProperty();
@@ -45,7 +47,10 @@ public class ProfileModel {
balance.addListener((ov, o, n) -> LOG.debug("Change balance, old: {}, new: {}", o, n)); balance.addListener((ov, o, n) -> LOG.debug("Change balance, old: {}, new: {}", o, n));
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);
if (!ModelFabric.isFake(o)) prevSystem.setValue(o);
if (!ModelFabric.isFake(n)){
if (route.getValue() != null) {getRoute().updateCurrentEntry(n);} if (route.getValue() != null) {getRoute().updateCurrentEntry(n);}
}
}); });
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);
@@ -96,6 +101,14 @@ public class ProfileModel {
this.balance.set(balance); this.balance.set(balance);
} }
public SystemModel getPrevSystem() {
return prevSystem.get();
}
public ReadOnlyObjectProperty<SystemModel> prevSystemProperty() {
return prevSystem;
}
public SystemModel getSystem() { public SystemModel getSystem() {
return system.get(); return system.get();
} }
@@ -207,6 +220,10 @@ public class ProfileModel {
return profile.getShip().getMaxJumpRange(); return profile.getShip().getMaxJumpRange();
} }
public double getEmptyMaxShipJumpRange(){
return profile.getShip().getEmptyMaxJumpRange();
}
private void refresh(){ private void refresh(){
name.setValue(profile.getName()); name.setValue(profile.getName());
balance.setValue(profile.getBalance()); balance.setValue(profile.getBalance());

View File

@@ -23,12 +23,30 @@
</columnConstraints> </columnConstraints>
<Label text="%sEditor.text.orientates" prefWidth="170" GridPane.rowSpan="2"/> <Label text="%sEditor.text.orientates" prefWidth="170" GridPane.rowSpan="2"/>
<TextField fx:id="system1Text" prefWidth="160" GridPane.columnIndex="1" /> <HBox GridPane.columnIndex="1">
<TextField fx:id="system2Text" prefWidth="160" GridPane.columnIndex="2" /> <TextField fx:id="system1Text" prefWidth="160"/>
<TextField fx:id="system3Text" prefWidth="160" GridPane.columnIndex="3" /> <Button minWidth="30" onAction="#copySys1"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
<TextField fx:id="system4Text" prefWidth="160" GridPane.rowIndex="1" GridPane.columnIndex="1" /> </HBox>
<TextField fx:id="system5Text" prefWidth="160" GridPane.rowIndex="1" GridPane.columnIndex="2" /> <HBox GridPane.columnIndex="2">
<TextField fx:id="system6Text" prefWidth="160" GridPane.rowIndex="1" GridPane.columnIndex="3" /> <TextField fx:id="system2Text" prefWidth="160"/>
<Button minWidth="30" onAction="#copySys2"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
</HBox>
<HBox GridPane.columnIndex="3">
<TextField fx:id="system3Text" prefWidth="160"/>
<Button minWidth="30" onAction="#copySys3"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
</HBox>
<HBox GridPane.rowIndex="1" GridPane.columnIndex="1">
<TextField fx:id="system4Text" prefWidth="160"/>
<Button minWidth="30" onAction="#copySys4"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
</HBox>
<HBox GridPane.rowIndex="1" GridPane.columnIndex="2">
<TextField fx:id="system5Text" prefWidth="160"/>
<Button minWidth="30" onAction="#copySys5"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
</HBox>
<HBox GridPane.rowIndex="1" GridPane.columnIndex="3">
<TextField fx:id="system6Text" prefWidth="160"/>
<Button minWidth="30" onAction="#copySys6"><graphic><Glyph text="FontAwesome|COPY"/></graphic></Button>
</HBox>
<HBox GridPane.rowIndex="2" spacing="4"> <HBox GridPane.rowIndex="2" spacing="4">
<Button prefWidth="30" onAction="#add"> <Button prefWidth="30" onAction="#add">

View File

@@ -27,8 +27,47 @@ public interface Market {
Collection<Place> get(); Collection<Place> get();
default Collection<String> getPlaceNames(){ default Collection<String> getPlaceNames(){
return get() .stream().map(Place::getName).collect(Collectors.toList()); return get().stream().map(Place::getName).collect(Collectors.toList());
} }
default Place getNear(double x, double y, double z, double xlimit, double ylimit, double zlimit){
Optional<Place> place = get().stream()
.filter(p -> {
boolean check = false;
if (xlimit == Double.NEGATIVE_INFINITY){
check = p.getX() < x;
} else {
if (xlimit == Double.POSITIVE_INFINITY){
check = p.getX() > x;
} else {
check = Math.abs(p.getX() - x) < xlimit;
}
}
if (!check) return false;
if (ylimit == Double.NEGATIVE_INFINITY){
check = p.getY() < y;
} else {
if (ylimit == Double.POSITIVE_INFINITY){
check = p.getY() > y;
} else {
check = Math.abs(p.getY() - y) < ylimit;
}
}
if (!check) return false;
if (zlimit == Double.NEGATIVE_INFINITY){
check = p.getZ() < z;
} else {
if (zlimit == Double.POSITIVE_INFINITY){
check = p.getZ() > z;
} else {
check = Math.abs(p.getZ() - z) < zlimit;
}
}
return check;
})
.findFirst();
return place.isPresent() ? place.get() : null;
}
default Collection<Vendor> getVendors(){ default Collection<Vendor> getVendors(){
return getVendors(false); return getVendors(false);
} }
@@ -36,7 +75,7 @@ public interface Market {
return new PlacesWrapper(get(), includeTransit); return new PlacesWrapper(get(), includeTransit);
} }
default Collection<String> getVendorNames(){ default Collection<String> getVendorNames(){
return getVendors() .stream().map(Vendor::getFullName).collect(Collectors.toList()); return getVendors().stream().map(Vendor::getFullName).collect(Collectors.toList());
} }
Collection<Group> getGroups(); Collection<Group> getGroups();
Collection<Item> getItems(); Collection<Item> getItems();