2 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
8 static partial class GameAnalyticsManager
10 static partial
void CreateConsentPrompt()
12 if (ConsentTextAvailable)
14 var background =
new GUIFrame(
new RectTransform(GUI.Canvas.RelativeSize, GUI.Canvas), style:
"GUIBackgroundBlocker");
15 var frame =
new GUIFrame(
new RectTransform(
new Vector2(0.5f, 0.7f), background.RectTransform,
Anchor.Center) { MinSize = new Point(800, 0), MaxSize = new Point(1500, int.MaxValue) });
17 var content =
new GUILayoutGroup(
new RectTransform(
new Vector2(0.95f), frame.RectTransform,
Anchor.Center))
20 AbsoluteSpacing = GUI.IntScale(15)
23 string consentTextTag =
"statisticsconsenttext";
24 if (EosInterface.IdQueries.IsLoggedIntoEosConnect)
26 consentTextTag =
"statisticsconsenteostext";
28 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), content.RectTransform), TextManager.Get(
"statisticsconsentheader"), font: GUIStyle.SubHeadingFont, textColor: Color.White);
29 var mainText =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), content.RectTransform), RichString.Rich(TextManager.Get(consentTextTag)), wrap:
true);
31 foreach (var data
in mainText.RichTextData)
33 mainText.ClickableAreas.Add(
new GUITextBlock.ClickableArea()
36 OnClick = (GUITextBlock component, GUITextBlock.ClickableArea area) =>
38 GameMain.ShowOpenUriPrompt(
"https://gameanalytics.com/privacy/");
43 string privacyPolicyText = File.ReadAllText(
"daedalic_privacypolicy.txt");
44 var privacyPolicyBox =
new GUIListBox(
new RectTransform(
new Vector2(1.0f, 0.5f), content.RectTransform) { MaxSize = new Point(int.MaxValue, GUI.IntScale(200)) });
45 var privacyPolicy =
new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), privacyPolicyBox.Content.RectTransform), privacyPolicyText, wrap:
true)
49 privacyPolicy.RectTransform.MinSize =
new Point(0, (
int)privacyPolicy.TextSize.Y);
51 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.0f), content.RectTransform), TextManager.Get(
"statisticsconsentstatement"), wrap:
true);
53 var buttonContainer =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.0f), content.RectTransform), isHorizontal:
true);
55 void buttonContainerSpacing(
float width)
56 =>
new GUIFrame(
new RectTransform(
new Vector2(width, 1.0f), buttonContainer.RectTransform), style:
null);
58 buttonContainerSpacing(0.1f);
59 var yesBtn =
new GUIButton(
new RectTransform(
new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), TextManager.Get(
"Yes"));
60 yesBtn.OnClicked += (btn, userdata) =>
62 GUIMessageBox.MessageBoxes.Remove(background);
63 var loadingBox = GUIMessageBox.CreateLoadingBox(TextManager.Get(
"PleaseWait"));
64 SetConsentInternal(Consent.Yes, onAnswerSent: loadingBox.Close);
67 yesBtn.Enabled =
false;
69 IEnumerable<CoroutineStatus> enableAfterTime(WaitForSeconds time, params GUIComponent[] components)
72 foreach (var c
in components)
76 yield
return CoroutineStatus.Success;
79 buttonContainerSpacing(0.2f);
81 var noBtn =
new GUIButton(
new RectTransform(
new Vector2(0.3f, 1.0f), buttonContainer.RectTransform), TextManager.Get(
"No"));
82 noBtn.OnClicked += (btn, userdata) =>
84 GUIMessageBox.MessageBoxes.Remove(background);
85 var loadingBox = GUIMessageBox.CreateLoadingBox(TextManager.Get(
"PleaseWait"));
86 SetConsent(Consent.No, onAnswerSent: loadingBox.Close);
89 noBtn.Enabled =
false;
91 CoroutineManager.StartCoroutine(enableAfterTime(
new WaitForSeconds(0.3f), yesBtn, noBtn));
93 buttonContainerSpacing(0.1f);
95 buttonContainer.RectTransform.MinSize =
new Point(0, yesBtn.RectTransform.MinSize.Y);
96 buttonContainer.RectTransform.MaxSize =
new Point(
int.MaxValue, yesBtn.RectTransform.MinSize.Y);
98 content.Recalculate();
99 foreach (var child
in content.Children)
101 if (child is GUITextBlock textBlock)
103 textBlock.TextScale = MathHelper.Min(1.0f, 1.0f / GameSettings.CurrentConfig.Graphics.TextScale);
104 textBlock.RectTransform.MinSize =
new Point(0, (
int)textBlock.TextSize.Y);
105 textBlock.RectTransform.MaxSize =
new Point(
int.MaxValue, (
int)textBlock.TextSize.Y);
109 int contentHeight = content.Children.Sum(c => c.RectTransform.MaxSize.Y + content.AbsoluteSpacing);
110 frame.RectTransform.MinSize =
new Point(frame.RectTransform.MinSize.X, (
int)(contentHeight / content.RectTransform.RelativeSize.Y));
111 frame.RectTransform.MaxSize =
new Point(frame.RectTransform.MaxSize.X, (
int)(contentHeight / content.RectTransform.RelativeSize.Y));
113 GUIMessageBox.MessageBoxes.Add(background);
118 SetConsent(Consent.Unknown);