Skip to content

Commit ef5c64f

Browse files
committed
Remove dead code, prepare for more CWG components
1 parent 2288295 commit ef5c64f

File tree

14 files changed

+240
-267
lines changed

14 files changed

+240
-267
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,18 @@
2424
package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui;
2525

2626
import com.google.common.base.Converter;
27-
import com.google.common.eventbus.Subscribe;
2827
import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod;
2928
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiButton;
3029
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiCheckBox;
3130
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiLabel;
3231
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiSeparator;
3332
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiSlider;
34-
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISplitLayout;
33+
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.ICwgGuiComponent;
3534
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.WrappedVanillaComponent;
3635
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.converter.Converters;
3736
import net.malisis.core.client.gui.MalisisGui;
38-
import net.malisis.core.client.gui.component.UIComponent;
39-
import net.malisis.core.client.gui.component.decoration.UILabel;
40-
import net.malisis.core.client.gui.component.interaction.UITextField;
41-
import net.malisis.core.client.gui.event.ComponentEvent;
42-
import net.malisis.core.renderer.font.FontOptions;
4337
import net.minecraft.client.Minecraft;
38+
import net.minecraft.client.gui.Gui;
4439
import net.minecraft.client.gui.GuiButton;
4540
import net.minecraft.client.gui.GuiLabel;
4641
import net.minecraft.client.gui.GuiTextField;
@@ -70,8 +65,12 @@ public static <T extends GuiTextField> WrappedVanillaComponent<T> wrap(MalisisGu
7065
return WrappedVanillaComponent.of(gui, vanillaComponent);
7166
}
7267

68+
public static <T extends Gui & ICwgGuiComponent> WrappedVanillaComponent<T> wrap(MalisisGui gui, T vanillaComponent) {
69+
return WrappedVanillaComponent.of(gui, vanillaComponent);
70+
}
71+
7372
public static CwgGuiSeparator separator() {
74-
return new CwgGuiSeparator(0, 0);
73+
return new CwgGuiSeparator(0, 0, 0);
7574
}
7675

7776
public static GuiTextField intTextField(int defaultValue) {

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

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

26-
import java.util.ArrayList;
27-
import java.util.List;
2826
import java.util.Map.Entry;
2927
import java.util.function.Consumer;
3028
import java.util.stream.Collectors;
3129

3230
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.DummyWorld;
3331
import io.github.opencubicchunks.cubicchunks.cubicgen.preset.wrapper.BlockStateDesc;
34-
import net.minecraft.client.gui.GuiButton;
3532
import net.minecraft.client.renderer.BufferBuilder;
3633
import net.minecraft.client.renderer.RenderHelper;
3734
import org.lwjgl.opengl.GL11;
@@ -51,29 +48,24 @@
5148
import net.minecraft.tileentity.TileEntity;
5249
import net.minecraft.util.math.BlockPos;
5350

54-
public class CwgGuiBlockStateButton extends GuiButton {
51+
public class CwgGuiBlockStateButton extends CwgGuiComponent {
5552

5653
public static final int SIZE = 24;
5754
public static final int PADDED_SIZE = SIZE + 6;
58-
private final List<String> tooltipLines = new ArrayList<>();
5955
private BlockStateDesc blockState;
6056
private Consumer<CwgGuiBlockStateButton> onClick;
6157

6258
public CwgGuiBlockStateButton(BlockStateDesc blockState) {
63-
super(0, 0, 0, SIZE, SIZE, "");
59+
super(SIZE, SIZE);
6460
this.blockState = blockState;
6561
updateTooltip();
6662
}
6763

68-
public void onClick(Consumer<CwgGuiBlockStateButton> action) {
69-
this.onClick = action;
70-
}
71-
7264
private void updateTooltip() {
73-
this.tooltipLines.clear();
74-
this.tooltipLines.add(blockState.getBlockId());
65+
clearTooltip();
66+
addTooltipLine(blockState.getBlockId());
7567
for (Entry<String, String> entry : blockState.getProperties().entrySet()) {
76-
this.tooltipLines.add(entry.getKey() + " = " + entry.getValue());
68+
addTooltipLine(entry.getKey() + " = " + entry.getValue());
7769
}
7870
}
7971

@@ -87,18 +79,10 @@ public void setBlockState(BlockStateDesc state) {
8779
}
8880

8981
@Override
90-
public boolean mousePressed(Minecraft mc, int x, int y) {
91-
onClick.accept(this);
92-
return true;
93-
}
94-
95-
@Override
96-
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTick) {
97-
if (!visible || blockState == null || blockState.getBlockState() == null) {
82+
public void drawBackground(Minecraft mc, int mouseX, int mouseY, float partialTick) {
83+
if (!isVisible() || blockState == null || blockState.getBlockState() == null) {
9884
return;
9985
}
100-
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
101-
10286
IBlockState state = blockState.getBlockState();
10387
RenderHelper.disableStandardItemLighting();
10488
GlStateManager.enableDepth();
@@ -109,7 +93,7 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTick)
10993
GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockTexture.getGlTextureId());
11094
VertexFormat format = DefaultVertexFormats.BLOCK;
11195
GlStateManager.pushMatrix();
112-
GlStateManager.translate(this.x, this.y + 16f, 100.0F);
96+
GlStateManager.translate(this.getX(), this.getY() + 16f, 100.0F);
11397
GlStateManager.scale(12.0F, 12.0F, -12.0F);
11498
GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F);
11599
GlStateManager.rotate(45.0F, 0.0F, 1.0F, 0.0F);
@@ -134,11 +118,6 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTick)
134118
GlStateManager.enableLighting();
135119
}
136120

