DrawHelpPanel.cs
6.3 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
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
using Codice.Client.Common;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Help
{
internal static class DrawHelpPanel
{
internal static void For(
HelpPanel helpPanel)
{
if (!helpPanel.Visible)
return;
DoHelpPanelToolbar(helpPanel);
GUILayout.Space(10);
DoHelpPanelContent(helpPanel);
}
static void DoHelpPanelToolbar(
HelpPanel helpPanel)
{
Rect rect = GUILayoutUtility.GetLastRect();
rect.y = rect.yMax;
rect.height = 22;
GUILayout.Space(1);
GUIStyle expandableToolbar = new GUIStyle(EditorStyles.toolbar);
expandableToolbar.fixedHeight = 0;
GUI.Label(rect, GUIContent.none, expandableToolbar);
using (new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button("<", EditorStyles.miniButtonLeft))
{
// TODO(codice): On Left Clicked
}
if (GUILayout.Button(">", EditorStyles.miniButtonRight))
{
// TODO(codice): On Right Clicked
}
GUILayout.FlexibleSpace();
// TODO(codice): The bool used here must be loaded and persisted by some means
helpPanel.Data.ShouldShowAgain = EditorGUILayout.ToggleLeft(
PlasticLocalization.GetString(PlasticLocalization.Name.DontShowItAgain),
helpPanel.Data.ShouldShowAgain, UnityStyles.MiniToggle);
bool okWasPressed = GUILayout.Button(
PlasticLocalization.GetString(PlasticLocalization.Name.OkButton),
EditorStyles.miniButton);
if (okWasPressed)
{
helpPanel.Hide();
// TODO(codice): Do on helppanel dismiss actions
return;
}
}
}
static void DoHelpPanelContent(
HelpPanel helpPanel)
{
using (new EditorGUILayout.HorizontalScope())
{
Texture image = Images.GetHelpImage(helpPanel.Image);
var imgRect = GUILayoutUtility.GetRect(
image.width, image.width, image.height, image.height);
GUI.DrawTexture(imgRect, image, ScaleMode.ScaleToFit);
using (new EditorGUILayout.VerticalScope())
{
GUIStyle helpParagraph = UnityStyles.Paragraph;
helpPanel.TextScroll = GUILayout.BeginScrollView(helpPanel.TextScroll);
GUILayout.Label(helpPanel.GUIContent, helpParagraph);
if (Event.current.type != EventType.Layout)
DoHelpPanelLinks(helpPanel, helpParagraph);
GUILayout.EndScrollView();
Rect scrollRect = GUILayoutUtility.GetLastRect();
if (Mouse.IsRightMouseButtonPressed(Event.current) &&
scrollRect.Contains(Event.current.mousePosition))
{
GenericMenu contextMenu = BuildHelpPanelMenu(helpPanel.Data.CleanText);
contextMenu.ShowAsContext();
}
}
}
}
static void DoHelpPanelLinks(
HelpPanel helpPanel,
GUIStyle helpParagraph)
{
var lastRect = GUILayoutUtility.GetLastRect();
bool linkWasClicked = false;
GUIContent charContent = new GUIContent();
for (int charIdx = 0; charIdx < helpPanel.GUIContent.text.Length; charIdx++)
{
HelpLink link;
if (!helpPanel.TryGetLinkAtChar(charIdx, out link))
continue;
charContent.text = helpPanel.GUIContent.text[charIdx].ToString();
var pos = helpParagraph.GetCursorPixelPosition(
lastRect, helpPanel.GUIContent, charIdx);
float charWidth = helpParagraph.CalcSize(charContent).x;
Rect charRect = new Rect(pos, new Vector2(
charWidth - 4, helpParagraph.lineHeight));
if (!linkWasClicked &&
Mouse.IsLeftMouseButtonPressed(Event.current) &&
charRect.Contains(Event.current.mousePosition))
{
linkWasClicked = true;
OnHelpLinkClicked(helpPanel, link);
}
// Underline for links
charRect.y = charRect.yMax - 1;
charRect.height = 1;
GUI.DrawTexture(charRect, Images.GetLinkUnderlineImage());
}
}
static void OnHelpLinkClicked(
HelpPanel helpPanel,
HelpLink helpLink)
{
HelpLink.LinkType linkType;
string content;
if (!HelpLinkData.TryGet(helpLink.Link, out linkType, out content))
return;
switch (linkType)
{
case HelpLink.LinkType.Action:
GuiMessage.ShowInformation(
"An ACTION link has been clicked:\n" + content);
break;
case HelpLink.LinkType.Help:
helpPanel.Show(
PlasticGui.Help.HelpImage.GenericBuho,
content == "sample1" ?
TestingHelpData.GetSample1() :
TestingHelpData.GetSample2());
break;
case HelpLink.LinkType.Link:
Process.Start(content);
break;
}
}
static void CopyToClipboard(string data)
{
EditorGUIUtility.systemCopyBuffer = data;
}
static GenericMenu BuildHelpPanelMenu(string cleanText)
{
GenericMenu result = new GenericMenu();
result.AddItem(
new GUIContent(PlasticLocalization.GetString(PlasticLocalization.Name.Copy)),
false,
() => CopyToClipboard(cleanText)
);
return result;
}
}
}