/**
* Rules Tutorial library
* Show the rules in the dedicated interface
*/

#Const Version "2017-05-15"
#Const ScriptName "TutorialInterface.Script.txt"

#Include "TextLib" as TextLib
#Include "Libs/Nadeo/UISync.Script.txt" as UISync
#Include "Libs/Nadeo/MatchmakingLobby.Script.txt" as MMLobby
#Include "Libs/Nadeo/Manialink3.Script.txt" as Manialink


//-------------------------//
// Globales
//-------------------------//
declare Text G_LibTutorialInterface_ModeName; 															///<The name of the mode
declare Text G_LibTutorialInterface_ModeType;															///<The type of the mode : Free For All, Team Versus Team, Attack Versus Defence, Custom

declare Text G_LibTutorialInterface_ModeMethod;														///<What you have to do in the mode
declare Text G_LibTutorialInterface_ModeMethodAttack;											///<What you have to do in attack-defence if attack
declare Text G_LibTutorialInterface_ModeMethodDefence;											///<What you have to do in attack-defence if defence

declare Integer G_LibTutorialInterface_ModePlayerArmor;										///<The armor of a player if FFA or TeamBased
declare Text G_LibTutorialInterface_ModePlayerWeapon;											///<The weapon of a player if FFA or TeamBased : Lazer, Arrow, Nucleus, Rocket, Custom
declare Integer G_LibTutorialInterface_ModePlayerAmmo;											///<The ammo of the player

declare Integer G_LibTutorialInterface_ModeAttackerArmor;									///<The armor of an attacker if Attack-Defence
declare Integer G_LibTutorialInterface_ModeDefenderArmor;									///<The armor of a defender if Attack-Defence
declare Text G_LibTutorialInterface_ModeAttackerWeapon;										///<The weapon of an attacker if Attack-Defence : Lazer, Arrow, Nucleus, Rocket, Custom
declare Integer G_LibTutorialInterface_ModeAttackerAmmo;										///<The ammo of the attacker
declare Text G_LibTutorialInterface_ModeDefenderWeapon;										///<The weapon of a defender if Attack-Defence : Lazer, Arrow, Nucleus, Rocket, Custom
declare Integer G_LibTutorialInterface_ModeDefenderAmmo;										///<The ammo of the defender


declare Ident G_LibTutorialInterface_LayerRulesId;													///<The id of the layer containing the canvas

declare Text[] G_LibTutorialInterface_WinConditions;												///<Array of win conditions
declare Text[Text] G_LibTutorialInterface_WinConditionsText;							///<Array of win conditions' text
declare Integer[Text] G_LibTutorialInterface_WinConditionsTeam;						///<Array of number defining the team the win condition apply to
declare Text[Text] G_LibTutorialInterface_WinConditionsPicture;						///<Array of pictures illustrating win conditions

declare Integer G_LibTutorialInterface_FrameCount;

declare Text[] G_LibTutorialInterface_GameflowTabs;												///Array of susbsections' tab id
declare Text[] G_LibTutorialInterface_GameflowFrames;											///Array of subsections' frame id
declare Text[] G_LibTutorialInterface_GameflowMediaTracks;								///Array of subsections' mediatrack's buttons
declare Text[] G_LibTutorialInterface_GameflowLabels; 											///Array of subsections' title label id
declare Text[] G_LibTutorialInterface_GameflowLabelsStripes;								///Array of subsections' title stripes

declare Text[]		G_LibTutorialInterface_GameflowSubsections; 							///<Array of subsections' titles in Gameflow
declare Text[Text] 	G_LibTutorialInterface_GameflowSubsectionsText;			///<Array of subssections' texts in Gameflow
declare Text[Text] 	G_LibTutorialInterface_GameflowSubsectionsPicture1;	///<Array of subsectionss' first picture in Gameflow
declare Text[Text] 	G_LibTutorialInterface_GameflowSubsectionsPicture2;	///<Array of subsectionss' second picture in Gameflow
declare Text[Text] 	G_LibTutorialInterface_GameflowSubsectionsPicture3;	///<Array of subsectionss' third picture in Gameflow
declare Text[Text]		G_LibTutorialInterface_GameflowSubsectionsMediaTrack;///<Array of subsectionss' mediatrack

declare Text  G_LibTutorialInterface_FirstPage;														///<Define the first page

//for Teams[0]

//-------------------------//
// Getters
//-------------------------//
/** Return the version number of the script
*
* @return The version number of the script
*/

Text GetScriptVersion(){
	return Version;
}

// ---------------------------------- //
/** Return the name of the script
 *
 *	@return		The name of the script
 */
Text GetScriptName() {
	return ScriptName;
}

// ---------------------------------- //
// Setters
// ---------------------------------- //


/**
 * Set the name of the mode 
 */
Void SetModeName(Text _ModeName) {
	G_LibTutorialInterface_ModeName = TextLib::MLEncode(_ModeName);
}

/**
 * Set the type of the mode 
 */
Void SetModeType(Text _ModeType) {
	G_LibTutorialInterface_ModeType = TextLib::MLEncode(_ModeType);
}

/**
 * Set what you have to do in the mode 
 */
Void SetModePrinciple(Text _ModeMethod) {
	G_LibTutorialInterface_ModeMethod = TextLib::MLEncode(_ModeMethod);
}

/**
 * Set what you have to do in the mode 
 */
Void SetModePrinciple(Text _ModeMethodAttack, Text _ModeMethodDefence) {
	G_LibTutorialInterface_ModeMethodAttack = TextLib::MLEncode(_ModeMethodAttack);
	G_LibTutorialInterface_ModeMethodDefence = TextLib::MLEncode(_ModeMethodDefence);	
}

/**
 * Set equipment of the player 
 */
Void SetEquipment(Text _PlayerWeapon, Integer _PlayerAmmo, Integer _PlayerArmor){
	G_LibTutorialInterface_ModePlayerArmor = _PlayerArmor;
	G_LibTutorialInterface_ModePlayerAmmo = _PlayerAmmo;
	G_LibTutorialInterface_ModePlayerWeapon = TextLib::MLEncode(_PlayerWeapon);
}

/**
 * OVERLOAD
 * Set equipment of the teams if asymmetric
 */
Void SetEquipment(Text _AttackerWeapon, Integer _AttackerAmmo, Integer _AttackerArmor, Text _DefenderWeapon, Integer _DefenderAmmo, Integer _DefenderArmor){
	G_LibTutorialInterface_ModeAttackerArmor = _AttackerArmor;
	G_LibTutorialInterface_ModeAttackerAmmo = _AttackerAmmo;
	G_LibTutorialInterface_ModeAttackerWeapon = TextLib::MLEncode(_AttackerWeapon);	
	G_LibTutorialInterface_ModeDefenderArmor = _DefenderArmor;
	G_LibTutorialInterface_ModeDefenderAmmo = _DefenderAmmo;
	G_LibTutorialInterface_ModeDefenderWeapon = TextLib::MLEncode(_DefenderWeapon);
}

Void SetFirstPage(Text _FirstPage){
	G_LibTutorialInterface_FirstPage = _FirstPage;
}

// ---------------------------------- //
// Reset
// ---------------------------------- //

/**
 * Reset all previously written pretty rules.
 */
Void Reset_Gameflow_Section() {
	G_LibTutorialInterface_GameflowSubsections.clear();
	G_LibTutorialInterface_GameflowSubsectionsText.clear();
	G_LibTutorialInterface_GameflowSubsectionsPicture1.clear();
	G_LibTutorialInterface_GameflowSubsectionsPicture2.clear();
	G_LibTutorialInterface_GameflowSubsectionsPicture3.clear();
	G_LibTutorialInterface_FrameCount = 0;
}

/**
* Reset all previously written equipment
*/
Void Reset_Equipment_Section() {
	G_LibTutorialInterface_ModeAttackerAmmo = 0;
	G_LibTutorialInterface_ModeAttackerArmor = 0;
	G_LibTutorialInterface_ModeAttackerWeapon = "";
	G_LibTutorialInterface_ModeDefenderAmmo = 0;
	G_LibTutorialInterface_ModeDefenderArmor = 0;
	G_LibTutorialInterface_ModeDefenderWeapon = "";
	G_LibTutorialInterface_ModePlayerAmmo = 0;
	G_LibTutorialInterface_ModePlayerArmor = 0;
	G_LibTutorialInterface_ModePlayerWeapon = "";
}

/**
* Reset all previously written Win Conditions
*/
Void Reset_WinConditions_Section(){
	G_LibTutorialInterface_WinConditions.clear();
	G_LibTutorialInterface_WinConditionsPicture.clear();
	G_LibTutorialInterface_WinConditionsTeam.clear();
	G_LibTutorialInterface_WinConditionsText.clear();
}

Void Load(){
	Reset_WinConditions_Section();
	Reset_Equipment_Section();
	Reset_Gameflow_Section();
}

// ---------------------------------- //
// Public Functions
// ---------------------------------- //

/**Add a quad with a title, a text and a picture for symmetric game modes
* @param _Title text and identifier of the quad
*	@param _Text text displayed in the quad
* @param _Picture picture displayed in the quad
* @param _Team integer that require 0 for "Attack" or 1 for "Defense" as parameter to set a specific color to the quad
**/
Void Add_WinCondition(Text _Title, Text _Text, Integer _Team , Text _Picture){
	G_LibTutorialInterface_WinConditions.add(_Title);
	G_LibTutorialInterface_WinConditionsText[_Title] = _Text;
	G_LibTutorialInterface_WinConditionsTeam[_Title] = _Team;
	G_LibTutorialInterface_WinConditionsPicture[_Title] = _Picture;
}

