diff --git a/common/src/main/java/com/ultreon/devices/core/TaskBar.java b/common/src/main/java/com/ultreon/devices/core/TaskBar.java index 7f198595c..c1331a067 100644 --- a/common/src/main/java/com/ultreon/devices/core/TaskBar.java +++ b/common/src/main/java/com/ultreon/devices/core/TaskBar.java @@ -1,10 +1,13 @@ package com.ultreon.devices.core; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import com.ultreon.devices.Devices; import com.ultreon.devices.api.TrayItemAdder; import com.ultreon.devices.api.app.Application; +import com.ultreon.devices.api.app.Layout; +import com.ultreon.devices.api.app.System; +import com.ultreon.devices.api.app.component.ItemList; +import com.ultreon.devices.api.app.renderer.ListItemRenderer; import com.ultreon.devices.api.event.LaptopEvent; import com.ultreon.devices.api.utils.RenderUtil; import com.ultreon.devices.core.network.TrayItemWifi; @@ -16,7 +19,6 @@ import com.ultreon.devices.programs.system.SystemApp; import com.ultreon.devices.util.Vulnerability; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -34,6 +36,7 @@ public class TaskBar { public static final ResourceLocation APP_BAR_GUI = new ResourceLocation("devices:textures/gui/application_bar.png"); public static final int BAR_HEIGHT = 18; private static final int APPS_DISPLAYED = Devices.DEVELOPER_MODE ? 18 : 10; + private static final int TASKS_START = 18; private final CompoundTag tag; @@ -106,7 +109,7 @@ public void onTick() { trayItems.forEach(TrayItem::tick); } - public void render(GuiGraphics graphics, Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, float partialTicks) { + public void render(GuiGraphics gfx, Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, float partialTicks) { RenderSystem.setShaderColor(1f, 1f, 1f, 0.75f); RenderSystem.enableBlend(); RenderSystem.setShaderTexture(0, APP_BAR_GUI); @@ -117,45 +120,58 @@ public void render(GuiGraphics graphics, Laptop laptop, Minecraft mc, int x, int bgColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2])); RenderSystem.setShaderColor(bgColor.getRed() / 255f, bgColor.getGreen() / 255f, bgColor.getBlue() / 255f, 1f); + // Draw system tray. int trayItemsWidth = trayItems.size() * 14; - graphics.blit(APP_BAR_GUI, x, y, 1, 18, 0, 0, 1, 18, 256, 256); - graphics.blit(APP_BAR_GUI, x + 1, y, Laptop.SCREEN_WIDTH - 36 - trayItemsWidth, 18, 1, 0, 1, 18, 256, 256); - graphics.blit(APP_BAR_GUI, x + Laptop.SCREEN_WIDTH - 35 - trayItemsWidth, y, 35 + trayItemsWidth, 18, 2, 0, 1, 18, 256, 256); + gfx.blit(APP_BAR_GUI, x, y, 1, 18, 0, 0, 1, 18, 256, 256); + gfx.blit(APP_BAR_GUI, x + 1, y, Laptop.SCREEN_WIDTH - 36 - trayItemsWidth, 18, 1, 0, 1, 18, 256, 256); + gfx.blit(APP_BAR_GUI, x + Laptop.SCREEN_WIDTH - 35 - trayItemsWidth, y, 35 + trayItemsWidth, 18, 2, 0, 1, 18, 256, 256); - RenderSystem.disableBlend(); + // Draw start menu button + gfx.blit(APP_BAR_GUI, x, y, 18, 18, 0, 0, 1, 18, 256, 256); RenderSystem.setShaderColor(1f, 1f, 1f, 1f); + gfx.blit(APP_BAR_GUI, x + 1, y + 1, 52, 0, 16, 16); for (int i = 0; i < APPS_DISPLAYED && i < laptop.installedApps.size(); i++) { AppInfo info = laptop.installedApps.get(i + offset); - RenderUtil.drawApplicationIcon(graphics, info, x + 2 + i * 16, y + 2); + RenderUtil.drawApplicationIcon(gfx, info, TASKS_START + x + 2 + i * 16, y + 2); if (laptop.isApplicationRunning(info)) { RenderSystem.setShaderTexture(0, APP_BAR_GUI); - graphics.blit(APP_BAR_GUI, x + 1 + i * 16, y + 1, 35, 0, 16, 16); + gfx.blit(APP_BAR_GUI, TASKS_START + x + 1 + i * 16, y + 1, 35, 0, 16, 16); } } + RenderSystem.disableBlend(); + assert mc.level == null || mc.player != null; - // assert mc.level != null; //can no longer assume - graphics.drawString(mc.font, timeToString(mc.level != null ? mc.level.getDayTime() : 0), x + 334, y + 5, Color.WHITE.getRGB(), true); +// assert mc.level != null; //can no longer assume + gfx.drawString(mc.font, timeToString(mc.level != null ? mc.level.getDayTime() : 0), x + 334, y + 5, Color.WHITE.getRGB(), true); + + RenderSystem.enableBlend(); /* Settings App */ int startX = x + 317; for (int i = 0; i < trayItems.size(); i++) { int posX = startX - (trayItems.size() - 1 - i) * 14; if (isMouseInside(mouseX, mouseY, posX, y + 2, posX + 13, y + 15)) { - graphics.fill(posX, y + 2, posX + 14, y + 16, new Color(1f, 1f, 1f, 0.1f).getRGB()); + gfx.fill(posX, y + 2, posX + 14, y + 16, new Color(1f, 1f, 1f, 0.1f).getRGB()); } - trayItems.get(i).getIcon().draw(graphics, mc, posX + 2, y + 4); + trayItems.get(i).getIcon().draw(gfx, mc, posX + 2, y + 4); } + RenderSystem.disableBlend(); + RenderSystem.setShaderTexture(0, APP_BAR_GUI); + /* Other Apps */ + if (isMouseInside(mouseX, mouseY, x + 1, y + 1, x + 17, y + 16)) { + gfx.blit(APP_BAR_GUI, x + 1, y + 1, 35, 0, 16, 16); + } /* Other Apps */ - if (isMouseInside(mouseX, mouseY, x + 1, y + 1, x + 236, y + 16)) { - int appIndex = (mouseX - x - 1) / 16; + if (isMouseInside(mouseX, mouseY, TASKS_START + x + 1, y + 1, x + 236, y + 16)) { + int appIndex = (mouseX - x - 1 - TASKS_START) / 16; if (appIndex >= 0 && appIndex < offset + APPS_DISPLAYED && appIndex < laptop.installedApps.size()) { - graphics.blit(APP_BAR_GUI, x + appIndex * 16 + 1, y + 1, 35, 0, 16, 16); - laptop.renderComponentTooltip(graphics, List.of(Component.literal(laptop.installedApps.get(appIndex).getName())), mouseX, mouseY); + gfx.blit(APP_BAR_GUI, TASKS_START + x + appIndex * 16 + 1, y + 1, 35, 0, 16, 16); + laptop.renderComponentTooltip(gfx, List.of(Component.literal(laptop.installedApps.get(appIndex).getName())), mouseX, mouseY); } } @@ -163,9 +179,20 @@ public void render(GuiGraphics graphics, Laptop laptop, Minecraft mc, int x, int } public void handleClick(Laptop laptop, int x, int y, int mouseX, int mouseY, int mouseButton) { - if (isMouseInside(mouseX, mouseY, x + 1, y + 1, x + 236, y + 16)) { + if (isMouseInside(mouseX, mouseY, x + 1, y + 1, x + 17, y + 16)) { + System system = Laptop.getSystem(); + if (system.hasContext()) { + system.closeContext(); + return; + } + Layout startMenu = createStartMenu(); + system.openContext(startMenu, x + 1, y - 1 - startMenu.height); + return; + } + + if (isMouseInside(mouseX, mouseY, TASKS_START + x + 1, y + 1, x + 236, y + 16)) { Devices.LOGGER.debug(MARKER, "Clicked on task bar"); - int appIndex = (mouseX - x - 1) / 16; + int appIndex = (mouseX - x - 1 - TASKS_START) / 16; if (appIndex >= 0 && appIndex <= offset + APPS_DISPLAYED && appIndex < laptop.installedApps.size()) { laptop.openApplication(laptop.installedApps.get(appIndex)); return; @@ -184,6 +211,43 @@ public void handleClick(Laptop laptop, int x, int y, int mouseX, int mouseY, int } } + /** + * @author Qboi + */ + private Layout createStartMenu() { + var layout = new Layout(120, 114); + + // Set background. + layout.setBackground((gfx, mc, x, y, width, height, mouseX, mouseY, windowActive) -> gfx.fill(x, y, x + width, y + height, new Color(0.65f, 0.65f, 0.65f, 0.9f).getRGB())); + + // Create app info list with installed applications. + ItemList appList = new ItemList<>(5, 5, 110, 6); + appList.setItems(laptop.installedApps); + + // Application item renderer. + appList.setListItemRenderer(new ListItemRenderer<>(16) { + @Override + public void render(GuiGraphics gfx, AppInfo appInfo, Minecraft mc, int x, int y, int width, int height, boolean selected) { + gfx.fill(x, y, x + width, y + height, selected ? Color.DARK_GRAY.getRGB() : Color.GRAY.getRGB()); + + // Draw text and icon. + RenderUtil.drawStringClipped(gfx, appInfo.getName(), x + 18, y + 4, 70, Color.WHITE.getRGB(), false); + RenderUtil.drawApplicationIcon(gfx, appInfo, x + 1, y + 1); + } + }); + + // Set handler for when the item gets clicked. + appList.setItemClickListener((appInfo, index, mouseButton) -> { + // Open the application by entry. + Laptop.getSystem().closeContext(); + laptop.openApplication(appInfo); + }); + + // Add the list to the layout and return. + layout.addComponent(appList); + return layout; + } + public boolean isMouseInside(int mouseX, int mouseY, int x1, int y1, int x2, int y2) { return mouseX >= x1 && mouseX <= x2 && mouseY >= y1 && mouseY <= y2; } diff --git a/common/src/main/java/com/ultreon/devices/core/network/Connection.java b/common/src/main/java/com/ultreon/devices/core/network/Connection.java index 2fd9ac332..5200f871a 100644 --- a/common/src/main/java/com/ultreon/devices/core/network/Connection.java +++ b/common/src/main/java/com/ultreon/devices/core/network/Connection.java @@ -67,6 +67,7 @@ public CompoundTag toTag() { CompoundTag tag = new CompoundTag(); tag.putString("id", routerId.toString()); if (routerPos != null) { + // FIXME: Router position can be null. Pls fix this. tag.put("Pos", NbtUtils.writeBlockPos(routerPos)); } return tag; diff --git a/common/src/main/resources/assets/devices/textures/gui/application_bar.png b/common/src/main/resources/assets/devices/textures/gui/application_bar.png index 6d1438692..73c43b1a7 100644 Binary files a/common/src/main/resources/assets/devices/textures/gui/application_bar.png and b/common/src/main/resources/assets/devices/textures/gui/application_bar.png differ