-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathDisconnectedWindow.cs
95 lines (74 loc) · 2.99 KB
/
DisconnectedWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using UnityEngine;
using Verse;
namespace Multiplayer.Client
{
public class DisconnectedWindow : Window
{
public override Vector2 InitialSize => new(info.wideWindow ? 430f : 320f, height);
public override float Margin => 26f;
private float height;
protected SessionDisconnectInfo info;
public bool returnToServerBrowser;
public DisconnectedWindow(SessionDisconnectInfo info)
{
this.info = info;
if (this.info.titleTranslated.NullOrEmpty())
this.info.titleTranslated = "MpDisconnected".Translate();
closeOnAccept = false;
closeOnCancel = false;
closeOnClickedOutside = false;
forcePause = true;
absorbInputAroundWindow = true;
}
const float ButtonHeight = 40f;
const float ButtonSpacing = 10f;
public override void DoWindowContents(Rect inRect)
{
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.UpperCenter;
var text = info.descTranslated.NullOrEmpty()
? info.titleTranslated
: $"<b>{info.titleTranslated}</b>\n{info.descTranslated}";
var buttonHeight = ButtonHeight + ButtonSpacing;
if (info.specialButtonTranslated != null)
buttonHeight += ButtonHeight + ButtonSpacing;
var textHeight = Text.CalcHeight(text, inRect.width);
height = textHeight + buttonHeight + Margin * 2;
SetInitialSizeAndPosition();
Widgets.Label(inRect, text);
Text.Anchor = TextAnchor.UpperLeft;
DrawButtons(inRect);
}
private void DrawButtons(Rect inRect)
{
var isPlaying = Current.ProgramState != ProgramState.Entry;
var buttonWidth = isPlaying ? 140f : 120f;
var buttonRect = new Rect((inRect.width - buttonWidth) / 2f, inRect.height - ButtonHeight, buttonWidth, ButtonHeight);
var buttonText = isPlaying ? "QuitToMainMenu" : "CloseButton";
if (Widgets.ButtonText(buttonRect, buttonText.Translate()))
{
if (isPlaying)
GenScene.GoToMainMenu();
else
Close();
}
if (info.specialButtonTranslated == null)
return;
var connectAsBtn = buttonRect;
connectAsBtn.y -= ButtonHeight + ButtonSpacing;
connectAsBtn.width = Text.CalcSize(info.specialButtonTranslated).x + 30;
connectAsBtn = connectAsBtn.CenteredOnXIn(buttonRect);
if (Widgets.ButtonText(connectAsBtn, info.specialButtonTranslated))
{
returnToServerBrowser = false;
info.specialButtonAction();
Close();
}
}
public override void PostClose()
{
if (returnToServerBrowser)
Find.WindowStack.Add(new ServerBrowser());
}
}
}