//Overload
Void Add_WinCondition(Text _Title, Text _Text, Integer _Team){
	G_LibTutorialInterface_WinConditions.add(_Title);
	G_LibTutorialInterface_WinConditionsText[_Title] = _Text;
	G_LibTutorialInterface_WinConditionsTeam[_Title] = _Team;
}
//Overload
Void Add_WinCondition(Text _Title, Text _Text, Text _Picture){
	G_LibTutorialInterface_WinConditions.add(_Title);
	G_LibTutorialInterface_WinConditionsText[_Title] = _Text;
	G_LibTutorialInterface_WinConditionsPicture[_Title] = _Picture;
}
//Overload
Void Add_WinCondition(Text _Title, Text _Text){
	G_LibTutorialInterface_WinConditions.add(_Title);
	G_LibTutorialInterface_WinConditionsText[_Title] = _Text;
}

/**
 * Add a frame with a title, a text and 0 to 3 pictures. Can't add more than 8 frames
 * @param _Title	text and identifier of the frame subsection in gameflow
 * @param _MainText	a text displayed in this subsection
 * @param _Picture1  first picture displayed
 * @param _Picture2  second picture displayed
 * @param _Picture3  third picture displayed
 */
Void Add_Gameflow_Subsection(Text _Title, Text _MainText) {
	if(G_LibTutorialInterface_FrameCount < 8){
		G_LibTutorialInterface_GameflowSubsections.add(_Title);
		G_LibTutorialInterface_GameflowSubsectionsText[_Title] = _MainText;
		G_LibTutorialInterface_FrameCount = G_LibTutorialInterface_GameflowSubsections.count;
	}
}

//OVERLOAD
Void Add_Gameflow_Subsection(Text _Title, Text _MainText, Text Picture1) {
	if(G_LibTutorialInterface_FrameCount < 8){
		G_LibTutorialInterface_GameflowSubsections.add(_Title);
		G_LibTutorialInterface_GameflowSubsectionsText[_Title] = _MainText;
		G_LibTutorialInterface_GameflowSubsectionsPicture1[_Title] = Picture1;
		G_LibTutorialInterface_FrameCount = G_LibTutorialInterface_GameflowSubsections.count;
	}
}

//OVERLOAD
Void Add_Gameflow_Subsection(Text _Title, Text _MainText, Text Picture1, Text Picture2) {
	if(G_LibTutorialInterface_FrameCount < 8){
		G_LibTutorialInterface_GameflowSubsections.add(_Title);
		G_LibTutorialInterface_GameflowSubsectionsText[_Title] = _MainText;
		G_LibTutorialInterface_GameflowSubsectionsPicture1[_Title] = Picture1;
		G_LibTutorialInterface_GameflowSubsectionsPicture2[_Title] = Picture2;
		G_LibTutorialInterface_FrameCount = G_LibTutorialInterface_GameflowSubsections.count;
	}
}

//OVERLOAD
Void Add_Gameflow_Subsection(Text _Title, Text _MainText, Text Picture1, Text Picture2, Text Picture3) {
	if(G_LibTutorialInterface_FrameCount < 8){
		G_LibTutorialInterface_GameflowSubsections.add(_Title);
		G_LibTutorialInterface_GameflowSubsectionsText[_Title] = _MainText;
		G_LibTutorialInterface_GameflowSubsectionsPicture1[_Title] = Picture1;
		G_LibTutorialInterface_GameflowSubsectionsPicture2[_Title] = Picture2;
		G_LibTutorialInterface_GameflowSubsectionsPicture3[_Title] = Picture3;
		G_LibTutorialInterface_FrameCount = G_LibTutorialInterface_GameflowSubsections.count;
	}
}
/**
 * Add a mediatrack related to a gameflow subsection
 * @param _GameflowSubsectionName text and identifier of the frame subsection
 * @param _MediaTrack the name of the CustomMediaTrack to link to a gameflow subsection, its name is registered with the map
 */
Void Add_Gameflow_Subsection_Mediatrack(Text _GameflowSubsectionName, Text _MediaTrack){
	G_LibTutorialInterface_GameflowSubsectionsMediaTrack[_GameflowSubsectionName] = _MediaTrack;
}

// ---------------------------------- //
// Private Functions
// ---------------------------------- //


/**
 *	Create the Manialink for the Type and Method
 **/
Text Private_Create_ModeMethod_Content(){
	declare ML="";
		//L16N 	Win conditions of the game, conditions players have to fulfill to win
	if(G_LibTutorialInterface_ModeMethod != ""){
		ML^="""
		<!--Symmetric-->
		<quad pos="0 -11" z-index="23" size="140 38" bgcolor="00000066"/>
		<quad pos="0 -11" z-index="22" size="140 38" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<label pos="8 -13.5" z-index="30" textsize="7" text=">" textfont="Oswald" />
		<label pos="18 -16" z-index="30" size="125 14" text="{{{G_LibTutorialInterface_ModeType}}}" textsize="4" 
		textfont="Oswald" textcolor="FFFFFFFF" maxline="2"/>
		<label pos="8 -28.5" z-index="30" textsize="7" text=">" textfont="Oswald" />
		<label pos="18 -31" z-index="30" size="125 25" text="{{{G_LibTutorialInterface_ModeMethod}}}" textsize="4" 
		textfont="Oswald"  autonewline="1" maxline="2"/>
		""";
	}else if(G_LibTutorialInterface_ModeMethodAttack != "" || G_LibTutorialInterface_ModeMethodDefence != ""){
		ML^="""
		<!--Asymetric-->
		<quad pos="0 -11" z-index="23" size="140 38" bgcolor="00000066"/>
		<quad pos="0 -11" z-index="22" size="140 38" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<quad pos="13 -20" z-index="30" size="7 7" bgcolor="FFFA" style="Icons128x128_1" substyle="BackFocusable" 
		rot="180"/>
		<label pos="13 -14" z-index="30" size="125 14" text="{{{G_LibTutorialInterface_ModeType}}}" textsize="4" 
		textfont="Oswald" textcolor="FFFFFFFF" maxline="2"/>
		<quad pos="13 -30" z-index="30" size="7 7" bgcolor="FFFA" style="Icons128x128_1" substyle="BackFocusable" 
		rot="180"/>
		<label pos="13 -24" z-index="30" size="125 25" text="{{{G_LibTutorialInterface_ModeMethodAttack}}}" textsize="4" 
		textfont="Oswald" textcolor="FF0000FF" autonewline="1" maxline="2"/>
		<quad pos="13 -43" z-index="30" size="7 7" bgcolor="FFFA" style="Icons128x128_1" substyle="BackFocusable" 
		rot="180"/>
		<label pos="13 -37" z-index="30" size="125 25" text="{{{G_LibTutorialInterface_ModeMethodDefence}}}" textsize="4" 
		textfont="Oswald" textcolor="0000FFFF" autonewline="1" maxline="2" />
		""";
	}
	return ML;
}

/**
 *	Create the Manialink for the Win Conditions
 **/

Text Private_Create_WinCondition_Content(){
	declare ML="";
	declare Text WinConditionText = "";
	declare Text WinConditionsTitle = _("|Parameters that define how to win|Win Conditions");
	declare Text WinConditionPicture = "";
	declare Real WinConditionPosX = 0.;
	declare Real WinConditionPosY = -65.;
	declare Real PictureSize = 16.0 ;
	declare Text ColorText = "FFFFFFFF";
	declare Integer WinConditionCount = G_LibTutorialInterface_WinConditions.count;
	declare Integer WinConditionMaxPerPage = 4;
	declare Text LabelID = "";
	declare Text PictureID = "";
	declare Text StripeID="";
	while (WinConditionCount%4 != 0){
		Add_WinCondition("WCFill"^WinConditionCount+1,"");
		WinConditionCount = G_LibTutorialInterface_WinConditions.count;
	}
	ML^="""
	<label pos="0 -56" z-index="25" size="40 10" text="{{{WinConditionsTitle}}}" textsize="7" textfont="Oswald" 
	valign="center2" halign="Left" textprefix="$s"/>	
	<quad pos="0 -61" z-index="28" size="140 80" bgcolor="00000066" />
	<quad pos="0 -61" z-index="27" size="140 80" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
	""";
	for(WinConditionCurrentPageIndex,0,WinConditionMaxPerPage-1){
		ColorText = "FFFFFFFF";
		declare Text WinConditionIndex = G_LibTutorialInterface_WinConditions[WinConditionCurrentPageIndex];
		if(G_LibTutorialInterface_WinConditionsTeam.existskey(WinConditionIndex)){
			if(G_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 0){
				ColorText = "1111FFFF";
			}
			if(G_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 1){
				ColorText = "FF1111FF";
			}			
		}

		LabelID = "Label_WinCondition"^WinConditionCurrentPageIndex;
		PictureID = "Picture_WinCondition"^WinConditionCurrentPageIndex;
		StripeID= "Stripe_WinCondition"^WinConditionCurrentPageIndex;
		
		declare Text _Text = G_LibTutorialInterface_WinConditionsText[WinConditionIndex];
		ML^="""
		<label pos="19 {{{WinConditionPosY}}}" z-index="30" textsize="4" text="{{{_Text}}}" 
		size="119 {{{PictureSize+2}}}" textfont="Oswald" autonewline="1" textcolor="{{{ColorText}}}" 
		maxline="3" id="{{{LabelID}}}"/>
		""";
		if(G_LibTutorialInterface_WinConditionsPicture.existskey(WinConditionIndex)){
			declare Text _Picture = G_LibTutorialInterface_WinConditionsPicture[WinConditionIndex];
			ML^="""
			<quad pos="1.5 {{{WinConditionPosY - 1}}}" z-index="30" size="{{{PictureSize}}} {{{PictureSize}}}" 
			image="{{{_Picture}}}" id="{{{PictureID}}}"/>
			<label pos="8 {{{WinConditionPosY + 2}}}" z-index="30" textsize="7" text=">" textfont="Oswald" 
			id="{{{StripeID}}}" hidden="1"/>
			""";
		}else if(G_LibTutorialInterface_WinConditionsText[WinConditionIndex] != ""){
			ML^="""
			<quad pos="7 {{{WinConditionPosY}}}" z-index="30" size="{{{PictureSize - 10}}} {{{PictureSize - 10}}}" 
			image=" " id="{{{PictureID}}}" />
			<label pos="8 {{{WinConditionPosY + 2}}}" z-index="30" textsize="7" text=">" textfont="Oswald" id="{{{StripeID}}}" />
			""";
		}	
		WinConditionPosY -= 19.5;	
	}	
	if(WinConditionCount > 4){
		ML^="""
		<quad pos="127 -52" z-index="40" size="6 8" colorize="FFFF" 
		image="file://Media/Manialinks/Common/Button_Scroll_v.dds" id="Button_WinConditionsPrev" scriptevents="1"/>
		<quad rot="180" pos="140 -60.2" z-index="40" size="6 8"  colorize="FFFF" 
		image="file://Media/Manialinks/Common/Button_Scroll_v.dds" id="Button_WinConditionsNext" scriptevents="1"/>
		""";
	}
	return ML;
}


