summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Menu/ConfirmationWindow.cs
blob: 896c432bf9aa9ea481626ea723475d0d96d27454 (plain)
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
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>

using UnityEditor;
using UnityEngine;

namespace AmplifyShaderEditor
{
	public class ConfirmationWindow
	{
		public delegate ShaderLoadResult OnConfirmationSelected( bool value, Shader shader, Material material );
		public event OnConfirmationSelected OnConfirmationSelectedEvt;

		private const string m_yesStr = "Yes";
		private const string m_noStr = "No";
		private bool m_isActive = false;
		private string m_currentMessage;

		private GUIStyle m_areaStyle;
		private GUIContent m_content;
		private GUIStyle m_buttonStyle;
		private GUIStyle m_labelStyle;


		private Shader m_shader;
		private Material m_material;
		private Rect m_area;
		private bool m_autoDeactivate = true;


		public ConfirmationWindow( float x, float y, float width, float height )
		{
			m_content = new GUIContent( GUIContent.none );
			m_area = new Rect( x, y, width, height );
		}

		public void Destroy()
		{
			m_shader = null;
			OnConfirmationSelectedEvt = null;
		}

		public void ActivateConfirmation( Shader shader, Material material, string message, OnConfirmationSelected evt, bool autoDeactivate = true )
		{
			OnConfirmationSelectedEvt = evt;
			m_currentMessage = message;
			m_shader = shader;
			m_material = material;
			m_autoDeactivate = autoDeactivate;
			m_isActive = true;
		}

		public void OnGUI()
		{
			if ( m_areaStyle == null )
			{
				m_areaStyle = new GUIStyle( UIUtils.TextArea );
				m_areaStyle.stretchHeight = true;
				m_areaStyle.stretchWidth = true;
				m_areaStyle.fontSize = ( int ) Constants.DefaultTitleFontSize;
			}

			if ( m_buttonStyle == null )
			{
				m_buttonStyle = UIUtils.Button;
			}

			if ( m_labelStyle == null )
			{
				m_labelStyle = new GUIStyle( UIUtils.Label );
				m_labelStyle.alignment = TextAnchor.MiddleCenter;
				m_labelStyle.wordWrap = true;
			}

			m_area.x = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.width );
			m_area.y = ( int ) ( 0.5f * UIUtils.CurrentWindow.CameraInfo.height );

			GUILayout.BeginArea( m_area, m_content, m_areaStyle );
			{
				EditorGUILayout.BeginVertical();
				{
					EditorGUILayout.Separator();
					EditorGUILayout.LabelField( m_currentMessage, m_labelStyle );

					EditorGUILayout.Separator();
					EditorGUILayout.Separator();
					EditorGUILayout.BeginHorizontal();
					{
						if ( GUILayout.Button( m_yesStr, m_buttonStyle ) )
						{
							if ( OnConfirmationSelectedEvt != null )
								OnConfirmationSelectedEvt( true, m_shader, m_material );

							if ( m_autoDeactivate )
								Deactivate();
						}

						if ( GUILayout.Button( m_noStr, m_buttonStyle ) )
						{
							if ( OnConfirmationSelectedEvt != null )
								OnConfirmationSelectedEvt( false, m_shader, m_material );
							if ( m_autoDeactivate )
								Deactivate();
						}
					}
					EditorGUILayout.EndHorizontal();
				}
				EditorGUILayout.EndVertical();
			}
			GUILayout.EndArea();
		}

		public void Deactivate()
		{
			m_isActive = false;
			OnConfirmationSelectedEvt = null;
		}
		public bool IsActive { get { return m_isActive; } }
	}
}