Skip to content

Commit

Permalink
Display a button to join the channels from the online server browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aessi committed May 23, 2019
1 parent effcd55 commit 6a2924c
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Makers/base/Media/Apps/MainMenuLagoon.Script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#Const C_FirstPage "SectionsSelector"

main() {
log("["^Now^"] Main Lagoon");
log("New version for test");
MenuController::LoadAll();
Pages::GotoNext(C_FirstPage);
while(True) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ main() {
// User input
foreach (Event in PendingEvents) {

//log("Event.Type: "^ Event.Type);
if (Event.Type == CEditorPluginEvent::Type::EditorInput) {
switch (Event.Input) {
case CEditorPluginEvent::EInput::CursorDelete : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ Text Inject_While()
HideServerInfo();
}
case "Back" : {
log("JE SUIS TOUCHE");
if(G_IsServerInfo)
{
SendCustomEvent("GotoPrevious", [""]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Struct K_ChannelInfo {
Text channel_name;
Integer channel_online_players;
Text channel_join_manialink;
}

#Struct K_ChannelTimeSlot {
Integer time_slot_start_timestamp;
Integer time_slot_end_timestamp;
Integer time_slot_duration;
Text program_name;
Text program_card_image_url;
}

#Struct K_ChannelInfoResult {
K_ChannelInfo[Text] channels;
K_ChannelTimeSlot[][][Text] time_slots;
}

#Const K_ChannelInfo_ML """
#Struct K_ChannelInfo {
Text channel_name;
Integer channel_online_players;
Text channel_join_manialink;
}

#Struct K_ChannelTimeSlot {
Integer time_slot_start_timestamp;
Integer time_slot_end_timestamp;
Integer time_slot_duration;
Text program_name;
Text program_card_image_url;
}

#Struct K_ChannelInfoResult {
K_ChannelInfo[Text] channels;
K_ChannelTimeSlot[][][Text] time_slots;
}
"""
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#Include "Libs/Nadeo/Common/ManialinkTools/Manialink3WPrevAnims.Script.txt" as Manialink
#Include "Libs/Nadeo/MP4/Common/Components/ListDisplayer/LBListDisplayer.Script.txt" as ListDisplayer
#Include "Libs/Nadeo/MP4/Common/ManialinkTools/FontManager.Script.txt" as Font
#Include "Libs/Nadeo/MP4/TPLagoon/Components/Multiplayer/ChannelInfoStructs.Script.txt" as ChannelInfoStructs

#Const C_ImgBase "file://Media/MEDIABROWSER_HiddenResources/Common/Images/Menus/"
#Const C_LPMinToJoin 60000
Expand Down Expand Up @@ -29,14 +30,43 @@ Text Build() {

declare Text[] Levels_Instructions = [_("|Server|Very easy"), _("|Server|Easy"), _("|Server|At your level"), _("|Server|Difficult"), _("|Server|Very Difficult"), LPToJoin, _("|Server|Private")];

declare Text Main = Font::GetFontName("Main");
declare Text Chrono = Font::GetFontName("Chrono");
declare Text SubFont = Font::GetFontName("SubTitle");

declare Real QuadSizeX = 53.;
declare Real ChannelPos = 112.;

declare Text MLText = """
<manialink version="3" name="L_Multiplayer_Find">
{{{ListDisplayer::ManialinkFrameModels()}}}

<frame id="Frame_All">
<frame id="frame-channel" pos="{{{ChannelPos}}} -12" hidden="1">
<quad id="quad-image" halign="center" valign="center" size="{{{QuadSizeX}}} 30" scriptevents="1" z-index="-1"/>
<quad halign="center" valign="center" size="{{{QuadSizeX}}} 39.5" bgcolor="000" z-index="-1"/>
<frame id="frame-headline" pos="0 17.5">
<label halign="left" valign="center" size="{{{QuadSizeX}}} 5" pos="-25 0" textsize="2" textprefix="$t" text="{{{_("Channels")}}}" textfont="{{{Main}}}"/>
<label id="label-players" halign="right" valign="center" size="{{{QuadSizeX}}} 5" pos="25 0" textsize="1" text="0 " textfont="{{{Main}}}"/>
</frame>
<frame id="frame-timer" pos="0 -17.5">
<label id="label-starttime" halign="left" valign="center2" size="{{{QuadSizeX}}} 5" pos="-25 0" textsize="0.8" textfont="{{{Chrono}}}"/>
<label id="label-timeleft" halign="right" valign="center2" size="{{{QuadSizeX}}} 5" pos="25 0" textsize="0.8" textfont="{{{Chrono}}}" textcolor="F00"/>
</frame>
<frame id="frame-progress" pos="0 -15.25">
<quad id="quad-progress" halign="left" valign="center" size="0 0.5" pos="-26.5 0" bgcolor="F00" z-index="-1"/>
</frame>
<frame id="frame-play" hidden="1">
<quad halign="center" valign="center" size="{{{QuadSizeX}}} 30" bgcolor="000" opacity="0.5" z-index="-1"/>
<label halign="center" valign="center" size="{{{QuadSizeX}}} 5" pos="0 3" textsize="7" text=""/>
<label halign="center" valign="center" size="{{{QuadSizeX}}} 5" pos="0 -6" textsize="4" textprefix="$t" text="{{{_("Play for free")}}}" textfont="{{{Main}}}"/>
</frame>
<frame id="frame-play-button" pos="0 -25">
<quad id="button-play" halign="center" valign="center" size="{{{QuadSizeX}}} 10" bgcolor="111" bgcolorfocus="444" opacity="0.6" scriptevents="1" z-index="-1"/>
<label halign="center" valign="center" size="{{{QuadSizeX}}} 10" pos="0 0" textsize="4" textprefix="$t" text="{{{_("Play for free")}}}" textfont="{{{Main}}}"/>
</frame>
</frame>

<frame id="Frame_CursorHelper" z-index="5" hidden="1">
<quad halign="center" valign="center" size="50 15" pos="0 10" z-index="-1" bgcolor="666"/>
<label id="Label_CursorHelper" halign="center" valign="center" size="40 5" pos="0 10" textfont="{{{SubFont}}}" autonewline="1"/>
Expand All @@ -46,11 +76,19 @@ Text Build() {

<script><!--
#Include "TextLib" as Multiplayer_Find_TextLib
#Include "MathLib" as Multiplayer_Find_MathLib
#Include "TimeLib" as Multiplayer_Find_TimeLib
{{{ListDisplayer::Includes()}}}
#Const C_IMG_Levels {{{dump(IMG_Levels)}}}
#Const C_Levels_Instructions {{{dump(Levels_Instructions)}}}
{{{ChannelInfoStructs::K_ChannelInfo_ML}}}
// Timer to resend http request
#Const C_TimerRequest 120000

declare Boolean G_IsCursorHelperShown;

declare Text G_ChannelTimeStampEnd;
declare Integer G_ChannelTimeDuration;

Text ListDisplayer_ConvertToImageUrl(Integer _QuadId) {
return "";
Expand Down Expand Up @@ -85,6 +123,8 @@ Text Build() {
Void Init()
{
G_IsCursorHelperShown = False;
G_ChannelTimeStampEnd = "";
G_ChannelTimeDuration = 0;
}

Void ShowCursorHelper(Text _CursorHelperText)
Expand All @@ -111,8 +151,39 @@ Text Build() {
declare Frame_CursorHelper <=> Page.GetFirstChild("Frame_CursorHelper");
Frame_CursorHelper.RelativePosition_V3 = <MouseX, MouseY>;
}

Void UpdateChannelInfo(Integer TimeSlotNumber, Boolean Animate) {
declare CMlFrame Frame_Channel <=> (Page.GetFirstChild("frame-channel") as CMlFrame);
Frame_Channel.Show();
if (Animate) {
Frame_Channel.RelativePosition_V3.X = 250.;
AnimMgr.Add(Frame_Channel, "<frame pos=\"{{{ChannelPos}}} -12\"/>", Now+350, 500, CAnimManager::EAnimManagerEasing::CubicOut);
}

declare K_ChannelInfoResult ChannelInfoResultShare for Page;
declare K_ChannelTimeSlot ChannelTimeSlot;
foreach (TimeSlot in ChannelInfoResultShare.time_slots) {
if (TimeSlot.existskey(0) && TimeSlot[0].existskey(TimeSlotNumber)) {
ChannelTimeSlot = TimeSlot[0][TimeSlotNumber];
break;
}
}
(Frame_Channel.GetFirstChild("quad-image") as CMlQuad).ChangeImageUrl(ChannelTimeSlot.program_card_image_url);
G_ChannelTimeStampEnd = Multiplayer_Find_TextLib::ToText(ChannelTimeSlot.time_slot_end_timestamp);
G_ChannelTimeDuration = ChannelTimeSlot.time_slot_duration;
(Frame_Channel.GetFirstChild("label-starttime") as CMlLabel).SetText(Multiplayer_Find_TimeLib::FormatDate(ChannelTimeSlot.time_slot_start_timestamp^"", Multiplayer_Find_TimeLib::EDateFormats::TimeShort));

declare K_ChannelInfo ChannelInfo;
foreach (ChannelInfoTmp in ChannelInfoResultShare.channels) {
ChannelInfo = ChannelInfoTmp;
break;
}
(Frame_Channel.GetFirstChild("label-players") as CMlLabel).SetText(ChannelInfo.channel_online_players^" ");
}

main() {
declare Boolean JustShowed = False;
declare Integer LastTimeRequest = -1;
Init();
ListDisplayer_Init();
while(True) {
Expand All @@ -123,6 +194,30 @@ Text Build() {
CursorHelper_Loop();
LibManialink_AnimLoop();

if (LastTimeRequest > 0 && LastTimeRequest <= Now) {
SendCustomEvent("Multiplayer_GetChannelInfo", []);
G_ChannelTimeStampEnd = "";
}

if (G_ChannelTimeStampEnd != "" && Multiplayer_Find_TimeLib::Compare(G_ChannelTimeStampEnd, Multiplayer_Find_TimeLib::GetCurrent()) <= 0) {
UpdateChannelInfo(1, False);
}

if (G_ChannelTimeStampEnd != "") {
declare Text TimeLeftUI = Multiplayer_Find_TimeLib::FormatDelta(G_ChannelTimeStampEnd, Multiplayer_Find_TimeLib::GetCurrent(), Multiplayer_Find_TimeLib::EDurationFormats::Chrono);
(Page.GetFirstChild("label-timeleft") as CMlLabel).SetText(TimeLeftUI);

declare Integer TimeLeft = Multiplayer_Find_TimeLib::GetDelta(G_ChannelTimeStampEnd, Multiplayer_Find_TimeLib::GetCurrent());
TimeLeft = Multiplayer_Find_MathLib::Max(0, TimeLeft);
TimeLeft = Multiplayer_Find_MathLib::Min(G_ChannelTimeDuration, TimeLeft);
declare CMlQuad Quad_Progress = (Page.GetFirstChild("quad-progress") as CMlQuad);
if (G_ChannelTimeDuration != 0) {
Quad_Progress.Size.X = {{{QuadSizeX}}}-{{{QuadSizeX}}}*TimeLeft/G_ChannelTimeDuration;
} else {
Quad_Progress.Size.X = 0.;
}
}

foreach(Event in PendingEvents) {
switch(Event.Type) {

Expand Down Expand Up @@ -158,6 +253,14 @@ Text Build() {
declare Integer ListDisplayer_Id for Label;
SendCustomEvent("SetFilterForScript", [Multiplayer_Find_TextLib::ToText(ListDisplayer_Id)]);
HideCursorHelper();
} else if (Event.ControlId == "quad-image" || Event.ControlId == "button-play") {
declare K_ChannelInfoResult ChannelInfoResultShare for Page;
declare K_ChannelInfo ChannelInfo;
foreach (ChannelInfoTmp in ChannelInfoResultShare.channels) {
ChannelInfo = ChannelInfoTmp;
break;
}
OpenLink(ChannelInfo.channel_join_manialink, CMlScript::LinkType::ManialinkBrowser);
}
}
case CMlEvent::Type::MouseOver: {
Expand All @@ -175,22 +278,29 @@ Text Build() {
if (Label != Null) {
ShowCursorHelper(Multiplayer_Find_TextLib::Compose("{{{_("Click to filter by %1")}}}", Label.Value));
}
} else if (Event.ControlId == "quad-image") {
Page.GetFirstChild("frame-play").Show();
}
}
case CMlEvent::Type::MouseOut: {
if (Event.ControlId == "Elem_Category4" || Event.ControlId == "Elem_Category2") {
HideCursorHelper();
} else if (Event.ControlId == "quad-image") {
Page.GetFirstChild("frame-play").Hide();
}
}
case CMlEvent::Type::PluginCustomEvent: {
switch(Event.CustomEventType) {
case "Show" : {
JustShowed = True;
ShowPage();
SendCustomEvent("UpdateBarreSection", ["Multiplayer_Find"]);
SendCustomEvent("GetServers", ["Multiplayer_Find"]);
SendCustomEvent("Multiplayer_GetChannelInfo", []);
ListDisplayer_Show();
declare PreviousPage = Event.CustomEventData[1];
AnimShow_Frame(PreviousPage == "SectionsSelector");
Page.GetFirstChild("frame-channel").Hide();
}
case "Hide" : {
EnableMenuNavigation(True,False,Null,0);
Expand All @@ -203,6 +313,11 @@ Text Build() {
declare Text ServerLink = Event.CustomEventData[0];
OpenLink(ServerLink, CMlScript::LinkType::Goto);
}
case "Multiplayer_GetChannelInfo" : {
LastTimeRequest = Now + C_TimerRequest;
UpdateChannelInfo(0, JustShowed);
JustShowed = False;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#Include "Libs/Nadeo/Common/ManiascriptTools/XmlParser.Script.txt" as XmlParser
#Include "Libs/Nadeo/MP4/TPLagoon/TokenManager.Script.txt" as TokenManager
#Include "Libs/Nadeo/Common/Core/Logger.Script.txt" as Logger
#Include "Libs/Nadeo/MP4/TPLagoon/Components/Multiplayer/ChannelInfoStructs.Script.txt" as ChannelInfoStructs

#Const C_ImgBase "file://Media/MEDIABROWSER_HiddenResources/Common/Images/Menus/"
#Const C_WaitTimeMax 5000
Expand All @@ -17,6 +18,9 @@ declare CHttpRequest G_Request;
declare Boolean G_HasFetched;
declare Boolean G_HasStartedFetch;

declare CHttpRequest G_RequestChannelInfo;
declare ChannelInfoStructs::K_ChannelInfoResult G_ChannelInfoResult;

declare Text G_OrderBy;
declare Integer G_Order;
declare Text G_TextFilter;
Expand All @@ -43,7 +47,8 @@ Void Load(Boolean _TitleServersOnly)
{
G_LimitTime = -1;
G_Request = Null;
G_Base_API_Url = "https://www.maniaplanet.com";
G_RequestChannelInfo = Null;
G_Base_API_Url = "https://prod.live.maniaplanet.com";
G_CurrentPage = 0;
G_DisplayTitleServersOnly = _TitleServersOnly;
}
Expand All @@ -53,8 +58,14 @@ Void Load()
Load(True);
}

Text Http_GetHeaders(Boolean UseJson) {
declare Text AcceptHeader = "xml";
if (UseJson) AcceptHeader = "json";
return """Maniaplanet-Auth: Login="{{{ LocalUser.Login }}}", Token="{{{ Authentication_Token }}}" """ ^ "\nAccept: application/"^AcceptHeader;
}

Text Http_GetHeaders() {
return """Maniaplanet-Auth: Login="{{{ LocalUser.Login }}}", Token="{{{ Authentication_Token }}}" """ ^ "\nAccept: application/xml";
return Http_GetHeaders(False);
}

Integer GetPlayerLevelClass(Integer _LadderPoints, Integer _MaxLadderPoints)
Expand Down Expand Up @@ -628,4 +639,40 @@ Text[] GetMultiplayerPlayerRanking() {
PlayerCount);
}
return Result;
}


// Channel info http request
Void FetchChannelInfo() {
if (G_RequestChannelInfo != Null) return;

declare Text UidKey = TextLib::URLEncode("uid[]");
declare Text TitleKey = TextLib::URLEncode("trackmania");
declare Text ProjectEnviro for LocalUser;
if (ProjectEnviro == "Storm") TitleKey = TextLib::URLEncode("shootmania");

G_RequestChannelInfo = Http.CreateGet("""{{{G_Base_API_Url}}}/ingame/public/channels?{{{UidKey}}}={{{TitleKey}}}""", True, Http_GetHeaders(True));
}

Boolean HasFetchedChannelInfo() {
if (G_RequestChannelInfo == Null || !TokenManager::Is_Auth_Success()) return False;

if (G_RequestChannelInfo.IsCompleted) {
if (G_RequestChannelInfo.StatusCode < 200 || G_RequestChannelInfo.StatusCode >= 300) {
Logger::Warn("ERROR Url " ^ G_RequestChannelInfo.Url);
Logger::Warn("ERROR Code " ^ G_RequestChannelInfo.StatusCode);
Logger::Warn("ERROR Content " ^ G_RequestChannelInfo.Result);
return False;
} else {
G_ChannelInfoResult.fromjson(G_RequestChannelInfo.Result);
Http.Destroy(G_RequestChannelInfo);
G_RequestChannelInfo = Null;
return True;
}
}
return False;
}

ChannelInfoStructs::K_ChannelInfoResult GetChannelInfo() {
return G_ChannelInfoResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#Include "Libs/Nadeo/MP4/Common/Components/ListDisplayer/ListDisplayerController_Menu.Script.txt" as ListDisplayerController_Menu
#Include "Libs/Nadeo/MP4/Common/Components/MatchSettingsEditor/MatchSettingsEditorController.Script.txt" as MatchSettingsEditorController
#Include "Libs/Nadeo/MP4/TPLagoon/Components/Multiplayer/ChannelInfoStructs.Script.txt" as ChannelInfoStructs

//APIs
#Include "Libs/Nadeo/MP4/Common/SettingsController.Script.txt" as SettingsController
Expand Down Expand Up @@ -174,6 +175,12 @@ Void Loop() {
if (MultiplayerAPI::HasFetched()) {
GetServers("Multiplayer_Find");
}
if (MultiplayerAPI::HasFetchedChannelInfo()) {
declare LayerToSend <=> Layers::Get("Multiplayer_Find");
declare ChannelInfoStructs::K_ChannelInfoResult ChannelInfoResultShare for LayerToSend.LocalPage;
ChannelInfoResultShare = MultiplayerAPI::GetChannelInfo();
LayerCustomEvent(LayerToSend, "Multiplayer_GetChannelInfo", []);
}
foreach(Event in PendingEvents) {
if(Event.Type != CManiaAppEvent::EType::LayerCustomEvent) continue;
switch(Event.CustomEventType) {
Expand Down Expand Up @@ -286,6 +293,9 @@ Void Loop() {
if(MaxPlayerCount > 255) MaxPlayerCount = 255;
TitleFlow.CreateServer(ServerName, ServerComment, MaxPlayerCount, Password, PasswordSpectators, False, G_MatchSettingsFileName ^ ".txt");
}
case "Multiplayer_GetChannelInfo": {
MultiplayerAPI::FetchChannelInfo();
}
}
}
}
Expand Down
Loading

0 comments on commit 6a2924c

Please sign in to comment.