From e02a2e0b31083803069ff0de4985274f15e2a12f Mon Sep 17 00:00:00 2001 From: Vantha Date: Wed, 25 Feb 2026 14:37:05 +0100 Subject: [PATCH] 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. --- .../mods/public/gui/session/hotkeys/misc.xml | 2 +- .../data/mods/public/gui/session/messages.js | 2 +- .../data/mods/public/gui/session/session.js | 4 +- .../gui/session/tutorial/InstructionPanel.js | 66 +++ .../gui/session/tutorial/InstructionPanel.xml | 10 + .../public/gui/session/tutorial/Tutorial.js | 69 ---- .../public/gui/session/tutorial/Tutorial.xml | 14 +- .../gui/session/tutorial/TutorialManager.js | 74 ++++ .../data/mods/public/maps/scripts/Tutorial.js | 22 +- .../maps/tutorials/introductory_tutorial.js | 164 +++++--- .../tutorials/starting_economy_walkthrough.js | 377 ++++++++++-------- 11 files changed, 495 insertions(+), 309 deletions(-) create mode 100644 binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js create mode 100644 binaries/data/mods/public/gui/session/tutorial/InstructionPanel.xml delete mode 100644 binaries/data/mods/public/gui/session/tutorial/Tutorial.js create mode 100644 binaries/data/mods/public/gui/session/tutorial/TutorialManager.js diff --git a/binaries/data/mods/public/gui/session/hotkeys/misc.xml b/binaries/data/mods/public/gui/session/hotkeys/misc.xml index e846075095..c022747887 100644 --- a/binaries/data/mods/public/gui/session/hotkeys/misc.xml +++ b/binaries/data/mods/public/gui/session/hotkeys/misc.xml @@ -9,7 +9,7 @@ - g_Tutorial?.toggle(); + g_TutorialManager?.toggleVisibility(); diff --git a/binaries/data/mods/public/gui/session/messages.js b/binaries/data/mods/public/gui/session/messages.js index a65d42ba16..857d73b936 100644 --- a/binaries/data/mods/public/gui/session/messages.js +++ b/binaries/data/mods/public/gui/session/messages.js @@ -164,7 +164,7 @@ var g_NotificationsTypes = }, "tutorial": function(notification, player) { - g_Tutorial.handleNotification(notification); + g_TutorialManager.handleNotification(notification); }, "tribute": function(notification, player) { diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 90ef75f54a..66b95176b0 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -35,7 +35,7 @@ var g_ResearchProgress; var g_TimeNotificationOverlay; var g_TopPanel; var g_TradeDialog; -var g_Tutorial; +var g_TutorialManager; /** * Map, player and match settings set in game setup. @@ -345,7 +345,7 @@ async function init(initData, hotloadData) g_NetworkStatusOverlay = new NetworkStatusOverlay(closePageCallback); g_QuitConfirmationDefeat = new QuitConfirmationDefeat(closePageCallback); g_QuitConfirmationReplay = new QuitConfirmationReplay(closePageCallback); - g_Tutorial = new Tutorial(closePageCallback); + g_TutorialManager = new TutorialManager(closePageCallback); })]); // TODO: use event instead diff --git a/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js b/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js new file mode 100644 index 0000000000..b3b6b6d011 --- /dev/null +++ b/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.js @@ -0,0 +1,66 @@ +/** + * 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" }; diff --git a/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.xml b/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.xml new file mode 100644 index 0000000000..437db1e460 --- /dev/null +++ b/binaries/data/mods/public/gui/session/tutorial/InstructionPanel.xml @@ -0,0 +1,10 @@ + + + + + + + + Ready + + diff --git a/binaries/data/mods/public/gui/session/tutorial/Tutorial.js b/binaries/data/mods/public/gui/session/tutorial/Tutorial.js deleted file mode 100644 index cf55c6d76b..0000000000 --- a/binaries/data/mods/public/gui/session/tutorial/Tutorial.js +++ /dev/null @@ -1,69 +0,0 @@ -class Tutorial -{ - panel = Engine.GetGUIObjectByName("tutorialPanel"); - text = Engine.GetGUIObjectByName("tutorialText"); - warning = Engine.GetGUIObjectByName("tutorialWarning"); - readyButton = Engine.GetGUIObjectByName("tutorialReady"); - instructions = []; - closePageCallback; - - constructor(closePageCallback) - { - this.closePageCallback = closePageCallback; - } - - toggle() - { - this.panel.hidden = !this.panel.hidden || !this.text.caption; - } - - handleNotification(notification) - { - if (notification.step) - this.displayStep(notification.step); - if (notification.warning) - this.displayWarning(notification.warning); - } - - displayWarning(warning) - { - this.warning.caption = coloredText(translate(warning), "orange"); - } - - displayStep(step) - { - this.panel.hidden = false; - - const notificationText = - step.instructions.reduce((instructions, item) => - 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.instructions.push(notificationText); - - if (step.readyButton) - { - this.readyButton.hidden = false; - if (step.leave) - { - this.warning.caption = translate("Click to quit this tutorial."); - this.readyButton.caption = translate("Quit"); - this.readyButton.onPress = () => { this.closePageCallback({ [Engine.openRequest]: endGame(true) }); }; - } - else - this.warning.caption = translate("Click when ready."); - } - else - { - this.warning.caption = translate("Follow the instructions."); - this.readyButton.hidden = true; - } - } -} - -/** - * GUI tags applied to the most recent instruction. - */ -Tutorial.prototype.NewInstructionTags = { "color": "255 226 149" }; - diff --git a/binaries/data/mods/public/gui/session/tutorial/Tutorial.xml b/binaries/data/mods/public/gui/session/tutorial/Tutorial.xml index 7016004e34..ccb9470b44 100644 --- a/binaries/data/mods/public/gui/session/tutorial/Tutorial.xml +++ b/binaries/data/mods/public/gui/session/tutorial/Tutorial.xml @@ -1,14 +1,4 @@ -