Skip to content

Commit

Permalink
Integrate widget tooltips into respective widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
3TUSK committed Aug 27, 2024
1 parent c6bdc98 commit 544618a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/main/java/org/teacon/voteme/screen/CounterScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.font.TextFieldHelper;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -80,12 +81,17 @@ public CounterScreen(UUID artifactUUID, String artifactName, int inventoryIndex,
@Override
protected void init() {
Minecraft mc = Objects.requireNonNull(this.minecraft);
this.addRenderableWidget(new ImageButton(this.width / 2 - 99, this.height / 2 - 20, 18, 19, PREV_BUTTON_SPRITE, this::onPrevButtonClick));
this.addRenderableWidget(new ImageButton(this.width / 2 - 79, this.height / 2 - 20, 18, 19, NEXT_BUTTON_SPRITE, this::onNextButtonClick));
var prevCategoryButton = new ImageButton(this.width / 2 - 99, this.height / 2 - 20, 18, 19, PREV_BUTTON_SPRITE, this::onPrevButtonClick);
prevCategoryButton.setTooltip(Tooltip.create(Component.translatable("gui.voteme.counter.prev")));
this.addRenderableWidget(prevCategoryButton);
var nextCategoryButton = new ImageButton(this.width / 2 - 79, this.height / 2 - 20, 18, 19, NEXT_BUTTON_SPRITE, this::onNextButtonClick);
nextCategoryButton.setTooltip(Tooltip.create(Component.translatable("gui.voteme.counter.next")));
this.addRenderableWidget(nextCategoryButton);
this.okButton = this.addRenderableWidget(new BottomButton(this.width / 2 + 61, this.height / 2 + 77, this::onOKButtonClick, Component.translatable("gui.voteme.counter.ok")));
this.cancelButton = this.addRenderableWidget(new BottomButton(this.width / 2 + 61, this.height / 2 + 77, this::onCancelButtonClick, Component.translatable("gui.voteme.counter.cancel")));
this.renameButton = this.addRenderableWidget(new BottomButton(this.width / 2 + 19, this.height / 2 + 77, this::onRenameButtonClick, Component.translatable("gui.voteme.counter.rename")));
this.bottomSwitch = this.addRenderableWidget(new BottomSwitch(this.width / 2 - 98, this.height / 2 + 76, () -> this.enabledInfos.contains(this.infoCollection.iterator().next().id), this::onSwitchClick, Component.translatable("gui.voteme.counter.switch")));
this.bottomSwitch.setTooltip(Tooltip.create(Component.translatable("gui.voteme.counter.switch")));
this.artifactInput = new TextFieldHelper(() -> this.artifact, text -> this.artifact = text, TextFieldHelper.createClipboardGetter(mc), TextFieldHelper.createClipboardSetter(mc), text -> mc.font.width(text) * ARTIFACT_SCALE_FACTOR <= 199);
this.cancelButton.visible = this.renameButton.visible = this.bottomSwitch.visible = false;
}
Expand Down Expand Up @@ -171,12 +177,6 @@ private void onSwitchClick(Button button) {
private void drawTooltips(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
Minecraft mc = Objects.requireNonNull(this.minecraft);
int dx = mouseX - this.width / 2, dy = mouseY - this.height / 2;
if (dx >= -79 && dy >= -20 && dx < -61 && dy < -1) {
guiGraphics.renderTooltip(mc.font, Component.translatable("gui.voteme.counter.next"), mouseX, mouseY);
}
if (dx >= -99 && dy >= -20 && dx < -81 && dy < -1) {
guiGraphics.renderTooltip(mc.font, Component.translatable("gui.voteme.counter.prev"), mouseX, mouseY);
}
if (dx >= 73 && dy >= -19 && dx < 99 && dy < -2) {
List<Component> tooltipList = new ArrayList<>();
ShowCounterPacket.Info info = this.infoCollection.iterator().next();
Expand Down Expand Up @@ -206,9 +206,6 @@ private void drawTooltips(GuiGraphics guiGraphics, float partialTicks, int mouse
}
guiGraphics.renderComponentTooltip(mc.font, tooltipList, mouseX, mouseY);
}
if (dx >= -98 && dy >= 76 && dx < -61 && dy < 96) {
guiGraphics.renderTooltip(mc.font, Component.translatable("gui.voteme.counter.switch"), mouseX, mouseY);
}
}

@Override
Expand Down

0 comments on commit 544618a

Please sign in to comment.