Advertisement
adolf01

Untitled

Dec 27th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.59 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: Alois
  4.  * Date: 25.12.2016
  5.  * Time: 18:04
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Windows.Forms;
  12.  
  13.  
  14. namespace AppartusQuestConfigurator
  15. {
  16.     /// <summary>
  17.     /// Description of MainForm.
  18.     /// </summary>
  19.     public partial class MainForm : Form
  20.     {
  21.         List<Quest> Quests = new List<Quest>();
  22.         List<int> liust = new List<int>();
  23.        
  24.         String QuestExample = @"""@@ID@@"" {
  25.    ""Quest Lore""=""@@LORE@@""
  26.    ""Quest Name""=""@@NAME@@""
  27.    ""Quest Requirements""=[
  28. @@REQ@@
  29.    ]
  30.    ""Quest Reward""=[
  31. @@REW@@
  32.    ]
  33. }";
  34.         class Quest
  35.         {
  36.             public int QuestId{ get; set; }
  37.             public String QuestName{ get; set; }
  38.             public String QuestLore{ get; set; }
  39.             public List<String> Quest_Req = new List<String>();
  40.            
  41.             public List<String> Quest_Rew = new List<String>();
  42.         }
  43.        
  44.         public MainForm()
  45.         {
  46.             //
  47.             // The InitializeComponent() call is required for Windows Forms designer support.
  48.             //
  49.             InitializeComponent();
  50.             //richTextBox1.Text = QuestExample;
  51.             //
  52.             // TODO: Add constructor code after the InitializeComponent() call.
  53.             //
  54.         }
  55.        
  56.         void Button1Click(object sender, EventArgs e)
  57.         {
  58.             dataGridView1.Rows.Clear();
  59.             if (openFileDialog1.ShowDialog() == DialogResult.OK) {
  60.                 ConfigFileBox.Text = openFileDialog1.FileName;
  61.                 ConfigToTable(openFileDialog1.FileName);
  62.             }
  63.            
  64.         }
  65.        
  66.         public void ConfigToTable(String FileName)
  67.         {
  68.             dataGridView1.Rows.Clear();
  69.             Quests.Clear();
  70.             System.IO.StreamReader Config = new System.IO.StreamReader(FileName, true);
  71.             String config = Config.ReadToEnd();
  72.             //Config.Close();
  73.             String[] Data = config.Split(new string[] { "\" {" }, StringSplitOptions.None);
  74.             int i = 0;
  75.            
  76.             foreach (String item in Data) {
  77.                 Quest quest = new Quest();
  78.                
  79.                 if (item.Contains("Quest Name")) {
  80.                     i++;
  81.                    
  82.                     quest.QuestId = i;
  83.                     quest.QuestName = "prvni quest";
  84.                     quest.QuestLore = "aaaaA";
  85.                
  86.                
  87.                
  88.                     String[] lines = item.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
  89.                     foreach (String line in lines) {
  90.                         if (line.Contains("Quest Lore"))
  91.                             quest.QuestLore = line.Split('=')[1].Replace("\"", "");
  92.                         if (line.Contains("Quest Name"))
  93.                             quest.QuestName = line.Split('=')[1].Replace("\"", "");
  94.                        
  95.                         if (line.Contains("Quest Requirements")) {
  96.                             String req = item.Split(new string[] { "\"=[" }, StringSplitOptions.None)[1];
  97.                             req = req.Split(new string[] { "]\r\n", "]\r", "]\n"  }, StringSplitOptions.None)[0];
  98.                             foreach (String requ in req.Split(',')) {
  99.                                 quest.Quest_Req.Add(requ.Replace("        ", "").Replace("\"", "").Replace("    ", "").Replace(System.Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\r", ""));
  100.                             }
  101.                            
  102.                         }
  103.                         if (line.Contains("Quest Reward")) {
  104.                             String rew = item.Split(new string[] { "\"=[" }, StringSplitOptions.None)[2];
  105.                             rew = rew.Split(new string[] { "]\r\n", "]\r", "]\n"  }, StringSplitOptions.None)[0];
  106.                             foreach (String rewa in rew.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  107.                                 String Rew_Line = rewa;
  108.                                 Rew_Line = Rew_Line.Replace("\",", "");
  109.                                 Rew_Line = Rew_Line.Replace("        ", "").Replace("\"", "").Replace("    ", "").Replace(System.Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
  110.                                
  111.                                 //if (Rew_Line[Rew_Line.Length - 1] == ',') Rew_Line = rewa.Remove(rewa.Length - 1);
  112.                                
  113.                                 if (Rew_Line != "\"\"")
  114.                                     quest.Quest_Rew.Add(Rew_Line);
  115.                             }
  116.                            
  117.                         }
  118.                     }
  119.                     Quests.Add(quest);
  120.                 }
  121.             }
  122.             foreach (Quest Q in Quests) {
  123.                 dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
  124.                
  125.             }
  126.                
  127.             Config.Close();
  128.         }
  129.            
  130.         void Button2Click(object sender, EventArgs e)
  131.         {
  132.             IDLabel.Text = "ID";
  133.             QuestNameBox.Text = null;
  134.             QuestLoreBox.Text = null;
  135.             LevelCombo.Text = "0";
  136.             PermBox.Text = null;
  137.             PermNotBox.Text = null;
  138.             ItemsReqBox.Text = null;
  139.             ItemsRewBox.Text = null;
  140.             CommandsBox.Text = null;
  141.            
  142.         }
  143.        
  144.         void Button3Click(object sender, EventArgs e)
  145.         {
  146.             if (IDLabel.Text == "ID" && QuestNameBox.Text != "" && QuestLoreBox.Text != "") {
  147.                 Quest quest = new Quest();
  148.                 quest.QuestName = QuestNameBox.Text;
  149.                 quest.QuestLore = QuestLoreBox.Text;
  150.                
  151.                 if (LevelCombo.Text != "0")
  152.                     quest.Quest_Req.Add("Level||" + LevelCombo.Text);
  153.                
  154.                 if (ItemsReqBox.Text != "") {
  155.                     foreach (String line in ItemsReqBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  156.                         if (line != "")
  157.                             quest.Quest_Req.Add("Item||" + line);                  
  158.                     }
  159.                 }
  160.                 if (PermBox.Text != "") {
  161.                     foreach (String line in PermBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  162.                         if (line != "")
  163.                             quest.Quest_Req.Add("Perm||" + line);                  
  164.                     }
  165.                 }
  166.                 if (PermNotBox.Text != "") {
  167.                     foreach (String line in PermNotBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  168.                         if (line != "")
  169.                             quest.Quest_Req.Add("PermNot||" + line);                   
  170.                     }
  171.                 }
  172.  
  173.                 if (ItemsRewBox.Text != "") {
  174.                     foreach (String line in ItemsRewBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  175.                         if (line != "")
  176.                             quest.Quest_Rew.Add("Item||" + line);                  
  177.                     }
  178.                 }
  179.                 if (CommandsBox.Text != "") {
  180.                     foreach (String line in CommandsBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  181.                         if (line != "")
  182.                             quest.Quest_Rew.Add("Command||" + line);                   
  183.                     }
  184.                 }
  185.                 int i = 1;
  186.                 foreach (Quest Q in Quests) {
  187.                     i++;
  188.                 }
  189.                 quest.QuestId = i;
  190.                 Quests.Add(quest);
  191.                 dataGridView1.Rows.Clear();
  192.                 dataGridView1.Refresh();
  193.                
  194.                 foreach (Quest Q in Quests) {
  195.                     dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
  196.                     //CommandsBox.Text = Q.Quest_Rew[0];
  197.                 }
  198.                
  199.                 IDLabel.Text = "ID";
  200.                 QuestNameBox.Text = null;
  201.                 QuestLoreBox.Text = null;
  202.                 LevelCombo.Text = "0";
  203.                 PermBox.Text = null;
  204.                 PermNotBox.Text = null;
  205.                 ItemsReqBox.Text = null;
  206.                 ItemsRewBox.Text = null;
  207.                 CommandsBox.Text = null;
  208.                
  209.                
  210.             }
  211.             if (IDLabel.Text != "ID") {
  212.                 int i = 0;
  213.                 foreach (Quest Q in Quests) {
  214.                     if (IDLabel.Text == Q.QuestId.ToString()) {
  215.                         Q.QuestLore = QuestLoreBox.Text;
  216.                         Q.QuestName = QuestNameBox.Text;
  217.                        
  218.                         Q.Quest_Req.Clear();
  219.                         Q.Quest_Rew.Clear();
  220.                        
  221.                         if (LevelCombo.Text != "0")
  222.                             Q.Quest_Req.Add("Level||" + LevelCombo.Text);
  223.                
  224.                         if (ItemsReqBox.Text != "") {
  225.                             foreach (String line in ItemsReqBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  226.                                 if (line != "")
  227.                                     Q.Quest_Req.Add("Item||" + line);                  
  228.                             }
  229.                         }
  230.                         if (PermBox.Text != "") {
  231.                             foreach (String line in PermBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  232.                                 if (line != "")
  233.                                     Q.Quest_Req.Add("Perm||" + line);                  
  234.                             }
  235.                         }
  236.                         if (PermNotBox.Text != "") {
  237.                             foreach (String line in PermNotBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  238.                                 if (line != "")
  239.                                     Q.Quest_Req.Add("PermNot||" + line);                   
  240.                             }
  241.                         }
  242.  
  243.                         if (ItemsRewBox.Text != "") {
  244.                             foreach (String line in ItemsRewBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  245.                                 if (line != "")
  246.                                     Q.Quest_Rew.Add("Item||" + line);                  
  247.                             }
  248.                         }
  249.                         if (CommandsBox.Text != "") {
  250.                             foreach (String line in CommandsBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
  251.                                 if (line != "")
  252.                                     Q.Quest_Rew.Add("Command||" + line);                   
  253.                             }
  254.                         }
  255.                     }
  256.                     //Quests[i] = Q;
  257.                     i++;
  258.                 }
  259.             }
  260.         }
  261.        
  262.         void DataGridView1CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  263.         {
  264.             IDLabel.Text = "ID";
  265.             QuestNameBox.Text = null;
  266.             QuestLoreBox.Text = null;
  267.             LevelCombo.Text = "0";
  268.             PermBox.Text = null;
  269.             PermNotBox.Text = null;
  270.             ItemsReqBox.Text = null;
  271.             ItemsRewBox.Text = null;
  272.             CommandsBox.Text = null;
  273.            
  274.            
  275.             int rowIndex = e.RowIndex;
  276.             int x = 0;
  277.  
  278.             if (Int32.TryParse(dataGridView1.Rows[rowIndex].Cells[0].Value.ToString(), out x)) {
  279.                 foreach (Quest quest in Quests) {
  280.                     if (quest.QuestId == x) {
  281.                         IDLabel.Text = quest.QuestId.ToString();
  282.                         QuestNameBox.Text = quest.QuestName;
  283.                         QuestLoreBox.Text = quest.QuestLore;
  284.                        
  285.                         //PermNotBox.Text += quest.QuestLore + System.Environment.NewLine;
  286.                         foreach (String item in quest.Quest_Req) {
  287.                             //PermNotBox.Text += item + System.Environment.NewLine;
  288.                             if (item.Contains("Level||")) {
  289.                                 LevelCombo.Text = item.Split(new string[] { "||" }, StringSplitOptions.None)[1];
  290.                             }
  291.                             if (item.Contains("Perm||")) {
  292.                                 PermBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
  293.                             }
  294.                             if (item.Contains("Item||")) {
  295.                                 ItemsReqBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
  296.                             }
  297.                             if (item.Contains("PermNot||")) {
  298.                                 PermNotBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
  299.                             }
  300.                
  301.                         }
  302.                        
  303.                         foreach (String itemR in quest.Quest_Rew) {
  304.                             //PermNotBox.Text += item + System.Environment.NewLine;
  305.                             if (itemR.Contains("Item||")) {
  306.                                 ItemsRewBox.Text += itemR.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
  307.                             }
  308.                             if (itemR.Contains("Command||")) {
  309.                                 CommandsBox.Text += itemR.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
  310.                             }
  311.                
  312.                         }
  313.                        
  314.                        
  315. //                      richTextBox1.Text = quest.QuestName + System.Environment.NewLine;
  316. //                      richTextBox1.Text += quest.QuestLore + System.Environment.NewLine;
  317. //                      foreach (String req in quest.Quest_Req) {
  318. //                          richTextBox1.Text += req + System.Environment.NewLine;
  319. //                      }
  320. //                      foreach (String rew in quest.Quest_Rew) {
  321. //                          richTextBox1.Text += rew + System.Environment.NewLine;
  322. //                      }
  323.                     }
  324.                    
  325.                 }
  326.                 // you know that the parsing attempt
  327.                 // was successful
  328.             }
  329.            
  330.            
  331.         }
  332.        
  333.         void Button4Click(object sender, EventArgs e)
  334.         {
  335.             dataGridView1.Rows.Clear();
  336.             foreach (Quest Q in Quests) {
  337.                 dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
  338.                
  339.             }
  340.             System.IO.StreamWriter Config = new System.IO.StreamWriter(openFileDialog1.FileName);
  341.             //Config.WriteLine(lines);
  342.            
  343.            
  344.             foreach (Quest Q in Quests) {
  345.                 String Quest = QuestExample;
  346.                
  347.                 Quest = Quest.Replace("@@ID@@", Q.QuestId.ToString());
  348.                 Quest = Quest.Replace("@@NAME@@", Q.QuestName);
  349.                 Quest = Quest.Replace("@@LORE@@", Q.QuestLore);
  350.                
  351.                 String REQ = "";
  352.                 foreach (String req in Q.Quest_Req) {
  353.                     if (req != "")
  354.                         REQ += "        " + "\"" + req + "\"," + System.Environment.NewLine;
  355.                 }
  356.                 String REW = "";
  357.                 foreach (String rew in Q.Quest_Rew) {
  358.                     if (rew != "")
  359.                         REW += "        " + "\"" + rew + "\"," + System.Environment.NewLine;
  360.                 }
  361.                 if (REW.Length >= 3)
  362.                     REW = REW.Remove(REW.Length - 3);
  363.                 if (REQ.Length >= 3)
  364.                     REQ = REQ.Remove(REQ.Length - 3);
  365.                 Quest = Quest.Replace("@@REQ@@", REQ);
  366.                 Quest = Quest.Replace("@@REW@@", REW);
  367.                
  368.                
  369.                 Config.WriteLine(Quest);
  370.             }
  371.             Config.Close();
  372.            
  373.         }
  374.  
  375.        
  376.        
  377.        
  378.     }
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement