show tutorial hints from script side
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
e00eb85bcb
commit
f7015bd614
@ -49,8 +49,15 @@ class TestScene1 extends Scene {
|
|||||||
signal: "itemPickup",
|
signal: "itemPickup",
|
||||||
callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
||||||
console.log(entityId + ' picked up an item, destroying ' + inWorldItemEntityId + ' and creating ' + inInventoryItemEntityId)
|
console.log(entityId + ' picked up an item, destroying ' + inWorldItemEntityId + ' and creating ' + inInventoryItemEntityId)
|
||||||
|
engine.classes.simulation.static.setFramestep(0)
|
||||||
|
engine.classes.tutorialUtils.static.showTutorialHint(
|
||||||
|
"BasicNavigation",
|
||||||
|
true,
|
||||||
|
() => {
|
||||||
engine.classes.simulation.static.setFramestep(2)
|
engine.classes.simulation.static.setFramestep(2)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -25,5 +25,7 @@ export const ENGINE_onInit = () => {
|
|||||||
engine.sceneLoader.engine = engine
|
engine.sceneLoader.engine = engine
|
||||||
engine.hookManager.engine = engine
|
engine.hookManager.engine = engine
|
||||||
|
|
||||||
|
console.log(Object.keys(engine.classes))
|
||||||
|
|
||||||
loggerScripts.INFO('Script Engine Initialized')
|
loggerScripts.INFO('Script Engine Initialized')
|
||||||
}
|
}
|
||||||
|
|||||||
7
assets/Scripts/types/host/renderer/renderer.ts
Normal file
7
assets/Scripts/types/host/renderer/renderer.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Class for interacting with the renderer
|
||||||
|
*/
|
||||||
|
export interface Renderer {
|
||||||
|
|
||||||
|
}
|
||||||
18
assets/Scripts/types/host/renderer/ui/tutorial.ts
Normal file
18
assets/Scripts/types/host/renderer/ui/tutorial.ts
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { TutorialUtils } from "/Scripts/types/host/renderer/ui/tutorial";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,6 +16,11 @@ export interface StaticClasses {
|
|||||||
*/
|
*/
|
||||||
readonly simulation?: Class<SimulationClass>,
|
readonly simulation?: Class<SimulationClass>,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tutorial ui utils
|
||||||
|
*/
|
||||||
|
readonly tutorialUtils?: Class<TutorialUtils>,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
+ spawn into the world
|
+ spawn into the world
|
||||||
Server commands client to load a given scene file
|
|
||||||
+ there is a sword lying on the ground
|
+ there is a sword lying on the ground
|
||||||
+ when you grab the sword, a tutorial popup appears to tell you how to use in
|
+ 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
|
+ on clearing the tutorial, continue the game+ when the sword is equipped, create another popup to teach sword controls. it pauses the game
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package electrosphere.menu.tutorial;
|
package electrosphere.menu.tutorial;
|
||||||
|
|
||||||
|
import org.graalvm.polyglot.HostAccess.Export;
|
||||||
|
|
||||||
|
import electrosphere.controls.ControlHandler.ControlsState;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.game.data.tutorial.TutorialHint;
|
import electrosphere.game.data.tutorial.TutorialHint;
|
||||||
import electrosphere.menu.WindowStrings;
|
import electrosphere.menu.WindowStrings;
|
||||||
@ -16,11 +19,15 @@ import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification
|
|||||||
*/
|
*/
|
||||||
public class TutorialMenus {
|
public class TutorialMenus {
|
||||||
|
|
||||||
|
@Export
|
||||||
/**
|
/**
|
||||||
* Shows a tutorial hint
|
* 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
|
//Get the window
|
||||||
Window windowEl;
|
Window windowEl;
|
||||||
@ -30,6 +37,7 @@ public class TutorialMenus {
|
|||||||
//create the window
|
//create the window
|
||||||
windowEl = new Window(Globals.renderingEngine.getOpenGLState(),50,50,500,500,true);
|
windowEl = new Window(Globals.renderingEngine.getOpenGLState(),50,50,500,500,true);
|
||||||
windowEl.setParentAlignContent(YogaAlignment.Center);
|
windowEl.setParentAlignContent(YogaAlignment.Center);
|
||||||
|
windowEl.setParentAlignItem(YogaAlignment.Center);
|
||||||
windowEl.setParentJustifyContent(YogaJustification.Center);
|
windowEl.setParentJustifyContent(YogaJustification.Center);
|
||||||
windowEl.setFlexDirection(YogaFlexDirection.Column);
|
windowEl.setFlexDirection(YogaFlexDirection.Column);
|
||||||
Globals.elementManager.registerWindow(WindowStrings.TUTORIAL_POPUP, windowEl);
|
Globals.elementManager.registerWindow(WindowStrings.TUTORIAL_POPUP, windowEl);
|
||||||
@ -38,11 +46,23 @@ public class TutorialMenus {
|
|||||||
//clear previous content
|
//clear previous content
|
||||||
windowEl.clearChildren();
|
windowEl.clearChildren();
|
||||||
|
|
||||||
|
//optionally switch to ui controls
|
||||||
|
if(captureControls){
|
||||||
|
Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU);
|
||||||
|
}
|
||||||
|
|
||||||
//create tutorial elements
|
//create tutorial elements
|
||||||
windowEl.addChild(Label.createLabel(hint.getTitleString()));
|
windowEl.addChild(Label.createLabel(hintDefinition.getTitleString()));
|
||||||
windowEl.addChild(Label.createLabel(hint.getDescriptionString()));
|
windowEl.addChild(Label.createLabel(hintDefinition.getDescriptionString()));
|
||||||
windowEl.addChild(Button.createButton("Close", () -> {
|
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
|
//show the window
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import org.graalvm.polyglot.Value;
|
|||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.engine.Main;
|
import electrosphere.engine.Main;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
import electrosphere.menu.tutorial.TutorialMenus;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.MathUtils;
|
||||||
|
|
||||||
@ -83,6 +84,7 @@ public class ScriptEngine {
|
|||||||
static final Object[][] staticClasses = new Object[][]{
|
static final Object[][] staticClasses = new Object[][]{
|
||||||
{"mathUtils",MathUtils.class},
|
{"mathUtils",MathUtils.class},
|
||||||
{"simulation",Main.class},
|
{"simulation",Main.class},
|
||||||
|
{"tutorialUtils",TutorialMenus.class},
|
||||||
};
|
};
|
||||||
|
|
||||||
//singletons from the host that are provided to the javascript context
|
//singletons from the host that are provided to the javascript context
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user