protected override AlertResult ShowInternal(IComponent owner, string text, string caption, AlertButtons alertButtons, AlertLevel alertLevel, AlertDefaultButton defaultButton, bool showInTaskbar) { Trace.TraceInformation("~~~ {0}", text); MessageBoxButtons type = GetButtonsForButtons(alertButtons); MessageBoxIcon icon = GetIconForAlertLevel(alertLevel); MessageBoxDefaultButton defaultBtn = GetDefaultButtonForDefaultButton(defaultButton); DialogResult result = DialogResult.Cancel; ProgressUtils.InvokeOnUIThread(() => result = MessageBox.Show((IWin32Window)owner, text, caption, type, icon, defaultBtn, showInTaskbar ? MessageBoxOptions.DefaultDesktopOnly : 0)); switch (result) { case DialogResult.OK: case DialogResult.Yes: case DialogResult.Retry: return(AlertResult.Positive); case DialogResult.No: case DialogResult.Abort: return(AlertResult.Negative); default: // DialogResult.Cancel return(AlertResult.Cancel); } }
public static void SyncProgress(float fProgress, bool bSendToServer) { if (updateProgress != null) { float fPercent = ProgressUtils.GetCurrentProgress(fProgress); updateProgress(fPercent, bSendToServer); //Debug.Log("<color=yellow>SyncProgress: " + fPercent + "</color>"); } }
public LuaArgs getCompletedLevelCount(LuaArgs args) { var campaign = GetCampaign(); if (campaign != null) { return(new LuaArgs(ProgressUtils.CountLevelsCompleted(campaign, GetMod(), m_state.Game.User, GetIgnoreLevel()))); } return(new LuaArgs(false)); }
public LuaArgs isLevelUnlocked(LuaArgs args) { var num = args.GetInt(0); var campaign = GetCampaign(); if (campaign != null) { return(new LuaArgs(ProgressUtils.IsLevelUnlocked(campaign, GetMod(), num, m_state.Game.User, GetIgnoreLevel()))); } return(new LuaArgs(false)); }
public LuaArgs getRobotCount(LuaArgs args) { var campaign = GetCampaign(); if (campaign != null) { int total; int rescued = ProgressUtils.CountRobotsRescued(campaign, GetMod(), m_state.Game.User, out total, GetIgnoreLevel()); return(new LuaArgs(total, rescued)); } return(new LuaArgs(0, 0)); }
private static void GenerateCodeAndAssets() { if (!GenerateCodeAndAssetsCheck()) { return; } var generateCoroutine = CoroutineScheduler.Schedule ( GenerateCodeAndAssetsAsync( progressCallback: ProgressUtils.ShowProgressBar(Resources.UI_UNITYPLUGIN_GENERATING_CODE_AND_ASSETS)) ); generateCoroutine.ContinueWith(ProgressUtils.HideProgressBar); FocusConsoleWindow(); }
private static void ValidateAll() { if (!ValidateAllCheck()) { return; } var validateCoroutine = CoroutineScheduler.Schedule <Dictionary <string, object> >( ValidateAsync( progressCallback: ProgressUtils.ShowProgressBar(Resources.UI_UNITYPLUGIN_VALIDATING_ASSETS) ) ); validateCoroutine.ContinueWith(ProgressUtils.HideProgressBar); FocusConsoleWindow(); }
public SoundcloudSyncMainForm() { InitializeComponent(); updateUtil = new UpdateUtils(); updateToolStripMenuItem.Text = updateUtil.LabelTextForCurrentStatus(); clientIdUtil = new ClientIDsUtils(); _apiConfigSettings = new API_Config(clientIdUtil); progressUtil = new ProgressUtils(); Text = $"SoundCloud Playlist Sync {Version()} Stable"; _performSyncCompleteImplementation = SyncCompleteButton; _progressBarUpdateImplementation = UpdateProgressBar; _performStatusUpdateImplementation = UpdateStatus; status.Text = @"Ready"; MinimumSize = new Size(Width, Height); MaximumSize = new Size(Width, Height); }
public SoundcloudSyncMainForm() { InitializeComponent(); updateUtil = new UpdateUtils(); updateToolStripMenuItem.Text = LanguageManager.Language["STR_MAIN_MENU_UPDATE"] + updateUtil.LabelTextForCurrentStatus(); clientIdUtil = new ClientIDsUtils(); _apiConfigSettings = new API_Config(clientIdUtil); progressUtil = new ProgressUtils(); Text = string.Format(LanguageManager.Language["STR_MAIN_TITLE_STABLE"], Version()); _performSyncCompleteImplementation = SyncCompleteButton; _progressBarUpdateImplementation = UpdateProgressBar; _performStatusUpdateImplementation = UpdateStatus; status.Tag = "STR_MAIN_STATUS_READY"; status.Text = LanguageManager.Language[status.Tag.ToString()]; MinimumSize = new Size(Width, Height); MaximumSize = new Size(Width, Height); }
public SoundcloudSyncMainForm() { InitializeComponent(); updateUtil = new UpdateUtils(); clientIdUtil = new ClientIDsUtils(); _apiConfigSettings = new API_Config(clientIdUtil); progressUtil = new ProgressUtils(); LoadLanguagesInAllForms(int.Parse(SyncSetting.settings.Get("Language"))); Text = string.Format(LanguageManager.Language["STR_MAIN_TITLE_STABLE"], UpdateUtils.GetCurrentVersion()); _performSyncCompleteImplementation = SyncCompleteButton; _progressBarUpdateImplementation = UpdateProgressBar; _performStatusUpdateImplementation = UpdateStatus; status.Tag = "STR_MAIN_STATUS_READY"; status.Text = LanguageManager.Language[status.Tag.ToString()]; MinimumSize = new Size(Width, Height); MaximumSize = new Size(Width, Height); }
/// <summary> /// If Browser control dosesn't have X11 input focus. /// then Ensure that it does.. /// </summary> protected void EnsureFocusedGeckoControlHasInputFocus() { if ((_browser == null) || (_browser.HasInputFocus())) { return; } // Attempt ot do it right away. this._browser.SetInputFocus(); // Othewise do it on the first idle event. Action setInputFocus = null; setInputFocus = () => { ProgressUtils.InvokeLaterOnIdle(() => { if (_browser == null) { return; } if (Form.ActiveForm == null || _browser.ContainsFocus == false) { MoveInputFocusBacktoAWinFormsControl(); return; } if (!_browser.HasInputFocus()) { this._browser.SetInputFocus(); } if (!_browser.HasInputFocus()) { setInputFocus(); } }, null); }; setInputFocus(); }
protected override void OnLeave(EventArgs e) { if ((_browser != null) && (_browser.WebBrowserFocus != null)) { _browser.WebBrowserFocus.Deactivate(); } _entered = false; base.OnLeave(e); #if __MonoCS__ Action EnsureXInputFocusIsRemovedFromReceivedWinFormsControl = () => { var control = Control.FromHandle(NativeReplacements.MonoGetFocus()); if (control is GeckoWebBrowser) { return; } MoveInputFocusBacktoAWinFormsControl(); // Setting the ActiveControl ensure a Focus event occurs on the control focus is moving to. // And this allows us to call RemoveinputFocus at the neccessary time. // This prevents keypress still going to the gecko controls when a winform TextBox has focus // and the mouse is over a gecko control. Form.ActiveForm.ActiveControl = control; EventHandler focusEvent = null; // Attach a execute once only focus handler to the Non GeckoWebBrowser control focus is moving too... focusEvent = (object sender, EventArgs eventArg) => { control.GotFocus -= focusEvent; MoveInputFocusBacktoAWinFormsControl(); }; control.GotFocus += focusEvent; }; ProgressUtils.InvokeLaterOnUIThread(() => EnsureXInputFocusIsRemovedFromReceivedWinFormsControl()); #endif }
private static void Update() { if (Settings.Current == null) { return; } if (LastWatchedGameDataTrackerVersion != GameDataTracker.Version) { var gameDataPaths = new HashSet <string>(GameDataTracker.All); foreach (var gameDataPath in gameDataPaths) { if (Watchers.ContainsKey(gameDataPath) || File.Exists(gameDataPath) == false) { continue; } try { var fullPath = Path.GetFullPath(gameDataPath); var directoryName = Path.GetDirectoryName(fullPath); var watcher = new FileSystemWatcher(directoryName) { NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size }; watcher.Filter = Path.GetFileName(fullPath); watcher.Changed += GameDataChanged; Watchers.Add(gameDataPath, watcher); try { GameDataHashByPath[gameDataPath] = FileAndPathUtils.ComputeHash(gameDataPath); } catch { // ignored } watcher.EnableRaisingEvents = true; } catch (Exception e) { Debug.LogError("Failed to create FileSystemWatcher for GameData " + gameDataPath + ": " + e); } } foreach (var gameDataPath in Watchers.Keys.ToArray()) { if (gameDataPaths.Contains(gameDataPath)) { continue; } var watcher = Watchers[gameDataPath]; Watchers.Remove(gameDataPath); try { watcher.Dispose(); } catch (Exception e) { Debug.LogError("Failed to dispose FileSystemWatcher of GameData: " + e); } } LastWatchedGameDataTrackerVersion = GameDataTracker.Version; } var changedAssetsCopy = default(string[]); lock (ChangedAssetPaths) { if (ChangedAssetPaths.Count > 0) { changedAssetsCopy = ChangedAssetPaths.ToArray(); ChangedAssetPaths.Clear(); } } if (changedAssetsCopy != null) { foreach (var changedAsset in changedAssetsCopy) { if (Settings.Current.Verbose) { Debug.Log("Changed Asset: " + changedAsset); } if (!File.Exists(changedAsset) || GameDataTracker.IsTracked(changedAsset) == false) { continue; } var gameDataSettings = GameDataSettings.Load(changedAsset); if (!gameDataSettings.AutoGeneration) { continue; } var assetHash = default(string); try { assetHash = FileAndPathUtils.ComputeHash(changedAsset); } catch (Exception e) { Debug.LogWarning("Failed to compute hash of " + changedAsset + ": " + e); continue; } var oldAssetHash = default(string); if (GameDataHashByPath.TryGetValue(changedAsset, out oldAssetHash) && assetHash == oldAssetHash) { continue; // not changed } if (EditorApplication.isUpdating) { continue; } if (Settings.Current.Verbose) { Debug.Log("Asset's " + changedAsset + " hash has changed from " + (oldAssetHash ?? "<none>") + " to " + assetHash); } GameDataHashByPath[changedAsset] = assetHash; CoroutineScheduler.Schedule ( Menu.GenerateCodeAndAssetsAsync( path: changedAsset, progressCallback: ProgressUtils.ReportToLog("Generation(Auto): ")), "generation::" + changedAsset ); } } }
private static IEnumerable LoadEditor(string gameDataPath, string reference, Promise waitTask) { // un-select gamedata file in Project window if (Selection.activeObject != null && AssetDatabase.GetAssetPath(Selection.activeObject) == gameDataPath) { Selection.activeObject = null; } if (waitTask != null) { yield return(waitTask.IgnoreFault()); } var title = Path.GetFileName(gameDataPath); if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_CHECKING_RUNTIME, 0.05f)) { throw new InvalidOperationException("Interrupted by user."); } var checkRequirements = CharonCli.CheckRequirementsAsync(); yield return(checkRequirements); switch (checkRequirements.GetResult()) { case RequirementsCheckResult.MissingRuntime: yield return(UpdateRuntimeWindow.ShowAsync()); break; case RequirementsCheckResult.WrongVersion: case RequirementsCheckResult.MissingExecutable: yield return(CharonCli.DownloadCharon(ProgressUtils.ShowCancellableProgressBar(Resources.UI_UNITYPLUGIN_MENU_CHECK_UPDATES, 0.05f, 0.50f))); break; case RequirementsCheckResult.Ok: break; default: throw new InvalidOperationException("Unknown requirements check result."); } var port = Settings.Current.EditorPort; var gameDataEditorUrl = "http://localhost:" + port + "/"; var lockFilePath = CharonCli.GetDefaultLockFilePath(); CharonCli.FindAndEndGracefully(lockFilePath); if (Settings.Current.Verbose) { Debug.Log("Starting gamedata editor at " + gameDataEditorUrl + "..."); } if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.50f)) { throw new InvalidOperationException("Interrupted by user."); } if (EditorApplication.isCompiling) { throw new InvalidOperationException("Interrupted by Unity's script compilation. Retry after Unity is finished script compilation."); } var charonRunTask = CharonCli.Listen(gameDataPath, lockFilePath, port, shadowCopy: true, progressCallback: ProgressUtils.ShowCancellableProgressBar(title, 0.50f, 0.60f)); if (Settings.Current.Verbose) { Debug.Log("Launching gamedata editor process."); } // wait untill server process start var timeoutPromise = Promise.Delayed(TimeSpan.FromSeconds(10)); var startPromise = (Promise)charonRunTask.IgnoreFault(); var startCompletePromise = Promise.WhenAny(timeoutPromise, startPromise); var cancelPromise = new Coroutine <bool>(RunCancellableProgress(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.65f, 0.80f, TimeSpan.FromSeconds(5), startCompletePromise)); yield return(Promise.WhenAny(timeoutPromise, startPromise, cancelPromise)); if (timeoutPromise.IsCompleted) { EditorUtility.ClearProgressBar(); Debug.LogWarning(Resources.UI_UNITYPLUGIN_WINDOW_FAILED_TO_START_EDITOR_TIMEOUT); yield break; } else if (cancelPromise.IsCompleted) { EditorUtility.ClearProgressBar(); if (EditorApplication.isCompiling) { throw new InvalidOperationException("Interrupted by Unity's script compilation. Retry after Unity is finished script compilation."); } else { throw new InvalidOperationException("Interrupted by user."); } } else if (charonRunTask.HasErrors) { throw new InvalidOperationException("Failed to start editor.", charonRunTask.Error.Unwrap()); } if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.80f)) { throw new InvalidOperationException("Interrupted by user."); } if (EditorApplication.isCompiling) { throw new InvalidOperationException("Interrupted by Unity's script compilation. Retry after Unity is finished script compilation."); } // wait untill server start to respond var downloadStream = new MemoryStream(); timeoutPromise = Promise.Delayed(TimeSpan.FromSeconds(10)); startPromise = HttpUtils.DownloadTo(downloadStream, new Uri(gameDataEditorUrl), timeout: TimeSpan.FromSeconds(1)); startCompletePromise = new Promise(); cancelPromise = new Coroutine <bool>(RunCancellableProgress(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.80f, 0.90f, TimeSpan.FromSeconds(5), startCompletePromise)); while (!timeoutPromise.IsCompleted) { yield return(startPromise.IgnoreFault()); if (startPromise.HasErrors == false && downloadStream.Length > 0) { break; } if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.93f)) { throw new InvalidOperationException("Interrupted by user."); } if (EditorApplication.isCompiling) { throw new InvalidOperationException("Interrupted by Unity's script compilation. Retry after Unity is finished script compilation."); } downloadStream.SetLength(0); startPromise = HttpUtils.DownloadTo(downloadStream, new Uri(gameDataEditorUrl), timeout: TimeSpan.FromSeconds(1)); } if (timeoutPromise.IsCompleted && (!startPromise.IsCompleted || startPromise.HasErrors)) { EditorUtility.ClearProgressBar(); startCompletePromise.TrySetCompleted(); Debug.LogWarning(Resources.UI_UNITYPLUGIN_WINDOW_FAILED_TO_START_EDITOR_TIMEOUT); yield break; } startCompletePromise.TrySetCompleted(); if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_OPENING_BROWSER, 0.95f)) { throw new InvalidOperationException("Interrupted by user."); } if (EditorApplication.isCompiling) { throw new InvalidOperationException("Interrupted by Unity's script compilation. Retry after Unity is finished script compilation."); } var nearPanels = typeof(SceneView); var editorWindow = GetWindow <GameDataEditorWindow>(nearPanels); editorWindow.titleContent = new GUIContent(title); var browserType = (BrowserType)Settings.Current.Browser; if (browserType == BrowserType.UnityEmbedded && !IsWebViewAvailable) { browserType = BrowserType.SystemDefault; } switch (browserType) { case BrowserType.UnityEmbedded: editorWindow.LoadUrl(gameDataEditorUrl + reference); editorWindow.SetWebViewVisibility(true); editorWindow.Repaint(); editorWindow.Focus(); break; case BrowserType.Custom: if (string.IsNullOrEmpty(Settings.Current.BrowserPath)) { goto case BrowserType.SystemDefault; } Process.Start(Settings.Current.BrowserPath, gameDataEditorUrl + reference); editorWindow.isOffsiteBrowserLaunched = true; break; case BrowserType.SystemDefault: EditorUtility.OpenWithDefaultApp(gameDataEditorUrl + reference); editorWindow.isOffsiteBrowserLaunched = true; break; } }
protected override void ShowLaterInternal(string text, string caption, AlertLevel alertLevel) { MessageBoxIcon icon = GetIconForAlertLevel(alertLevel); ProgressUtils.InvokeLaterOnUIThread(() => MessageBox.Show(text, caption, MessageBoxButtons.OK, icon)); }
public static IEnumerable ExtractT4Templates(string extractionPath) { var checkRequirements = CharonCli.CheckRequirementsAsync(); yield return(checkRequirements); switch (checkRequirements.GetResult()) { case RequirementsCheckResult.MissingRuntime: yield return(UpdateRuntimeWindow.ShowAsync()); break; case RequirementsCheckResult.WrongVersion: case RequirementsCheckResult.MissingExecutable: yield return(CharonCli.DownloadCharon(ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_MENU_CHECK_UPDATES))); break; case RequirementsCheckResult.Ok: break; default: throw new InvalidOperationException("Unknown Tools check result."); } if (Settings.Current.Verbose) { Debug.Log(string.Format("Extracting T4 Templates to '{0}'...", extractionPath)); } var dumpProcess = CharonCli.DumpTemplatesAsync(extractionPath); yield return(dumpProcess); using (var dumpResult = dumpProcess.GetResult()) { if (string.IsNullOrEmpty(dumpResult.GetErrorData()) == false) { Debug.LogWarning(string.Format(Resources.UI_UNITYPLUGIN_T4_EXTRACTION_FAILED, dumpResult.GetErrorData())); } else { Debug.Log(Resources.UI_UNITYPLUGIN_T4_EXTRACTION_COMPLETE + "\r\n" + dumpResult.GetOutputData()); } } }
public override void OnInspectorGUI() { var gameDataAsset = (Object)this.target; var gameDataPath = FileAndPathUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(gameDataAsset)); var assetPath = FileAndPathUtils.MakeProjectRelative(AssetDatabase.GetAssetPath(Selection.activeObject)); if (GameDataTracker.IsGameDataFile(assetPath) == false) { this.DrawDefaultInspector(); return; } if (this.lastAsset != gameDataAsset || this.gameDataSettings == null) { this.gameDataSettings = GameDataSettings.Load(gameDataPath); this.gameDataSettings.ScriptingAssemblies = this.gameDataSettings.ScriptingAssemblies ?? new string[0]; this.lastAsset = gameDataAsset; this.newScriptingAssembly = null; this.newScriptingAssemblyName = null; } GUI.enabled = true; GUILayout.Label(Path.GetFileName(gameDataPath), EditorStyles.boldLabel); this.gameDataSettings.Generator = (int)(GameDataSettings.CodeGenerator)EditorGUILayout.EnumPopup(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATOR, (GameDataSettings.CodeGenerator) this.gameDataSettings.Generator); if (this.gameDataSettings.Generator != (int)GameDataSettings.CodeGenerator.None) { this.codeGenerationFold = EditorGUILayout.Foldout(this.codeGenerationFold, Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_LABEL); if (this.codeGenerationFold) { this.gameDataSettings.AutoGeneration = EditorGUILayout.Toggle(Resources.UI_UNITYPLUGIN_INSPECTOR_AUTO_GENERATION, this.gameDataSettings.AutoGeneration); var codeAsset = !string.IsNullOrEmpty(this.gameDataSettings.CodeGenerationPath) && File.Exists(this.gameDataSettings.CodeGenerationPath) ? AssetDatabase.LoadAssetAtPath <TextAsset>(this.gameDataSettings.CodeGenerationPath) : null; var assetAsset = !string.IsNullOrEmpty(this.gameDataSettings.AssetGenerationPath) && File.Exists(this.gameDataSettings.AssetGenerationPath) ? AssetDatabase.LoadAssetAtPath <ScriptableObject>(this.gameDataSettings.AssetGenerationPath) : null; if (codeAsset != null) { this.gameDataSettings.CodeGenerationPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_PATH, codeAsset, typeof(TextAsset), false)); } else { this.gameDataSettings.CodeGenerationPath = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_GENERATION_PATH, this.gameDataSettings.CodeGenerationPath); } if (this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset) { if (assetAsset != null) { this.gameDataSettings.AssetGenerationPath = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_GENERATION_PATH, assetAsset, typeof(ScriptableObject), false)); } else { this.gameDataSettings.AssetGenerationPath = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_GENERATION_PATH, this.gameDataSettings.AssetGenerationPath); } } if ((this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharp || this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset) && Path.GetExtension(this.gameDataSettings.CodeGenerationPath) != ".cs") { this.gameDataSettings.CodeGenerationPath = Path.ChangeExtension(this.gameDataSettings.CodeGenerationPath, ".cs"); } if (this.gameDataSettings.Generator == (int)GameDataSettings.CodeGenerator.CSharpCodeAndAsset && Path.GetExtension(this.gameDataSettings.AssetGenerationPath) != ".asset") { this.gameDataSettings.AssetGenerationPath = Path.ChangeExtension(this.gameDataSettings.AssetGenerationPath, ".asset"); } this.gameDataSettings.Namespace = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_NAMESPACE, this.gameDataSettings.Namespace); this.gameDataSettings.GameDataClassName = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_API_CLASS_NAME, this.gameDataSettings.GameDataClassName); this.gameDataSettings.DocumentClassName = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_DOCUMENT_CLASS_NAME, this.gameDataSettings.DocumentClassName); this.gameDataSettings.LineEnding = (int)(GameDataSettings.LineEndings)EditorGUILayout.EnumPopup( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_LINE_ENDINGS, (GameDataSettings.LineEndings) this.gameDataSettings.LineEnding); this.gameDataSettings.Indentation = (int)(GameDataSettings.Indentations)EditorGUILayout.EnumPopup( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_INDENTATION, (GameDataSettings.Indentations) this.gameDataSettings.Indentation); this.gameDataSettings.Options = (int)(CodeGenerationOptions)EditorGUILayout.EnumMaskField( Resources.UI_UNITYPLUGIN_INSPECTOR_CODE_OPTIONS, (CodeGenerationOptions)this.gameDataSettings.Options); } } this.scriptingAssembliesFold = EditorGUILayout.Foldout(this.scriptingAssembliesFold, Resources.UI_UNITYPLUGIN_INSPECTOR_SCRIPTING_ASSEMBLIES_LABEL); if (this.scriptingAssembliesFold) { for (var i = 0; i < this.gameDataSettings.ScriptingAssemblies.Length; i++) { var watchedAssetPath = this.gameDataSettings.ScriptingAssemblies[i]; var assetExists = !string.IsNullOrEmpty(watchedAssetPath) && (File.Exists(watchedAssetPath) || Directory.Exists(watchedAssetPath)); var watchedAsset = assetExists ? AssetDatabase.LoadMainAssetAtPath(watchedAssetPath) : null; if (watchedAsset != null) { this.gameDataSettings.ScriptingAssemblies[i] = AssetDatabase.GetAssetPath(EditorGUILayout.ObjectField(Resources.UI_UNITYPLUGIN_INSPECTOR_ASSET_LABEL, watchedAsset, typeof(Object), false)); } else { this.gameDataSettings.ScriptingAssemblies[i] = EditorGUILayout.TextField(Resources.UI_UNITYPLUGIN_INSPECTOR_NAME_LABEL, watchedAssetPath); } } EditorGUILayout.Space(); this.newScriptingAssembly = EditorGUILayout.ObjectField("<" + Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_ASSET_BUTTON + ">", this.newScriptingAssembly, typeof(Object), false); if (Event.current.type == EventType.repaint && this.newScriptingAssembly != null) { var assemblies = new HashSet <string>(this.gameDataSettings.ScriptingAssemblies); assemblies.Remove(""); assemblies.Add(AssetDatabase.GetAssetPath(this.newScriptingAssembly)); this.gameDataSettings.ScriptingAssemblies = assemblies.ToArray(); this.newScriptingAssembly = null; GUI.changed = true; } EditorGUILayout.BeginHorizontal(); this.newScriptingAssemblyName = EditorGUILayout.TextField("<" + Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_NAME_BUTTON + ">", this.newScriptingAssemblyName); if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_ADD_BUTTON, EditorStyles.toolbarButton, GUILayout.Width(70), GUILayout.Height(18))) { var assemblies = new HashSet <string>(this.gameDataSettings.ScriptingAssemblies); assemblies.Remove(""); assemblies.Add(this.newScriptingAssemblyName); this.gameDataSettings.ScriptingAssemblies = assemblies.ToArray(); this.newScriptingAssemblyName = null; GUI.changed = true; this.Repaint(); } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); GUILayout.Label(Resources.UI_UNITYPLUGIN_INSPECTOR_ACTIONS_GROUP, EditorStyles.boldLabel); if (EditorApplication.isCompiling) { EditorGUILayout.HelpBox(Resources.UI_UNITYPLUGIN_COMPILING_WARNING, MessageType.Warning); } else if (CoroutineScheduler.IsRunning) { EditorGUILayout.HelpBox(Resources.UI_UNITYPLUGIN_COROUTINE_IS_RUNNIG_WARNING, MessageType.Warning); } EditorGUILayout.BeginHorizontal(); GUI.enabled = !CoroutineScheduler.IsRunning && !EditorApplication.isCompiling; if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_EDIT_BUTTON)) { AssetDatabase.OpenAsset(gameDataAsset); this.Repaint(); } if (this.gameDataSettings.Generator != (int)GameDataSettings.CodeGenerator.None && string.IsNullOrEmpty(this.gameDataSettings.CodeGenerationPath) == false) { if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_RUN_GENERATOR_BUTTON)) { CoroutineScheduler.Schedule(Menu.GenerateCodeAndAssetsAsync(gameDataPath, ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_INSPECTOR_GENERATION_PREFIX + " ")), "generation::" + gameDataPath) .ContinueWith(_ => this.Repaint()); } } GUI.enabled = !CoroutineScheduler.IsRunning && !EditorApplication.isCompiling; if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_VALIDATE_BUTTON)) { CoroutineScheduler.Schedule(Menu.ValidateAsync(gameDataPath, ProgressUtils.ReportToLog(Resources.UI_UNITYPLUGIN_INSPECTOR_VALIDATION_PREFIX + " ")), "validation::" + gameDataPath) .ContinueWith(_ => this.Repaint()); } if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_BACKUP_BUTTON)) { this.Backup(gameDataPath); } if (GUILayout.Button(Resources.UI_UNITYPLUGIN_INSPECTOR_RESTORE_BUTTON)) { this.Restore(gameDataPath); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; if (GUI.changed) { this.gameDataSettings.Save(gameDataPath); } }
public void Refresh() { // Unhighlight int oldHighlight = m_highlight; int oldCount = m_count; if (Screen != null) { SetHighlight(-1); } // Dispose old elements for (int i = 0; i < m_campaignThumbnails.Count; ++i) { var thumbnail = m_campaignThumbnails[i]; thumbnail.Dispose(); } m_campaignThumbnails.Clear(); // Get campaign list var campaigns = AllCampaigns(); m_count = campaigns.Count; // Add new elements var yPos = 0.0f; for (int i = m_offset; i < Math.Min(campaigns.Count, m_offset + ENTRIES_PER_PAGE); ++i) { var campaign = campaigns[i].Campaign; var mod = campaigns[i].Mod; var thumbnail = new CampaignThumbnail(m_width, 16.0f + 2.0f * UIFonts.Default.Height); thumbnail.Anchor = Anchor; thumbnail.LocalPosition = LocalPosition + new Vector2(0.0f, yPos); // Set icon if (mod != null) { var icon = mod.LoadIcon(true); if (icon != null) { thumbnail.Icon = icon; thumbnail.DisposeIcon = true; } else { thumbnail.Icon = Texture.Get("gui/blue_icon.png", true); } } else { thumbnail.Icon = Texture.Get("gui/red_icon.png", true); } // Set title, info and action int robotsRescued, totalRobots; bool allLevelsCompleted = ProgressUtils.IsCampaignCompleted(campaign, mod, m_game.User); robotsRescued = ProgressUtils.CountRobotsRescued(campaign, mod, m_game.User, out totalRobots); thumbnail.Title = campaign.Title; if (m_editor) { thumbnail.Info = "[gui/red_robot.png] " + totalRobots; thumbnail.Action = CampaignThumbnailAction.Delete; } else { if (allLevelsCompleted) { thumbnail.Info = "[gui/red_robot.png] " + robotsRescued + " [gui/completed.png]"; } else { thumbnail.Info = "[gui/red_robot.png] " + robotsRescued; } if (mod != null && mod.Source == ModSource.Editor) { thumbnail.Action = CampaignThumbnailAction.Edit; } else if (mod != null && mod.Source == ModSource.Workshop) { thumbnail.Action = CampaignThumbnailAction.ShowInWorkshop; } } thumbnail.OnClicked += delegate(object sender, EventArgs e) { FireOnSelection(campaign, mod); }; thumbnail.OnActionClicked += delegate(object sender, EventArgs e) { FireOnAction(campaign, mod, thumbnail.Action); }; m_campaignThumbnails.Add(thumbnail); yPos += thumbnail.Height + MARGIN_HEIGHT; } m_actionButton.Anchor = Anchor; m_actionButton.LocalPosition = LocalPosition + new Vector2(0.0f, yPos); if (Screen != null) { // Init new elements for (int i = 0; i < m_campaignThumbnails.Count; ++i) { var thumbnail = m_campaignThumbnails[i]; thumbnail.Init(Screen); } // Set highlight if (oldHighlight == oldCount) { SetHighlight(m_count); } else if (oldHighlight >= 0 && oldHighlight < m_count) { SetHighlight(oldHighlight); } else { SetHighlight(-1); } } m_upButton.Visible = m_offset > 0; m_downButton.Visible = (m_offset + ENTRIES_PER_PAGE) < m_count; }