Example #1
0
        private void NewNPCScriptMenuItem_Click(object sender, EventArgs e)
        {
            if (this.treeProject.SelectedNodes.Count <= 0)
            {
                return;
            }

            var createScriptDialog = new CreateScriptDialog();

            if (createScriptDialog.ShowDialog() == DialogResult.OK)
            {
                var scriptFile = _project.AddScriptToGameContent(this.treeProject.SelectedNodes[0].Tag as FileInfo, createScriptDialog.ScriptName);

                var fileNode = new DarkTreeNode(scriptFile.Name)
                {
                    Tag  = scriptFile,
                    Icon = Icons.document_16xLG,
                };

                this.treeProject.SelectedNodes[0].Nodes.Add(fileNode);

                // We have to load up the NPC and attach the script to it.
                var npcFile = (this.treeProject.SelectedNodes[0].Tag as FileInfo);
                var npc     = _project.LoadNPC(npcFile.FullName);
                npc.Scripts.Add(Helpers.MakeRelative(scriptFile.FullName, _project.ServerRootDirectory.FullName + "/"));
                this.FileSelected.Invoke(this, new FileEventArgs(npcFile));

                // We do this at the very end to ensure our script document is focused, because attaching a script to a NPC will inherently load and open it as a document even if it wasn't prior.
                this.FileCreated?.Invoke(this, new FileEventArgs(scriptFile));
            }
        }
Example #2
0
        private void ToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (this.treeProject.SelectedNodes.Count <= 0)
            {
                return;
            }

            var createScriptDialog = new CreateScriptDialog();

            if (createScriptDialog.ShowDialog() == DialogResult.OK)
            {
                var scriptFile = _project.AddScriptToGameContent(this.treeProject.SelectedNodes[0].Tag as FileInfo, createScriptDialog.ScriptName);

                var fileNode = new DarkTreeNode(scriptFile.Name)
                {
                    Tag  = scriptFile,
                    Icon = Icons.document_16xLG,
                };

                this.treeProject.SelectedNodes[0].Nodes.Add(fileNode);

                // We have to load up the Dialogue and attach the script to it.
                var dialogueFile = (this.treeProject.SelectedNodes[0].Tag as FileInfo);
                var dialogue     = _project.LoadDialogue(dialogueFile.FullName);

                if (File.Exists(dialogue.ScriptPath))
                {
                    var response = DarkMessageBox.ShowWarning("Creating a new script will replace existing script file.", "Warning!", DarkDialogButton.OkCancel);

                    if (response != DialogResult.OK)
                    {
                        return;
                    }
                }

                // If there was a previous script in the scriptmap, remove it
                if (_project.ScriptMap.ContainsKey(dialogue.Name))
                {
                    _project.ScriptMap[dialogue.Name].ToObject <JArray>().Remove(dialogue.ScriptPath);
                }

                dialogue.ScriptPath = Helpers.MakeRelative(scriptFile.FullName, _project.ServerRootDirectory.FullName + "/");
                this.FileSelected.Invoke(this, new FileEventArgs(dialogueFile));

                // We do this at the very end to ensure our script document is focused, because attaching a script to a piece of content will inherently load and open it as a document even if it wasn't prior.
                this.FileCreated?.Invoke(this, new FileEventArgs(scriptFile));
            }
        }