diff --git a/assets/Data/menu/npcintro.html b/assets/Data/menu/npcintro.html index d83855d2..92ae389d 100644 --- a/assets/Data/menu/npcintro.html +++ b/assets/Data/menu/npcintro.html @@ -5,4 +5,4 @@ testClass { }
Hello!
- \ No newline at end of file + \ No newline at end of file diff --git a/assets/Data/menu/testwindow.html b/assets/Data/menu/testwindow.html new file mode 100644 index 00000000..0634bc56 --- /dev/null +++ b/assets/Data/menu/testwindow.html @@ -0,0 +1,8 @@ + +Test window!
+ \ No newline at end of file diff --git a/assets/Scripts/client/uihooks.ts b/assets/Scripts/client/uihooks.ts index f50eac58..f5b35bee 100644 --- a/assets/Scripts/client/uihooks.ts +++ b/assets/Scripts/client/uihooks.ts @@ -8,6 +8,10 @@ export const clientUIButtonHook: Hook = { signal: "uiButton", callback: (engine: Engine, data: string) => { - console.log("button clicked " + data) + if(data.length > 4 && data.substring(0,9) === "openDiag("){ + engine.classes.menuUtils.static.openDialog(data.substring(9,data.length - 1)) + } else { + console.log("button clicked " + data) + } } } \ No newline at end of file diff --git a/assets/Scripts/types/host/renderer/ui/menus.ts b/assets/Scripts/types/host/renderer/ui/menus.ts index efde5d86..65acc5b4 100644 --- a/assets/Scripts/types/host/renderer/ui/menus.ts +++ b/assets/Scripts/types/host/renderer/ui/menus.ts @@ -18,4 +18,10 @@ export interface MenuUtils { */ readonly openFabSelection: () => void + /** + * Opens the dialog specied at the given path + * @param path The path to the dialog to open + */ + readonly openDialog: (path: string) => void + } \ No newline at end of file diff --git a/docs/src/progress/bigthings.md b/docs/src/progress/bigthings.md index efb0bd88..8f9f31cb 100644 --- a/docs/src/progress/bigthings.md +++ b/docs/src/progress/bigthings.md @@ -25,7 +25,6 @@ TODO(?): (ie 10k armies) - Use HTML to define ui windows - - Some css support - Language file for translation - Live reloading of scripts diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 66f66ac4..2a47251a 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1684,6 +1684,7 @@ Add JSoup dependency Proof of concept of loading html to define ui Styling support for html-defined menus Dynamic html-defined menus support button elements that call a client hook when clicked +Dynamic menu navigation between windows diff --git a/src/main/java/electrosphere/client/interact/ButtonInteraction.java b/src/main/java/electrosphere/client/interact/ButtonInteraction.java index f0583493..8e533a11 100644 --- a/src/main/java/electrosphere/client/interact/ButtonInteraction.java +++ b/src/main/java/electrosphere/client/interact/ButtonInteraction.java @@ -59,7 +59,7 @@ public class ButtonInteraction { Globals.clientConnection.queueOutgoingMessage(EntityMessage.constructinteractMessage(serverEntityId, InteractionData.ON_INTERACT_DOOR)); } break; case InteractionData.ON_INTERACT_DIALOG: { - DialogMenuGenerator.displayDialog(target); + DialogMenuGenerator.displayEntityDialog(target); } break; default: { throw new Error("Unhandled interaction signal " + interactionData.getOnInteract()); diff --git a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiUIFramework.java b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiUIFramework.java index 582bd428..fde1f5d1 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/ImGuiUIFramework.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/ImGuiUIFramework.java @@ -46,7 +46,11 @@ public class ImGuiUIFramework { } if(ImGui.button("Test load dialog")){ - DialogMenuGenerator.displayDialog("Data/menu/npcintro.html"); + DialogMenuGenerator.createDialogWindow("Data/menu/npcintro.html"); + } + + if(ImGui.button("Reload dynamic menus")){ + DialogMenuGenerator.refresh(); } } diff --git a/src/main/java/electrosphere/client/ui/menu/dialog/DialogMenuGenerator.java b/src/main/java/electrosphere/client/ui/menu/dialog/DialogMenuGenerator.java index 6d44a952..4fa2028b 100644 --- a/src/main/java/electrosphere/client/ui/menu/dialog/DialogMenuGenerator.java +++ b/src/main/java/electrosphere/client/ui/menu/dialog/DialogMenuGenerator.java @@ -26,13 +26,29 @@ import electrosphere.util.FileUtils; */ public class DialogMenuGenerator { + /** + * The currently displayed dialog's path + */ + static String currentDialog = null; + /** * Displays the appropriate dialog for opening a dialog window with a given entity * @param target The entity */ - public static void displayDialog(Entity target){ - WindowUtils.replaceWindow(WindowStrings.NPC_DIALOG, DialogMenuGenerator.displayDialog("Data/menu/npcintro.html")); - Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + public static void displayEntityDialog(Entity target){ + //TODO: logic to determine what menu to actually display + DialogMenuGenerator.currentDialog = "Data/menu/npcintro.html"; + DialogMenuGenerator.refresh(); + } + + /** + * Displays the appropriate dialog for opening a dialog window with a given entity + * @param target The entity + */ + public static void displayDialogPath(String path){ + //TODO: logic to determine what menu to actually display + DialogMenuGenerator.currentDialog = path; + DialogMenuGenerator.refresh(); } /** @@ -40,7 +56,8 @@ public class DialogMenuGenerator { * @param path The path to the html * @return The element that is the root for the window */ - public static Window displayDialog(String path){ + public static Window createDialogWindow(String path){ + DialogMenuGenerator.currentDialog = path; // //Boilerplate for window itself // @@ -77,4 +94,12 @@ public class DialogMenuGenerator { return rVal; } + /** + * Refreshes the currently displayed dialog + */ + public static void refresh(){ + WindowUtils.replaceWindow(WindowStrings.NPC_DIALOG, DialogMenuGenerator.createDialogWindow(DialogMenuGenerator.currentDialog)); + Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + } + } diff --git a/src/main/java/electrosphere/client/ui/menu/script/ScriptMenuUtils.java b/src/main/java/electrosphere/client/ui/menu/script/ScriptMenuUtils.java index ae96e795..daaec3c0 100644 --- a/src/main/java/electrosphere/client/ui/menu/script/ScriptMenuUtils.java +++ b/src/main/java/electrosphere/client/ui/menu/script/ScriptMenuUtils.java @@ -4,6 +4,7 @@ import org.graalvm.polyglot.HostAccess.Export; import electrosphere.client.ui.menu.WindowStrings; import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.client.ui.menu.dialog.DialogMenuGenerator; import electrosphere.client.ui.menu.ingame.FabMenus; import electrosphere.client.ui.menu.ingame.MenuGeneratorsTerrainEditing; import electrosphere.controls.ControlHandler.ControlsState; @@ -41,4 +42,13 @@ public class ScriptMenuUtils { Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); } + /** + * Opens a specified dialog + */ + @Export + public static void openDialog(String path){ + String sanitized = path.replace("\"", "").replace("'", ""); + DialogMenuGenerator.displayDialogPath(sanitized); + } + }