proof of concept of loading html to define ui
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-05 17:53:33 -04:00
parent c72903794c
commit 800c45033b
7 changed files with 106 additions and 1 deletions

View File

@ -20,4 +20,5 @@
- [yoga](https://github.com/facebook/yoga) --- [MIT](https://github.com/facebook/yoga/blob/main/LICENSE) - [yoga](https://github.com/facebook/yoga) --- [MIT](https://github.com/facebook/yoga/blob/main/LICENSE)
- [MathUtils](https://github.com/StudioRailgun/MathUtils) --- [MIT](https://github.com/StudioRailgun/MathUtils/blob/main/LICENSE) - [MathUtils](https://github.com/StudioRailgun/MathUtils) --- [MIT](https://github.com/StudioRailgun/MathUtils/blob/main/LICENSE)
- [DataStructures](https://github.com/StudioRailgun/DataStructures) --- [MIT](https://github.com/StudioRailgun/DataStructures/blob/main/LICENSE) - [DataStructures](https://github.com/StudioRailgun/DataStructures) --- [MIT](https://github.com/StudioRailgun/DataStructures/blob/main/LICENSE)
- [Typescript](https://github.com/microsoft/TypeScript) --- [Apache 2](https://github.com/microsoft/TypeScript/blob/main/LICENSE.txt) - [Typescript](https://github.com/microsoft/TypeScript) --- [Apache 2](https://github.com/microsoft/TypeScript/blob/main/LICENSE.txt)
- [JSoup](https://jsoup.org/) --- [MIT](https://github.com/jhy/jsoup/blob/master/LICENSE)

View File

@ -0,0 +1 @@
<p>Hello!</p>

View File

@ -1680,6 +1680,8 @@ Block pathing work
(05/05/2025) (05/05/2025)
Scaffolding for structure scanning service Scaffolding for structure scanning service
Add JSoup dependency
Proof of concept of loading html to define ui

View File

@ -296,6 +296,14 @@
<classifier>${lwjgl.natives}</classifier> <classifier>${lwjgl.natives}</classifier>
</dependency> </dependency>
<!--JSoup-->
<!--License: MIT-->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.20.1</version>
</dependency>
<!--MathUtils--> <!--MathUtils-->
<!--License: MIT--> <!--License: MIT-->
<dependency> <dependency>
@ -313,6 +321,7 @@
</dependency> </dependency>
</dependencies> </dependencies>
<profiles> <profiles>

View File

@ -1,5 +1,6 @@
package electrosphere.client.ui.menu.debug; package electrosphere.client.ui.menu.debug;
import electrosphere.client.ui.menu.dialog.DialogMenuGenerator;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.debug.DebugRendering; import electrosphere.renderer.debug.DebugRendering;
@ -44,6 +45,10 @@ public class ImGuiUIFramework {
printUITrees(); printUITrees();
} }
if(ImGui.button("Test load dialog")){
DialogMenuGenerator.displayDialog("Data/menu/npcintro.html");
}
} }
}); });
uiFrameworkWindow.setOpen(false); uiFrameworkWindow.setOpen(false);

View File

@ -0,0 +1,41 @@
package electrosphere.client.ui.menu.dialog;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Node;
import electrosphere.client.ui.parsing.HtmlParser;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elementtypes.Element;
import electrosphere.util.FileUtils;
/**
* Generates dialog menus
*/
public class DialogMenuGenerator {
/**
* Displays a dialog menu
* @param path The path to the html
* @return The element that is the root for the window
*/
public static Element displayDialog(String path){
Div container = Div.createCol();
try {
String content = FileUtils.getAssetFileAsString(path);
Document doc = Jsoup.parseBodyFragment(content);
Node bodyNode = doc.getElementsByTag("body").first();
for(Node node : bodyNode.childNodes()){
container.addChild(
HtmlParser.recursivelyParseChildren(node));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return container;
}
}

View File

@ -0,0 +1,46 @@
package electrosphere.client.ui.parsing;
import org.jsoup.nodes.Node;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elementtypes.Element;
/**
* Converts HTML to engine elements
*/
public class HtmlParser {
/**
* Recursively parses a jsoup node into engine ui elements
* @param jsoupNode The jsoup node
* @return The engine ui elements
*/
public static Element recursivelyParseChildren(Node jsoupNode){
String tag = jsoupNode.nodeName();
Element rVal = null;
switch(tag){
case "p": {
rVal = Div.createDiv();
for(Node child : jsoupNode.childNodes()){
((Div)rVal).addChild(HtmlParser.recursivelyParseChildren(child));
}
} break;
case "#text": {
String content = jsoupNode.outerHtml();
rVal = Label.createLabel(content);
} break;
case "div": {
rVal = Div.createDiv();
for(Node child : jsoupNode.childNodes()){
((Div)rVal).addChild(HtmlParser.recursivelyParseChildren(child));
}
} break;
default: {
throw new Error("Unsupported element type " + tag);
}
}
return Div.createDiv();
}
}