Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: Alois
- * Date: 25.12.2016
- * Time: 18:04
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace AppartusQuestConfigurator
- {
- /// <summary>
- /// Description of MainForm.
- /// </summary>
- public partial class MainForm : Form
- {
- List<Quest> Quests = new List<Quest>();
- List<int> liust = new List<int>();
- String QuestExample = @"""@@ID@@"" {
- ""Quest Lore""=""@@LORE@@""
- ""Quest Name""=""@@NAME@@""
- ""Quest Requirements""=[
- @@REQ@@
- ]
- ""Quest Reward""=[
- @@REW@@
- ]
- }";
- class Quest
- {
- public int QuestId{ get; set; }
- public String QuestName{ get; set; }
- public String QuestLore{ get; set; }
- public List<String> Quest_Req = new List<String>();
- public List<String> Quest_Rew = new List<String>();
- }
- public MainForm()
- {
- //
- // The InitializeComponent() call is required for Windows Forms designer support.
- //
- InitializeComponent();
- //richTextBox1.Text = QuestExample;
- //
- // TODO: Add constructor code after the InitializeComponent() call.
- //
- }
- void Button1Click(object sender, EventArgs e)
- {
- dataGridView1.Rows.Clear();
- if (openFileDialog1.ShowDialog() == DialogResult.OK) {
- ConfigFileBox.Text = openFileDialog1.FileName;
- ConfigToTable(openFileDialog1.FileName);
- }
- }
- public void ConfigToTable(String FileName)
- {
- dataGridView1.Rows.Clear();
- Quests.Clear();
- System.IO.StreamReader Config = new System.IO.StreamReader(FileName, true);
- String config = Config.ReadToEnd();
- //Config.Close();
- String[] Data = config.Split(new string[] { "\" {" }, StringSplitOptions.None);
- int i = 0;
- foreach (String item in Data) {
- Quest quest = new Quest();
- if (item.Contains("Quest Name")) {
- i++;
- quest.QuestId = i;
- quest.QuestName = "prvni quest";
- quest.QuestLore = "aaaaA";
- String[] lines = item.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
- foreach (String line in lines) {
- if (line.Contains("Quest Lore"))
- quest.QuestLore = line.Split('=')[1].Replace("\"", "");
- if (line.Contains("Quest Name"))
- quest.QuestName = line.Split('=')[1].Replace("\"", "");
- if (line.Contains("Quest Requirements")) {
- String req = item.Split(new string[] { "\"=[" }, StringSplitOptions.None)[1];
- req = req.Split(new string[] { "]\r\n", "]\r", "]\n" }, StringSplitOptions.None)[0];
- foreach (String requ in req.Split(',')) {
- quest.Quest_Req.Add(requ.Replace(" ", "").Replace("\"", "").Replace(" ", "").Replace(System.Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\r", ""));
- }
- }
- if (line.Contains("Quest Reward")) {
- String rew = item.Split(new string[] { "\"=[" }, StringSplitOptions.None)[2];
- rew = rew.Split(new string[] { "]\r\n", "]\r", "]\n" }, StringSplitOptions.None)[0];
- foreach (String rewa in rew.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- String Rew_Line = rewa;
- Rew_Line = Rew_Line.Replace("\",", "");
- Rew_Line = Rew_Line.Replace(" ", "").Replace("\"", "").Replace(" ", "").Replace(System.Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
- //if (Rew_Line[Rew_Line.Length - 1] == ',') Rew_Line = rewa.Remove(rewa.Length - 1);
- if (Rew_Line != "\"\"")
- quest.Quest_Rew.Add(Rew_Line);
- }
- }
- }
- Quests.Add(quest);
- }
- }
- foreach (Quest Q in Quests) {
- dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
- }
- Config.Close();
- }
- void Button2Click(object sender, EventArgs e)
- {
- IDLabel.Text = "ID";
- QuestNameBox.Text = null;
- QuestLoreBox.Text = null;
- LevelCombo.Text = "0";
- PermBox.Text = null;
- PermNotBox.Text = null;
- ItemsReqBox.Text = null;
- ItemsRewBox.Text = null;
- CommandsBox.Text = null;
- }
- void Button3Click(object sender, EventArgs e)
- {
- if (IDLabel.Text == "ID" && QuestNameBox.Text != "" && QuestLoreBox.Text != "") {
- Quest quest = new Quest();
- quest.QuestName = QuestNameBox.Text;
- quest.QuestLore = QuestLoreBox.Text;
- if (LevelCombo.Text != "0")
- quest.Quest_Req.Add("Level||" + LevelCombo.Text);
- if (ItemsReqBox.Text != "") {
- foreach (String line in ItemsReqBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- quest.Quest_Req.Add("Item||" + line);
- }
- }
- if (PermBox.Text != "") {
- foreach (String line in PermBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- quest.Quest_Req.Add("Perm||" + line);
- }
- }
- if (PermNotBox.Text != "") {
- foreach (String line in PermNotBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- quest.Quest_Req.Add("PermNot||" + line);
- }
- }
- if (ItemsRewBox.Text != "") {
- foreach (String line in ItemsRewBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- quest.Quest_Rew.Add("Item||" + line);
- }
- }
- if (CommandsBox.Text != "") {
- foreach (String line in CommandsBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- quest.Quest_Rew.Add("Command||" + line);
- }
- }
- int i = 1;
- foreach (Quest Q in Quests) {
- i++;
- }
- quest.QuestId = i;
- Quests.Add(quest);
- dataGridView1.Rows.Clear();
- dataGridView1.Refresh();
- foreach (Quest Q in Quests) {
- dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
- //CommandsBox.Text = Q.Quest_Rew[0];
- }
- IDLabel.Text = "ID";
- QuestNameBox.Text = null;
- QuestLoreBox.Text = null;
- LevelCombo.Text = "0";
- PermBox.Text = null;
- PermNotBox.Text = null;
- ItemsReqBox.Text = null;
- ItemsRewBox.Text = null;
- CommandsBox.Text = null;
- }
- if (IDLabel.Text != "ID") {
- int i = 0;
- foreach (Quest Q in Quests) {
- if (IDLabel.Text == Q.QuestId.ToString()) {
- Q.QuestLore = QuestLoreBox.Text;
- Q.QuestName = QuestNameBox.Text;
- Q.Quest_Req.Clear();
- Q.Quest_Rew.Clear();
- if (LevelCombo.Text != "0")
- Q.Quest_Req.Add("Level||" + LevelCombo.Text);
- if (ItemsReqBox.Text != "") {
- foreach (String line in ItemsReqBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- Q.Quest_Req.Add("Item||" + line);
- }
- }
- if (PermBox.Text != "") {
- foreach (String line in PermBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- Q.Quest_Req.Add("Perm||" + line);
- }
- }
- if (PermNotBox.Text != "") {
- foreach (String line in PermNotBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- Q.Quest_Req.Add("PermNot||" + line);
- }
- }
- if (ItemsRewBox.Text != "") {
- foreach (String line in ItemsRewBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- Q.Quest_Rew.Add("Item||" + line);
- }
- }
- if (CommandsBox.Text != "") {
- foreach (String line in CommandsBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)) {
- if (line != "")
- Q.Quest_Rew.Add("Command||" + line);
- }
- }
- }
- //Quests[i] = Q;
- i++;
- }
- }
- }
- void DataGridView1CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- IDLabel.Text = "ID";
- QuestNameBox.Text = null;
- QuestLoreBox.Text = null;
- LevelCombo.Text = "0";
- PermBox.Text = null;
- PermNotBox.Text = null;
- ItemsReqBox.Text = null;
- ItemsRewBox.Text = null;
- CommandsBox.Text = null;
- int rowIndex = e.RowIndex;
- int x = 0;
- if (Int32.TryParse(dataGridView1.Rows[rowIndex].Cells[0].Value.ToString(), out x)) {
- foreach (Quest quest in Quests) {
- if (quest.QuestId == x) {
- IDLabel.Text = quest.QuestId.ToString();
- QuestNameBox.Text = quest.QuestName;
- QuestLoreBox.Text = quest.QuestLore;
- //PermNotBox.Text += quest.QuestLore + System.Environment.NewLine;
- foreach (String item in quest.Quest_Req) {
- //PermNotBox.Text += item + System.Environment.NewLine;
- if (item.Contains("Level||")) {
- LevelCombo.Text = item.Split(new string[] { "||" }, StringSplitOptions.None)[1];
- }
- if (item.Contains("Perm||")) {
- PermBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
- }
- if (item.Contains("Item||")) {
- ItemsReqBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
- }
- if (item.Contains("PermNot||")) {
- PermNotBox.Text += item.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
- }
- }
- foreach (String itemR in quest.Quest_Rew) {
- //PermNotBox.Text += item + System.Environment.NewLine;
- if (itemR.Contains("Item||")) {
- ItemsRewBox.Text += itemR.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
- }
- if (itemR.Contains("Command||")) {
- CommandsBox.Text += itemR.Split(new string[] { "||" }, StringSplitOptions.None)[1] + System.Environment.NewLine;
- }
- }
- // richTextBox1.Text = quest.QuestName + System.Environment.NewLine;
- // richTextBox1.Text += quest.QuestLore + System.Environment.NewLine;
- // foreach (String req in quest.Quest_Req) {
- // richTextBox1.Text += req + System.Environment.NewLine;
- // }
- // foreach (String rew in quest.Quest_Rew) {
- // richTextBox1.Text += rew + System.Environment.NewLine;
- // }
- }
- }
- // you know that the parsing attempt
- // was successful
- }
- }
- void Button4Click(object sender, EventArgs e)
- {
- dataGridView1.Rows.Clear();
- foreach (Quest Q in Quests) {
- dataGridView1.Rows.Add(Q.QuestId, Q.QuestName);
- }
- System.IO.StreamWriter Config = new System.IO.StreamWriter(openFileDialog1.FileName);
- //Config.WriteLine(lines);
- foreach (Quest Q in Quests) {
- String Quest = QuestExample;
- Quest = Quest.Replace("@@ID@@", Q.QuestId.ToString());
- Quest = Quest.Replace("@@NAME@@", Q.QuestName);
- Quest = Quest.Replace("@@LORE@@", Q.QuestLore);
- String REQ = "";
- foreach (String req in Q.Quest_Req) {
- if (req != "")
- REQ += " " + "\"" + req + "\"," + System.Environment.NewLine;
- }
- String REW = "";
- foreach (String rew in Q.Quest_Rew) {
- if (rew != "")
- REW += " " + "\"" + rew + "\"," + System.Environment.NewLine;
- }
- if (REW.Length >= 3)
- REW = REW.Remove(REW.Length - 3);
- if (REQ.Length >= 3)
- REQ = REQ.Remove(REQ.Length - 3);
- Quest = Quest.Replace("@@REQ@@", REQ);
- Quest = Quest.Replace("@@REW@@", REW);
- Config.WriteLine(Quest);
- }
- Config.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement