-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start working on inspector screen * pass 2 * pass 3 * merge fixes (cherry picked from commit 07cfed3)
- Loading branch information
Showing
16 changed files
with
485 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/mcp/mobius/waila/gui/hud/ComponentRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package mcp.mobius.waila.gui.hud; | ||
|
||
import java.util.Random; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.vertex.BufferUploader; | ||
import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
import com.mojang.blaze3d.vertex.Tesselator; | ||
import com.mojang.blaze3d.vertex.VertexFormat; | ||
import mcp.mobius.waila.WailaClient; | ||
import mcp.mobius.waila.api.ITooltipComponent; | ||
import net.minecraft.client.DeltaTracker; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraft.util.Mth; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static mcp.mobius.waila.util.DisplayUtil.renderRectBorder; | ||
|
||
public abstract class ComponentRenderer { | ||
|
||
private static final Random RANDOM = new Random(); | ||
|
||
public abstract void render(GuiGraphics ctx, ITooltipComponent component, int x, int y, int cw, int ch, DeltaTracker delta); | ||
|
||
private static @Nullable ComponentRenderer current = null; | ||
|
||
public static ComponentRenderer get() { | ||
if (current == null) current = Default.INSTANCE; | ||
return current; | ||
} | ||
|
||
public static void set(@Nullable ComponentRenderer value) { | ||
if (value == null) value = Default.INSTANCE; | ||
current = value; | ||
} | ||
|
||
public static class Default extends ComponentRenderer { | ||
|
||
public static final Default INSTANCE = new Default(); | ||
|
||
@Override | ||
public void render(GuiGraphics ctx, ITooltipComponent component, int x, int y, int cw, int ch, DeltaTracker delta) { | ||
component.render(ctx, x, y, delta); | ||
|
||
if (WailaClient.showComponentBounds) { | ||
renderBounds(ctx, x, y, cw, ch, 1f); | ||
} | ||
} | ||
|
||
public static void renderBounds(GuiGraphics ctx, int x, int y, int cw, int ch, float v) { | ||
ctx.pose().pushPose(); | ||
var scale = (float) Minecraft.getInstance().getWindow().getGuiScale(); | ||
ctx.pose().scale(1 / scale, 1 / scale, 1); | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
|
||
var buf = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); | ||
var bx = Mth.floor(x * scale + 0.5); | ||
var by = Mth.floor(y * scale + 0.5); | ||
var bw = Mth.floor(cw * scale + 0.5); | ||
var bh = Mth.floor(ch * scale + 0.5); | ||
var color = (0xFF << 24) + Mth.hsvToRgb(RANDOM.nextFloat(), RANDOM.nextFloat(), v); | ||
renderRectBorder(ctx.pose().last().pose(), buf, bx, by, bw, bh, 1, color, color); | ||
BufferUploader.drawWithShader(buf.buildOrThrow()); | ||
|
||
ctx.pose().popPose(); | ||
} | ||
|
||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/mcp/mobius/waila/gui/hud/InspectComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package mcp.mobius.waila.gui.hud; | ||
|
||
import mcp.mobius.waila.api.ITooltipComponent; | ||
import mcp.mobius.waila.registry.PluginAware; | ||
import net.minecraft.client.DeltaTracker; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class InspectComponent implements ITooltipComponent { | ||
|
||
public static boolean wrap = false; | ||
|
||
public final ITooltipComponent actual; | ||
public final PluginAware<?> origin; | ||
public final ResourceLocation tag; | ||
|
||
private InspectComponent(ITooltipComponent actual, PluginAware<?> origin, ResourceLocation tag) { | ||
this.actual = actual; | ||
this.origin = origin; | ||
this.tag = tag; | ||
} | ||
|
||
public static @Nullable ITooltipComponent maybeWrap(@Nullable ITooltipComponent actual, @Nullable PluginAware<?> origin, @Nullable ResourceLocation tag) { | ||
if (!wrap || actual == null || origin == null || actual instanceof InspectComponent) { | ||
return actual; | ||
} | ||
|
||
if (actual instanceof ITooltipComponent.HorizontalGrowing hg) { | ||
return new InspectComponent.Growing(hg, origin, tag); | ||
} | ||
|
||
return new InspectComponent(actual, origin, tag); | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
return actual.getWidth(); | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return actual.getHeight(); | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) { | ||
actual.render(ctx, x, y, delta); | ||
} | ||
|
||
public static class Growing extends InspectComponent implements HorizontalGrowing { | ||
|
||
public final HorizontalGrowing actual; | ||
|
||
public Growing(HorizontalGrowing actual, PluginAware<?> origin, ResourceLocation tag) { | ||
super(actual, origin, tag); | ||
this.actual = actual; | ||
} | ||
|
||
@Override | ||
public int getMinimalWidth() { | ||
return actual.getMinimalWidth(); | ||
} | ||
|
||
@Override | ||
public void setGrownWidth(int grownWidth) { | ||
actual.setGrownWidth(grownWidth); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.