Skip to content

Commit 1b491b8

Browse files
author
Stewart Miles
committed
Prep for a custom more flexible dialog box.
Change-Id: Ic8218444fafbc1c1e2c9ebc38caff95be64565c6
1 parent 8fa3d93 commit 1b491b8

File tree

8 files changed

+541
-328
lines changed

8 files changed

+541
-328
lines changed

source/AndroidResolver/src/AndroidSdkManager.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ public void InstallPackages(HashSet<AndroidSdkPackageNameVersion> packages,
937937
var packagesString = AndroidSdkPackageNameVersion.ListToString(packages);
938938
// TODO: Remove this dialog when the package manager provides feedback while
939939
// downloading.
940-
var installPackage = Dialog.Display(
940+
Dialog.Display(
941941
"Missing Android SDK packages",
942942
String.Format(
943943
"Android SDK packages need to be installed:\n" +
@@ -947,19 +947,22 @@ public void InstallPackages(HashSet<AndroidSdkPackageNameVersion> packages,
947947
"which may lead you to think Unity has hung / crashed. Would you like " +
948948
"to wait for these package to be installed?",
949949
packagesString),
950-
Dialog.Option.Selected0, "Yes", "No");
951-
if (installPackage == Dialog.Option.Selected0) {
952-
PlayServicesResolver.Log(
953-
"User cancelled installation of Android SDK tools package.",
954-
level: LogLevel.Warning);
955-
complete(false);
956-
return;
957-
}
958-
var packageNames = new List<string>();
959-
foreach (var pkg in packages) packageNames.Add(pkg.Name);
960-
SdkManagerUtil.InstallPackages(toolPath, String.Join(" ", packageNames.ToArray()),
961-
packages, "Accept? (y/N):", "y", "N",
962-
new Regex("^License\\W+[^ ]+:"), complete);
950+
Dialog.Option.Selected0, "Yes", "No",
951+
(selectedOption) => {
952+
if (selectedOption == Dialog.Option.Selected0) {
953+
PlayServicesResolver.Log(
954+
"User cancelled installation of Android SDK tools package.",
955+
level: LogLevel.Warning);
956+
complete(false);
957+
return;
958+
}
959+
var packageNames = new List<string>();
960+
foreach (var pkg in packages) packageNames.Add(pkg.Name);
961+
SdkManagerUtil.InstallPackages(toolPath,
962+
String.Join(" ", packageNames.ToArray()),
963+
packages, "Accept? (y/N):", "y", "N",
964+
new Regex("^License\\W+[^ ]+:"), complete);
965+
});
963966
}
964967
}
965968

source/AndroidResolver/src/GradleResolver.cs

Lines changed: 138 additions & 95 deletions
Large diffs are not rendered by default.

source/AndroidResolver/src/PlayServicesResolver.cs

Lines changed: 192 additions & 75 deletions
Large diffs are not rendered by default.

source/IOSResolver/src/IOSResolver.cs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -700,23 +700,26 @@ exception is TypeInitializationException ||
700700
CocoapodsIntegrationUpgradeDefault) == CocoapodsIntegrationMethod.None &&
701701
!ExecutionEnvironment.InBatchMode && !UpgradeToWorkspaceWarningDisabled) {
702702

703-
switch (Dialog.Display(
703+
Dialog.Display(
704704
"Warning: CocoaPods integration is disabled!",
705705
"Would you like to enable CocoaPods integration with workspaces?\n\n" +
706706
"Unity 5.6+ now supports loading workspaces generated from CocoaPods.\n" +
707707
"If you enable this, and still use Unity less than 5.6, it will fallback " +
708708
"to integrating CocoaPods with the .xcodeproj file.\n",
709-
Dialog.Option.Selected0, "Yes", "Not Now", "Silence Warning")) {
710-
case Dialog.Option.Selected0: // Yes
711-
settings.SetInt(PREFERENCE_COCOAPODS_INTEGRATION_METHOD,
712-
(int)CocoapodsIntegrationMethod.Workspace);
713-
break;
714-
case Dialog.Option.Selected1: // Not now
715-
break;
716-
case Dialog.Option.Selected2: // Ignore
717-
UpgradeToWorkspaceWarningDisabled = true;
718-
break;
719-
}
709+
Dialog.Option.Selected0, "Yes", "Not Now", "Silence Warning",
710+
(selectedOption) => {
711+
switch (selectedOption) {
712+
case Dialog.Option.Selected0: // Yes
713+
settings.SetInt(PREFERENCE_COCOAPODS_INTEGRATION_METHOD,
714+
(int)CocoapodsIntegrationMethod.Workspace);
715+
break;
716+
case Dialog.Option.Selected1: // Not now
717+
break;
718+
case Dialog.Option.Selected2: // Ignore
719+
UpgradeToWorkspaceWarningDisabled = true;
720+
break;
721+
}
722+
});
720723
}
721724
}
722725

