private void BtnAdd_Click(object sender, EventArgs e) { switch (selectionMode) { case 0: frmChromeEditorAddSub addSubWin = new frmChromeEditorAddSub(oraMod, dic[chromeList.SelectedNode]); if (addSubWin.ShowDialog() == DialogResult.OK) { MiniYamlNode miniYamlNode = new MiniYamlNode() { Name = addSubWin.ChromeName, Value = addSubWin.Coord }; dic[chromeList.SelectedNode].ChildNodes.Add(miniYamlNode); var treeNode = chromeList.SelectedNode.Nodes.Add(addSubWin.ChromeName); dic.Add(treeNode, miniYamlNode); chromeYaml.Save(); } break; case 1: frmChromeEditorAdd addWin = new frmChromeEditorAdd(oraMod, chromeYaml); if (addWin.ShowDialog() == DialogResult.OK) { MiniYamlNode miniYamlNode = new MiniYamlNode() { Name = addWin.ChromeName, Value = addWin.Resource }; chromeYaml.Nodes.Add(miniYamlNode); var treeNode = chromeList.SelectedNode.Nodes.Add(addWin.ChromeName); dic.Add(treeNode, miniYamlNode); chromeYaml.Save(); } break; } }
private void ChromeList_AfterSelect(object sender, TreeViewEventArgs e) { if (dic.ContainsKey(e.Node)) { MiniYamlNode miniYamlNode = dic[e.Node]; string miniYamlNodeValue = miniYamlNode.Value.Trim(); if (miniYamlNodeValue.Where(o => o == ',').Count() == 3) { selectionMode = -1; btnAdd.Enabled = false; btnDelete.Enabled = true; var token = miniYamlNode.Value.Trim().Split(','); Bitmap bitmap = new Bitmap(oraMod.Manifest.Resources[miniYamlNode.ParentNode.Value.Trim()]); var bitmapData = bitmap.LockBits(new Rectangle( int.Parse(token[0]), int.Parse(token[1]), int.Parse(token[2]), int.Parse(token[3])), System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat); bitmap.UnlockBits(bitmapData); //clip the image try { Bitmap newBitmap = new Bitmap(int.Parse(token[2]), int.Parse(token[3]), bitmapData.Stride, bitmap.PixelFormat, bitmapData.Scan0); pictureBox1.Image = newBitmap; } catch { } txtChromeX.Enabled = true; txtChromeY.Enabled = true; txtChromeWidth.Enabled = true; txtChromeHeight.Enabled = true; txtChromeX.Text = token[0]; txtChromeY.Text = token[1]; txtChromeWidth.Text = token[2]; txtChromeHeight.Text = token[3]; } else { selectionMode = 0; btnAdd.Enabled = true; btnDelete.Enabled = true; var fullPath = oraMod.Manifest.Resources[miniYamlNodeValue]; var extension = Path.GetExtension(fullPath); if (extension == ".png " || extension == ".jpg") { pictureBox1.Image = new Bitmap(fullPath); } txtChromeX.Enabled = false; txtChromeY.Enabled = false; txtChromeWidth.Enabled = false; txtChromeHeight.Enabled = false; txtChromeX.Text = null; txtChromeY.Text = null; txtChromeWidth.Text = null; txtChromeHeight.Text = null; } } else { selectionMode = 1; btnAdd.Enabled = true; btnDelete.Enabled = false; txtChromeX.Enabled = false; txtChromeY.Enabled = false; txtChromeWidth.Enabled = false; txtChromeHeight.Enabled = false; txtChromeX.Text = null; txtChromeY.Text = null; txtChromeWidth.Text = null; txtChromeHeight.Text = null; } }
public void Parse() { MiniYamlNode currentNode = null; using (StreamReader reader = new StreamReader(miniYamlFilePath)) { int lastCount = -1; while (reader.Peek() > -1) { string line = reader.ReadLine(); if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) { continue; } int count = line.StartsWithCharCount('\t'); if (count == 0) { currentNode = new MiniYamlNode(); var tokens = line.Split(':'); currentNode.Name = tokens[0].Replace("\t", null); if (tokens.Length > 1) { currentNode.Value = tokens[1]; } Nodes.Add(currentNode); } else { if (count == 1) { if (currentNode.ParentNode != null) { currentNode = currentNode.ParentNode; } var subNode = new MiniYamlNode(); var tokens = line.Split(':'); subNode.Name = tokens[0].Replace("\t", null);; if (tokens.Length > 1) { subNode.Value = tokens[1]; } subNode.ParentNode = currentNode; currentNode.ChildNodes.Add(subNode); currentNode = subNode; } else { MiniYamlNode yamlNode = new MiniYamlNode(); var tokens = line.Split(':'); yamlNode.Name = tokens[0].Replace("\t", null); if (tokens.Length > 1) { yamlNode.Value = tokens[1]; } int c**t = line.StartsWithCharCount('\t'); if (count == lastCount) { yamlNode.ParentNode = currentNode.ParentNode; currentNode.ParentNode.ChildNodes.Add(yamlNode); } else if (c**t == lastCount + 1) { yamlNode.ParentNode = currentNode; currentNode.ChildNodes.Add(yamlNode); } else if (c**t == lastCount - 1) { yamlNode.ParentNode = currentNode.ParentNode.ParentNode; currentNode.ParentNode.ParentNode.ChildNodes.Add(yamlNode); } currentNode = yamlNode; } } lastCount = count; } } }