137-
@Override public void drawButtonForegroundLayer(int mouseX, int mouseY) {
138-
if (hovered) {
139-
Minecraft.getMinecraft().currentScreen.drawHoveringText(tooltipLines, mouseX, mouseY);
140-
}
141-
}
142121

143122
public String getBlockName() {
144123
return this.blockState.getBlockId();
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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.Gui;
28+
29+
import java.util.ArrayList;
30+
import java.util.Arrays;
31+
import java.util.List;
32+
import java.util.function.Consumer;
33+
34+
public abstract class CwgGuiComponent extends Gui implements ICwgGuiComponent {
35+
36+
private int x, y, width, height;
37+
private boolean enabled, visible, hovered;
38+
private final List<String> tooltipLines = new ArrayList<>();
39+
private Consumer<? super CwgGuiComponent> onClick;
40+
41+
public CwgGuiComponent(int width, int height) {
42+
this.width = width;
43+
this.height = height;
44+
}
45+
46+
public void setOnClick(Consumer<? super CwgGuiComponent> action) {
47+
this.onClick = action;
48+
}
49+
50+
public void addTooltipLines(String... lines) {
51+
this.tooltipLines.addAll(Arrays.asList(lines));
52+
}
53+
54+
public void addTooltipLine(String line) {
55+
this.tooltipLines.add(line);
56+
}
57+
58+
public void setTooltip(String... lines) {
59+
this.tooltipLines.clear();
60+
this.tooltipLines.addAll(Arrays.asList(lines));
61+
}
62+
63+
public void clearTooltip() {
64+
this.tooltipLines.clear();
65+
}
66+
67+
@Override public int getX() {
68+
return x;
69+
}
70+
71+
@Override public int getY() {
72+
return y;
73+
}
74+
75+
@Override public int getWidth() {
76+
return width;
77+
}
78+
79+
@Override public int getHeight() {
80+
return height;
81+
}
82+
83+
@Override public void setX(int x) {
84+
this.x = x;
85+
}
86+
87+
@Override public void setY(int y) {
88+
this.y = y;
89+
}
90+
91+
@Override public void setWidth(int width) {
92+
this.width = width;
93+
}
94+
95+
@Override public void setHeight(int height) {
96+
this.height = height;
97+
}
98+
99+
@Override public boolean isEnabled() {
100+
return enabled;
101+
}
102+
103+
@Override public boolean isVisible() {
104+
return visible;
105+
}
106+
107+
public boolean isHovered() {
108+
return hovered;
109+
}
110+
111+
@Override public void setEnabled(boolean enabled) {
112+
this.enabled = enabled;
113+
}
114+
115+
@Override public void setVisible(boolean visible) {
116+
this.visible = visible;
117+
}
118+
119+
@Override public void preDraw(Minecraft mc, int mouseX, int mouseY, float partialTick) {
120+
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
121+
}
122+
123+
124+
@Override public void drawForeground(Minecraft mc, int mouseX, int mouseY, float partialTick) {
125+
if (hovered && !tooltipLines.isEmpty()) {
126+
Minecraft.getMinecraft().currentScreen.drawHoveringText(tooltipLines, mouseX, mouseY);
127+
}
128+
}
129+
130+
@Override
131+
public boolean onMousePressed(Minecraft mc, int x, int y) {
132+
if (onClick == null) {
133+
return false;
134+
}
135+
onClick.accept(this);
136+
return true;
137+
}
138+
}

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,19 @@
2424
package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component;
2525

2626
import net.minecraft.client.Minecraft;
27-
import net.minecraft.client.gui.GuiButton;
2827

29-
public class CwgGuiSeparator extends GuiButton {
28+
public class CwgGuiSeparator extends CwgGuiComponent {
3029

31-
public CwgGuiSeparator(int x, int y) {
32-
super(0, x, y, "");
33-
height = 5;
34-
}
30+
private final int colorOverride;
3531

36-
@Override public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
37-
if (visible) {
38-
drawHorizontalLine(x, x + width, y + height / 2, packedFGColour == 0 ? 0xFF767676 : packedFGColour);
39-
}
32+
public CwgGuiSeparator(int x, int y, int colorOverride) {
33+
super(0, 5);
34+
this.colorOverride = colorOverride;
4035
}
4136

42-
@Override public void mouseReleased(int mouseX, int mouseY) {
43-
}
44-
45-
@Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
46-
return false;
37+
@Override public void drawBackground(Minecraft mc, int mouseX, int mouseY, float partialTick) {
38+
if (isVisible()) {
39+
drawHorizontalLine(getX(), getX() + getWidth(), getY() + getHeight() / 2, colorOverride == 0 ? 0xFF767676 : colorOverride);
40+
}
4741
}
4842
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
28+
public interface ICwgGuiComponent {
29+
int getX();
30+
int getY();
31+
int getWidth();
32+
int getHeight();
33+
34+
void setX(int x);
35+
void setY(int y);
36+
void setWidth(int width);
37+
void setHeight(int height);
38+
39+
boolean isEnabled();
40+
boolean isVisible();
41+
void setEnabled(boolean enabled);
42+
void setVisible(boolean visible);
43+
44+
default void preDraw(Minecraft mc, int mouseX, int mouseY, float partialTick) {}
45+
void drawBackground(Minecraft mc, int mouseX, int mouseY, float partialTick);
46+
default void drawForeground(Minecraft mc, int mouseX, int mouseY, float partialTick) {}
47+
48+
default boolean onMousePressed(Minecraft mc, int mouseX, int mouseY) {
49+
return false;
50+
}
51+
52+
default boolean onMouseReleased(Minecraft mc, int mouseX, int mouseY) {
53+
return false;
54+
}
55+
56+
default boolean onKeyTyped(char keyChar, int keyCode) {
57+
return false;
58+
}
59+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public UIFlatTerrainLayer(FlatCubicGui guiFor, FlatLayersTab flatLayersTabFor, F
6666
this.gui = guiFor;
6767

6868
this.block = new CwgGuiBlockStateButton(layer.blockState);
69-
this.block.onClick(btn -> UIBlockStateSelect.makeOverlay(gui, state -> {
69+
this.block.setOnClick(btn -> UIBlockStateSelect.makeOverlay(gui, state -> {
7070
block.setBlockState(new BlockStateDesc(state));
7171
updateLabels();
7272
}).display());

0 commit comments

Comments
 (0)