PlasticQuestionAlert.cs
6.0 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using UnityEditor;
using UnityEngine;
using Codice.Client.Common;
using PlasticGui;
namespace Unity.PlasticSCM.Editor.UI.Message
{
internal class PlasticQuestionAlert : PlasticDialog
{
protected override Rect DefaultRect
{
get
{
var baseRect = base.DefaultRect;
string buttonsText = mFirst + mSecond + (mThird ?? string.Empty);
int textWidth = (int)((GUIStyle)UnityStyles.Dialog.AcceptButtonText)
.CalcSize(new GUIContent(buttonsText)).x;
return new Rect(
baseRect.x, baseRect.y,
Math.Max(500, textWidth + 150), 180);
}
}
internal static ResponseType Show(
string title,
string message, string first,
string second, string third,
bool isFirstButtonEnabled,
GuiMessage.GuiMessageType alertType,
EditorWindow parentWindow)
{
PlasticQuestionAlert alert = Create(
title, message, first, second, third,
isFirstButtonEnabled, alertType);
return alert.RunModal(parentWindow);
}
protected override void OnModalGUI()
{
DoMessageArea();
GUILayout.FlexibleSpace();
GUILayout.Space(20);
DoButtonsArea();
}
protected override string GetTitle()
{
return PlasticLocalization.GetString(
PlasticLocalization.Name.PlasticSCM);
}
void DoMessageArea()
{
using (new EditorGUILayout.HorizontalScope())
{
DrawDialogIcon.ForMessage(mAlertType);
using (new EditorGUILayout.VerticalScope())
{
GUILayout.Label(mTitle, UnityStyles.Dialog.MessageTitle);
GUIContent message = new GUIContent(mMessage);
Rect lastRect = GUILayoutUtility.GetLastRect();
GUIStyle scrollPlaceholder = new GUIStyle(UnityStyles.Dialog.MessageText);
scrollPlaceholder.normal.textColor = Color.clear;
scrollPlaceholder.clipping = TextClipping.Clip;
if (Event.current.type == EventType.Repaint)
{
mMessageDesiredHeight = ((GUIStyle)UnityStyles.Dialog.MessageText)
.CalcHeight(message, lastRect.width - 20) + 20;
mMessageViewHeight = Mathf.Min(mMessageDesiredHeight, 60);
}
GUILayout.Space(mMessageViewHeight);
Rect scrollPanelRect = new Rect(
lastRect.xMin, lastRect.yMax,
lastRect.width + 20, mMessageViewHeight);
Rect contentRect = new Rect(
scrollPanelRect.xMin,
scrollPanelRect.yMin,
scrollPanelRect.width - 20,
mMessageDesiredHeight);
mScroll = GUI.BeginScrollView(scrollPanelRect, mScroll, contentRect);
GUI.Label(contentRect, mMessage, UnityStyles.Dialog.MessageText);
GUI.EndScrollView();
}
}
}
void DoButtonsArea()
{
using (new EditorGUILayout.HorizontalScope())
{
GUILayout.FlexibleSpace();
if (Application.platform == RuntimePlatform.WindowsEditor)
{
DoFirstButton();
DoSecondButton();
DoThirdButton();
return;
}
DoThirdButton();
DoSecondButton();
DoFirstButton();
}
}
void DoFirstButton()
{
GUI.enabled = mIsFirstButtonEnabled;
bool pressed = mIsFirstButtonEnabled ?
AcceptButton(mFirst) :
NormalButton(mFirst);
GUI.enabled = true;
if (!pressed)
return;
OkButtonAction();
}
void DoSecondButton()
{
if (!NormalButton(mSecond))
return;
CancelButtonAction();
}
void DoThirdButton()
{
if (mThird == null)
return;
bool pressed = mIsFirstButtonEnabled ?
NormalButton(mThird) :
AcceptButton(mThird);
if (!pressed)
return;
ApplyButtonAction();
}
static PlasticQuestionAlert Create(
string title, string message, string first,
string second, string third, bool isFirstButtonEnabled,
GuiMessage.GuiMessageType alertType)
{
var instance = CreateInstance<PlasticQuestionAlert>();
instance.titleContent = new GUIContent(title);
instance.mTitle = title;
instance.mMessage = message;
instance.mFirst = first;
instance.mSecond = second;
instance.mThird = third;
instance.mIsFirstButtonEnabled = isFirstButtonEnabled;
instance.mAlertType = alertType;
instance.mEnterKeyAction = GetEnterKeyAction(isFirstButtonEnabled, instance);
instance.mEscapeKeyAction = instance.CancelButtonAction;
return instance;
}
static Action GetEnterKeyAction(
bool isFirstButtonEnabled,
PlasticQuestionAlert instance)
{
if (isFirstButtonEnabled)
return instance.OkButtonAction;
return instance.ApplyButtonAction;
}
string mTitle;
string mMessage, mFirst, mSecond, mThird;
bool mIsFirstButtonEnabled;
GuiMessage.GuiMessageType mAlertType;
Vector2 mScroll;
float mMessageDesiredHeight;
float mMessageViewHeight;
}
}