123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using NTERA.EmuEra.Game.EraEmu.Config;
- using NTERA.EmuEra.Game.EraEmu.Sub;
- namespace NTERA.EmuEra.Game.EraEmu.Content
- {
- static class AppContents
- {
- public static CroppedImage GetContent(string name)
- {
- if (name == null)
- return null;
- name = name.ToUpper();
- if (!itemDic.ContainsKey(name))
- return null;
- return itemDic[name];
- }
- public static void LoadContents()
- {
- if (!Directory.Exists(Program.ContentDir))
- return;
- try
- {
- List<string> bmpfilelist = new List<string>();
- bmpfilelist.AddRange(Directory.GetFiles(Program.ContentDir, "*.png", SearchOption.TopDirectoryOnly));
- bmpfilelist.AddRange(Directory.GetFiles(Program.ContentDir, "*.bmp", SearchOption.TopDirectoryOnly));
- bmpfilelist.AddRange(Directory.GetFiles(Program.ContentDir, "*.jpg", SearchOption.TopDirectoryOnly));
- bmpfilelist.AddRange(Directory.GetFiles(Program.ContentDir, "*.gif", SearchOption.TopDirectoryOnly));
- foreach (var filename in bmpfilelist)
- {//リスト化のみ。Loadはまだ
- string name = Path.GetFileName(filename).ToUpper();
- resourceDic.Add(name, new BaseImage(name, filename));
- }
- string[] csvFiles = Directory.GetFiles(Program.ContentDir, "*.csv", SearchOption.TopDirectoryOnly);
- foreach (var filename in csvFiles)
- {
- string[] lines = File.ReadAllLines(filename, Config.Config.Encode);
- foreach (var line in lines)
- {
- if (line.Length == 0)
- continue;
- string str = line.Trim();
- if (str.Length == 0 || str.StartsWith(";"))
- continue;
- string[] tokens = str.Split(',');
- CroppedImage item = CreateFromCsv(tokens);
- if (item != null && !itemDic.ContainsKey(item.Name))
- itemDic.Add(item.Name, item);
- }
- }
- }
- catch
- {
- throw new CodeEE("An error occurred while loading the resource file");
- }
- }
- public static void UnloadContents()
- {
- foreach (var img in resourceDic.Values)
- img.Dispose();
- resourceDic.Clear();
- itemDic.Clear();
- }
- private static CroppedImage CreateFromCsv(string[] tokens)
- {
- if(tokens.Length < 2)
- return null;
- string name = tokens[0].Trim().ToUpper();
- string parentName = tokens[1].ToUpper();
- if (name.Length == 0 || parentName.Length == 0)
- return null;
- if (!resourceDic.ContainsKey(parentName))
- return null;
- AContentFile parent = resourceDic[parentName];
- if(parent is BaseImage)
- {
- BaseImage parentImage = parent as BaseImage;
- parentImage.Load(Config.Config.TextDrawingMode == TextDrawingMode.WINAPI);
- if (!parentImage.Enabled)
- return null;
- Rectangle rect = new Rectangle(new Point(0, 0), parentImage.Bitmap.Size);
- bool noresize = false;
- if(tokens.Length >= 6)
- {
- int[] rectValue = new int[4];
- bool sccs = true;
- for (int i = 0; i < 4; i++)
- sccs &= int.TryParse(tokens[i + 2], out rectValue[i]);
- if (sccs)
- rect = new Rectangle(rectValue[0], rectValue[1], rectValue[2], rectValue[3]);
- if(tokens.Length >= 7)
- {
- string[] keywordTokens = tokens[6].Split('|');
- foreach(string keyword in keywordTokens)
- {
- switch(keyword.Trim().ToUpper())
- {
- case "NORESIZE":
- throw new NotImplCodeEE();
- noresize = true;
- break;
- }
- }
- }
- }
- CroppedImage image = new CroppedImage(name, parentImage.Bitmap, rect, noresize);
- return image;
- }
- return null;
- }
- static Dictionary<string, AContentFile> resourceDic = new Dictionary<string, AContentFile>();
- static Dictionary<string, CroppedImage> itemDic = new Dictionary<string, CroppedImage>();
- }
- }
|