mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07: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:
parent
f1a9c503b8
commit
27fbf02ff4
4 changed files with 41 additions and 24 deletions
|
|
@ -37,7 +37,10 @@ Trigger.prototype.InitTutorial = function(data)
|
||||||
Trigger.prototype.NextStep = function(deserializing = false)
|
Trigger.prototype.NextStep = function(deserializing = false)
|
||||||
{
|
{
|
||||||
if (++this.stepIndex >= this.tutorialSteps.length)
|
if (++this.stepIndex >= this.tutorialSteps.length)
|
||||||
|
{
|
||||||
|
this.CompleteTutorial();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
const step = this.tutorialSteps[this.stepIndex];
|
const step = this.tutorialSteps[this.stepIndex];
|
||||||
|
|
||||||
Trigger.prototype.Init = step.Init || null;
|
Trigger.prototype.Init = step.Init || null;
|
||||||
|
|
@ -68,16 +71,15 @@ Trigger.prototype.NextStep = function(deserializing = false)
|
||||||
|
|
||||||
Trigger.prototype.IsDone = step.IsDone || (() => false);
|
Trigger.prototype.IsDone = step.IsDone || (() => false);
|
||||||
const isDone = this.IsDone();
|
const isDone = this.IsDone();
|
||||||
const isLast = this.stepIndex === this.tutorialSteps.length - 1;
|
const showContinueButton = isDone || (step.panelData.showContinueButton === undefined ?
|
||||||
const showContinueButton = isDone || isLast || (step.panelData.showContinueButton === undefined ?
|
|
||||||
this.tutorialEvents.every(event => !step[event]) :
|
this.tutorialEvents.every(event => !step[event]) :
|
||||||
step.panelData.showContinueButton
|
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);
|
const cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||||
cmpGUIInterface.PushNotification({
|
cmpGUIInterface.PushNotification({
|
||||||
|
|
@ -86,7 +88,7 @@ Trigger.prototype.DisplayStep = function(step, showContinueButton = false, isDon
|
||||||
"step": {
|
"step": {
|
||||||
"type": step.type,
|
"type": step.type,
|
||||||
"panelData": {
|
"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)
|
Trigger.prototype.BasePlayerCommandAction = function(msg)
|
||||||
{
|
{
|
||||||
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial == "continue")
|
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial == "continue")
|
||||||
|
|
|
||||||
|
|
@ -446,18 +446,7 @@ Trigger.prototype.tutorialSteps = [
|
||||||
if (msg.from != this.enemyID)
|
if (msg.from != this.enemyID)
|
||||||
return;
|
return;
|
||||||
if (TriggerHelper.EntityMatchesClassList(msg.entity, "CivilCentre"))
|
if (TriggerHelper.EntityMatchesClassList(msg.entity, "CivilCentre"))
|
||||||
this.NextStep();
|
this.CompleteTutorial(markForTranslation("You have defeated the enemy by destroying or capturing the Civic Center. These tutorial tasks are now completed."));
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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", () => "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -572,13 +572,7 @@ Trigger.prototype.tutorialSteps = [
|
||||||
"OnResearchFinished": function(msg)
|
"OnResearchFinished": function(msg)
|
||||||
{
|
{
|
||||||
if (this.IsDone())
|
if (this.IsDone())
|
||||||
this.NextStep();
|
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."));
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,13 @@ Trigger.prototype.DisableTrigger = function(event, name)
|
||||||
triggerData.enabled = false;
|
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)
|
Trigger.prototype.EnableTrigger = function(event, name)
|
||||||
{
|
{
|
||||||
if (!this.triggers[event][name])
|
if (!this.triggers[event][name])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue