Skip to content

Commit

Permalink
Update to 24w36a
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Sep 10, 2024
1 parent 1e05ed0 commit 29c3a2d
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 458 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
- v14
- v14-24w14potato
- v15
- v16

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}

architectury {
common("fabric", "forge", "neoforge")
common("fabric"/*, "forge", "neoforge"*/)
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,15 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package me.shedaniel.clothconfig2.api;
package me.shedaniel.clothconfig2;

import me.shedaniel.clothconfig2.impl.ScissorsHandlerImpl;
import me.shedaniel.math.Rectangle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;

import java.util.List;

@Environment(EnvType.CLIENT)
public interface ScissorsHandler {
ScissorsHandler INSTANCE = ScissorsHandlerImpl.INSTANCE;

void clearScissors();

List<Rectangle> getScissorsAreas();

void scissor(Rectangle rectangle);

void removeLastScissor();

void applyScissors();
@ApiStatus.Internal
public class CCTextures {
private static final String MOD_ID = "cloth-config2";
public static final ResourceLocation VERTICAL_HEADER_SEPARATOR = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/vertical_header_separator.png");
public static final ResourceLocation VERTICAL_FOOTER_SEPARATOR = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/vertical_footer_separator.png");
public static final ResourceLocation CONFIG = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/cloth_config.png");
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget;
import me.shedaniel.clothconfig2.impl.EasingMethod;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.FastColor;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;

import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_BACKGROUND_SPRITE;
import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_SPRITE;

@Deprecated
public abstract class ScrollingContainer {
public double scrollAmount;
Expand Down Expand Up @@ -141,16 +144,8 @@ public void renderScrollBar(GuiGraphics graphics, int background, float alpha, f
int minY = Math.min(Math.max((int) scrollAmount * (bounds.height - height) / maxScroll + bounds.y, bounds.y), bounds.getMaxY() - height);

int scrollbarPositionMinX = getScrollBarX();
int scrollbarPositionMaxX = scrollbarPositionMinX + 6;
boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.ofMouse());
float bottomC = (hovered ? .67f : .5f) * scrollBarAlphaOffset;
float topC = (hovered ? .87f : .67f) * scrollBarAlphaOffset;

graphics.fill(scrollbarPositionMinX, bounds.y, scrollbarPositionMaxX, bounds.getMaxY(), background);
graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height,
FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F)));
graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1,
FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F)));
graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, scrollbarPositionMinX, bounds.y, 6, bounds.height, background);
graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height, ARGB.white(alpha));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
import me.shedaniel.clothconfig2.api.animator.ValueAnimator;
import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.FastColor;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;

public abstract class ScrollingContainer {
public static final ResourceLocation SCROLLER_SPRITE = ResourceLocation.withDefaultNamespace("widget/scroller");
public static final ResourceLocation SCROLLER_BACKGROUND_SPRITE = ResourceLocation.withDefaultNamespace("widget/scroller_background");
private final NumberAnimator<Double> scroll = ValueAnimator.ofDouble();
private boolean draggingScrollBar = false;
private long scrollDuration = ClothConfigInitializer.getScrollDuration();
Expand Down Expand Up @@ -106,6 +109,10 @@ public final void scrollTo(double value, boolean animated, long duration) {
}
}

public void setScrollTarget(double scrollTarget) {
this.scroll.setTarget(scrollTarget);
}

public void updatePosition(float delta) {
scroll.setTarget(handleBounceBack(this.scrollTarget(), this.getMaxScroll(), delta));
this.scroll.update(delta);
Expand Down Expand Up @@ -137,10 +144,10 @@ public static double clampExtension(double v, double maxScroll, double clampExte
}

public void renderScrollBar(GuiGraphics graphics) {
renderScrollBar(graphics, 0, 1, 1);
renderScrollBar(graphics, ARGB.alpha(255), 1);
}

public void renderScrollBar(GuiGraphics graphics, int background, float alpha, float scrollBarAlphaOffset) {
public void renderScrollBar(GuiGraphics graphics, int background, float alpha) {
if (hasScrollBar()) {
Rectangle bounds = getBounds();
int maxScroll = getMaxScroll();
Expand All @@ -151,16 +158,8 @@ public void renderScrollBar(GuiGraphics graphics, int background, float alpha, f
int minY = Math.min(Math.max((int) scrollAmount() * (bounds.height - height) / maxScroll + bounds.y, bounds.y), bounds.getMaxY() - height);

int scrollbarPositionMinX = getScrollBarX(bounds.getMaxX());
int scrollbarPositionMaxX = scrollbarPositionMinX + 6;
boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.ofMouse());
float bottomC = (hovered ? .67f : .5f) * scrollBarAlphaOffset;
float topC = (hovered ? .87f : .67f) * scrollBarAlphaOffset;

graphics.fill(scrollbarPositionMinX, bounds.y, scrollbarPositionMaxX, bounds.getMaxY(), background);
graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height,
FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F)));
graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1,
FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F)));
graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, scrollbarPositionMinX, bounds.y, 6, bounds.height, background);
graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height, ARGB.white(alpha));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.blaze3d.vertex.VertexConsumer;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import me.shedaniel.clothconfig2.ClothConfigInitializer;
import me.shedaniel.clothconfig2.api.*;
Expand All @@ -36,7 +35,7 @@
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
Expand Down Expand Up @@ -366,26 +365,16 @@ public void addTooltip(Tooltip tooltip) {
this.tooltips.add(tooltip);
}

@Deprecated
protected void overlayBackground(GuiGraphics graphics, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) {
overlayBackground(graphics.pose(), rect, red, green, blue, startAlpha, endAlpha);
}

protected void overlayBackground(PoseStack matrices, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) {
overlayBackground(matrices.last().pose(), rect, red, green, blue, startAlpha, endAlpha);
}

protected void overlayBackground(Matrix4f matrix, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) {
if (isTransparentBackground())
return;
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, getBackgroundLocation());
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
buffer.addVertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
buffer.addVertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
graphics.drawSpecial(source -> {
VertexConsumer buffer = source.getBuffer(RenderType.guiTextured(getBackgroundLocation()));
Matrix4f matrix = graphics.pose().last().pose();
buffer.addVertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
buffer.addVertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
});
}

@Override
Expand Down
Loading

0 comments on commit 29c3a2d

Please sign in to comment.