generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
34 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
84 changes: 55 additions & 29 deletions
84
...uare/b1.7.3/src/main/java/net/pixaurora/kitten_square/impl/ui/display/GuiDisplayImpl.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 |
---|---|---|
@@ -1,66 +1,92 @@ | ||
package net.pixaurora.kitten_square.impl.ui.display; | ||
|
||
import org.lwjgl.opengl.GL11; | ||
|
||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiElement; | ||
import net.pixaurora.kit_tunes.api.resource.ResourcePath; | ||
import net.pixaurora.kitten_cube.impl.MinecraftClient; | ||
import net.pixaurora.kitten_cube.impl.math.Point; | ||
import net.pixaurora.kitten_cube.impl.math.Size; | ||
import net.pixaurora.kitten_cube.impl.text.Color; | ||
import net.pixaurora.kitten_cube.impl.text.Component; | ||
import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay; | ||
import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox; | ||
import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl; | ||
import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl; | ||
|
||
public class GuiDisplayImpl implements GuiDisplay { | ||
private final GuiElement element; | ||
private final ConversionCacheImpl conversions; | ||
|
||
public GuiDisplayImpl(ConversionCacheImpl conversions) { | ||
private int offsetX; | ||
private int offsetY; | ||
|
||
public GuiDisplayImpl(GuiElement element, ConversionCacheImpl conversions, int offsetX, int offsetY) { | ||
this.element = element; | ||
this.conversions = conversions; | ||
this.offsetX = offsetX; | ||
this.offsetY = offsetY; | ||
} | ||
|
||
// TODO: Reimplement methods | ||
public GuiDisplayImpl(GuiElement element, ConversionCacheImpl conversions) { | ||
this(element, conversions, 0, 0); | ||
} | ||
|
||
@Override | ||
public void drawTexture(ResourcePath path, Size size, Point pos) { | ||
// int width = size.width(); | ||
// int height = size.height(); | ||
|
||
// RenderSystem.setShaderTexture(0, conversions.convert(path)); | ||
// GuiComponent.blit(poseStack, pos.x(), pos.y(), 0, 0.0F, 0.0F, width, height, | ||
// width, height); | ||
this.drawGuiTextureSubsection(path, size, pos, size, pos); | ||
} | ||
|
||
@Override | ||
public void drawGuiTextureSubsection(ResourcePath path, Size size, Point pos, Size subsection, Point offset) { | ||
// RenderSystem.setShaderTexture(0, conversions.convert(path)); | ||
// GuiComponent.blit(poseStack, pos.x(), pos.y(), offset.x(), offset.y(), | ||
// subsection.width(), subsection.height(), | ||
// size.width(), size.height()); | ||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, Minecraft.INSTANCE.textureManager.load(this.conversions.convert(path))); | ||
|
||
int x = pos.x(); | ||
int y = pos.y(); | ||
float textureWidth = size.width(); | ||
float textureHeight = size.height(); | ||
|
||
float u = offset.x(); | ||
float v = offset.y(); | ||
int width = subsection.width(); | ||
int height = subsection.height(); | ||
|
||
float invertedTexWidth = 1.0f / textureWidth; | ||
float invertedTexHeight = 1.0f / textureHeight; | ||
BufferBuilder bufferBuilder = BufferBuilder.INSTANCE; | ||
bufferBuilder.start(); | ||
bufferBuilder.vertex(x, y + height, 0.0, u * invertedTexWidth, (v + (float) height) * invertedTexHeight); | ||
bufferBuilder.vertex(x + width, y + height, 0.0, (u + (float) width) * invertedTexWidth, | ||
(v + (float) height) * invertedTexHeight); | ||
bufferBuilder.vertex(x + width, y, 0.0, (u + (float) width) * invertedTexWidth, v * invertedTexHeight); | ||
bufferBuilder.vertex(x, y, 0.0, u * invertedTexWidth, v * invertedTexHeight); | ||
bufferBuilder.end(); | ||
} | ||
|
||
@SuppressWarnings("resource") | ||
@Override | ||
public void drawText(Component text, Color color, Point pos, boolean shadowed) { | ||
// GuiComponent.drawString(poseStack, Minecraft.getInstance().font, | ||
// conversions.convert(text), pos.x(), pos.y(), | ||
// color.hex()); | ||
element.drawString(Minecraft.INSTANCE.textRenderer, this.conversions.convert(text), pos.x() + offsetX, | ||
pos.y() + offsetY, color.hex()); | ||
} | ||
|
||
@SuppressWarnings("resource") | ||
@Override | ||
public void drawTextBox(TextBox textBox) { | ||
// if (textBox instanceof TextBoxImpl) { | ||
// TextBoxImpl impl = (TextBoxImpl) textBox; | ||
if (!(textBox instanceof TextBoxImpl)) { | ||
throw new UnsupportedOperationException("Unsupported instance of textbox"); | ||
} | ||
|
||
TextBoxImpl impl = (TextBoxImpl) textBox; | ||
|
||
// int y = impl.startPos.y(); | ||
int x = impl.startPos.x() + offsetX; | ||
int y = impl.startPos.y() + offsetY; | ||
|
||
// for (FormattedCharSequence line : impl.lines) { | ||
// GuiComponent.drawString(poseStack, Minecraft.getInstance().font, line, | ||
// impl.startPos.x(), y, | ||
// impl.color.hex()); | ||
for (String line : impl.lines) { | ||
this.element.drawString(Minecraft.INSTANCE.textRenderer, line, x, y, impl.color.hex()); | ||
|
||
// y += MinecraftClient.textHeight(); | ||
// } | ||
// } else { | ||
// throw new UnsupportedOperationException("Unsupported instance of textbox"); | ||
// } | ||
y += MinecraftClient.textHeight(); | ||
} | ||
} | ||
} |
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