/**
 * create the manialink for the gameflow subsections
 */
 
Text Private_Create_GameflowSubsection_Content(){
	declare Text ML="";
	//L16N	Show how to perform an action
	declare Text MediaTrackButtonText = _("|Display a video showing a feature of a mode|Show me"); 
	declare Real PosPicY = 69.;
	declare Real SizePicX = 42.;
	declare Real SizePicY = 42.;
	for(CurrentFrame,G_LibTutorialInterface_FrameCount,7){
		declare Text FrameId = G_LibTutorialInterface_GameflowFrames[CurrentFrame];
		declare Text LabelId = G_LibTutorialInterface_GameflowLabels[CurrentFrame];
		declare Text TabId = G_LibTutorialInterface_GameflowTabs[CurrentFrame];
		declare Text LabelStripeId = G_LibTutorialInterface_GameflowLabelsStripes[CurrentFrame];
		ML^="""
			<frame id="{{{FrameId}}}" hidden="1" pos = "-130 60">
				<label pos="2000 2000" z-index="30" size="60 10" text=" " textsize="8" 
				textfont="Oswald" textcolor="FFFFFFFF" id={{{LabelId}}}/>
				<label pos="2000 2000" z-index="30" size="60 10" text="" textsize="8"
				textfont="Oswald" textcolor="FFFFFFFF" id={{{LabelStripeId}}}/>
				<quad pos="2000 2000" z-index="28" size="60 10" 
				id="{{{TabId}}}" bgcolor="00000066" scriptevents="1"  />
			</frame>
		""";
	} 
	for(CurrentFrame,0,G_LibTutorialInterface_FrameCount -1){
		declare Text GameflowSubsection = G_LibTutorialInterface_GameflowSubsections[CurrentFrame];
		declare Text GameflowSubsectionText = G_LibTutorialInterface_GameflowSubsectionsText[GameflowSubsection];
		declare Text GameflowSubsectionPicture1;
		declare Text GameflowSubsectionPicture2;
		declare Text GameflowSubsectionPicture3;
		if(G_LibTutorialInterface_GameflowSubsectionsPicture1.existskey(GameflowSubsection)){
			GameflowSubsectionPicture1 = G_LibTutorialInterface_GameflowSubsectionsPicture1[GameflowSubsection];
		}
		if(G_LibTutorialInterface_GameflowSubsectionsPicture2.existskey(GameflowSubsection)){
			GameflowSubsectionPicture2 = G_LibTutorialInterface_GameflowSubsectionsPicture2[GameflowSubsection];
		}
		if(G_LibTutorialInterface_GameflowSubsectionsPicture3.existskey(GameflowSubsection)){
			GameflowSubsectionPicture3 = G_LibTutorialInterface_GameflowSubsectionsPicture3[GameflowSubsection];
		}
		declare Text FrameId = G_LibTutorialInterface_GameflowFrames[CurrentFrame];
		declare Text TabId = G_LibTutorialInterface_GameflowTabs[CurrentFrame];
		declare Text LabelId = G_LibTutorialInterface_GameflowLabels[CurrentFrame];
		declare Text LabelStripesId = G_LibTutorialInterface_GameflowLabelsStripes[CurrentFrame];
		declare Real PosTabY = 51. - CurrentFrame * 11.;
		ML^="""
		<quad pos="-130 {{{PosTabY}}}" z-index="24" size="60 10" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<quad pos="-130 {{{PosTabY}}}" z-index="28" size="60 10" id="{{{TabId}}}" bgcolor="00000066" scriptevents="1"  />
		<label pos="-120 {{{PosTabY-2}}}" z-index="30" size="60 10" text="{{{GameflowSubsection}}}" textsize="6" 
		textfont="Oswald" textcolor="FFFFFFFF" id={{{LabelId}}}/>
		<label pos="-126 {{{PosTabY-1}}}" z-index="30" size="60 10" text=">" textfont="Oswald" textsize="6" 
		textcolor="FF0000FF" id="{{{LabelStripesId}}}"/>
		
		<frame id="{{{FrameId}}}" hidden="1" pos="-69 -9" z-index="24.5">
			
		""";
		if(G_LibTutorialInterface_GameflowSubsectionsPicture1.existskey(GameflowSubsection)){
			ML^="""
			<quad pos="0 24" z-index="25" size="140 94" bgcolor="00000066"/>
			<quad pos="0 24" z-index="25" size="140 94" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<label pos="4 21" z-index="28" size="133 84" text="{{{GameflowSubsectionText}}}" textcolor="FFFFFFFF" 
			textsize="4" textfont="Oswald" autonewline="1" maxline="11"/>
			""";
		}else{
			ML^="""
			<quad pos="0 71" z-index="25" size="140 141" bgcolor="00000066"/>
			<quad pos="0 71" z-index="25" size="140 141" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<label pos="4 68" z-index="30" size="133 125" text="{{{GameflowSubsectionText}}}" textcolor="FFFFFF" 
			textsize="4" textfont="Oswald" autonewline="1" maxline="16"/>
			""";
			}
		if(G_LibTutorialInterface_GameflowSubsectionsPicture3.existskey(GameflowSubsection)){
			ML^="""
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="46 46" bgcolor="00000066"/>
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="46 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="2 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture1}}}"/>
			<quad pos="47 {{{PosPicY+2}}}" z-index="24" size="46 46" bgcolor="00000066"/>
			<quad pos="47 {{{PosPicY+2}}}" z-index="24" size="46 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="49 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture2}}}"/>
			<quad pos="94 {{{PosPicY+2}}}" z-index="24" size="46 46" bgcolor="00000066"/>
			<quad pos="94 {{{PosPicY+2}}}" z-index="24" size="46 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="96 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture3}}}"/>
			""";
		}else if(G_LibTutorialInterface_GameflowSubsectionsPicture2.existskey(GameflowSubsection)){
			ML^="""
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="69.5 46" bgcolor="00000066"/>
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="69.5 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="15 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture1}}}"/>
			<quad pos="70.5 {{{PosPicY+2}}}" z-index="24" size="69.5 46" bgcolor="00000066"/>
			<quad pos="70.5 {{{PosPicY+2}}}" z-index="24" size="69.5 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="85 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture2}}}"/>
			""";
		}else if(G_LibTutorialInterface_GameflowSubsectionsPicture1.existskey(GameflowSubsection)){
			ML^="""
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="140 46" bgcolor="00000066"/>
			<quad pos="0 {{{PosPicY+2}}}" z-index="24" size="140 46" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="51 {{{PosPicY}}}" z-index="25" size="{{{SizePicX}}} {{{SizePicY}}}" bgcolor="FFFA" 
			image="{{{GameflowSubsectionPicture1}}}"/>
			""";
		}
		if(G_LibTutorialInterface_GameflowSubsectionsMediaTrack.existskey(GameflowSubsection)){
			declare Text MediaTrackButtonId = G_LibTutorialInterface_GameflowMediaTracks[CurrentFrame];
			ML^="""
			<label pos="44 -57" z-index="26" size="50 10" focusareacolor1="44FF4433" focusareacolor2="FFFFFF33" 
			scriptevents="1" id="{{{MediaTrackButtonId}}}" />
			<quad pos="46 -55.5" z-index="28" size="12 12" style="ManiaPlanetMainMenu" substyle="IconPlay"/>
			<label pos="60 -58" z-index="28" size="60 10" textfont="Oswald" text="{{{MediaTrackButtonText}}}" 
			textsize="7"/>
			""";
		}		
		ML^="""</frame>""";
	}
	return ML;
}


/**
 * Create the Manialink for the equipment (symmetric)
 */
 
