Openplanet-Plugins/TMWTInterfacesRemover/main.as

91 lines
3.8 KiB
ActionScript

bool InterfacesAreHidden;
bool HideInterfaces;
string Last_ServerLogin;
CGameUILayer@ UILayer_LiveRanking;
CGameUILayer@ UILayer_TeamsScores;
void RenderMenu() {
if(UI::MenuItem("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "", HideInterfaces)) {
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 != "") {
HideInterfaces = !HideInterfaces;
}
}
}
CGameUILayer@ findUILayer(const MwFastBuffer<CGameUILayer@> _UILayers, string _ManialinkId) {
for (uint i = 0; i < _UILayers.Length; i++) {
string manialink = _UILayers[i].ManialinkPage;
auto firstlines = manialink.Split("\n", 5);
if (firstlines.Length > 0) {
for (uint j = 0; j < firstlines.Length - 1; j++) {
if (firstlines[j].Contains(_ManialinkId)) {
return _UILayers[i];
}
}
}
}
return null;
}
void Main() {
while(true) {
yield();
auto app = cast<CTrackMania>(GetApp());
auto network = cast<CTrackManiaNetwork>(app.Network);
auto serverinfo = cast<CTrackManiaNetworkServerInfo>(network.ServerInfo);
if (network !is null && serverinfo !is null) {
if (Last_ServerLogin != serverinfo.ServerLogin) {
Last_ServerLogin = serverinfo.ServerLogin;
HideInterfaces = false;
InterfacesAreHidden = false;
}
// Prevent to continue the loop when not needed
if (!HideInterfaces && !InterfacesAreHidden) continue;
CGameManiaAppPlayground@ ManiaApp = cast<CGameManiaAppPlayground>(network.ClientManiaAppPlayground);
if (ManiaApp !is null) {
if (UILayer_LiveRanking is null) {
@UILayer_LiveRanking = findUILayer(ManiaApp.UILayers, "UIModule_TMWTCommon_LiveRanking");
}
if (UILayer_TeamsScores is null) {
@UILayer_TeamsScores = findUILayer(ManiaApp.UILayers, "UIModule_TMWTCommon_Header");
}
if (UILayer_TeamsScores is null && UILayer_LiveRanking is null) {
UI::ShowNotification("\\$77d" + Icons::User + " \\$fffTMWT Interfaces Remover", "Can't find Interfaces to hide, disabling the plugin");
HideInterfaces = false;
InterfacesAreHidden = false;
}
if (HideInterfaces && !InterfacesAreHidden && ManiaApp.UI.UISequence == CGamePlaygroundUIConfig::EUISequence::Playing) {
if (HideLiveRanking && UILayer_LiveRanking !is null) {
UILayer_LiveRanking.IsVisible = false;
}
if (HideTeamsScores && UILayer_TeamsScores !is null) {
UILayer_TeamsScores.IsVisible = false;
}
InterfacesAreHidden = true;
} else if (InterfacesAreHidden && (!HideInterfaces || ManiaApp.UI.UISequence != CGamePlaygroundUIConfig::EUISequence::Playing)) {
if (UILayer_LiveRanking !is null) {
UILayer_LiveRanking.IsVisible = true;
}
if (UILayer_TeamsScores !is null) {
UILayer_TeamsScores.IsVisible = true;
}
InterfacesAreHidden = false;
}
}
} else {
Last_ServerLogin = "";
HideInterfaces = false;
InterfacesAreHidden = false;
@UILayer_LiveRanking = null;
@UILayer_TeamsScores = null;
}
}
}