Skip to content

Commit d142182

Browse files
committed
again tweak the ModalInputPopup
1 parent 8f2d885 commit d142182

File tree

1 file changed

+12
-54
lines changed

1 file changed

+12
-54
lines changed

Editor/UIElements/ModalInputPopup.cs

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
namespace EditorUI {
77
public class ModalInputPopup : EditorWindow {
8-
ModalInputPopup window;
9-
108
//Visual Elements
119
TextField keyInput;
1210
Button okButton;
@@ -21,47 +19,9 @@ public class ModalInputPopup : EditorWindow {
2119
string description;
2220
string okText;
2321
string cancelText;
24-
string defaultValue = string.Empty;
22+
string defaultValue;
2523
Func<string, bool> inputCheck;
2624

27-
public string Header {
28-
set {
29-
window.titleContent.text = value;
30-
}
31-
}
32-
public string Description {
33-
set {
34-
description = value;
35-
}
36-
}
37-
public string OkText {
38-
set {
39-
okText = value;
40-
}
41-
}
42-
public string CancelText {
43-
set {
44-
cancelText = value;
45-
}
46-
}
47-
public string DefaultValue {
48-
set {
49-
defaultValue = value;
50-
}
51-
}
52-
public Func<string, bool> InputCheck {
53-
set {
54-
inputCheck = value;
55-
}
56-
}
57-
public Vector2 WindowSize {
58-
set {
59-
window.minSize = value;
60-
window.maxSize = value;
61-
window.position = new Rect(EditorGUIUtility.GetMainWindowPosition().center - windowSize / 2, window.minSize);
62-
}
63-
}
64-
6525
/// <summary>
6626
/// Create an Modal Input Popup
6727
/// </summary>
@@ -70,25 +30,23 @@ public Vector2 WindowSize {
7030
/// <param name="okText">Text for the Ok Button</param>
7131
/// <param name="cancelText">Text for the Cancel Button</param>
7232
/// <param name="inputCheck">Function that should called on input change to check the typed string with</param>
73-
public ModalInputPopup(string header, string description, string okText = "Ok", string cancelText = "Cancel", Func<string, bool> inputCheck = null) {
74-
window = CreateInstance<ModalInputPopup>();
33+
public static Result ShowModalPopup(string header, string description, string okText = "Ok", string cancelText = "Cancel", string defaultValue = "", Func<string, bool> inputCheck = null, Vector2? windowSize = null) {
34+
ModalInputPopup window = CreateInstance<ModalInputPopup>();
7535
window.description = description;
7636
window.okText = okText;
7737
window.cancelText = cancelText;
7838
window.inputCheck = inputCheck;
79-
window.maxSize = windowSize;
80-
window.minSize = windowSize;
39+
window.defaultValue = defaultValue;
40+
if (windowSize != null) {
41+
window.windowSize = windowSize.Value;
42+
}
43+
window.maxSize = window.windowSize;
44+
window.minSize = window.windowSize;
8145
window.titleContent = new GUIContent(header);
82-
window.position = new Rect(EditorGUIUtility.GetMainWindowPosition().center - windowSize / 2, windowSize);
83-
}
46+
window.position = new Rect(EditorGUIUtility.GetMainWindowPosition().center - window.windowSize / 2, window.windowSize);
47+
window.ShowModalUtility();
8448

85-
/// <summary>
86-
/// Opens the Popup and returns the Result
87-
/// </summary>
88-
/// <returns></returns>
89-
public Result ShowModalPopup() {
90-
ShowModalUtility();
91-
return result;
49+
return window.result;
9250
}
9351

9452
void CreateGUI() {

0 commit comments

Comments
 (0)