Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Jan 13, 2024
1 parent 28c6c85 commit a3a3217
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private boolean tryNavigating(Element element, NavigationDirection direction, bo
@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
ScissorManager.pushScaleFactor(this.scaleFactor);
this.renderBackground(graphics, mouseX, mouseY, delta);
this.renderBackground(graphics);
this.renderWidgets(graphics, mouseX, mouseY, delta);
this.renderTitle(graphics, mouseX, mouseY, delta);
Tooltip.renderAll(graphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.gui.widget.ClickableWidgetStateTextures;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
Expand All @@ -41,14 +40,6 @@ public abstract class AbstractSpruceButtonWidget extends AbstractSpruceWidget im
private long lastTick;
protected float alpha = 1.f;

/**
* @see net.minecraft.client.gui.widget.PressableWidget#TEXTURES
*/
protected static final ClickableWidgetStateTextures
BUTTON_TEXTURES = new ClickableWidgetStateTextures(
new Identifier("widget/button"), new Identifier("widget/button_disabled"), new Identifier("widget/button_highlighted")
);

public AbstractSpruceButtonWidget(Position position, int width, int height, Text message) {
super(position);
this.width = width;
Expand Down Expand Up @@ -140,8 +131,10 @@ protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY

/* Rendering */

protected Identifier getTexture() {
return BUTTON_TEXTURES.getTexture(this.isActive(), this.isFocusedOrHovered());
protected int getVOffset() {
if (!this.isActive())
return 0;
return this.isFocusedOrHovered() ? 2 : 1;
}

@Override
Expand All @@ -165,7 +158,43 @@ protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, fl
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
graphics.drawGuiTexture(this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight());
int v = 46 + this.getVOffset() * 20;
if (this.getWidth() / 2 < 200) {
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX(), this.getY(),
0, v,
this.getWidth() / 2, this.getHeight());
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX() + this.getWidth() / 2, this.getY(),
200 - this.getWidth() / 2, v,
this.getWidth() / 2, this.getHeight());
} else {
int middleWidth = this.getWidth() - 100;
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX(), this.getY(),
0, v,
50, this.getHeight());

int x;
for (x = 50; x < middleWidth; x += 100) {
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX() + x, this.getY(),
50, v,
100, this.getHeight());
}

if (x - middleWidth > 0) {
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX() + x, this.getY(),
50, v,
x - middleWidth, this.getHeight());
}

graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE,
this.getX() + this.getWidth() - 50, this.getY(),
150, v,
50, this.getHeight());
}
}

/* Narration */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ protected boolean onMouseDrag(double mouseX, double mouseY, int button, double d
return false;
}

public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
if (this.isActive() && this.isVisible() && this.isMouseOver(mouseX, mouseY)) {
return this.onMouseScroll(mouseX, mouseY, scrollX, scrollY);
return this.onMouseScroll(mouseX, mouseY, amount);
}
return false;
}

protected boolean onMouseScroll(double mouseX, double mouseY, double scrollX, double scrollY) {
protected boolean onMouseScroll(double mouseX, double mouseY, double amount) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -165,16 +166,17 @@ private void setValueFromMouse(double mouseX) {
/* Rendering */

@Override
protected Identifier getTexture() {
return SLIDER;
protected int getVOffset() {
return 0;
}

@Override
protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f);

final Identifier texture = this.isFocusedOrHovered() ? SLIDER_HANDLE_HIGHLIGHTED : SLIDER_HANDLE;
graphics.drawGuiTexture(texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20);
RenderSystem.setShaderTexture(0, ClickableWidget.WIDGETS_TEXTURE);
int vOffset = (this.isFocusedOrHovered() ? 2 : 1) * 20;
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 0, 46 + vOffset, 4, 20);
graphics.drawTexture(ClickableWidget.WIDGETS_TEXTURE, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)) + 4, this.getY(), 196, 46 + vOffset, 4, 20);

if (!this.isMouseHovered() && this.inUse) {
this.inUse = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected boolean onMouseDrag(double mouseX, double mouseY, int button, double d
}

@Override
protected boolean onMouseScroll(double mouseX, double mouseY, double scrollX, double scrollY) {
return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseScrolled(mouseX, mouseY, scrollX, scrollY)).isPresent();
protected boolean onMouseScroll(double mouseX, double mouseY, double amount) {
return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseScrolled(mouseX, mouseY, amount)).isPresent();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ else if (button == GLFW.GLFW_MOUSE_BUTTON_1 && this.scrolling) {
}

@Override
protected boolean onMouseScroll(double mouseX, double mouseY, double scrollX, double scrollY) {
if (super.onMouseScroll(mouseX, mouseY, scrollX, scrollY)) return true;
this.setScrollAmount(this.getScrollAmount() - scrollY * ((double) this.getMaxPosition() / this.getEntriesCount()) / 2);
protected boolean onMouseScroll(double mouseX, double mouseY, double amount) {
if (super.onMouseScroll(mouseX, mouseY, amount)) return true;
this.setScrollAmount(this.getScrollAmount() - amount * ((double) this.getMaxPosition() / this.getEntriesCount()) / 2);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ protected boolean onMouseDrag(double mouseX, double mouseY, int button, double d
}

@Override
protected boolean onMouseScroll(double mouseX, double mouseY, double scrollX, double scrollY) {
return this.getTextFieldWidget().mouseScrolled(mouseX, mouseY, scrollX, scrollY);
protected boolean onMouseScroll(double mouseX, double mouseY, double amount) {
return this.getTextFieldWidget().mouseScrolled(mouseX, mouseY, amount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ protected boolean onMouseClick(double mouseX, double mouseY, int button) {
}

@Override
protected boolean onMouseScroll(double mouseX, double mouseY, double scrollX, double scrollY) {
protected boolean onMouseScroll(double mouseX, double mouseY, double amount) {
if (!this.isEditorActive()) {
return false;
}

if (scrollY > 0.) {
if (amount > 0.) {
this.cursor.moveUp();
} else {
this.cursor.moveDown();
Expand Down

0 comments on commit a3a3217

Please sign in to comment.