diff --git a/LevelScriptEditor.csproj b/LevelScriptEditor.csproj index 910f1d6..d4de372 100644 --- a/LevelScriptEditor.csproj +++ b/LevelScriptEditor.csproj @@ -2,10 +2,22 @@ WinExe - net5.0-windows - true + net5.0 + false 0.0.2 joey - \ No newline at end of file + + + + + + + + + + + + + diff --git a/LevelScriptEditor.sln.DotSettings b/LevelScriptEditor.sln.DotSettings new file mode 100644 index 0000000..5ced463 --- /dev/null +++ b/LevelScriptEditor.sln.DotSettings @@ -0,0 +1,2 @@ + + NPC \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..02021d3 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.100-rc.1.20452.10" + } +} \ No newline at end of file diff --git a/src/Forms/MainWindow.Designer.cs b/src/Forms/MainWindow.Designer.cs index d24d5bd..d5887f3 100644 --- a/src/Forms/MainWindow.Designer.cs +++ b/src/Forms/MainWindow.Designer.cs @@ -1,4 +1,10 @@ -namespace LevelScriptEditor.Forms +using System; +using Gdk; +using Gtk; +using GtkSource; +using LevelScriptEditor.State; + +namespace LevelScriptEditor.Forms { partial class MainWindow { @@ -29,6 +35,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow)); + /* this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -44,14 +51,20 @@ private void InitializeComponent() this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.optionsReplaceStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionReplaceMatchImagesMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.treeView1 = new System.Windows.Forms.TreeView(); + */ + this.treeView1 = new (); + + /* this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.npcScriptTextBox = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.npcImageTextBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.npcDescTextBox = new System.Windows.Forms.TextBox(); + */ + this.npcScriptTextBox = new (); + + this.label1 = new (); + this.npcImageTextBox = new (); + this.label2 = new (); + this.npcDescTextBox = new (); + /* this.searchBox = new System.Windows.Forms.TextBox(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); @@ -60,7 +73,7 @@ private void InitializeComponent() // menuStrip1 // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1.Items.AddRange(new ToolStripItem[] { this.fileToolStripMenuItem, this.optionsStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); @@ -71,7 +84,7 @@ private void InitializeComponent() // // fileToolStripMenuItem // - this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.openToolStripMenuItem, this.reloadToolStripMenuItem, this.toolStripSeparator, @@ -87,7 +100,7 @@ private void InitializeComponent() this.openToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripMenuItem.Image"))); this.openToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta; this.openToolStripMenuItem.Name = "openToolStripMenuItem"; - this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); + this.openToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.O))); this.openToolStripMenuItem.Size = new System.Drawing.Size(246, 26); this.openToolStripMenuItem.Tag = ""; this.openToolStripMenuItem.Text = "&Open Directory"; @@ -110,7 +123,7 @@ private void InitializeComponent() this.saveToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem.Image"))); this.saveToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.saveToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control | Keys.S))); this.saveToolStripMenuItem.Size = new System.Drawing.Size(246, 26); this.saveToolStripMenuItem.Text = "&Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); @@ -129,7 +142,7 @@ private void InitializeComponent() // // optionsStripMenuItem // - this.optionsStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.optionsStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.optionsShowEmptyLevelsMenuItem, this.optionsShowEmptyNpcsMenuItem, this.optionsShowCompleteMenuItem, @@ -159,7 +172,7 @@ private void InitializeComponent() // this.optionsShowCompleteMenuItem.Checked = true; this.optionsShowCompleteMenuItem.CheckOnClick = true; - this.optionsShowCompleteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.optionsShowCompleteMenuItem.CheckState = CheckState.Checked; this.optionsShowCompleteMenuItem.Name = "optionsShowCompleteMenuItem"; this.optionsShowCompleteMenuItem.Size = new System.Drawing.Size(263, 26); this.optionsShowCompleteMenuItem.Text = "Show Completed NPCS"; @@ -187,22 +200,111 @@ private void InitializeComponent() this.optionReplaceMatchImagesMenuItem.Size = new System.Drawing.Size(229, 26); this.optionReplaceMatchImagesMenuItem.Text = "Match Image Names"; this.optionReplaceMatchImagesMenuItem.CheckedChanged += new System.EventHandler(this.OptionReplaceMatchImagesMenuItem_CheckedChanged); + */ // // treeView1 // - this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.treeView1.Location = new System.Drawing.Point(12, 44); + //this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) +// | System.Windows.Forms.AnchorStyles.Left))); this.treeView1.Location = new System.Drawing.Point(12, 44); this.treeView1.Name = "treeView1"; - this.treeView1.Size = new System.Drawing.Size(270, 632); - this.treeView1.TabIndex = 1; - this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeView1_AfterSelect); - this.treeView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TreeView1_MouseDown); + + //this.treeView1.TabIndex = 1; + //this.treeView1.AfterSelect += new TreeViewEventHandler(this.TreeView1_AfterSelect); + this.treeView1.NodeSelection.Changed += this.TreeView1_AfterSelect; + //this.treeView1.ButtonPressEvent += this.TreeView1_MouseDown; + this.treeView1.NodeSelection.Mode = SelectionMode.Single; + + //this.treeView1.Sensitive = true; //.ButtonPressEvent += TreeView1_MouseDown; + this.treeView1.FixedHeightMode = false; + this.treeView1.HeadersClickable = true; + this.treeView1.HeadersVisible = true; + this.treeView1.SearchColumn = 0; + this.treeView1.EnableSearch = true; + this.treeView1.EnableTreeLines = true; + + //this.treeView1.PopupMenu += TreeView1OnPopupMenu; + this.treeView1.WidgetEvent += TreeView1_MouseDown; + this.treeView1.ShowExpanders = true; + + // Create our TreeView and add it as our child widget + this.treeView1.NodeStore = Store; + /* + Dialog test = new Dialog("test", this, DialogFlags.Modal); + test.SetSizeRequest(800,600); + test.AddButton("_OK", ResponseType.Ok); + test.AddButton("_Cancel", ResponseType.Cancel); + test.DestroyEvent += delegate(object sender, DestroyEventArgs args) + { + + }; + test.ShowAll(); + */ + var column = this.treeView1.AppendColumn ("Levels", new Gtk.CellRendererText (), "text", 0); + column.SortIndicator = true; + column.SortOrder = SortType.Ascending; + column.SortColumnId = 0; + + // Create a column with title 'Song Title' and bind its renderer to model column 1 + //treeView1.AppendColumn ("Song Title", new Gtk.CellRendererText (), "text", 1); + this.treeView1.ShowAll (); + + Table table = new Table(1, 1, false); + + //Table ServersFrameTable = new Table(1, 2, true); + HPaned mainPane = new HPaned(); + mainPane.Expand = true; + + + ScrolledWindow npcListScrolledWindow = new global::Gtk.ScrolledWindow(); + npcListScrolledWindow.Name = "GtkScrolledWindow"; + npcListScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + npcListScrolledWindow.Add(this.treeView1); + npcListScrolledWindow.SetSizeRequest(270, 632); + + ScrolledWindow npcScriptTextBoxScrolledWindow = new global::Gtk.ScrolledWindow(); + npcScriptTextBoxScrolledWindow.Name = "ServerInfoScrolledWindow"; + npcScriptTextBoxScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + npcScriptTextBoxScrolledWindow.Add(this.npcScriptTextBox); + npcScriptTextBoxScrolledWindow.Expand = true; + + Table npcContentBox = new Table(2,1, false); + //npcContentBox.Fill = true; + npcContentBox.Expand = true; + + + HBox hbox = new HBox(false, 5); + hbox.Add(label1); + hbox.Add(npcImageTextBox); + hbox.Add(label2); + hbox.Add(npcDescTextBox); + hbox.SetSizeRequest(10, 22 ); + hbox.Expand = false; + hbox.Fill = true; + + npcContentBox.Attach(hbox, 0, 1 ,0, 1, AttachOptions.Fill | AttachOptions.Expand | AttachOptions.Shrink, AttachOptions.Fill | AttachOptions.Shrink, 5, 5); + npcContentBox.Attach(npcScriptTextBoxScrolledWindow, 0, 1 ,1, 2, AttachOptions.Fill | AttachOptions.Expand | AttachOptions.Shrink, AttachOptions.Fill | AttachOptions.Shrink, 5, 5); + + mainPane.Add(npcListScrolledWindow); + mainPane.Add(npcContentBox); + + // + table.BorderWidth = 0; + //table.SetSizeRequest(100, 100); + /* + Frame ServersFrame = new Frame(); + ServersFrame.LabelWidget = new Label() { Name = "Servers", Text = " Servers " }; + ServersFrame.ShadowType = ShadowType.EtchedIn; + ServersFrame.Add(ServersFrameTable); + */ + table.Attach(mainPane, 0, 1, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 5); + this.Add(table); + + /* // // statusStrip1 // this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.statusStrip1.Items.AddRange(new ToolStripItem[] { this.toolStripStatusLabel1}); this.statusStrip1.Location = new System.Drawing.Point(0, 779); this.statusStrip1.Name = "statusStrip1"; @@ -214,62 +316,78 @@ private void InitializeComponent() // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 16); + */ // // npcScriptTextBox // - this.npcScriptTextBox.AcceptsReturn = true; + //this.npcScriptTextBox.AcceptsReturn = true; this.npcScriptTextBox.AcceptsTab = true; - this.npcScriptTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.npcScriptTextBox.Location = new System.Drawing.Point(288, 77); - this.npcScriptTextBox.Multiline = true; + this.npcScriptTextBox.ShowLineNumbers = true; + this.npcScriptTextBox.Monospace = true; + this.npcScriptTextBox.Buffer.Language = new LanguageManager().GetLanguage("js"); + this.npcScriptTextBox.Buffer.HighlightSyntax = true; + this.npcScriptTextBox.Buffer.StyleScheme = new StyleSchemeManager().GetScheme("cobalt"); + //Console.WriteLine(new LanguageManager().SearchPath); + //manager.SearchPath = state.BaseDir; + //var test = manager.GetLanguage("graal"); + //paths.append('resources:///plugins/my-plugin/language-specs/') + //manager.set_search_path(paths) + //this.npcScriptTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + //| System.Windows.Forms.AnchorStyles.Left) + //| System.Windows.Forms.AnchorStyles.Right))); + //this.npcScriptTextBox.Location = new System.Drawing.Point(288, 77); + //this.npcScriptTextBox.Multiline = true; this.npcScriptTextBox.Name = "npcScriptTextBox"; - this.npcScriptTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.npcScriptTextBox.Size = new System.Drawing.Size(788, 699); - this.npcScriptTextBox.TabIndex = 5; - this.npcScriptTextBox.TextChanged += new System.EventHandler(this.NpcScriptTextBox_TextChanged); + //this.npcScriptTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + //this.npcScriptTextBox.Size = new System.Drawing.Size(788, 699); + //this.npcScriptTextBox.TabIndex = 5; + this.npcScriptTextBox.Buffer.Changed += this.NpcScriptTextBox_TextChanged; + // // label1 // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(288, 47); + //this.label1.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) + //| AnchorStyles.Left))); + //this.label1.Expand = true; + //this.label1.Location = new System.Drawing.Point(288, 47); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(51, 20); - this.label1.TabIndex = 6; + this.label1.SetSizeRequest(51, 20); + //this.label1.TabIndex = 6; this.label1.Text = "Image"; // // npcImageTextBox // - this.npcImageTextBox.Location = new System.Drawing.Point(345, 44); + //this.npcImageTextBox.Location = new System.Drawing.Point(345, 44); this.npcImageTextBox.Name = "npcImageTextBox"; - this.npcImageTextBox.Size = new System.Drawing.Size(256, 27); - this.npcImageTextBox.TabIndex = 7; - this.npcImageTextBox.TextChanged += new System.EventHandler(this.NpcImageTextBox_TextChanged); + this.npcImageTextBox.SetSizeRequest(256, 27); + this.npcImageTextBox.Editable = true; + //this.npcImageTextBox.Buffer. + + //this.npcImageTextBox.TabIndex = 7; + this.npcImageTextBox.Changed += this.NpcImageTextBox_TextChanged; // // label2 // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(607, 47); + //this.label2.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) + //| AnchorStyles.Left))); + //this.label2.Expand = true; + //this.label2.Location = new System.Drawing.Point(607, 47); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(85, 20); - this.label2.TabIndex = 8; + this.label2.SetSizeRequest(85, 20); + //this.label2.TabIndex = 8; this.label2.Text = "Description"; // // npcDescTextBox // - this.npcDescTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.npcDescTextBox.Location = new System.Drawing.Point(698, 44); - this.npcDescTextBox.MinimumSize = new System.Drawing.Size(128, 4); + //this.npcDescTextBox.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) + //| AnchorStyles.Right))); + //this.npcDescTextBox.Location = new System.Drawing.Point(698, 44); + //this.npcDescTextBox.MinimumSize = new System.Drawing.Size(128, 4); this.npcDescTextBox.Name = "npcDescTextBox"; - this.npcDescTextBox.Size = new System.Drawing.Size(378, 27); - this.npcDescTextBox.TabIndex = 9; - this.npcDescTextBox.TextChanged += new System.EventHandler(this.NpcDescTextBox_TextChanged); + this.npcDescTextBox.SetSizeRequest(378, 27); + //this.npcDescTextBox.TabIndex = 9; + this.npcDescTextBox.Changed += this.NpcDescTextBox_TextChanged; + /* // // searchBox // @@ -298,20 +416,32 @@ private void InitializeComponent() this.Controls.Add(this.treeView1); this.Controls.Add(this.menuStrip1); this.MinimumSize = new System.Drawing.Size(18, 256); - this.Name = "MainWindow"; - this.Text = "Quick Script Editor"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainWindow_FormClosing); + + this.FormClosing += new FormClosingEventHandler(this.MainWindow_FormClosing); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); + */ + + + this.SetDefaultSize(1089,802); + //this.SetSizeRequest(280, 210); + //this.DoubleBuffered = true; + + this.Name = "MainWindow"; + + this.SetPosition(Gtk.WindowPosition.Center); + this.Title = "Quick Script Editor"; + //this.Icon = Pixbuf.LoadFromResource("OpenGraal.RC.Resources.rcicon.ico"); + this.DeleteEvent += MainWindow_FormClosing; } #endregion - + /* private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; @@ -319,13 +449,18 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; - private System.Windows.Forms.TreeView treeView1; + */ + private NodeView treeView1; + /* private System.Windows.Forms.StatusStrip statusStrip1; - private System.Windows.Forms.TextBox npcScriptTextBox; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox npcImageTextBox; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.TextBox npcDescTextBox; + */ + private SourceView npcScriptTextBox; + + private Label label1; + private Entry npcImageTextBox; + private Label label2; + private Entry npcDescTextBox; + /* private System.Windows.Forms.ToolStripMenuItem reloadToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; private System.Windows.Forms.ToolStripMenuItem optionsStripMenuItem; @@ -336,6 +471,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem optionsReplaceStripMenuItem; private System.Windows.Forms.ToolStripMenuItem optionReplaceMatchImagesMenuItem; private System.Windows.Forms.TextBox searchBox; + */ } } diff --git a/src/Forms/MainWindow.cs b/src/Forms/MainWindow.cs index 62df494..bb9ca0a 100644 --- a/src/Forms/MainWindow.cs +++ b/src/Forms/MainWindow.cs @@ -5,98 +5,134 @@ using System.Data; using System.IO; using System.Linq; -using System.Windows.Forms; +using Gdk; +using Gtk; +using GtkSource; +using LevelScriptEditor.Levels; +using Window = Gtk.Window; +using WindowType = Gtk.WindowType; +using static Gtk.Application; +using Buffer = GtkSource.Buffer; namespace LevelScriptEditor.Forms { - public partial class MainWindow : Form + public partial class MainWindow : Window { private readonly GlobalState state = new GlobalState(); - private LevelNPCNode activeNode = null; + private UINode activeNode = null; + private static MainWindow _instance; + public static MainWindow Instance => _instance ??= new MainWindow(); - public MainWindow() + private MainWindow() : base(WindowType.Toplevel) { InitializeComponent(); + OpenToolStripMenuItem_Click(null, null); } - private void TreeView1_AfterSelect(System.Object sender, System.Windows.Forms.TreeViewEventArgs e) + private void TreeView1_AfterSelect(object o, EventArgs args) { - switch (e.Node.Level) + NodeSelection selection = (NodeSelection) o; + UINode node = (UINode)selection.SelectedNode; + + if (node == null) return; + + switch (node?.NodeObject?.GetType()?.ToString()) { // Level node - case 0: + case "LevelScriptEditor.Levels.GameLevel": { - var node = (LevelNode)e.Node; - if (node.GameLevel == null) + + if (!node.Loaded) { - node.Load(); - if (e.Action != TreeViewAction.ByKeyboard) - node.Expand(); + //node.Load(); + /* + if (e.Action != TreeViewAction.ByKeyboard) + node.Expand(); + */ + } break; } // NPC node - case 1: - SetActiveNode((LevelNPCNode)e.Node); + case "LevelScriptEditor.Levels.LevelNPC": + SetActiveNode(node); break; } } - private void TreeView1_MouseDown(object sender, MouseEventArgs e) + private void TreeView1_MouseDown(object sender, WidgetEventArgs e) { - if (e.Button != MouseButtons.Right) + if (e.Event is not EventButton ev || ev.Type != EventType.ButtonPress || ev.Window != treeView1.BinWindow) return; + + if (ev.Button != 3) return; - TreeNode node_here = treeView1.GetNodeAt(e.X, e.Y); - treeView1.SelectedNode = node_here; + treeView1.GetPathAtPos((int) ev.X, (int) ev.Y, out TreePath path); + + treeView1.NodeSelection.SelectPath(path); + + if (treeView1.NodeSelection.SelectedNode == null) return; + + UINode node = (UINode)treeView1.NodeSelection.SelectedNode; + ShowContextMenu(node, ev); + } - if (node_here != null) + private void ShowContextMenu(UINode node, EventButton e) + { + Menu menu = new(); + switch (node?.NodeObject?.GetType().ToString()) { - switch (node_here.Level) + + case "LevelScriptEditor.Levels.GameLevel": { - // Level node - case 0: - ShowContextMenu((LevelNode)node_here, e); - break; - - // NPC node - case 1: - ShowContextMenu((LevelNPCNode)node_here, e); - break; + //var contextMenuStrip = new ContextMenuStrip(); + break; } + case "LevelScriptEditor.Levels.LevelNPC": + { + + MenuItem menu_item = new("Add file"); + menu.AttachToWidget(treeView1, null); + LevelNPCMenu(menu, node); + + menu.ShowAll(); + + menu.PopupAtPointer(e); + + break; + } + default: + Console.WriteLine(node?.NodeObject?.GetType().ToString()); + break; } + } - private void ShowContextMenu(LevelNode node, MouseEventArgs e) - { - //var contextMenuStrip = new ContextMenuStrip(); - } - - private void ShowContextMenu(LevelNPCNode node, MouseEventArgs e) + private void LevelNPCMenu(Menu menu, UINode node) { - var contextMenuStrip = new ContextMenuStrip(); /////////// { - var marked = node.NPC.Headers.ContainsKey("MARKED"); + bool marked = ((LevelNPC)node.NodeObject).Headers.ContainsKey("MARKED"); - ToolStripMenuItem markLabel = new ToolStripMenuItem(); - markLabel.Text = (marked ? "Unmark Complete" : "Mark Complete"); - markLabel.Click += new EventHandler((s, e) => + MenuItem markLabel = new(); + markLabel.Label = (marked ? "Unmark Complete" : "Mark Complete"); + markLabel.Activated += (s, e) => { - node.NPC.ToggleHeader("MARKED"); - RedrawLevelNode((LevelNode)node.Parent); - }); - contextMenuStrip.Items.Add(markLabel); + ((LevelNPC)node.NodeObject).ToggleHeader("MARKED"); + RedrawLevelNode((UINode)node.Parent); + }; + menu.Add(markLabel); } { - ToolStripMenuItem replaceLabel = new ToolStripMenuItem(); - replaceLabel.Text = "Replace similar scripts"; - replaceLabel.Click += new EventHandler((s, e) => + MenuItem replaceLabel = new (); + replaceLabel.Label = "Replace similar scripts"; + replaceLabel.Activated += (s, e) => { + /* using (var diag = new ReplaceScriptsForm(state, node)) { var result = diag.ShowDialog(); @@ -113,121 +149,155 @@ private void ShowContextMenu(LevelNPCNode node, MouseEventArgs e) RedrawNodes(); } - } - }); - contextMenuStrip.Items.Add(replaceLabel); + }*/ + }; + menu.Add(replaceLabel); } - - contextMenuStrip.Show(treeView1, e.Location); } #region Update NPC Scripts - private void SetActiveNode(LevelNPCNode node) + private void SetActiveNode(UINode node) { // Save current node changes if (activeNode != null) UpdateActiveNode(); // Clear fields - npcDescTextBox.Clear(); - npcImageTextBox.Clear(); - npcScriptTextBox.Clear(); - +/* + npcDescTextBox.Text = string.Empty; + npcImageTextBox.Text = string.Empty; + npcScriptTextBox.Buffer.Clear(); +*/ // Set new node activeNode = node; - if (node != null) - { - npcDescTextBox.Text = node.NPC.Headers.GetValueOrDefault("DESC", string.Empty); - npcImageTextBox.Text = node.NPC.Image; - npcScriptTextBox.Text = node.NPC.Code.Replace("\n", "\r\n"); - } + + if (node == null) return; + + _dontRunHandler = true; + + npcDescTextBox.Text = ((LevelNPC)node.NodeObject).Headers.GetValueOrDefault("DESC", string.Empty); + npcImageTextBox.Text = ((LevelNPC)node.NodeObject).Image; + npcScriptTextBox.Buffer.Text = ((LevelNPC)node.NodeObject).Code.Replace("\n", "\r\n"); + + _dontRunHandler = false; } - + private static bool _dontRunHandler = true; private void UpdateActiveNode() { if (activeNode != null) { + state.UpdateNPC(activeNode, - npcScriptTextBox.Text.Replace("\r\n", "\n"), + npcScriptTextBox.Buffer.Text.Replace("\r\n", "\n"), npcImageTextBox.Text.Trim(), npcDescTextBox.Text.Trim(), null); + } } private void SetStatusDescription(string text) { - toolStripStatusLabel1.Text = text; + //TODO: toolStripStatusLabel1.Text = text; } private void NpcDescTextBox_TextChanged(object sender, EventArgs e) { - var s = (TextBox)sender; - if (s.Modified) + if (_dontRunHandler) return; + Entry s = (Entry)sender; + //if (s.Modified) { UpdateActiveNode(); - if (activeNode != null) - activeNode.UpdateDescription(); + activeNode?.UpdateDescription(); } } private void NpcScriptTextBox_TextChanged(object sender, EventArgs e) { - var s = (TextBox)sender; - if (s.Modified) + if (_dontRunHandler) return; + Buffer s = (Buffer)sender; + + //if (s.Modified) + { UpdateActiveNode(); + } } private void NpcImageTextBox_TextChanged(object sender, EventArgs e) { - var s = (TextBox)sender; - if (s.Modified) + if (_dontRunHandler) return; + Entry s = (Entry)sender; + //if (s.Modified) + { UpdateActiveNode(); + } } #endregion #region Toolbar Options + + private static IEnumerable GetFilesRecursive(string sDir, string pattern) + { + try + { + List files = Directory.GetFiles(sDir, pattern).ToList(); + + foreach (string d in Directory.GetDirectories(sDir)) + { + files.AddRange(GetFilesRecursive(d, pattern));; + } + + return files; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + + } + return null; + } private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { - using (var fbd = new FolderBrowserDialog()) + //using (var fbd = new FolderBrowserDialog()) { - DialogResult result = fbd.ShowDialog(); + //DialogResult result = fbd.ShowDialog(); - if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) + //if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { // TODO(joey): are you sure you want to discard changes? // reset state SetActiveNode(null); - state.nodeList.Clear(); - state.levelChangeList.Clear(); - state.npcChangeList.Clear(); - treeView1.Nodes.Clear(); + state.NodeList.Clear(); + state.LevelChangeList.Clear(); + state.NpcChangeList.Clear(); + treeView1.NodeStore.Clear(); - state.baseDir = fbd.SelectedPath; - string[] files = Directory.GetFiles(state.baseDir, "*.nw").Select(file => Path.GetFileName(file)).ToArray(); + //state.BaseDir = fbd.SelectedPath; + string[] files = GetFilesRecursive(state.BaseDir, "*.nw").ToArray(); if (files.Length > 0) { // create nodes foreach (string file in files) - state.nodeList.Add(new LevelNode(state.baseDir, file)); + state.NodeList.Add(new UINode(state.BaseDir, file)); // read all levels - foreach (LevelNode node in state.nodeList) - node.Load(); + //foreach (UINode node in state.NodeList) + // node.Load(); // sort the nodes (may move into RedrawNodes) - state.nodeList.Sort(new LevelNodeSorter()); + state.NodeList.Sort(new LevelNodeSorter()); RedrawNodes(); - SetStatusDescription(string.Format("Loaded folder {0} with {1} levels", state.baseDir, files.Length)); + SetStatusDescription(string.Format("Loaded folder {0} with {1} levels", state.BaseDir, files.Length)); } - else SetStatusDescription(string.Format("No levels found in {0}", state.baseDir)); + else SetStatusDescription(string.Format("No levels found in {0}", state.BaseDir)); } } } - +/* + TODO: private void ReloadToolStripMenuItem_Click(object sender, EventArgs e) { if (activeNode != null) @@ -282,19 +352,19 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e) } private void OptionsShowEmptyLevelsMenuItem_CheckedChanged(object sender, EventArgs e) { - state.showEmptyLevels = optionsShowEmptyLevelsMenuItem.Checked; + state.ShowEmptyLevels = optionsShowEmptyLevelsMenuItem.Checked; RedrawNodes(); } private void OptionsShowCompletedMenuItem_CheckedChanged(object sender, EventArgs e) { - state.showCompletedNpcs = optionsShowCompleteMenuItem.Checked; + state.ShowCompletedNpcs = optionsShowCompleteMenuItem.Checked; RedrawNodes(); } private void OptionsShowEmptyNpcsMenuItem_CheckedChanged(object sender, EventArgs e) { - state.showEmptyNpcs = optionsShowEmptyNpcsMenuItem.Checked; + state.ShowEmptyNpcs = optionsShowEmptyNpcsMenuItem.Checked; RedrawNodes(); } @@ -302,9 +372,11 @@ private void OptionReplaceMatchImagesMenuItem_CheckedChanged(object sender, Even { state.matchImageNames = optionReplaceMatchImagesMenuItem.Checked; } + */ #endregion #region Script filtering + /* private Timer m_delayedTextChangedTimer; private string m_searchText; @@ -328,48 +400,53 @@ private void SearchBox_TextChanged(object sender, EventArgs e) m_delayedTextChangedTimer.Start(); } } + */ #endregion + NodeStore store; + NodeStore Store => store ??= new NodeStore(typeof(UINode)); private void RedrawNodes() { - var nodes = state.nodeList.AsEnumerable(); + IEnumerable nodes = state.NodeList.AsEnumerable(); - if (!state.showEmptyLevels) - nodes = nodes.Where(n => n.ChildrenNodes.Count > 0); + if (!state.ShowEmptyLevels) + nodes = nodes.Where(n => n.ChildCount > 0); - m_searchText = searchBox.Text.Replace("\r\n", "\n"); + //m_searchText = searchBox.Text.Replace("\r\n", "\n"); - treeView1.Nodes.Clear(); - treeView1.BeginUpdate(); + //treeView1.Nodes.Clear(); + //treeView1.BeginUpdate(); - foreach (var n in nodes) + foreach (UINode n in nodes) { RedrawLevelNode(n); - if (n.Nodes.Count > 0) - treeView1.Nodes.Add(n); + treeView1.NodeStore.AddNode(n); } - treeView1.EndUpdate(); + //treeView1.EndUpdate(); // Try to preserve the current position in the treeview if (activeNode != null && activeNode.Parent != null) { + /* if (activeNode.Parent.LastNode != null) activeNode.Parent.LastNode.EnsureVisible(); else activeNode.Parent.EnsureVisible(); activeNode.EnsureVisible(); + */ } } - private void RedrawLevelNode(LevelNode node) + private void RedrawLevelNode(UINode node) { + /* var childNodes = node.ChildrenNodes.AsEnumerable(); - if (!state.showCompletedNpcs) + if (!state.ShowCompletedNpcs) childNodes = childNodes.Where(n => !n.NPC.Headers.ContainsKey("MARKED")); - if (!state.showEmptyNpcs) + if (!state.ShowEmptyNpcs) childNodes = childNodes.Where(n => n.NPC.Code.Trim().Length > 0); if (m_searchText.Length > 0) @@ -377,22 +454,29 @@ private void RedrawLevelNode(LevelNode node) node.Nodes.Clear(); node.Nodes.AddRange(childNodes.ToArray()); + */ } - private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) + private void MainWindow_FormClosing(object sender, DeleteEventArgs e) { - var modFileCount = state.levelChangeList.Count; - + int modFileCount = state.LevelChangeList.Count; + bool cancel = false; if (modFileCount > 0) { - var window = MessageBox.Show("You still have " + modFileCount.ToString() + " levels with unsaved changes! Click No, and save your changes!", "Close the application without saving?", MessageBoxButtons.YesNo); - e.Cancel = (window == DialogResult.No); + //TODO: var window = MessageBox.Show("You still have " + modFileCount.ToString() + " levels with unsaved changes! Click No, and save your changes!", "Close the application without saving?", MessageBoxButtons.YesNo); + cancel = false; //TODO: (window == DialogResult.No); + } + + if (!cancel) + { + Quit(); } } - private void ExitToolStripMenuItem_Click(object sender, EventArgs e) + private void TreeView1OnPopupMenu(object o, PopupMenuArgs args) { - Close(); + + throw new NotImplementedException(); } } } diff --git a/src/Forms/ReplaceScriptsForm.cs b/src/Forms/ReplaceScriptsForm.cs index 006e75f..d6a9d97 100644 --- a/src/Forms/ReplaceScriptsForm.cs +++ b/src/Forms/ReplaceScriptsForm.cs @@ -42,7 +42,7 @@ private void GetIdenticalScripts() bool variableImage = false; - foreach (var levelNode in state.nodeList) + foreach (var levelNode in state.NodeList) { var childNodes = levelNode.ChildrenNodes.AsEnumerable() .Where(n => n.NPC.Code == originalCode); diff --git a/src/Levels/GameLevel.cs b/src/Levels/GameLevel.cs index 0473ef5..9e68ccd 100644 --- a/src/Levels/GameLevel.cs +++ b/src/Levels/GameLevel.cs @@ -1,10 +1,11 @@ using System.Collections.Generic; using System.IO; using System.Text; +using LevelScriptEditor.UI; namespace LevelScriptEditor.Levels { - public class GameLevel + public class GameLevel : INodeObject { private static readonly string BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; private readonly string filePath; diff --git a/src/Levels/LevelNPC.cs b/src/Levels/LevelNPC.cs index a2296fc..479c392 100644 --- a/src/Levels/LevelNPC.cs +++ b/src/Levels/LevelNPC.cs @@ -1,9 +1,10 @@ using System.Collections.Generic; using System.Text; +using LevelScriptEditor.UI; namespace LevelScriptEditor.Levels { - public class LevelNPC + public class LevelNPC : INodeObject { const string META_PREFIX = "//#["; const char META_SEP = ':'; diff --git a/src/Program.cs b/src/Program.cs index 3934b55..b5038b0 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,21 +1,24 @@ using LevelScriptEditor.Forms; using System; -using System.Windows.Forms; +using Gtk; +using static Gtk.Application; + namespace LevelScriptEditor { - static class Program + internal static class Program { /// /// The main entry point for the application. /// [STAThread] - static void Main() + private static void Main(string[] args) { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainWindow()); + Init(); + + MainWindow.Instance.ShowAll(); + + Run(); } } } diff --git a/src/State/GlobalState.cs b/src/State/GlobalState.cs index 46429f9..032cf6f 100644 --- a/src/State/GlobalState.cs +++ b/src/State/GlobalState.cs @@ -1,26 +1,27 @@ using LevelScriptEditor.Levels; using LevelScriptEditor.UI; using System.Collections.Generic; +using LevelScriptEditor.Levels; namespace LevelScriptEditor.State { public class GlobalState { - public string baseDir = ""; + public string BaseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location); - public bool showCompletedNpcs = true; - public bool showEmptyLevels = false; - public bool showEmptyNpcs = false; - public bool matchImageNames = true; + public bool ShowCompletedNpcs = true; + public bool ShowEmptyLevels = true; + public bool ShowEmptyNpcs = false; + public bool MatchImageNames = true; - public List nodeList = new List(); + public readonly List NodeList = new(); - public HashSet levelChangeList = new HashSet(); - public HashSet npcChangeList = new HashSet(); + public readonly HashSet LevelChangeList = new(); + public readonly HashSet NpcChangeList = new(); - public bool UpdateNPC(LevelNPCNode npcNode, string code, string image, string desc, bool? markComplete) + public bool UpdateNPC(UINode npcNode, string code, string image, string desc, bool? markComplete) { - var npc = npcNode.NPC; + LevelNPC npc = (LevelNPC)npcNode.NodeObject; bool changed = false; if (code != null && npc.Code != code) @@ -50,17 +51,17 @@ public bool UpdateNPC(LevelNPCNode npcNode, string code, string image, string de if (markComplete != npcMarkComplete) { if (markComplete == true) - npcNode.NPC.Headers["MARKED"] = "true"; + ((LevelNPC)npcNode.NodeObject).Headers["MARKED"] = "true"; else - npcNode.NPC.Headers.Remove("MARKED"); + ((LevelNPC)npcNode.NodeObject).Headers.Remove("MARKED"); changed = true; } } if (changed) { - npcChangeList.Add(npcNode); - levelChangeList.Add(npc.Level); + NpcChangeList.Add(npcNode); + LevelChangeList.Add(npc.Level); } return changed; @@ -68,11 +69,11 @@ public bool UpdateNPC(LevelNPCNode npcNode, string code, string image, string de public void SaveLevels() { - foreach (var levelChange in levelChangeList) + foreach (GameLevel levelChange in LevelChangeList) levelChange.Save(); - levelChangeList.Clear(); - npcChangeList.Clear(); + LevelChangeList.Clear(); + NpcChangeList.Clear(); } } } diff --git a/src/UI/LevelNPCNode.cs b/src/UI/LevelNPCNode.cs index 2a73758..596948d 100644 --- a/src/UI/LevelNPCNode.cs +++ b/src/UI/LevelNPCNode.cs @@ -1,28 +1,34 @@ using LevelScriptEditor.Levels; -using System.Windows.Forms; +using Gtk; namespace LevelScriptEditor.UI { public class LevelNPCNode : TreeNode { - private readonly LevelNPC npc = null; - private readonly int npcId = 0; + private readonly int _npcId = 0; + private string _text = null; - public LevelNPC NPC { get => npc; } + public LevelNPC NPC { get; } = null; + + [TreeNodeValue (Column=0)] + public string Text => _text; - public LevelNPCNode(LevelNPC levelNPC, int npcId) - : base() + [TreeNodeValue (Column=1)] + public string test = ""; + + public LevelNPCNode(LevelNPC levelNPC, int npcId) : base() { - this.npc = levelNPC; - this.npcId = npcId; + NPC = levelNPC; + _npcId = npcId; UpdateDescription(); } public void UpdateDescription() { - var newDesc = (npc.Headers.ContainsKey("DESC") && npc.Headers["DESC"] != string.Empty) ? npc.Headers["DESC"] : "NPC " + npcId; - if (newDesc != Text) - Text = newDesc; + var newDesc = NPC.Headers.ContainsKey("DESC") && NPC.Headers["DESC"] != string.Empty ? NPC.Headers["DESC"] : "NPC " + _npcId; + + if (newDesc != _text) + _text = newDesc; } } } diff --git a/src/UI/LevelNode.cs b/src/UI/LevelNode.cs index 12f5d12..9cf7d17 100644 --- a/src/UI/LevelNode.cs +++ b/src/UI/LevelNode.cs @@ -1,38 +1,46 @@ using LevelScriptEditor.Levels; using System.Collections.Generic; using System.IO; -using System.Windows.Forms; +using Gtk; namespace LevelScriptEditor.UI { public class LevelNode : TreeNode { - private string filePath = string.Empty; - private GameLevel level; + private string filePath; - public GameLevel GameLevel { get => level; } + public bool Loaded => GameLevel != null; - public List ChildrenNodes = new List(); + public GameLevel GameLevel { get; private set; } = null; + [TreeNodeValue (Column=0)] + public string Text { get; set; } + + [TreeNodeValue (Column=1)] + public string FilePath => filePath; public LevelNode(string baseDir, string name) - : base(name) + /*: base(name)*/ { - this.filePath = Path.Combine(baseDir, name); + Text = name; + filePath = Path.Combine(baseDir, name); } + + //public List ChildrenNodes = new List(); + public void Load() { - Nodes.Clear(); - ChildrenNodes.Clear(); + //Nodes.Clear(); + //ChildrenNodes.Clear(); - level = GameLevel.Load(filePath); - if (level != null) + GameLevel = GameLevel.Load(filePath); + if (GameLevel == null) return; + + for (int i = 0; i < GameLevel.NpcList.Count; i++) { - for (int i = 0; i < level.NpcList.Count; i++) - { - var npc = level.NpcList[i]; - ChildrenNodes.Add(new LevelNPCNode(npc, i + 1)); - } + LevelNPC npc = GameLevel.NpcList[i]; + + /*ChildrenNodes.*/AddChild(new LevelNPCNode(npc, i + 1)); } } } diff --git a/src/UI/LevelNodeSorter.cs b/src/UI/LevelNodeSorter.cs index f30bb14..5f1e581 100644 --- a/src/UI/LevelNodeSorter.cs +++ b/src/UI/LevelNodeSorter.cs @@ -1,18 +1,14 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace LevelScriptEditor.UI { - public class LevelNodeSorter : IComparer + public class LevelNodeSorter : IComparer { - public LevelNodeSorter() { } - - public int Compare(LevelNode tx, LevelNode ty) + public int Compare(UINode tx, UINode ty) { - var check = (tx.Nodes.Count > 0 ? 0 : 1) - (ty.Nodes.Count > 0 ? 0 : 1); - if (check != 0) - return check; - - return string.Compare(tx.Text, ty.Text); + int check = (tx.ChildCount > 0 ? 0 : 1) - (ty.ChildCount > 0 ? 0 : 1); + return check != 0 ? check : string.CompareOrdinal(tx.Text, ty.Text); } } } diff --git a/src/UI/UINode.cs b/src/UI/UINode.cs new file mode 100644 index 0000000..cd9b610 --- /dev/null +++ b/src/UI/UINode.cs @@ -0,0 +1,58 @@ +using LevelScriptEditor.Levels; +using System.Collections.Generic; +using System.IO; +using Gtk; + +namespace LevelScriptEditor.UI +{ + [TreeNode (ListOnly=false)] + public class UINode : TreeNode + { + public bool Loaded => NodeObject != null; + private int _npcId = 0; + + public INodeObject NodeObject { get; private set; } = null; + + [TreeNodeValue (Column=0)] + public string Text { get; set; } + + public UINode(string baseDir, string filePath) + { + Text = filePath.Replace($"{baseDir}{Path.DirectorySeparatorChar}",""); + //string filePath = Path.Combine(baseDir, name); + NodeObject = GameLevel.Load(filePath); + if (NodeObject == null) return; + + for (int i = 0; i < ((GameLevel)NodeObject).NpcList.Count; i++) + { + LevelNPC npc = ((GameLevel)NodeObject).NpcList[i]; + + AddChild(new UINode(npc, i + 1)); + } + } + + private UINode(INodeObject levelNPC, int npcId) : base() + { + NodeObject = levelNPC; + _npcId = npcId; + UpdateDescription(); + } + + public void UpdateDescription() + { + string newDesc = ((LevelNPC)NodeObject).Headers.ContainsKey("DESC") && ((LevelNPC)NodeObject).Headers["DESC"] != string.Empty ? ((LevelNPC)NodeObject).Headers["DESC"] : $"NPC {_npcId}"; + if (newDesc != Text) + Text = newDesc; + } + + public void Save() + { + if (Loaded) + ((GameLevel)NodeObject).Save(); + } + } + + public interface INodeObject + { + } +} \ No newline at end of file