feat(demo): Enhance DemoModule with secondary window setup and UI controls
This commit is contained in:
@@ -12,8 +12,11 @@ import de.extio.game_engine.renderer.RendererControl;
|
|||||||
import de.extio.game_engine.renderer.container.Window;
|
import de.extio.game_engine.renderer.container.Window;
|
||||||
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
import de.extio.game_engine.renderer.model.RenderingBoLayer;
|
||||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo;
|
||||||
import de.extio.game_engine.renderer.model.bo.DrawImageRenderingBo;
|
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.ButtonControl;
|
||||||
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.LabelControl;
|
import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.LabelControl;
|
||||||
|
import de.extio.game_engine.renderer.model.bo.DrawFontRenderingBo;
|
||||||
|
import de.extio.game_engine.renderer.model.bo.DrawImageRenderingBo;
|
||||||
|
import de.extio.game_engine.renderer.model.bo.HorizontalAlignment;
|
||||||
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
import de.extio.game_engine.renderer.model.event.UiControlEvent;
|
||||||
import de.extio.game_engine.renderer.work.RenderingBoPool;
|
import de.extio.game_engine.renderer.work.RenderingBoPool;
|
||||||
import de.extio.game_engine.resource.StaticResource;
|
import de.extio.game_engine.resource.StaticResource;
|
||||||
@@ -34,6 +37,8 @@ public class DemoModule extends AbstractClientModule {
|
|||||||
|
|
||||||
private Window mainWindow;
|
private Window mainWindow;
|
||||||
|
|
||||||
|
private Window secondaryWindow;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
this.mainWindow = this.applicationContext.getBean(Window.class);
|
this.mainWindow = this.applicationContext.getBean(Window.class);
|
||||||
@@ -41,6 +46,11 @@ public class DemoModule extends AbstractClientModule {
|
|||||||
this.mainWindow.setNormalizedDimension(RendererControl.REFERENCE_RESOLUTION.divide(9).multiply(7));
|
this.mainWindow.setNormalizedDimension(RendererControl.REFERENCE_RESOLUTION.divide(9).multiply(7));
|
||||||
this.mainWindow.setDraggable(true);
|
this.mainWindow.setDraggable(true);
|
||||||
|
|
||||||
|
this.secondaryWindow = this.applicationContext.getBean(Window.class);
|
||||||
|
this.secondaryWindow.setNormalizedPosition(RendererControl.REFERENCE_RESOLUTION.divide(7).multiply(3));
|
||||||
|
this.secondaryWindow.setNormalizedDimension(RendererControl.REFERENCE_RESOLUTION.divide(7).multiply(2));
|
||||||
|
this.secondaryWindow.setDraggable(true);
|
||||||
|
|
||||||
this.getModuleService().changeActiveState(this.getId(), true);
|
this.getModuleService().changeActiveState(this.getId(), true);
|
||||||
this.getModuleService().changeDisplayState(this.getId(), true);
|
this.getModuleService().changeDisplayState(this.getId(), true);
|
||||||
}
|
}
|
||||||
@@ -48,10 +58,56 @@ public class DemoModule extends AbstractClientModule {
|
|||||||
@Override
|
@Override
|
||||||
public void onUnload() {
|
public void onUnload() {
|
||||||
this.getModuleService().unloadModule(this.mainWindow.getId());
|
this.getModuleService().unloadModule(this.mainWindow.getId());
|
||||||
|
this.getModuleService().unloadModule(this.secondaryWindow.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivate() {
|
public void onActivate() {
|
||||||
|
this.setupMainWindow();
|
||||||
|
this.getModuleService().changeActiveState(this.mainWindow.getId(), true);
|
||||||
|
this.eventService.register(UiControlEvent.class, this.getId(), this::onUiControlEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeactivate() {
|
||||||
|
this.getModuleService().changeActiveState(this.mainWindow.getId(), false);
|
||||||
|
this.getModuleService().changeActiveState(this.secondaryWindow.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShow() {
|
||||||
|
this.getModuleService().changeDisplayState(this.mainWindow.getId(), true);
|
||||||
|
this.audioController.playMusic(null, List.of(new StaticResource(List.of("audio"), "race.ogg")), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHide() {
|
||||||
|
this.getModuleService().changeDisplayState(this.mainWindow.getId(), false);
|
||||||
|
this.getModuleService().changeActiveState(this.secondaryWindow.getId(), false);
|
||||||
|
this.audioController.stopMusic();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onUiControlEvent(final UiControlEvent event) {
|
||||||
|
switch (event.getId()) {
|
||||||
|
case "DemoModule_MainWindow_Label_Welcome" -> {
|
||||||
|
this.audioController.play(new StaticResource(List.of("audio"), "alert0.ogg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
case "DemoModule_MainWindow_Label_Start" -> {
|
||||||
|
this.audioController.play(new StaticResource(List.of("audio"), "alert2.ogg"));
|
||||||
|
this.setupSecondaryWindow();
|
||||||
|
this.getModuleService().changeActiveState(this.secondaryWindow.getId(), true);
|
||||||
|
this.getModuleService().changeDisplayState(this.secondaryWindow.getId(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "DemoModule_SecondaryWindow_Button_Ok" -> {
|
||||||
|
this.audioController.play(new StaticResource(List.of("audio"), "alert0.ogg"));
|
||||||
|
this.getModuleService().changeActiveState(this.secondaryWindow.getId(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupMainWindow() {
|
||||||
var bo = this.renderingBoPool.acquire("DemoModule_MainWindow_Label_Welcome", ControlRenderingBo.class)
|
var bo = this.renderingBoPool.acquire("DemoModule_MainWindow_Label_Welcome", ControlRenderingBo.class)
|
||||||
.setCaption("Welcome to Exo's Game Engine Demo!")
|
.setCaption("Welcome to Exo's Game Engine Demo!")
|
||||||
.setFontSize(48)
|
.setFontSize(48)
|
||||||
@@ -78,39 +134,24 @@ public class DemoModule extends AbstractClientModule {
|
|||||||
.withDimensionAbsolute(RendererControl.REFERENCE_RESOLUTION.divide(9).multiply(7).substract(20).getX(), 120)
|
.withDimensionAbsolute(RendererControl.REFERENCE_RESOLUTION.divide(9).multiply(7).substract(20).getX(), 120)
|
||||||
.withPositionRelative(10, 600);
|
.withPositionRelative(10, 600);
|
||||||
this.mainWindow.putRenderingBo(bo);
|
this.mainWindow.putRenderingBo(bo);
|
||||||
|
|
||||||
this.eventService.register(UiControlEvent.class, this.getId(), this::onUiControlEvent);
|
|
||||||
|
|
||||||
this.getModuleService().changeActiveState(this.mainWindow.getId(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void setupSecondaryWindow() {
|
||||||
public void onDeactivate() {
|
var bo = this.renderingBoPool.acquire("DemoModule_SecondaryWindow_Text", DrawFontRenderingBo.class)
|
||||||
this.getModuleService().changeActiveState(this.mainWindow.getId(), false);
|
.setText("This is a message\n\nbla bla bla...\n\nHave a nice day!")
|
||||||
|
.setSize(32)
|
||||||
|
.setAlignment(HorizontalAlignment.CENTER)
|
||||||
|
.withDimensionAbsolute(RendererControl.REFERENCE_RESOLUTION.divide(7).multiply(2).substract(20).getX(), 40)
|
||||||
|
.withPositionRelative(10, 50);
|
||||||
|
this.secondaryWindow.putRenderingBo(bo);
|
||||||
|
|
||||||
|
bo = this.renderingBoPool.acquire("DemoModule_SecondaryWindow_Button_Ok", ControlRenderingBo.class)
|
||||||
|
.setCaption("OK")
|
||||||
|
.setType(ButtonControl.class)
|
||||||
|
.setVisible(true)
|
||||||
|
.setEnabled(true)
|
||||||
|
.withDimensionAbsolute(160, 60)
|
||||||
|
.withPositionRelative(RendererControl.REFERENCE_RESOLUTION.divide(7).getX() - 80, 200);
|
||||||
|
this.secondaryWindow.putRenderingBo(bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShow() {
|
|
||||||
this.getModuleService().changeDisplayState(this.mainWindow.getId(), true);
|
|
||||||
this.audioController.playMusic(null, List.of(new StaticResource(List.of("audio"), "race.ogg")), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHide() {
|
|
||||||
this.getModuleService().changeDisplayState(this.mainWindow.getId(), false);
|
|
||||||
this.audioController.stopMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onUiControlEvent(final UiControlEvent event) {
|
|
||||||
switch (event.getId()) {
|
|
||||||
case "DemoModule_MainWindow_Label_Welcome" -> {
|
|
||||||
this.audioController.play(new StaticResource(List.of("audio"), "alert0.ogg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
case "DemoModule_MainWindow_Label_Start" -> {
|
|
||||||
this.audioController.play(new StaticResource(List.of("audio"), "alert2.ogg"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user