mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-24 15:34:36 +00:00
Improve the ending of tutorials
This patch introduces two functions `CompleteTutorial` and `FailTutorial` for the tutorial steps to call. They can pass a message to it to be shown on the victory/defeat screen. `CompleteTutorial` is also called automatically when all steps are finished, which resolves #8583 and prevents it from happening in the future. `FailTutorial` isn't used anywhere at the moment, but it'll be useful for the future. Fixes #8583
This commit is contained in:
@@ -37,7 +37,10 @@ Trigger.prototype.InitTutorial = function(data)
|
||||
Trigger.prototype.NextStep = function(deserializing = false)
|
||||
{
|
||||
if (++this.stepIndex >= this.tutorialSteps.length)
|
||||
{
|
||||
this.CompleteTutorial();
|
||||
return;
|
||||
}
|
||||
const step = this.tutorialSteps[this.stepIndex];
|
||||
|
||||
Trigger.prototype.Init = step.Init || null;
|
||||
@@ -68,16 +71,15 @@ Trigger.prototype.NextStep = function(deserializing = false)
|
||||
|
||||
Trigger.prototype.IsDone = step.IsDone || (() => false);
|
||||
const isDone = this.IsDone();
|
||||
const isLast = this.stepIndex === this.tutorialSteps.length - 1;
|
||||
const showContinueButton = isDone || isLast || (step.panelData.showContinueButton === undefined ?
|
||||
const showContinueButton = isDone || (step.panelData.showContinueButton === undefined ?
|
||||
this.tutorialEvents.every(event => !step[event]) :
|
||||
step.panelData.showContinueButton
|
||||
);
|
||||
|
||||
this.DisplayStep(step, showContinueButton, isDone, isLast);
|
||||
this.DisplayStep(step, showContinueButton, isDone);
|
||||
};
|
||||
|
||||
Trigger.prototype.DisplayStep = function(step, showContinueButton = false, isDone = false, isLast = false)
|
||||
Trigger.prototype.DisplayStep = function(step, showContinueButton = false, isDone = false)
|
||||
{
|
||||
const cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
cmpGUIInterface.PushNotification({
|
||||
@@ -86,7 +88,7 @@ Trigger.prototype.DisplayStep = function(step, showContinueButton = false, isDon
|
||||
"step": {
|
||||
"type": step.type,
|
||||
"panelData": {
|
||||
...step.panelData, showContinueButton, isDone, isLast
|
||||
...step.panelData, showContinueButton, isDone
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -102,6 +104,31 @@ Trigger.prototype.DisplayWarning = function(warning)
|
||||
});
|
||||
};
|
||||
|
||||
Trigger.prototype.CompleteTutorial = function(message = markForTranslation("You have successfully completed the tutorial."))
|
||||
{
|
||||
// End the tutorial first, before marking the player won, since otherwise the triggers would be invoked
|
||||
// once more when doing so.
|
||||
this.EndTutorial(message);
|
||||
TriggerHelper.SetPlayerWon(this.playerID, () => markForTranslation("%(player)s has completed the tutorial."), () => "", message);
|
||||
};
|
||||
|
||||
Trigger.prototype.FailTutorial = function(message = markForTranslation("You have failed to complete the tutorial."))
|
||||
{
|
||||
// End the tutorial first, before marking the player defeated, since otherwise the triggers would be invoked
|
||||
// once more when doing so.
|
||||
this.EndTutorial(message);
|
||||
TriggerHelper.DefeatPlayer(this.playerID, markForTranslation("%(player)s has failed the tutorial."), message);
|
||||
};
|
||||
|
||||
Trigger.prototype.EndTutorial = function(message)
|
||||
{
|
||||
this.DisableAllTriggers();
|
||||
this.DisplayStep({
|
||||
"type": TUTORIAL_STEP_TYPE.INSTRUCTION,
|
||||
"panelData": { "isLast": true, "text": message }
|
||||
}, true, false);
|
||||
};
|
||||
|
||||
Trigger.prototype.BasePlayerCommandAction = function(msg)
|
||||
{
|
||||
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial == "continue")
|
||||
|
||||
@@ -446,18 +446,7 @@ Trigger.prototype.tutorialSteps = [
|
||||
if (msg.from != this.enemyID)
|
||||
return;
|
||||
if (TriggerHelper.EntityMatchesClassList(msg.entity, "CivilCentre"))
|
||||
this.NextStep();
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": TUTORIAL_STEP_TYPE.INSTRUCTION,
|
||||
"panelData": {
|
||||
"text": markForTranslation("The enemy has been defeated. These tutorial tasks are now completed.")
|
||||
},
|
||||
"Init": function()
|
||||
{
|
||||
const cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
|
||||
cmpEndGameManager.MarkPlayerAndAlliesAsWon(1, () => "Tutorial completed", () => "");
|
||||
this.CompleteTutorial(markForTranslation("You have defeated the enemy by destroying or capturing the Civic Center. These tutorial tasks are now completed."));
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -572,13 +572,7 @@ Trigger.prototype.tutorialSteps = [
|
||||
"OnResearchFinished": function(msg)
|
||||
{
|
||||
if (this.IsDone())
|
||||
this.NextStep();
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": TUTORIAL_STEP_TYPE.INSTRUCTION,
|
||||
"panelData": {
|
||||
"text": markForTranslation("This is the end of the walkthrough. This should give you a good idea of the basics of setting up your economy.")
|
||||
this.CompleteTutorial(markForTranslation("This is the end of the walkthrough. This should give you a good idea of the basics of setting up your economy."));
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -173,6 +173,13 @@ Trigger.prototype.DisableTrigger = function(event, name)
|
||||
triggerData.enabled = false;
|
||||
};
|
||||
|
||||
Trigger.prototype.DisableAllTriggers = function()
|
||||
{
|
||||
for (const event of this.eventNames)
|
||||
for (const name in this.triggers[event])
|
||||
this.DisableTrigger(event, name);
|
||||
};
|
||||
|
||||
Trigger.prototype.EnableTrigger = function(event, name)
|
||||
{
|
||||
if (!this.triggers[event][name])
|
||||
|
||||
Reference in New Issue
Block a user