/// <summary> /// Handles new incoming online users and dictates if they are available to display /// <see cref="AvailableUsers"/> /// </summary> /// <param name="users"></param> public void HandleNewOnlineUsers(IEnumerable <User> users) { lock (AvailableUsers) { var incomingAvailableUsers = users.Where(CheckIfUserShouldBeDrawn).ToList(); var allAvailableUsers = new List <User>(AvailableUsers); // Concatenate the old list of available users with the new one, and order it properly. AvailableUsers = allAvailableUsers .Concat(incomingAvailableUsers) .ToList(); SortUsers(); RecalculateContainerHeight(); Logger.Debug($"There are now {AvailableUsers.Count} total available users.", LogType.Runtime); // If we already have enough buffered objects, then just update all of the current buffered users. if (UserBufferObjectsUsed == MAX_USERS_SHOWN) { UpdateBufferUsers(); return; } // Based on how many new available users we have, we can add that many new contained drawables. for (var i = 0; i < incomingAvailableUsers.Count && UserBufferObjectsUsed != MAX_USERS_SHOWN; i++) { UserBufferObjectsUsed++; } UpdateBufferUsers(); } }
/// <summary> /// Handles messages from IPC /// </summary> /// <param name="message"></param> public static void HandleMessage(string message) { Logger.Important($"Received IPC Message: {message}", LogType.Runtime); if (message.StartsWith(protocolUriStarter)) { HandleProtocolMessage(message.Substring(protocolUriStarter.Length)); } else { // Quaver was launched with a file path, try to import it. MapsetImporter.ImportFile(message); } }
/// <summary> /// Queues a load of the background for a map /// </summary> public static void Load(Map map) => ThreadScheduler.Run(async() => { Source.Cancel(); Source.Dispose(); Source = new CancellationTokenSource(); Map = map; var token = Source.Token; token.ThrowIfCancellationRequested(); try { var oldRawTexture = RawTexture; var oldBlurredTexture = BlurredTexture; var path = MapManager.GetBackgroundPath(map); var tex = File.Exists(path) ? AssetLoader.LoadTexture2DFromFile(path) : UserInterface.MenuBackgroundRaw; RawTexture = tex; ThreadScheduler.RunAfter(() => { if (oldRawTexture != null && oldRawTexture != UserInterface.MenuBackgroundRaw) { oldRawTexture?.Dispose(); oldBlurredTexture?.Dispose(); } }, 500); token.ThrowIfCancellationRequested(); await Task.Delay(100, token); ShouldBlur = true; Loaded?.Invoke(typeof(BackgroundHelper), new BackgroundLoadedEventArgs(map, tex)); } catch (OperationCanceledException e) { // ignored } catch (Exception e) { Logger.Error(e, LogType.Runtime); } });
/// <summary> /// Called when a new steam avatar is loaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSteamAvatarLoaded(object sender, SteamAvatarLoadedEventArgs e) { // If it doesn't apply to this message. if (e.SteamId != (ulong)Message.Sender.OnlineUser.SteamId) { return; } try { Avatar.Animations.Clear(); Avatar.Animations.Add(new Animation(AnimationProperty.Alpha, Easing.Linear, 0, 1, 300)); Avatar.Image = e.Texture; } catch (Exception exception) { Logger.Error(exception, LogType.Runtime); } }
/// <summary> /// Exports the entire mapset to a zip (.qp) file. /// </summary> public void ExportToZip() { var exportsDir = $"{ConfigManager.DataDirectory}/Exports/"; System.IO.Directory.CreateDirectory(exportsDir); var tempFolder = $"{ConfigManager.DataDirectory}/temp/{GameBase.Game.TimeRunning}/"; System.IO.Directory.CreateDirectory(tempFolder); using (var archive = ZipArchive.Create()) { foreach (var map in Maps) { try { switch (map.Game) { case MapGame.Quaver: var path = $"{ConfigManager.SongDirectory.Value}/{map.Directory}/{map.Path}"; File.Copy(path, $"{tempFolder}/{map.Path}"); break; // Map is from osu!, so we need to convert it to .qua format case MapGame.Osu: var osuPath = $"{MapManager.OsuSongsFolder}{map.Directory}/{map.Path}"; var osu = new OsuBeatmap(osuPath); map.BackgroundPath = osu.Background; var name = StringHelper.FileNameSafeString($"{map.Artist} - {map.Title} [{map.DifficultyName}].qua"); var savePath = $"{tempFolder}/{name}"; osu.ToQua().Save(savePath); Logger.Debug($"Successfully converted osu beatmap: {osuPath}", LogType.Runtime); break; } // Copy over audio file if necessary if (File.Exists(MapManager.GetAudioPath(map)) && !File.Exists($"{tempFolder}/{map.AudioPath}")) { File.Copy(MapManager.GetAudioPath(map), $"{tempFolder}/{map.AudioPath}"); } // Copy over background file if necessary if (File.Exists(MapManager.GetBackgroundPath(map)) && !File.Exists($"{tempFolder}/{map.BackgroundPath}")) { File.Copy(MapManager.GetBackgroundPath(map), $"{tempFolder}/{map.BackgroundPath}"); } } catch (Exception e) { Logger.Error(e, LogType.Runtime); } } archive.AddAllFromDirectory(tempFolder); var outputPath = exportsDir + $"{StringHelper.FileNameSafeString(Artist + " - " + Title + " - " + GameBase.Game.TimeRunning)}.qp"; archive.SaveTo(outputPath, CompressionType.Deflate); Utils.NativeUtils.HighlightInFileManager(outputPath); } System.IO.Directory.Delete(tempFolder, true); }