Add support of the TMWC2023 game mode

This commit is contained in:
Beu 2023-08-28 12:24:14 +02:00
parent efa20e6421
commit db9a4bbe59
3 changed files with 80 additions and 51 deletions

View File

@ -1,6 +1,6 @@
[meta] [meta]
name = "TMWT Interfaces Remover" name = "TMWT Interfaces Remover"
category = "TMWT" category = "TMWT"
version = "1.2" version = "1.3"
siteid = 318 siteid = 318

View File

@ -1,16 +1,31 @@
bool InterfacesAreHidden; const string C_Class_UIModules = 'component-modelibs-uimodules-module';
bool HideInterfaces; const string C_Id_TMWT_LiveRanking = 'TMWTCommon_LiveRanking';
string Last_ServerLogin; const string C_Id_TMWT_Header = 'TMWTCommon_Header';
CGameUILayer@ UILayer_LiveRanking; const string C_Id_TMWC2023_LiveRanking = 'TMWC2023_LiveRanking';
CGameUILayer@ UILayer_TeamsScores; const string C_Id_TMWC2023_Header = 'TMWC2023_Header';
bool G_InterfacesAreHidden;
bool G_HideInterfaces;
string G_Last_ServerLogin;
CGameUILayer@ G_UILayer_LiveRanking;
CGameUILayer@ G_UILayer_TeamsScores;
void OnSettingsChanged() {
trace("Settings updated");
@G_UILayer_LiveRanking = null;
@G_UILayer_TeamsScores = null;
G_InterfacesAreHidden = false;
}
void RenderMenu() { void RenderMenu() {
if(UI::MenuItem("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "", HideInterfaces)) { if(UI::MenuItem("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "", G_HideInterfaces)) {
auto app = cast<CTrackMania>(GetApp()); auto app = cast<CTrackMania>(GetApp());
auto network = cast<CTrackManiaNetwork>(app.Network); auto network = cast<CTrackManiaNetwork>(app.Network);
auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo); auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo);
if (network !is null && serverinfo !is null && serverinfo.ServerLogin != "") { if (network !is null && serverinfo !is null && serverinfo.ServerLogin != "") {
HideInterfaces = !HideInterfaces; G_HideInterfaces = !G_HideInterfaces;
} }
} }
} }
@ -32,17 +47,20 @@ bool IsPlaying() {
} }
CGameUILayer@ findUILayer(const MwFastBuffer<CGameUILayer@> _UILayers, string _ManialinkId) { CGameUILayer@ findUILayer(const MwFastBuffer<CGameUILayer@> _UILayers, string _ManialinkId) {
for (uint i = 0; i < _UILayers.Length; i++) { for (uint Index = 0; Index < _UILayers.Length; ++Index) {
string manialink = _UILayers[i].ManialinkPage; CGameUILayer@ Layer = _UILayers[Index];
auto firstlines = manialink.Split("\n", 5); CGameManialinkPage@ Page = Layer.LocalPage;
if (firstlines.Length > 0) {
for (uint j = 0; j < firstlines.Length - 1; j++) { // Check if we have the main UI module
if (firstlines[j].Contains(_ManialinkId)) { Page.GetClassChildren(C_Class_UIModules, Page.MainFrame, true);
return _UILayers[i];
} if (Page.GetClassChildren_Result.Length > 0) {
} if (Page.GetClassChildren_Result[0].ControlId == _ManialinkId) {
} return _UILayers[Index];
} }
}
}
return null; return null;
} }
@ -54,55 +72,58 @@ void Main() {
auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo); auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo);
if (network !is null && serverinfo !is null) { if (network !is null && serverinfo !is null) {
if (Last_ServerLogin != serverinfo.ServerLogin) { if (G_Last_ServerLogin != serverinfo.ServerLogin) {
Last_ServerLogin = serverinfo.ServerLogin; G_Last_ServerLogin = serverinfo.ServerLogin;
@UILayer_LiveRanking = null; @G_UILayer_LiveRanking = null;
@UILayer_TeamsScores = null; @G_UILayer_TeamsScores = null;
HideInterfaces = false; G_HideInterfaces = false;
InterfacesAreHidden = false; G_InterfacesAreHidden = false;
} }
// Prevent to continue the loop when not needed // Prevent to continue the loop when not needed
if (!HideInterfaces && !InterfacesAreHidden) continue; if (!G_HideInterfaces && !G_InterfacesAreHidden) continue;
CGameManiaAppPlayground@ ManiaApp = cast<CGameManiaAppPlayground>(network.ClientManiaAppPlayground); CGameManiaAppPlayground@ ManiaApp = cast<CGameManiaAppPlayground>(network.ClientManiaAppPlayground);
if (ManiaApp !is null) { if (ManiaApp !is null) {
if (UILayer_LiveRanking is null) { if (G_UILayer_LiveRanking is null) {
@UILayer_LiveRanking = findUILayer(ManiaApp.UILayers, "UIModule_TMWTCommon_LiveRanking"); if (Setting_GameMode == GameMode::TMWT) @G_UILayer_LiveRanking = findUILayer(ManiaApp.UILayers, C_Id_TMWT_LiveRanking);
else if (Setting_GameMode == GameMode::TMWC2023) @G_UILayer_LiveRanking = findUILayer(ManiaApp.UILayers, C_Id_TMWC2023_LiveRanking);
} }
if (UILayer_TeamsScores is null) { if (G_UILayer_TeamsScores is null) {
@UILayer_TeamsScores = findUILayer(ManiaApp.UILayers, "UIModule_TMWTCommon_Header"); if (Setting_GameMode == GameMode::TMWT) @G_UILayer_TeamsScores = findUILayer(ManiaApp.UILayers, C_Id_TMWT_Header);
else if (Setting_GameMode == GameMode::TMWC2023) @G_UILayer_TeamsScores = findUILayer(ManiaApp.UILayers, C_Id_TMWC2023_Header);
} }
if (UILayer_TeamsScores is null && UILayer_LiveRanking is null) { if (G_UILayer_TeamsScores is null && G_UILayer_LiveRanking is null) {
UI::ShowNotification("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "Can't find Interfaces to hide, disabling the plugin"); UI::ShowNotification("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "Can't find Interfaces to hide, disabling the plugin");
HideInterfaces = false; G_HideInterfaces = false;
InterfacesAreHidden = false; G_InterfacesAreHidden = false;
} }
if (HideInterfaces && !InterfacesAreHidden && IsPlaying() ) { if (G_HideInterfaces && !G_InterfacesAreHidden && IsPlaying() ) {
if (HideLiveRanking && UILayer_LiveRanking !is null) { if (HideLiveRanking && G_UILayer_LiveRanking !is null) {
UILayer_LiveRanking.IsVisible = false; G_UILayer_LiveRanking.IsVisible = false;
} }
if (HideTeamsScores && UILayer_TeamsScores !is null) { if (HideTeamsScores && G_UILayer_TeamsScores !is null) {
UILayer_TeamsScores.IsVisible = false; G_UILayer_TeamsScores.IsVisible = false;
} }
InterfacesAreHidden = true; G_InterfacesAreHidden = true;
} else if (InterfacesAreHidden && (!HideInterfaces || !IsPlaying())) { } else if (G_InterfacesAreHidden && (!G_HideInterfaces || !IsPlaying())) {
if (UILayer_LiveRanking !is null) { if (G_UILayer_LiveRanking !is null) {
UILayer_LiveRanking.IsVisible = true; G_UILayer_LiveRanking.IsVisible = true;
} }
if (UILayer_TeamsScores !is null) { if (G_UILayer_TeamsScores !is null) {
UILayer_TeamsScores.IsVisible = true; G_UILayer_TeamsScores.IsVisible = true;
} }
InterfacesAreHidden = false; G_InterfacesAreHidden = false;
} }
} }
} else { } else {
Last_ServerLogin = ""; G_Last_ServerLogin = "";
HideInterfaces = false; G_HideInterfaces = false;
InterfacesAreHidden = false; G_InterfacesAreHidden = false;
@UILayer_LiveRanking = null; @G_UILayer_LiveRanking = null;
@UILayer_TeamsScores = null; @G_UILayer_TeamsScores = null;
} }
} }
} }

View File

@ -1,5 +1,13 @@
enum GameMode {
TMWT,
TMWC2023,
}
[Setting category="Interfaces" name="Game mode"]
GameMode Setting_GameMode = GameMode::TMWT;
[Setting category="Interfaces" name="Hide Live Ranking"] [Setting category="Interfaces" name="Hide Live Ranking"]
bool HideLiveRanking = true; bool HideLiveRanking = true;
[Setting category="Interfaces" name="Hide Teams Scores"] [Setting category="Interfaces" name="Hide Teams Scores"]
bool HideTeamsScores = true; bool HideTeamsScores = true;