Separate handling of tutorial goals and warnings

This is more explicit and makes the code cleaner.
This commit is contained in:
Vantha 2026-02-24 16:55:09 +01:00 committed by Vantha
parent ca8a0a5611
commit dd396f19b6
3 changed files with 23 additions and 14 deletions

View file

@ -164,7 +164,7 @@ var g_NotificationsTypes =
}, },
"tutorial": function(notification, player) "tutorial": function(notification, player)
{ {
g_Tutorial.update(notification); g_Tutorial.handleNotification(notification);
}, },
"tribute": function(notification, player) "tribute": function(notification, player)
{ {

View file

@ -17,28 +17,35 @@ class Tutorial
this.panel.hidden = !this.panel.hidden || !this.text.caption; this.panel.hidden = !this.panel.hidden || !this.text.caption;
} }
update(notification) handleNotification(notification)
{
if (notification.goal)
this.displayGoal(notification.goal);
if (notification.warning)
this.displayWarning(notification.warning);
}
displayWarning(warning)
{
this.warning.caption = coloredText(translate(warning), "orange");
}
displayGoal(goal)
{ {
this.panel.hidden = false; this.panel.hidden = false;
if (notification.warning)
{
this.warning.caption = coloredText(translate(notification.warning), "orange");
return;
}
const notificationText = const notificationText =
notification.instructions.reduce((instructions, item) => goal.instructions.reduce((instructions, item) =>
instructions + (typeof item === "string" ? translate(item) : colorizeHotkey(translate(item.text), item.hotkey)), instructions + (typeof item === "string" ? translate(item) : colorizeHotkey(translate(item.text), item.hotkey)),
""); "");
this.text.caption = this.instructions.concat(setStringTags(notificationText, this.NewInstructionTags)).join("\n"); this.text.caption = this.instructions.concat(setStringTags(notificationText, this.NewInstructionTags)).join("\n");
this.instructions.push(notificationText); this.instructions.push(notificationText);
if (notification.readyButton) if (goal.readyButton)
{ {
this.readyButton.hidden = false; this.readyButton.hidden = false;
if (notification.leave) if (goal.leave)
{ {
this.warning.caption = translate("Click to quit this tutorial."); this.warning.caption = translate("Click to quit this tutorial.");
this.readyButton.caption = translate("Quit"); this.readyButton.caption = translate("Quit");

View file

@ -85,9 +85,11 @@ Trigger.prototype.GoalMessage = function(instructions, readyButton=false, leave=
cmpGUIInterface.PushNotification({ cmpGUIInterface.PushNotification({
"type": "tutorial", "type": "tutorial",
"players": [1], "players": [1],
"instructions": typeof instructions === "string" ? [instructions] : instructions, "goal": {
"readyButton": readyButton, "instructions": typeof instructions === "string" ? [instructions] : instructions,
"leave": leave "readyButton": readyButton,
"leave": leave
}
}); });
}; };