2323 */
2424package io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .component ;
2525
26+ import io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .component .UIVerticalTableLayout .GridLocation ;
2627import io .github .opencubicchunks .cubicchunks .cubicgen .preset .wrapper .BlockStateDesc ;
27- import net .malisis .core .client .gui .Anchor ;
2828import net .malisis .core .client .gui .component .UIComponent ;
2929import net .malisis .core .client .gui .component .container .UIContainer ;
30- import net .malisis .core .client .gui .component .decoration .UILabel ;
3130import net .malisis .core .client .gui .component .decoration .UISeparator ;
32- import net .malisis .core .client .gui .component .interaction .UIButton ;
33- import net .malisis .core .renderer .font .FontOptions ;
3431import net .minecraft .init .Blocks ;
3532
33+ import static io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .CwgGuiFactory .makeButton ;
34+ import static io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .CwgGuiFactory .makeLabel ;
3635import static io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .CwgGuiFactory .wrap ;
37- import static io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .MalisisGuiUtils .malisisText ;
38-
39- import com .google .common .eventbus .Subscribe ;
4036
4137import io .github .opencubicchunks .cubicchunks .cubicgen .preset .FlatLayer ;
4238import io .github .opencubicchunks .cubicchunks .cubicgen .common .gui .FlatCubicGui ;
@@ -47,85 +43,94 @@ public class UIFlatTerrainLayer extends UIContainer<UIFlatTerrainLayer> {
4743
4844 private static final int BTN_WIDTH = 90 ;
4945 private final FlatLayersTab flatLayersTab ;
50- private final UIButton addLayer ;
51- private final UIButton removeLayer ;
46+ private final CwgGuiButton addLayer ;
47+ private final CwgGuiButton removeLayer ;
5248 private final CwgGuiBlockStateButton block ;
53- private final UILabel blockName ;
54- private final UILabel blockProperties ;
55- private final UILabel from ;
56- private final UILabel to ;
49+ private final CwgGuiLabel blockName ;
50+ private final CwgGuiLabel blockProperties ;
51+ private final CwgGuiLabel from ;
52+ private final CwgGuiLabel to ;
5753 private final UISeparator separator ;
5854 private final UIIntegerInputField fromField ;
5955 private final UIIntegerInputField toField ;
60- private final FontOptions whiteFontWithShadow = FontOptions .builder ().color (0xFFFFFF ).shadow ().build ();
6156
6257 private final FlatCubicGui gui ;
6358
6459 public UIFlatTerrainLayer (FlatCubicGui guiFor , FlatLayersTab flatLayersTabFor , FlatLayer layer ) {
6560 super (guiFor );
66- this .setSize (UIComponent .INHERITED , 60 );
6761 this .flatLayersTab = flatLayersTabFor ;
6862 this .gui = guiFor ;
6963
7064 this .block = new CwgGuiBlockStateButton (layer .blockState );
71- this .blockName = new UILabel (gui ).setPosition (30 , 0 ).setFontOptions (whiteFontWithShadow );
72- this .blockProperties = new UILabel (gui ).setPosition (30 , 10 ).setFontOptions (whiteFontWithShadow );
7365 this .block .onClick (btn -> UIBlockStateSelect .makeOverlay (gui , state -> {
7466 block .setBlockState (new BlockStateDesc (state ));
7567 updateLabels ();
7668 }).display ());
77- add (wrap (gui , block ));
69+
70+ this .blockName = makeLabel ("" );
71+ this .blockProperties = makeLabel ("" );
72+
7873 updateLabels ();
79- add (blockName );
80- add (blockProperties );
81-
82- addLayer = new UIButton (gui , malisisText ("add_layer" )).setSize (BTN_WIDTH , 20 ).setPosition (0 , 0 )
83- .setAnchor (Anchor .RIGHT ).register (new Object () {
84-
85- @ Subscribe
86- public void onClick (UIButton .ClickEvent evt ) {
87- UIFlatTerrainLayer .this .addLayer ();
88- }
89- });
90- add (addLayer );
91-
92- removeLayer = new UIButton (gui , malisisText ("remove_layer" )).setSize (BTN_WIDTH , 20 ).setPosition (0 , 20 )
93- .setAnchor (Anchor .RIGHT ).register (new Object () {
94-
95- @ Subscribe
96- public void onClick (UIButton .ClickEvent evt ) {
97- UIFlatTerrainLayer .this .removeLayer ();
98- }
99- });
100- add (removeLayer );
101-
102- toField = (UIIntegerInputField ) new UIIntegerInputField (gui , layer .toY ).setPosition (0 , 45 , Anchor .RIGHT )
103- .setSize (80 , 5 );
104- add (toField );
105-
106- to = new UILabel (gui , malisisText ("to_exclusively" ), false )
107- .setPosition (-10 - toField .getWidth (), 47 , Anchor .RIGHT ).setFontOptions (whiteFontWithShadow );
108- add (to );
109-
110- from = new UILabel (gui , malisisText ("from" ), false ).setPosition (0 , 47 ).setFontOptions (whiteFontWithShadow );
111- add (from );
112-
113- fromField = (UIIntegerInputField ) new UIIntegerInputField (gui , layer .fromY )
114- .setPosition (from .getWidth () + 10 , 45 ).setSize (80 , 5 );
115- add (fromField );
116-
117- separator = new UISeparator (gui , false ).setColor (0x767676 ).setPosition (0 , to .getY () + to .getHeight () + 3 )
118- .setSize (UIComponent .INHERITED , 1 );
119- super .add (separator );
120- }
12174
122- private void updateLabels () {
123- blockName .setText (block .getBlockName ());
124- blockProperties .setText (block .getBlockProperties ());
75+ addLayer = makeButton ("add_layer" );
76+ addLayer .onClick (btn -> addLayer ());
77+
78+ removeLayer = makeButton ("remove_layer" );
79+ removeLayer .y = 20 ;
80+ removeLayer .onClick (btn -> removeLayer ());
81+
82+ from = makeLabel ("from" );
83+ to = makeLabel ("to_exclusively" );
84+
85+ fromField = new UIIntegerInputField (gui , layer .fromY );
86+ toField = new UIIntegerInputField (gui , layer .toY );
87+
88+ separator = new UISeparator (gui , false ).setColor (0x767676 );
89+
90+ /*
91+ The layout:
92+
93+ left/right split, size to fit second
94+ v
95+ +-----------------------------------------+
96+ | BLOCKSTATE | ADD LAYER^ |
97+ | | REMOVE LAYER |
98+ +--------------------+--------------------+ < vertical table layout, 2 columns, top one takes 2 columns
99+ | From [ ] | To [ ] |
100+ +--------------------+--------------------+
101+ */
102+
103+ UIContainer <?> blockstateContainer = new UIContainer <>(gui );
104+ blockstateContainer .add (wrap (gui , block ));
105+ blockstateContainer .add (wrap (gui , blockName ).setPosition (CwgGuiBlockStateButton .PADDED_SIZE , 0 ));
106+ blockstateContainer .add (wrap (gui , blockProperties ).setPosition (CwgGuiBlockStateButton .PADDED_SIZE , 10 ));
107+ blockstateContainer .setSize (0 , CwgGuiBlockStateButton .PADDED_SIZE ); // width set by layout
108+
109+ UIVerticalTableLayout <?> buttonsContainer = new UIVerticalTableLayout <>(gui , 1 ).autoFitToContent (true );
110+ buttonsContainer .add (wrap (gui , addLayer ), new GridLocation (0 , 0 , 1 ));
111+ buttonsContainer .add (wrap (gui , removeLayer ), new GridLocation (0 , 1 , 1 ));
112+
113+ UILayout <?> blockstateButtonsSplit = new UISplitLayout <>(gui , UISplitLayout .Type .SIDE_BY_SIDE , blockstateContainer , buttonsContainer )
114+ .userResizable (false ).setSizeOf (UISplitLayout .Pos .SECOND , BTN_WIDTH ).autoFitToContent (true );
115+
116+ UISplitLayout <?> fromLayout = new UISplitLayout <>(gui , UISplitLayout .Type .SIDE_BY_SIDE ,
117+ wrap (gui , from ), fromField ).setSizeOf (UISplitLayout .Pos .FIRST , 50 ).autoFitToContent (true );
118+ UISplitLayout <?> toLayout = new UISplitLayout <>(gui , UISplitLayout .Type .SIDE_BY_SIDE ,
119+ wrap (gui , to ), toField ).setSizeOf (UISplitLayout .Pos .FIRST , 90 ).autoFitToContent (true );
120+
121+ UIVerticalTableLayout <?> main = new UIVerticalTableLayout <>(gui , 2 );
122+ main .add (blockstateButtonsSplit , new GridLocation (0 , 0 , 2 ));
123+ main .add (fromLayout , new GridLocation (0 , 1 , 1 ));
124+ main .add (toLayout , new GridLocation (1 , 1 , 1 ));
125+ main .add (separator , new GridLocation (0 , 2 , 2 ));
126+
127+ add (main );
128+ this .setSize (UIComponent .INHERITED , 70 );
125129 }
126130
127- protected void saveConfig () {
128- this .gui .saveConfig ();
131+ private void updateLabels () {
132+ blockName .displayString = block .getBlockName ();
133+ blockProperties .displayString = block .getBlockProperties ();
129134 }
130135
131136 protected void removeLayer () {
0 commit comments