dynamic menu navigation
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
cbdfb63663
commit
e3ab44227f
@ -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>
|
||||
8
assets/Data/menu/testwindow.html
Normal file
8
assets/Data/menu/testwindow.html
Normal 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>
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user