Make MBP replay saving system more natural

This commit is contained in:
Terry Hearst 2023-02-05 21:28:48 -05:00
parent e6605efaa6
commit 73b70ab6ab
4 changed files with 69 additions and 29 deletions

View file

@ -1,5 +1,6 @@
package src; package src;
import gui.ReplayNameDlg;
import gui.ConsoleDlg; import gui.ConsoleDlg;
import src.Replay; import src.Replay;
import touch.TouchInput; import touch.TouchInput;
@ -218,7 +219,11 @@ class MarbleGame {
world.setCursorLock(false); world.setCursorLock(false);
exitGameDlg = new ExitGameDlg((sender) -> { exitGameDlg = new ExitGameDlg((sender) -> {
canvas.popDialog(exitGameDlg); canvas.popDialog(exitGameDlg);
quitMission(); if (world.isRecording) {
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {quitMission();}));
} else {
quitMission();
}
}, (sender) -> { }, (sender) -> {
canvas.popDialog(exitGameDlg); canvas.popDialog(exitGameDlg);
paused = !paused; paused = !paused;
@ -247,9 +252,6 @@ class MarbleGame {
var pmg = new PlayMissionGui(); var pmg = new PlayMissionGui();
PlayMissionGui.currentSelectionStatic = world.mission.index; PlayMissionGui.currentSelectionStatic = world.mission.index;
PlayMissionGui.currentGameStatic = world.mission.game; PlayMissionGui.currentGameStatic = world.mission.game;
if (world.isRecording) {
world.saveReplay();
}
world.dispose(); world.dispose();
world = null; world = null;
canvas.setContent(pmg); canvas.setContent(pmg);
@ -263,7 +265,6 @@ class MarbleGame {
world.dispose(); world.dispose();
} }
world = new MarbleWorld(scene, scene2d, mission, toRecord); world = new MarbleWorld(scene, scene2d, mission, toRecord);
toRecord = false;
world.init(); world.init();
} }

View file

@ -1,5 +1,6 @@
package src; package src;
import gui.ReplayNameDlg;
import collision.Collision; import collision.Collision;
import shapes.MegaMarble; import shapes.MegaMarble;
import shapes.Blast; import shapes.Blast;
@ -1636,7 +1637,8 @@ class MarbleWorld extends Scheduler {
this.finishYaw = this.marble.camera.CameraYaw; this.finishYaw = this.marble.camera.CameraYaw;
this.finishPitch = this.marble.camera.CameraPitch; this.finishPitch = this.marble.camera.CameraPitch;
displayAlert("Congratulations! You've finished!"); displayAlert("Congratulations! You've finished!");
this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen()); if (!this.isWatching)
this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen());
// Stop the ongoing sounds // Stop the ongoing sounds
if (timeTravelSound != null) { if (timeTravelSound != null) {
timeTravelSound.stop(); timeTravelSound.stop();
@ -1650,16 +1652,17 @@ class MarbleWorld extends Scheduler {
} }
function showFinishScreen() { function showFinishScreen() {
if (this.isWatching)
return 0;
Console.log("State End"); Console.log("State End");
var egg:EndGameGui = null; var egg:EndGameGui = null;
#if js #if js
var pointercontainer = js.Browser.document.querySelector("#pointercontainer"); var pointercontainer = js.Browser.document.querySelector("#pointercontainer");
pointercontainer.hidden = false; pointercontainer.hidden = false;
#end #end
if (this.isRecording) { this.schedule(this.timeState.currentAttemptTime + 3, () -> {
this.isRecording = false; // Stop recording here this.isRecording = false; // Stop recording here
this.saveReplay(); }, "stopRecordingTimeout");
}
if (Util.isTouchDevice()) { if (Util.isTouchDevice()) {
MarbleGame.instance.touchInput.setControlsEnabled(false); MarbleGame.instance.touchInput.setControlsEnabled(false);
} }
@ -1667,24 +1670,48 @@ class MarbleWorld extends Scheduler {
if (Util.isTouchDevice()) { if (Util.isTouchDevice()) {
MarbleGame.instance.touchInput.hideControls(@:privateAccess this.playGui.playGuiCtrl); MarbleGame.instance.touchInput.hideControls(@:privateAccess this.playGui.playGuiCtrl);
} }
this.dispose(); if (this.isRecording) {
var pmg = new PlayMissionGui(); this.isRecording = false; // Stop recording here if we haven't already
PlayMissionGui.currentSelectionStatic = mission.index + 1; this.clearScheduleId("stopRecordingTimeout");
MarbleGame.canvas.setContent(pmg); }
#if js var endGameCode = () -> {
pointercontainer.hidden = false; this.dispose();
#end var pmg = new PlayMissionGui();
}, (sender) -> { PlayMissionGui.currentSelectionStatic = mission.index + 1;
MarbleGame.canvas.popDialog(egg); MarbleGame.canvas.setContent(pmg);
this.setCursorLock(true); #if js
this.restart(true); pointercontainer.hidden = false;
#if js #end
pointercontainer.hidden = true; }
#end if (MarbleGame.instance.toRecord) {
if (Util.isTouchDevice()) { MarbleGame.canvas.pushDialog(new ReplayNameDlg(endGameCode));
MarbleGame.instance.touchInput.setControlsEnabled(true); } else {
endGameCode();
}
}, (sender) -> {
var restartGameCode = () -> {
MarbleGame.canvas.popDialog(egg);
this.setCursorLock(true);
this.restart(true);
#if js
pointercontainer.hidden = true;
#end
if (Util.isTouchDevice()) {
MarbleGame.instance.touchInput.setControlsEnabled(true);
}
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
}
if (this.isRecording) {
this.clearScheduleId("stopRecordingTimeout");
}
if (MarbleGame.instance.toRecord) {
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {
this.isRecording = true;
restartGameCode();
}));
} else {
restartGameCode();
} }
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
}, mission, finishTime); }, mission, finishTime);
MarbleGame.canvas.pushDialog(egg); MarbleGame.canvas.pushDialog(egg);
this.setCursorLock(false); this.setCursorLock(false);

