-
-
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) (cherry picked from commit 131f2bd) (cherry picked from commit 040d1b7)
- Loading branch information
Showing
16 changed files
with
483 additions
and
104 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.DefaultVertexFormat; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
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.Minecraft; | ||
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(PoseStack matrices, ITooltipComponent component, int x, int y, int cw, int ch, float 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(PoseStack matrices, ITooltipComponent component, int x, int y, int cw, int ch, float delta) { | ||
component.render(matrices, x, y, delta); | ||
|
||
if (WailaClient.showComponentBounds) { | ||
renderBounds(matrices, x, y, cw, ch, 1f); | ||
} | ||
} | ||
|
||
public static void renderBounds(PoseStack matrices, int x, int y, int cw, int ch, float v) { | ||
matrices.pushPose(); | ||
var scale = (float) Minecraft.getInstance().getWindow().getGuiScale(); | ||
matrices.scale(1 / scale, 1 / scale, 1); | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
|
||
var tesselator = Tesselator.getInstance(); | ||
var buf = tesselator.getBuilder(); | ||
buf.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(matrices.last().pose(), buf, bx, by, bw, bh, 1, color, color); | ||
tesselator.end(); | ||
|
||
matrices.popPose(); | ||
} | ||
|
||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
package mcp.mobius.waila.gui.hud; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mcp.mobius.waila.api.ITooltipComponent; | ||
import mcp.mobius.waila.registry.PluginAware; | ||
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(PoseStack matrices, int x, int y, float delta) { | ||
actual.render(matrices, 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.