0ad/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js
Vantha e02a2e0b31 Add support for different types of tutorial steps
This patch doesn't add any new functionality and keeps the introductory
tutorial and economy walkthrough as they are. Instead, it rearranges some
code to enable easily adding different types of tutorial steps in the
future. The idea is for each type to be displayed on a different panel
and for the TutorialManager to switch back and forth between them, and
to handle and translate the received messages from the simulation and
pass them along to the active panel. Currently, there are only
"instruction"-type steps, which are handled by the InstructionPanel in
the GUI. But new ones can be added in the future, like information boxes
or bigger objectives.
2026-07-22 23:51:49 +02:00

66 lines
1.7 KiB
JavaScript

/**
* This class manages a tutorial panel meant to display basic instructions of simple tasks for the player to fulfill,
* consisting of just a text, like "Order one of your units to build a house."
*/
class InstructionPanel
{
panel = Engine.GetGUIObjectByName("instructionPanel");
text = Engine.GetGUIObjectByName("instructionPanelText");
warning = Engine.GetGUIObjectByName("instructionPanelWarning");
readyButton = Engine.GetGUIObjectByName("instructionPanelReady");
instructions = [];
closePage;
constructor(closePage)
{
this.closePage = closePage;
this.readyButton.onPress = () =>
{
Engine.PostNetworkCommand({ "type": "dialog-answer", "tutorial": "ready" });
};
}
setVisible(visible)
{
this.panel.hidden = !visible;
}
displayWarning(warning)
{
this.warning.caption = setStringTags(warning, this.WarningTags);
}
displayStep(panelData)
{
this.text.caption = this.instructions.concat(setStringTags(panelData.text, this.NewInstructionTags)).join("\n");
this.instructions.push(panelData.text);
if (panelData.readyButton)
{
this.readyButton.hidden = false;
if (panelData.leave)
{
this.warning.caption = translate("Click to quit this tutorial.");
this.readyButton.caption = translate("Quit");
this.readyButton.onPress = this.closePage;
}
else
this.warning.caption = translate("Click when ready.");
}
else
{
this.warning.caption = translate("Follow the instructions.");
this.readyButton.hidden = true;
}
}
}
/**
* Tags applied to the most recent instruction.
*/
InstructionPanel.prototype.NewInstructionTags = { "color": "255 226 149" };
/**
* Tags applied to warning messages.
*/
InstructionPanel.prototype.WarningTags = { "color": "orange" };