Skip to content

Commit 4a1e04e

Browse files
committed
Refactor selection list rendering and lower opacity of hovered/selected GUI elements
1 parent 1bd3610 commit 4a1e04e

3 files changed

Lines changed: 27 additions & 28 deletions

File tree

‎src/main/java/com/chaosthedude/explorerscompass/gui/StructureSearchEntry.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,12 @@ public StructureSearchEntry(StructureSearchList structuresList, Identifier struc
5555

5656
@Override
5757
public void renderContent(GuiGraphics guiGraphics, int mouseX, int mouseY, boolean isHovering, float partialTick) {
58-
int maxTextWidth = getWidth() - 10;
59-
6058
if (xpLevels > 0) {
6159
int spriteSize = (int) (getHeight() * 0.4F);
6260
int spriteBorder = (getHeight() - spriteSize) / 2;
6361
int spriteIndex = xpLevels - 1;
6462
Identifier spriteId = isEnabled() ? ENABLED_LEVEL_SPRITES[spriteIndex] : DISABLED_LEVEL_SPRITES[spriteIndex];
6563
guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, spriteId, getX() + getWidth() - spriteSize - spriteBorder, getY() + spriteBorder, spriteSize, spriteSize);
66-
67-
// XP sprite is rendered, need extra room for it
68-
maxTextWidth = getWidth() - getHeight() - 5;
6964
}
7065

7166
int nameColor = isEnabled() ? 0xffffffff : 0xff808080;

‎src/main/java/com/chaosthedude/explorerscompass/gui/StructureSearchList.java‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ public class StructureSearchList extends ObjectSelectionList<StructureSearchEntr
1313

1414
private final ExplorersCompassScreen parentScreen;
1515
private Player player;
16-
private int itemHeight;
1716

1817
public StructureSearchList(ExplorersCompassScreen parentScreen, Minecraft mc, Player player, int width, int height, int y, int itemHeight) {
1918
super(mc, width, height, y, itemHeight);
2019
this.parentScreen = parentScreen;
2120
this.player = player;
22-
this.itemHeight = itemHeight;
2321
refreshList();
2422
}
2523

@@ -34,19 +32,33 @@ public int getRowWidth() {
3432
}
3533

3634
@Override
37-
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
38-
enableScissor(guiGraphics);
35+
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
36+
enableScissor(guiGraphics);
37+
renderListBackground(guiGraphics);
38+
renderListItems(guiGraphics, mouseX, mouseY, partialTicks);
39+
guiGraphics.disableScissor();
40+
renderScrollbar(guiGraphics, mouseX, mouseY);
41+
}
42+
43+
@Override
44+
protected void renderListBackground(GuiGraphics guiGraphics) {
3945
for (int i = 0; i < getItemCount(); ++i) {
4046
if (getRowBottom(i) >= getY() && getRowTop(i) <= getBottom()) {
4147
StructureSearchEntry entry = children().get(i);
4248
int fillColor = RenderUtils.getBackgroundColor(entry.isEnabled(), entry == getSelected());
43-
guiGraphics.fill(getRowLeft(), getRowTop(i), getRowLeft() + getRowWidth(), getRowTop(i) + itemHeight, fillColor);
44-
entry.renderContent(guiGraphics, mouseX, mouseY, entry == getHovered(), partialTicks);
49+
guiGraphics.fill(getRowLeft(), getRowTop(i), getRowLeft() + getRowWidth(), getRowTop(i) + defaultEntryHeight, fillColor);
4550
}
4651
}
47-
guiGraphics.disableScissor();
48-
49-
if (maxScrollAmount() > 0) {
52+
}
53+
54+
@Override
55+
protected void renderSelection(GuiGraphics guiGraphics, StructureSearchEntry entry, int backgroundColor) {
56+
// Selection is rendered in renderListBackground()
57+
}
58+
59+
@Override
60+
protected void renderScrollbar(GuiGraphics guiGraphics, int mouseX, int mouseY) {
61+
if (scrollbarVisible()) {
5062
int left = scrollBarX();
5163
int right = left + 6;
5264
int height = (int) ((float) ((getBottom() - getY()) * (getBottom() - getY())) / (float) contentHeight());
@@ -55,22 +67,14 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
5567
if (top < getY()) {
5668
top = getY();
5769
}
58-
59-
guiGraphics.fill(left, getY(), right, getBottom(), (int) (2.35F * 255.0F) / 2 << 24);
60-
guiGraphics.fill(left, top, right, top + height, (int) (1.9F * 255.0F) / 2 << 24);
70+
71+
int backgroundFillColor = RenderUtils.getBackgroundColor(false, false);
72+
int scrollbarFillColor = RenderUtils.getBackgroundColor(true, true);
73+
guiGraphics.fill(left, getY(), right, getBottom(), backgroundFillColor);
74+
guiGraphics.fill(left, top, right, top + height, scrollbarFillColor);
6175
}
6276
}
6377

64-
@Override
65-
protected void enableScissor(GuiGraphics guiGraphics) {
66-
guiGraphics.enableScissor(getX(), getY(), getRight(), getBottom());
67-
}
68-
69-
@Override
70-
public int getRowBottom(int index) {
71-
return getRowTop(index) + itemHeight;
72-
}
73-
7478
public void refreshList() {
7579
clearEntries();
7680
for (Identifier structureId : parentScreen.sortStructures()) {

‎src/main/java/com/chaosthedude/explorerscompass/util/RenderUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static int getBackgroundColor(boolean active, boolean hovered) {
3636
if (!active) {
3737
state = 5;
3838
} else if (hovered) {
39-
state = 4;
39+
state = 3;
4040
}
4141
final float f = state / 2 * 0.9F + 0.1F;
4242
final int color = (int) (255.0F * f);

0 commit comments

Comments
 (0)