public void GetCommandsFromFile(Storage info, OpenFileDialog openDialog)
        {
            List <string> commandStrings = new List <string>();
            Stream        fileStream     = null;

            if ((fileStream = openDialog.OpenFile()) == null)
            {
                return;
            }
            StreamReader sr = new StreamReader(fileStream);

            while (!sr.EndOfStream)
            {
                commandStrings.Add(sr.ReadLine());
            }
            for (int i = 0; i < commandStrings.Count; i += 4)
            {
                Storage.Command newCommand = new Storage.Command();
                newCommand.command   = commandStrings[i];
                newCommand.chatValue = commandStrings[i + 1];
                newCommand.self      = Convert.ToBoolean(commandStrings[i + 2]);
                newCommand.type      = (Storage.AbilityType)Enum.Parse(typeof(Storage.AbilityType), commandStrings[i + 3]);
                info.commands.Add(newCommand);
            }
        }
예제 #2
0
        private void AddCommands_BTN_Click(object sender, EventArgs e)
        {
            if (ChatValue_TB.Text.Length == 0 || NewCommand_TB.Text.Length == 0 || Type_CB.SelectedItem == null)
            {
                MessageBox.Show("You are missing a command field, make sure everything has been entered!", "Error");
                return;
            }
            Storage.Command newCommand = new Storage.Command();
            newCommand.chatValue = ChatValue_TB.Text;
            newCommand.command   = NewCommand_TB.Text;
            newCommand.self      = SelfTarget_CKB.Checked;
            if (Type_CB.SelectedItem.ToString().Equals("Buff"))
            {
                newCommand.type = Storage.AbilityType.Buff;
            }
            else if (Type_CB.SelectedItem.ToString().Equals("Magic Attack"))
            {
                newCommand.type = Storage.AbilityType.MagicAttack;
            }
            else if (Type_CB.SelectedItem.ToString().Equals("Job Ability"))
            {
                newCommand.type = Storage.AbilityType.JobAbility;
            }
            else if (Type_CB.SelectedItem.ToString().Equals("Weapon Skill"))
            {
                newCommand.type = Storage.AbilityType.WeaponSkill;
            }
            foreach (Storage.Command c in info.commands)
            {
                if (c.chatValue.Equals(newCommand.chatValue))
                {
                    MessageBox.Show("Another command already has this chat value! Please use a different value.", "Error");
                    return;
                }
            }

            var item = new ListViewItem(new[] { newCommand.command, newCommand.chatValue, newCommand.type.ToString(), newCommand.self.ToString() });

            info.commands.Add(newCommand);
            Commands_LV.Items.Add(item);
            Commands_LV.Items.Clear();
            UpdateCommandsListBox();
        }