View file

@ -65,6 +65,8 @@ class PlayMissionGui extends GuiImage {
currentCategory = PlayMissionGui.currentCategoryStatic; currentCategory = PlayMissionGui.currentCategoryStatic;
currentGame = PlayMissionGui.currentGameStatic; currentGame = PlayMissionGui.currentGameStatic;
MarbleGame.instance.toRecord = false;
function chooseBg() { function chooseBg() {
if (currentGame == "gold") if (currentGame == "gold")
return ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg'); return ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg');
@ -667,7 +669,8 @@ class PlayMissionGui extends GuiImage {
pmRecord.position = new Vector(247, 46); pmRecord.position = new Vector(247, 46);
pmRecord.extent = new Vector(43, 43); pmRecord.extent = new Vector(43, 43);
pmRecord.pressedAction = (sender) -> { pmRecord.pressedAction = (sender) -> {
cast(this.parent, Canvas).pushDialog(new ReplayNameDlg()); MarbleGame.instance.toRecord = true;
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("The next mission you play will be recorded."));
}; };
pmMorePopDlg.addChild(pmRecord); pmMorePopDlg.addChild(pmRecord);

View file

@ -7,7 +7,7 @@ import src.ResourceLoader;
import src.Settings; import src.Settings;
class ReplayNameDlg extends GuiControl { class ReplayNameDlg extends GuiControl {
public function new() { public function new(callback:Void->Void) {
super(); super();
var text = "Enter a name for the recording"; var text = "Enter a name for the recording";
this.horizSizing = Width; this.horizSizing = Width;
@ -59,6 +59,13 @@ class ReplayNameDlg extends GuiControl {
textInput.text.selectionTile = h2d.Tile.fromColor(0x808080, 0, hxd.Math.ceil(textInput.text.font.lineHeight)); textInput.text.selectionTile = h2d.Tile.fromColor(0x808080, 0, hxd.Math.ceil(textInput.text.font.lineHeight));
textFrame.addChild(textInput); textFrame.addChild(textInput);
textInput.text.text = MarbleGame.instance.world.mission.title;
if (MarbleGame.instance.world.finishTime == null) {
textInput.text.text += " Unfinished Run";
} else {
textInput.text.text += " " + MarbleGame.instance.world.finishTime.gameplayClock;
}
var yesButton = new GuiButton(loadButtonImages("data/ui/common/ok")); var yesButton = new GuiButton(loadButtonImages("data/ui/common/ok"));
yesButton.position = new Vector(171, 124); yesButton.position = new Vector(171, 124);
yesButton.extent = new Vector(95, 45); yesButton.extent = new Vector(95, 45);
@ -66,9 +73,10 @@ class ReplayNameDlg extends GuiControl {
yesButton.accelerator = hxd.Key.ENTER; yesButton.accelerator = hxd.Key.ENTER;
yesButton.pressedAction = (sender) -> { yesButton.pressedAction = (sender) -> {
if (StringTools.trim(textInput.text.text) != "") { if (StringTools.trim(textInput.text.text) != "") {
MarbleGame.instance.toRecord = true;
MarbleGame.instance.recordingName = textInput.text.text; MarbleGame.instance.recordingName = textInput.text.text;
MarbleGame.canvas.popDialog(this); MarbleGame.canvas.popDialog(this);
MarbleGame.instance.world.saveReplay();
callback();
} }
} }
yesNoFrame.addChild(yesButton); yesNoFrame.addChild(yesButton);
@ -80,6 +88,7 @@ class ReplayNameDlg extends GuiControl {
noButton.accelerator = hxd.Key.ESCAPE; noButton.accelerator = hxd.Key.ESCAPE;
noButton.pressedAction = (sender) -> { noButton.pressedAction = (sender) -> {
MarbleGame.canvas.popDialog(this); MarbleGame.canvas.popDialog(this);
callback();
} }
yesNoFrame.addChild(noButton); yesNoFrame.addChild(noButton);