Skip to content

Commit

Permalink
Implement GuiDisplay for Beta 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Nov 19, 2024
1 parent 1c47e47 commit 3b31adb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;

public abstract class ModInfoExtension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private Minecraft client() {

public static String internalToMinecraftType(ResourcePath path) {
String namespacePart = path.namespace() != "" ? path.namespace() + "/" : "";
return "assets/" + namespacePart + path.path();
return "/assets/" + namespacePart + path.path();
}

public static String internalToMinecraftType(Component component) {
Expand Down
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.pixaurora.kitten_cube.impl.ui.controls.MouseButton;
import net.pixaurora.kitten_cube.impl.ui.display.GuiDisplay;
import net.pixaurora.kitten_cube.impl.ui.screen.Screen;
import net.pixaurora.kitten_heart.impl.KitTunes;
import net.pixaurora.kitten_square.impl.service.UICompatImpl;
import net.pixaurora.kitten_square.impl.ui.ConversionCacheImpl;
import net.pixaurora.kitten_square.impl.ui.display.GuiDisplayImpl;
Expand Down Expand Up @@ -35,7 +34,7 @@ public void render(int mouseX, int mouseY, float delta) {
this.renderBackground();
super.render(mouseX, mouseY, delta);

GuiDisplay display = new GuiDisplayImpl(this.conversions);
GuiDisplay display = new GuiDisplayImpl(this, this.conversions);
Point mousePos = Point.of(mouseX, mouseY);

this.screen.draw(display, mousePos);
Expand Down

0 comments on commit 3b31adb

Please sign in to comment.