private void LoadConfigs() { pathToConfigs = Path.GetDirectoryName(Application.ExecutablePath) + "\\Configs\\minimaps\\"; try { string[] configcontent = File.ReadAllLines(pathToConfigs + "config.txt"); foreach (string line in configcontent) { if (!line.StartsWith("#")) { ConfigStr cfg = new ConfigStr(); string[] split = line.Split('@'); cfg.GridSize = int.Parse(split[1]); cfg.ImageXoffset = int.Parse(split[2]); cfg.ImageYoffset = int.Parse(split[3]); cfg.rows = int.Parse(split[5]); cfg.cols = int.Parse(split[4]); cfg.ImageSize = int.Parse(split[6]); cfg.rowsStart = int.Parse(split[7]); cfg.colsStart = int.Parse(split[8]); configs.Add(split[0].ToLower().Trim(), cfg); } } } catch { JMessageBox.Show(this, "Unable to load config:" + pathToConfigs); return; } if (FilePath != null) { LoadMap(FilePath); } }
private void LoadMap(string mapName) { pathToFiles = Path.Combine(mapName, pathToConfigs); try { Regex rgx = new Regex("[^a-zA-Z0-9-]"); string key = rgx.Replace(mapName, "").ToLower().Trim(); if (configs.ContainsKey(key)) { currentConfig = configs[key]; currentImage = new Bitmap(currentConfig.rows * currentConfig.ImageSize, currentConfig.cols * currentConfig.ImageSize); using (Graphics g = Graphics.FromImage(currentImage)) { for (int col = 0; col < currentConfig.cols; col++) { for (int row = 0; row < currentConfig.rows; row++) { string imageName = Path.Combine(pathToFiles + key, (col + currentConfig.colsStart).ToString("D2") + (row + currentConfig.rowsStart).ToString("D2") + ".dds"); int x = currentConfig.ImageSize * (row + currentConfig.rowsStart); int y = currentConfig.ImageSize * (col + currentConfig.colsStart); try { using (DevIL.ImageImporter imImport = new DevIL.ImageImporter()) { g.DrawImage(LoadImage(imImport, new MemoryStream(File.ReadAllBytes(imageName)), currentConfig.ImageSize, currentConfig.ImageSize), x, y, currentConfig.ImageSize, currentConfig.ImageSize); } } catch { g.DrawImage(new Bitmap(currentConfig.ImageSize, currentConfig.ImageSize), x, y, currentConfig.ImageSize, currentConfig.ImageSize); } } } } pictureBox_path.Width = currentConfig.rows * currentConfig.ImageSize; pictureBox_path.Height = currentConfig.cols * currentConfig.ImageSize; pictureBox_path.BackgroundImage = currentImage; pictureBox_path.Refresh(); comboBox_lists.Items.Clear(); foreach (string map in configs.Keys) { comboBox_lists.Items.Add(map); } autoSlected = true; comboBox_lists.SelectedIndex = comboBox_lists.FindString(key); autoSlected = false; Loaded = true; } else { JMessageBox.Show(this, "Unable to load images for :" + mapName + ".\rWill not continue without graphic suport!"); return; } } catch (Exception e) { JMessageBox.Show(this, "Unable to load config:" + e.ToString()); return; } }
public string this[ConfigStr configName] { get { return(StrConfigs[configName]); } }