show tutorial hints from script side
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-07-20 10:18:34 -04:00
parent e00eb85bcb
commit f7015bd614
8 changed files with 68 additions and 7 deletions

View File

@ -49,7 +49,14 @@ class TestScene1 extends Scene {
signal: "itemPickup",
callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
console.log(entityId + ' picked up an item, destroying ' + inWorldItemEntityId + ' and creating ' + inInventoryItemEntityId)
engine.classes.simulation.static.setFramestep(2)
engine.classes.simulation.static.setFramestep(0)
engine.classes.tutorialUtils.static.showTutorialHint(
"BasicNavigation",
true,
() => {
engine.classes.simulation.static.setFramestep(2)
}
)
}
},

View File

@ -25,5 +25,7 @@ export const ENGINE_onInit = () => {
engine.sceneLoader.engine = engine
engine.hookManager.engine = engine
console.log(Object.keys(engine.classes))
loggerScripts.INFO('Script Engine Initialized')
}

View File

@ -0,0 +1,7 @@
/**
* Class for interacting with the renderer
*/
export interface Renderer {
}

View File

@ -0,0 +1,18 @@
/**
* Tutorial ui related functions
*/
export interface TutorialUtils {
/**
* Shows a hint popup with contents defined at the hintId
* Optionally allows passing a close callback
* @param hintId The hint id in data
* @param captureControls Instructs the engine to switch to ui controls from in-game controls
* @param onClose Fired when the hint popup is closed
*/
showTutorialHint: (hintId: string, captureControls: boolean, onClose?: () => void) => void
}

View File

@ -1,3 +1,4 @@
import { TutorialUtils } from "/Scripts/types/host/renderer/ui/tutorial";
/**
@ -15,6 +16,11 @@ export interface StaticClasses {
*/
readonly simulation?: Class<SimulationClass>,
/**
* Tutorial ui utils
*/
readonly tutorialUtils?: Class<TutorialUtils>,
}

View File

@ -1,5 +1,4 @@
+ spawn into the world
Server commands client to load a given scene file
+ there is a sword lying on the ground
+ when you grab the sword, a tutorial popup appears to tell you how to use in
+ on clearing the tutorial, continue the game+ when the sword is equipped, create another popup to teach sword controls. it pauses the game

View File

@ -1,5 +1,8 @@
package electrosphere.menu.tutorial;
import org.graalvm.polyglot.HostAccess.Export;
import electrosphere.controls.ControlHandler.ControlsState;
import electrosphere.engine.Globals;
import electrosphere.game.data.tutorial.TutorialHint;
import electrosphere.menu.WindowStrings;
@ -16,11 +19,15 @@ import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification
*/
public class TutorialMenus {
@Export
/**
* Shows a tutorial hint
* @param hint the hint
* @param hint the hint id
* @param onClose A callback fired when the hint popup is closed. Either a
*/
public static void showTutorialHint(TutorialHint hint){
public static void showTutorialHint(String hintId, boolean captureControls, Runnable onClose){
//get the hint definition
TutorialHint hintDefinition = Globals.gameConfigCurrent.getHintData().getHintById(hintId);
//Get the window
Window windowEl;
@ -30,6 +37,7 @@ public class TutorialMenus {
//create the window
windowEl = new Window(Globals.renderingEngine.getOpenGLState(),50,50,500,500,true);
windowEl.setParentAlignContent(YogaAlignment.Center);
windowEl.setParentAlignItem(YogaAlignment.Center);
windowEl.setParentJustifyContent(YogaJustification.Center);
windowEl.setFlexDirection(YogaFlexDirection.Column);
Globals.elementManager.registerWindow(WindowStrings.TUTORIAL_POPUP, windowEl);
@ -38,11 +46,23 @@ public class TutorialMenus {
//clear previous content
windowEl.clearChildren();
//optionally switch to ui controls
if(captureControls){
Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU);
}
//create tutorial elements
windowEl.addChild(Label.createLabel(hint.getTitleString()));
windowEl.addChild(Label.createLabel(hint.getDescriptionString()));
windowEl.addChild(Label.createLabel(hintDefinition.getTitleString()));
windowEl.addChild(Label.createLabel(hintDefinition.getDescriptionString()));
windowEl.addChild(Button.createButton("Close", () -> {
WindowUtils.recursiveSetVisible(windowEl, true);
WindowUtils.recursiveSetVisible(windowEl, false);
if(onClose != null){
onClose.run();
}
//optionally switch to ui controls
if(captureControls){
Globals.controlHandler.hintUpdateControlState(ControlsState.MAIN_GAME);
}
}));
//show the window

View File

@ -16,6 +16,7 @@ import org.graalvm.polyglot.Value;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.logger.LoggerInterface;
import electrosphere.menu.tutorial.TutorialMenus;
import electrosphere.util.FileUtils;
import electrosphere.util.MathUtils;
@ -83,6 +84,7 @@ public class ScriptEngine {
static final Object[][] staticClasses = new Object[][]{
{"mathUtils",MathUtils.class},
{"simulation",Main.class},
{"tutorialUtils",TutorialMenus.class},
};
//singletons from the host that are provided to the javascript context