Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/src/main/java/com/ultreon/devices/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ private Resources() {
}



public static final ResourceLocation ENDER_MAIL_ICONS = Devices.id("textures/gui/ender_mail.png");
public static final ResourceLocation ENDER_MAIL_BACKGROUND = Devices.id("textures/gui/ender_mail_background.png");
public static final ResourceLocation MISSING_ICON = Devices.id("textures/app/icon/missing.png");
}
35 changes: 25 additions & 10 deletions common/src/main/java/com/ultreon/devices/core/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.ultreon.devices.Resources;
import com.ultreon.devices.api.app.Application;
import com.ultreon.devices.api.app.Dialog;
import com.ultreon.devices.api.app.component.Image;
import com.ultreon.devices.gui.GuiButtonClose;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.Objects;

public class Window<T extends Wrappable> {
public static final ResourceLocation WINDOW_GUI = new ResourceLocation("devices:textures/gui/application.png");

public static final int Color_WINDOW_DARK = new Color(0f, 0f, 0f, 0.25f).getRGB();
public static final int TITLE_BAR_HEIGHT = 16;

final Laptop laptop;
double dragFromX;
double dragFromY;
Expand All @@ -27,6 +33,7 @@ public class Window<T extends Wrappable> {
int offsetX, offsetY;
Window<Dialog> dialogWindow = null;
Window<? extends Wrappable> parent = null;
private Image icon = new Image(0, 0, 0, 0, 14, 14, Resources.MISSING_ICON);
protected boolean removed;

public Window(T wrappable, Laptop laptop) {
Expand Down Expand Up @@ -69,6 +76,11 @@ public void onClose() {
}
}

public void setIcon(@NotNull Image icon) {
Objects.requireNonNull(icon, "icon cannot be null");
this.icon = icon;
}

public void onTick() {
if (dialogWindow != null) {
dialogWindow.onTick();
Expand All @@ -93,32 +105,35 @@ public void render(PoseStack pose, Laptop gui, Minecraft mc, int x, int y, int m
RenderSystem.setShaderTexture(0, WINDOW_GUI);

/* Corners */
gui.blit(pose, x + offsetX, y + offsetY, 0, 0, 1, 13);
gui.blit(pose, x + offsetX + width - 13, y + offsetY, 2, 0, 13, 13);
gui.blit(pose, x + offsetX, y + offsetY, 0, 0, 1, TITLE_BAR_HEIGHT);
gui.blit(pose, x + offsetX + width - TITLE_BAR_HEIGHT, y + offsetY, 2, 0, TITLE_BAR_HEIGHT, TITLE_BAR_HEIGHT);
gui.blit(pose, x + offsetX + width - 1, y + offsetY + height - 1, 14, 14, 1, 1);
gui.blit(pose, x + offsetX, y + offsetY + height - 1, 0, 14, 1, 1);

/* Edges */
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY, width - 14, 13, 1, 0, 1, 13, 256, 256);
GuiComponent.blit(pose, x + offsetX + width - 1, y + offsetY + 13, 1, height - 14, 14, 13, 1, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY + height - 1, width - 2, 1, 1, 14, 13, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX, y + offsetY + 13, 1, height - 14, 0, 13, 1, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY, width - 14, TITLE_BAR_HEIGHT, 1, 0, 1, TITLE_BAR_HEIGHT, 256, 256);
GuiComponent.blit(pose, x + offsetX + width - 1, y + offsetY + TITLE_BAR_HEIGHT, 1, height - 14, 14, TITLE_BAR_HEIGHT, 1, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY + height - 1, width - 2, 1, 1, 14, TITLE_BAR_HEIGHT, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX, y + offsetY + TITLE_BAR_HEIGHT, 1, height - 14, 0, TITLE_BAR_HEIGHT, 1, 1, 256, 256);

/* Center */
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY + 13, width - 2, height - 14, 1, 13, 13, 1, 256, 256);
GuiComponent.blit(pose, x + offsetX + 1, y + offsetY + TITLE_BAR_HEIGHT, width - 2, height - 14, 1, TITLE_BAR_HEIGHT, TITLE_BAR_HEIGHT, 1, 256, 256);

icon.render(pose, laptop, mc, x + offsetX + 1, y + offsetY + 1, mouseX, mouseY, active, partialTicks);

String windowTitle = content.getWindowTitle();
if (mc.font.width(windowTitle) > width - 2 - 13 - 3) { // window width, border, close button, padding, padding
windowTitle = mc.font.plainSubstrByWidth(windowTitle, width - 2 - 13 - 3);
if (mc.font.width(windowTitle) > width - 2 - TITLE_BAR_HEIGHT - 3) { // window width, border, close button, padding, padding
windowTitle = mc.font.plainSubstrByWidth(windowTitle, width - 2 - TITLE_BAR_HEIGHT - 3);
}

mc.font.drawShadow(pose, windowTitle, x + offsetX + 3, y + offsetY + 3, Color.WHITE.getRGB(), true);

btnClose.renderButton(pose, mouseX, mouseY, partialTicks);

RenderSystem.disableBlend();

/* Render content */
content.render(pose, gui, mc, x + offsetX + 1, y + offsetY + 13, mouseX, mouseY, active && dialogWindow == null, partialTicks);
content.render(pose, gui, mc, x + offsetX + 1, y + offsetY + TITLE_BAR_HEIGHT, mouseX, mouseY, active && dialogWindow == null, partialTicks);

RenderSystem.setShaderColor(1f, 1f, 1f, 1f);

Expand Down