Exemplo n.º 1
0
    public static void ExportModules(string filePath, bool showQuickTip = false)
    {
        if (string.IsNullOrWhiteSpace(filePath))
        {
            return;
        }
        ContainerManager.UpdateCurrentDisplayObjectData();
        List <Module> modules = new List <Module>();
        int           count   = GlobalData.Modules.Count;

        for (int idx = 0; idx < count; ++idx)
        {
            Module module = new Module {
                Name = GlobalData.Modules[idx]
            };
            module.Elements = GlobalData.ModuleDic[module.Name];
            Rectangle rect = DisplayObjectUtil.GetMinRectangleContainsDisplayObjects(module.Elements);
            if (rect != null)
            {
                module.X      = rect.X;
                module.Y      = rect.Y;
                module.Width  = rect.Width;
                module.Height = rect.Height;
            }

            modules.Add(module);
        }

        string jsonString = JsonConvert.SerializeObject(modules, Formatting.Indented);
        bool   result     = Utils.WriteFile(filePath, Encoding.UTF8.GetBytes(jsonString));

        if (result)
        {
            string message = $"成功导出到 {filePath}";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowInfo(message);
            }
            GlobalData.CurrentFilePath = filePath;
            GlobalData.ModifyCount     = 0;
        }
        else
        {
            const string message = "导出失败";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowError(message, 0, 0);
            }
        }
    }
Exemplo n.º 2
0
    public static void CheckExportModules()
    {
        if (GlobalData.Modules.Count == 0)
        {
            QuickTipManager.ShowQuickTip("当前没有任何 module, 导出失败");
            return;
        }

        string filePath = SaveFileUtil.SaveFile("json 文件(*.json)\0*.json");

        ExportModules(filePath);
    }
Exemplo n.º 3
0
    public static void ExportCurrentModule()
    {
        if (string.IsNullOrWhiteSpace(GlobalData.CurrentModule))
        {
            DialogManager.ShowWarn("请先打开一个 module");
            return;
        }

        ContainerManager.UpdateCurrentDisplayObjectData();
        Module module = new Module {
            Name = GlobalData.CurrentModule
        };

        module.Elements = GlobalData.ModuleDic[module.Name];
        string jsonString = JsonConvert.SerializeObject(module, Formatting.Indented);

        GUIUtility.systemCopyBuffer = jsonString;
        QuickTipManager.ShowQuickTip("已导出到剪切板");
    }
Exemplo n.º 4
0
    public static void CreateModule()
    {
        DialogManager.ShowGetValue("请输入 module 名:",
                                   "module",
                                   txt => {
            if (string.IsNullOrWhiteSpace(txt))
            {
                QuickTipManager.ShowQuickTip("请输入正确的 module");
                return;
            }

            if (GlobalData.ModuleDic.ContainsKey(txt))
            {
                QuickTipManager.ShowQuickTip("module 已存在");
                return;
            }

            HistoryManager.Do(BehaviorFactory.GetCreateModuleBehavior(txt));
        });
    }