-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin backport of mod to Minecraft version 1.19.2
- Loading branch information
1 parent
61e0be3
commit 7862623
Showing
14 changed files
with
1,039 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/cstav/genshinstrument/client/gui/widget/BetterSlider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraftforge.client.gui.widget.ForgeSlider; | ||
|
||
public class BetterSlider extends ForgeSlider { | ||
|
||
protected final SliderEvent onSliderChanged; | ||
public BetterSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, | ||
double maxValue, double currentValue, double stepSize, SliderEvent onSliderChanged) { | ||
super(x, y, width, height, prefix, suffix, minValue, maxValue, currentValue, stepSize, 0, true); | ||
|
||
this.onSliderChanged = onSliderChanged; | ||
} | ||
|
||
@Override | ||
protected void applyValue() { | ||
onSliderChanged.run(this, getValue()); | ||
} | ||
|
||
// Forge's very, very clever overflow implementation makes clients | ||
// (primarily Optifine clients) crash | ||
// For some reason the ellipsize method is undefined | ||
// Beats me idk | ||
//NOTE: Seems to note exist in 1.19.2 | ||
// @Override | ||
// public void renderButton(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick) | ||
// { | ||
// RenderSystem.setShader(GameRenderer::getPositionTexShader); | ||
// RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); | ||
|
||
// final Minecraft mc = Minecraft.getInstance(); | ||
// final int bgYImage = this.getYImage(this.isHoveredOrFocused()); | ||
// ScreenUtils.blitWithBorder(poseStack, | ||
// this.x, this.y, | ||
// 0, 46 + bgYImage * 20, | ||
// this.width, this.height, | ||
// 200, 20, | ||
// 2, 3, | ||
// 2, 2 | ||
// , this.getBlitOffset()); | ||
|
||
// final int sliderYImage = (this.isHoveredOrFocused() ? 2 : 1) * 20; | ||
// ScreenUtils.blitWithBorder(poseStack, | ||
// this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), | ||
// 0, 46 + sliderYImage, | ||
// 8, this.height, | ||
// 200, 20, | ||
// 2, 3, 2, 2 | ||
// , this.getBlitOffset()); | ||
|
||
// // final FormattedText message = mc.font.ellipsize(getMessage(), this.width - 6); | ||
// drawCenteredString(poseStack, mc.font, getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor()); | ||
// } | ||
|
||
|
||
@FunctionalInterface | ||
public static interface SliderEvent { | ||
void run(final BetterSlider slider, final double value); | ||
} | ||
} |
198 changes: 198 additions & 0 deletions
198
...main/java/com/cstav/genshinstrument/client/gui/widget/copied/AbstractContainerWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
|
||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.client.gui.components.events.ContainerEventHandler; | ||
import net.minecraft.client.gui.components.events.GuiEventListener; | ||
import net.minecraft.client.gui.narration.NarratableEntry; | ||
import net.minecraft.client.gui.narration.NarrationElementOutput; | ||
import net.minecraft.client.gui.narration.NarrationSupplier; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.Mth; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public abstract class AbstractContainerWidget extends AbstractWidget implements ContainerEventHandler { | ||
@Nullable | ||
private GuiEventListener focused; | ||
private boolean dragging; | ||
|
||
public AbstractContainerWidget(int pX, int pY, int pWidth, int pHeight, Component pMessage) { | ||
super(pX, pY, pWidth, pHeight, pMessage); | ||
} | ||
|
||
public void renderButton(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { | ||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
AbstractWidget.render(pPoseStack, pMouseX, pMouseY, pPartialTick); | ||
} | ||
|
||
} | ||
|
||
public boolean isMouseOver(double pMouseX, double pMouseY) { | ||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
if (AbstractWidget.isMouseOver(pMouseX, pMouseY)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public void mouseMoved(double pMouseX, double pMouseY) { | ||
this.getContainedChildren().forEach((p_253796_) -> { | ||
p_253796_.mouseMoved(pMouseX, pMouseY); | ||
}); | ||
} | ||
|
||
public List<? extends GuiEventListener> children() { | ||
return this.getContainedChildren(); | ||
} | ||
|
||
protected abstract List<? extends AbstractWidget> getContainedChildren(); | ||
|
||
public boolean isDragging() { | ||
return this.dragging; | ||
} | ||
|
||
public void setDragging(boolean pIsDragging) { | ||
this.dragging = pIsDragging; | ||
} | ||
|
||
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) { | ||
boolean flag = false; | ||
|
||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
if (AbstractWidget.isMouseOver(pMouseX, pMouseY) && AbstractWidget.mouseScrolled(pMouseX, pMouseY, pDelta)) { | ||
flag = true; | ||
} | ||
} | ||
|
||
return flag || super.mouseScrolled(pMouseX, pMouseY, pDelta); | ||
} | ||
|
||
public boolean changeFocus(boolean pFocus) { | ||
return ContainerEventHandler.super.changeFocus(pFocus); | ||
} | ||
|
||
@Nullable | ||
protected GuiEventListener getHovered() { | ||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
if (AbstractWidget.isHoveredOrFocused()) { | ||
return AbstractWidget; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Nullable | ||
public GuiEventListener getFocused() { | ||
return this.focused; | ||
} | ||
|
||
public void setFocused(@Nullable GuiEventListener pFocused) { | ||
this.focused = pFocused; | ||
} | ||
|
||
public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) { | ||
GuiEventListener guieventlistener = this.getHovered(); | ||
if (guieventlistener != null) { | ||
if (guieventlistener instanceof NarrationSupplier) { | ||
NarrationSupplier narrationsupplier = (NarrationSupplier)guieventlistener; | ||
narrationsupplier.updateNarration(pNarrationElementOutput.nest()); | ||
} | ||
} else { | ||
GuiEventListener guieventlistener1 = this.getFocused(); | ||
if (guieventlistener1 != null && guieventlistener1 instanceof NarrationSupplier) { | ||
NarrationSupplier narrationsupplier1 = (NarrationSupplier)guieventlistener1; | ||
narrationsupplier1.updateNarration(pNarrationElementOutput.nest()); | ||
} | ||
} | ||
|
||
} | ||
|
||
public NarratableEntry.NarrationPriority narrationPriority() { | ||
if (!this.isHovered && this.getHovered() == null) { | ||
return this.focused != null ? NarratableEntry.NarrationPriority.FOCUSED : super.narrationPriority(); | ||
} else { | ||
return NarratableEntry.NarrationPriority.HOVERED; | ||
} | ||
} | ||
|
||
public void setX(int pX) { | ||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
int i = AbstractWidget.x + (pX - this.x); | ||
AbstractWidget.x = i; | ||
} | ||
|
||
super.x = pX; | ||
} | ||
|
||
public void setY(int pY) { | ||
for(AbstractWidget AbstractWidget : this.getContainedChildren()) { | ||
int i = AbstractWidget.y + (pY - this.y); | ||
AbstractWidget.y = i; | ||
} | ||
|
||
super.y = pY; | ||
} | ||
|
||
/** | ||
* Returns the first event listener that intersects with the mouse coordinates. | ||
*/ | ||
public Optional<GuiEventListener> getChildAt(double pMouseX, double pMouseY) { | ||
return ContainerEventHandler.super.getChildAt(pMouseX, pMouseY); | ||
} | ||
|
||
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) { | ||
return ContainerEventHandler.super.mouseClicked(pMouseX, pMouseY, pButton); | ||
} | ||
|
||
public boolean mouseReleased(double pMouseX, double pMouseY, int pButton) { | ||
return ContainerEventHandler.super.mouseReleased(pMouseX, pMouseY, pButton); | ||
} | ||
|
||
public boolean mouseDragged(double pMouseX, double pMouseY, int pButton, double pDragX, double pDragY) { | ||
return ContainerEventHandler.super.mouseDragged(pMouseX, pMouseY, pButton, pDragX, pDragY); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
protected abstract static class AbstractChildWrapper { | ||
public final AbstractWidget child; | ||
public final LayoutSettings.LayoutSettingsImpl layoutSettings; | ||
|
||
protected AbstractChildWrapper(AbstractWidget pChild, LayoutSettings pLayoutSettings) { | ||
this.child = pChild; | ||
this.layoutSettings = pLayoutSettings.getExposed(); | ||
} | ||
|
||
public int getHeight() { | ||
return this.child.getHeight() + this.layoutSettings.paddingTop + this.layoutSettings.paddingBottom; | ||
} | ||
|
||
public int getWidth() { | ||
return this.child.getWidth() + this.layoutSettings.paddingLeft + this.layoutSettings.paddingRight; | ||
} | ||
|
||
public void setX(int pX, int pWidth) { | ||
float f = (float)this.layoutSettings.paddingLeft; | ||
float f1 = (float)(pWidth - this.child.getWidth() - this.layoutSettings.paddingRight); | ||
int i = (int)Mth.lerp(this.layoutSettings.xAlignment, f, f1); | ||
this.child.x = i + pX; | ||
} | ||
|
||
public void setY(int pY, int pHeight) { | ||
float f = (float)this.layoutSettings.paddingTop; | ||
float f1 = (float)(pHeight - this.child.getHeight() - this.layoutSettings.paddingBottom); | ||
int i = (int)Mth.lerp(this.layoutSettings.yAlignment, f, f1); | ||
this.child.y = i + pY; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/cstav/genshinstrument/client/gui/widget/copied/AbstractWidget2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied; | ||
|
||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.network.chat.Component; | ||
|
||
public abstract class AbstractWidget2 extends AbstractWidget { | ||
|
||
public AbstractWidget2(int pX, int pY, int pWidth, int pHeight, Component pMessage) { | ||
super(pX, pY, pWidth, pHeight, pMessage); | ||
} | ||
|
||
public boolean isHovered; | ||
|
||
public void setX(final int x) { | ||
this.x = x; | ||
} | ||
public int getX() { | ||
return x; | ||
} | ||
|
||
public void setY(final int y) { | ||
this.y = y; | ||
} | ||
public int getY() { | ||
return y; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...m/cstav/genshinstrument/client/gui/widget/copied/BelowOrAboveWidgetTooltipPositioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied; | ||
|
||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import org.joml.Vector2i; | ||
import org.joml.Vector2ic; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class BelowOrAboveWidgetTooltipPositioner implements ClientTooltipPositioner { | ||
private final AbstractWidget widget; | ||
|
||
public BelowOrAboveWidgetTooltipPositioner(AbstractWidget pWidget) { | ||
this.widget = pWidget; | ||
} | ||
|
||
public Vector2ic positionTooltip(Screen pScreen, int pMouseX, int pMouseY, int pWidth, int pHeight) { | ||
Vector2i vector2i = new Vector2i(); | ||
vector2i.x = this.widget.x + 3; | ||
vector2i.y = this.widget.y + this.widget.getHeight() + 3 + 1; | ||
if (vector2i.y + pHeight + 3 > pScreen.height) { | ||
vector2i.y = this.widget.y - pHeight - 3 - 1; | ||
} | ||
|
||
if (vector2i.x + pWidth > pScreen.width) { | ||
vector2i.x = Math.max(this.widget.x + this.widget.getWidth() - pWidth - 3, 4); | ||
} | ||
|
||
return vector2i; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/com/cstav/genshinstrument/client/gui/widget/copied/ClientTooltipPositioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied; | ||
|
||
import org.joml.Vector2ic; | ||
|
||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public interface ClientTooltipPositioner { | ||
Vector2ic positionTooltip(Screen pScreen, int pMouseX, int pMouseY, int pWidth, int pHeight); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/cstav/genshinstrument/client/gui/widget/copied/CreateNarration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public interface CreateNarration { | ||
MutableComponent createNarrationMessage(Supplier<MutableComponent> p_253695_); | ||
} |
Oops, something went wrong.