private void RefreshModes() { if (_dispatcher.CheckAccess() == false) { _dispatcher.Invoke(new Action(RefreshModes)); return; } Log.Info("Refreshing modes"); GameModes.Clear(); if (Game == null) { Log.Warn("Game is null, can't refresh modes. User probably uninstalled the game."); return; } //pack://application:,,,/OCTGN;component/Resources/gamemode.png" var mode = new GameMode(); mode.Name = "Back"; mode.Image = "pack://application:,,,/OCTGN;component/Resources/circle-back-button.png"; GameModes.Add(mode); foreach (var m in Game.Modes) { if (m.Image == null) { m.Image = "pack://application:,,,/OCTGN;component/Resources/gamemode.png"; } GameModes.Add(m); } Log.Info("Refreshed modes"); }
/// <summary> /// Add all game modes by default /// </summary> public LobbySearchFilter() { foreach (var value in Enum.GetNames(typeof(GameMode))) { GameModes.Add((GameMode)Enum.Parse(typeof(GameMode), value)); } }
/// <summary> /// Attempts to load a custom map. /// </summary> /// <param name="mapPath">The path to the map file relative to the game directory.</param> /// <param name="userInvoked">Whether this function was invoked by the user. /// If true, displays notifications regarding the success of the map loading.</param> /// <returns>The map if loading it was succesful, otherwise false.</returns> protected Map LoadCustomMap(string mapPath, bool userInvoked) { // TODO This belongs to MapLoader if (!File.Exists(ProgramConstants.GamePath + mapPath + MapLoader.MAP_FILE_EXTENSION)) { Logger.Log("LoadCustomMap: Map " + mapPath + " not found!"); AddNotice($"Map file {mapPath}{MapLoader.MAP_FILE_EXTENSION} doesn't exist!"); return(null); } Logger.Log("Loading custom map " + mapPath); Map map = new Map(mapPath, false); if (map.SetInfoFromMap(ProgramConstants.GamePath + mapPath + MapLoader.MAP_FILE_EXTENSION)) { foreach (GameMode gm in GameModes) { if (gm.Maps.Find(m => m.SHA1 == map.SHA1) != null) { Logger.Log("Custom map " + mapPath + " is already loaded!"); if (userInvoked) { AddNotice($"Map {mapPath} is already loaded."); } return(null); } } Logger.Log("Map " + mapPath + " added succesfully."); foreach (string gameMode in map.GameModes) { GameMode gm = GameModes.Find(g => g.Name == gameMode); if (gm == null) { if (!allowedGameModes.Contains(gameMode)) { continue; } gm = new GameMode(gameMode); GameModes.Add(gm); } gm.Maps.Add(map); Logger.Log("Adding map to game mode " + gm.Name); } if (userInvoked) { AddNotice($"Map {mapPath} loaded succesfully."); } return(map); } if (userInvoked) { AddNotice($"Loading map {mapPath} failed!"); } Logger.Log("Loading map " + mapPath + " failed!"); return(null); }