From f23ef7d50eb78153fad08fc227461ae230d3fff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Thu, 25 Feb 2021 00:04:55 +0100 Subject: [PATCH 1/5] Begin GtkSharp refactoring --- LevelScriptEditor.csproj | 17 +- LevelScriptEditor.sln.DotSettings | 2 + src/Forms/MainWindow.Designer.cs | 221 ++++++++++++++++-------- src/Forms/MainWindow.cs | 271 +++++++++++++++++++----------- src/Levels/GameLevel.cs | 3 +- src/Levels/LevelNPC.cs | 3 +- src/Program.cs | 17 +- src/State/GlobalState.cs | 33 ++-- src/UI/LevelNPCNode.cs | 23 ++- src/UI/LevelNode.cs | 43 ++--- src/UI/LevelNodeSorter.cs | 16 +- src/UI/UINode.cs | 57 +++++++ 12 files changed, 474 insertions(+), 232 deletions(-) create mode 100644 LevelScriptEditor.sln.DotSettings create mode 100644 src/UI/UINode.cs diff --git a/LevelScriptEditor.csproj b/LevelScriptEditor.csproj index 910f1d6..7130e44 100644 --- a/LevelScriptEditor.csproj +++ b/LevelScriptEditor.csproj @@ -2,10 +2,21 @@ WinExe - net5.0-windows - true + net6.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/src/Forms/MainWindow.Designer.cs b/src/Forms/MainWindow.Designer.cs index b582e9f..b35cf30 100644 --- a/src/Forms/MainWindow.Designer.cs +++ b/src/Forms/MainWindow.Designer.cs @@ -1,4 +1,7 @@ -namespace LevelScriptEditor.Forms +using Gdk; +using Gtk; + +namespace LevelScriptEditor.Forms { partial class MainWindow { @@ -29,26 +32,29 @@ 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(); - this.reloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator(); - this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsShowEmptyLevelsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsShowEmptyNpcsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsShowCompleteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.treeView1 = new System.Windows.Forms.TreeView(); - 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.menuStrip1 = new MenuStrip(); + this.fileToolStripMenuItem = new ToolStripMenuItem(); + this.openToolStripMenuItem = new ToolStripMenuItem(); + this.reloadToolStripMenuItem = new ToolStripMenuItem(); + this.toolStripSeparator = new ToolStripSeparator(); + this.saveToolStripMenuItem = new ToolStripMenuItem(); + this.toolStripSeparator1 = new ToolStripSeparator(); + this.exitToolStripMenuItem = new ToolStripMenuItem(); + this.optionsStripMenuItem = new ToolStripMenuItem(); + this.optionsShowEmptyLevelsMenuItem = new ToolStripMenuItem(); + this.optionsShowEmptyNpcsMenuItem = new ToolStripMenuItem(); + this.optionsShowCompleteMenuItem = new ToolStripMenuItem(); + */ + this.treeView1 = new NodeView(); + /* + this.statusStrip1 = new StatusStrip(); + this.toolStripStatusLabel1 = new ToolStripStatusLabel(); + this.npcScriptTextBox = new TextBox(); + this.label1 = new Label(); + this.npcImageTextBox = new TextBox(); + this.label2 = new Label(); + this.npcDescTextBox = new TextBox(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -56,7 +62,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); @@ -67,7 +73,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, @@ -83,7 +89,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"; @@ -106,7 +112,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); @@ -124,7 +130,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}); @@ -152,25 +158,91 @@ 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(266, 26); this.optionsShowCompleteMenuItem.Text = "Show Completed NPCS"; this.optionsShowCompleteMenuItem.CheckedChanged += new System.EventHandler(this.OptionsShowCompletedMenuItem_CheckedChanged); + */ // // treeView1 // - this.treeView1.Location = new System.Drawing.Point(12, 44); + //this.treeView1.Location = new System.Drawing.Point(12, 44); this.treeView1.Name = "treeView1"; - this.treeView1.Size = new System.Drawing.Size(270, 733); - 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.SetSizeRequest(270,733);//.Size = new System.Drawing.Size(270, 733); + //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; + //Add (this.treeView1); + + var column = this.treeView1.AppendColumn ("", 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(2, 1, false); + + Table ServersFrameTable = new Table(1, 2, false); + + ServersFrameTable.RowSpacing = 1; + Label spacer = new Label(); + spacer.SetSizeRequest(10, 1); + ServersFrameTable.Attach(spacer, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 5, 1); + + ScrolledWindow ServerListScrolledWindow = new global::Gtk.ScrolledWindow(); + ServerListScrolledWindow.Name = "GtkScrolledWindow"; + ServerListScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + + // Container child GtkScrolledWindow.Gtk.Container+ContainerChild + + ServerListScrolledWindow.Add(this.treeView1); + + Frame ServerListFrame = new Frame(); + //ServerListFrame.Add(ServerListScrolledWindow); + + Frame ServerInfoFrame = new Frame(); + + ServersFrameTable.Attach(ServerInfoFrame, 1, 2, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 1); + ServersFrameTable.Attach(ServerListScrolledWindow, 0, 1, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 1); + + HBox hbox = new HBox(true, 5); + 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(ServersFrameTable, 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, 780); this.statusStrip1.Name = "statusStrip1"; @@ -185,9 +257,9 @@ private void InitializeComponent() // // npcScriptTextBox // - 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.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) + | AnchorStyles.Left) + | AnchorStyles.Right))); this.npcScriptTextBox.Location = new System.Drawing.Point(288, 77); this.npcScriptTextBox.Multiline = true; this.npcScriptTextBox.Name = "npcScriptTextBox"; @@ -197,8 +269,8 @@ private void InitializeComponent() // // 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.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) + | AnchorStyles.Left))); this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(288, 47); this.label1.Name = "label1"; @@ -216,8 +288,8 @@ private void InitializeComponent() // // 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.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) + | AnchorStyles.Left))); this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(607, 47); this.label2.Name = "label2"; @@ -227,8 +299,8 @@ private void InitializeComponent() // // 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.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"; @@ -239,7 +311,7 @@ private void InitializeComponent() // MainWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScaleMode = AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1089, 802); this.Controls.Add(this.npcDescTextBox); this.Controls.Add(this.label2); @@ -250,40 +322,55 @@ 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; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator; - 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 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 System.Windows.Forms.ToolStripMenuItem reloadToolStripMenuItem; - private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; - private System.Windows.Forms.ToolStripMenuItem optionsStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem optionsShowEmptyLevelsMenuItem; - private System.Windows.Forms.ToolStripMenuItem optionsShowCompleteMenuItem; - private System.Windows.Forms.ToolStripMenuItem optionsShowEmptyNpcsMenuItem; + /* + private MenuStrip menuStrip1; + private ToolStripMenuItem fileToolStripMenuItem; + private ToolStripMenuItem openToolStripMenuItem; + private ToolStripSeparator toolStripSeparator; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripSeparator toolStripSeparator1; + private ToolStripMenuItem exitToolStripMenuItem; + */ + private NodeView treeView1; + //private StatusStrip statusStrip1; + //private TextBox npcScriptTextBox; + private Label label1; + //private TextBox npcImageTextBox; + private Label label2; + /* + private TextBox npcDescTextBox; + private ToolStripMenuItem reloadToolStripMenuItem; + private ToolStripStatusLabel toolStripStatusLabel1; + private ToolStripMenuItem optionsStripMenuItem; + private ToolStripMenuItem optionsShowEmptyLevelsMenuItem; + private ToolStripMenuItem optionsShowCompleteMenuItem; + private ToolStripMenuItem optionsShowEmptyNpcsMenuItem; + */ } } diff --git a/src/Forms/MainWindow.cs b/src/Forms/MainWindow.cs index 6c043c2..5f13628 100644 --- a/src/Forms/MainWindow.cs +++ b/src/Forms/MainWindow.cs @@ -5,102 +5,142 @@ using System.Data; using System.IO; using System.Linq; -using System.Windows.Forms; +using Gdk; +using Gtk; +using LevelScriptEditor.Levels; +using Window = Gtk.Window; +using WindowType = Gtk.WindowType; +using static Gtk.Application; 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(); - + /* + TODO: npcScriptTextBox.AcceptsReturn = true; npcScriptTextBox.AcceptsTab = true; npcScriptTextBox.ScrollBars = ScrollBars.Vertical; + */ + 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; + + Console.WriteLine($@"Select: {node?.NodeObject?.GetType()}"); + if (node != null) { - // Level node - case 0: + switch (node?.NodeObject?.GetType()?.ToString()) { - var node = (LevelNode)e.Node; - if (!node.Loaded) + // Level node + case "LevelScriptEditor.UI.LevelNode": { - node.Load(); - if (e.Action != TreeViewAction.ByKeyboard) - node.Expand(); + + if (!node.Loaded) + { + //node.Load(); + /* + if (e.Action != TreeViewAction.ByKeyboard) + node.Expand(); + */ + + } + + break; } - break; + // NPC node + case "LevelScriptEditor.UI.LevelNPCNode": + SetActiveNode(node); + break; } - - // NPC node - case 1: - SetActiveNode((LevelNPCNode)e.Node); - break; } } - private void TreeView1_MouseDown(object sender, MouseEventArgs e) + private void TreeView1_MouseDown(object sender, WidgetEventArgs e) { - if (e.Button != MouseButtons.Right) - return; + if ((e.Event is EventButton ev) && (ev.Type == EventType.ButtonPress) && (ev.Window == treeView1.BinWindow)) + { + + 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); - if (node_here != null) - { - switch (node_here.Level) - { - // Level node - case 0: - ShowContextMenu((LevelNode)node_here, e); - break; + treeView1.NodeSelection.SelectPath(_path); - // NPC node - case 1: - ShowContextMenu((LevelNPCNode)node_here, e); - break; - } + if (treeView1.NodeSelection.SelectedNode == null) return; + + UINode node = (UINode)treeView1.NodeSelection.SelectedNode; + ShowContextMenu(node, ev); } } - private void ShowContextMenu(LevelNode node, MouseEventArgs e) + private void ShowContextMenu(UINode node, EventButton e) { - //var contextMenuStrip = new ContextMenuStrip(); + Menu menu = new(); + switch (node?.NodeObject?.GetType().ToString()) + { + + case "LevelScriptEditor.Levels.GameLevel": + { + //var contextMenuStrip = new ContextMenuStrip(); + break; + } + case "LevelScriptEditor.Levels.LevelNPC": + { + + MenuItem menu_item = new("Add file"); + menu.AttachToWidget(treeView1, null); + LevelNPCMenu(menu, node); + //menu.Add(menu_item); + menu.ShowAll(); + //menu.Popup (null, null, null, e.Button, e.Time); + menu.PopupAtPointer(e); + //menu.Realize(); + break; + } + default: + Console.WriteLine(node?.NodeObject?.GetType().ToString()); + break; + } + } - 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(); @@ -112,33 +152,35 @@ private void ShowContextMenu(LevelNPCNode node, MouseEventArgs e) SetActiveNode(node); 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(); - + /* + TODO: // Clear fields npcDescTextBox.Clear(); npcImageTextBox.Clear(); npcScriptTextBox.Clear(); - + */ // Set new node activeNode = node; if (node != null) { + /* + TODO: npcDescTextBox.Text = node.NPC.Headers.GetValueOrDefault("DESC", string.Empty); npcImageTextBox.Text = node.NPC.Image; npcScriptTextBox.Text = node.NPC.Code.Replace("\n", "\r\n"); + */ } } @@ -146,82 +188,93 @@ private void UpdateActiveNode() { if (activeNode != null) { + /* + TODO: state.UpdateNPC(activeNode, npcScriptTextBox.Text.Replace("\r\n", "\n"), npcImageTextBox.Text.Trim(), npcDescTextBox.Text.Trim()); + */ } } 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) UpdateActiveNode(); + */ } private void NpcScriptTextBox_TextChanged(object sender, EventArgs e) { + /* var s = (TextBox)sender; if (s.Modified) UpdateActiveNode(); + */ } private void NpcImageTextBox_TextChanged(object sender, EventArgs e) { + /* var s = (TextBox)sender; if (s.Modified) UpdateActiveNode(); + */ } #endregion #region Toolbar Options + 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 = Directory.GetFiles(state.BaseDir, "*.nw").Select(file => System.IO.Path.GetFileName(file)).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) @@ -253,8 +306,8 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { try { - var levelsModified = state.levelChangeList.Count; - var npcsModified = state.npcChangeList.Count; + var levelsModified = state.LevelChangeList.Count; + var npcsModified = state.NpcChangeList.Count; // Save level-change-list state.SaveLevels(); @@ -281,75 +334,95 @@ 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(); } + */ #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); - treeView1.Nodes.Clear(); - treeView1.BeginUpdate(); + //treeView1.Nodes.Clear(); + //treeView1.BeginUpdate(); + - foreach (var n in nodes) + foreach (UINode n in nodes) { RedrawLevelNode(n); - 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); 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 TreeView1OnPopupMenu(object o, PopupMenuArgs args) + { + + throw new NotImplementedException(); } } } diff --git a/src/Levels/GameLevel.cs b/src/Levels/GameLevel.cs index 2465e3f..b617b88 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 37fdf17..a5cb9c0 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 729b8a8..a506fca 100644 --- a/src/State/GlobalState.cs +++ b/src/State/GlobalState.cs @@ -1,32 +1,33 @@ using LevelScriptEditor.UI; using System.Collections.Generic; +using LevelScriptEditor.Levels; namespace LevelScriptEditor.State { public class GlobalState { - public string baseDir = ""; + public string BaseDir = "/home/marlon/Games/graal-stuff/clients/Graal-v2-Win"; - public bool showCompletedNpcs = true; - public bool showEmptyLevels = false; - public bool showEmptyNpcs = false; + public bool ShowCompletedNpcs = true; + public bool ShowEmptyLevels = true; + public bool ShowEmptyNpcs = false; - 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 void UpdateNPC(LevelNPCNode npcNode, string code, string image, string desc) + public void UpdateNPC(UINode npcNode, string code, string image, string desc) { - var npc = npcNode.NPC; + LevelNPC npc = (LevelNPC)npcNode.NodeObject; // Nothing has changed here - var npcDesc = npc.Headers.GetValueOrDefault("DESC", string.Empty); + string npcDesc = npc.Headers.GetValueOrDefault("DESC", string.Empty); if (npc.Code == code && npc.Image == image && npcDesc == desc) return; // Copy changes over - var levelNode = (LevelNode)npcNode.Parent; + var levelNode = (UINode)npcNode.Parent; npc.Code = code; npc.Image = image; npc.Headers["DESC"] = desc; @@ -37,16 +38,16 @@ public void UpdateNPC(LevelNPCNode npcNode, string code, string image, string de if (npcDesc != desc) npcNode.UpdateDescription(); - npcChangeList.Add(npcNode); - levelChangeList.Add(levelNode); + NpcChangeList.Add(npcNode); + LevelChangeList.Add(levelNode); } public void SaveLevels() { - foreach (var levelChange in levelChangeList) + foreach (UINode 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 2fc0c53..663a1fb 100644 --- a/src/UI/LevelNPCNode.cs +++ b/src/UI/LevelNPCNode.cs @@ -1,26 +1,31 @@ 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() { - Text = (npc.Headers.ContainsKey("DESC") && npc.Headers["DESC"] != string.Empty) ? npc.Headers["DESC"] : "NPC " + npcId; + _text = NPC.Headers.ContainsKey("DESC") && NPC.Headers["DESC"] != string.Empty ? NPC.Headers["DESC"] : "NPC " + _npcId; } } } diff --git a/src/UI/LevelNode.cs b/src/UI/LevelNode.cs index 366ee78..004e8c7 100644 --- a/src/UI/LevelNode.cs +++ b/src/UI/LevelNode.cs @@ -1,48 +1,53 @@ using LevelScriptEditor.Levels; using System.Collections.Generic; using System.IO; -using System.Windows.Forms; +using Gtk; namespace LevelScriptEditor.UI { public partial class LevelNode : TreeNode { - private string filePath = string.Empty; - private GameLevel level = null; + private string filePath; - public bool Loaded { get => level != null; } + public bool Loaded => GameLevel != null; + + public GameLevel GameLevel { get; private set; } = null; + [TreeNodeValue (Column=0)] + public string Text { get; set; } + + [TreeNodeValue (Column=1)] + public string FilePath => filePath; - public GameLevel GameLevel { get => level; } - 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 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)); } } public void Save() { if (Loaded) - level.Save(); + GameLevel.Save(); } } } 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..549bb36 --- /dev/null +++ b/src/UI/UINode.cs @@ -0,0 +1,57 @@ +using LevelScriptEditor.Levels; +using System.Collections.Generic; +using System.IO; +using Gtk; + +namespace LevelScriptEditor.UI +{ + 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 name) + { + Text = name; + 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(LevelNPC 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 From 56f49f57fe11fdb6afef5aa5a04a58848f70465c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Thu, 25 Feb 2021 00:07:59 +0100 Subject: [PATCH 2/5] remove junk --- src/State/GlobalState.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/State/GlobalState.cs b/src/State/GlobalState.cs index a506fca..d130591 100644 --- a/src/State/GlobalState.cs +++ b/src/State/GlobalState.cs @@ -6,7 +6,7 @@ namespace LevelScriptEditor.State { public class GlobalState { - public string BaseDir = "/home/marlon/Games/graal-stuff/clients/Graal-v2-Win"; + public string BaseDir = ""; public bool ShowCompletedNpcs = true; public bool ShowEmptyLevels = true; From 422dd112606fbf68948a97696fd8e7c185c7a969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Thu, 25 Feb 2021 17:17:39 +0100 Subject: [PATCH 3/5] Recursive --- src/Forms/MainWindow.Designer.cs | 21 ++++++++++++++++----- src/UI/UINode.cs | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Forms/MainWindow.Designer.cs b/src/Forms/MainWindow.Designer.cs index 1403976..fb55bd2 100644 --- a/src/Forms/MainWindow.Designer.cs +++ b/src/Forms/MainWindow.Designer.cs @@ -1,4 +1,5 @@ -using Gdk; +using System; +using Gdk; using Gtk; namespace LevelScriptEditor.Forms @@ -206,6 +207,7 @@ private void InitializeComponent() 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; @@ -213,6 +215,7 @@ private void InitializeComponent() 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; @@ -220,13 +223,21 @@ private void InitializeComponent() // Create our TreeView and add it as our child widget this.treeView1.NodeStore = Store; - //Add (this.treeView1); - - var column = this.treeView1.AppendColumn ("", new Gtk.CellRendererText (), "text", 0); + + 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 (); diff --git a/src/UI/UINode.cs b/src/UI/UINode.cs index 77ecf4c..aaf56b9 100644 --- a/src/UI/UINode.cs +++ b/src/UI/UINode.cs @@ -5,6 +5,7 @@ namespace LevelScriptEditor.UI { + [TreeNode (ListOnly=false)] public class UINode : TreeNode { public bool Loaded => NodeObject != null; From 444b44ff4aefeafffacacf596f6e8e4307f405fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Thu, 25 Feb 2021 20:20:53 +0100 Subject: [PATCH 4/5] - --- src/Forms/ReplaceScriptsForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Forms/ReplaceScriptsForm.cs b/src/Forms/ReplaceScriptsForm.cs index 427ddd4..1286cd5 100644 --- a/src/Forms/ReplaceScriptsForm.cs +++ b/src/Forms/ReplaceScriptsForm.cs @@ -36,7 +36,7 @@ private void GetIdenticalScripts() { identicalScripts.Clear(); - foreach (var levelNode in state.nodeList) + foreach (var levelNode in state.NodeList) { var childNodes = levelNode.ChildrenNodes.AsEnumerable() .Where(n => n.NPC.Code == originalCode) From 852d67b335fc75a6e9ec7de364479e893f2ab580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Fri, 26 Feb 2021 00:13:34 +0100 Subject: [PATCH 5/5] Fix script editing --- LevelScriptEditor.csproj | 1 + global.json | 5 + src/Forms/MainWindow.Designer.cs | 179 +++++++++++++++++++------------ src/Forms/MainWindow.cs | 129 +++++++++++----------- src/UI/UINode.cs | 4 +- 5 files changed, 181 insertions(+), 137 deletions(-) create mode 100644 global.json diff --git a/LevelScriptEditor.csproj b/LevelScriptEditor.csproj index 783642e..d4de372 100644 --- a/LevelScriptEditor.csproj +++ b/LevelScriptEditor.csproj @@ -10,6 +10,7 @@ + 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 fb55bd2..d5887f3 100644 --- a/src/Forms/MainWindow.Designer.cs +++ b/src/Forms/MainWindow.Designer.cs @@ -1,6 +1,8 @@ using System; using Gdk; using Gtk; +using GtkSource; +using LevelScriptEditor.State; namespace LevelScriptEditor.Forms { @@ -50,15 +52,19 @@ private void InitializeComponent() this.optionsReplaceStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionReplaceMatchImagesMenuItem = new System.Windows.Forms.ToolStripMenuItem(); */ - this.treeView1 = new NodeView(); + 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(); @@ -201,7 +207,7 @@ private void InitializeComponent() //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.SetSizeRequest(270, 632); + //this.treeView1.TabIndex = 1; //this.treeView1.AfterSelect += new TreeViewEventHandler(this.TreeView1_AfterSelect); this.treeView1.NodeSelection.Changed += this.TreeView1_AfterSelect; @@ -220,10 +226,9 @@ private void InitializeComponent() 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); @@ -233,6 +238,7 @@ private void InitializeComponent() }; test.ShowAll(); + */ var column = this.treeView1.AppendColumn ("Levels", new Gtk.CellRendererText (), "text", 0); column.SortIndicator = true; column.SortOrder = SortType.Ascending; @@ -242,41 +248,55 @@ private void InitializeComponent() //treeView1.AppendColumn ("Song Title", new Gtk.CellRendererText (), "text", 1); this.treeView1.ShowAll (); - Table table = new Table(2, 1, false); + Table table = new Table(1, 1, false); - Table ServersFrameTable = new Table(1, 2, false); + //Table ServersFrameTable = new Table(1, 2, true); + HPaned mainPane = new HPaned(); + mainPane.Expand = true; - ServersFrameTable.RowSpacing = 1; - Label spacer = new Label(); - spacer.SetSizeRequest(10, 1); - ServersFrameTable.Attach(spacer, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 5, 1); - - ScrolledWindow ServerListScrolledWindow = new global::Gtk.ScrolledWindow(); - ServerListScrolledWindow.Name = "GtkScrolledWindow"; - ServerListScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); - // Container child GtkScrolledWindow.Gtk.Container+ContainerChild + ScrolledWindow npcListScrolledWindow = new global::Gtk.ScrolledWindow(); + npcListScrolledWindow.Name = "GtkScrolledWindow"; + npcListScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + npcListScrolledWindow.Add(this.treeView1); + npcListScrolledWindow.SetSizeRequest(270, 632); - ServerListScrolledWindow.Add(this.treeView1); + ScrolledWindow npcScriptTextBoxScrolledWindow = new global::Gtk.ScrolledWindow(); + npcScriptTextBoxScrolledWindow.Name = "ServerInfoScrolledWindow"; + npcScriptTextBoxScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1)); + npcScriptTextBoxScrolledWindow.Add(this.npcScriptTextBox); + npcScriptTextBoxScrolledWindow.Expand = true; - Frame ServerListFrame = new Frame(); - //ServerListFrame.Add(ServerListScrolledWindow); - - Frame ServerInfoFrame = new Frame(); - - ServersFrameTable.Attach(ServerInfoFrame, 1, 2, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 1); - ServersFrameTable.Attach(ServerListScrolledWindow, 0, 1, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 1); - - HBox hbox = new HBox(true, 5); + 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); + //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(ServersFrameTable, 0, 1, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 5); + table.Attach(mainPane, 0, 1, 0, 1, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Expand, 5, 5); this.Add(table); /* @@ -296,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 = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) - | 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 = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Bottom) - | 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 = ((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.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 // @@ -417,11 +453,14 @@ private void InitializeComponent() 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; diff --git a/src/Forms/MainWindow.cs b/src/Forms/MainWindow.cs index cc89d74..bb9ca0a 100644 --- a/src/Forms/MainWindow.cs +++ b/src/Forms/MainWindow.cs @@ -7,10 +7,12 @@ using System.Linq; 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 { @@ -31,54 +33,50 @@ private void TreeView1_AfterSelect(object o, EventArgs args) { NodeSelection selection = (NodeSelection) o; UINode node = (UINode)selection.SelectedNode; + + if (node == null) return; - Console.WriteLine($@"Select: {node?.NodeObject?.GetType()}"); - if (node != null) + switch (node?.NodeObject?.GetType()?.ToString()) { - switch (node?.NodeObject?.GetType()?.ToString()) + // Level node + case "LevelScriptEditor.Levels.GameLevel": { - // Level node - case "LevelScriptEditor.UI.LevelNode": - { - if (!node.Loaded) - { - //node.Load(); - /* + if (!node.Loaded) + { + //node.Load(); + /* if (e.Action != TreeViewAction.ByKeyboard) node.Expand(); */ - } - - break; } - // NPC node - case "LevelScriptEditor.UI.LevelNPCNode": - SetActiveNode(node); - break; + break; } + + // NPC node + case "LevelScriptEditor.Levels.LevelNPC": + SetActiveNode(node); + break; } } private void TreeView1_MouseDown(object sender, WidgetEventArgs e) { - if ((e.Event is EventButton ev) && (ev.Type == EventType.ButtonPress) && (ev.Window == treeView1.BinWindow)) - { - - if (ev.Button != 3) - return; + if (e.Event is not EventButton ev || ev.Type != EventType.ButtonPress || ev.Window != treeView1.BinWindow) return; + + if (ev.Button != 3) + return; - treeView1.GetPathAtPos((int) ev.X, (int) ev.Y, out TreePath _path); + treeView1.GetPathAtPos((int) ev.X, (int) ev.Y, out TreePath path); - treeView1.NodeSelection.SelectPath(_path); + treeView1.NodeSelection.SelectPath(path); - if (treeView1.NodeSelection.SelectedNode == null) return; + if (treeView1.NodeSelection.SelectedNode == null) return; - UINode node = (UINode)treeView1.NodeSelection.SelectedNode; - ShowContextMenu(node, ev); - } + UINode node = (UINode)treeView1.NodeSelection.SelectedNode; + ShowContextMenu(node, ev); } private void ShowContextMenu(UINode node, EventButton e) @@ -98,11 +96,11 @@ private void ShowContextMenu(UINode node, EventButton e) MenuItem menu_item = new("Add file"); menu.AttachToWidget(treeView1, null); LevelNPCMenu(menu, node); - //menu.Add(menu_item); + menu.ShowAll(); - //menu.Popup (null, null, null, e.Button, e.Time); + menu.PopupAtPointer(e); - //menu.Realize(); + break; } default: @@ -163,38 +161,38 @@ private void SetActiveNode(UINode node) // Save current node changes if (activeNode != null) UpdateActiveNode(); - /* - TODO: + // 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) - { - /* - TODO: - 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) { - /* - TODO: + state.UpdateNPC(activeNode, - npcScriptTextBox.Text.Replace("\r\n", "\n"), + npcScriptTextBox.Buffer.Text.Replace("\r\n", "\n"), npcImageTextBox.Text.Trim(), npcDescTextBox.Text.Trim(), null); - */ + } } @@ -205,33 +203,34 @@ private void SetStatusDescription(string 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 diff --git a/src/UI/UINode.cs b/src/UI/UINode.cs index aaf56b9..cd9b610 100644 --- a/src/UI/UINode.cs +++ b/src/UI/UINode.cs @@ -31,7 +31,7 @@ public UINode(string baseDir, string filePath) } } - private UINode(LevelNPC levelNPC, int npcId) : base() + private UINode(INodeObject levelNPC, int npcId) : base() { NodeObject = levelNPC; _npcId = npcId; @@ -40,7 +40,7 @@ private UINode(LevelNPC levelNPC, int npcId) : base() public void UpdateDescription() { - string newDesc = (((LevelNPC)NodeObject).Headers.ContainsKey("DESC") && ((LevelNPC)NodeObject).Headers["DESC"] != string.Empty) ? ((LevelNPC)NodeObject).Headers["DESC"] : $"NPC {_npcId}"; + string newDesc = ((LevelNPC)NodeObject).Headers.ContainsKey("DESC") && ((LevelNPC)NodeObject).Headers["DESC"] != string.Empty ? ((LevelNPC)NodeObject).Headers["DESC"] : $"NPC {_npcId}"; if (newDesc != Text) Text = newDesc; }