Openplanet-Plugins/TMWTInterfacesRemover/main.as

130 lines
5.4 KiB
ActionScript
Raw Normal View History

2023-08-28 12:24:14 +02:00
const string C_Class_UIModules = 'component-modelibs-uimodules-module';
const string C_Id_TMWT_LiveRanking = 'TMWTCommon_LiveRanking';
const string C_Id_TMWT_Header = 'TMWTCommon_Header';
const string C_Id_TMWC2023_LiveRanking = 'TMWC2023_LiveRanking';
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;
}
2023-01-24 01:25:19 +01:00
void RenderMenu() {
2023-08-28 12:24:14 +02:00
if(UI::MenuItem("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "", G_HideInterfaces)) {
2023-01-24 01:25:19 +01:00
auto app = cast<CTrackMania>(GetApp());
auto network = cast<CTrackManiaNetwork>(app.Network);
auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo);
if (network !is null && serverinfo !is null && serverinfo.ServerLogin != "") {
2023-08-28 12:24:14 +02:00
G_HideInterfaces = !G_HideInterfaces;
2023-01-24 01:25:19 +01:00
}
}
}
bool IsPlaying() {
auto app = cast<CTrackMania>(GetApp());
auto CurrentPlayground = cast<CGamePlayground>(app.CurrentPlayground);
if (CurrentPlayground is null) return false;
if (CurrentPlayground.GameTerminals.Length < 1) return false;
if (CurrentPlayground.GameTerminals[0].ControlledPlayer is null) return false;
if (CurrentPlayground.GameTerminals[0].ControlledPlayer.User is null) return false;
if (CurrentPlayground.GameTerminals[0].GUIPlayer is null) return false;
if (CurrentPlayground.GameTerminals[0].GUIPlayer.User is null) return false;
if (CurrentPlayground.GameTerminals[0].ControlledPlayer.User.Login == CurrentPlayground.GameTerminals[0].GUIPlayer.User.Login) return true;
return false;
}
2023-01-24 01:25:19 +01:00
CGameUILayer@ findUILayer(const MwFastBuffer<CGameUILayer@> _UILayers, string _ManialinkId) {
2023-08-28 12:24:14 +02:00
for (uint Index = 0; Index < _UILayers.Length; ++Index) {
CGameUILayer@ Layer = _UILayers[Index];
CGameManialinkPage@ Page = Layer.LocalPage;
// Check if we have the main UI module
Page.GetClassChildren(C_Class_UIModules, Page.MainFrame, true);
if (Page.GetClassChildren_Result.Length > 0) {
if (Page.GetClassChildren_Result[0].ControlId == _ManialinkId) {
return _UILayers[Index];
}
}
}
2023-01-24 01:25:19 +01:00
return null;
}
void Main() {
while(true) {
2023-01-28 15:14:40 +01:00
yield();
2023-01-24 01:25:19 +01:00
auto app = cast<CTrackMania>(GetApp());
auto network = cast<CTrackManiaNetwork>(app.Network);
auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo);
if (network !is null && serverinfo !is null) {
2023-08-28 12:24:14 +02:00
if (G_Last_ServerLogin != serverinfo.ServerLogin) {
G_Last_ServerLogin = serverinfo.ServerLogin;
@G_UILayer_LiveRanking = null;
@G_UILayer_TeamsScores = null;
G_HideInterfaces = false;
G_InterfacesAreHidden = false;
2023-01-24 01:25:19 +01:00
}
2023-01-28 15:14:40 +01:00
// Prevent to continue the loop when not needed
2023-08-28 12:24:14 +02:00
if (!G_HideInterfaces && !G_InterfacesAreHidden) continue;
2023-01-28 15:14:40 +01:00
2023-01-24 01:25:19 +01:00
CGameManiaAppPlayground@ ManiaApp = cast<CGameManiaAppPlayground>(network.ClientManiaAppPlayground);
if (ManiaApp !is null) {
2023-08-28 12:24:14 +02:00
if (G_UILayer_LiveRanking is null) {
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);
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
if (G_UILayer_TeamsScores is null) {
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);
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
if (G_UILayer_TeamsScores is null && G_UILayer_LiveRanking is null) {
2023-01-28 15:14:40 +01:00
UI::ShowNotification("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "Can't find Interfaces to hide, disabling the plugin");
2023-08-28 12:24:14 +02:00
G_HideInterfaces = false;
G_InterfacesAreHidden = false;
2023-01-28 15:14:40 +01:00
}
2023-08-28 12:24:14 +02:00
if (G_HideInterfaces && !G_InterfacesAreHidden && IsPlaying() ) {
if (HideLiveRanking && G_UILayer_LiveRanking !is null) {
G_UILayer_LiveRanking.IsVisible = false;
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
if (HideTeamsScores && G_UILayer_TeamsScores !is null) {
G_UILayer_TeamsScores.IsVisible = false;
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
G_InterfacesAreHidden = true;
} else if (G_InterfacesAreHidden && (!G_HideInterfaces || !IsPlaying())) {
if (G_UILayer_LiveRanking !is null) {
G_UILayer_LiveRanking.IsVisible = true;
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
if (G_UILayer_TeamsScores !is null) {
G_UILayer_TeamsScores.IsVisible = true;
2023-01-24 01:25:19 +01:00
}
2023-08-28 12:24:14 +02:00
G_InterfacesAreHidden = false;
2023-01-24 01:25:19 +01:00
}
}
} else {
2023-08-28 12:24:14 +02:00
G_Last_ServerLogin = "";
G_HideInterfaces = false;
G_InterfacesAreHidden = false;
@G_UILayer_LiveRanking = null;
@G_UILayer_TeamsScores = null;
2023-01-24 01:25:19 +01:00
}
2023-01-28 15:14:40 +01:00
2023-01-24 01:25:19 +01:00
}
}
2023-08-28 12:24:14 +02:00