0ad/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js
Vantha 702e3f1113 Revise tutorial step handling
- Remove the delay functionality from the tutorial. It was unused and
  that for a reason. Switching to the next step after a fixed amount of
  time is never wanted. It was only used to force-show the ready button
  in one case, but a designated bool communicates the purpose better.
- Rename the "ready" button to "continue" as it fits better.
- Rename "leave" to "isLast" as it's more descriptive.
- Rename the "warning" object of the instruction panel to "hint" as it's
  not always display warnings, and move its captions to the class
  prototype like the coding conventions state.
- Simplify the logic in NextStep a bit to make it more readable.
2026-07-22 23:51:49 +02:00

72 lines
1.9 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");
hint = Engine.GetGUIObjectByName("instructionPanelHint");
continueButton = Engine.GetGUIObjectByName("instructionPanelContinueButton");
instructions = [];
closePage;
constructor(closePage)
{
this.closePage = closePage;
this.continueButton.onPress = () =>
{
Engine.PostNetworkCommand({ "type": "dialog-answer", "tutorial": "continue" });
};
}
setVisible(visible)
{
this.panel.hidden = !visible;
}
displayWarning(warning)
{
this.hint.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.showContinueButton)
{
this.continueButton.hidden = false;
if (panelData.isLast)
{
this.hint.caption = translate("Click to quit this tutorial.");
this.continueButton.caption = translate("Quit");
this.continueButton.onPress = this.closePage;
}
else
this.hint.caption = this.HintCaptions.Continue;
}
else
{
this.hint.caption = this.HintCaptions.Instruction;
this.continueButton.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" };
InstructionPanel.prototype.HintCaptions = {
"Continue": translate("Click when continue."),
"Instruction": translate("Follow the instructions."),
"Quit": translate("Click to quit this tutorial.")
};