From f3b6fd94c0ead7de627eb688094cd0078b6da388 Mon Sep 17 00:00:00 2001 From: Ocelot Date: Fri, 19 Jun 2026 10:27:15 -0600 Subject: [PATCH 1/3] Update to ImGuiMC 2.0.0 --- .../veil/api/client/editor/EditorManager.java | 16 +- .../veil/api/client/imgui/CodeEditor.java | 588 +++++++++--------- .../veil/api/client/imgui/VeilImGuiUtil.java | 200 +----- .../AdvancedFboTextureAttachment.java | 3 +- .../resource/editor/BlockModelInspector.java | 8 +- .../api/resource/editor/EffectInspector.java | 2 +- .../editor/FramebufferFileEditor.java | 67 +- .../editor/ResourceOverrideEditor.java | 5 +- .../api/resource/editor/ShellInspector.java | 8 +- .../api/resource/editor/TextFileEditor.java | 98 +-- .../api/resource/type/BlockModelResource.java | 6 + .../veil/api/resource/type/FlareResource.java | 6 + .../resource/type/FramebufferResource.java | 6 + .../api/resource/type/LanguageResource.java | 5 + .../resource/type/PostPipelineResource.java | 6 + .../api/resource/type/RenderTypeResource.java | 6 + .../veil/api/resource/type/ShellResource.java | 6 + .../veil/api/resource/type/TextResource.java | 19 +- .../type/VanillaShaderFileResource.java | 1 + .../type/VeilShaderDefinitionResource.java | 6 + .../resource/type/VeilShaderFileResource.java | 1 + .../type/VeilShaderIncludeResource.java | 1 + .../api/resource/type/VeilShaderResource.java | 9 +- .../api/resource/type/VeilTextResource.java | 8 +- .../impl/client/editor/DeviceInfoViewer.java | 11 +- .../client/editor/FramebufferInspector.java | 9 +- .../impl/client/editor/LightInspector.java | 12 +- .../editor/PipelineStatisticsViewer.java | 11 +- .../impl/client/editor/PostInspector.java | 5 +- .../editor/ResourceManagerInspector.java | 6 +- .../impl/client/editor/ShaderInspector.java | 7 +- .../impl/client/editor/TextureInspector.java | 6 +- .../impl/client/imgui/VeilImGuiCompat.java | 9 +- .../impl/resource/VeilResourceRenderer.java | 7 +- .../resource/loader/TextResourceLoader.java | 8 +- fabric/src/main/resources/fabric.mod.json | 5 +- gradle.properties | 2 +- .../resources/META-INF/neoforge.mods.toml | 4 +- 38 files changed, 570 insertions(+), 613 deletions(-) diff --git a/common/src/main/java/foundry/veil/api/client/editor/EditorManager.java b/common/src/main/java/foundry/veil/api/client/editor/EditorManager.java index 7af665392..a6089a691 100644 --- a/common/src/main/java/foundry/veil/api/client/editor/EditorManager.java +++ b/common/src/main/java/foundry/veil/api/client/editor/EditorManager.java @@ -1,6 +1,5 @@ package foundry.veil.api.client.editor; -import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.VeilClient; import foundry.veil.api.event.VeilRegisterInspectorsEvent; @@ -38,7 +37,12 @@ */ public class EditorManager implements VeilEditorEnvironment, PreparableReloadListener { - public static final ResourceLocation DEFAULT_FONT = Veil.veilPath("jetbrains_mono"); + /** + * @deprecated Use ImGuiMC#DEFAULT_FONT instead + */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated + public static final ResourceLocation DEFAULT_FONT = ResourceLocation.fromNamespaceAndPath("imguimc", "jetbrains_mono"); private final Map editors; private final Map> resourceFileEditors; @@ -73,8 +77,6 @@ public void render() { Minecraft.getInstance()); } - ImGui.pushFont(ImGuiMC.getFont(DEFAULT_FONT, false, false)); - if (ImGui.beginMainMenuBar()) { ImFont font = ImGui.getFont(); float dingleWidth = font.calcTextSizeAX(ImGui.getFontSize(), Float.MAX_VALUE, 0, " Veil ") + 1; @@ -144,8 +146,6 @@ public void render() { next.render(); } - - ImGui.popFont(); } @ApiStatus.Internal @@ -154,8 +154,6 @@ public void renderLast() { return; } - ImGui.pushFont(ImGuiMC.getFont(DEFAULT_FONT, false, false)); - for (Map.Entry entry : this.editors.entrySet()) { Inspector inspector = entry.getKey(); ImBoolean enabled = entry.getValue(); @@ -163,8 +161,6 @@ public void renderLast() { inspector.renderLast(); } } - - ImGui.popFont(); } @ApiStatus.Internal diff --git a/common/src/main/java/foundry/veil/api/client/imgui/CodeEditor.java b/common/src/main/java/foundry/veil/api/client/imgui/CodeEditor.java index adc562955..3b6def4cc 100644 --- a/common/src/main/java/foundry/veil/api/client/imgui/CodeEditor.java +++ b/common/src/main/java/foundry/veil/api/client/imgui/CodeEditor.java @@ -1,288 +1,300 @@ -//package foundry.veil.api.client.imgui; -// -//import foundry.imgui.api.ImGuiMC; -//import imgui.ImGui; -//import imgui.ImVec2; -//import imgui.extension.texteditor.TextEditor; -//import imgui.extension.texteditor.TextEditorCoordinates; -//import imgui.flag.ImGuiCond; -//import imgui.flag.ImGuiWindowFlags; -//import imgui.type.ImBoolean; -//import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; -//import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -//import net.minecraft.network.chat.Component; -//import org.jetbrains.annotations.Nullable; -//import org.lwjgl.system.NativeResource; -// -//import java.util.Collections; -// -///** -// * Creates a text editor window with saving callback support. -// * -// * @author Ocelot -// */ -//public class CodeEditor implements NativeResource { -// -// private static final Component EDITOR = Component.translatable("editor.veil.default"); -// -// // TODO reimplement in Java -// private final Component name; -// private final TextEditor editor; -// private final Component saveText; -// private CharSequence oldSource; -// private SaveCallback saveCallback; -// private String fileName; -// -// private final ImBoolean open; -// -// public CodeEditor(@Nullable Component saveText) { -// this(EDITOR, saveText); -// } -// -// public CodeEditor(Component name, @Nullable Component saveText) { -// this.name = name; -// this.editor = new TextEditor(); -// this.editor.setShowWhitespaces(false); -// this.saveText = saveText; -// this.oldSource = null; -// this.saveCallback = null; -// -// this.open = new ImBoolean(); -// } -// -// /** -// * @return Whether the text has changed since last save -// */ -// public boolean hasTextChanged() { -// return this.oldSource != null && !this.oldSource.equals(this.editor.getText()); -// } -// -// /** -// * Fires the save callback if the text has changed. -// */ -// public void save() { -// Int2ObjectMap errors = new Int2ObjectArrayMap<>(); -// if (this.saveCallback != null) { -// this.saveCallback.save(this.editor.getText(), errors); -// } -// if (errors.isEmpty()) { -// this.oldSource = this.editor.getText(); -// } -// ImGuiMC.withImGui(() -> this.editor.setErrorMarkers(errors)); -// } -// -// /** -// * Shows the editor with the specified source. -// * -// * @param source The source to display -// */ -// public void show(@Nullable String fileName, String source) { -// this.editor.setText(source); -// this.fileName = fileName; -// this.oldSource = this.editor.getText(); -// this.editor.setErrorMarkers(Collections.emptyMap()); -// this.open.set(true); -// ImGuiMC.withImGui(() -> { -// ImGui.setWindowFocus("###editor"); -// ImGui.setWindowCollapsed("###editor", false); -// }); -// } -// -// /** -// * Attempts to hide and save the editor. -// */ -// public void hide() { -// if (this.hasTextChanged()) { -// this.open.set(true); -// ImGuiMC.withImGui(() -> { -// ImGui.pushID(this.hashCode()); -// ImGui.openPopup("###save_confirm"); -// ImGui.popID(); -// }); -// } else { -// this.oldSource = null; -// this.open.set(false); -// } -// } -// -// /** -// * Renders the editor in a closable window. -// */ -// public void renderWindow() { -// int flags = ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoSavedSettings; -// if (!this.editor.isReadOnly() && this.hasTextChanged()) { -// flags |= ImGuiWindowFlags.UnsavedDocument; -// } -// -// if (!this.open.get()) { -// return; -// } -// -// int id = this.hashCode(); -// ImGui.pushID(id); -// ImGui.setNextWindowSizeConstraints(800, 600, Float.MAX_VALUE, Float.MAX_VALUE); -// if (ImGui.begin(this.name.getString() + (this.fileName != null ? ": " + this.fileName : "") + "###editor" + id, this.open, flags)) { -// this.render(); -// } -// -// if (!this.open.get()) { -// this.hide(); -// } -// -// ImGui.end(); -// ImGui.popID(); -// } -// -// /** -// * Renders the editor onto the stack. -// */ -// public void render() { -// ImGui.pushID(this.hashCode()); -// if (this.open.get()) { -// if (!this.hasTextChanged()) { -// this.editor.setErrorMarkers(Collections.emptyMap()); -// } -// -// if (ImGui.beginMenuBar()) { -// boolean immutable = this.editor.isReadOnly(); -// if (ImGui.menuItem("Read-only mode", "", immutable)) { -// this.editor.setReadOnly(!immutable); -// } -// if (ImGui.menuItem("Show Whitespace", "", this.editor.isShowingWhitespaces())) { -// this.editor.setShowWhitespaces(!this.editor.isShowingWhitespaces()); -// } -// -// if (this.saveText != null) { -// if (ImGui.menuItem(this.saveText.getString())) { -// this.save(); -// } -// } -// -// ImGui.separator(); -// -// ImGui.beginDisabled(immutable); -// { -// ImGui.beginDisabled(!this.editor.canUndo()); -// if (ImGui.menuItem("Undo", "ALT-Backspace")) { -// this.editor.undo(1); -// } -// ImGui.endDisabled(); -// -// ImGui.beginDisabled(!this.editor.canRedo()); -// if (ImGui.menuItem("Redo", "Ctrl-Y")) { -// this.editor.redo(1); -// } -// ImGui.endDisabled(); -// } -// ImGui.endDisabled(); -// ImGui.separator(); -// -// ImGui.beginDisabled(!this.editor.hasSelection()); -// if (ImGui.menuItem("Copy", "Ctrl-C")) { -// this.editor.copy(); -// } -// ImGui.endDisabled(); -// -// ImGui.beginDisabled(immutable); -// { -// ImGui.beginDisabled(!this.editor.hasSelection()); -// if (ImGui.menuItem("Cut", "Ctrl-X")) { -// this.editor.cut(); -// } -// if (ImGui.menuItem("Delete", "Del")) { -// this.editor.delete(); -// } -// ImGui.endDisabled(); -// -// ImGui.beginDisabled(ImGui.getClipboardText() == null); -// if (ImGui.menuItem("Paste", "Ctrl-V")) { -// this.editor.paste(); -// } -// ImGui.endDisabled(); -// } -// ImGui.endDisabled(); -// -// ImGui.endMenuBar(); -// } -// -// TextEditorCoordinates pos = this.editor.getCursorPosition(); -// int cposX = pos.mLine; -// int cposY = pos.mColumn; -// -// String overwrite = this.editor.isOverwrite() ? "Ovr" : "Ins"; -// String canUndo = this.editor.canUndo() ? "*" : " "; -// -// ImGui.text(cposX + ":" + cposY + " " + this.editor.getTotalLines() + " lines | " + overwrite + " | " + canUndo); -// -// this.editor.render("TextEditor"); -// } -// -// ImVec2 center = ImGui.getMainViewport().getCenter(); -// ImGui.setNextWindowPos(center.x, center.y, ImGuiCond.Appearing, 0.5f, 0.5f); -// -// if (this.saveText != null) { -// String save = this.saveText.getString(); -// if (ImGui.beginPopupModal(save + "?###save_confirm", ImGuiWindowFlags.AlwaysAutoResize)) { -// ImGui.text("Your changes have not been saved.\nThis operation cannot be undone!"); -// ImGui.separator(); -// -// ImGui.setItemDefaultFocus(); -// if (ImGui.button(save)) { -// this.save(); -// this.hide(); -// ImGui.closeCurrentPopup(); -// } -// -// ImGui.sameLine(); -// if (ImGui.button("Discard")) { -// this.oldSource = null; -// this.hide(); -// ImGui.closeCurrentPopup(); -// } -// -// ImGui.sameLine(); -// if (ImGui.button("Cancel")) { -// ImGui.closeCurrentPopup(); -// } -// -// ImGui.endPopup(); -// } -// } -// -// ImGui.popID(); -// } -// -// public TextEditor getEditor() { -// return this.editor; -// } -// -// public boolean isOpen() { -// return this.open.get(); -// } -// -// public void setSaveCallback(@Nullable SaveCallback saveCallback) { -// this.saveCallback = saveCallback; -// } -// -// @Override -// public void free() { -// this.editor.destroy(); -// } -// -// /** -// * Callback for when editor is saved. -// * -// * @author Ocelot -// */ -// @FunctionalInterface -// public interface SaveCallback { -// -// /** -// * Fired when the editor contents are saved. -// * -// * @param source The new source code -// * @param errors The map of errors. The first parameter is the line number and the second is the error. Multiple errors are supported -// */ -// void save(String source, Int2ObjectMap errors); -// } -//} +package foundry.veil.api.client.imgui; + +import foundry.imgui.api.ImGuiMC; +import imgui.ImGui; +import imgui.ImVec2; +import imgui.extension.texteditor.TextEditor; +import imgui.extension.texteditor.TextEditorCursorPosition; +import imgui.flag.ImGuiCond; +import imgui.flag.ImGuiWindowFlags; +import imgui.type.ImBoolean; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.system.NativeResource; + +/** + * Creates a text editor window with saving callback support. + * + * @author Ocelot + */ +public class CodeEditor implements NativeResource { + + private static final Component EDITOR = Component.translatable("editor.veil.default"); + + // TODO reimplement in Java + private final Component name; + private final TextEditor editor; + private final Component saveText; + private CharSequence oldSource; + private SaveCallback saveCallback; + private String fileName; + + private final ImBoolean open; + + public CodeEditor(@Nullable Component saveText) { + this(EDITOR, saveText); + } + + public CodeEditor(Component name, @Nullable Component saveText) { + this.name = name; + this.editor = new TextEditor(); + this.editor.setShowWhitespacesEnabled(false); + this.saveText = saveText; + this.oldSource = null; + this.saveCallback = null; + + this.open = new ImBoolean(); + } + + /** + * @return Whether the text has changed since last save + */ + public boolean hasTextChanged() { + return this.oldSource != null && !this.oldSource.equals(this.editor.getText()); + } + + /** + * Fires the save callback if the text has changed. + */ + public void save() { + try (final ImGuiMC.ActiveContext context = ImGuiMC.withImGui()) { + if (context != null) { + if (this.saveCallback != null) { + this.saveCallback.save(this.editor.getText(), this.editor::addMarker); + } + if (this.editor.hasMarkers()) { + this.oldSource = this.editor.getText(); + } + } + } + } + + /** + * Shows the editor with the specified source. + * + * @param source The source to display + */ + public void show(@Nullable String fileName, String source) { + this.editor.setText(source); + this.fileName = fileName; + this.oldSource = this.editor.getText(); + this.editor.clearMarkers(); + this.open.set(true); + try (final ImGuiMC.ActiveContext context = ImGuiMC.withImGui()) { + if (context != null) { + ImGui.setWindowFocus("###editor"); + ImGui.setWindowCollapsed("###editor", false); + } + } + } + + /** + * Attempts to hide and save the editor. + */ + public void hide() { + if (this.hasTextChanged()) { + this.open.set(true); + try (final ImGuiMC.ActiveContext context = ImGuiMC.withImGui()) { + if (context != null) { + ImGui.pushID(this.hashCode()); + ImGui.openPopup("###save_confirm"); + ImGui.popID(); + } + } + } else { + this.oldSource = null; + this.open.set(false); + } + } + + /** + * Renders the editor in a closable window. + */ + public void renderWindow() { + int flags = ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoSavedSettings; + if (!this.editor.isReadOnlyEnabled() && this.hasTextChanged()) { + flags |= ImGuiWindowFlags.UnsavedDocument; + } + + if (!this.open.get()) { + return; + } + + int id = this.hashCode(); + ImGui.pushID(id); + ImGui.setNextWindowSizeConstraints(800, 600, Float.MAX_VALUE, Float.MAX_VALUE); + if (ImGui.begin(this.name.getString() + (this.fileName != null ? ": " + this.fileName : "") + "###editor" + id, this.open, flags)) { + this.render(); + } + + if (!this.open.get()) { + this.hide(); + } + + ImGui.end(); + ImGui.popID(); + } + + /** + * Renders the editor onto the stack. + */ + public void render() { + ImGui.pushID(this.hashCode()); + if (this.open.get()) { + if (!this.hasTextChanged()) { + this.editor.clearMarkers(); + } + + if (ImGui.beginMenuBar()) { + boolean immutable = this.editor.isReadOnlyEnabled(); + if (ImGui.menuItem("Read-only mode", "", immutable)) { + this.editor.setReadOnlyEnabled(!immutable); + } + if (ImGui.menuItem("Show Whitespace", "", this.editor.isShowWhitespacesEnabled())) { + this.editor.setShowWhitespacesEnabled(!this.editor.isShowWhitespacesEnabled()); + } + + if (this.saveText != null) { + if (ImGui.menuItem(this.saveText.getString())) { + this.save(); + } + } + + ImGui.separator(); + + ImGui.beginDisabled(immutable); + { + ImGui.beginDisabled(!this.editor.canUndo()); + if (ImGui.menuItem("Undo", "ALT-Backspace")) { + this.editor.undo(); + } + ImGui.endDisabled(); + + ImGui.beginDisabled(!this.editor.canRedo()); + if (ImGui.menuItem("Redo", "Ctrl-Y")) { + this.editor.redo(); + } + ImGui.endDisabled(); + } + ImGui.endDisabled(); + ImGui.separator(); + + ImGui.beginDisabled(!this.editor.anyCursorHasSelection()); + if (ImGui.menuItem("Copy", "Ctrl-C")) { + this.editor.copy(); + } + ImGui.endDisabled(); + + ImGui.beginDisabled(immutable); + { + ImGui.beginDisabled(!this.editor.anyCursorHasSelection()); + if (ImGui.menuItem("Cut", "Ctrl-X")) { + this.editor.cut(); + } + ImGui.endDisabled(); + + ImGui.beginDisabled(ImGui.getClipboardText() == null); + if (ImGui.menuItem("Paste", "Ctrl-V")) { + this.editor.paste(); + } + ImGui.endDisabled(); + } + ImGui.endDisabled(); + + ImGui.endMenuBar(); + } + + TextEditorCursorPosition pos = this.editor.getCurrentCursorPosition(); + int cposX = pos.line; + int cposY = pos.column; + + String overwrite = this.editor.isOverwriteEnabled() ? "Ovr" : "Ins"; + String canUndo = this.editor.canUndo() ? "*" : " "; + + ImGui.text(cposX + ":" + cposY + " " + this.editor.getLineCount() + " lines | " + overwrite + " | " + canUndo); + + this.editor.render("TextEditor"); + } + + ImVec2 center = ImGui.getMainViewport().getCenter(); + ImGui.setNextWindowPos(center.x, center.y, ImGuiCond.Appearing, 0.5f, 0.5f); + + if (this.saveText != null) { + String save = this.saveText.getString(); + if (ImGui.beginPopupModal(save + "?###save_confirm", ImGuiWindowFlags.AlwaysAutoResize)) { + ImGui.text("Your changes have not been saved.\nThis operation cannot be undone!"); + ImGui.separator(); + + ImGui.setItemDefaultFocus(); + if (ImGui.button(save)) { + this.save(); + this.hide(); + ImGui.closeCurrentPopup(); + } + + ImGui.sameLine(); + if (ImGui.button("Discard")) { + this.oldSource = null; + this.hide(); + ImGui.closeCurrentPopup(); + } + + ImGui.sameLine(); + if (ImGui.button("Cancel")) { + ImGui.closeCurrentPopup(); + } + + ImGui.endPopup(); + } + } + + ImGui.popID(); + } + + public TextEditor getEditor() { + return this.editor; + } + + public boolean isOpen() { + return this.open.get(); + } + + public void setSaveCallback(@Nullable SaveCallback saveCallback) { + this.saveCallback = saveCallback; + } + + @Override + public void free() { + this.editor.destroy(); + } + + /** + * Callback for when editor is saved. + * + * @author Ocelot + */ + @FunctionalInterface + public interface SaveCallback { + + /** + * Fired when the editor contents are saved. + * + * @param source The new source code + * @param errors The error consumer + */ + void save(String source, ErrorConsumer errors); + } + + public interface ErrorConsumer { + + void addMarker(final int line, final int lineNumberColor, final int textColor, final String lineNumberTooltip, final String textTooltip); + + default void addMarker(final int line, final int lineNumberColor, final int textColor) { + this.addMarker(line, lineNumberColor, textColor, "", ""); + } + + default void addMarker(final int line, final int lineNumberColor, final int textColor, final String lineNumberTooltip) { + this.addMarker(line, lineNumberColor, textColor, lineNumberTooltip, ""); + } + } +} diff --git a/common/src/main/java/foundry/veil/api/client/imgui/VeilImGuiUtil.java b/common/src/main/java/foundry/veil/api/client/imgui/VeilImGuiUtil.java index 4b0dbf253..cc9d407b3 100644 --- a/common/src/main/java/foundry/veil/api/client/imgui/VeilImGuiUtil.java +++ b/common/src/main/java/foundry/veil/api/client/imgui/VeilImGuiUtil.java @@ -4,7 +4,6 @@ import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.api.client.editor.EditorManager; -import foundry.veil.api.client.render.VeilRenderSystem; import foundry.veil.api.client.render.framebuffer.AdvancedFbo; import foundry.veil.impl.client.imgui.AdvancedFboImGuiAreaImpl; import imgui.ImFont; @@ -12,24 +11,12 @@ import imgui.ImVec4; import imgui.flag.ImGuiCol; import imgui.flag.ImGuiStyleVar; -import net.minecraft.Util; -import net.minecraft.client.Minecraft; import net.minecraft.client.StringSplitter; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.locale.Language; -import net.minecraft.network.chat.*; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.util.FormattedCharSink; -import net.minecraft.util.StringUtil; import org.jetbrains.annotations.ApiStatus; -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import java.util.Locale; import java.util.function.Consumer; /** @@ -39,9 +26,6 @@ */ public class VeilImGuiUtil { - private static final ImGuiCharSink IM_GUI_CHAR_SINK = new ImGuiCharSink(); - private static final StringSplitter IM_GUI_SPLITTER = new StringSplitter((charId, style) -> getStyleFont(style).getCharAdvance(charId)); - public static final ResourceLocation ICON_FONT = Veil.veilPath("remixicon"); /** @@ -67,7 +51,7 @@ public static void tooltip(String text) { */ public static void setTooltip(FormattedText text) { ImGui.beginTooltip(); - component(text); + ImGuiMC.component(text); ImGui.endTooltip(); } @@ -75,9 +59,12 @@ public static void setTooltip(FormattedText text) { * Fully renders Minecraft text into ImGui. * * @param text The text to render + * @deprecated Use {@link ImGuiMC#component(FormattedText)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated public static void component(FormattedText text) { - component(text, Float.POSITIVE_INFINITY); + ImGuiMC.component(text); } /** @@ -85,14 +72,12 @@ public static void component(FormattedText text) { * * @param text The text to render * @param wrapWidth The width to wrap to + * @deprecated Use {@link ImGuiMC#component(FormattedText, float)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated public static void component(FormattedText text, float wrapWidth) { - IM_GUI_CHAR_SINK.reset(); - for (FormattedCharSequence part : Language.getInstance().getVisualOrder(IM_GUI_SPLITTER.splitLines(text, (int) wrapWidth, Style.EMPTY))) { - part.accept(IM_GUI_CHAR_SINK); - IM_GUI_CHAR_SINK.finish(); - ImGui.newLine(); - } + ImGuiMC.component(text, wrapWidth); } /** @@ -101,7 +86,7 @@ public static void component(FormattedText text, float wrapWidth) { * @param code The icon code (ex. ) */ public static void icon(int code) { - ImGui.pushFont(ImGuiMC.getFont(ICON_FONT, false, false)); + ImGui.pushFont(ImGuiMC.getFont(ICON_FONT, false, false), 0); ImGui.text("" + (char) code); ImGui.popFont(); } @@ -113,7 +98,7 @@ public static void icon(int code) { * @param color The color of the icon */ public static void icon(int code, int color) { - ImGui.pushFont(ImGuiMC.getFont(ICON_FONT, false, false)); + ImGui.pushFont(ImGuiMC.getFont(ICON_FONT, false, false), 0); ImGui.textColored(color, "" + (char) code); ImGui.popFont(); } @@ -204,7 +189,10 @@ public static int colorOf(String modid) { * * @param style The style to get the font for * @return The ImFont to use + * @deprecated Use {@link ImGuiMC#getStyleFont(Style)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated public static ImFont getStyleFont(Style style) { return ImGuiMC.getFont(Style.DEFAULT_FONT.equals(style.getFont()) ? EditorManager.DEFAULT_FONT : style.getFont(), style.isBold(), style.isItalic()); } @@ -214,7 +202,10 @@ public static ImFont getStyleFont(Style style) { * * @param color The ImGui color index * @return The ARGB ImGui color + * @deprecated Use {@link ImGuiMC#getColor(int)} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated public static int getColor(int color) { ImVec4 colors = ImGui.getStyle().getColors()[color]; return (int) (colors.w * 255) << 24 | (int) (colors.x * 255) << 16 | (int) (colors.y * 255) << 8 | (int) (colors.z * 255); @@ -222,156 +213,11 @@ public static int getColor(int color) { /** * @return A string splitter for ImGui fonts + * @deprecated Use {@link ImGuiMC#getStringSplitter()} instead */ + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + @Deprecated public static StringSplitter getStringSplitter() { - return IM_GUI_SPLITTER; - } - - @ApiStatus.Internal - private static class ImGuiCharSink implements FormattedCharSink { - - private ImFont font; - private int textColor; - private HoverEvent hoverEvent; - private ClickEvent clickEvent; - - private final StringBuilder buffer; - - private ImGuiCharSink() { - this.buffer = new StringBuilder(); - this.reset(); - } - - public void reset() { - this.font = ImGui.getFont(); - this.textColor = getColor(ImGuiCol.Text); - this.buffer.setLength(0); - this.hoverEvent = null; - this.clickEvent = null; - } - - @Override - public boolean accept(int positionInCurrentSequence, Style style, int codePoint) { - ImFont font = getStyleFont(style); - int styleColor = style.getColor() != null ? style.getColor().getValue() : this.textColor; - if (font != this.font || styleColor != this.textColor || style.getHoverEvent() != this.hoverEvent || style.getClickEvent() != this.clickEvent) { - if (!this.buffer.isEmpty()) { - this.finish(); - } - this.font = getStyleFont(style); - this.textColor = styleColor; - this.hoverEvent = style.getHoverEvent(); - this.clickEvent = style.getClickEvent(); - } - this.buffer.appendCodePoint(codePoint); - return true; - } - - public void finish() { - if (!this.buffer.isEmpty()) { - ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0, 0); - ImGui.pushFont(this.font); - ImGui.textColored(0xFF000000 | (this.textColor & 0xFF0000) >> 16 | (this.textColor & 0xFF00) | (this.textColor & 0xFF) << 16, this.buffer.toString()); - - if (ImGui.isItemClicked() && this.clickEvent != null) { - this.handleClick(); - } - if (ImGui.isItemHovered() && this.hoverEvent != null) { - this.handleHover(); - } - - ImGui.sameLine(); - ImGui.popFont(); - ImGui.popStyleVar(); - this.buffer.setLength(0); - } - } - - private void handleClick() { - Minecraft minecraft = Minecraft.getInstance(); - String value = this.clickEvent.getValue(); - if (this.clickEvent.getAction() == ClickEvent.Action.OPEN_URL) { - try { - URI uri = new URI(value); - String scheme = uri.getScheme(); - if (scheme == null) { - throw new URISyntaxException(value, "Missing protocol"); - } - - if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) { - throw new URISyntaxException(value, "Unsupported protocol: " + scheme.toLowerCase(Locale.ROOT)); - } - - Util.getPlatform().openUri(uri); - } catch (URISyntaxException e) { - Veil.LOGGER.error("Can't open url for {}", this.clickEvent, e); - } - return; - } - - if (this.clickEvent.getAction() == ClickEvent.Action.OPEN_FILE) { - Util.getPlatform().openUri(new File(value).toURI()); - return; - } - - // TODO - if (this.clickEvent.getAction() == ClickEvent.Action.SUGGEST_COMMAND) { - return; - } - - if (this.clickEvent.getAction() == ClickEvent.Action.RUN_COMMAND) { - String s = StringUtil.filterText(this.clickEvent.getValue()); - if (s.startsWith("/")) { - LocalPlayer player = Minecraft.getInstance().player; - if (player != null && !player.connection.sendUnsignedCommand(s.substring(1))) { - Veil.LOGGER.error("Not allowed to run command with signed argument from click event: '{}'", s); - } - } else { - Veil.LOGGER.error("Failed to run command without '/' prefix from click event: '{}'", s); - } - return; - } - - if (this.clickEvent.getAction() == ClickEvent.Action.COPY_TO_CLIPBOARD) { - minecraft.keyboardHandler.setClipboard(value); - return; - } - - Veil.LOGGER.error("Don't know how to handle {}", this.clickEvent); - } - - private void handleHover() { - Minecraft minecraft = Minecraft.getInstance(); - HoverEvent.ItemStackInfo stack = this.hoverEvent.getValue(HoverEvent.Action.SHOW_ITEM); - if (stack != null) { - ImGui.beginTooltip(); - List tooltip = Screen.getTooltipFromItem(minecraft, stack.getItemStack()); - for (Component line : tooltip) { - component(line, ImGui.getFontSize() * 35.0f); - } - ImGui.endTooltip(); - return; - } - - HoverEvent.EntityTooltipInfo entity = this.hoverEvent.getValue(HoverEvent.Action.SHOW_ENTITY); - if (entity != null) { - if (minecraft.options.advancedItemTooltips) { - ImGui.beginTooltip(); - List tooltip = entity.getTooltipLines(); - for (Component line : tooltip) { - component(line, ImGui.getFontSize() * 35.0f); - } - ImGui.endTooltip(); - } - return; - } - - Component showText = this.hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); - if (showText != null) { - ImGui.beginTooltip(); - component(showText, ImGui.getFontSize() * 35.0f); - ImGui.endTooltip(); - } - } + return ImGuiMC.getStringSplitter(); } } diff --git a/common/src/main/java/foundry/veil/api/client/render/framebuffer/AdvancedFboTextureAttachment.java b/common/src/main/java/foundry/veil/api/client/render/framebuffer/AdvancedFboTextureAttachment.java index 679a03216..1e090ad08 100644 --- a/common/src/main/java/foundry/veil/api/client/render/framebuffer/AdvancedFboTextureAttachment.java +++ b/common/src/main/java/foundry/veil/api/client/render/framebuffer/AdvancedFboTextureAttachment.java @@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.AbstractTexture; import net.minecraft.server.packs.resources.ResourceManager; import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.ByteBuffer; @@ -226,6 +227,6 @@ public void free() { } @Override - public void load(ResourceManager manager) { + public void load(@NotNull ResourceManager manager) { } } diff --git a/common/src/main/java/foundry/veil/api/resource/editor/BlockModelInspector.java b/common/src/main/java/foundry/veil/api/resource/editor/BlockModelInspector.java index db5cc68a0..fabdb99fc 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/BlockModelInspector.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/BlockModelInspector.java @@ -92,7 +92,7 @@ public void render() { BufferBuilder builder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); - for (BakedQuad quad : quads) { + for (BakedQuad quad : this.quads) { builder.putBulkData(POSE, quad, 1.0F, 1.0F, 1.0F, 1.0F, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY); } @@ -119,7 +119,7 @@ public void render() { }); if (ImGui.beginChild("3D View", desiredWidth / 2.0F + 2, desiredHeight / 2.0F + 2, false, ImGuiWindowFlags.NoScrollbar)) { - ImGui.image(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.1F); + ImGui.imageWithBg(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 0.1F, 1.0F, 1.0F, 1.0F, 1.0F); } ImGui.endChild(); } @@ -141,7 +141,7 @@ public void loadFromDisk() { Minecraft client = Minecraft.getInstance(); this.quads = new ObjectArrayList<>(); - try (Reader reader = resource.resourceInfo().openAsReader(resourceManager)) { + try (Reader reader = this.resource.resourceInfo().openAsReader(this.resourceManager)) { BlockModel unbaked = BlockModel.fromStream(reader); unbaked.resolveParents((location) -> { @@ -161,7 +161,7 @@ public void loadFromDisk() { Material material = unbaked.getMaterial(blockelementface.texture()); TextureAtlasSprite sprite = client.getTextureAtlas(material.atlasLocation()).apply(material.texture()); - quads.add(FACE_BAKERY.bakeQuad(blockelement.from, blockelement.to, blockelementface, sprite, direction, BlockModelRotation.X0_Y0, blockelement.rotation, blockelement.shade)); + this.quads.add(FACE_BAKERY.bakeQuad(blockelement.from, blockelement.to, blockelementface, sprite, direction, BlockModelRotation.X0_Y0, blockelement.rotation, blockelement.shade)); } } } catch (Exception e) { diff --git a/common/src/main/java/foundry/veil/api/resource/editor/EffectInspector.java b/common/src/main/java/foundry/veil/api/resource/editor/EffectInspector.java index d45b3b41f..f87efa6ca 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/EffectInspector.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/EffectInspector.java @@ -138,7 +138,7 @@ public void render() { if (ImGui.isWindowHovered()) { this.applyCameraChanges(); } - ImGui.image(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.1F); + ImGui.imageWithBg(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 0.1F, 1.0F, 1.0F, 1.0F, 1.0F); } ImGui.endChild(); } diff --git a/common/src/main/java/foundry/veil/api/resource/editor/FramebufferFileEditor.java b/common/src/main/java/foundry/veil/api/resource/editor/FramebufferFileEditor.java index fada80f2e..a06875061 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/FramebufferFileEditor.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/FramebufferFileEditor.java @@ -295,40 +295,41 @@ private static void text(Consumer text) { BUILDER.setLength(0); } + // TODO re-implement this when fonts can be accessed again private static void drawVerticalText(String next) { - ImFont font = ImGui.getFont(); - float pad = ImGui.getStyle().getFramePaddingX(); - float posX = ImGui.getCursorScreenPosX() + pad; - float posY = ImGui.getCursorScreenPosY() + pad; - - ImDrawList drawList = ImGui.getWindowDrawList(); - int length = next.length(); - drawList.primReserve(6 * length, 4 * length); - for (int i = 0; i < length; i++) { - int codePoint = next.codePointAt(i); - ImFontGlyph glyph = font.findGlyph(codePoint); - - posY -= font.getCharAdvance(codePoint); - drawList.primQuadUV( - (int) (posX + glyph.getY1()), - (int) (posY + glyph.getX0()), - (int) (posX + glyph.getY1()), - (int) (posY + glyph.getX1()), - (int) (posX + glyph.getY0()), - (int) (posY + glyph.getX1()), - (int) (posX + glyph.getY0()), - (int) (posY + glyph.getX0()), - - glyph.getU1(), - glyph.getV1(), - glyph.getU0(), - glyph.getV1(), - glyph.getU0(), - glyph.getV0(), - glyph.getU1(), - glyph.getV0(), - -1); - } +// ImFont font = ImGui.getFont(); +// float pad = ImGui.getStyle().getFramePaddingX(); +// float posX = ImGui.getCursorScreenPosX() + pad; +// float posY = ImGui.getCursorScreenPosY() + pad; +// +// ImDrawList drawList = ImGui.getWindowDrawList(); +// int length = next.length(); +// drawList.primReserve(6 * length, 4 * length); +// for (int i = 0; i < length; i++) { +// int codePoint = next.codePointAt(i); +// ImFontGlyph glyph = font.findGlyph(codePoint); +// +// posY -= font.getCharAdvance(codePoint); +// drawList.primQuadUV( +// (int) (posX + glyph.getY1()), +// (int) (posY + glyph.getX0()), +// (int) (posX + glyph.getY1()), +// (int) (posY + glyph.getX1()), +// (int) (posX + glyph.getY0()), +// (int) (posY + glyph.getX1()), +// (int) (posX + glyph.getY0()), +// (int) (posY + glyph.getX0()), +// +// glyph.getU1(), +// glyph.getV1(), +// glyph.getU0(), +// glyph.getV1(), +// glyph.getU0(), +// glyph.getV0(), +// glyph.getU1(), +// glyph.getV0(), +// -1); +// } } private void renderFramebufferSettings() { diff --git a/common/src/main/java/foundry/veil/api/resource/editor/ResourceOverrideEditor.java b/common/src/main/java/foundry/veil/api/resource/editor/ResourceOverrideEditor.java index 9be7f9c7a..9522a1616 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/ResourceOverrideEditor.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/ResourceOverrideEditor.java @@ -1,5 +1,6 @@ package foundry.veil.api.resource.editor; +import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.api.client.imgui.VeilImGuiUtil; import foundry.veil.api.resource.VeilEditorEnvironment; @@ -71,11 +72,11 @@ public void render() { return; } - VeilImGuiUtil.component(NAME); + ImGuiMC.component(NAME); VeilResourceManager resourceManager = this.environment.getResourceManager(); for (Path writePath : this.options) { - if (ImGui.selectable(writePath.toString(), false, ImGuiSelectableFlags.AllowItemOverlap)) { + if (ImGui.selectable(writePath.toString(), false, ImGuiSelectableFlags.AllowOverlap)) { Veil.LOGGER.info("Writing to {}", writePath); VeilResourceInfo info = this.veilResource.resourceInfo(); diff --git a/common/src/main/java/foundry/veil/api/resource/editor/ShellInspector.java b/common/src/main/java/foundry/veil/api/resource/editor/ShellInspector.java index 3a2ce654a..3cd7c60ae 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/ShellInspector.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/ShellInspector.java @@ -10,6 +10,7 @@ import foundry.veil.Veil; import foundry.veil.api.client.imgui.VeilImGuiUtil; import foundry.veil.api.client.render.rendertype.VeilRenderType; +import foundry.veil.api.client.render.vertex.VertexArray; import foundry.veil.api.flare.data.model.FlareShell; import foundry.veil.api.flare.model.BakedShell; import foundry.veil.api.resource.VeilEditorEnvironment; @@ -104,8 +105,9 @@ public void render() { RenderSystem.backupProjectionMatrix(); RenderSystem.setProjectionMatrix(projMat, VertexSorting.ORTHOGRAPHIC_Z); - shell.getVertexArray().bind(); - shell.getVertexArray().drawWithRenderType(renderType); + this.shell.getVertexArray().bind(); + this.shell.getVertexArray().drawWithRenderType(renderType); + VertexArray.unbind(); stack.popMatrix(); RenderSystem.restoreProjectionMatrix(); @@ -116,7 +118,7 @@ public void render() { if (ImGui.isWindowHovered()) { this.applyCameraChanges(); } - ImGui.image(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.1F); + ImGui.imageWithBg(texture, desiredWidth / 2.0F, desiredHeight / 2.0F, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.1F); } ImGui.endChild(); } diff --git a/common/src/main/java/foundry/veil/api/resource/editor/TextFileEditor.java b/common/src/main/java/foundry/veil/api/resource/editor/TextFileEditor.java index b5a9b0d93..03ded051c 100644 --- a/common/src/main/java/foundry/veil/api/resource/editor/TextFileEditor.java +++ b/common/src/main/java/foundry/veil/api/resource/editor/TextFileEditor.java @@ -1,13 +1,25 @@ package foundry.veil.api.resource.editor; +import foundry.veil.Veil; +import foundry.veil.api.client.imgui.CodeEditor; import foundry.veil.api.resource.VeilEditorEnvironment; +import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.api.resource.type.VeilTextResource; import imgui.ImGui; -import imgui.type.ImBoolean; +import imgui.extension.texteditor.TextEditor; +import imgui.extension.texteditor.TextEditorLanguage; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; + @ApiStatus.Internal public class TextFileEditor implements ResourceFileEditor> { @@ -15,14 +27,12 @@ public class TextFileEditor implements ResourceFileEditor> { private final VeilResourceManager resourceManager; private final VeilTextResource resource; -// private final CodeEditor editor; - - private final ImBoolean open = new ImBoolean(true); + private final CodeEditor editor; public TextFileEditor(VeilEditorEnvironment environment, VeilTextResource resource) { -// this.editor = new CodeEditor(SAVE); -// this.editor.show(resource.resourceInfo().fileName(), ""); -// this.editor.setSaveCallback(null); + this.editor = new CodeEditor(SAVE); + this.editor.show(resource.resourceInfo().fileName(), ""); + this.editor.setSaveCallback(null); this.resourceManager = environment.getResourceManager(); this.resource = resource; this.loadFromDisk(); @@ -30,12 +40,7 @@ public TextFileEditor(VeilEditorEnvironment environment, VeilTextResource res @Override public void render() { - if (ImGui.begin("Info", this.open)) { - ImGui.text("Text Editing is disabled for now. Use an external editor with hotswapping until re-implemented."); - } - ImGui.end(); - -// this.editor.renderWindow(); + this.editor.renderWindow(); if (ImGui.beginPopupModal("###open_failed")) { ImGui.text("Failed to open file"); ImGui.endPopup(); @@ -44,46 +49,45 @@ public void render() { @Override public void loadFromDisk() { -// VeilResourceInfo info = this.resource.resourceInfo(); -// TextEditorLanguageDefinition languageDefinition = this.resource.languageDefinition(); -// TextEditor editor = this.editor.getEditor(); -// -// editor.setReadOnly(true); + VeilResourceInfo info = this.resource.resourceInfo(); + TextEditorLanguage languageDefinition = this.resource.languageDefinition(); + TextEditor editor = this.editor.getEditor(); + + editor.setReadOnlyEnabled(true); // editor.setColorizerEnable(false); -// -// info.getResource(this.resourceManager).ifPresentOrElse(data -> CompletableFuture.supplyAsync(() -> { -// try (InputStream stream = data.open()) { -// return new String(stream.readAllBytes(), StandardCharsets.UTF_8); -// } catch (IOException e) { -// throw new CompletionException(e); -// } -// }, Util.ioPool()).handleAsync((contents, error) -> { -// if (error != null) { -// this.editor.hide(); -// ImGui.openPopup("###open_failed"); -// Veil.LOGGER.error("Failed to open file", error); -// return null; -// } -// -// this.editor.show(info.fileName(), contents); -// this.editor.setSaveCallback((source, errorMap) -> this.save(source.getBytes(StandardCharsets.UTF_8), this.resourceManager, this.resource)); -// -// editor.setReadOnly(info.isStatic()); -// if (languageDefinition != null) { + + info.getResource(this.resourceManager).ifPresentOrElse(data -> CompletableFuture.supplyAsync(() -> { + try (InputStream stream = data.open()) { + return new String(stream.readAllBytes(), StandardCharsets.UTF_8); + } catch (IOException e) { + throw new CompletionException(e); + } + }, Util.ioPool()).handleAsync((contents, error) -> { + if (error != null) { + this.editor.hide(); + ImGui.openPopup("###open_failed"); + Veil.LOGGER.error("Failed to open file", error); + return null; + } + + this.editor.show(info.fileName(), contents); + this.editor.setSaveCallback((source, errorMap) -> this.save(source.getBytes(StandardCharsets.UTF_8), this.resourceManager, this.resource)); + + editor.setReadOnlyEnabled(info.isStatic()); + if (languageDefinition != null) { // editor.setColorizerEnable(true); -// editor.setLanguageDefinition(languageDefinition); -// } -// return null; -// }, Minecraft.getInstance()), () -> { -// this.editor.hide(); -// ImGui.openPopup("###open_failed"); -// }); + editor.setLanguage(languageDefinition); + } + return null; + }, Minecraft.getInstance()), () -> { + this.editor.hide(); + ImGui.openPopup("###open_failed"); + }); } @Override public boolean isClosed() { - return !this.open.get(); -// return !this.editor.isOpen(); + return !this.editor.isOpen(); } @Override diff --git a/common/src/main/java/foundry/veil/api/resource/type/BlockModelResource.java b/common/src/main/java/foundry/veil/api/resource/type/BlockModelResource.java index 94e695aa5..9e250be0d 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/BlockModelResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/BlockModelResource.java @@ -7,6 +7,7 @@ import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.ModelInspectAction; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelManager; @@ -56,4 +57,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xF383; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/FlareResource.java b/common/src/main/java/foundry/veil/api/resource/type/FlareResource.java index fb43eed5f..daacf6e62 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/FlareResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/FlareResource.java @@ -6,6 +6,7 @@ import foundry.veil.impl.flare.FlareManager; import foundry.veil.impl.resource.action.TemplateInspectAction; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.util.profiling.InactiveProfiler; @@ -37,4 +38,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xEA1C; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/FramebufferResource.java b/common/src/main/java/foundry/veil/api/resource/type/FramebufferResource.java index e50b19a4a..abdb431ef 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/FramebufferResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/FramebufferResource.java @@ -12,6 +12,7 @@ import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.FramebufferEditAction; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import org.jetbrains.annotations.ApiStatus; import java.io.BufferedReader; @@ -46,4 +47,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xED0F; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/LanguageResource.java b/common/src/main/java/foundry/veil/api/resource/type/LanguageResource.java index cb31ea5c0..492098ca8 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/LanguageResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/LanguageResource.java @@ -4,6 +4,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.LanguageManager; import net.minecraft.server.packs.resources.ResourceManager; @@ -39,4 +40,8 @@ public int getIconCode() { return 0xEDCF; } + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/PostPipelineResource.java b/common/src/main/java/foundry/veil/api/resource/type/PostPipelineResource.java index b8539b6a5..d72c577f7 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/PostPipelineResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/PostPipelineResource.java @@ -5,6 +5,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.util.profiling.InactiveProfiler; @@ -36,4 +37,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xED0F; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/RenderTypeResource.java b/common/src/main/java/foundry/veil/api/resource/type/RenderTypeResource.java index d5fbd892d..ec71f6d0d 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/RenderTypeResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/RenderTypeResource.java @@ -5,6 +5,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.util.profiling.InactiveProfiler; @@ -36,4 +37,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xED0F; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/ShellResource.java b/common/src/main/java/foundry/veil/api/resource/type/ShellResource.java index 6498d4413..a3c4dbf28 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/ShellResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/ShellResource.java @@ -6,6 +6,7 @@ import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.ShellInspectAction; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.util.profiling.InactiveProfiler; @@ -35,4 +36,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xEDDF; } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/TextResource.java b/common/src/main/java/foundry/veil/api/resource/type/TextResource.java index 61d99a531..19ea83edb 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/TextResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/TextResource.java @@ -4,13 +4,16 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.List; @ApiStatus.Internal -public record TextResource(VeilResourceInfo resourceInfo, Type type) implements VeilTextResource { +public record TextResource(VeilResourceInfo resourceInfo, Type type, + @Nullable TextEditorLanguage languageDefinition) implements VeilTextResource { @Override public List> getActions() { @@ -33,14 +36,20 @@ public int getIconCode() { public enum Type { TEXT(".txt", 0xED0F), - JSON(".json", 0xECCD); + JSON(".json", 0xECCD, TextEditorLanguage.Json()); private final String extension; private final int icon; + private final TextEditorLanguage languageDefinition; - Type(String extension, int icon) { + Type(String extension, int icon, @Nullable TextEditorLanguage languageDefinition) { this.extension = extension; this.icon = icon; + this.languageDefinition = languageDefinition; + } + + Type(String extension, int icon) { + this(extension, icon, null); } public String getExtension() { @@ -50,5 +59,9 @@ public String getExtension() { public int getIcon() { return this.icon; } + + public @Nullable TextEditorLanguage getLanguageDefinition() { + return this.languageDefinition; + } } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/VanillaShaderFileResource.java b/common/src/main/java/foundry/veil/api/resource/type/VanillaShaderFileResource.java index 2f313de41..529fb2145 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VanillaShaderFileResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VanillaShaderFileResource.java @@ -6,6 +6,7 @@ import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; import foundry.veil.mixin.debug.accessor.DebugGameRendererAccessor; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.client.Minecraft; import org.jetbrains.annotations.ApiStatus; diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderDefinitionResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderDefinitionResource.java index 2fc0cec1d..2cb459655 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderDefinitionResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderDefinitionResource.java @@ -5,6 +5,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import org.jetbrains.annotations.ApiStatus; import java.io.IOException; @@ -57,4 +58,9 @@ public void hotReload(VeilResourceManager resourceManager) throws IOException { public int getIconCode() { return 0xED0F; // Text file icon } + + @Override + public TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Json(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderFileResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderFileResource.java index 16c45af34..dbd24369e 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderFileResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderFileResource.java @@ -8,6 +8,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderIncludeResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderIncludeResource.java index feca0213b..3a185931a 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderIncludeResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderIncludeResource.java @@ -8,6 +8,7 @@ import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; import foundry.veil.impl.resource.action.TextEditAction; +import imgui.extension.texteditor.TextEditorLanguage; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderResource.java index d615cd1ea..b3456c03f 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilShaderResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilShaderResource.java @@ -1,5 +1,6 @@ package foundry.veil.api.resource.type; +import imgui.extension.texteditor.TextEditorLanguage; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -10,8 +11,8 @@ default int getIconCode() { return 0xECD1; // Code file icon } -// @Override -// default @Nullable TextEditorLanguageDefinition languageDefinition() { -// return VeilLanguageDefinitions.glsl(); -// } + @Override + default TextEditorLanguage languageDefinition() { + return TextEditorLanguage.Glsl(); + } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java index 013a41781..9e4c4c3a3 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java @@ -1,10 +1,14 @@ package foundry.veil.api.resource.type; import foundry.veil.api.resource.VeilResource; +import imgui.extension.texteditor.TextEditorLanguage; +import org.jetbrains.annotations.Nullable; public interface VeilTextResource> extends VeilResource { // TODO re-implement -// @Nullable -// TextEditorLanguageDefinition languageDefinition(); + @Nullable + default TextEditorLanguage languageDefinition() { + return null; + } } diff --git a/common/src/main/java/foundry/veil/impl/client/editor/DeviceInfoViewer.java b/common/src/main/java/foundry/veil/impl/client/editor/DeviceInfoViewer.java index ccfdc5c84..4fd04b9cc 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/DeviceInfoViewer.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/DeviceInfoViewer.java @@ -1,6 +1,7 @@ package foundry.veil.impl.client.editor; import com.mojang.blaze3d.systems.RenderSystem; +import foundry.imgui.api.ImGuiMC; import foundry.veil.api.client.editor.SingleWindowInspector; import foundry.veil.api.client.imgui.VeilImGuiUtil; import foundry.veil.api.client.render.VeilRenderSystem; @@ -62,12 +63,12 @@ private static void text(String key, @Nullable String tooltip, @Nullable Object. .map(value -> value instanceof MutableComponent c ? c.withStyle(style -> style.withColor(0xFFFFFFFF)) : Component.literal(value.toString()).withStyle(style -> style.withColor(0xFFFFFFFF))) .toArray(); if (valueComponents.length == 0) { - VeilImGuiUtil.component(Component.translatable(key, UNSUPPORTED).withStyle(style -> style.withColor(VeilImGuiUtil.getColor(ImGuiCol.TextDisabled)))); + ImGuiMC.component(Component.translatable(key, UNSUPPORTED).withStyle(style -> style.withColor(ImGuiMC.getColor(ImGuiCol.TextDisabled)))); } else { - VeilImGuiUtil.component(Component.translatable(key, valueComponents)); + ImGuiMC.component(Component.translatable(key, valueComponents)); } } else { - VeilImGuiUtil.component(Component.translatable(key, UNSUPPORTED).withStyle(style -> style.withColor(VeilImGuiUtil.getColor(ImGuiCol.TextDisabled)))); + ImGuiMC.component(Component.translatable(key, UNSUPPORTED).withStyle(style -> style.withColor(ImGuiMC.getColor(ImGuiCol.TextDisabled)))); } if (tooltip != null) { ImGui.sameLine(); @@ -76,7 +77,7 @@ private static void text(String key, @Nullable String tooltip, @Nullable Object. } private static void flagText(String key, boolean supported, @Nullable String tooltip) { - VeilImGuiUtil.component(Component.translatable(key, supported ? YES : NO)); + ImGuiMC.component(Component.translatable(key, supported ? YES : NO)); if (tooltip != null) { ImGui.sameLine(); VeilImGuiUtil.tooltip(tooltip); @@ -85,7 +86,7 @@ private static void flagText(String key, boolean supported, @Nullable String too private static void title(Component component) { ImGui.pushStyleColor(ImGuiCol.Text, 0xFFFFFFFF); - VeilImGuiUtil.component(component); + ImGuiMC.component(component); ImGui.popStyleColor(); } diff --git a/common/src/main/java/foundry/veil/impl/client/editor/FramebufferInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/FramebufferInspector.java index c6df42179..690c2653a 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/FramebufferInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/FramebufferInspector.java @@ -1,6 +1,7 @@ package foundry.veil.impl.client.editor; import com.mojang.blaze3d.systems.RenderSystem; +import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.api.client.editor.SingleWindowInspector; import foundry.veil.api.client.imgui.VeilImGuiUtil; @@ -13,6 +14,8 @@ import foundry.veil.api.compat.IrisCompat; import foundry.veil.ext.iris.IrisRenderTargetExtension; import imgui.ImGui; +import imgui.flag.ImGuiCol; +import imgui.flag.ImGuiStyleVar; import imgui.type.ImBoolean; import net.minecraft.Util; import net.minecraft.client.Minecraft; @@ -175,7 +178,7 @@ private void drawBuffers(ResourceLocation id, @Nullable Consumer sa ImGui.beginGroup(); AdvancedFboTextureAttachment attachment = buffer.getColorTextureAttachment(i); ImGui.text(getAttachmentName(i, attachment.getId(), attachment.getName())); - ImGui.image(attachment.getId(), width, height, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.5F); + ImGuiMC.image(ImGuiMC.getTexture(attachment), width, height, 0, 1, 1, 0); ImGui.endGroup(); } @@ -186,7 +189,7 @@ private void drawBuffers(ResourceLocation id, @Nullable Consumer sa ImGui.beginGroup(); AdvancedFboTextureAttachment attachment = buffer.getDepthTextureAttachment(); ImGui.text(getAttachmentName(-1, attachment.getId(), attachment.getName())); - ImGui.image(attachment.getId(), width, height, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.5F); + ImGuiMC.image(ImGuiMC.getTexture(attachment), width, height, 0, 1, 1, 0); ImGui.endGroup(); } @@ -213,7 +216,7 @@ private void drawRenderTarget(ResourceLocation id, @Nullable IrisRenderTargetExt int texture = this.showAlt.get() ? renderTarget.veil$getAltTexture() : renderTarget.veil$getMainTexture(); ImGui.beginGroup(); ImGui.text(getAttachmentName(0, texture, this.showAlt.get() ? "Alt" : "Main")); - ImGui.image(texture, width, height, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.5F); + ImGui.imageWithBg(texture, width, height, 0, 1, 1, 0, 1.0F, 1.0F, 1.0F, 0.5F); ImGui.endGroup(); if (saveCallback != null && ImGui.button(SAVE.getString(), ImGui.getContentRegionAvailX() - 4, 0)) { diff --git a/common/src/main/java/foundry/veil/impl/client/editor/LightInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/LightInspector.java index 04604e60a..3b04c272b 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/LightInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/LightInspector.java @@ -1,5 +1,6 @@ package foundry.veil.impl.client.editor; +import foundry.imgui.api.ImGuiMC; import foundry.veil.api.client.color.Colorc; import foundry.veil.api.client.editor.EditorAttributeProvider; import foundry.veil.api.client.editor.SingleWindowInspector; @@ -20,7 +21,10 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.UUID; public class LightInspector extends SingleWindowInspector { @@ -32,7 +36,6 @@ public class LightInspector extends SingleWindowInspector { private static final Component REMOVE_ALL_DESC = Component.translatable("inspector.veil.light.button.remove_all.desc"); private static final Component SET_POSITION = Component.translatable("inspector.veil.light.button.set_position"); private static final Component ATTRIBUTES = Component.translatable("inspector.veil.light.attributes"); - private static final Component ENABLE_AO = Component.translatable("inspector.veil.light.toggle.ao"); private final List>> lightTypes = new ArrayList<>(); private ResourceKey> selectedTab; @@ -78,7 +81,8 @@ protected void renderComponents() { ImGui.sameLine(); ImGui.beginDisabled(lightType == null); if (ImGui.button(REMOVE.getString()) && lightType != null) { - for (LightRenderHandle handle : List.copyOf(lightRenderer.getLights(lightType))) { + List> lights = List.copyOf(lightRenderer.getLights(lightType)); + for (LightRenderHandle handle : lights) { handle.free(); } } @@ -156,7 +160,7 @@ private static void renderLightAttributeComponents(LightData lightData) { } ImGui.newLine(); - VeilImGuiUtil.component(ATTRIBUTES); + ImGuiMC.component(ATTRIBUTES); if (lightData instanceof EditorAttributeProvider editorAttributeProvider) { editorAttributeProvider.renderImGuiAttributes(); diff --git a/common/src/main/java/foundry/veil/impl/client/editor/PipelineStatisticsViewer.java b/common/src/main/java/foundry/veil/impl/client/editor/PipelineStatisticsViewer.java index 98f5bca46..af821b8d2 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/PipelineStatisticsViewer.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/PipelineStatisticsViewer.java @@ -1,5 +1,6 @@ package foundry.veil.impl.client.editor; +import foundry.imgui.api.ImGuiMC; import foundry.veil.api.client.editor.Inspector; import foundry.veil.api.client.imgui.VeilImGuiUtil; import foundry.veil.api.client.render.VeilRenderSystem; @@ -7,6 +8,7 @@ import foundry.veil.impl.client.render.profiler.VeilRenderProfilerImpl; import imgui.ImGui; import imgui.extension.implot.ImPlot; +import imgui.extension.implot.ImPlotSpec; import imgui.extension.implot.flag.*; import imgui.type.ImBoolean; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -23,6 +25,8 @@ @ApiStatus.Internal public class PipelineStatisticsViewer implements Inspector { + private static final ImPlotSpec PLOT_SPEC = new ImPlotSpec(); + public static final Component TITLE = Component.translatable("inspector.veil.pipeline_statistics.title"); public static final int HISTORY_LENGTH = 200; @@ -102,12 +106,13 @@ private void renderCounters(String path, RenderProfilerCounter sortedStatistic) ImPlot.setupAxesLimits(0, HISTORY_LENGTH, 0, Math.max(max * 1.1, 10), ImPlotCond.Always); ImPlot.setupAxisFormat(ImPlotAxis.Y1, "%3.0f"); - ImPlot.pushStyleColor(ImPlotCol.Line, VeilImGuiUtil.colorOf(statistic.name())); + // TODO make sure this is correct + final int colors = VeilImGuiUtil.colorOf(statistic.name()); + PLOT_SPEC.setLineColor((colors & 0xFF) / 255.0F, ((colors >> 8) & 0xFF) / 255.0F, ((colors >> 16) & 0xFF) / 255.0F, ((colors >> 24) & 0xFF) / 255.0F); ImPlot.pushStyleVar(ImPlotStyleVar.PlotPadding, 0.0F, 0.0F); ImPlot.pushStyleVar(ImPlotStyleVar.LabelPadding, 0.0F, 0.0F); - ImPlot.plotLine(statistic.name(), values); + ImPlot.plotLine(statistic.name(), values, -1, -1, PLOT_SPEC); ImPlot.popStyleVar(); - ImPlot.popStyleColor(); ImPlot.endPlot(); } diff --git a/common/src/main/java/foundry/veil/impl/client/editor/PostInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/PostInspector.java index 4aa0375b4..a4e73c4da 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/PostInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/PostInspector.java @@ -1,5 +1,6 @@ package foundry.veil.impl.client.editor; +import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.api.client.editor.SingleWindowInspector; import foundry.veil.api.client.imgui.VeilImGuiUtil; @@ -50,7 +51,7 @@ public void renderComponents() { ImGui.setNextItemWidth(availableWidth / 2); ImGui.beginGroup(); - VeilImGuiUtil.component(INACTIVE); + ImGuiMC.component(INACTIVE); if (ImGui.beginListBox("##available_pipelines", availableWidth / 2, 0)) { for (ResourceLocation entry : postProcessingManager.getPipelines()) { if (postProcessingManager.isActive(entry) || isInternal(entry)) { @@ -85,7 +86,7 @@ public void renderComponents() { ImGui.setNextItemWidth(availableWidth / 2); ImGui.beginGroup(); - VeilImGuiUtil.component(ACTIVE); + ImGuiMC.component(ACTIVE); if (ImGui.beginListBox("##shaders", availableWidth / 2, 0)) { List pipelines = postProcessingManager.getActivePipelines(); diff --git a/common/src/main/java/foundry/veil/impl/client/editor/ResourceManagerInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/ResourceManagerInspector.java index 260aefa86..dce2963b0 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/ResourceManagerInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/ResourceManagerInspector.java @@ -50,7 +50,7 @@ public void renderComponents() { ImGui.inputTextWithHint("##search", SEARCH.getString(), this.searchText); ImGui.sameLine(); - ImGui.pushFont(ImGuiMC.getFont(VeilImGuiUtil.ICON_FONT, false, false)); + ImGui.pushFont(ImGuiMC.getFont(VeilImGuiUtil.ICON_FONT, false, false), 0); // Add button ImGui.beginDisabled(); @@ -148,7 +148,7 @@ public void accept(int index) { VeilResource resource = resources.get(index); float startX = ImGui.getCursorScreenPosX(); - ImGui.selectable("##" + resource.resourceInfo().location(), false, ImGuiSelectableFlags.AllowItemOverlap, ImGui.getContentRegionAvailX(), 22f); + ImGui.selectable("##" + resource.resourceInfo().location(), false, ImGuiSelectableFlags.AllowOverlap, ImGui.getContentRegionAvailX(), 22f); ImGui.setNextItemAllowOverlap(); ImGui.sameLine(); @@ -206,7 +206,7 @@ public void accept(int index) { VeilResource resource = resources.get(index); float startX = ImGui.getCursorScreenPosX(); - ImGui.selectable("##" + resource.resourceInfo().location(), false, ImGuiSelectableFlags.AllowItemOverlap, ImGui.getContentRegionAvailX(), cellHeight); + ImGui.selectable("##" + resource.resourceInfo().location(), false, ImGuiSelectableFlags.AllowOverlap, ImGui.getContentRegionAvailX(), cellHeight); ImGui.setNextItemAllowOverlap(); ImGui.sameLine(); diff --git a/common/src/main/java/foundry/veil/impl/client/editor/ShaderInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/ShaderInspector.java index 4dec4b75b..31569b3b8 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/ShaderInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/ShaderInspector.java @@ -1,6 +1,7 @@ package foundry.veil.impl.client.editor; import com.mojang.blaze3d.systems.RenderSystem; +import foundry.imgui.api.ImGuiMC; import foundry.veil.Veil; import foundry.veil.api.client.editor.SingleWindowInspector; import foundry.veil.api.client.imgui.VeilImGuiUtil; @@ -163,7 +164,7 @@ protected void renderComponents() { this.removedDefinitions.clear(); ImGui.beginChild("##shader_programs", ImGui.getContentRegionAvailX() * 2 / 3, 0); - VeilImGuiUtil.component(SHADER_PROGRAMS); + ImGuiMC.component(SHADER_PROGRAMS); TabSource[] sources = TabSource.values(); if (ImGui.beginTabBar("##controls")) { @@ -237,7 +238,7 @@ protected void renderComponents() { ImGui.sameLine(); if (ImGui.beginChild("##panel", 0, ImGui.getContentRegionAvailY())) { if (ImGui.beginChild("##open_source", 0, ImGui.getContentRegionAvailY() / 2)) { - VeilImGuiUtil.component(OPEN_SOURCE); + ImGuiMC.component(OPEN_SOURCE); this.openShaderButton(GL_FRAGMENT_SHADER); this.openShaderButton(GL_VERTEX_SHADER); @@ -255,7 +256,7 @@ protected void renderComponents() { ImGui.endChild(); if (ImGui.beginChild("##shader_definitions", 0, ImGui.getContentRegionAvailY())) { - VeilImGuiUtil.component(SHADER_DEFINITIONS); + ImGuiMC.component(SHADER_DEFINITIONS); ImGui.setNextItemWidth(ImGui.getContentRegionAvailX()); if (ImGui.inputTextWithHint("##add_definition", SHADER_DEFINITIONS_HINT.getString(), this.addDefinitionText, ImGuiInputTextFlags.EnterReturnsTrue)) { String[] parts = this.addDefinitionText.get().split("=", 2); diff --git a/common/src/main/java/foundry/veil/impl/client/editor/TextureInspector.java b/common/src/main/java/foundry/veil/impl/client/editor/TextureInspector.java index 3bd6be72a..9d1928374 100644 --- a/common/src/main/java/foundry/veil/impl/client/editor/TextureInspector.java +++ b/common/src/main/java/foundry/veil/impl/client/editor/TextureInspector.java @@ -353,7 +353,7 @@ private void addImage(int selectedId, boolean flipX, boolean flipY) { float size = ImGui.getContentRegionAvailX(); cubemapStorage.render((int) size, (int) (size / 2.0F)); - ImGui.image(cubemapStorage.renderedTextureId(), size, size / 2.0F, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); + ImGui.imageWithBg(cubemapStorage.renderedTextureId(), size, size / 2.0F, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); } else if (target == GL_TEXTURE_2D_ARRAY) { TextureStorage storage = this.textureStorage.get(selectedId); if (!(storage instanceof ArrayStorage)) { @@ -371,7 +371,7 @@ private void addImage(int selectedId, boolean flipX, boolean flipY) { arrayStorage.render(selectedId, width, height, depth); for (int i = 0; i < depth; i++) { - ImGui.image(arrayStorage.renderedTextureId(i), size, size * (float) height / (float) width, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); + ImGui.imageWithBg(arrayStorage.renderedTextureId(i), size, size * (float) height / (float) width, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); } } else if (target == GL_TEXTURE_2D) { TextureStorage storage = this.textureStorage.remove(selectedId); @@ -382,7 +382,7 @@ private void addImage(int selectedId, boolean flipX, boolean flipY) { int width = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH); int height = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT); float size = ImGui.getContentRegionAvailX(); - ImGui.image(selectedId, size, size * (float) height / (float) width, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); + ImGui.imageWithBg(selectedId, size, size * (float) height / (float) width, flipX ? 1 : 0, flipY ? 1 : 0, flipX ? 0 : 1, flipY ? 0 : 1, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F); } } diff --git a/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java b/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java index c20b30170..a3744dfcc 100644 --- a/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java +++ b/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java @@ -6,6 +6,10 @@ import foundry.veil.api.client.render.VeilRenderSystem; import foundry.veil.impl.client.editor.*; import foundry.veil.platform.VeilEventPlatform; +import imgui.ImGui; +import imgui.ImGuiViewport; +import imgui.flag.ImGuiConfigFlags; +import imgui.flag.ImGuiDockNodeFlags; import net.minecraft.client.KeyMapping; import org.jetbrains.annotations.ApiStatus; @@ -18,12 +22,13 @@ private VeilImGuiCompat() { } public static void load() { - ImGuiMCEvents.INSTANCE.preRenderImGuiEvents(() -> { + ImGuiMCEvents.INSTANCE.imGuiLoadPre(() -> ImGui.getIO().addConfigFlags(ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable)); + ImGuiMCEvents.INSTANCE.preRenderImGuiEvent(() -> { VeilImGuiStylesheet.initStyles(); AdvancedFboImGuiAreaImpl.begin(); VeilRenderSystem.renderer().getEditorManager().render(); }); - ImGuiMCEvents.INSTANCE.postRenderImGuiEvents(() -> { + ImGuiMCEvents.INSTANCE.postRenderImGuiEvent(() -> { VeilImGuiStylesheet.initStyles(); VeilRenderSystem.renderer().getEditorManager().renderLast(); AdvancedFboImGuiAreaImpl.end(); diff --git a/common/src/main/java/foundry/veil/impl/resource/VeilResourceRenderer.java b/common/src/main/java/foundry/veil/impl/resource/VeilResourceRenderer.java index baedc8ee2..a12147b3d 100644 --- a/common/src/main/java/foundry/veil/impl/resource/VeilResourceRenderer.java +++ b/common/src/main/java/foundry/veil/impl/resource/VeilResourceRenderer.java @@ -1,5 +1,6 @@ package foundry.veil.impl.resource; +import foundry.imgui.api.ImGuiMC; import foundry.veil.api.client.imgui.VeilImGuiUtil; import foundry.veil.api.client.render.VeilRenderSystem; import foundry.veil.api.resource.VeilResource; @@ -61,7 +62,7 @@ public static void renderFilename(VeilResource resource, boolean fullName) { VeilImGuiUtil.icon(0xEB91); ImGui.sameLine(); ImGui.popStyleVar(); - VeilImGuiUtil.component(COPY_PATH); + ImGuiMC.component(COPY_PATH); ImGui.beginDisabled(info.isStatic()); if (ImGui.selectable("##open_folder")) { @@ -77,7 +78,7 @@ public static void renderFilename(VeilResource resource, boolean fullName) { VeilImGuiUtil.icon(0xECAF); ImGui.sameLine(); ImGui.popStyleVar(); - VeilImGuiUtil.component(OPEN_FOLDER); + ImGuiMC.component(OPEN_FOLDER); ImGui.endDisabled(); for (int i = 0; i < actions.size(); i++) { @@ -94,7 +95,7 @@ public static void renderFilename(VeilResource resource, boolean fullName) { ImGui.sameLine(); }); ImGui.popStyleVar(); - VeilImGuiUtil.component(action.getName()); + ImGuiMC.component(action.getName()); } ImGui.popStyleVar(); diff --git a/common/src/main/java/foundry/veil/impl/resource/loader/TextResourceLoader.java b/common/src/main/java/foundry/veil/impl/resource/loader/TextResourceLoader.java index dfaa41107..6d0788466 100644 --- a/common/src/main/java/foundry/veil/impl/resource/loader/TextResourceLoader.java +++ b/common/src/main/java/foundry/veil/impl/resource/loader/TextResourceLoader.java @@ -15,9 +15,11 @@ public class TextResourceLoader implements VeilResourceLoader { + private static final TextResource.Type[] RESOURCE_TYPES = TextResource.Type.values(); + @Override public boolean canLoad(PackType packType, ResourceLocation location, @Nullable Path filePath, @Nullable Path modResourcePath) { - for (TextResource.Type type : TextResource.Type.values()) { + for (TextResource.Type type : RESOURCE_TYPES) { if (location.getPath().endsWith(type.getExtension())) { return true; } @@ -27,9 +29,9 @@ public boolean canLoad(PackType packType, ResourceLocation location, @Nullable P @Override public VeilResource load(VeilResourceManager resourceManager, ResourceProvider provider, PackType packType, ResourceLocation location, @Nullable Path filePath, @Nullable Path modResourcePath) throws IOException { - for (TextResource.Type type : TextResource.Type.values()) { + for (TextResource.Type type : RESOURCE_TYPES) { if (location.getPath().endsWith(type.getExtension())) { - return new TextResource(new VeilResourceInfo(packType, location, filePath, modResourcePath, false), type); + return new TextResource(new VeilResourceInfo(packType, location, filePath, modResourcePath, false), type, type.getLanguageDefinition()); } } throw new IOException("Unknown text resource: " + location); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index b8ac21115..644bfe7af 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -68,11 +68,14 @@ "minecraft": "~${minecraft_version}", "java": ">=${java_version}" }, + "suggests": { + "imguimc": ">=${imguimc_version}" + }, "breaks": { "sodium": "<${sodium_version}", "embeddium": "*", "celeritas": "*", - "imguimc": ["<${imguimc_version}", ">=2.0.0"] + "imguimc": ["<${imguimc_version}", ">=3.0.0"] }, "accessWidener": "veil.accesswidener" } diff --git a/gradle.properties b/gradle.properties index 78e12b479..7bc09cf7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ parchment_version=2024.11.17 # Dependencies molang_compiler_version=3.1.1.19 glsl_processor_version=0.2.3 -imguimc_version=1.1.0 +imguimc_version=2.0.0 lwjgl_version=3.3.3 # There is no 0.8.12-alpha.3 for NeoForge, so just use 0.8.12-alpha.2 sodium_version=0.8.12-alpha.2+mc1.21.1 diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 5137ed73d..110cfe7d4 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -77,5 +77,5 @@ description='''${description}''' [[dependencies.${mod_id}]] modId = "imguimc" type = "optional" - versionRange = "[${imguimc_version},2.0.0)" - reason = "${mod_name} supports imguimc ${imguimc_version} to 2.0.0" \ No newline at end of file + versionRange = "[${imguimc_version},3.0.0)" + reason = "${mod_name} supports imguimc ${imguimc_version} to 3.0.0" \ No newline at end of file From 52717a3159db393a368fdcbd5dadf7da7da0f083 Mon Sep 17 00:00:00 2001 From: Ocelot Date: Fri, 19 Jun 2026 10:34:43 -0600 Subject: [PATCH 2/3] Fix crash on startup --- .../veil/api/resource/type/TextResource.java | 17 +++++++++++------ .../api/resource/type/VeilTextResource.java | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/foundry/veil/api/resource/type/TextResource.java b/common/src/main/java/foundry/veil/api/resource/type/TextResource.java index 19ea83edb..d18a08f60 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/TextResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/TextResource.java @@ -1,5 +1,6 @@ package foundry.veil.api.resource.type; +import foundry.veil.Veil; import foundry.veil.api.resource.VeilResourceAction; import foundry.veil.api.resource.VeilResourceInfo; import foundry.veil.api.resource.VeilResourceManager; @@ -10,10 +11,14 @@ import java.io.IOException; import java.util.List; +import java.util.function.Supplier; @ApiStatus.Internal -public record TextResource(VeilResourceInfo resourceInfo, Type type, - @Nullable TextEditorLanguage languageDefinition) implements VeilTextResource { +public record TextResource( + VeilResourceInfo resourceInfo, + Type type, + @Nullable TextEditorLanguage languageDefinition +) implements VeilTextResource { @Override public List> getActions() { @@ -36,13 +41,13 @@ public int getIconCode() { public enum Type { TEXT(".txt", 0xED0F), - JSON(".json", 0xECCD, TextEditorLanguage.Json()); + JSON(".json", 0xECCD, TextEditorLanguage::Json); private final String extension; private final int icon; - private final TextEditorLanguage languageDefinition; + private final Supplier languageDefinition; - Type(String extension, int icon, @Nullable TextEditorLanguage languageDefinition) { + Type(String extension, int icon, @Nullable Supplier languageDefinition) { this.extension = extension; this.icon = icon; this.languageDefinition = languageDefinition; @@ -61,7 +66,7 @@ public int getIcon() { } public @Nullable TextEditorLanguage getLanguageDefinition() { - return this.languageDefinition; + return Veil.IMGUIMC && this.languageDefinition != null ? this.languageDefinition.get() : null; } } } diff --git a/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java b/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java index 9e4c4c3a3..5c6384605 100644 --- a/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java +++ b/common/src/main/java/foundry/veil/api/resource/type/VeilTextResource.java @@ -6,7 +6,10 @@ public interface VeilTextResource> extends VeilResource { - // TODO re-implement + /** + * @return The text language definition for this resource or null to disable syntax highlighting + * @since 4.3.0 + */ @Nullable default TextEditorLanguage languageDefinition() { return null; From 1eccc785bc350df23835dd243887f2771b2d6e56 Mon Sep 17 00:00:00 2001 From: Ocelot Date: Fri, 19 Jun 2026 10:41:07 -0600 Subject: [PATCH 3/3] Disable PipelineStatisticsViewer for now --- .../java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java b/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java index a3744dfcc..de6f1eaa2 100644 --- a/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java +++ b/common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiCompat.java @@ -41,7 +41,8 @@ public static void load() { // Debug editors registry.registerInspector(new DeviceInfoViewer()); - registry.registerInspector(new PipelineStatisticsViewer()); + // TODO fix +// registry.registerInspector(new PipelineStatisticsViewer()); registry.registerInspector(new PostInspector()); registry.registerInspector(new ShaderInspector()); registry.registerInspector(new TextureInspector());