Skip to content

Commit

Permalink
Make it so that installed stone generator upgrades and remaining dict…
Browse files Browse the repository at this point in the history
…ionary dropdowns fit within the gui in english without resorting to having to scroll
  • Loading branch information
pupnewfster committed Sep 28, 2024
1 parent 0d1d299 commit 50a38e8
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 195 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ private void addMisc() {
add(MekanismLang.DICTIONARY_MOB_EFFECT_DESC, "Display Mob Effect Tags");
add(MekanismLang.DICTIONARY_ENCHANTMENT, "Enchantment");
add(MekanismLang.DICTIONARY_ENCHANTMENT_DESC, "Display Enchantment Tags");
add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE, "Block Entity Type");
add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE, "BE Type");
add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE_DESC, "Display Block Entity Type Tags");
add(MekanismLang.DICTIONARY_CHEMICAL, "Chemical");
add(MekanismLang.DICTIONARY_CHEMICAL_DESC, "Display Chemical Tags");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void validate() {
for (RecipeMethod method : methods) {
if (!method.hasExample) {
StringBuilder signature = new StringBuilder(method.methodName);
signature.append("(");
signature.append('(');
method.appendParameters(signature, (sb, name, type, generic) -> {
sb.append(type.getSimpleName())
.append(' ')
Expand All @@ -285,7 +285,7 @@ private void validate() {
.append('>');
}
});
signature.append(")");
signature.append(')');
throw new RuntimeException("Recipe method: '" + signature + "' has no example usage declared.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class GuiSupportedUpgrades extends GuiElement {

private static final Component SUPPORTED = MekanismLang.UPGRADES_SUPPORTED.translate();
private static final int ELEMENT_WIDTH = 125;
private static final int ELEMENT_WIDTH = 167;
private static final int PADDED_ELEMENT_WIDTH = ELEMENT_WIDTH - 2;
private static final int ELEMENT_SIZE = 12;
private static final int ROW_ROOM = PADDED_ELEMENT_WIDTH / ELEMENT_SIZE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package mekanism.client.gui.element.scroll;

import java.util.List;
import mekanism.api.text.EnumColor;
import mekanism.client.gui.IGuiWrapper;
import mekanism.client.render.MekanismRenderer;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class GuiInstallableScrollList<TYPE> extends GuiScrollList {

private final ResourceLocation texture;
private final int textureWidth;
private final int textureHeight;
@Nullable
protected TYPE selectedType;
@Nullable
protected ScreenRectangle cachedTooltipRect;

protected GuiInstallableScrollList(IGuiWrapper gui, int x, int y, int height, ResourceLocation background, int backgroundSideSize,
ResourceLocation texture, int textureWidth, int textureHeight) {
super(gui, x, y, textureWidth + 8, height, textureHeight / 3, background, backgroundSideSize);
this.texture = texture;
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
}

protected abstract List<TYPE> getCurrentInstalled();

protected abstract void drawName(GuiGraphics guiGraphics, TYPE type, int multipliedElement);

protected abstract ItemStack getRenderStack(TYPE type);

@Nullable
public TYPE getSelection() {
return selectedType;
}

@Override
public boolean hasSelection() {
return selectedType != null;
}

@Override
protected int getMaxElements() {
return getCurrentInstalled().size();
}

@Override
protected void setSelected(int index) {
if (index >= 0) {
List<TYPE> currentInstalled = getCurrentInstalled();
if (index < currentInstalled.size()) {
setSelected(currentInstalled.get(index));
}
}
}

protected abstract void setSelected(TYPE newType);

@Override
public void clearSelection() {
setSelected(null);
}

@Override
public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) {
super.renderForeground(guiGraphics, mouseX, mouseY);
int currentSelection = getCurrentSelection();
List<TYPE> currentInstalled = getCurrentInstalled();
int max = Math.min(getFocusedElements(), currentInstalled.size());
for (int i = 0; i < max; i++) {
drawName(guiGraphics, currentInstalled.get(currentSelection + i), 3 + i * elementHeight);
}
}

protected void drawNameText(GuiGraphics guiGraphics, int y, Component name, int color, float scale) {
drawScaledScrollingString(guiGraphics, name, 13, y, TextAlignment.LEFT, color, barXShift - 16, 0, false, scale);
}

@NotNull
@Override
protected ScreenRectangle getTooltipRectangle(int mouseX, int mouseY) {
return cachedTooltipRect == null ? super.getTooltipRectangle(mouseX, mouseY) : cachedTooltipRect;
}

@Nullable
protected EnumColor getColor(TYPE type) {
return null;
}

@Override
public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
//Draw elements
List<TYPE> currentInstalled = getCurrentInstalled();
int currentSelection = getCurrentSelection();
int max = Math.min(getFocusedElements(), currentInstalled.size());
for (int i = 0; i < max; i++) {
TYPE type = currentInstalled.get(currentSelection + i);
int multipliedElement = i * elementHeight;
int shiftedY = getY() + 1 + multipliedElement;
int j = 1;
if (type == getSelection()) {
j = 2;
} else if (mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1 && mouseY >= shiftedY && mouseY < shiftedY + elementHeight) {
j = 0;
}
EnumColor color = getColor(type);
if (color != null) {
MekanismRenderer.color(guiGraphics, color);
}
guiGraphics.blit(texture, relativeX + 1, relativeY + 1 + multipliedElement, 0, elementHeight * j, textureWidth,
elementHeight, textureWidth, textureHeight);
if (color != null) {
MekanismRenderer.resetColor(guiGraphics);
}
}
//Note: This needs to be in its own loop as rendering the items is likely to cause the texture manager to be bound to a different texture
// and thus would make the selection area background get all screwed up
for (int i = 0; i < max; i++) {
TYPE type = currentInstalled.get(currentSelection + i);
gui().renderItem(guiGraphics, getRenderStack(type), relativeX + 3, relativeY + 3 + i * elementHeight, 0.5F);
}
}
}
Loading

0 comments on commit 50a38e8

Please sign in to comment.