A game about forced loneliness, made by TACStudios
1using UnityEditor;
2
3using PlasticGui;
4
5namespace Unity.PlasticSCM.Editor.UI.Progress
6{
7 internal class ProgressControlsForViews : IProgressControls
8 {
9 internal class Data
10 {
11 internal bool IsOperationRunning;
12 internal float ProgressPercent;
13 internal string ProgressMessage;
14
15 internal MessageType NotificationType;
16 internal string NotificationMessage;
17
18 internal void CopyInto(Data other)
19 {
20 other.IsOperationRunning = IsOperationRunning;
21 other.ProgressPercent = ProgressPercent;
22 other.ProgressMessage = ProgressMessage;
23 other.NotificationType = NotificationType;
24 other.NotificationMessage = NotificationMessage;
25 }
26 }
27
28 internal Data ProgressData { get { return mData; } }
29
30 internal bool IsOperationRunning()
31 {
32 return mData.IsOperationRunning;
33 }
34
35 internal bool HasNotification()
36 {
37 return !string.IsNullOrEmpty(mData.NotificationMessage);
38 }
39
40 internal void UpdateDeterminateProgress(EditorWindow parentWindow)
41 {
42 if (IsOperationRunning() || mRequestedRepaint)
43 {
44 parentWindow.Repaint();
45
46 mRequestedRepaint = false;
47 }
48 }
49
50 internal void UpdateProgress(EditorWindow parentWindow)
51 {
52 if (IsOperationRunning() || mRequestedRepaint)
53 {
54 if (IsOperationRunning())
55 UpdateIndeterminateProgress();
56
57 parentWindow.Repaint();
58
59 mRequestedRepaint = false;
60 }
61 }
62
63 void IProgressControls.HideProgress()
64 {
65 HideNotification();
66
67 mData.IsOperationRunning = false;
68 mData.ProgressMessage = string.Empty;
69
70 mRequestedRepaint = true;
71 }
72
73 void IProgressControls.ShowProgress(string message)
74 {
75 HideNotification();
76
77 mData.IsOperationRunning = true;
78 mData.ProgressMessage = message;
79
80 mRequestedRepaint = true;
81 }
82
83 void IProgressControls.ShowError(string message)
84 {
85 mData.NotificationMessage = message;
86 mData.NotificationType = MessageType.Error;
87
88 mRequestedRepaint = true;
89 }
90
91 void IProgressControls.ShowNotification(string message)
92 {
93 mData.NotificationMessage = message;
94 mData.NotificationType = MessageType.Info;
95
96 mRequestedRepaint = true;
97 }
98
99 void IProgressControls.ShowSuccess(string message)
100 {
101 mData.NotificationMessage = message;
102 mData.NotificationType = MessageType.Info;
103
104 mRequestedRepaint = true;
105 }
106
107 void IProgressControls.ShowWarning(string message)
108 {
109 mData.NotificationMessage = message;
110 mData.NotificationType = MessageType.Warning;
111
112 mRequestedRepaint = true;
113 }
114
115 void HideNotification()
116 {
117 mData.NotificationMessage = string.Empty;
118 mData.NotificationType = MessageType.None;
119
120 mRequestedRepaint = true;
121 }
122
123 void UpdateIndeterminateProgress()
124 {
125 // NOTE(rafa): there is no support for indeterminate progress bar
126 // i use this neverending progress bar as workaround
127
128 mData.ProgressPercent += .003f;
129
130 if (mData.ProgressPercent > 1f)
131 mData.ProgressPercent = .1f;
132 }
133
134 Data mData = new Data();
135
136 bool mRequestedRepaint;
137 }
138}