Text Private_Create_Symmetric_Equipment_Content(){
	declare Real ArmorPosX = 70.;
	declare Real ArmorPosY = 45.;
	declare Real ArmorSizeX = 50.0 / G_LibTutorialInterface_ModePlayerArmor ;
	declare Real ArmorSizeY = 4.;
	declare Real AmmoPosX = 70.;
	declare Real AmmoPosY = 13.;
	declare Real AmmoSizeX = 50.0 / G_LibTutorialInterface_ModePlayerAmmo ;
	declare Real AmmoSizeY = 4.;
	
	declare ManiaLink="""
		<label pos="10 {{{ArmorPosY}}}" z-index="4" size="30 10" text="Armor :" halign="left" valign="center" textsize="5" 
		textfont="Oswald" textcolor="FFFFFFFF"/>
		<quad pos="50 {{{ArmorPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" substyle="UnknownHit" 
		halign="center" valign="center"/>
		<quad pos="94 {{{ArmorPosY}}}" z-index="4" size=" 62 12" bgcolor="FFFA" style="Bgs1" substyle="BgButtonGlow" 
		halign="center" valign="center"/>
		<quad pos="94 {{{ArmorPosY}}}" z-index="4.5" size="59 9" bgcolor="FFFA" style="EnergyBar" substyle="EnergyBar" 
		halign="center" valign="center"/>
	""";
		for(i,0,G_LibTutorialInterface_ModePlayerArmor-1) {
			ManiaLink^="""
				<quad pos="{{{ArmorPosX}}} {{{ArmorPosY}}}" z-index="5" size="{{{ArmorSizeX}}} {{{ArmorSizeY}}}" bgcolor="FFFA" 
				style="ProgressBarSmall" halign="left" valign="center" modulatecolor="80F"/>
			""";
			ArmorPosX+= ArmorSizeX; 
			 
		}
	ManiaLink^="""
		<label pos="10 {{{AmmoPosY}}}" z-index="4" size="30 10" text="Weapon :" halign="left" valign="center" 
		textsize="5" textfont="Oswald" />
		<quad pos="94 {{{AmmoPosY}}}" z-index="4" size=" 62 12" bgcolor="FFFA" style="Bgs1" substyle="BgButtonGlow" 
		halign="center" valign="center"/>
		<quad pos="94 {{{AmmoPosY}}}" z-index="4.5" size="59 9" bgcolor="FFFA" style="EnergyBar" substyle="EnergyBar" 
		halign="center" valign="center"/>
	""";
		if(G_LibTutorialInterface_ModePlayerWeapon == "Rocket"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" substyle="RocketHit" 
				halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModePlayerWeapon == "Nucleus"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" substyle="NucleusHit" 
				halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModePlayerWeapon == "Laser"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" substyle="LaserHit" 
				halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModePlayerWeapon == "Arrow"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" substyle="ArrowHit" 
				halign="center" valign="center"/>
			""";
		}
		for(i,0,G_LibTutorialInterface_ModePlayerAmmo-1){
			ManiaLink^="""
				<quad pos="{{{AmmoPosX}}} {{{AmmoPosY}}}" z-index="5" size="{{{AmmoSizeX}}} {{{AmmoSizeY}}}" bgcolor="FFFA" 
				style="ProgressBarSmall" halign="left" valign="center" modulatecolor="80F"/>
			""";
			AmmoPosX+= AmmoSizeX;
		
		}
			
	return ManiaLink;
}

/**
 * Create the Manialink for the equipment (asymmetric)
 */

Text Private_Create_Asymmetric_Equipment_Content(){
	declare Text Attack = _("Attack");
	declare ArmorAttackerPosX = 70.;
	declare ArmorAttackerPosY= 44.;
	declare ArmorAttackerSizeX = 50 / G_LibTutorialInterface_ModeAttackerArmor ;
	declare ArmorAttackerSizeY = 4.;
	declare AmmoAttackerPosX = 70.;
	declare AmmoAttackerPosY = 18.;
	declare AmmoAttackerSizeX = 50 / G_LibTutorialInterface_ModeAttackerAmmo ;
	declare AmmoAttackerSizeY = 4.;
	declare ManiaLink="""
		<label pos="15 {{{ArmorAttackerPosY}}}" z-index="4" size="30 10" text="Armor :" halign="left" valign="center" 
		textsize="5" textfont="Oswald" textcolor="FF0000FF"/>
		<quad pos="50 {{{ArmorAttackerPosY}}}" z-index="4" size="20 20" halign="center" valign="center" bgcolor="FFFA" 	
		style="Icons64x64_2" substyle="UnknownHit"/>
		<quad pos="94 {{{ArmorAttackerPosY}}}" z-index="4" size=" 62 12" halign="center" valign="center" bgcolor="FFFA" 
		style="Bgs1" substyle="BgButtonGlow" />
		<quad pos="94 {{{ArmorAttackerPosY}}}" z-index="4.5" size="59 9" halign="center" valign="center" bgcolor="FFFA" 
		style="EnergyBar" substyle="EnergyBar" />
		<label pos="0 64" z-index="25" size="40 10" text="{{{Attack}}}" textsize="6" textfont="Oswald" valign="center2" 
		halign="Left" textprefix="$s"/>
	""";
		for(i,0,G_LibTutorialInterface_ModeAttackerArmor-1) {
			ManiaLink^="""
				<quad pos="{{{ArmorAttackerPosX}}} {{{ArmorAttackerPosY}}}"size="{{{ArmorAttackerSizeX}}} {{{ArmorAttackerSizeY}}}"
				 bgcolor="FFFA" z-index="5" style="ProgressBarSmall" halign="left" valign="center" modulatecolor="F00"/>
			""";
			ArmorAttackerPosX+= ArmorAttackerSizeX;  
		}
	ManiaLink^="""
		<label pos="15 {{{AmmoAttackerPosY}}}" z-index="4" size="30 10" text="Weapon :" halign="left" valign="center" 
		textsize="5" textfont="Oswald" textcolor="FF0000FF"/>
		<quad pos="94 {{{AmmoAttackerPosY}}}" z-index="4" size=" 62 12" bgcolor="FFFA" style="Bgs1" substyle="BgButtonGlow" 
		halign="center" valign="center"/>
		<quad pos="94 {{{AmmoAttackerPosY}}}" z-index="4.5" size="59 9" bgcolor="FFFA" style="EnergyBar" substyle="EnergyBar" 
		halign="center" valign="center"/>
	""";
		if(G_LibTutorialInterface_ModeAttackerWeapon == "Rocket"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoAttackerPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="RocketHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeAttackerWeapon == "Nucleus"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoAttackerPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="NucleusHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeAttackerWeapon == "Laser"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoAttackerPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="LaserHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeAttackerWeapon == "Arrow"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoAttackerPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="ArrowHit" halign="center" valign="center"/>
			""";
		}
		for(i,0,G_LibTutorialInterface_ModeAttackerAmmo-1){
			ManiaLink^="""
				<quad pos="{{{AmmoAttackerPosX}}} {{{AmmoAttackerPosY}}}" z-index="5" 
				size="{{{AmmoAttackerSizeX}}} {{{ArmorAttackerSizeY}}}" bgcolor="FFFA" 
				style="ProgressBarSmall" halign="left" valign="center" modulatecolor="F00"/>
			""";
		AmmoAttackerPosX+= AmmoAttackerSizeX;
		}
	declare Text Defense = _("Defense"); 
	declare ArmorDefenderPosX = 70.;
	declare ArmorDefenderPosY = -25.;
	declare ArmorDefenderSizeX = 50 / G_LibTutorialInterface_ModeDefenderArmor ;
	declare ArmorDefenderSizeY= 4.;
	declare AmmoDefenderPosX = 70.;
	declare AmmoDefenderPosY = -52.;
	declare AmmoDefenderSizeX = 50 / G_LibTutorialInterface_ModeDefenderAmmo ;
	declare AmmoDefenderSizeY= 4.;
	ManiaLink^="""
		<label pos="15 {{{ArmorDefenderPosY}}}" z-index="4" size="30 10" text="Armor :" halign="left" valign="center" 
		textsize="5" textfont="Oswald" textcolor="0000FFFF"/>
		<quad pos="50 {{{ArmorDefenderPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
		substyle="UnknownHit" halign="center" valign="center"/>
		<quad pos="94 {{{ArmorDefenderPosY}}}" z-index="4" size=" 62 12" bgcolor="FFFA" style="Bgs1" substyle="BgButtonGlow" 
		halign="center" valign="center"/>
		<quad pos="94 {{{ArmorDefenderPosY}}}" z-index="4.5" size="59 9" bgcolor="FFFA" style="EnergyBar" substyle="EnergyBar" 
		halign="center" valign="center"/>
		<label pos="0 -6.5" z-index="25" size="40 10" text="{{{Defense}}}" textsize="6" textfont="Oswald" valign="center2" 
		halign="Left" textprefix="$s"/>
	""";
		for(i,0,G_LibTutorialInterface_ModeDefenderArmor-1) {
			ManiaLink^="""
				<quad pos="{{{ArmorDefenderPosX}}} {{{ArmorDefenderPosY}}}" 
				size="{{{ArmorDefenderSizeX}}} {{{ArmorDefenderSizeY}}}" z-index="5" bgcolor="FFFA" style="ProgressBarSmall" 
				halign="left" valign="center" modulatecolor="00F"/>
			""";
			ArmorDefenderPosX+= ArmorDefenderSizeX;  
		}
	ManiaLink^="""
		<label pos="15 {{{AmmoDefenderPosY}}}" z-index="4" size="30 10" text="Weapon :" halign="left" valign="center" 
		textsize="5" textfont="Oswald" textcolor="0000FFFF"/>
		<quad pos="94 {{{AmmoDefenderPosY}}}" z-index="4" size=" 62 12" bgcolor="FFFA" style="Bgs1" substyle="BgButtonGlow"
		 halign="center" valign="center"/>
		<quad pos="94 {{{AmmoDefenderPosY}}}" z-index="4.5" size="59 9" bgcolor="FFFA" style="EnergyBar" 
		substyle="EnergyBar" halign="center" valign="center"/>
	""";
		if(G_LibTutorialInterface_ModeDefenderWeapon == "Rocket"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoDefenderPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="RocketHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeDefenderWeapon == "Nucleus"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoDefenderPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="NucleusHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeDefenderWeapon == "Lazer"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoDefenderPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="LaserHit" halign="center" valign="center"/>
			""";
		}
		if(G_LibTutorialInterface_ModeDefenderWeapon == "Arrow"){
			ManiaLink^="""
				<quad pos="50 {{{AmmoDefenderPosY}}}" z-index="4" size="20 20" bgcolor="FFFA" style="Icons64x64_2" 
				substyle="ArrowHit" halign="center" valign="center"/>
			""";
		}
		for(i,0,G_LibTutorialInterface_ModeDefenderAmmo-1){
			ManiaLink^="""
				<quad pos="{{{AmmoDefenderPosX}}} {{{AmmoDefenderPosY}}}"  size="{{{AmmoDefenderSizeX}}} {{{AmmoDefenderSizeY}}}"
				z-index="5" bgcolor="FFFA" style="ProgressBarSmall" halign="left" valign="center" modulatecolor="00F"/>
			""";
		AmmoDefenderPosX+= AmmoDefenderSizeX;
		}
	return ManiaLink;
}

/**
 *	Create the Manialink for the equipment
 */
Text Private_Create_Equipment_Content(){
		//L16N	The armor and weapons the player is going to use for this mode
	declare Text Equipment = _("|The weapons and stuff the players have|Equipment");
	declare Text ML="";
	if(G_LibTutorialInterface_ModePlayerWeapon != "" || G_LibTutorialInterface_ModeDefenderWeapon != ""){
		ML^="""
		<quad pos="-130 {{{51 - G_LibTutorialInterface_FrameCount * 11}}}" z-index="25" size="60 10" 
		style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<quad pos="-130 {{{51 - G_LibTutorialInterface_FrameCount * 11}}}" z-index="28" size="60 10" 
		id="Tab_Equipment" bgcolor="00000066" scriptevents="1" />
		<label pos="-120 {{{49 - G_LibTutorialInterface_FrameCount * 11}}}" z-index="30" size="60 10" 
		text="{{{Equipment}}}" textfont="Oswald" textsize="6" textcolor="FFFFFFFF" id="Label_Equipment" />
		<label pos="-126 {{{50 - G_LibTutorialInterface_FrameCount * 11}}}" z-index="30" size="60 10" 
		text=">" textfont="Oswald" textsize="6" textcolor="FF0000FF" id="Label_Equipment_Stripe"/>
		""";
	}else{
		ML^="""
		<label pos="2000 2000" z-index="30" size="60 10" 
		text="" textfont="Oswald" textsize="8" textcolor="FFFFFFFF" id="Label_Equipment" />
		<label pos="2000 2000" z-index="30" size="60 10" 
		text=">" textfont="Oswald" textsize="6" textcolor="FF0000FF" id="Label_Equipment_Stripe"/>
		<quad pos="2000 2000" z-index="28" size="60 10" id="Tab_Equipment" bgcolor="00000066" scriptevents="1" />
		""";
	}
	ML^="""
	<frame id="Frame_Equipment" hidden="1" pos="-69 -8" z-index="24">
	""";
	if(G_LibTutorialInterface_ModePlayerWeapon != "" || G_LibTutorialInterface_ModeDefenderWeapon != ""){
		if(G_LibTutorialInterface_ModePlayerWeapon != ""){
			ML^="""
			<!--Symmetric-->
			<quad pos="0 69" z-index="1" size="140 140" bgcolor="00000066"/>
			<quad pos="0 69" z-index="24" size="140 140" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			{{{Private_Create_Symmetric_Equipment_Content()}}}
			""";
		}else{
			ML^="""
			<!--Asymmetric-->
			<quad pos="0 59" z-index="1" size="140 59.5" bgcolor="00000066"/>
			<quad pos="0 59" z-index="24" size="140 59.5" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			<quad pos="0 -11" z-index="1" size="140 59.5" bgcolor="00000066"/>
			<quad pos="0 -11" z-index="24" size="140 59.5" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
			{{{Private_Create_Asymmetric_Equipment_Content()}}}
			""";
		}
	}
	ML^="""
	</frame>
	""";
	return ML;
}


/**
 * Create the Global Manialink 
 */

Text Private_CreateLayerBetterRules(Boolean _Hidden){
	declare ML = "";
	UISync::SyncUIs();
	G_LibTutorialInterface_GameflowTabs = ["Tab_Gf1","Tab_Gf2","Tab_Gf3","Tab_Gf4","Tab_Gf5","Tab_Gf6","Tab_Gf7","Tab_Gf8"];
	G_LibTutorialInterface_GameflowFrames = ["Frame_Gf1","Frame_Gf2","Frame_Gf3","Frame_Gf4","Frame_Gf5","Frame_Gf6","Frame_Gf7","Frame_Gf8"];
	G_LibTutorialInterface_GameflowMediaTracks = ["Button_MT1","Button_MT2","Button_MT3","Button_MT4","Button_MT5","Button_MT6","Button_MT7","Button_MT8"];
	G_LibTutorialInterface_GameflowLabels = ["Label_Gf1","Label_Gf2","Label_Gf3","Label_Gf4","Label_Gf5","Label_Gf6","Label_Gf7","Label_Gf8"];
	G_LibTutorialInterface_GameflowLabelsStripes = ["Label_Stripe1","Label_Stripe2","Label_Stripe3","Label_Stripe4","Label_Stripe5","Label_Stripe6","Label_Stripe7","Label_Stripe8"];
	
	declare TextCenterAlign = """ valign="center" halign="center" """;
	
	declare Real PosFrameX = 0.0;
	declare Real PosFrameY = 0.0;
		
	//L16N 	Press %1 to stop watching the mediatracker clip currently running
	declare Text ButtonStopMTText = _("Stop the MediaTracker");  
	//L16N 	Press %1 to hide or to show opponents'cars 
	declare Text ButtonShowOpponentsText = TextLib::Compose(_("Press %1 to Show/Hide Opponents'Cars"),"O"); 

	//L16N	Summary of the game mode : key points
	declare Text SummaryText = _("|A recap|Summary");
	//L16N	The principle of the game, the concept
	declare Text Principle = _("|The concept of the mode|Principles");
	//L16N The rules of the mode
	declare Text Title = _("Rules");
	
	if(G_LibTutorialInterface_GameflowSubsections.count == 0){
		G_LibTutorialInterface_GameflowSubsections = [""];
	}
	 
	if(G_LibTutorialInterface_FirstPage == ""){
		G_LibTutorialInterface_FirstPage = "Summary";
	}
	
	declare Text WCDumpText = "";
	if(G_LibTutorialInterface_WinConditions.count > 0) {
		WCDumpText = """Client_LibTutorialInterface_WinConditions = {{{dump(G_LibTutorialInterface_WinConditions)}}};""";
	}
	declare Text WCTextDumpText = "";
	if(G_LibTutorialInterface_WinConditionsText.count > 0) {
		WCTextDumpText ="""Client_LibTutorialInterface_WinConditionsText = {{{dump(G_LibTutorialInterface_WinConditionsText)}}};""";
	}
	declare Text WCTeamDumpText = "";
	if(G_LibTutorialInterface_WinConditionsTeam.count > 0) {
		WCTeamDumpText ="""Client_LibTutorialInterface_WinConditionsTeam = {{{dump(G_LibTutorialInterface_WinConditionsTeam)}}};""";
	}
	declare Text WCPDumpText = "";
	if(G_LibTutorialInterface_WinConditionsPicture.count > 0) {
		WCPDumpText = """	Client_LibTutorialInterface_WinConditionsPicture = {{{dump(G_LibTutorialInterface_WinConditionsPicture)}}};""";
	}
	declare Text GSDumpText = "";
	if(G_LibTutorialInterface_GameflowSubsections.count > 0){
		GSDumpText = """Client_LibTutorialInterface_GameflowSubsections = {{{dump(G_LibTutorialInterface_GameflowSubsections)}}};""";
	}
	
	ML ^= """
	<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
	<manialink version="3">
	<script><!--
	
	#Include "MathLib" as ML
	{{{Manialink::DefaultIncludes()}}}
	{{{Manialink::Animations(["EaseInOutExp","EaseInOutElastic"])}}}
	
	main(){
		
		declare Text[] Client_LibTutorialInterface_WinConditions;
		{{{WCDumpText}}}
		
		declare Text[Text] Client_LibTutorialInterface_WinConditionsText;
		{{{WCTextDumpText}}}
		
		declare Integer[Text] Client_LibTutorialInterface_WinConditionsTeam;
		{{{WCTeamDumpText}}}
		
		declare Text[Text] Client_LibTutorialInterface_WinConditionsPicture;
		{{{WCPDumpText}}}

		declare Text[] Client_LibTutorialInterface_GameflowSubsections;
		{{{GSDumpText}}}
 
		
		declare Text FillWinCondition;
		while (Client_LibTutorialInterface_WinConditions.count%4 != 0){
			FillWinCondition = "WCFill"^Client_LibTutorialInterface_WinConditions.count+1;
			Client_LibTutorialInterface_WinConditions.add(FillWinCondition);
			Client_LibTutorialInterface_WinConditionsText[FillWinCondition] = " ";
		}
		
		declare netwrite		Integer Net_LaunchMTSequenceNow 						for UI;
		declare netwrite		Integer Net_MTSequenceIndex 								for UI;
		declare netwrite		Integer Net_StopMTSequenceNow 							for UI;
		declare netread 		Boolean Net_HideButtonStop 								for UI;
		
		declare Integer PageIndex;
		PageIndex = 0;
		
		declare Vec3 Red = <1.0,0.1,0.1>;
		
		declare Vec3 Blue = <0.1,0.1,1.0>; 
		
		declare Vec3 Grey = <0.35,0.35,0.35>;
		
		declare Vec3 White = <1.0,1.0,1.0>;
		
		declare Vec3 Black = <0.0,0.0,0.0>;
		
		declare Boolean ShowRules    = {{{ !_Hidden }}};
		declare PrevShowRules 		= !ShowRules;
		declare ShowButtonStop		= False;
		declare MTHideRules = False;
		declare PrevMTHideRules = !MTHideRules;
		
		declare Quad_Background 				<=> (Page.GetFirstChild("Quad_Background") as CMlQuad);
				
		declare RulesReminderMainFrame <=> (Page.GetFirstChild("RulesReminderMainFrame") as CMlFrame);
		declare Frame_Show			  			<=> (Page.GetFirstChild("Frame_Show") as CMlFrame);
		declare Button_Show						<=> (Page.GetFirstChild("Button_Show") as CMlLabel);
		
		declare Frame_Stop 						<=> (Page.GetFirstChild("Frame_Stop") as CMlFrame);
		declare Button_Stop						<=> (Page.GetFirstChild("Button_Stop") as CMlQuad);
		declare Label_Stop							<=> (Page.GetFirstChild("Label_Stop") as CMlLabel);
		declare Label_Stop_Stripe 			<=> (Page.GetFirstChild("Label_Stop_Stripe") as CMlLabel);
		
		declare Frame_Summary          <=> (Page.GetFirstChild("Frame_Summary") as CMlFrame);
		declare Frame_Equipment        <=> (Page.GetFirstChild("Frame_Equipment") as CMlFrame);
	
		declare Tab_Summary            <=> (Page.GetFirstChild("Tab_Summary") as CMlQuad);
		declare Tab_Equipment          <=> (Page.GetFirstChild("Tab_Equipment") as CMlQuad);
		
		declare Label_Summary					<=> (Page.GetFirstChild("Label_Summary") as CMlLabel);
		declare Label_Equipment				<=> (Page.GetFirstChild("Label_Equipment") as CMlLabel);
		
		declare Label_Summary_Stripe		<=> (Page.GetFirstChild("Label_Summary_Stripe") as CMlLabel);
		declare Label_Equipment_Stripe <=> (Page.GetFirstChild("Label_Equipment_Stripe") as CMlLabel);
	
		declare Button_Close           <=> (Page.GetFirstChild("Button_Close") as CMlQuad);
		declare Label_Close						<=> (Page.GetFirstChild("Label_Close") as CMlLabel);
		
		declare Button_WinConditionsNext <=> (Page.GetFirstChild("Button_WinConditionsNext") as CMlQuad);
		declare Button_WinConditionsPrev	<=>	(Page.GetFirstChild("Button_WinConditionsPrev") as CMlQuad);
				
		declare Integer FrameNumber;
		FrameNumber = 8;
		declare CMlQuad[Integer] Array_Gameflow_Tab;
		declare CMlFrame[Integer] Array_Gameflow_Frame;
		declare CMlLabel[Integer] Array_Gameflow_Label;
		declare CMlLabel[Integer] Array_Gameflow_LabelStripe;
		declare CMlLabel[Integer] Array_Gameflow_Button_MediaTrack;
		
		for(CurrentFrame,1,FrameNumber){
			Array_Gameflow_Tab[CurrentFrame]									<=>	(Page.GetFirstChild("Tab_Gf"^CurrentFrame) as CMlQuad);
			Array_Gameflow_Frame[CurrentFrame]								<=>	(Page.GetFirstChild("Frame_Gf"^CurrentFrame) as CMlFrame);
			Array_Gameflow_Label[CurrentFrame]								<=> (Page.GetFirstChild("Label_Gf"^CurrentFrame) as CMlLabel);
			Array_Gameflow_LabelStripe[CurrentFrame]					<=> (Page.GetFirstChild("Label_Stripe"^CurrentFrame) as CMlLabel);
			Array_Gameflow_Button_MediaTrack[CurrentFrame]		<=>	(Page.GetFirstChild("Button_MT"^CurrentFrame) as CMlLabel);
		}
		
		declare Integer WinConditionPerPage;
		WinConditionPerPage =4;
		declare CMlLabel[Integer] Array_WinCondition_Label;
		declare CMlQuad[Integer] Array_WinCondition_Picture;
		declare CMlLabel[Integer] Array_WinCondition_Stripe;
		
		for(WinConditionIndex,0,WinConditionPerPage-1){
			Array_WinCondition_Label[WinConditionIndex]		<=>  (Page.GetFirstChild("Label_WinCondition"^WinConditionIndex) 
			as CMlLabel);
			Array_WinCondition_Picture[WinConditionIndex]	<=>  (Page.GetFirstChild("Picture_WinCondition"^WinConditionIndex) 
			as CMlQuad);
			Array_WinCondition_Stripe[WinConditionIndex] 	<=>	 (Page.GetFirstChild("Stripe_WinCondition"^WinConditionIndex)
			as CMlLabel ); 
		}
		
		Label_Summary.TextColor = Grey;
		Label_Summary_Stripe.TextColor = Grey; 
		Label_Equipment.TextColor = Grey;
		Label_Equipment_Stripe.TextColor = Grey;
		for(CurrentFrame,0,Client_LibTutorialInterface_GameflowSubsections.count-1){
			Array_Gameflow_Label[CurrentFrame+1].TextColor = Grey;
			Array_Gameflow_LabelStripe[CurrentFrame+1].TextColor = Grey;
		}
		
		if("{{{G_LibTutorialInterface_FirstPage}}}" == "Summary"){
				Frame_Summary.Show();
				Label_Summary.TextColor = White;
				Label_Summary_Stripe.TextColor = Red;
		}else if ("{{{G_LibTutorialInterface_FirstPage}}}" == "Equipment"){
				Frame_Equipment.Show();
				Label_Equipment.TextColor = White;
				Label_Equipment_Stripe.TextColor = Red;
		}else{
			for(CurrentFrame,0,Client_LibTutorialInterface_GameflowSubsections.count-1){
				if("{{{G_LibTutorialInterface_FirstPage}}}" == Client_LibTutorialInterface_GameflowSubsections[CurrentFrame]){
					Array_Gameflow_Frame[CurrentFrame+1].Show();
					Array_Gameflow_Label[CurrentFrame+1].TextColor = White;
					Array_Gameflow_LabelStripe[CurrentFrame+1].TextColor = Red;
				}
			}
		}
		
		{{{MMLobby::InjectMLRulesVisibilityVariable("RulesAreVisible")}}}
		declare Boolean PrevRulesAreVisible = !RulesAreVisible;
		declare Boolean Quiz_RulesAreVisible for UI;
		Quiz_RulesAreVisible = False;
		declare Boolean PrevQuiz_RulesAreVisible = ! Quiz_RulesAreVisible;
		declare Boolean PlayableAnim = True;
		
		while(True){
			yield;
			LibManialink_AnimLoop();
			{{{UISync::ML_SyncUI()}}}				
			
			if (PrevRulesAreVisible != RulesAreVisible || PrevMTHideRules != MTHideRules || 
			PrevQuiz_RulesAreVisible != Quiz_RulesAreVisible) {
				PrevRulesAreVisible = RulesAreVisible;
				PrevMTHideRules = MTHideRules;
				PrevQuiz_RulesAreVisible = Quiz_RulesAreVisible;
			}
				
			if ((RulesAreVisible || Quiz_RulesAreVisible) && !MTHideRules) {
				RulesReminderMainFrame.Visible = True;
				if(PlayableAnim){
					RulesReminderMainFrame.RelativePosition_V3 = <400.0,0.0>;
					Quad_Background.Opacity = 0.0;
					LibManialink_Anim({{{Manialink::Inject("""<frame pos="25 0" 
					id="RulesReminderMainFrame" />""")}}},1000, "EaseInOutExp");
					LibManialink_Anim({{{Manialink::Inject("""<frame opacity="0.1" 
					id="Quad_Background" />""")}}},1000, "EaseInOutExp");
					PlayableAnim = False;
				}
			} else {
				RulesReminderMainFrame.Visible = False;
			}
				
			if(ShowButtonStop){
				Frame_Stop.Show();
			}else{
				Frame_Stop.Hide();
			}
			
			if(Net_HideButtonStop){
				Frame_Stop.Hide();
			}
			
			foreach (Event in PendingEvents){
				
				switch(Event.Type){
					case CMlEvent::Type::MouseClick: {
						if(Event.ControlId == "Tab_Summary"){
							if(Frame_Summary.Visible == False){
								Frame_Summary.Show();
								Frame_Summary.RelativePosition_V3 = <200.0,62.0>; 
								LibManialink_Anim({{{Manialink::Inject("""<frame pos="-69 62" 
								id="Frame_Summary" />""")}}},300, "EaseInOutExp");
							}
							Label_Summary.TextColor = White;
							Label_Summary_Stripe.TextColor = Red;
							Tab_Summary.BgColor = Black;
							Tab_Summary.Opacity = 0.4;
							Frame_Equipment.Hide();
							Label_Equipment.TextColor = Grey;
							Label_Equipment_Stripe.TextColor = Grey;
							Tab_Equipment.BgColor = Black;
							Tab_Equipment.Opacity = 0.4;
							for(FrameIndex,1,8){
								Array_Gameflow_Frame[FrameIndex].Hide();
								Array_Gameflow_Label[FrameIndex].TextColor = Grey;
								Array_Gameflow_LabelStripe[FrameIndex].TextColor = Grey;
								Array_Gameflow_Tab[FrameIndex].BgColor = Black;
								Array_Gameflow_Tab[FrameIndex].Opacity = 0.4;
							}
						}
						if(Event.ControlId == "Tab_Equipment"){
							Frame_Summary.Hide();
							Label_Summary.TextColor = Grey;
							Label_Summary_Stripe.TextColor = Grey;
							Tab_Summary.BgColor = Black;
							Tab_Summary.Opacity = 0.4;
							if(Frame_Equipment.Visible == False){
								Frame_Equipment.Show();
								Frame_Equipment.RelativePosition_V3 = <200.0,-8.0>; 
								LibManialink_Anim({{{Manialink::Inject("""<frame pos="-69 -8" 
								id="Frame_Equipment" />""")}}},300, "EaseInOutExp");
							}
							Label_Equipment.TextColor = White;
							Label_Equipment_Stripe.TextColor = Red;
							Tab_Equipment.BgColor = Black;
							Tab_Equipment.Opacity = 0.4;
							for(FrameIndex,1,8){
								Array_Gameflow_Frame[FrameIndex].Hide();
								Array_Gameflow_Label[FrameIndex].TextColor = Grey;
								Array_Gameflow_LabelStripe[FrameIndex].TextColor = Grey;
								Array_Gameflow_Tab[FrameIndex].BgColor = Black;
								Array_Gameflow_Tab[FrameIndex].Opacity = 0.4;
							}
						}
						for(EventIndex,1,8){
							if(Event.ControlId == "Tab_Gf"^EventIndex){
								Frame_Summary.Hide();
								Label_Summary.TextColor = Grey;
								Label_Summary_Stripe.TextColor = Grey;
								Tab_Summary.BgColor = Black;
								Tab_Summary.Opacity = 0.4;
								Frame_Equipment.Hide();
								Label_Equipment.TextColor = Grey;
								Label_Equipment_Stripe.TextColor = Grey;
								Tab_Equipment.BgColor = Black;
								Tab_Equipment.Opacity = 0.4;
								if(Array_Gameflow_Frame[EventIndex].Visible == False){
									Array_Gameflow_Frame[EventIndex].Show();
									Array_Gameflow_Frame[EventIndex].RelativePosition_V3 = <200.0,-9.0>; 
									LibManialink_Anim(Array_Gameflow_Frame[EventIndex],
									{{{Manialink::Inject("""<frame pos="-69.0,-9.0"/>""")}}},300,"EaseInOutExp");
								}
								Array_Gameflow_Label[EventIndex].TextColor = White;
								Array_Gameflow_LabelStripe[EventIndex].TextColor = Red;
								Array_Gameflow_Tab[EventIndex].BgColor = Black;
								Array_Gameflow_Tab[EventIndex].Opacity = 0.4;
								for(FrameIndex,1,8){
									if(FrameIndex != EventIndex){
										Array_Gameflow_Frame[FrameIndex].Hide();
										Array_Gameflow_Label[FrameIndex].TextColor = Grey;
										Array_Gameflow_LabelStripe[FrameIndex].TextColor = Grey;
										Array_Gameflow_Tab[FrameIndex].BgColor = Black;
										Array_Gameflow_Tab[FrameIndex].Opacity = 0.4;
									}
								}
								
							}
						}
						
						for(ButtonId,1,8){
							if(Event.ControlId == "Button_MT" ^ ButtonId){
								Net_LaunchMTSequenceNow += 1 ;
								Net_MTSequenceIndex = ButtonId - 1;
								ShowButtonStop = True;
								MTHideRules = True;
							} 
						}
						if(Event.ControlId == "Button_Stop"){
							Net_StopMTSequenceNow +=1;
							ShowButtonStop = False;
							MTHideRules = False;
						}
						if(Event.ControlId == "Button_Close"){
							declare Boolean FromQuiz for UI;
							declare Boolean ShowQuiz for UI;
							PlayableAnim = True;
							if(FromQuiz){
								ShowQuiz = True;
								FromQuiz = False;
								Quiz_RulesAreVisible = !Quiz_RulesAreVisible;
							}else{
								RulesAreVisible = !RulesAreVisible;
							}
						}
						
						if(Event.ControlId == "Button_WinConditionsNext"){
							PageIndex = PageIndex + 4;
							if(PageIndex == Client_LibTutorialInterface_WinConditions.count){
								PageIndex = 0;
							}
							for(WinConditionCurrentPageIndex,0,WinConditionPerPage-1){
							 	declare Integer Index = WinConditionCurrentPageIndex + PageIndex;
								declare Text WinConditionIndex = Client_LibTutorialInterface_WinConditions[Index];
								if(Client_LibTutorialInterface_WinConditionsTeam.existskey(WinConditionIndex)){	
									if(Client_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 1){
										Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = Red; 
									}
									if(Client_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 0){
										Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = Blue; 
									}
								}else{
									Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = White; 
								}
								declare Text _Text = Client_LibTutorialInterface_WinConditionsText[WinConditionIndex];	
								Array_WinCondition_Label[WinConditionCurrentPageIndex].SetText(_Text);
								Array_WinCondition_Label[WinConditionCurrentPageIndex].Opacity = 0.0;
								LibManialink_Anim(Array_WinCondition_Label[WinConditionCurrentPageIndex],
								{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
								if(Client_LibTutorialInterface_WinConditionsPicture.existskey(WinConditionIndex)){
									declare Text _Picture = Client_LibTutorialInterface_WinConditionsPicture[WinConditionIndex];
									Array_WinCondition_Picture[WinConditionCurrentPageIndex].ChangeImageUrl(_Picture);
									Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Visible = False;
								}else{
									Array_WinCondition_Picture[WinConditionCurrentPageIndex].ChangeImageUrl("");
									Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Visible = True;	
								}
								if(Client_LibTutorialInterface_WinConditionsText[WinConditionIndex] != " "){
									if(Array_WinCondition_Picture[WinConditionCurrentPageIndex].Opacity == 0.0){
										LibManialink_Anim(Array_WinCondition_Picture[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
									}
									if(Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Opacity == 0.0){
										LibManialink_Anim(Array_WinCondition_Stripe[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
									}
								}else{
									if(Array_WinCondition_Picture[WinConditionCurrentPageIndex].Opacity == 1.0){
										LibManialink_Anim(Array_WinCondition_Picture[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="0.0"/>""")}}},300,"EaseInOutExp");
									}
									if(Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Opacity == 1.0){
										LibManialink_Anim(Array_WinCondition_Stripe[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="0.0"/>""")}}},300,"EaseInOutExp");
									}
								}
							}
						}
						if(Event.ControlId == "Button_WinConditionsPrev"){
							PageIndex = PageIndex - 4;
							if(PageIndex < 0){
								PageIndex = Client_LibTutorialInterface_WinConditions.count + PageIndex;
							}
							for(WinConditionCurrentPageIndex,0,WinConditionPerPage-1){
								declare Integer Index = WinConditionCurrentPageIndex + PageIndex;
								declare Text WinConditionIndex = Client_LibTutorialInterface_WinConditions[Index];
								if(Client_LibTutorialInterface_WinConditionsTeam.existskey(WinConditionIndex)){	
									if(Client_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 1){ 
										Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = Red;  
									}
									if(Client_LibTutorialInterface_WinConditionsTeam[WinConditionIndex] == 0){
										Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = Blue; 
									}
								}else{
									Array_WinCondition_Label[WinConditionCurrentPageIndex].TextColor = White; 
								}
								
								declare Text _Text = Client_LibTutorialInterface_WinConditionsText[WinConditionIndex];
								Array_WinCondition_Label[WinConditionCurrentPageIndex].SetText(_Text);
								Array_WinCondition_Label[WinConditionCurrentPageIndex].Opacity = 0.0;
								LibManialink_Anim(Array_WinCondition_Label[WinConditionCurrentPageIndex],
								{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
								if(Client_LibTutorialInterface_WinConditionsPicture.existskey(WinConditionIndex)){
									declare Text _Picture = Client_LibTutorialInterface_WinConditionsPicture[WinConditionIndex];
									Array_WinCondition_Picture[WinConditionCurrentPageIndex].ChangeImageUrl(_Picture);
									Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Visible = False;
								}else{
									Array_WinCondition_Picture[WinConditionCurrentPageIndex].ChangeImageUrl("");
									Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Visible = True;
								}
								if(Client_LibTutorialInterface_WinConditionsText[WinConditionIndex] != " "){
									if(Array_WinCondition_Picture[WinConditionCurrentPageIndex].Opacity == 0.0){
										LibManialink_Anim(Array_WinCondition_Picture[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
									}
									if(Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Opacity == 0.0){
										LibManialink_Anim(Array_WinCondition_Stripe[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="1.0"/>""")}}},300,"EaseInOutExp");
									}
								}else{
									if(Array_WinCondition_Picture[WinConditionCurrentPageIndex].Opacity == 1.0){
										LibManialink_Anim(Array_WinCondition_Picture[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="0.0"/>""")}}},300,"EaseInOutExp");
									}
									if(Array_WinCondition_Stripe[WinConditionCurrentPageIndex].Opacity == 1.0){
										LibManialink_Anim(Array_WinCondition_Stripe[WinConditionCurrentPageIndex],
										{{{Manialink::Inject("""<frame opacity="0.0"/>""")}}},300,"EaseInOutExp");
									}
								}
							}
						}			
					}
					case CMlEvent::Type::MouseOver:{
						if(Event.ControlId == "Tab_Summary" && Frame_Summary.Visible == False){
							Tab_Summary.BgColor = White;
							Tab_Summary.Opacity = 0.4;
							Label_Summary.TextColor = Black;	
							Label_Summary_Stripe.TextColor = Black;
						}
						if(Event.ControlId == "Tab_Equipment" && Frame_Equipment.Visible == False){
							Tab_Equipment.BgColor = White;
							Tab_Equipment.Opacity = 0.4;
							Label_Equipment.TextColor = Black;
							Label_Equipment_Stripe.TextColor = Black;
						}
						for(EventIndex,1,8){
							if(Event.ControlId == "Tab_Gf"^EventIndex && Array_Gameflow_Frame[EventIndex].Visible == False){
								Array_Gameflow_Tab[EventIndex].BgColor = White;
								Array_Gameflow_Tab[EventIndex].Opacity = 0.4;
								Array_Gameflow_Label[EventIndex].TextColor = Black;
								Array_Gameflow_LabelStripe[EventIndex].TextColor = Black;
							}
						}
						if(Event.ControlId == "Button_Stop"){
							Button_Stop.BgColor = White;
							Button_Stop.Opacity = 0.4;
							Label_Stop.TextColor = Black;
							Label_Stop_Stripe.TextColor = Black;	
						}
						if(Event.ControlId == "Button_Close"){
							Button_Close.BgColor = White;
							Button_Close.Opacity = 0.4;
							Label_Close.TextColor = Black;
						}
						if(Event.ControlId == "Button_WinConditionsNext"){
							Button_WinConditionsNext.BgColor = White;
							Button_WinConditionsNext.Opacity = 0.4;
						}
						if(Event.ControlId == "Button_WinConditionsPrev"){
							Button_WinConditionsPrev.BgColor = White;
							Button_WinConditionsPrev.Opacity = 0.4;
						}
					}
					case CMlEvent::Type::MouseOut:{
						if(Event.ControlId == "Tab_Summary" && Frame_Summary.Visible == False){
							Tab_Summary.BgColor = Black;
							Tab_Summary.Opacity = 0.4;
							Label_Summary.TextColor = Grey;	
							Label_Summary_Stripe.TextColor = Grey;
						}
						if(Event.ControlId == "Tab_Equipment" && Frame_Equipment.Visible == False){
							Tab_Equipment.BgColor = Black;
							Tab_Equipment.Opacity = 0.4;
							Label_Equipment.TextColor = Grey;
							Label_Equipment_Stripe.TextColor = Grey;
						}
						for(EventIndex,1,8){
							if(Event.ControlId == "Tab_Gf"^EventIndex && Array_Gameflow_Frame[EventIndex].Visible == False){
								Array_Gameflow_Tab[EventIndex].BgColor = Black;
								Array_Gameflow_Tab[EventIndex].Opacity = 0.4;
								Array_Gameflow_Label[EventIndex].TextColor = Grey;
								Array_Gameflow_LabelStripe[EventIndex].TextColor = Grey;
							}
						}
						if(Event.ControlId == "Button_Stop"){
							Button_Stop.BgColor = Black;
							Button_Stop.Opacity = 0.4;
							Label_Stop.TextColor = White;
							Label_Stop_Stripe.TextColor = Red;	
						}
						if(Event.ControlId == "Button_Close"){
							Button_Close.BgColor = Black;
							Button_Close.Opacity = 0.4;
							Label_Close.TextColor = White;
						}
						if(Event.ControlId == "Button_WinConditionsNext"){
							Button_WinConditionsNext.Opacity = 1.0;
						}
						if(Event.ControlId == "Button_WinConditionsPrev"){
							Button_WinConditionsPrev.Opacity = 1.0;
						}
					}
				}	
			}
		}
	}
	--></script>
	
	<frame id="Frame_Stop" hidden="1" pos = "-48 -77" z-index="20000">
	
		<label pos="9.3 6" z-index="30" size="109 6" text="{{{ButtonShowOpponentsText}}}" textsize="5" textfont="Oswald" />
		<quad pos="1 -1.5" z-index="28" size="92 7" id="Button_Stop" bgcolor="00000066" scriptevents="1"/>
		<label pos="3.3 -1" z-index="30" size="60 10" text=">" textfont="Oswald" textsize="6" 
		textcolor="FF0000FF" id="Label_Stop_Stripe"/>
		<label pos="9.3 -2" z-index="30" size="92 6" text="{{{ButtonStopMTText}}}" textsize="5" 
		textfont="Oswald" id="Label_Stop" />
	</frame>
	
	<frame id="RulesReminderMainFrame" hidden="1" pos = "25 0" z-index="20000000000">
		<quad pos="-185 100" z-index="0" size="360 200" bgcolor="00000044" id="Quad_Background"/>
		<quad pos="-185 100" z-index="0" size="360 200" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<quad pos="-69 83" z-index="30" size="1.5 18" bgcolor="FFFA" style="Bgs1" substyle="BgWindow4"/>
		<quad pos="-69 64" z-index="30" size="140 0.8" bgcolor="FFFA" style="Bgs1" substyle="BgWindow4"/>
		<quad pos="51 64.7" z-index="30" size="20 1.3" bgcolor="FFFA" style="Bgs1" substyle="BgWindow4"/>
		<label pos="-67 83.2" z-index="30" size="195 14" text="{{{Title}}}" textsize="10" 
		textfont="Oswald" textcolor="FFFFFFFF" textprefix="$s"/>
		<label pos="-67 73.2" z-index="30" size="195 14" text="{{{G_LibTutorialInterface_ModeName}}}" textsize="7" 
		textfont="Oswald" textcolor="FFFFFFFF" textprefix="$s"/>
		<quad pos="65 72" z-index="28" size="6 6" id="Button_Close" bgcolor="00000066" scriptevents="1"/>
		<label pos="65.5 72" z-index="30" size="9 9" bgcolor="FFFA" textsize="6" text="X" id="Label_Close"/>
		<quad pos="-130 62" z-index="24" size="60 10" style="Bgs1" substyle="BgDialogBlur" opacity="0.1"/>
		<quad pos="-130 62" z-index="28" size="60 10" id="Tab_Summary" bgcolor="00000066" scriptevents="1"/>
		<label pos="-126 61" z-index="30" size="60 10" text=">" textfont="Oswald" textsize="6" 
		textcolor="FF0000FF" id="Label_Summary_Stripe"/>
		<label pos="-120 60" z-index="30" size="60 10" text="{{{SummaryText}}}" textfont="Oswald" textsize="6" 
		textcolor="FFFFFFFF" id="Label_Summary"/>
		<frame id="Frame_Summary" hidden="1" pos="-69 62" z-index="4">
			<label pos="0 -6" z-index="25" size="40 10" text="{{{Principle}}}" textsize="7" textfont="Oswald" valign="center2" 
			halign="Left" textprefix="$s"/>
			{{{Private_Create_ModeMethod_Content()}}}
			{{{Private_Create_WinCondition_Content()}}}
		</frame>
		{{{Private_Create_GameflowSubsection_Content()}}}
		{{{Private_Create_Equipment_Content()}}}
	</frame>	
	
</manialink>
	""";
	return ML;
}

/**
 * Loop to enable the mediaTracks' displaying
 */

Void Loop() {
	
	foreach(Player in Players){
		declare UI <=> UIManager.GetUI(Player);
		if(UI != Null && UISync::IsUISync(Player)) {
			
			// Launch new MT Clip
			declare 					Integer Prev_LaunchMTSequenceNow 	for UI = 0;
			declare netread		Integer Net_LaunchMTSequenceNow 		for UI;
			declare netread		Integer Net_MTSequenceIndex 				for UI;
			declare netwrite 	Boolean	Net_HideButtonStop 				for UI = False;
			
			if(Prev_LaunchMTSequenceNow != Net_LaunchMTSequenceNow) {
				Prev_LaunchMTSequenceNow = Net_LaunchMTSequenceNow;
				Net_HideButtonStop = False; 
				declare Text GameflowSubsection = G_LibTutorialInterface_GameflowSubsections[Net_MTSequenceIndex];
				if(! G_LibTutorialInterface_GameflowSubsectionsMediaTrack.existskey(GameflowSubsection))
					continue;
	
				declare Text GameflowMTClip = G_LibTutorialInterface_GameflowSubsectionsMediaTrack[GameflowSubsection];
				UI.UISequence_CustomMTClip = "";
				UI.UISequence = CUIConfig::EUISequence::UIInteraction;
				UI.UISequence_CustomMTClip = GameflowMTClip;
				UI.UISequence = CUIConfig::EUISequence::CustomMTClip_WithUIInteraction;
				log(Now^"> Launch Custom MTClip");
			}
			
			
			// Stop MT Clip if needed
			if(UI.UISequence == CUIConfig::EUISequence::CustomMTClip_WithUIInteraction)
			{
				declare 					Integer Prev_StopMTSequenceNow for UI = 0;
				declare netread		Integer Net_StopMTSequenceNow 	for UI;
				
				if(UI.UISequenceIsCompleted || Prev_StopMTSequenceNow != Net_StopMTSequenceNow){
					Prev_StopMTSequenceNow = Net_StopMTSequenceNow;
					Net_HideButtonStop = True;
					UI.UISequence = CUIConfig::EUISequence::Playing;
					UI.UISequence_CustomMTClip = "";
					UI.UISequence = CUIConfig::EUISequence::CustomMTClip_WithUIInteraction;
					log(Now^"> Stop Custom MTClip");
				}
			}
		}
	}
}

// ---------------------------------- //
/// Destroy the rules
Void DestroyRules() {
	if (G_LibTutorialInterface_LayerRulesId != NullId && UIManager.UILayers.existskey(G_LibTutorialInterface_LayerRulesId)) {
		UIManager.UILayerDestroy(UIManager.UILayers[G_LibTutorialInterface_LayerRulesId]);
		G_LibTutorialInterface_LayerRulesId = NullId;
	}
	
	MMLobby::UseCustomRulesML(False);
}

// ---------------------------------- //
/** Create the rules 
 *
 *	@param	_Name			The name of the mode
 *	@param	_StartHidden	Start with the rules hidden
 *  @param _Type      Is the game mode "Team Versus Team"/"Attack Versus Defence"/"Free For All"
 *  @param _Principle Explain the principle of the game, what is the main concept, what the players do
 */
Void CreateRules(Text _Name, Text _Type, Text _Principle, Boolean _StartHidden) {
	// Check if a rules layer was already created and destroy it if it's the case
	DestroyRules();
	
	// Set the name and the settings of the mode
	if(_Name != "") {
			G_LibTutorialInterface_ModeName = TextLib::MLEncode(_Name);	
	}
	if(_Type != "") {
		G_LibTutorialInterface_ModeType = TextLib::MLEncode(_Type);
	}
	if(_Principle !=""){
		G_LibTutorialInterface_ModeMethod = TextLib::MLEncode(_Principle);
	}
	
	// Create and assign the layer
	declare LayerRules <=> UIManager.UILayerCreate();
	LayerRules.Type = CUILayer::EUILayerType::Normal;
	LayerRules.ManialinkPage = Private_CreateLayerBetterRules(_StartHidden);
	G_LibTutorialInterface_LayerRulesId = LayerRules.Id;
	UIManager.UIAll.UILayers.add(LayerRules);
	
	MMLobby::UseCustomRulesML(True);
}

Void CreateRules(Text _Name, Boolean _StartHidden) {
	CreateRules(_Name,"","",_StartHidden);
}

Void CreateRules(){
	CreateRules("","","",True);
}

// ---------------------------------- //
/// Attach the rules layer to all players
Void AttachRules() {
	if (UIManager.UIAll.UILayers.existskey(G_LibTutorialInterface_LayerRulesId)) return;
	if (!UIManager.UILayers.existskey(G_LibTutorialInterface_LayerRulesId)) return;
	
	UIManager.UIAll.UILayers.add(UIManager.UILayers[G_LibTutorialInterface_LayerRulesId]);
}

// ---------------------------------- //
/// Detach the rules layer from all players
Void DetachRules() {
	if (!UIManager.UIAll.UILayers.existskey(G_LibTutorialInterface_LayerRulesId)) return;
	if (!UIManager.UILayers.existskey(G_LibTutorialInterface_LayerRulesId)) return;
	
	declare Detached = UIManager.UIAll.UILayers.removekey(G_LibTutorialInterface_LayerRulesId);
}






