diff options
22 files changed, 290 insertions, 136 deletions
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 6cba8593f..dfd2da84d 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -25,10 +25,16 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.impl.Internals; import me.shedaniel.rei.utils.CollectionUtils; +import me.shedaniel.rei.utils.FormattingUtils; +import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.jetbrains.annotations.ApiStatus; @@ -135,7 +141,11 @@ public interface ClientHelper { * @param item the item to find * @return the mod name */ - String getModFromItem(Item item); + default String getModFromItem(Item item) { + if (item.equals(Items.AIR)) + return ""; + return getModFromIdentifier(Registry.ITEM.getKey(item)); + } /** * Tries to delete the player's cursor item @@ -148,7 +158,12 @@ public interface ClientHelper { * @param item the item to find * @return the mod name with blue and italic formatting */ - ITextComponent getFormattedModFromItem(Item item); + default ITextComponent getFormattedModFromItem(Item item) { + String mod = getModFromItem(item); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new StringTextComponent(mod).withStyle(TextFormatting.BLUE, TextFormatting.ITALIC); + } /** * Gets the formatted mod from an identifier @@ -156,7 +171,38 @@ public interface ClientHelper { * @param identifier the identifier to find * @return the mod name with blue and italic formatting */ - ITextComponent getFormattedModFromIdentifier(ResourceLocation identifier); + default ITextComponent getFormattedModFromIdentifier(ResourceLocation identifier) { + String mod = getModFromIdentifier(identifier); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new StringTextComponent(mod).withStyle(TextFormatting.BLUE, TextFormatting.ITALIC); + } + + /** + * Gets the mod from a modid + * + * @param modid the modid of the mod + * @return the mod name with blue and italic formatting + */ + default ITextComponent getFormattedModFromModId(String modid) { + String mod = getModFromModId(modid); + if (mod.isEmpty()) + return NarratorChatListener.NO_TITLE; + return new StringTextComponent(mod).withStyle(TextFormatting.BLUE, TextFormatting.ITALIC); + } + + default List<ITextComponent> appendModIdToTooltips(List<ITextComponent> components, String modId) { + final String modName = ClientHelper.getInstance().getModFromModId(modId); + boolean alreadyHasMod = false; + for (ITextComponent s : components) + if (FormattingUtils.stripFormatting(s.getString()).equalsIgnoreCase(modName)) { + alreadyHasMod = true; + break; + } + if (!alreadyHasMod) + components.add(ClientHelper.getInstance().getFormattedModFromModId(modId)); + return components; + } /** * Gets the mod from an identifier diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index ab7017a79..420473060 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -165,15 +165,18 @@ public interface DisplayHelper { * @see BaseBoundsHandler#registerExclusionZones(Class, Supplier) for easier api */ default ActionResultType canItemSlotWidgetFit(int left, int top, T screen, Rectangle fullBounds) { - ActionResultType fit = isInZone(left, top); - if (fit == ActionResultType.FAIL) - return ActionResultType.FAIL; - ActionResultType fit2 = isInZone(left + 18, top + 18); - if (fit2 == ActionResultType.FAIL) - return ActionResultType.FAIL; - if (fit == ActionResultType.SUCCESS && fit2 == ActionResultType.SUCCESS) - return ActionResultType.SUCCESS; - return ActionResultType.PASS; + ActionResultType fit; + fit = isInZone(left, top); + if (fit != ActionResultType.PASS) + return fit; + fit = isInZone(left + 18, top); + if (fit != ActionResultType.PASS) + return fit; + fit = isInZone(left, top + 18); + if (fit != ActionResultType.PASS) + return fit; + fit = isInZone(left + 18, top + 18); + return fit; } @Override diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java index c0450e106..ddae54f4e 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/TextRepresentable.java @@ -26,8 +26,8 @@ package me.shedaniel.rei.api; import me.shedaniel.clothconfig2.forge.api.PointHelper; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.utils.FormattingUtils; +import me.shedaniel.rei.utils.ImmutableLiteralText; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.jetbrains.annotations.NotNull; @@ -41,11 +41,11 @@ public interface TextRepresentable { if (tooltip != null && !tooltip.getText().isEmpty()) return tooltip.getText().get(0); } - return new StringTextComponent(""); + return ImmutableLiteralText.EMPTY; } @NotNull default ITextComponent asFormatStrippedText() { - return new StringTextComponent(FormattingUtils.stripFormatting(asFormattedText().getString())); + return new ImmutableLiteralText(FormattingUtils.stripFormatting(asFormattedText().getString())); } } diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Label.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Label.java index 6a44cc793..685c3916d 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Label.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/widgets/Label.java @@ -311,6 +311,8 @@ public abstract class Label extends WidgetWithBounds { public abstract void setMessage(@NotNull ITextProperties message); + public abstract void setRainbow(boolean rainbow); + @NotNull public final Label text(@NotNull ITextComponent text) { setText(text); @@ -322,4 +324,10 @@ public abstract class Label extends WidgetWithBounds { setMessage(message); return this; } + + @NotNull + public final Label rainbow(boolean rainbow) { + setRainbow(rainbow); + return this; + } } diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/ImmutableLiteralText.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/ImmutableLiteralText.java index 022af2879..fe71442e4 100644 --- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/ImmutableLiteralText.java +++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/ImmutableLiteralText.java @@ -30,7 +30,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -public final class ImmutableLiteralText implements ITextComponent { +public final class ImmutableLiteralText implements IFormattableTextComponent { public static final ImmutableLiteralText EMPTY = new ImmutableLiteralText(""); private final String content; private IReorderingProcessor orderedText; @@ -56,7 +56,7 @@ public final class ImmutableLiteralText implements ITextComponent { @Override public IFormattableTextComponent plainCopy() { - return new StringTextComponent(content); + return this; } @Override @@ -81,4 +81,14 @@ public final class ImmutableLiteralText implements ITextComponent { } return orderedText; } + + @Override + public IFormattableTextComponent setStyle(Style style) { + return new StringTextComponent(content).withStyle(style); + } + + @Override + public IFormattableTextComponent append(ITextComponent component) { + return new StringTextComponent(content).append(component); + } } diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 737600746..a98c49e69 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -76,6 +76,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.List; +import java.util.Random; import java.util.Set; @ApiStatus.Internal @@ -321,7 +322,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } subsetsButtonBounds = getSubsetsButtonBounds(); if (ConfigObject.getInstance().isSubsetsEnabled()) { - widgets.add(InternalWidgets.wrapLateRenderable(InternalWidgets.wrapTranslate(Widgets.createButton(subsetsButtonBounds, ((ClientHelperImpl) ClientHelper.getInstance()).isAprilFools.get() ? new TranslationTextComponent("text.rei.tiny_potato") : new TranslationTextComponent("text.rei.subsets")) + widgets.add(InternalWidgets.wrapLateRenderable(InternalWidgets.wrapTranslate(Widgets.createButton(subsetsButtonBounds, ClientHelperImpl.getInstance().isAprilFools.get() ? new TranslationTextComponent("text.rei.tiny_potato") : new TranslationTextComponent("text.rei.subsets")) .onClick(button -> { if (subsetsMenu == null) { wrappedSubsetsMenu = InternalWidgets.wrapTranslate(InternalWidgets.wrapLateRenderable(this.subsetsMenu = Menu.createSubsetsMenuFromRegistry(new Point(this.subsetsButtonBounds.x, this.subsetsButtonBounds.getMaxY()))), 0, 0, 400); @@ -340,7 +341,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl }).tooltipLine(I18n.get("text.rei.go_back_first_page")).focusable(false).onRender((matrices, label) -> { label.setClickable(ENTRY_LIST_WIDGET.getTotalPages() > 1); label.setText(new StringTextComponent(String.format("%s/%s", ENTRY_LIST_WIDGET.getPage() + 1, Math.max(ENTRY_LIST_WIDGET.getTotalPages(), 1)))); - })); + }).rainbow(new Random().nextFloat() < 1.0E-4D || ClientHelperImpl.getInstance().isAprilFools.get())); } if (ConfigObject.getInstance().isCraftableFilterEnabled()) { Rectangle area = getCraftableToggleArea(); @@ -591,10 +592,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl public void renderTooltipInner(MatrixStack matrices, List<IReorderingProcessor> lines, int mouseX, int mouseY) { if (lines.isEmpty()) return; - tooltipWidth = lines.stream().map(font::width).max(Integer::compareTo).get(); - tooltipHeight = lines.size() <= 1 ? 8 : lines.size() * 10; - tooltipLines = lines; - ScreenHelper.drawHoveringWidget(matrices, mouseX, mouseY, renderTooltipCallback, tooltipWidth, tooltipHeight, 0); + matrices.pushPose(); + matrices.translate(0, 0, 500); + minecraft.screen.renderTooltip(matrices, lines, mouseX, mouseY); + matrices.popPose(); } public void addTooltip(@Nullable Tooltip tooltip) { diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java index 9c1a414f9..e2523bb29 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java @@ -327,17 +327,18 @@ public class FilteringScreen extends Screen { } public void updateEntriesPosition() { + int entrySize = entrySize(); this.innerBounds = updateInnerBounds(getBounds()); - int width = innerBounds.width / entrySize(); - int pageHeight = innerBounds.height / entrySize(); + int width = innerBounds.width / entrySize; + int pageHeight = innerBounds.height / entrySize; int slotsToPrepare = Math.max(entryStacks.size() * 3, width * pageHeight * 3); int currentX = 0; int currentY = 0; List<EntryListEntry> entries = Lists.newArrayList(); for (int i = 0; i < slotsToPrepare; i++) { - int xPos = currentX * entrySize() + innerBounds.x; - int yPos = currentY * entrySize() + innerBounds.y; - entries.add(new EntryListEntry(xPos, yPos)); + int xPos = currentX * entrySize + innerBounds.x; + int yPos = currentY * entrySize + innerBounds.y; + entries.add(new EntryListEntry(xPos, yPos, entrySize)); currentX++; if (currentX >= width) { currentX = 0; @@ -453,10 +454,10 @@ public class FilteringScreen extends Screen { private boolean filtered = false; private boolean dirty = true; - private EntryListEntry(int x, int y) { + private EntryListEntry(int x, int y, int entrySize) { super(new Point(x, y)); this.backupY = y; - getBounds().width = getBounds().height = entrySize(); + getBounds().width = getBounds().height = entrySize; interactableFavorites(false); interactable(false); noHighlight(); diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java index 7678b225e..855f6033a 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java @@ -25,12 +25,20 @@ package me.shedaniel.rei.gui.credits; import com.mojang.blaze3d.matrix.MatrixStack; import me.shedaniel.clothconfig2.forge.gui.widget.DynamicNewSmoothScrollingEntryListWidget; +import me.shedaniel.rei.impl.TextTransformations; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.SimpleSound; import net.minecraft.client.gui.AbstractGui; import net.minecraft.util.IReorderingProcessor; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.Util; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; import org.jetbrains.annotations.ApiStatus; +import java.net.URI; +import java.net.URISyntaxException; import java.util.List; @ApiStatus.Internal @@ -139,4 +147,66 @@ public class CreditsEntryListWidget extends DynamicNewSmoothScrollingEntryListWi } } + public static class LinkItem extends CreditsItem { + private ITextComponent text; + private List<IReorderingProcessor> textSplit; + private String link; + private boolean contains; + private boolean rainbow; + + public LinkItem(ITextComponent text, String link, int width, boolean rainbow) { + this.text = text; + this.textSplit = Minecraft.getInstance().font.split(text, width); + this.link = link; + this.rainbow = rainbow; + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + contains = mouseX >= x && mouseX <= x + entryWidth && mouseY >= y && mouseY <= y + entryHeight; + if (contains) { + Minecraft.getInstance().screen.renderTooltip(matrices, new StringTextComponent("Click to open link."), mouseX, mouseY); + int yy = y; + for (IReorderingProcessor textSp : textSplit) { + IReorderingProcessor underlined = characterVisitor -> { + return textSp.accept((charIndex, style, codePoint) -> characterVisitor.accept(charIndex, style.applyFormat(TextFormatting.UNDERLINE), codePoint)); + }; + if (rainbow) underlined = TextTransformations.applyRainbow(underlined, x + 5, yy); + Minecraft.getInstance().font.drawShadow(matrices, underlined, x + 5, yy, 0xff1fc3ff); + yy += 12; + } + } else { + int yy = y; + for (IReorderingProcessor textSp : textSplit) { + if (rainbow) textSp = TextTransformations.applyRainbow(textSp, x + 5, yy); + Minecraft.getInstance().font.drawShadow(matrices, textSp, x + 5, yy, 0xff1fc3ff); + yy += 12; + } + } + } + + @Override + public int getItemHeight() { + return 12 * textSplit.size(); + } + + @Override + public boolean changeFocus(boolean boolean_1) { + return false; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (contains && button == 0) { + Minecraft.getInstance().getSoundManager().play(SimpleSound.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + try { + Util.getPlatform().openUri(new URI(link)); + return true; + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + return false; + } + } } diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java index 4c1a71e70..60f6a217a 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java @@ -110,6 +110,10 @@ public class CreditsScreen extends Screen { } } else entryListWidget.creditsAddEntry(new TextCreditsItem(new ImmutableLiteralText(line))); entryListWidget.creditsAddEntry(new TextCreditsItem(NarratorChatListener.NO_TITLE)); + entryListWidget.creditsAddEntry(new CreditsEntryListWidget.LinkItem(new ImmutableLiteralText("Visit the project at GitHub."), "https://www.github.com/shedaniel/RoughlyEnoughItems", entryListWidget.getItemWidth(), false)); + entryListWidget.creditsAddEntry(new CreditsEntryListWidget.LinkItem(new ImmutableLiteralText("Visit the project page at CurseForge."), "https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items", entryListWidget.getItemWidth(), false)); + entryListWidget.creditsAddEntry(new CreditsEntryListWidget.LinkItem(new ImmutableLiteralText("Support the project via Patreon!"), "https://patreon.com/shedaniel", entryListWidget.getItemWidth(), true)); + entryListWidget.creditsAddEntry(new TextCreditsItem(NarratorChatListener.NO_TITLE)); children.add(buttonDone = new AbstractButton(width / 2 - 100, height - 26, 200, 20, new TranslationTextComponent("gui.done")) { @Override public void onPress() { @@ -131,7 +135,7 @@ public class CreditsScreen extends Screen { public void render(MatrixStack matrices, int int_1, int int_2, float float_1) { this.renderDirtBackground(0); this.entryListWidget.render(matrices, int_1, int_2, float_1); - this.drawCenteredString(matrices, this.font, I18n.get("text.rei.credits"), this.width / 2, 16, 16777215); + drawCenteredString(matrices, this.font, I18n.get("text.rei.credits"), this.width / 2, 16, 16777215); super.render(matrices, int_1, int_2, float_1); buttonDone.render(matrices, int_1, int_2, float_1); } diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java index 02acc94dc..14e92c0af 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java @@ -70,12 +70,12 @@ public class DefaultRuntimePlugin implements REIPluginV0 { @Override public boolean isEmpty() { - return !((ClientHelperImpl) ClientHelper.getInstance()).isAprilFools.get(); + return !ClientHelperImpl.getInstance().isAprilFools.get(); } @Override public @Nullable Tooltip getTooltip(Point point) { - return Tooltip.create(new StringTextComponent("Kibby")); + return Tooltip.create(new StringTextComponent("Kirby"), ClientHelper.getInstance().getFormattedModFromModId("Dream Land")); } }); } diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java index b57cad0b3..1c0d32744 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java @@ -31,15 +31,13 @@ import me.shedaniel.rei.api.EntryStack; import net.minecraft.client.gui.screen.Screen; import net.minecraft.item.Item; -import static me.shedaniel.rei.gui.widget.EntryListWidget.entrySize; - public class EntryListEntryWidget extends EntryWidget { public int backupY; - protected EntryListEntryWidget(Point point) { + protected EntryListEntryWidget(Point point, int entrySize) { super(point); this.backupY = point.y; - getBounds().width = getBounds().height = entrySize(); + getBounds().width = getBounds().height = entrySize; } @Override diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index 8e3c4f75d..bebf829f4 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -112,31 +112,42 @@ public class EntryListWidget extends WidgetWithBounds { return MathHelper.ceil(SIZE * ConfigObject.getInstance().getEntrySize()); } - static boolean notSteppingOnExclusionZones(int left, int top, Rectangle listArea) { + static boolean notSteppingOnExclusionZones(int left, int top, int width, int height, Rectangle listArea) { Minecraft instance = Minecraft.getInstance(); for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(instance.screen.getClass())) { - ActionResultType fit = decider.isInZone(left, top); - if (fit == ActionResultType.FAIL) - return false; - ActionResultType fit2 = decider.isInZone(left + 18, top + 18); - if (fit2 == ActionResultType.FAIL) - return false; - if (fit == ActionResultType.SUCCESS && fit2 == ActionResultType.SUCCESS) - return true; + ActionResultType fit = canItemSlotWidgetFit(left, top, width, height, decider); + if (fit != ActionResultType.PASS) + return fit == ActionResultType.SUCCESS; } return true; } + private static ActionResultType canItemSlotWidgetFit(int left, int top, int width, int height, OverlayDecider decider) { + ActionResultType fit; + fit = decider.isInZone(left, top); + if (fit != ActionResultType.PASS) + return fit; + fit = decider.isInZone(left + width, top); + if (fit != ActionResultType.PASS) + return fit; + fit = decider.isInZone(left, top + height); + if (fit != ActionResultType.PASS) + return fit; + fit = decider.isInZone(left + width, top + height); + return fit; + } + private static Rectangle updateInnerBounds(Rectangle bounds) { + int entrySize = entrySize(); if (ConfigObject.getInstance().isEntryListWidgetScrolled()) { - int width = Math.max(MathHelper.floor((bounds.width - 2 - 6) / (float) entrySize()), 1); + int width = Math.max(MathHelper.floor((bounds.width - 2 - 6) / (float) entrySize), 1); if (ConfigObject.getInstance().isLeftHandSidePanel()) - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize() / 2f) + 3), bounds.y, width * entrySize(), bounds.height); - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize() / 2f) - 3), bounds.y, width * entrySize(), bounds.height); + return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f) + 3), bounds.y, width * entrySize, bounds.height); + return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f) - 3), bounds.y, width * entrySize, bounds.height); } - int width = Math.max(MathHelper.floor((bounds.width - 2) / (float) entrySize()), 1); - int height = Math.max(MathHelper.floor((bounds.height - 2) / (float) entrySize()), 1); - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize() / 2f)), (int) (bounds.getCenterY() - height * (entrySize() / 2f)), width * entrySize(), height * entrySize()); + int width = Math.max(MathHelper.floor((bounds.width - 2) / (float) entrySize), 1); + int height = Math.max(MathHelper.floor((bounds.height - 2) / (float) entrySize), 1); + return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f)), (int) (bounds.getCenterY() - height * (entrySize / 2f)), width * entrySize, height * entrySize); } @Override @@ -234,9 +245,11 @@ public class EntryListWidget extends WidgetWithBounds { blockedCount = 0; Stream<EntryListEntry> entryStream = this.entries.stream().skip(nextIndex).filter(entry -> { - entry.getBounds().y = (int) (entry.backupY - scrolling.scrollAmount); - if (entry.getBounds().y > bounds.getMaxY()) return false; - if (notSteppingOnExclusionZones(entry.getBounds().x, entry.getBounds().y, innerBounds)) { + Rectangle entryBounds = entry.getBounds(); + + entryBounds.y = (int) (entry.backupY - scrolling.scrollAmount); + if (entryBounds.y > this.bounds.getMaxY()) return false; + if (notSteppingOnExclusionZones(entryBounds.x, entryBounds.y, entryBounds.width, entryBounds.height, innerBounds)) { EntryStack stack = allStacks.get(i[0]++); if (!stack.isEmpty()) { entry.entry(stack); @@ -368,17 +381,20 @@ public class EntryListWidget extends WidgetWithBounds { } public void updateEntriesPosition() { + int entrySize = entrySize(); this.innerBounds = updateInnerBounds(bounds); if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { this.renders = Lists.newArrayList(); page = Math.max(page, 0); List<EntryListEntry> entries = Lists.newArrayList(); - int width = innerBounds.width / entrySize(); - int height = innerBounds.height / entrySize(); + int width = innerBounds.width / entrySize; + int height = innerBounds.height / entrySize; for (int currentY = 0; currentY < height; currentY++) { for (int currentX = 0; currentX < width; currentX++) { - if (notSteppingOnExclusionZones(currentX * entrySize() + innerBounds.x, currentY * entrySize() + innerBounds.y, innerBounds)) { - entries.add((EntryListEntry) new EntryListEntry(currentX * entrySize() + innerBounds.x, currentY * entrySize() + innerBounds.y).noBackground()); + int slotX = currentX * entrySize + innerBounds.x; + int slotY = currentY * entrySize + innerBounds.y; + if (notSteppingOnExclusionZones(slotX - 1, slotY - 1, entrySize, entrySize, innerBounds)) { + entries.add((EntryListEntry) new EntryListEntry(slotX, slotY, entrySize).noBackground()); } } } @@ -393,16 +409,16 @@ public class EntryListWidget extends WidgetWithBounds { this.widgets.addAll(entries); } else { |
