diff --git a/common/src/main/java/com/ultreon/devices/Resources.java b/common/src/main/java/com/ultreon/devices/Resources.java index 8c10643fa..2612720e5 100644 --- a/common/src/main/java/com/ultreon/devices/Resources.java +++ b/common/src/main/java/com/ultreon/devices/Resources.java @@ -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"); } diff --git a/common/src/main/java/com/ultreon/devices/core/Window.java b/common/src/main/java/com/ultreon/devices/core/Window.java index d0a3b18c0..45c16121f 100644 --- a/common/src/main/java/com/ultreon/devices/core/Window.java +++ b/common/src/main/java/com/ultreon/devices/core/Window.java @@ -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 { 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; @@ -27,6 +33,7 @@ public class Window { int offsetX, offsetY; Window dialogWindow = null; Window 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) { @@ -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(); @@ -93,24 +105,27 @@ 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); @@ -118,7 +133,7 @@ public void render(PoseStack pose, Laptop gui, Minecraft mc, int x, int y, int m 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);