22
33import com .faforever .client .fx .JavaFxUtil ;
44import com .faforever .client .fx .NodeController ;
5+ import com .faforever .client .fx .ToStringOnlyConverter ;
56import com .faforever .client .i18n .I18n ;
67import com .faforever .client .map .generator .GenerationType ;
78import com .faforever .client .map .generator .GeneratorOptions ;
1415import javafx .collections .FXCollections ;
1516import javafx .collections .ObservableList ;
1617import javafx .collections .transformation .FilteredList ;
18+ import javafx .scene .Node ;
1719import javafx .scene .control .Button ;
1820import javafx .scene .control .CheckBox ;
1921import javafx .scene .control .ComboBox ;
2830import javafx .util .StringConverter ;
2931import lombok .RequiredArgsConstructor ;
3032import lombok .extern .slf4j .Slf4j ;
33+ import org .controlsfx .control .RangeSlider ;
3134import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
3235import org .springframework .context .annotation .Scope ;
3336import org .springframework .stereotype .Component ;
@@ -63,55 +66,44 @@ public class GenerateMapController extends NodeController<Pane> {
6366 public Label commandLineLabel ;
6467 public TextField commandLineArgsText ;
6568 public ComboBox <GenerationType > generationTypeComboBox ;
66- public Label mapStyleLabel ;
6769 public ComboBox <String > mapStyleComboBox ;
68- public Label biomeLabel ;
6970 public ComboBox <String > biomeComboBox ;
7071 public Spinner <Integer > spawnCountSpinner ;
7172 public Spinner <Double > mapSizeSpinner ;
72- public Label symmetryLabel ;
7373 public ComboBox <String > symmetryComboBox ;
74- public Label customStyleLabel ;
7574 public CheckBox customStyleCheckBox ;
76- public Label fixedSeedLabel ;
7775 public CheckBox fixedSeedCheckBox ;
7876 public TextField seedTextField ;
7977 public Button seedRerollButton ;
80- public Label terrainLabel ;
8178 public ComboBox <String > terrainComboBox ;
82- public Label resourceLabel ;
8379 public ComboBox <String > resourcesComboBox ;
84- public Label propLabel ;
8580 public ComboBox <String > propsComboBox ;
81+ public RangeSlider reclaimDensitySlider ;
82+ public RangeSlider resourcesDensitySlider ;
8683
8784 private Runnable onCloseButtonClickedListener ;
88- private final ObservableList <Integer > validTeamSizes = FXCollections .observableList (IntStream .range (0 , 17 )
89- .filter (value -> value != 1 )
90- .boxed ()
91- .collect (Collectors .toList ()));
85+ private final ObservableList <Integer > validTeamSizes = FXCollections .observableList (
86+ IntStream .range (0 , 17 ).filter (value -> value != 1 ).boxed ().collect (Collectors .toList ()));
9287 private final FilteredList <Integer > selectableTeamSizes = new FilteredList <>(validTeamSizes );
93- private final ObservableList <Integer > validSpawnCount = FXCollections .observableList (IntStream .range (2 , 17 )
94- .boxed ()
95- .collect (Collectors .toList ()));
88+ private final ObservableList <Integer > validSpawnCount = FXCollections .observableList (
89+ IntStream .range (2 , 17 ).boxed ().collect (Collectors .toList ()));
9690 private final FilteredList <Integer > selectableSpawnCounts = new FilteredList <>(validSpawnCount );
9791 public Spinner <Integer > numTeamsSpinner ;
9892
9993 @ Override
10094 protected void onInitialize () {
101- JavaFxUtil .bindManagedToVisible (commandLineLabel , commandLineArgsText , mapStyleComboBox , mapStyleLabel , biomeComboBox , biomeLabel );
95+ JavaFxUtil .bindManagedToVisible (commandLineLabel , commandLineArgsText );
10296 initCommandlineArgs ();
10397 initGenerationTypeComboBox ();
10498 initSymmetryComboBox ();
10599 initMapStyleComboBox ();
106- initCheckBoxes ();
100+ initCustomStyleOptions ();
107101 initNumTeamsSpinner ();
108102 initSpawnCountSpinner ();
109103 initMapSizeSpinner ();
110104 initSeedField ();
111- initGeneratorComboBox (terrainComboBox );
112- initGeneratorComboBox (biomeComboBox );
113- initGeneratorComboBox (resourcesComboBox );
114- initGeneratorComboBox (propsComboBox );
105+ bindCustomStyleDisabledProperty (terrainComboBox , biomeComboBox , resourcesComboBox , propsComboBox ,
106+ resourcesDensitySlider , reclaimDensitySlider );
115107 }
116108
117109 private StringConverter <GenerationType > getGenerationTypeConverter () {
@@ -164,8 +156,9 @@ private void initGenerationTypeComboBox() {
164156 generationTypeComboBox .setValue (generationType );
165157 generatorPrefs .generationTypeProperty ().bind (generationTypeComboBox .valueProperty ());
166158 generationTypeComboBox .disableProperty ()
167- .bind (previousMapName .textProperty ().isNotEmpty ()
168- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
159+ .bind (previousMapName .textProperty ()
160+ .isNotEmpty ()
161+ .or (commandLineArgsText .textProperty ().isNotEmpty ()));
169162 }
170163
171164 private void initNumTeamsSpinner () {
@@ -192,8 +185,8 @@ private void initNumTeamsSpinner() {
192185 });
193186 generatorPrefs .numTeamsProperty ().bind (numTeamsSpinner .valueProperty ());
194187 numTeamsSpinner .disableProperty ()
195- .bind (previousMapName . textProperty (). isNotEmpty ()
196- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
188+ .bind (
189+ previousMapName . textProperty (). isNotEmpty () .or (commandLineArgsText .textProperty ().isNotEmpty ()));
197190 int lastIndex = selectableTeamSizes .indexOf (numTeamsProperty );
198191 numTeamsSpinner .increment (lastIndex >= 0 ? lastIndex : 1 );
199192 }
@@ -207,8 +200,9 @@ private void initSpawnCountSpinner() {
207200 spawnCountSpinner .setValueFactory (new ListSpinnerValueFactory <>(selectableSpawnCounts ));
208201 generatorPrefs .spawnCountProperty ().bind (spawnCountSpinner .valueProperty ());
209202 spawnCountSpinner .disableProperty ()
210- .bind (previousMapName .textProperty ().isNotEmpty ()
211- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
203+ .bind (previousMapName .textProperty ()
204+ .isNotEmpty ()
205+ .or (commandLineArgsText .textProperty ().isNotEmpty ()));
212206 int lastIndex = selectableSpawnCounts .indexOf (spawnCountProperty );
213207 spawnCountSpinner .increment (Math .max (lastIndex , 0 ));
214208 }
@@ -219,61 +213,85 @@ private void initMapSizeSpinner() {
219213 mapSizeSpinner .getValueFactory ().setConverter (getMapSizeConverter ());
220214 generatorPrefs .mapSizeInKmProperty ().bind (mapSizeSpinner .getValueFactory ().valueProperty ());
221215 mapSizeSpinner .disableProperty ()
222- .bind (previousMapName . textProperty (). isNotEmpty ()
223- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
216+ .bind (
217+ previousMapName . textProperty (). isNotEmpty () .or (commandLineArgsText .textProperty ().isNotEmpty ()));
224218 }
225219
226220 private void initSymmetryComboBox () {
227221 symmetryComboBox .disableProperty ()
228- .bind (previousMapName .textProperty ().isNotEmpty ()
229- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
230- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
222+ .bind (previousMapName .textProperty ()
223+ .isNotEmpty ()
224+ .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
225+ .or (commandLineArgsText .textProperty ().isNotEmpty ()));
231226 }
232227
233228 private void initMapStyleComboBox () {
234229 mapStyleComboBox .disableProperty ()
235- .bind (previousMapName .textProperty ().isNotEmpty ()
236- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
237- .or (commandLineArgsText .textProperty ().isNotEmpty ())
238- .or (customStyleCheckBox .selectedProperty ()));
230+ .bind (previousMapName .textProperty ()
231+ .isNotEmpty ()
232+ .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
233+ .or (commandLineArgsText .textProperty ().isNotEmpty ())
234+ .or (customStyleCheckBox .selectedProperty ()));
239235 }
240236
241- private void initCheckBoxes () {
237+ private void initCustomStyleOptions () {
242238 customStyleCheckBox .setSelected (generatorPrefs .getCustomStyle ());
243239 generatorPrefs .customStyleProperty ().bind (customStyleCheckBox .selectedProperty ());
244240 customStyleCheckBox .disableProperty ()
245- .bind (previousMapName .textProperty ().isNotEmpty ()
246- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
247- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
241+ .bind (previousMapName .textProperty ()
242+ .isNotEmpty ()
243+ .or (generationTypeComboBox .valueProperty ()
244+ .isNotEqualTo (GenerationType .CASUAL ))
245+ .or (commandLineArgsText .textProperty ().isNotEmpty ()));
248246 fixedSeedCheckBox .setSelected (generatorPrefs .getFixedSeed ());
249247 generatorPrefs .fixedSeedProperty ().bind (fixedSeedCheckBox .selectedProperty ());
250248 fixedSeedCheckBox .disableProperty ()
251- .bind (previousMapName .textProperty ().isNotEmpty ()
252- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
253- .or (commandLineArgsText .textProperty ().isNotEmpty ()));
249+ .bind (previousMapName .textProperty ()
250+ .isNotEmpty ()
251+ .or (generationTypeComboBox .valueProperty ()
252+ .isNotEqualTo (GenerationType .CASUAL ))
253+ .or (commandLineArgsText .textProperty ().isNotEmpty ()));
254+
255+ reclaimDensitySlider .setLabelFormatter (
256+ new LessMoreStringConverter (reclaimDensitySlider .getMin (), reclaimDensitySlider .getMax ()));
257+ resourcesDensitySlider .setLabelFormatter (
258+ new LessMoreStringConverter (resourcesDensitySlider .getMin (), resourcesDensitySlider .getMax ()));
259+ reclaimDensitySlider .setHighValue (generatorPrefs .getReclaimDensityMax ());
260+ generatorPrefs .reclaimDensityMaxProperty ().bind (reclaimDensitySlider .highValueProperty ());
261+ reclaimDensitySlider .setLowValue (generatorPrefs .getReclaimDensityMin ());
262+ generatorPrefs .reclaimDensityMinProperty ().bind (reclaimDensitySlider .lowValueProperty ());
263+ resourcesDensitySlider .setHighValue (generatorPrefs .getResourceDensityMax ());
264+ generatorPrefs .resourceDensityMaxProperty ().bind (resourcesDensitySlider .highValueProperty ());
265+ resourcesDensitySlider .setLowValue (generatorPrefs .getResourceDensityMin ());
266+ generatorPrefs .resourceDensityMinProperty ().bind (resourcesDensitySlider .lowValueProperty ());
254267 }
255268
256269 private void initSeedField () {
257270 seedTextField .setText (String .valueOf (generatorPrefs .getSeed ()));
258271 generatorPrefs .seedProperty ().bind (seedTextField .textProperty ());
259272 seedTextField .disableProperty ()
260- .bind (previousMapName .textProperty ().isNotEmpty ()
261- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
262- .or (commandLineArgsText .textProperty ().isNotEmpty ())
263- .or (fixedSeedCheckBox .selectedProperty ().not ()));
273+ .bind (previousMapName .textProperty ()
274+ .isNotEmpty ()
275+ .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
276+ .or (commandLineArgsText .textProperty ().isNotEmpty ())
277+ .or (fixedSeedCheckBox .selectedProperty ().not ()));
264278 seedRerollButton .disableProperty ()
265- .bind (previousMapName .textProperty ().isNotEmpty ()
266- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
267- .or (commandLineArgsText .textProperty ().isNotEmpty ())
268- .or (fixedSeedCheckBox .selectedProperty ().not ()));
279+ .bind (previousMapName .textProperty ()
280+ .isNotEmpty ()
281+ .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
282+ .or (commandLineArgsText .textProperty ().isNotEmpty ())
283+ .or (fixedSeedCheckBox .selectedProperty ().not ()));
269284 }
270285
271- private void initGeneratorComboBox (ComboBox <String > comboBox ) {
272- comboBox .disableProperty ()
273- .bind (previousMapName .textProperty ().isNotEmpty ()
274- .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
275- .or (commandLineArgsText .textProperty ().isNotEmpty ())
276- .or (customStyleCheckBox .selectedProperty ().not ()));
286+ private void bindCustomStyleDisabledProperty (Node ... nodes ) {
287+ for (Node node : nodes ) {
288+ node .disableProperty ()
289+ .bind (previousMapName .textProperty ()
290+ .isNotEmpty ()
291+ .or (generationTypeComboBox .valueProperty ().isNotEqualTo (GenerationType .CASUAL ))
292+ .or (commandLineArgsText .textProperty ().isNotEmpty ())
293+ .or (customStyleCheckBox .selectedProperty ().not ()));
294+ }
277295 }
278296
279297 private GeneratorOptions getGeneratorOptions () {
@@ -296,6 +314,21 @@ private GeneratorOptions getGeneratorOptions() {
296314 optionsBuilder .textureStyle (biomeComboBox .getValue ());
297315 optionsBuilder .resourceStyle (resourcesComboBox .getValue ());
298316 optionsBuilder .propStyle (propsComboBox .getValue ());
317+ Random random = new Random ();
318+ int reclaimLowValue = (int ) reclaimDensitySlider .getLowValue ();
319+ int reclaimHighValue = (int ) reclaimDensitySlider .getHighValue ();
320+ if (reclaimLowValue == reclaimHighValue ) {
321+ optionsBuilder .reclaimDensity (reclaimLowValue / 127f );
322+ } else {
323+ optionsBuilder .reclaimDensity (random .nextInt (reclaimLowValue , reclaimHighValue ) / 127f );
324+ }
325+ int resourcesLowValue = (int ) resourcesDensitySlider .getLowValue ();
326+ int resourcesHighValue = (int ) resourcesDensitySlider .getHighValue ();
327+ if (resourcesLowValue == resourcesHighValue ) {
328+ optionsBuilder .resourceDensity (resourcesLowValue / 127f );
329+ } else {
330+ optionsBuilder .resourceDensity (random .nextInt (resourcesLowValue , resourcesHighValue ) / 127f );
331+ }
299332 } else {
300333 optionsBuilder .style (mapStyleComboBox .getValue ());
301334 }
@@ -458,4 +491,20 @@ void setOnCloseButtonClickedListener(Runnable onCloseButtonClickedListener) {
458491 public void onSeedRerollButtonClicked () {
459492 seedTextField .setText (String .valueOf (new Random ().nextLong ()));
460493 }
494+
495+ private class LessMoreStringConverter extends ToStringOnlyConverter <Number > {
496+ public LessMoreStringConverter (Number min , Number max ) {
497+ super (number -> {
498+ if (number .equals (max )) {
499+ return i18n .get ("more" );
500+ }
501+
502+ if (number .equals (min )) {
503+ return i18n .get ("less" );
504+ }
505+
506+ return "" ;
507+ });
508+ }
509+ }
461510}
0 commit comments