add CC compute and stat to PowerPlay
This commit is contained in:
@@ -17,6 +17,7 @@ import ru.trader.analysis.PowerPlayAnalyzator;
|
||||
import ru.trader.core.*;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.PowerStateStringConverter;
|
||||
import ru.trader.view.support.PowerStringConverter;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
@@ -25,6 +26,7 @@ import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||
import ru.trader.view.support.autocomplete.SystemsProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -67,6 +69,10 @@ public class PowerPlayController {
|
||||
private Label resultPopSumm;
|
||||
@FXML
|
||||
private Label detailPopSumm;
|
||||
@FXML
|
||||
private Label resultCCSumm;
|
||||
@FXML
|
||||
private Label detailCCSumm;
|
||||
|
||||
private MarketModel world;
|
||||
private ProfileModel profile;
|
||||
@@ -173,11 +179,15 @@ public class PowerPlayController {
|
||||
});
|
||||
tblDetail.setOnDragDetected(new StarSystemDragDetect(tblDetail));
|
||||
NumberStringConverter converter = new NumberStringConverter("#,##0.##");
|
||||
result.addListener((InvalidationListener) i ->
|
||||
resultPopSumm.setText(converter.toString(getPopulationSumm(result)))
|
||||
result.addListener((InvalidationListener) i -> {
|
||||
resultPopSumm.setText(converter.toString(getPopulationSumm(result)));
|
||||
resultCCSumm.setText(getCCSummText(result));
|
||||
}
|
||||
);
|
||||
detail.addListener((InvalidationListener) i ->
|
||||
detailPopSumm.setText(converter.toString(getPopulationSumm(detail)))
|
||||
detail.addListener((InvalidationListener) i -> {
|
||||
detailPopSumm.setText(converter.toString(getPopulationSumm(detail)));
|
||||
detailCCSumm.setText(getCCSummText(detail));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -185,11 +195,46 @@ public class PowerPlayController {
|
||||
return collection.stream().mapToLong(ResultEntry::getPopulation).sum();
|
||||
}
|
||||
|
||||
private String getCCSummText(Collection<ResultEntry> collection){
|
||||
String ccFormat = Localization.getString("powerplay.label.summcc");
|
||||
String pwCCFormat = Localization.getString("powerplay.label.cc");
|
||||
PowerStringConverter converter = new PowerStringConverter();
|
||||
long[] contestedCc = new long[POWER.values().length];
|
||||
long[] totalCc = new long[POWER.values().length];
|
||||
long contested = 0;
|
||||
long summCc = 0;
|
||||
for (ResultEntry entry : collection) {
|
||||
long cc = entry.getCc();
|
||||
summCc += cc;
|
||||
if (entry.getPower() == null || entry.getPowerState() == null) continue;
|
||||
if (entry.getPowerState() != POWER_STATE.NONE){
|
||||
contested += cc;
|
||||
if (entry.getPowerState() == POWER_STATE.CONTESTED){
|
||||
for (Place place : entry.getControllingSystems()){
|
||||
contestedCc[place.getPower().ordinal()] += cc;
|
||||
}
|
||||
} else {
|
||||
totalCc[entry.getPower().ordinal()] += cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(String.format(ccFormat, summCc, contested, summCc - contested));
|
||||
for (int i = 0; i < POWER.values().length; i++) {
|
||||
if (totalCc[i] > 0 || contestedCc[i] > 0){
|
||||
builder.append("\n");
|
||||
builder.append(String.format(pwCCFormat, converter.toString(POWER.values()[i]), totalCc[i], contestedCc[i]));
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void fillDetail(SystemModel detailSystem) {
|
||||
final Place starSystem = ModelFabric.get(detailSystem);
|
||||
detail.clear();
|
||||
if (starSystem != null){
|
||||
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem);
|
||||
controllings.add(new PowerPlayAnalyzator.IntersectData(starSystem));
|
||||
detail.addAll(BindingsHelper.observableList(controllings, d -> new ResultEntry(d, starSystem)));
|
||||
}
|
||||
}
|
||||
@@ -210,6 +255,7 @@ public class PowerPlayController {
|
||||
result.clear();
|
||||
if (starSystem != null){
|
||||
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem);
|
||||
controllings.add(new PowerPlayAnalyzator.IntersectData(starSystem));
|
||||
result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem)));
|
||||
}
|
||||
}
|
||||
@@ -366,6 +412,7 @@ public class PowerPlayController {
|
||||
private final ReadOnlyLongProperty population;
|
||||
private final ReadOnlyLongProperty upkeep;
|
||||
private final ReadOnlyLongProperty income;
|
||||
private final ReadOnlyLongProperty cc;
|
||||
|
||||
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
||||
this(data, null);
|
||||
@@ -383,7 +430,7 @@ public class PowerPlayController {
|
||||
population = new SimpleLongProperty(data.getStarSystem().getPopulation());
|
||||
upkeep = new SimpleLongProperty(data.getStarSystem().getUpkeep());
|
||||
income = new SimpleLongProperty(data.getStarSystem().getIncome());
|
||||
|
||||
cc = new SimpleLongProperty(data.getStarSystem().computeCC(ModelFabric.get(profile).getCCgroups()));
|
||||
}
|
||||
|
||||
private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
|
||||
@@ -461,6 +508,11 @@ public class PowerPlayController {
|
||||
return intersectCount;
|
||||
}
|
||||
|
||||
private Collection<Place> getControllingSystems(){
|
||||
Place place = ModelFabric.get(starSystem);
|
||||
return place != null ? place.getControllingSystems() : Collections.emptyList();
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty controllingProperty() {
|
||||
return controlling;
|
||||
}
|
||||
@@ -488,6 +540,14 @@ public class PowerPlayController {
|
||||
public ReadOnlyStringProperty nearStationsProperty() {
|
||||
return nearStations;
|
||||
}
|
||||
|
||||
public long getCc() {
|
||||
return cc.get();
|
||||
}
|
||||
|
||||
public ReadOnlyLongProperty ccProperty() {
|
||||
return cc;
|
||||
}
|
||||
}
|
||||
|
||||
private class StarSystemDragDetect implements EventHandler<MouseEvent> {
|
||||
|
||||
@@ -11,6 +11,7 @@ market.economic=Economy
|
||||
market.power=Power
|
||||
market.powerState=State
|
||||
market.population=Population
|
||||
market.cc=CC
|
||||
|
||||
#Item
|
||||
market.item=Commodity
|
||||
@@ -283,6 +284,8 @@ powerplay.label.controlling=Controlled systems:
|
||||
powerplay.label.power.systems=Systems of Power:
|
||||
powerplay.label.power.state=State:
|
||||
powerplay.label.populationSumm=Summ populations:
|
||||
powerplay.label.cc=%s: %4d CC Contested: %4d CC
|
||||
powerplay.label.summcc=Summ: %6d CC Contested: %6d CC Total: %6dCC
|
||||
powerplay.result.title=Analyze result
|
||||
powerplay.column.intersecting=Intersect
|
||||
powerplay.column.intersectCount=Intersect count
|
||||
|
||||
@@ -11,6 +11,7 @@ market.economic=\u042D\u043A\u043E\u043D\u043E\u043C\u0438\u043A\u0430
|
||||
market.power=\u0421\u0438\u043B\u0430
|
||||
market.powerState=\u0421\u0442\u0430\u0442\u0443\u0441
|
||||
market.population=\u041D\u0430\u0441\u0435\u043B\u0435\u043D\u0438\u0435
|
||||
market.cc=\u041A\u041A
|
||||
|
||||
#Item
|
||||
market.item=\u0422\u043E\u0432\u0430\u0440
|
||||
@@ -283,6 +284,8 @@ powerplay.label.controlling=\u041A\u043E\u043D\u0442\u0440\u043E\u043B\u043B\u04
|
||||
powerplay.label.power.systems=C\u0438\u0441\u0442\u0435\u043C\u044B \u0441\u0438\u043B\u044B:
|
||||
powerplay.label.power.state=\u0421\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435:
|
||||
powerplay.label.populationSumm=\u0421\u0443\u043C\u043C\u0430 \u043D\u0430\u0441\u0435\u043B\u0435\u043D\u0438\u044F:
|
||||
powerplay.label.cc=%s: %4d \u041A\u041A \u041E\u0441\u043F\u0430\u0440\u0438\u0432\u0430\u0435\u043C\u044B\u0445: %4d \u041A\u041A
|
||||
powerplay.label.summcc=\u0421\u0443\u043C\u043C\u0430: %6d \u041A\u041A \u041E\u0441\u043F\u0430\u0440\u0438\u0432\u0430\u0435\u043C\u044B\u0445: %6d \u041A\u041A \u0418\u0442\u043E\u0433\u043E: %6d\u041A\u041A
|
||||
powerplay.result.title=\u0420\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442\u044B \u0430\u043D\u0430\u043B\u0438\u0437\u0430
|
||||
powerplay.column.intersecting=\u041F\u0435\u0440\u0435\u0441\u0435\u043A\u0430\u0435\u0442\u0441\u044F \u0441
|
||||
powerplay.column.intersectCount=\u041F\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043D\u0438\u0439
|
||||
|
||||
@@ -122,6 +122,9 @@
|
||||
<cellFactory><DistanceCell /></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="60" text="%market.cc">
|
||||
<cellValueFactory><PropertyValueFactory property="cc"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="60" text="%market.system.income">
|
||||
<cellValueFactory><PropertyValueFactory property="income"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
@@ -154,7 +157,12 @@
|
||||
</ContextMenu>
|
||||
</contextMenu>
|
||||
</TableView>
|
||||
<HBox spacing="4" padding="$summPadding"><Label text="%powerplay.label.populationSumm" /><Label fx:id="resultPopSumm" /></HBox>
|
||||
<ScrollPane minHeight="50">
|
||||
<VBox spacing="4" padding="$summPadding">
|
||||
<HBox spacing="4"><Label text="%powerplay.label.populationSumm" /><Label fx:id="resultPopSumm" /></HBox>
|
||||
<HBox spacing="4"><Label fx:id="resultCCSumm" wrapText="true"/></HBox>
|
||||
</VBox>
|
||||
</ScrollPane>
|
||||
</VBox>
|
||||
</TitledPane>
|
||||
</masterNode>
|
||||
@@ -182,6 +190,9 @@
|
||||
<cellFactory><TextCell><converter><FactionStringConverter /></converter></TextCell></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="60" text="%market.cc">
|
||||
<cellValueFactory><PropertyValueFactory property="cc"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="60" text="%market.system.income">
|
||||
<cellValueFactory><PropertyValueFactory property="income"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
@@ -207,7 +218,12 @@
|
||||
</ContextMenu>
|
||||
</contextMenu>
|
||||
</TableView>
|
||||
<HBox spacing="4" padding="$summPadding"><Label text="%powerplay.label.populationSumm" /><Label fx:id="detailPopSumm" /></HBox>
|
||||
<ScrollPane minHeight="50">
|
||||
<VBox spacing="4" padding="$summPadding">
|
||||
<HBox spacing="4"><Label text="%powerplay.label.populationSumm" /><Label fx:id="detailPopSumm" /></HBox>
|
||||
<HBox spacing="4"><Label fx:id="detailCCSumm" wrapText="true"/></HBox>
|
||||
</VBox>
|
||||
</ScrollPane>
|
||||
</VBox>
|
||||
</TitledPane>
|
||||
</detailNode>
|
||||
|
||||
Reference in New Issue
Block a user