@@ -1176,41 +1179,39 @@ private static void ScheduleCheckTargetSdk() {
11761179
/// Update the target SDK if it's required.
11771180
/// </summary>
11781181
/// <param name="runningBuild">Whether the build is being processed.</param>
1179-
/// <returns>true if the SDK was updated, false otherwise.</returns>
1180-
public static bool UpdateTargetSdk(bool runningBuild) {
1182+
public static void UpdateTargetSdk(bool runningBuild) {
11811183
var minVersionAndPodNames = TargetSdkNeedsUpdate();
11821184
if (minVersionAndPodNames.Value != null) {
11831185
var minVersionString =
11841186
TargetSdkVersionToString(minVersionAndPodNames.Key);
1185-
var update = Dialog.Display(
1187+
Dialog.Display(
11861188
"Unsupported Target SDK",
1187-
"Target SDK selected in the iOS Player Settings (" +
1188-
TargetSdk + ") is not supported by the Cocoapods " +
1189-
"included in this project. " +
1190-
"The build will very likely fail. The minimum supported " +
1191-
"version is \"" + minVersionString + "\" " +
1192-
"required by pods (" +
1193-
String.Join(", ", minVersionAndPodNames.Value.ToArray()) +
1194-
").\n" +
1195-
"Would you like to update the target SDK version?",
1196-
Dialog.Option.Selected1 /* No */, "Yes", "No");
1197-
analytics.Report("updatetargetsdk/" +
1198-
(update == Dialog.Option.Selected0 ? "apply" : "cancel"),
1199-
"Update Target SDK");
1200-
if (update == Dialog.Option.Selected0) {
1201-
TargetSdkVersion = minVersionAndPodNames.Key;
1202-
if (runningBuild) {
1203-
string errorString = (
1204-
"Target SDK has been updated from " + TargetSdk +
1205-
" to " + minVersionString + ". You must restart the " +
1206-
"build for this change to take effect.");
1207-
Dialog.Display("Target SDK updated.", errorString, Dialog.Option.Selected0,
1208-
"OK");
1209-
}
1210-
return true;
1211-
}
1189+
String.Format(
1190+
"Target SDK selected in the iOS Player Settings ({0}) is not supported by " +
1191+
"the Cocoapods included in this project. The build will very likely fail. " +
1192+
"The minimum supported version is \"{1}\" required by pods ({2})\n" +
1193+
"Would you like to update the target SDK version?",
1194+
TargetSdk, minVersionString,
1195+
String.Join(", ", minVersionAndPodNames.Value.ToArray())),
1196+
Dialog.Option.Selected1 /* No */, "Yes", "No",
1197+
(selectedOption) => {
1198+
analytics.Report(
1199+
"updatetargetsdk/" +
1200+
(selectedOption == Dialog.Option.Selected0 ? "apply" : "cancel"),
1201+
"Update Target SDK");
1202+
if (selectedOption == Dialog.Option.Selected0) {
1203+
TargetSdkVersion = minVersionAndPodNames.Key;
1204+
if (runningBuild) {
1205+
string errorString = String.Format(
1206+
"Target SDK has been updated from {0} to {1}. " +
1207+
"You must restart the build for this change to take effect.",
1208+
TargetSdk, minVersionString);
1209+
Dialog.Display("Target SDK updated.", errorString,
1210+
Dialog.Option.Selected0, "OK");
1211+
}
1212+
}
1213+
});
12121214
}
1213-
return false;
12141215
}
12151216

12161217
/// <summary>
@@ -2262,7 +2263,7 @@ private static CommandLine.Result RunPodCommand(
22622263
public static void OnPostProcessInstallPods(BuildTarget buildTarget,
22632264
string pathToBuiltProject) {
22642265
if (!InjectDependencies() || !PodfileGenerationEnabled) return;
2265-
if (UpdateTargetSdk(true)) return;
2266+
UpdateTargetSdk(true);
22662267
if (!CocoapodsIntegrationEnabled || !cocoapodsToolsInstallPresent) {
22672268
Log(String.Format(
22682269
"Cocoapod installation is disabled.\n" +

source/VersionHandlerImpl/src/Dialog.cs

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,15 @@ public enum Option {
6161
/// <param name="option0">Text for the first option.</param>
6262
/// <param name="option1">Text for the second option or null to disable.</param>
6363
/// <param name="option2">Text for the third option or null to disable.</param>
64-
/// <returns>The selected option.</returns>
65-
public delegate Option DisplayDelegate(string title, string message, Option defaultOption,
66-
string option0, string option1, string option2);
64+
/// <param name="complete">Called with the selected option when
65+
/// ExecutionEnvironment.InteractiveMode, otherwise receives the defaultOption.</param>
66+
/// <param name="renderContent">Specify to optionally render content in the dialog.</param>
67+
/// <param name="renderButtons">Specify to optionally render buttons in the dialog.</param>
68+
public delegate void DisplayDelegate(string title, string message, Option defaultOption,
69+
string option0, string option1, string option2,
70+
Action<Option> complete,
71+
Action<UnityEditor.EditorWindow> renderContent,
72+
Action<UnityEditor.EditorWindow> renderButtons);
6773

6874
/// <summary>
6975
/// Delegate that displays a dialog requesting consent to report analytics.
@@ -80,25 +86,32 @@ public delegate Option DisplayDelegate(string title, string message, Option defa
8086
/// <param name="option1">Text for the second option.</param>
8187
/// <param name="option2">Text for the third option.</param>
8288
/// <param name="defaultOption">Option selected if interactivity is disabled.</param>
83-
/// <returns>When ExecutionEnvironment.InteractiveMode, the selected option, the
84-
/// defaultOption otherwise.</returns>
85-
internal static Option DisplayDefault(string title, string message, Option defaultOption,
86-
string option0, string option1, string option2) {
89+
/// <param name="complete">Called with the selected option when
90+
/// ExecutionEnvironment.InteractiveMode, otherwise receives the defaultOption.</param>
91+
/// <param name="renderContent">Specify to optionally render content in the dialog.</param>
92+
/// <param name="renderButtons">Specify to optionally render buttons in the dialog.</param>
93+
internal static void DisplayDefault(string title, string message, Option defaultOption,
94+
string option0, string option1, string option2,
95+
Action<Option> complete,
96+
Action<UnityEditor.EditorWindow> renderContent,
97+
Action<UnityEditor.EditorWindow> renderButtons) {
98+
if (complete == null) complete = (unusedOption) => {};
8799
if (ExecutionEnvironment.InteractiveMode) {
88100
if (String.IsNullOrEmpty(option1)) {
89-
UnityEditor.EditorUtility.DisplayDialog(title, message, option0, cancel: "");
90-
return Option.Selected0;
101+
if (UnityEditor.EditorUtility.DisplayDialog(title, message, option0, cancel: "")) {
102+
complete(Option.Selected0);
103+
}
91104
} else if (String.IsNullOrEmpty(option2)) {
92-
return UnityEditor.EditorUtility.DisplayDialog(title, message, option0,
93-
cancel: option1) ?
94-
Option.Selected0 : Option.Selected1;
105+
complete(UnityEditor.EditorUtility.DisplayDialog(title, message, option0,
106+
cancel: option1) ?
107+
Option.Selected0 : Option.Selected1);
95108
} else {
96-
return (Option)UnityEditor.EditorUtility.DisplayDialogComplex(title, message,
97-
option0, option1,
98-
option2);
109+
complete((Option)UnityEditor.EditorUtility.DisplayDialogComplex(title, message,
110+
option0, option1,
111+
option2));
99112
}
100113
}
101-
return defaultOption;
114+
complete(defaultOption);
102115
}
103116

104117
/// <summary>
@@ -110,11 +123,17 @@ internal static Option DisplayDefault(string title, string message, Option defau
110123
/// <param name="option0">Text for the first option.</param>
111124
/// <param name="option1">Text for the second option.</param>
112125
/// <param name="option2">Text for the third option.</param>
113-
/// <returns>When ExecutionEnvironment.InteractiveMode, the selected option, the defaultOption
114-
/// otherwise.</returns>
115-
public static Option Display(string title, string message, Option defaultOption,
116-
string option0, string option1, string option2) {
117-
return displayDialogMethod(title, message, defaultOption, option0, option1, option2);
126+
/// <param name="complete">Called with the selected option when
127+
/// ExecutionEnvironment.InteractiveMode, otherwise receives the defaultOption.</param>
128+
/// <param name="renderContent">Specify to optionally render content in the dialog.</param>
129+
/// <param name="renderButtons">Specify to optionally render buttons in the dialog.</param>
130+
public static void Display(string title, string message, Option defaultOption,
131+
string option0, string option1, string option2,
132+
Action<Option> complete,
133+
Action<UnityEditor.EditorWindow> renderContent = null,
134+
Action<UnityEditor.EditorWindow> renderButtons = null) {
135+
displayDialogMethod(title, message, defaultOption, option0, option1, option2, complete,
136+
renderContent, renderButtons);
118137
}
119138

120139
/// <summary>
@@ -125,11 +144,16 @@ public static Option Display(string title, string message, Option defaultOption,
125144
/// <param name="defaultOption">Option selected if interactivity is disabled.</param>
126145
/// <param name="option0">Text for the first option.</param>
127146
/// <param name="option1">Text for the second option.</param>
128-
/// <returns>When ExecutionEnvironment.InteractiveMode, the selected option, the defaultOption
129-
/// otherwise.</returns>
130-
public static Option Display(string title, string message, Option defaultOption,
131-
string option0, string option1) {
132-
return displayDialogMethod(title, message, defaultOption, option0, option1, null);
147+
/// <param name="complete">Called with the selected option when
148+
/// ExecutionEnvironment.InteractiveMode, otherwise receives the defaultOption.</param>
149+
/// <param name="renderContent">Specify to optionally render content in the dialog.</param>
150+
/// <param name="renderButtons">Specify to optionally render buttons in the dialog.</param>
151+
public static void Display(string title, string message, Option defaultOption,
152+
string option0, string option1, Action<Option> complete,
153+
Action<UnityEditor.EditorWindow> renderContent = null,
154+
Action<UnityEditor.EditorWindow> renderButtons = null) {
155+
displayDialogMethod(title, message, defaultOption, option0, option1, null, complete,
156+
renderContent, renderButtons);
133157
}
134158

135159
/// <summary>
@@ -140,11 +164,16 @@ public static Option Display(string title, string message, Option defaultOption,
140164
/// <param name="defaultOption">Option selected if interactivity is disabled.</param>
141165
/// <param name="option0">Text for the first option.</param>
142166
/// <param name="option1">Text for the second option.</param>
143-
/// <returns>When ExecutionEnvironment.InteractiveMode, the selected option, the defaultOption
144-
/// otherwise.</returns>
145-
public static Option Display(string title, string message, Option defaultOption,
146-
string option0) {
147-
return displayDialogMethod(title, message, defaultOption, option0, null, null);
167+
/// <param name="complete">Called with the selected option when
168+
/// ExecutionEnvironment.InteractiveMode, otherwise receives the defaultOption.</param>
169+
/// <param name="renderContent">Specify to optionally render content in the dialog.</param>
170+
/// <param name="renderButtons">Specify to optionally render buttons in the dialog.</param>
171+
public static void Display(string title, string message, Option defaultOption,
172+
string option0, Action<Option> complete = null,
173+
Action<UnityEditor.EditorWindow> renderContent = null,
174+
Action<UnityEditor.EditorWindow> renderButtons = null) {
175+
displayDialogMethod(title, message, defaultOption, option0, null, null, complete,
176+
renderContent, renderButtons);
148177
}
149178
}
150179

0 commit comments

Comments
 (0)