2017-05-17 10:33:36 -07:00
|
|
|
Trigger.prototype.InitTutorial = function(data)
|
|
|
|
|
{
|
|
|
|
|
this.index = 0;
|
|
|
|
|
this.fullText = "";
|
|
|
|
|
this.tutorialEvents = [];
|
|
|
|
|
|
|
|
|
|
// Register needed triggers
|
|
|
|
|
this.RegisterTrigger("OnDeserialized", "OnDeserializedTrigger", { "enabled": true });
|
|
|
|
|
this.RegisterTrigger("OnPlayerCommand", "OnPlayerCommandTrigger", { "enabled": false });
|
|
|
|
|
this.tutorialEvents.push("OnPlayerCommand");
|
|
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
for (const goal of this.tutorialGoals)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
for (const key in goal)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2025-06-26 01:37:24 -07:00
|
|
|
if (typeof goal[key] !== "function" || this.tutorialEvents.indexOf(key) != -1)
|
2017-05-17 10:33:36 -07:00
|
|
|
continue;
|
2017-08-31 10:48:50 -07:00
|
|
|
if (key == "Init")
|
2017-08-19 02:38:52 -07:00
|
|
|
continue;
|
2017-08-31 10:48:50 -07:00
|
|
|
if (key == "IsDone")
|
2017-08-19 02:38:52 -07:00
|
|
|
continue;
|
2025-05-09 10:44:52 -07:00
|
|
|
const action = key + "Trigger";
|
2017-05-17 10:33:36 -07:00
|
|
|
this.RegisterTrigger(key, action, { "enabled": false });
|
|
|
|
|
this.tutorialEvents.push(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.NextGoal();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Trigger.prototype.NextGoal = function(deserializing = false)
|
|
|
|
|
{
|
|
|
|
|
if (this.index > this.tutorialGoals.length)
|
|
|
|
|
return;
|
2025-05-09 10:44:52 -07:00
|
|
|
const goal = this.tutorialGoals[this.index];
|
2017-05-17 10:33:36 -07:00
|
|
|
let needDelay = true;
|
|
|
|
|
let readyButton = false;
|
2017-08-19 02:38:52 -07:00
|
|
|
|
|
|
|
|
Trigger.prototype.Init = goal.Init || null;
|
|
|
|
|
if (!deserializing && this.Init)
|
|
|
|
|
this.Init();
|
|
|
|
|
|
|
|
|
|
Trigger.prototype.IsDone = goal.IsDone || (() => false);
|
2025-05-09 10:44:52 -07:00
|
|
|
const goalAlreadyDone = this.IsDone();
|
2017-08-19 02:38:52 -07:00
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
for (const event of this.tutorialEvents)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
const action = event + "Trigger";
|
2017-05-17 10:33:36 -07:00
|
|
|
if (goal[event])
|
|
|
|
|
{
|
|
|
|
|
Trigger.prototype[action] = goal[event];
|
|
|
|
|
this.EnableTrigger(event, action);
|
2017-08-19 02:38:52 -07:00
|
|
|
if (!goalAlreadyDone)
|
|
|
|
|
needDelay = false;
|
2017-05-17 10:33:36 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.DisableTrigger(event, action);
|
|
|
|
|
}
|
2017-08-19 02:38:52 -07:00
|
|
|
|
|
|
|
|
// Goals without actions to be performed by the player must have
|
|
|
|
|
// - either the property delay (a value > 0 to wait for a given time, and -1 to display the Ready button)
|
|
|
|
|
// - or no trigger functions (needDelay will be set automatically to true and the Ready button displayed)
|
|
|
|
|
if (goal.delay || needDelay)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2017-08-19 02:38:52 -07:00
|
|
|
if (goal.delay && goal.delay > 0)
|
2017-05-17 10:33:36 -07:00
|
|
|
this.DoAfterDelay(+goal.delay, "NextGoal", {});
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.EnableTrigger("OnPlayerCommand", "OnPlayerCommandTrigger");
|
|
|
|
|
Trigger.prototype.OnPlayerCommandTrigger = function(msg)
|
2017-08-19 02:38:52 -07:00
|
|
|
{
|
2017-05-17 10:33:36 -07:00
|
|
|
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial && msg.cmd.tutorial == "ready")
|
|
|
|
|
this.NextGoal();
|
|
|
|
|
};
|
|
|
|
|
readyButton = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.GoalMessage(goal.instructions, readyButton, ++this.index == this.tutorialGoals.length);
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-20 11:04:48 -07:00
|
|
|
Trigger.prototype.GoalMessage = function(instructions, readyButton=false, leave=false)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
const cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
2017-05-17 10:33:36 -07:00
|
|
|
cmpGUIInterface.PushNotification({
|
|
|
|
|
"type": "tutorial",
|
|
|
|
|
"players": [1],
|
2025-06-26 01:37:24 -07:00
|
|
|
"instructions": typeof instructions === "string" ? [instructions] : instructions,
|
2017-05-17 10:33:36 -07:00
|
|
|
"readyButton": readyButton,
|
|
|
|
|
"leave": leave
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-20 11:04:48 -07:00
|
|
|
Trigger.prototype.WarningMessage = function(warning)
|
2017-05-17 10:33:36 -07:00
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
const cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
2017-05-17 10:33:36 -07:00
|
|
|
cmpGUIInterface.PushNotification({
|
|
|
|
|
"type": "tutorial",
|
|
|
|
|
"players": [1],
|
2017-08-20 11:04:48 -07:00
|
|
|
"warning": warning
|
2017-05-17 10:33:36 -07:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Trigger.prototype.OnDeserializedTrigger = function()
|
|
|
|
|
{
|
|
|
|
|
this.index = Math.max(0, this.index - 1);
|
|
|
|
|
|
|
|
|
|
// Display messages from already processed goals
|
|
|
|
|
for (let i = 0; i < this.index; ++i)
|
|
|
|
|
this.GoalMessage(this.tutorialGoals[i].instructions, false, false);
|
|
|
|
|
|
|
|
|
|
this.NextGoal(true);
|
|
|
|
|
};
|