Skip to content

Commit e924c74

Browse files
committed
Begin migration away from MalisisCore
1 parent 868e595 commit e924c74

File tree

17 files changed

+393
-102
lines changed

17 files changed

+393
-102
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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;
25+
26+
import com.google.common.base.Converter;
27+
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.CwgGuiSlider;
28+
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.converter.Converters;
29+
30+
import java.util.function.BiPredicate;
31+
import java.util.function.DoubleSupplier;
32+
import java.util.function.Function;
33+
34+
import javax.annotation.Nonnull;
35+
36+
public class GuiFactory {
37+
38+
private GuiFactory() {
39+
throw new Error();
40+
}
41+
42+
public static CwgGuiSlider makeSlider(double min, double max, double defVal, String formatString, Function<Double, String> toString) {
43+
44+
CwgGuiSlider[] wrappedSlider = new CwgGuiSlider[1];
45+
BiPredicate<Double, Double> isInRoundRadius = getIsInRoundRadiusPredicate(wrappedSlider);
46+
47+
double defMult = defVal == 0 ? 1 : defVal;
48+
49+
Converter<Double, Double> conv = Converters.builder()
50+
.linearScale(min, max).rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
51+
.withRoundingRadiusPredicate(isInRoundRadius)
52+
.build();
53+
54+
CwgGuiSlider slider = new CwgGuiSlider(formatString, toString, conv, defVal);
55+
wrappedSlider[0] = slider;
56+
return slider;
57+
}
58+
59+
@Nonnull private static BiPredicate<Double, Double> getIsInRoundRadiusPredicate(CwgGuiSlider[] slider) {
60+
return getIsInRoundRadiusPredicate(() -> slider[0] == null ? 1000 : slider[0].width);
61+
}
62+
63+
@Nonnull private static BiPredicate<Double, Double> getIsInRoundRadiusPredicate(DoubleSupplier width) {
64+
return (previousSlide, foundSlide) -> {
65+
double w = width.getAsDouble();
66+
double rangeCenter = Math.round(previousSlide * w) / w;
67+
double minRange = rangeCenter - 0.5 / w;
68+
double maxRange = rangeCenter + 0.5 / w;
69+
70+
return foundSlide >= minRange && foundSlide <= maxRange;
71+
};
72+
}
73+
74+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static UISlider<Float> makeFloatSlider(MalisisGui gui, float min, float m
7171
Converter<Float, Float> conv = Converters.builder()
7272
.linearScale(min, max).rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
7373
.withRoundingRadiusPredicate(isInRoundRadius)
74-
.build();
74+
.buildFloat();
7575

7676
UISlider<Float> slider = new UISliderImproved<>(gui, 100, conv, value -> text.apply((double) (float) value)).setValue(defVal);
7777
wrappedSlider[0] = slider;
@@ -94,7 +94,7 @@ public static UISlider<Float> makePositiveExponentialSlider(MalisisGui gui, floa
9494
.rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
9595
.withRoundingRadiusPredicate(isInRoundRadius)
9696
.withInfinity().positiveAt((float)Math.pow(2, maxPos)).negativeAt(Float.NaN)
97-
.build();
97+
.buildFloat();
9898

9999
UISlider<Float> slider = new UISliderImproved<>(gui, 100, conv, value -> text.apply((double) (float) value)).setValue(defaultVal);
100100
wrappedSlider[0] = slider;
@@ -114,7 +114,7 @@ public static UISlider<Float> makePositiveExponentialSlider(MalisisGui gui, Stri
114114
.rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
115115
.withRoundingRadiusPredicate(isInRoundRadius)
116116
.withInfinity().positiveAt((float)Math.pow(2, maxPos)).negativeAt(Float.NaN)
117-
.build();
117+
.buildFloat();
118118

119119
UISlider<Float> slider = new UISliderImproved<>(gui, 100, conv, name).setValue(defaultVal);
120120
wrappedSlider[0] = slider;
@@ -133,7 +133,7 @@ public static UISlider<Float> makeExponentialSlider(MalisisGui gui, String name,
133133
.exponential().withZero().withBaseValue(2).withNegativeExponentRange(minNeg, maxNeg).withPositiveExponentRange(minPos, maxPos)
134134
.rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
135135
.withRoundingRadiusPredicate(isInRoundRadius)
136-
.build();
136+
.buildFloat();
137137

138138
UISlider<Float> slider = new UISliderImproved<>(gui, 100, conv, name).setValue(defaultVal);
139139
wrappedSlider[0] = slider;
@@ -174,7 +174,7 @@ public static UISlider<Float> makeInvertedExponentialSlider(MalisisGui gui, Stri
174174
.inverse()
175175
.rounding().withBase(2, 1).withBase(10, 1).withBase(2, defMult).withBase(10, defMult).withMaxExp(128)
176176
.withRoundingRadiusPredicate(isInRoundRadius)
177-
.build();
177+
.buildFloat();
178178

179179
UISlider<Float> slider = new UISliderImproved<>(gui, 100, conv, name).setValue(defaultVal);
180180
wrappedSlider[0] = slider;
@@ -238,7 +238,7 @@ private static UIRangeSlider<Float> rangeSlider(ExtraGui gui, String name, float
238238
.linearScale(min, max)
239239
.rounding().withBase(2, 1).withBase(10, 1).withMaxExp(maxExp).withRoundingRadiusPredicate(isInRoundRadius)
240240
.withInfinity().negativeAt(min).positiveAt(max)
241-
.build();
241+
.buildFloat();
242242

243243
UIRangeSlider<Float> slider = new UIRangeSlider<>(gui, 100, conv, i18nFormat).setRange(defMin, defMax);
244244
wrappedSlider[0] = slider;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 com.google.common.base.Converter;
27+
import net.minecraft.client.Minecraft;
28+
import net.minecraft.client.gui.GuiButton;
29+
import net.minecraft.client.renderer.GlStateManager;
30+
import net.minecraft.client.resources.I18n;
31+
import net.minecraft.util.math.MathHelper;
32+
33+
import java.util.function.Function;
34+
35+
public class CwgGuiSlider extends GuiButton {
36+
37+
private final String textFormat;
38+
private final Function<Double, String> valueToString;
39+
private final Converter<Double, Double> positionToValue;
40+
41+
private double sliderPosition;
42+
private boolean mousePressed;
43+
44+
public CwgGuiSlider(String textFormat, Function<Double, String> valueToString, Converter<Double, Double> positionToValue, double defaultValue) {
45+
super(0, 0, 0, "");
46+
this.textFormat = textFormat;
47+
this.valueToString = valueToString;
48+
this.positionToValue = positionToValue;
49+
this.sliderPosition = positionToValue.reverse().convert(defaultValue);
50+
}
51+
52+
public double getSliderPosition() {
53+
return sliderPosition;
54+
}
55+
56+
public double getSliderValue() {
57+
return positionToValue.convert(getSliderPosition());
58+
}
59+
60+
@Override protected int getHoverState(boolean mouseOver) {
61+
return 0;
62+
}
63+
64+
// this is actually a draw() method
65+
@Override protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
66+
if (!enabled || !visible) {
67+
return;
68+
}
69+
if (mousePressed) {
70+
double position = (mouseX - (this.x + 4.0)) / (this.width - 8.0);
71+
this.sliderPosition = MathHelper.clamp(position, 0, 1);
72+
}
73+
74+
this.displayString = I18n.format(textFormat, valueToString.apply(getSliderValue()));
75+
76+
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
77+
this.drawTexturedModalRect(this.x + (int)(this.sliderPosition * (this.width - 8)), this.y, 0, 66, 4, 20);
78+
this.drawTexturedModalRect(this.x + (int)(this.sliderPosition * (this.width - 8)) + 4, this.y, 196, 66, 4, 20);
79+
}
80+
81+
@Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
82+
if (!super.mousePressed(mc, mouseX, mouseY)) {
83+
return false;
84+
}
85+
this.mousePressed = true;
86+
87+
double position = (mouseX - (this.x + 4.0)) / (this.width - 8.0);
88+
this.sliderPosition = MathHelper.clamp(position, 0, 1);
89+
90+
return true;
91+
}
92+
93+
@Override public void mouseReleased(int mouseX, int mouseY) {
94+
this.mousePressed = false;
95+
}
96+
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,12 @@
2525

2626
import com.google.common.collect.BiMap;
2727
import com.google.common.collect.HashBiMap;
28-
import com.google.common.collect.ImmutableMap;
29-
import com.google.common.collect.Maps;
3028
import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.ExtraGui;
3129
import net.malisis.core.client.gui.component.UIComponent;
32-
import net.malisis.core.client.gui.component.container.UIContainer;
33-
import net.minecraft.world.biome.Biome;
3430

35-
import java.util.ArrayList;
3631
import java.util.Collection;
37-
import java.util.Collections;
38-
import java.util.HashMap;
3932
import java.util.HashSet;
40-
import java.util.Iterator;
4133
import java.util.List;
42-
import java.util.Map;
4334
import java.util.Set;
4435
import java.util.function.Function;
4536

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public T setSplitType(Type type) {
264264
if (button == MouseButton.LEFT) {
265265
this.isMovingSplit = false;
266266
}
267-
return true;
267+
return false;
268268
}
269269

270270
@Override public void drawForeground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick) {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.malisis.core.client.gui.GuiRenderer;
27+
import net.malisis.core.client.gui.MalisisGui;
28+
import net.malisis.core.client.gui.component.UIComponent;
29+
import net.malisis.core.client.gui.component.container.UIContainer;
30+
import net.malisis.core.util.MouseButton;
31+
import net.minecraft.client.Minecraft;
32+
import net.minecraft.client.gui.GuiButton;
33+
34+
@Deprecated // this is temporary for incremental migration only
35+
public class WrappedVanillaButton<T extends WrappedVanillaButton<T>> extends UIComponent<T> {
36+
37+
private final GuiButton vanillaButton;
38+
39+
public WrappedVanillaButton(MalisisGui gui, GuiButton vanillaButton) {
40+
super(gui);
41+
this.vanillaButton = vanillaButton;
42+
setSize(vanillaButton.getButtonWidth(), vanillaButton.height);
43+
}
44+
45+
public T setEnabled(boolean enabled) {
46+
return super.setEnabled(enabled);
47+
}
48+
49+
public boolean isEnabled() {
50+
return super.isEnabled();
51+
}
52+
53+
@Override public T setPosition(int x, int y, int anchor) {
54+
super.setPosition(x, y, anchor);
55+
vanillaButton.x = getX();
56+
vanillaButton.y = getY();
57+
return self();
58+
}
59+
60+
@Override public T setSize(int width, int height) {
61+
super.setSize(width, height);
62+
vanillaButton.setWidth(getWidth());
63+
vanillaButton.height = getHeight();
64+
return self();
65+
}
66+
67+
@Override public void drawBackground(GuiRenderer guiRenderer, int mouseX, int mouseY, float partialTick) {
68+
vanillaButton.x = (int) (screenX() - ((UIContainer<?>) getParent()).getOffsetX());
69+
vanillaButton.y = (int) (screenY() - ((UIContainer<?>) getParent()).getOffsetY());
70+
vanillaButton.setWidth(getWidth());
71+
vanillaButton.height = getHeight();
72+
73+
guiRenderer.draw();
74+
vanillaButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, partialTick);
75+
// vanilla components can change it from under malisiscore, and malisiscore doesn't actually update if it thinks nothing changed
76+
Minecraft.getMinecraft().getTextureManager().bindTexture(guiRenderer.getDefaultTexture().getResourceLocation());
77+
guiRenderer.bindDefaultTexture();
78+
}
79+
80+
@Override public void drawForeground(GuiRenderer guiRenderer, int mouseX, int mouseY, float partialTick) {
81+
guiRenderer.draw();
82+
vanillaButton.drawButtonForegroundLayer(mouseX, mouseY);
83+
guiRenderer.next();
84+
}
85+
86+
@Override public boolean onButtonPress(int x, int y, MouseButton button) {
87+
if (!super.onButtonPress(x, y, button) && button == MouseButton.LEFT) {
88+
vanillaButton.mousePressed(Minecraft.getMinecraft(), x, y);
89+
return vanillaButton.enabled && vanillaButton.visible;
90+
}
91+
return false;
92+
}
93+
94+
@Override public boolean onButtonRelease(int x, int y, MouseButton button) {
95+
if (!super.onButtonRelease(x, y, button) && button == MouseButton.LEFT) {
96+
vanillaButton.mouseReleased(x, y);
97+
return vanillaButton.enabled && vanillaButton.visible;
98+
}
99+
return false;
100+
}
101+
}

0 commit comments

Comments
 (0)