|
| 1 | +using System; |
| 2 | +using Imui.Controls; |
| 3 | +using Imui.Core; |
| 4 | +using Imui.Style; |
| 5 | +using UnityEngine; |
| 6 | +using ZeepSDK.Controls; |
| 7 | +using ZeepSDK.UI; |
| 8 | +using ZeepSDK.Utilities; |
| 9 | + |
| 10 | +namespace TNRD.Zeepkist.GTR.Dialogs; |
| 11 | + |
| 12 | +internal sealed class LaLigaCensorshipDialog : IZeepGUIDrawer, IDisposable |
| 13 | +{ |
| 14 | + public const string MoreInformationUrl = "https://hayahora.futbol"; |
| 15 | + |
| 16 | + private readonly Action<bool> _onDecision; |
| 17 | + private readonly DisposableBag _inputOverride; |
| 18 | + private bool _active = true; |
| 19 | + private bool _useAlternativeDomains; |
| 20 | + |
| 21 | + public LaLigaCensorshipDialog(bool useAlternativeDomains, Action<bool> onDecision) |
| 22 | + { |
| 23 | + _useAlternativeDomains = useAlternativeDomains; |
| 24 | + _onDecision = onDecision ?? throw new ArgumentNullException(nameof(onDecision)); |
| 25 | + _inputOverride = ControlsApi.DisableAllInputExceptEventSystem(() => _active); |
| 26 | + } |
| 27 | + |
| 28 | + public void OnZeepGUI(ImGui gui) |
| 29 | + { |
| 30 | + if (!_active) |
| 31 | + return; |
| 32 | + |
| 33 | + uint id = gui.PushId("LaLigaCensorshipPopup"); |
| 34 | + try |
| 35 | + { |
| 36 | + gui.BeginPopup(); |
| 37 | + ImRect rect = ImWindow.GetInitialWindowRect(gui, new ImSize(920, 650)); |
| 38 | + |
| 39 | + gui.Canvas.PushClipRect(rect); |
| 40 | + gui.Canvas.PushRectMask(rect, 0); |
| 41 | + gui.Box(rect, gui.Style.Window.Box); |
| 42 | + gui.RegisterControl(id, rect); |
| 43 | + gui.RegisterGroup(id, rect); |
| 44 | + gui.Layout.Push(ImAxis.Vertical, rect.WithPadding(24)); |
| 45 | + |
| 46 | + gui.Text("Connection issues in Spain", new ImTextSettings(36, 0.5f)); |
| 47 | + gui.AddSpacing(10); |
| 48 | + DrawParagraph(gui, |
| 49 | + "During La Liga matches, Spanish internet providers block Cloudflare IP addresses at La Liga's " + |
| 50 | + "request. This goes beyond the websites covered by the court orders and blocks unrelated services " + |
| 51 | + "using Cloudflare infrastructure, including ZeepCentraal."); |
| 52 | + gui.AddSpacing(10); |
| 53 | + DrawParagraph(gui, |
| 54 | + "If you're affected, GTR may be unable to connect to ZeepCentraal, submit records, download ghosts " + |
| 55 | + "or use other online features."); |
| 56 | + gui.AddSpacing(10); |
| 57 | + DrawParagraph(gui, |
| 58 | + "You can use alternative ZeepCentraal domains that don't go through Cloudflare to avoid these blocks."); |
| 59 | + gui.AddSpacing(14); |
| 60 | + |
| 61 | + _useAlternativeDomains = gui.Checkbox( |
| 62 | + _useAlternativeDomains, |
| 63 | + "Use alternative domains in Spain"); |
| 64 | + |
| 65 | + gui.AddSpacing(14); |
| 66 | + DrawParagraph(gui, |
| 67 | + "Please only enable this if you're having connection problems due to ISP blocking. You can turn it " + |
| 68 | + "off or on at any time in the GTR mod settings under \"Other -> 5. URLs\"."); |
| 69 | + gui.AddSpacing(10); |
| 70 | + DrawParagraph(gui, |
| 71 | + "For more information about La Liga's censorship and how it affects internet access in Spain, visit:"); |
| 72 | + gui.AddSpacing(6); |
| 73 | + |
| 74 | + if (gui.Button(MoreInformationUrl, new ImSize(320, 42))) |
| 75 | + Application.OpenURL(MoreInformationUrl); |
| 76 | + |
| 77 | + const float buttonWidth = 220; |
| 78 | + const float buttonHeight = 52; |
| 79 | + gui.AddSpacing(Mathf.Max(12, gui.GetLayoutHeight() - buttonHeight)); |
| 80 | + |
| 81 | + using (gui.Horizontal(gui.GetLayoutWidth(), buttonHeight)) |
| 82 | + { |
| 83 | + gui.AddSpacing(Mathf.Max(0, gui.GetLayoutWidth() - buttonWidth)); |
| 84 | + if (gui.Button("Continue", new ImSize(buttonWidth, buttonHeight))) |
| 85 | + Decide(); |
| 86 | + } |
| 87 | + |
| 88 | + gui.Layout.Pop(); |
| 89 | + gui.Canvas.PopClipRect(); |
| 90 | + gui.Canvas.PopClipRect(); |
| 91 | + gui.EndPopup(); |
| 92 | + } |
| 93 | + finally |
| 94 | + { |
| 95 | + gui.PopId(); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + public void Dispose() |
| 100 | + { |
| 101 | + if (!_active) |
| 102 | + return; |
| 103 | + |
| 104 | + _active = false; |
| 105 | + _inputOverride.Dispose(); |
| 106 | + } |
| 107 | + |
| 108 | + private static void DrawParagraph(ImGui gui, string text) |
| 109 | + { |
| 110 | + gui.Text(text, new ImTextSettings(18, 0f, 0f, true)); |
| 111 | + } |
| 112 | + |
| 113 | + private void Decide() |
| 114 | + { |
| 115 | + if (!_active) |
| 116 | + return; |
| 117 | + |
| 118 | + _active = false; |
| 119 | + _inputOverride.Dispose(); |
| 120 | + _onDecision(_useAlternativeDomains); |
| 121 | + } |
| 122 | +} |
0 commit comments