Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Dec 6, 2024
1 parent 64d72a3 commit 3a3c849
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
- v14-24w14potato
- v15
- v16
- v17

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del
}

@Override
protected boolean clicked(double double_1, double double_2) {
return visible && active && isMouseOver(double_1, double_2);
protected boolean isValidClickButton(int i) {
return visible && active && super.isValidClickButton(i);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package me.shedaniel.clothconfig2.gui.entries;

import me.shedaniel.math.Rectangle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -98,13 +99,28 @@ public boolean isEdited() {
@ApiStatus.Internal
public static abstract class AbstractListCell<T, SELF extends AbstractListCell<T, SELF, OUTER_SELF>, OUTER_SELF extends AbstractListListEntry<T, SELF, OUTER_SELF>> extends BaseListCell {
protected final OUTER_SELF listListEntry;
protected final Rectangle cellBounds = new Rectangle();

public AbstractListCell(@Nullable T value, OUTER_SELF listListEntry) {
this.listListEntry = listListEntry;
this.setErrorSupplier(() -> Optional.ofNullable(listListEntry.cellErrorSupplier).flatMap(cellErrorFn -> cellErrorFn.apply(this.getValue())));
}

public abstract T getValue();

@Override
public void updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) {
if (expanded) {
this.cellBounds.setBounds(x, y, entryWidth, entryHeight);
} else {
this.cellBounds.setBounds(0, 0, 0, 0);
}
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return cellBounds.contains(mouseX, mouseY);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void setErrorSupplier(Supplier<Optional<Component>> errorSupplier) {

public abstract void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta);

public void updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) {}

public void updateSelected(boolean isSelected) {}

public boolean isRequiresRestart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth
int yy = y + 24;
for (BaseListCell cell : cells) {
cell.render(graphics, -1, yy, x + 14, entryWidth - 14, cell.getCellHeight(), mouseX, mouseY, getParent().getFocused() != null && getParent().getFocused().equals(this) && getFocused() != null && getFocused().equals(cell), delta);
cell.updateBounds(true, x + 14, yy, entryWidth - 14, cell.getCellHeight());
yy += cell.getCellHeight();
}
} else {
int yy = y + 24;
for (BaseListCell cell : cells) {
cell.updateBounds(false, x + 14, yy, entryWidth - 14, cell.getCellHeight());
yy += cell.getCellHeight();
}
}
Expand All @@ -327,6 +334,20 @@ public boolean insertInFront() {
return insertInFront;
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
if (super.isMouseOver(mouseX, mouseY)) return true;
if (isExpanded()) {
for (BaseListCell cell : cells) {
if (cell.isMouseOver(mouseX, mouseY)) {
return true;
}
}
}

return false;
}

public class ListLabelWidget implements GuiEventListener {
protected Rectangle rectangle = new Rectangle();

Expand Down Expand Up @@ -375,6 +396,11 @@ public void setFocused(boolean bl) {
public boolean isFocused() {
return false;
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return rectangle.contains(mouseX, mouseY) && !resetWidget.isMouseOver(mouseX, mouseY);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public boolean mouseScrolled(double double_1, double double_2, double amountX, d
return selectionElement.mouseScrolled(double_1, double_2, amountX, amountY);
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return super.isMouseOver(mouseX, mouseY) || selectionElement.isMouseOver(mouseX, mouseY);
}

public static class SelectionElement<R> extends AbstractContainerEventHandler implements Renderable {
protected Rectangle bounds;
protected boolean active;
Expand All @@ -189,6 +194,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
graphics.fill(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, topRenderer.isSelected ? -1 : -6250336);
graphics.fill(bounds.x + 1, bounds.y + 1, bounds.x + bounds.width - 1, bounds.y + bounds.height - 1, -16777216);
topRenderer.render(graphics, mouseX, mouseY, bounds.x, bounds.y, bounds.width, bounds.height, delta);
topRenderer.updateBounds(bounds);
if (menu.isExpanded())
menu.render(graphics, mouseX, mouseY, bounds, delta);
}
Expand Down Expand Up @@ -235,6 +241,11 @@ public boolean mouseClicked(double double_1, double double_2, int int_1) {
}
return b;
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return bounds.contains(mouseX, mouseY) || (menu.isExpanded() && menu.isMouseOver(mouseX, mouseY));
}
}

public static abstract class DropdownMenuElement<R> extends AbstractContainerEventHandler {
Expand Down Expand Up @@ -413,9 +424,12 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta
for (SelectionCellElement<R> cell : currentElements) {
if (yy + getCellCreator().getCellHeight() >= lastRectangle.y + lastRectangle.height && yy <= lastRectangle.y + lastRectangle.height + last10Height + 1) {
graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + getCellCreator().getCellWidth(), (int) yy + getCellCreator().getCellHeight(), 0xFF000000);
cell.bounds.setBounds(lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight());
cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight(), delta);
} else
} else {
cell.bounds.setBounds(0, 0, 0, 0);
cell.dontRender(graphics, delta);
}
yy += getCellCreator().getCellHeight();
}
graphics.disableScissor();
Expand Down Expand Up @@ -557,6 +571,7 @@ public int getDropBoxMaxHeight() {
}

public static abstract class SelectionCellElement<R> extends AbstractContainerEventHandler {
@Deprecated final Rectangle bounds = new Rectangle();
@SuppressWarnings("NotNullFieldNotInitialized") @Deprecated @NotNull private DropdownBoxEntry<R> entry;

@NotNull
Expand All @@ -573,6 +588,11 @@ public final DropdownBoxEntry<R> getEntry() {

@Nullable
public abstract R getSelection();

@Override
public boolean isMouseOver(double d, double e) {
return bounds.contains(d, e);
}
}

public static class DefaultSelectionCellElement<R> extends SelectionCellElement<R> {
Expand Down Expand Up @@ -638,6 +658,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int int_1) {
}

public static abstract class SelectionTopCellElement<R> extends AbstractContainerEventHandler {
@Deprecated private final Rectangle bounds = new Rectangle();
@Deprecated private DropdownBoxEntry<R> entry;
protected boolean isSelected = false;

Expand Down Expand Up @@ -689,6 +710,15 @@ public void selectFirstRecommendation() {
}

public abstract void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, int width, int height, float delta);

private void updateBounds(Rectangle bounds) {
this.bounds.setBounds(bounds);
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return this.bounds.contains(mouseX, mouseY);
}
}

public static class DefaultSelectionTopCellElement<R> extends SelectionTopCellElement<R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,32 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth
if (isExpanded()) {
int yy = y + 24;
for (AbstractConfigListEntry<?> entry : entries) {
entry.setBounds(new Rectangle(x, yy, entryWidth, entry.getItemHeight()));
entry.render(graphics, -1, yy, x + 14, entryWidth - 14, entry.getItemHeight(), mouseX, mouseY, isHovered, delta);
yy += entry.getItemHeight();
yy += Math.max(0, entry.getMorePossibleHeight());
}
} else {
for (AbstractConfigListEntry<?> entry : entries) {
entry.setBounds(new Rectangle());
}
}
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
if (super.isMouseOver(mouseX, mouseY)) return true;
if (isExpanded()) {
for (AbstractConfigListEntry<?> entry : entries) {
if (entry.isMouseOver(mouseX, mouseY)) {
return true;
}
}
}

return false;
}

