Skip to content

Commit 93eb246

Browse files
committed
Add CwgGuiLabel - vanilla GUI version of label component, and begin porting UIFlatTerrainLayer to vanilla components
1 parent f61339e commit 93eb246

File tree

5 files changed

+145
-66
lines changed

5 files changed

+145
-66
lines changed

src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/CwgGuiFactory.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod;
2828
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiButton;
2929
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiCheckBox;
30+
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiLabel;
3031
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiSlider;
3132
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.WrappedVanillaButton;
3233
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.converter.Converters;
@@ -50,6 +51,25 @@ public static <T extends GuiButton> WrappedVanillaButton<T> wrap(MalisisGui gui,
5051
return new WrappedVanillaButton<>(gui, vanillaComponent);
5152
}
5253

54+
public static CwgGuiLabel makeLabel(String formatString) {
55+
return makeLabel(formatString, 0xFFFFFFFF, 0, 0);
56+
}
57+
58+
public static CwgGuiLabel makeLabel(String formatString, int color) {
59+
return makeLabel(str(formatString), color, 0, 0);
60+
}
61+
62+
public static CwgGuiLabel makeLabel(String formatString, int x, int y) {
63+
return makeLabel(formatString, 0xFFFFFFFF, x, y);
64+
}
65+
66+
public static CwgGuiLabel makeLabel(String formatString, int color, int x, int y) {
67+
CwgGuiLabel label = new CwgGuiLabel(str(formatString), color);
68+
label.x = x;
69+
label.y = y;
70+
return label;
71+
}
72+
5373
public static CwgGuiButton makeButton(String formatString) {
5474
return new CwgGuiButton(str(formatString), null);
5575
}

src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/component/CwgGuiBlockStateButton.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
public class CwgGuiBlockStateButton extends GuiButton {
5353

5454
public static final int SIZE = 24;
55+
public static final int PADDED_SIZE = SIZE + 6;
5556
private String tooltip;
5657
private BlockStateDesc blockState;
5758
private Consumer<CwgGuiBlockStateButton> onClick;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of Cubic World Generation, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) 2015-2020 contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component;
25+
26+
import net.minecraft.client.Minecraft;
27+
import net.minecraft.client.gui.GuiButton;
28+
import net.minecraft.client.resources.I18n;
29+
30+
public class CwgGuiLabel extends GuiButton {
31+
32+
private int color;
33+
34+
public CwgGuiLabel(String formatString, int color) {
35+
super(0, 0, 0, I18n.format(formatString));
36+
this.color = color;
37+
this.height = Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT;
38+
}
39+
40+
public int getColor() {
41+
return color;
42+
}
43+
44+
public void setColor(int color) {
45+
this.color = color;
46+
}
47+
48+
@Override public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
49+
if (this.visible) {
50+
drawString(mc.fontRenderer, displayString, x + 2, y + 2, color);
51+
}
52+
}
53+
}

src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/component/UIFlatTerrainLayer.java

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@
2323
*/
2424
package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component;
2525

26+
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIVerticalTableLayout.GridLocation;
2627
import io.github.opencubicchunks.cubicchunks.cubicgen.preset.wrapper.BlockStateDesc;
27-
import net.malisis.core.client.gui.Anchor;
2828
import net.malisis.core.client.gui.component.UIComponent;
2929
import net.malisis.core.client.gui.component.container.UIContainer;
30-
import net.malisis.core.client.gui.component.decoration.UILabel;
3130
import 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;
3431
import 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;
3635
import 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

4137
import io.github.opencubicchunks.cubicchunks.cubicgen.preset.FlatLayer;
4238
import 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() {

src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CaveSettingsTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private void setupReplacedArea(ExtraGui gui, JsonObjectView conf) {
304304
private void setupSharedArea(ExtraGui gui, UIVerticalTableLayout<?> mainArea, UIVerticalTableLayout<?> replacedArea) {
305305
UISplitLayout<?> split = new UISplitLayout<>(gui, UISplitLayout.Type.SIDE_BY_SIDE, mainArea, replacedArea)
306306
.autoFitToContent(true)
307-
.setSizeOf(UISplitLayout.Pos.SECOND, CwgGuiBlockStateButton.SIZE)
307+
.setSizeOf(UISplitLayout.Pos.SECOND, CwgGuiBlockStateButton.PADDED_SIZE)
308308
.userResizable(false)
309309
.setRightPadding(4)
310310
.setBottomPadding(10);

0 commit comments

Comments
 (0)