Skip to content

Commit adcfb43

Browse files
committed
added zooming when scrolling with control held down, implements #1
1 parent 8668393 commit adcfb43

File tree

8 files changed

+62
-37
lines changed

8 files changed

+62
-37
lines changed

Common/src/main/java/betteradvancements/common/gui/BetterAdvancementTab.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void drawIcon(GuiGraphics guiGraphics, int left, int top,int width, int h
7272
this.type.drawIcon(guiGraphics, left, top, width, height, this.index, this.icon);
7373
}
7474

75-
public void drawContents(GuiGraphics guiGraphics, int left, int top, int width, int height) {
75+
public void drawContents(GuiGraphics guiGraphics, int left, int top, int width, int height, float zoom) {
7676
if (!this.centered) {
7777
this.scrollX = (width - (this.maxX + this.minX)) / 2;
7878
this.scrollY = (height - (this.maxY + this.minY)) / 2;
@@ -96,25 +96,25 @@ public void drawContents(GuiGraphics guiGraphics, int left, int top, int width,
9696
guiGraphics.blit(RenderType::guiTextured, resourcelocation, i + 16 * k, j + 16 * l, 0.0F, 0.0F, 16, height % 16, 16, 16);
9797
}
9898

99-
99+
guiGraphics.pose().scale(zoom, zoom, 1F);
100100
this.root.drawConnectivity(guiGraphics, this.scrollX, this.scrollY, true);
101101
this.root.drawConnectivity(guiGraphics, this.scrollX, this.scrollY, false);
102102
this.root.draw(guiGraphics, this.scrollX, this.scrollY);
103103
guiGraphics.pose().popPose();
104104
guiGraphics.disableScissor();
105105
}
106106

107-
public void drawToolTips(GuiGraphics guiGraphics, int mouseX, int mouseY, int left, int top, int width, int height) {
107+
public void drawToolTips(GuiGraphics guiGraphics, int mouseX, int mouseY, int left, int top, int width, int height, float zoom) {
108108
guiGraphics.pose().pushPose();
109109
guiGraphics.pose().translate(0.0D, 0.0D, -200.0D);
110110
guiGraphics.fill(0, 0, width, height, Mth.floor(this.fade * 255.0F) << 24);
111111
boolean flag = false;
112112

113113
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
114114
for (BetterAdvancementWidget betterAdvancementWidget : this.widgets.values()) {
115-
if (betterAdvancementWidget.isMouseOver(this.scrollX, this.scrollY, mouseX, mouseY)) {
115+
if (betterAdvancementWidget.isMouseOver(this.scrollX, this.scrollY, mouseX, mouseY, zoom)) {
116116
flag = true;
117-
betterAdvancementWidget.drawHover(guiGraphics, this.scrollX, this.scrollY, this.fade, left, top);
117+
betterAdvancementWidget.drawHover(guiGraphics, this.scrollX, this.scrollY, this.fade, left, top, zoom);
118118
break;
119119
}
120120
}

Common/src/main/java/betteradvancements/common/gui/BetterAdvancementWidget.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,25 @@ public void addGuiAdvancement(BetterAdvancementWidget betterAdvancementEntryScre
247247
this.children.add(betterAdvancementEntryScreen);
248248
}
249249

250-
public void drawHover(GuiGraphics guiGraphics, int scrollX, int scrollY, float fade, int left, int top) {
250+
public void drawHover(GuiGraphics guiGraphics, int scrollX, int scrollY, float fade, int left, int top, float zoom) {
251251
this.refreshHover();
252-
boolean drawLeft = left + scrollX + this.x + this.width + ADVANCEMENT_SIZE >= this.betterAdvancementTabGui.getScreen().internalWidth;
252+
float scaled_scrolled_x = (scrollX + this.x) * zoom;
253+
float scaled_scrolled_y = (scrollY + this.y) * zoom;
254+
boolean drawLeft = left + scaled_scrolled_x + this.width + ADVANCEMENT_SIZE >= this.betterAdvancementTabGui.getScreen().internalWidth;
253255
String s = this.advancementProgress == null || this.advancementProgress.getProgressText() == null ? null : this.advancementProgress.getProgressText().getString();
254256
int i = s == null ? 0 : this.minecraft.font.width(s);
255257
boolean drawTop;
256258

257259
if (!CriterionGrid.requiresShift || Screen.hasShiftDown()) {
258260
if (this.criterionGrid.height < this.betterAdvancementTabGui.getScreen().height) {
259-
drawTop = top + scrollY + this.y + this.description.size() * this.minecraft.font.lineHeight + this.criterionGrid.height + 50 >= this.betterAdvancementTabGui.getScreen().height;
261+
drawTop = top + scaled_scrolled_y + this.description.size() * this.minecraft.font.lineHeight + this.criterionGrid.height + 50 >= this.betterAdvancementTabGui.getScreen().height;
260262
} else {
261263
// Always draw on the bottom if the grid is larger than the screen
262264
drawTop = false;
263265
}
264266
}
265267
else {
266-
drawTop = top + scrollY + this.y + this.description.size() * this.minecraft.font.lineHeight + 50 >= this.betterAdvancementTabGui.getScreen().height;
268+
drawTop = top + scaled_scrolled_y + this.description.size() * this.minecraft.font.lineHeight + 50 >= this.betterAdvancementTabGui.getScreen().height;
267269
}
268270

269271
float percentageObtained = this.advancementProgress == null ? 0.0F : this.advancementProgress.getPercent();
@@ -295,13 +297,15 @@ public void drawHover(GuiGraphics guiGraphics, int scrollX, int scrollY, float f
295297

296298
int k = this.width - j;
297299
RenderSystem.enableBlend();
298-
int drawY = scrollY + this.y;
300+
int rounded_scaled_scrolled_x = Math.round(scaled_scrolled_x);
301+
int rounded_scaled_scrolled_y = Math.round(scaled_scrolled_y);
302+
int drawY = rounded_scaled_scrolled_y;
299303
int drawX;
300304

301305
if (drawLeft) {
302-
drawX = scrollX + this.x - this.width + ADVANCEMENT_SIZE + 6;
306+
drawX = rounded_scaled_scrolled_x - this.width + ADVANCEMENT_SIZE + 6;
303307
} else {
304-
drawX = scrollX + this.x;
308+
drawX = rounded_scaled_scrolled_x;
305309
}
306310
int boxHeight;
307311

@@ -337,28 +341,28 @@ public void drawHover(GuiGraphics guiGraphics, int scrollX, int scrollY, float f
337341
}
338342
// Advancement icon
339343
RenderUtil.setColor(betterDisplayInfo.getIconColor(stateIcon));
340-
guiGraphics.blitSprite(RenderType::guiTextured, stateIcon.frameSprite(this.displayInfo.getType()), scrollX + this.x + 3, scrollY + this.y, ICON_SIZE, ICON_SIZE);
344+
guiGraphics.blitSprite(RenderType::guiTextured, stateIcon.frameSprite(this.displayInfo.getType()), rounded_scaled_scrolled_x + 3, rounded_scaled_scrolled_y, ICON_SIZE, ICON_SIZE);
341345
RenderUtil.setColor(betterDisplayInfo.defaultIconColor());
342346

343347
if (drawLeft) {
344-
guiGraphics.drawString(this.minecraft.font, this.title, drawX + 5, scrollY + this.y + 9, -1);
348+
guiGraphics.drawString(this.minecraft.font, this.title, drawX + 5, rounded_scaled_scrolled_y + 9, -1);
345349

346350
if (s != null) {
347-
guiGraphics.drawString(this.minecraft.font, s, scrollX + this.x - i, scrollY + this.y + 9, -1);
351+
guiGraphics.drawString(this.minecraft.font, s, rounded_scaled_scrolled_x - i, rounded_scaled_scrolled_y + 9, -1);
348352
}
349353
} else {
350-
guiGraphics.drawString(this.minecraft.font, this.title, scrollX + this.x + 32, scrollY + this.y + 9, -1);
354+
guiGraphics.drawString(this.minecraft.font, this.title, rounded_scaled_scrolled_x + 32, rounded_scaled_scrolled_y + 9, -1);
351355

352356
if (s != null) {
353-
guiGraphics.drawString(this.minecraft.font, s, scrollX + this.x + this.width - i - 5, scrollY + this.y + 9, -1);
357+
guiGraphics.drawString(this.minecraft.font, s, rounded_scaled_scrolled_x + this.width - i - 5, rounded_scaled_scrolled_y + 9, -1);
354358
}
355359
}
356360

357361
int yOffset;
358362
if (drawTop) {
359363
yOffset = drawY + 26 - boxHeight + 7;
360364
} else {
361-
yOffset = scrollY + this.y + 9 + 17;
365+
yOffset = rounded_scaled_scrolled_y + 9 + 17;
362366
}
363367
for (int k1 = 0; k1 < this.description.size(); ++k1) {
364368
guiGraphics.drawString(this.minecraft.font, this.description.get(k1), drawX + 5, yOffset + k1 * this.minecraft.font.lineHeight, -5592406, false);
@@ -375,7 +379,7 @@ public void drawHover(GuiGraphics guiGraphics, int scrollX, int scrollY, float f
375379
}
376380
}
377381

378-
guiGraphics.renderFakeItem(this.displayInfo.getIcon(), scrollX + this.x + 8, scrollY + this.y + 5);
382+
guiGraphics.renderFakeItem(this.displayInfo.getIcon(), rounded_scaled_scrolled_x + 8, rounded_scaled_scrolled_y + 5);
379383
}
380384

381385
protected void render9Sprite(GuiGraphics guiGraphics, int x, int y, int width, int height, int textureHeight, int textureWidth, int textureDistance, int textureX, int textureY) {
@@ -399,13 +403,13 @@ protected void render9Sprite(GuiGraphics guiGraphics, int x, int y, int width, i
399403
RenderUtil.renderRepeating(Resources.Gui.WIDGETS, guiGraphics, x + width - textureHeight, y + textureHeight, textureHeight, height - textureHeight - textureHeight, textureX + textureWidth - textureHeight, textureY + textureHeight, textureWidth, textureDistance - textureHeight - textureHeight);
400404
}
401405

402-
public boolean isMouseOver(double scrollX, double scrollY, double mouseX, double mouseY) {
406+
public boolean isMouseOver(double scrollX, double scrollY, double mouseX, double mouseY, float zoom) {
403407
if (!this.displayInfo.isHidden() || this.advancementProgress != null && this.advancementProgress.isDone()) {
404408
double left = scrollX + this.x;
405409
double right = left + ADVANCEMENT_SIZE;
406410
double top = scrollY + this.y;
407411
double bottom = top + ADVANCEMENT_SIZE;
408-
return mouseX >= left && mouseX <= right && mouseY >= top && mouseY <= bottom;
412+
return mouseX >= left * zoom && mouseX <= right * zoom && mouseY >= top * zoom && mouseY <= bottom * zoom;
409413
} else {
410414
return false;
411415
}

Common/src/main/java/betteradvancements/common/gui/BetterAdvancementsScreen.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public class BetterAdvancementsScreen extends Screen implements ClientAdvancemen
2727
private static final Component TITLE =Component.translatable("gui.advancements");
2828
private static final int WIDTH = 252, HEIGHT = 140, CORNER_SIZE = 30;
2929
private static final int SIDE = 30, TOP = 40, BOTTOM = 30, PADDING = 9;
30-
private static final float MIN_ZOOM = 1, MAX_ZOOM = 2, ZOOM_STEP = 0.2F;
30+
public static final float MIN_ZOOM = 0.4F, MAX_ZOOM = 1.6F, ZOOM_STEP = 0.1F;
3131
private final ClientAdvancements clientAdvancements;
3232
private final Map<AdvancementHolder, BetterAdvancementTab> tabs = Maps.newLinkedHashMap();
3333
private BetterAdvancementTab selectedTab;
3434
private static int tabPage, maxPages;
35-
private float zoom = MIN_ZOOM;
35+
public static float zoom = 1.0F;
3636
private boolean isScrolling;
3737
protected int internalWidth, internalHeight;
3838
public static int uiScaling = 100;
@@ -126,7 +126,12 @@ public boolean mouseClicked(double mouseX, double mouseY, int modifiers) {
126126
@Override
127127
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
128128
if (this.selectedTab != null) {
129-
this.selectedTab.scroll(scrollX * 16.0, scrollY * 16.0, width, height);
129+
if (Screen.hasControlDown()) {
130+
zoom += scrollY > 0 ? ZOOM_STEP : -ZOOM_STEP;
131+
zoom = Math.max(MIN_ZOOM, Math.min(zoom, MAX_ZOOM));
132+
} else {
133+
this.selectedTab.scroll(scrollX * 16.0, scrollY * 16.0, width, height);
134+
}
130135
return true;
131136
} else {
132137
return false;
@@ -159,7 +164,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double mou
159164
boolean inGui = mouseX < left + internalWidth - 2*SIDE - PADDING && mouseX > left + PADDING && mouseY < top + internalHeight - TOP + 1 && mouseY > top + 2*PADDING;
160165
if (this.selectedTab != null && inGui) {
161166
for (BetterAdvancementWidget betterAdvancementEntryScreen : this.selectedTab.widgets.values()) {
162-
if (betterAdvancementEntryScreen.isMouseOver(this.selectedTab.scrollX, this.selectedTab.scrollY, mouseX - left - PADDING, mouseY - top - 2*PADDING)) {
167+
if (betterAdvancementEntryScreen.isMouseOver(this.selectedTab.scrollX, this.selectedTab.scrollY, mouseX - left - PADDING, mouseY - top - 2*PADDING, zoom)) {
163168

164169
if (betterAdvancementEntryScreen.betterDisplayInfo.allowDragging())
165170
{
@@ -383,7 +388,7 @@ private void renderInside(GuiGraphics guiGraphics, int mouseX, int mouseY, int l
383388
guiGraphics.drawString(this.font, NO_ADVANCEMENTS_LABEL, boxLeft + (width - this.font.width(NO_ADVANCEMENTS_LABEL)) / 2, boxTop + height / 2 - this.font.lineHeight, -1);
384389
guiGraphics.drawString(this.font, VERY_SAD_LABEL, boxLeft + (width - this.font.width(VERY_SAD_LABEL)) / 2, boxTop + height / 2 + this.font.lineHeight, -1);
385390
} else {
386-
betterAdvancementTab.drawContents(guiGraphics, boxLeft, boxTop, width, height);
391+
betterAdvancementTab.drawContents(guiGraphics, boxLeft, boxTop, width, height, zoom);
387392
}
388393
}
389394

@@ -441,7 +446,7 @@ private void renderToolTips(GuiGraphics guiGraphics, int mouseX, int mouseY, int
441446
guiGraphics.pose().pushPose();
442447
guiGraphics.pose().translate(left + PADDING, top + 2*PADDING, 400.0D);
443448
RenderSystem.enableDepthTest();
444-
this.selectedTab.drawToolTips(guiGraphics,mouseX - left - PADDING, mouseY - top - 2*PADDING, left, top, right - left - 2*PADDING, bottom - top - 3*PADDING);
449+
this.selectedTab.drawToolTips(guiGraphics,mouseX - left - PADDING, mouseY - top - 2*PADDING, left, top, right - left - 2*PADDING, bottom - top - 3*PADDING, zoom);
445450
RenderSystem.disableDepthTest();
446451
guiGraphics.pose().popPose();
447452
}

Fabric/src/main/java/betteradvancements/fabric/config/ConfigFileHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public static void readFromConfig() {
5757
if (root.has("uiScaling")) {
5858
BetterAdvancementsScreen.uiScaling = root.get("uiScaling").getAsInt();
5959
}
60+
if (root.has("defaultZoom")) {
61+
BetterAdvancementsScreen.zoom = root.get("defaultZoom").getAsFloat();
62+
}
6063
if (root.has("criteriaDetail")) {
6164
CriterionGrid.detailLevel = CriteriaDetail.fromName(root.get("criteriaDetail").getAsString());
6265
}
@@ -94,6 +97,7 @@ public static void writeToConfig() {
9497
root.addProperty("showDebugCoordinates", BetterAdvancementsScreen.showDebugCoordinates);
9598
root.addProperty("orderTabsAlphabetically", BetterAdvancementsScreen.orderTabsAlphabetically);
9699
root.addProperty("uiScaling", BetterAdvancementsScreen.uiScaling);
100+
root.addProperty("defaultZoom", BetterAdvancementsScreen.zoom);
97101
root.addProperty("criteriaDetail", CriterionGrid.detailLevel.getName());
98102
root.addProperty("criteriaDetailRequiresShift", CriterionGrid.requiresShift);
99103
root.addProperty("addInventoryButton", BetterAdvancementsScreenButton.addToInventory);

Fabric/src/main/java/betteradvancements/fabric/config/ConfigValues.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import betteradvancements.common.util.CriterionGrid;
1111
import me.shedaniel.clothconfig2.api.ConfigCategory;
1212
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
13-
import me.shedaniel.clothconfig2.gui.entries.BooleanListEntry;
14-
import me.shedaniel.clothconfig2.gui.entries.ColorEntry;
15-
import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry;
16-
import me.shedaniel.clothconfig2.gui.entries.IntegerSliderEntry;
13+
import me.shedaniel.clothconfig2.gui.entries.*;
1714
import net.minecraft.network.chat.Component;
1815

1916
public class ConfigValues {
@@ -27,6 +24,7 @@ public class ConfigValues {
2724
public static BooleanListEntry showDebugCoordinates;
2825
public static BooleanListEntry orderTabsAlphabetically;
2926
public static IntegerSliderEntry uiScaling;
27+
public static FloatListEntry defaultZoom;
3028

3129
public static DropdownBoxEntry<CriteriaDetail> detailLevel;
3230
public static BooleanListEntry requiresShift;
@@ -82,6 +80,14 @@ public static void build(ConfigCategory category, ConfigEntryBuilder builder) {
8280
.setSaveConsumer(newValue -> BetterAdvancementsScreen.uiScaling = newValue)
8381
.build();
8482
category.addEntry(uiScaling);
83+
defaultZoom = builder.startFloatField(Component.literal("defaultZoom"), BetterAdvancementsScreen.zoom)
84+
.setTooltip(Component.literal("UI zoom steps are 0.1"))
85+
.setDefaultValue(1F)
86+
.setMin(BetterAdvancementsScreen.MIN_ZOOM)
87+
.setMax(BetterAdvancementsScreen.MAX_ZOOM)
88+
.setSaveConsumer(newValue -> BetterAdvancementsScreen.zoom = newValue)
89+
.build();
90+
category.addEntry(defaultZoom);
8591

8692
detailLevel = builder.startDropdownMenu(Component.literal("criteriaDetail"),
8793
CriterionGrid.detailLevel, CriteriaDetail::fromName, o -> (Component.literal(o.getName()))

Forge/src/main/java/betteradvancements/forge/config/ConfigValues.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ConfigValues {
2121
public static ForgeConfigSpec.BooleanValue showDebugCoordinates;
2222
public static ForgeConfigSpec.BooleanValue orderTabsAlphabetically;
2323
public static ForgeConfigSpec.IntValue uiScaling;
24+
public static ForgeConfigSpec.FloatValue defaultZoom;
2425

2526
public static ForgeConfigSpec.ConfigValue<String> detailLevel;
2627
public static ForgeConfigSpec.BooleanValue requiresShift;
@@ -45,6 +46,7 @@ public static ForgeConfigSpec build() {
4546
showDebugCoordinates = builder.define("showDebugCoordinates", false);
4647
orderTabsAlphabetically = builder.define("orderTabsAlphabetically", false);
4748
uiScaling = builder.comment("Values below 50% might give odd results, use on own risk ;)").defineInRange("uiScaling", 100, 1, 100);
49+
defaultZoom = builder.comment("UI zoom steps are 0.1").defineInRange("defaultZoom", 1F, 0.4F, 2F);
4850

4951
detailLevel = builder.comment(CriteriaDetail.comments()).defineInList("criteriaDetail", CriteriaDetail.DEFAULT.getName(), CriteriaDetail.names());
5052
requiresShift = builder.define("criteriaDetailRequiresShift", false);
@@ -70,6 +72,7 @@ public static void pushChanges() {
7072
BetterAdvancementsScreen.showDebugCoordinates = showDebugCoordinates.get();
7173
BetterAdvancementsScreen.orderTabsAlphabetically = orderTabsAlphabetically.get();
7274
BetterAdvancementsScreen.uiScaling = uiScaling.get();
75+
BetterAdvancementsScreen.zoom = defaultZoom.get();
7376

7477
CriterionGrid.detailLevel = CriteriaDetail.fromName(detailLevel.get());
7578
CriterionGrid.requiresShift = requiresShift.get();

NeoForge/src/main/java/betteradvancements/neoforge/config/ConfigValues.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ConfigValues {
2121
public static ModConfigSpec.BooleanValue showDebugCoordinates;
2222
public static ModConfigSpec.BooleanValue orderTabsAlphabetically;
2323
public static ModConfigSpec.IntValue uiScaling;
24+
public static ModConfigSpec.DoubleValue defaultZoom;
2425

2526
public static ModConfigSpec.ConfigValue<String> detailLevel;
2627
public static ModConfigSpec.BooleanValue requiresShift;
@@ -45,6 +46,7 @@ public static ModConfigSpec build() {
4546
showDebugCoordinates = builder.define("showDebugCoordinates", false);
4647
orderTabsAlphabetically = builder.define("orderTabsAlphabetically", false);
4748
uiScaling = builder.comment("Values below 50% might give odd results, use on own risk ;)").defineInRange("uiScaling", 100, 1, 100);
49+
defaultZoom = builder.comment("UI zoom steps are 0.1").defineInRange("defaultZoom", 1F, 0.4F, 2F);
4850

4951
detailLevel = builder.comment(CriteriaDetail.comments()).defineInList("criteriaDetail", CriteriaDetail.DEFAULT.getName(), CriteriaDetail.names());
5052
requiresShift = builder.define("criteriaDetailRequiresShift", false);
@@ -70,6 +72,7 @@ public static void pushChanges() {
7072
BetterAdvancementsScreen.showDebugCoordinates = showDebugCoordinates.get();
7173
BetterAdvancementsScreen.orderTabsAlphabetically = orderTabsAlphabetically.get();
7274
BetterAdvancementsScreen.uiScaling = uiScaling.get();
75+
BetterAdvancementsScreen.zoom = Math.round(defaultZoom.get());
7376

7477
CriterionGrid.detailLevel = CriteriaDetail.fromName(detailLevel.get());
7578
CriterionGrid.requiresShift = requiresShift.get();

0 commit comments

Comments
 (0)