Esempio n. 1
0
        /// <summary>
        /// Dient zur Erstellung der Listen mit verkleinerten Rohstoff-Bitmaps, welche in den Forms angezeigt werden können
        /// (bessere Performance, weniger Speicherverbrauch).
        /// </summary>
        private static void RohstoffIconsAufbereiten()
        {
            if (_rohstoffIcons46px == null)
            {
                _rohstoffIcons46px = new List <Bitmap>();
            }

            if (_rohstoffIcons80px == null)
            {
                _rohstoffIcons80px = new List <Bitmap>();
            }

            if (_rohstoffIcons100px == null)
            {
                _rohstoffIcons100px = new List <Bitmap>();
            }

            if (_rohstoffIcons46px.Count == 0 || _rohstoffIcons80px.Count == 0 || _rohstoffIcons100px.Count == 0)
            {
                // Dummy an Index 0 hinzufügen, damit der Zugriff intuitiver wird (mit der RohstoffID, z.B. lstRohstoffIcons80px[rohID])
                if (_rohstoffIcons46px.Count == 0)
                {
                    _rohstoffIcons46px.Add(null);
                }

                if (_rohstoffIcons80px.Count == 0)
                {
                    _rohstoffIcons80px.Add(null);
                }

                if (_rohstoffIcons100px.Count == 0)
                {
                    _rohstoffIcons100px.Add(null);
                }

                string sPathImageCache = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Conspiratio", "imgcache");

                if (!Directory.Exists(sPathImageCache))
                {
                    Directory.CreateDirectory(sPathImageCache);
                }

                for (int i = 1; i < SW.Statisch.GetMaxRohID(); i++)
                {
                    bool   bIconFileExists46  = false;
                    bool   bIconFileExists80  = false;
                    bool   bIconFileExists100 = false;
                    string sFilenameIcon46    = Path.Combine(sPathImageCache, "Roh" + i.ToString() + "_46.png");
                    string sFilenameIcon80    = Path.Combine(sPathImageCache, "Roh" + i.ToString() + "_80.png");
                    string sFilenameIcon100   = Path.Combine(sPathImageCache, "Roh" + i.ToString() + "_100.png");

                    if (File.Exists(sFilenameIcon46))
                    {
                        _rohstoffIcons46px.Add((Bitmap)Image.FromFile(sFilenameIcon46));
                        bIconFileExists46 = true;
                    }

                    if (File.Exists(sFilenameIcon80))
                    {
                        _rohstoffIcons80px.Add((Bitmap)Image.FromFile(sFilenameIcon80));
                        bIconFileExists80 = true;
                    }

                    if (File.Exists(sFilenameIcon100))
                    {
                        _rohstoffIcons100px.Add((Bitmap)Image.FromFile(sFilenameIcon100));
                        bIconFileExists100 = true;
                    }

                    if (!bIconFileExists46 || !bIconFileExists80 || !bIconFileExists100)
                    {
                        object oRohstoffImage = Properties.Resources.ResourceManager.GetObject("Roh" + i.ToString());
                        if (oRohstoffImage != null && oRohstoffImage is Bitmap)   // Sicherheitsabfrage: ist ein gültiges Bitmap zurückgekommen?
                        {
                            if (!bIconFileExists46)
                            {
                                _rohstoffIcons46px.Add(Grafik.ResizeImage((Bitmap)oRohstoffImage, 46, 46));
                                _rohstoffIcons46px[i].Save(sFilenameIcon46, ImageFormat.Png);
                            }

                            if (!bIconFileExists80)
                            {
                                _rohstoffIcons80px.Add(Grafik.ResizeImage((Bitmap)oRohstoffImage, 80, 80));
                                _rohstoffIcons80px[i].Save(sFilenameIcon80, ImageFormat.Png);
                            }

                            if (!bIconFileExists100)
                            {
                                _rohstoffIcons100px.Add(Grafik.ResizeImage((Bitmap)oRohstoffImage, 100, 100));
                                _rohstoffIcons100px[i].Save(sFilenameIcon100, ImageFormat.Png);
                            }
                        }
                    }
                }
            }
        }