Skip to content

Commit

Permalink
fix some gui
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jun 28, 2024
1 parent c0e9bc5 commit c360724
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/irtimaled/bbor/client/gui/AbstractSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.util.Identifier;

abstract class AbstractSlider extends AbstractControl {
private static final Identifier TEXTURE = Identifier.ofVanilla("widget/slider");
private static final Identifier HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_highlighted");
private static final Identifier HANDLE_TEXTURE = Identifier.ofVanilla("widget/slider_handle");
private static final Identifier HANDLE_HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_handle_highlighted");

private final int optionCount;
private final int total;
int position = 0;
Expand All @@ -16,12 +22,18 @@ abstract class AbstractSlider extends AbstractControl {
total = this.width - 8;
}

private Identifier getTexture() {
return this.isFocused() ? HIGHLIGHTED_TEXTURE : TEXTURE;
}

private Identifier getHandleTexture() {
return !this.hovered ? HANDLE_TEXTURE : HANDLE_HIGHLIGHTED_TEXTURE;
}

@Override
protected void renderBackground(DrawContext ctx) {
// this.minecraft.getTextureManager().bindTexture(WIDGETS_TEXTURE);
int hoverState = this.isSelected() ? 1 : 0;
// ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage(), this.getY(), 0, 46 + hoverState * 20, 4, this.height); FIX
// ctx.drawTexture(WIDGETS_TEXTURE, this.getX() + (int) getProgressPercentage() + 4, this.getY(), 196, 46 + hoverState * 20, 4, 20);
ctx.drawGuiTexture(this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight());
ctx.drawGuiTexture(this.getHandleTexture(), this.getX() + (int) getProgressPercentage(), this.getY(), 8, this.getHeight());
}

private double getProgressPercentage() {
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/com/irtimaled/bbor/client/gui/ControlList.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;

public class ControlList implements IControlSet {
private static final Identifier OPTIONS_BACKGROUND_TEXTURE = Identifier.tryParse("bbor:textures/gui/options_background.png");

public static final int CONTROLS_WIDTH = 310;
protected static final int PADDING = 8;

Expand Down Expand Up @@ -179,14 +181,14 @@ public void render(DrawContext ctx, int mouseX, int mouseY) {

int listTop = this.top + PADDING - (int) this.amountScrolled;

Screen.renderBackgroundTexture(ctx, Screen.MENU_BACKGROUND_TEXTURE, 0, top, 0.0F, 0.0F, width, height);
Screen.renderBackgroundTexture(ctx, MinecraftClient.getInstance().world != null ? Screen.INWORLD_MENU_BACKGROUND_TEXTURE : Screen.MENU_BACKGROUND_TEXTURE, 0, top, 0.0F, 0.0F, width, height);
drawEntries(ctx, mouseX, mouseY, listTop);

RenderHelper.enableDepthTest();
RenderHelper.depthFuncAlways();

this.overlayBackground(ctx, 0, this.top, Screen.HEADER_SEPARATOR_TEXTURE);
this.overlayBackground(ctx, this.bottom, this.height, Screen.FOOTER_SEPARATOR_TEXTURE);
this.overlayBackground(0, this.top);
this.overlayBackground(this.bottom, this.height);
RenderHelper.depthFuncLessEqual();
RenderHelper.disableDepthTest();
RenderHelper.enableBlend();
Expand Down Expand Up @@ -227,10 +229,29 @@ protected void drawEntry(DrawContext ctx, int mouseX, int mouseY, int top, Contr
entry.render(ctx, mouseX, mouseY);
}

private void overlayBackground(DrawContext context, int top, int bottom, Identifier texture) {
RenderSystem.enableBlend();
context.drawTexture(texture, 0, top, 0.0F, 0.0F, 0, bottom, 32, 2);
RenderSystem.disableBlend();
private void overlayBackground(int top, int bottom) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
RenderSystem.setShaderTexture(0, OPTIONS_BACKGROUND_TEXTURE);

bufferBuilder
.vertex(0, bottom, -100.0F)
.texture(0.0F, (float) bottom / 32.0F)
.color(64, 64, 64, 255);
bufferBuilder
.vertex(this.width, bottom, -100.0F)
.texture((float) this.width / 32.0F, (float) bottom / 32.0F)
.color(64, 64, 64, 255);
bufferBuilder
.vertex(this.width, top, -100.0F)
.texture((float) this.width / 32.0F, (float) top / 32.0F)
.color(64, 64, 64, 255);
bufferBuilder
.vertex(0, top, -100.0F)
.texture(0.0f, (float) top / 32.0F)
.color(64, 64, 64, 255);
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
}

private void drawScrollBar(int maxScroll) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/bbor.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ accessible class net/minecraft/client/world/ClientChunkManager$ClientChunk

extendable class net/minecraft/structure/StructureStart
extendable class net/minecraft/world/biome/Biome
accessible field net/minecraft/client/gui/screen/Screen INWORLD_MENU_BACKGROUND_TEXTURE Lnet/minecraft/util/Identifier;

0 comments on commit c360724

Please sign in to comment.