Exemplo n.º 1
0
        private void EditItem(TreeNode node)
        {
            if (node == null)
            {
                return;
            }
            if (node.Tag is ItemPropertyGridItem item)
            {
                if (Path.GetExtension(item.Name) == ".fnt")
                {
                    FontDescription?description = Json.Deserialize <FontDescription>(
                        Path.Combine(_projectFile !.Location, item.VirtualPath, item.Name));
                    if (description == null)
                    {
                        return;
                    }

                    using (JsonEditorForm? jsonEditorForm =
                               new JsonEditorForm(description)
                    {
                        Text = $"Edit font '{item.Name}'"
                    })
                    {
                        if (jsonEditorForm.ShowDialog() != DialogResult.OK)
                        {
                            SetStatusLabel(StatusType.Error, "The font was not edited!");
                            return;
                        }
                        jsonEditorForm.Save(Path.Combine(_projectFile !.Location, item.VirtualPath, item.Name));
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void Show_Json_editor_button_Click(object sender, EventArgs e)
 {
     if (json_editor_form == null)
     {
         json_editor_form = new JsonEditorForm();
         json_editor_form.Show();
     }
 }
Exemplo n.º 3
0
        private void addFontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            treeView1.InvokeIfRequired(
                x =>
            {
                TreeNode?selectedNode = x.SelectedNode ?? x.TopNode;
                if (selectedNode == null)
                {
                    return;
                }
                int selectedNodeCount = selectedNode.GetNodeCount(false);

                using (JsonEditorForm? jsonEditorForm = new JsonEditorForm(
                           new FontDescription
                {
                    Name = "Arial",
                    Chars = "32-126,128,130-140,142,145-156,158-255",
                    Size = 12,
                    IsBold = false,
                    AA = true,
                    IsItalic = false
                })
                {
                    Text = "Add a new font to the project..."
                })
                {
                    if (jsonEditorForm.ShowDialog() != DialogResult.OK)
                    {
                        SetStatusLabel(StatusType.Error, "The font is not added to the project!");
                        return;
                    }

                    int i = 0;
                    if (jsonEditorForm.Deserialize <FontDescription>(out var fntDescription))
                    {
                        string fntFilePath;
                        while (File.Exists(
                                   fntFilePath = Path.Combine(
                                       _projectFile !.Location, selectedNode.FullPath,
                                       $"{fntDescription.Name}_{fntDescription.Size}{(i++ == 0 ? string.Empty : "_" + (i - 1))}.fnt"))
                               )
                        {
                        }

                        jsonEditorForm.Save(fntFilePath);

                        TreeNode?node = selectedNode.Nodes.Add(
                            $"{FONT_KEY_PREFIX}{selectedNodeCount}",
                            Path.GetFileName(fntFilePath), 4, 4);
                        node.Tag = _projectFile.AddResource(
                            new ItemPropertyGridItem
                        {
                            Name = node.Text, VirtualPath = node.Parent.FullPath,
                        })
                                   .Initialize();
                        node.ContextMenuStrip = itemContextMenuStrip;

                        if (node.Parent.Tag is FolderPropertyGridItem folderPropertyGridItem)
                        {
                            folderPropertyGridItem.TotalItems++;
                        }

                        selectedNode.Expand();
                        treeView1.SelectedNode = node;
                        node.BeginEdit();
                    }
                }
            });
        }