Beispiel #1
0
        public void Init()
        {
            string path      = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
            string cfgFolder = Path.Combine(path, "MapEditor");

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

            FileName = Path.Combine(cfgFolder, "MapEditorCfg.json");

            // 创建默认配置
            if (!File.Exists(FileName))
            {
                InitDefault();
                SaveCfg();

                return;
            }

            try
            {
                using (StreamReader reader = File.OpenText(FileName))
                {
                    string json = reader.ReadToEnd();
                    Cfg = JsonMapper.ToObject <EditorConfig>(json);
                }
            }
            catch (System.Exception)
            {
                System.Windows.MessageBox.Show("配置文件已损坏,将初始化默认配置!", "错误");

                // 删除损害的配置文件,重新初始化
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }

                Init();
            }

            isModified = false;
        }
Beispiel #2
0
        private void InitDefault()
        {
            Cfg = new EditorConfig
            {
                brushes = new Dictionary <string, Brush>()
            };
            Brush brush = new Brush()
            {
                Type  = 1,
                Color = "Red",
                Desc  = "不可行走"
            };

            Cfg.brushes[brush.Type.ToString()] = brush;

            // 自定义颜色
            Cfg.customColors = new List <int>()
            {
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#DC143C")),     // Crimson 猩红
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#4169E1")),     // RoyalBlue 皇家蓝
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#00BFFF")),     // DeepSkyBlue 深天蓝
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#2E8B57")),     // SeaGreen 海洋绿
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#32CD32")),     // LimeGreen 酸橙绿
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#FFD700")),     // Gold 金
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#FFA500")),     // Orange 橙色
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#FF4500")),     // OrangeRed 橙红色
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#FF6347")),     // Tomato 番茄
                ColorTranslator.ToWin32(ColorTranslator.FromHtml("#B22222")),     // FireBrick 砖红
            };

            Cfg.gridOpacity = 0.7;   // 默认网格透明度

            SetCurBrush(brush.Type); // 设置默认当前笔刷

            isModified = true;
        }