@Override
public Rectangle getEntryArea(int x, int y, int entryWidth, int entryHeight) {
widget.rectangle.x = x - 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import me.shedaniel.clothconfig2.api.ReferenceProvider;
import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry.NestedListCell;
import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget;
import me.shedaniel.math.Rectangle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -112,6 +113,16 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth
nestedEntry.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
}

@Override
public void updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) {
super.updateBounds(expanded, x, y, entryWidth, entryHeight);
if (expanded) {
nestedEntry.setBounds(new Rectangle(x, y, entryWidth, nestedEntry.getItemHeight()));
} else {
nestedEntry.setBounds(new Rectangle());
}
}

@Override
public List<? extends GuiEventListener> children() {
return Collections.singletonList(nestedEntry);
Expand Down Expand Up @@ -155,5 +166,10 @@ public NarrationPriority narrationPriority() {
public void updateNarration(NarrationElementOutput narrationElementOutput) {

}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return super.isMouseOver(mouseX, mouseY) || nestedEntry.isMouseOver(mouseX, mouseY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth
if (isExpanded()) {
int yy = y + 24;
for (AbstractConfigListEntry<?> entry : filteredEntries()) {
entry.setBounds(new Rectangle(x + 14, yy, entryWidth - 14, entry.getItemHeight()));
entry.render(graphics, -1, yy, x + 14, entryWidth - 14, entry.getItemHeight(), mouseX, mouseY, isHovered && getFocused() == entry, delta);
yy += entry.getItemHeight();
}
} else {
for (AbstractConfigListEntry<?> entry : entries) {
entry.setBounds(new Rectangle());
}
}
}

Expand Down Expand Up @@ -285,6 +290,20 @@ public Optional<Component> getError() {
return Optional.ofNullable(error);
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
if (super.isMouseOver(mouseX, mouseY)) return true;
if (isExpanded()) {
for (AbstractConfigListEntry<?> entry : entries) {
if (entry.isMouseOver(mouseX, mouseY)) {
return true;
}
}
}

return false;
}

public class CategoryLabelWidget implements GuiEventListener, NarratableEntry {
private final Rectangle rectangle = new Rectangle();
private boolean isHovered;
Expand Down Expand Up @@ -317,6 +336,11 @@ public NarrationPriority narrationPriority() {
public void updateNarration(NarrationElementOutput narrationElementOutput) {
narrationElementOutput.add(NarratedElementType.TITLE, getFieldName());
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return rectangle.contains(mouseX, mouseY);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import me.shedaniel.clothconfig2.api.HideableWidget;
import me.shedaniel.clothconfig2.api.Requirement;
import me.shedaniel.clothconfig2.api.TickableWidget;
import me.shedaniel.math.Rectangle;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -576,6 +577,7 @@ protected void renderList(GuiGraphics graphics, int startX, int startY, int mous
}

protected void renderItem(GuiGraphics graphics, E item, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
item.setBounds(new Rectangle(x, y, entryWidth, entryHeight));
item.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta);
}

Expand Down Expand Up @@ -636,6 +638,7 @@ private SmoothScrollingSettings() {}
@Environment(EnvType.CLIENT)
public abstract static class Entry<E extends Entry<E>> implements GuiEventListener, TickableWidget, HideableWidget, DisableableWidget {
@Deprecated DynamicEntryListWidget<E> parent;
@Deprecated final Rectangle bounds = new Rectangle();
@Nullable
private NarratableEntry lastNarratable;
@Nullable
Expand All @@ -651,7 +654,7 @@ public Entry() {
public abstract void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta);

public boolean isMouseOver(double double_1, double double_2) {
return Objects.equals(this.parent.getItemAtPosition(double_1, double_2), this);
return this.bounds.contains(double_1, double_2);
}

public DynamicEntryListWidget<E> getParent() {
Expand All @@ -662,6 +665,11 @@ public void setParent(DynamicEntryListWidget<E> parent) {
this.parent = parent;
}

@Deprecated
public void setBounds(Rectangle bounds) {
this.bounds.setBounds(bounds);
}

@Override
public boolean isEnabled() {
return isDisplayed() && enabled;
Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ unifiedPublishing {
curseforge {
token = project.hasProperty("curse_api_key") ? project.property("curse_api_key") : System.getenv("curse_api_key")
id = project.curseforge_id
gameVersions.addAll "1.21.2-Snapshot", "Java 21", "1.21.2"
gameVersions.addAll "1.21.4-Snapshot", "Java 21", "1.21.4"
}
}

Expand Down
4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "cloth-config",
"name": "Cloth Config v16",
"name": "Cloth Config v17",
"description": "An API for config screens.",
"version": "${version}",
"authors": [
Expand All @@ -27,7 +27,7 @@
],
"depends": {
"fabricloader": ">=0.14.0",
"minecraft": ">=1.21.2-"
"minecraft": ">=1.21.4-"
},
"accessWidener": "cloth-config.accessWidener",
"custom": {
Expand Down
Loading

0 comments on commit 3a3c849

Please sign in to comment.