dynamic menu navigation
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-05 20:01:38 -04:00
parent cbdfb63663
commit e3ab44227f
10 changed files with 66 additions and 9 deletions

View File

@ -5,4 +5,4 @@ testClass {
}
</style>
<p class="testClass">Hello!</p>
<button onclick="testButton()">Test button!</button>
<button onclick="openDiag('Data/menu/testwindow.html')">Test button!</button>

View File

@ -0,0 +1,8 @@
<style>
testClass {
margin-top: "50px";
margin-left: "50px";
}
</style>
<p class="testClass">Test window!</p>
<button onclick="openDiag('Data/menu/npcintro.html')">Back!</button>

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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());

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}