private async void ScreenshotNotify(object sender, EventArgs e) { // Delaying so created file handle is closed (write completed) before we look at the directory for its newest file. await Task.Delay(NewFileNotificationDelay).ContinueWith(delegate { FileInfo screenshot = null; var completed = false; var timeout = DateTime.Now.AddMilliseconds(FileTimeOutMilliseconds); while (!completed) { try { var directory = new DirectoryInfo(DirectoryUtil.ScreensPath); screenshot = directory.GetFiles() .OrderByDescending(f => f.LastWriteTime) .First(); completed = true; } catch (InvalidOperationException ex) { if (DateTime.Now < timeout) { continue; } Logger.Error(ex.Message + ex.StackTrace); return; } } ScreenshotNotification.ShowNotification(screenshot.FullName, ScreenshotCreated, 5.0f); }); }
public override void ClientInitialize() { var scene = Api.Client.Scene; ClientComponentDebugGrid.Instance.Refresh(); ClientDebugGuidesManager.Instance.Refresh(); ClientComponentPhysicsSpaceVisualizer.Init(); scene.CreateSceneObject("FPS Counter") .AddComponent <ClientComponentPerformanceIndicatorsManager>(); scene.CreateSceneObject("Console manager") .AddComponent <ClientComponentConsoleErrorsWatcher>(); ClientInputContext.Start("Console toggle") .HandleButtonDown( GameButton.ToggleDeveloperConsole, ConsoleControl.Toggle, evenIfHandled: true); ClientInputContext.Start("Debug tools toggle") .HandleButtonDown( GameButton.ToggleDebugToolsOverlay, DebugToolsOverlay.Toggle); ClientInputContext.Start("Full screen toggle") .HandleButtonDown( GameButton.ToggleFullscreen, () => { var option = Api.GetProtoEntity <VideoOptionScreenMode>(); option.CurrentValue = option.CurrentValue != VideoOptionScreenMode.ScreenMode.Fullscreen ? VideoOptionScreenMode.ScreenMode.Fullscreen : VideoOptionScreenMode.ScreenMode.Windowed; option.Category.ApplyAndSave(); }, evenIfHandled: true); ClientInputContext.Start("Main menu overlay") .HandleButtonDown( GameButton.CancelOrClose, MainMenuOverlay.Toggle); ClientInputContext.Start("Capture screenshot") .HandleButtonDown( GameButton.CaptureScreenshot, () => { if (Client.SteamApi.IsSteamClient && Client.Input.IsKeyDown(InputKey.F12, evenIfHandled: true)) { // The default screenshot key (F12) was pressed while playing from Steam Client. // It will trigger a screenshot by Steam Client (if it using the default key binding). // Ignore the in-game screenshot functionality to avoid any issues with Steam Client. return; } Client.Rendering.CaptureScreenshot(); Api.Client.Audio.PlayOneShot(new SoundResource("UI/Notifications/Screenshot")); }, evenIfHandled: true); ScreenshotNotification.InitializeScreenshotOverlaySystem(); }