11package com .bobsgame .client .engine .game .gui .customGameEditor ;
22
33import com .badlogic .gdx .scenes .scene2d .InputEvent ;
4+ import com .badlogic .gdx .scenes .scene2d .ui .CheckBox ;
45import com .badlogic .gdx .scenes .scene2d .ui .Label ;
56import com .badlogic .gdx .scenes .scene2d .ui .Skin ;
67import com .badlogic .gdx .scenes .scene2d .ui .Table ;
@@ -33,6 +34,12 @@ public class CustomGameEditor extends Scene2DPanel {
3334 private final Label hintLabel ;
3435 private final Label rotationOverviewLabel ;
3536 private final Table rotationOverviewTable ;
37+ private final CheckBox cascadeGravityCheckbox ;
38+ private final CheckBox disconnectedGravityCheckbox ;
39+ private final CheckBox chainRowCheckbox ;
40+ private final CheckBox chainColumnCheckbox ;
41+ private final CheckBox chainDiagonalCheckbox ;
42+ private final CheckBox recursiveChainCheckbox ;
3643
3744 private final GameType currentGameType = new GameType ();
3845 private int selectedPieceIndex = -1 ;
@@ -55,6 +62,12 @@ public CustomGameEditor(Engine engine) {
5562 hintLabel = new Label ("Build piece shapes with the 4x4 grid. Add pieces and rotations to sketch rules live." , skin );
5663 rotationOverviewLabel = new Label ("Rotation Overview" , skin );
5764 rotationOverviewTable = new Table ();
65+ cascadeGravityCheckbox = new CheckBox (" Cascade gravity" , skin );
66+ disconnectedGravityCheckbox = new CheckBox (" Disconnected-only gravity" , skin );
67+ chainRowCheckbox = new CheckBox (" Chain rows" , skin );
68+ chainColumnCheckbox = new CheckBox (" Chain columns" , skin );
69+ chainDiagonalCheckbox = new CheckBox (" Chain diagonals" , skin );
70+ recursiveChainCheckbox = new CheckBox (" Recursive chain search" , skin );
5871 hintLabel .setWrap (true );
5972 summaryLabel .setWrap (true );
6073
@@ -87,6 +100,15 @@ public CustomGameEditor(Engine engine) {
87100 controlsRow2 .add (prevRotationBtn );
88101 controlsRow2 .add (nextRotationBtn );
89102
103+ Table advancedRulesTable = new Table ();
104+ advancedRulesTable .defaults ().left ().pad (4 );
105+ advancedRulesTable .add (cascadeGravityCheckbox ).left ();
106+ advancedRulesTable .add (disconnectedGravityCheckbox ).left ().row ();
107+ advancedRulesTable .add (chainRowCheckbox ).left ();
108+ advancedRulesTable .add (chainColumnCheckbox ).left ().row ();
109+ advancedRulesTable .add (chainDiagonalCheckbox ).left ();
110+ advancedRulesTable .add (recursiveChainCheckbox ).left ().row ();
111+
90112 Table gridTable = new Table ();
91113 gridTable .defaults ().width (44 ).height (44 ).pad (2 );
92114 for (int y = 0 ; y < 4 ; y ++) {
@@ -183,11 +205,26 @@ public void clicked(InputEvent event, float x, float y) {
183205 }
184206 });
185207
208+ ClickListener toggleRefreshListener = new ClickListener () {
209+ @ Override
210+ public void clicked (InputEvent event , float x , float y ) {
211+ applyRuleCheckboxes ();
212+ refreshEditorState ();
213+ }
214+ };
215+ cascadeGravityCheckbox .addListener (toggleRefreshListener );
216+ disconnectedGravityCheckbox .addListener (toggleRefreshListener );
217+ chainRowCheckbox .addListener (toggleRefreshListener );
218+ chainColumnCheckbox .addListener (toggleRefreshListener );
219+ chainDiagonalCheckbox .addListener (toggleRefreshListener );
220+ recursiveChainCheckbox .addListener (toggleRefreshListener );
221+
186222 mainTable .defaults ().left ().padBottom (8 );
187223 mainTable .add (titleLabel ).left ().row ();
188224 mainTable .add (hintLabel ).width (520 ).left ().row ();
189225 mainTable .add (controlsRow1 ).left ().row ();
190226 mainTable .add (controlsRow2 ).left ().row ();
227+ mainTable .add (advancedRulesTable ).left ().row ();
191228 mainTable .add (pieceLabel ).left ().row ();
192229 mainTable .add (rotationLabel ).left ().row ();
193230 mainTable .add (gridTable ).left ().padTop (8 ).row ();
@@ -417,6 +454,26 @@ private int getFilledCellCount(Piece.Rotation rotation) {
417454 return rotation == null ? 0 : rotation .blockOffsets .size ();
418455 }
419456
457+ private void applyRuleCheckboxes () {
458+ currentGameType .moveDownAllLinesOverBlankSpacesAtOnce = cascadeGravityCheckbox .isChecked ();
459+ currentGameType .gravityRule_onlyMoveDownDisconnectedBlocks = disconnectedGravityCheckbox .isChecked ();
460+ currentGameType .chainRule_CheckRow = chainRowCheckbox .isChecked ();
461+ currentGameType .chainRule_CheckColumn = chainColumnCheckbox .isChecked ();
462+ currentGameType .chainRule_CheckDiagonal = chainDiagonalCheckbox .isChecked ();
463+ currentGameType .chainRule_CheckRecursiveConnections = recursiveChainCheckbox .isChecked ();
464+ }
465+
466+ private String getEnabledRuleSummary () {
467+ java .util .ArrayList <String > enabled = new java .util .ArrayList <String >();
468+ if (currentGameType .moveDownAllLinesOverBlankSpacesAtOnce ) enabled .add ("cascade gravity" );
469+ if (currentGameType .gravityRule_onlyMoveDownDisconnectedBlocks ) enabled .add ("disconnected gravity" );
470+ if (currentGameType .chainRule_CheckRow ) enabled .add ("row chains" );
471+ if (currentGameType .chainRule_CheckColumn ) enabled .add ("column chains" );
472+ if (currentGameType .chainRule_CheckDiagonal ) enabled .add ("diagonal chains" );
473+ if (currentGameType .chainRule_CheckRecursiveConnections ) enabled .add ("recursive search" );
474+ return enabled .isEmpty () ? "none" : String .join (", " , enabled );
475+ }
476+
420477 private int getTotalRotationCount () {
421478 int total = 0 ;
422479 for (PieceType pieceType : currentGameType .pieceTypes ) {
@@ -426,9 +483,17 @@ private int getTotalRotationCount() {
426483 }
427484
428485 private void refreshEditorState () {
486+ applyRuleCheckboxes ();
429487 PieceType pieceType = getSelectedPiece ();
430488 Piece .Rotation rotation = getSelectedRotation ();
431489
490+ cascadeGravityCheckbox .setChecked (currentGameType .moveDownAllLinesOverBlankSpacesAtOnce );
491+ disconnectedGravityCheckbox .setChecked (currentGameType .gravityRule_onlyMoveDownDisconnectedBlocks );
492+ chainRowCheckbox .setChecked (currentGameType .chainRule_CheckRow );
493+ chainColumnCheckbox .setChecked (currentGameType .chainRule_CheckColumn );
494+ chainDiagonalCheckbox .setChecked (currentGameType .chainRule_CheckDiagonal );
495+ recursiveChainCheckbox .setChecked (currentGameType .chainRule_CheckRecursiveConnections );
496+
432497 pieceLabel .setText (pieceType == null ? "Piece: none" : "Piece: " + pieceType .name + " (" + (selectedPieceIndex + 1 ) + "/" + currentGameType .pieceTypes .size () + ")" );
433498 rotationLabel .setText (rotation == null ? "Rotation: none" : "Rotation: " + selectedRotationIndex + " (" + getFilledCellCount (rotation ) + " blocks)" );
434499 rebuildRotationOverview (pieceType );
@@ -457,6 +522,7 @@ private void refreshEditorState() {
457522 + " | Rotations: " + getTotalRotationCount ()
458523 + " | Current piece rotations: " + currentRotationCount
459524 + " | Filled cells in current rotation: " + getFilledCellCount (rotation )
525+ + " | Rules: " + getEnabledRuleSummary ()
460526 );
461527 }
462528}
0 commit comments