private void SetQuest(TourGuideObjective objective)
        {
            WowObject questByID;
            bool skip = false;

            if (objective.Objective_Type != ObjectiveType.QUEST_ACCEPT &&
                objective.Objective_Type != ObjectiveType.QUEST_COMPLETE &&
                objective.Objective_Type != ObjectiveType.QUEST_TURNIN)
            {
                if (TextBox_QuestID.Text.Replace(" ", "") == String.Empty &&
                    TextBox_QuestName.Text.Replace(" ", "") == String.Empty)
                {
                    skip = true;
                    objective.QuestEnabled = false;
                    TextBox_QuestID.BackColor = Color.White;
                    TextBox_QuestName.BackColor = Color.White;
                }
            }

            if (!skip)
            {
                objective.QuestEnabled = true;
                try
                {
                    questByID = questIDManager.GetMatchingByID(TextBox_QuestID.Text);
                }
                catch (FormatException ex)
                {
                    questByID = null;
                }

                if (questByID == null)
                {
                    if (TextBox_QuestID.Text.Replace(" ", "") != String.Empty)
                    {
                        TextBox_QuestID.BackColor = Color.Red;
                        TextBox_QuestName.BackColor = Color.Orange;
                        objective.ErrorsPresent = true;
                        TextBox_QuestName.Text = String.Empty;
                    }
                    else
                    {
                        List<WowObject> quests = questIDManager.GetMatchingByName(TextBox_QuestName.Text);
                        if (quests.Count == 0)
                        {
                            TextBox_QuestName.BackColor = Color.Red;
                            TextBox_QuestID.BackColor = Color.Red;
                            objective.ErrorsPresent = true;
                        }
                        else if (quests.Count == 1)
                        {
                            TextBox_QuestName.BackColor = Color.LightGreen;
                            TextBox_QuestID.Text = quests[0].ID.ToString();
                            TextBox_QuestID.BackColor = Color.LightGreen;
                        }
                        else if (quests.Count > 1)
                        {
                            TextBox_QuestName.BackColor = Color.Orange;
                            ListBox_QuestIDsPossible.Items.Clear();
                            foreach (WowObject quest in quests)
                            {
                                ListBox_QuestIDsPossible.Items.Add(quest.ID.ToString());
                            }
                            objective.ErrorsPresent = true;
                        }
                    }
                }
                else
                {
                    objective.QuestName = questByID.name;
                    TextBox_QuestName.Text = questByID.name;
                    TextBox_QuestName.BackColor = Color.LightGreen;

                    objective.QuestID = questByID.ID.ToString();
                    TextBox_QuestID.Text = questByID.ID.ToString();
                    TextBox_QuestID.BackColor = Color.LightGreen;
                }

            }
            if (TextBox_QuestName.BackColor == Color.LightGreen && TextBox_QuestID.BackColor == Color.LightGreen)
            {
                if (CheckBox_QuestNameOverrides.Checked)
                    TextBox_ObjectOfInterest.Text = TextBox_QuestName.Text;
                TextBox_ObjectOfInterest.BackColor = Color.White;
                objective.ObjectOfInterest = TextBox_ObjectOfInterest.Text;
                objective.QuestID = TextBox_QuestID.Text;
                objective.QuestName = TextBox_QuestName.Text;
            }
        }
 private void SetObjectiveType(TourGuideObjective objective)
 {
     if (this.RadioButton_Boat.Checked)
         objective.Objective_Type = ObjectiveType.BOAT;
     else if (this.RadioButton_BuyItem.Checked)
         objective.Objective_Type = ObjectiveType.ITEM_BUY;
     else if (this.RadioButton_Fly.Checked)
         objective.Objective_Type = ObjectiveType.FLY;
     else if (this.RadioButton_GeneralNote.Checked)
         objective.Objective_Type = ObjectiveType.GENERAL_NOTE;
     else if (this.RadioButton_GetFlightPath.Checked)
         objective.Objective_Type = ObjectiveType.GET_FLIGHTPATH;
     else if (this.RadioButton_KillMob.Checked)
         objective.Objective_Type = ObjectiveType.KILL_MOB;
     else if (this.RadioButton_QuestAccept.Checked)
         objective.Objective_Type = ObjectiveType.QUEST_ACCEPT;
     else if (this.RadioButton_QuestComplete.Checked)
         objective.Objective_Type = ObjectiveType.QUEST_COMPLETE;
     else if (this.RadioButton_QuestTurnIn.Checked)
         objective.Objective_Type = ObjectiveType.QUEST_TURNIN;
     else if (this.RadioButton_Run.Checked)
         objective.Objective_Type = ObjectiveType.RUN;
     else if (this.RadioButton_SetHearth.Checked)
         objective.Objective_Type = ObjectiveType.HEARTH_SET;
     else if (this.RadioButton_UseHearth.Checked)
         objective.Objective_Type = ObjectiveType.HEARTH_USE;
     else if (this.RadioButton_UseItem.Checked)
         objective.Objective_Type = ObjectiveType.ITEM_USE;
 }
 private void SetObjectOfInterest(TourGuideObjective objective)
 {
     if (TextBox_ObjectOfInterest.Text.Replace(" ", "") == String.Empty &&
         TextBox_QuestName.Text.Replace(" ", "") == String.Empty)
     {
         TextBox_ObjectOfInterest.BackColor = Color.Red;
         objective.ErrorsPresent = true;
     }
     else
     {
             objective.ObjectOfInterest = TextBox_ObjectOfInterest.Text;
     }
 }
        private WowObject SetItem_NonEmpty(TourGuideObjective objective)
        {
            WowObject itemByID = null;
            //If item ID is entered in a box, it will override the item name
            if (TextBox_ItemID.Text.Replace(" ", "") != String.Empty)
            {
                itemByID = SetItem_ByID(objective, itemByID);
            }

            else if (TextBox_ItemName.Text.Replace(" ", "") != String.Empty) //If item name is entered but no ID
            {
                SetItem_ByName(objective);
            }
            return itemByID;
        }
 private void SetObjectiveCoords(TourGuideObjective objective)
 {
     if (TextBox_CoordX.Text.Replace(" ", "").Equals(String.Empty) &&
         TextBox_CoordY.Text.Replace(" ", "").Equals(String.Empty))
     {
         TextBox_CoordX.BackColor = Color.White;
         TextBox_CoordY.BackColor = Color.White;
         objective.CoordinatesEnabled = false;
     }
     else
     {
         try
         {
             float xCoord = float.Parse(this.TextBox_CoordX.Text);
             float yCoord = float.Parse(this.TextBox_CoordY.Text);
             objective.Coordinates = new Wow_Coordinate(xCoord, yCoord);
             objective.CoordinatesEnabled = true;
             if (xCoord < 0 || xCoord > 100)
             {
                 objective.ErrorsPresent = true;
                 objective.CoordinatesEnabled = false;
                 TextBox_CoordX.BackColor = Color.Red;
             }
             if (yCoord < 0 || yCoord > 100)
             {
                 objective.ErrorsPresent = true;
                 objective.CoordinatesEnabled = false;
                 TextBox_CoordY.BackColor = Color.Red;
             }
         }
         catch (FormatException ex)
         {
             objective.Coordinates = new Wow_Coordinate(0f, 0f);
             objective.CoordinatesEnabled = false;
             TextBox_CoordX.BackColor = Color.Red;
             TextBox_CoordY.BackColor = Color.Red;
             objective.ErrorsPresent = true;
         }
         if (objective.CoordinatesEnabled)
         {
             TextBox_CoordX.BackColor = Color.LightGreen;
             TextBox_CoordY.BackColor = Color.LightGreen;
             TextBox_CoordX.Text = objective.Coordinates.X.ToString();
             TextBox_CoordY.Text = objective.Coordinates.Y.ToString();
         }
     }
 }
        private void SetItem_ByName(TourGuideObjective objective)
        {
            List<WowObject> items = itemIDManager.GetMatchingByName(TextBox_ItemName.Text);

            if (items.Count == 0)
            {
                objective.ErrorsPresent = true;
                TextBox_ItemName.BackColor = Color.Red;
                TextBox_ItemID.BackColor = Color.Orange;
            }
            else if (items.Count == 1)
            {
                TextBox_ItemID.Text = items[0].ID.ToString();
                TextBox_ItemName.BackColor = Color.LightGreen;
                TextBox_ItemID.BackColor = Color.LightGreen;
            }
            else if (items.Count > 1)
            {
                TextBox_ItemName.BackColor = Color.Orange;
                objective.ErrorsPresent = true;
                ListBox_ItemIDsPossible.Items.Clear();
                foreach (WowObject item in items)
                {
                    ListBox_ItemIDsPossible.Items.Add(item.ID.ToString());
                }
            }
        }
 private WowObject SetItem_ByID(TourGuideObjective objective, WowObject itemByID)
 {
     itemByID = itemIDManager.GetMatchingByID(TextBox_ItemID.Text);
     if (itemByID == null)
     {
         objective.ErrorsPresent = true;
         TextBox_ItemID.BackColor = Color.Red;
         TextBox_ItemName.BackColor = Color.Orange;
         TextBox_ItemName.Text = String.Empty;
     }
     else
     {
         objective.ItemID = itemByID.ID.ToString();
         objective.ItemName = itemByID.name;
         TextBox_ItemName.Text = itemByID.name;
         TextBox_ItemID.BackColor = Color.LightGreen;
         TextBox_ItemName.BackColor = Color.LightGreen;
     }
     return itemByID;
 }
        private void SetItemQuantity(TourGuideObjective objective)
        {
            if (objective.Item_Objective_Type != ItemObjectiveType.LOOT_ITEM)
            {
                TextBox_ItemQuantity.Text = String.Empty;
            }

            if (TextBox_ItemQuantity.Text.Replace(" ", "") != String.Empty && TextBox_ItemQuantity.Text != "0")
            {
                int quantity;
                if (Int32.TryParse(TextBox_ItemQuantity.Text, out quantity))
                {
                    if (quantity > 0)
                    {
                        TextBox_ItemQuantity.BackColor = Color.LightGreen;
                        objective.ItemQuantity = quantity;
                    }
                    else
                    {
                        TextBox_ItemQuantity.BackColor = Color.Red;
                        objective.ErrorsPresent = true;
                    }
                }
                else
                {
                    TextBox_ItemQuantity.BackColor = Color.Red;
                    objective.ErrorsPresent = true;
                }
            }
            else
            {
                TextBox_ItemQuantity.BackColor = Color.White;
                objective.ItemQuantity = -1;
            }
        }
        private void SetItem(TourGuideObjective objective)
        {
            WowObject itemByID;

            if (RadioButton_Item_LootItem.Checked)
            {
                objective.Item_Objective_Type = ItemObjectiveType.LOOT_ITEM;
            }
            else if (RadioButton_Item_UseItem.Checked)
            {
                objective.Item_Objective_Type = ItemObjectiveType.USE_ITEM;
            }

            if (RadioButton_Item_NA.Checked)
            {
                objective.Item_Objective_Type = ItemObjectiveType.NONE;
                TextBox_ItemID.BackColor = Color.White;
                TextBox_ItemName.BackColor = Color.White;
                TextBox_ItemQuantity.BackColor = Color.White;
                TextBox_ItemID.Text = "";
                TextBox_ItemName.Text = "";
                TextBox_ItemQuantity.Text = "";
            }
            else //Validation, Lookup item
            {
                if (TextBox_ItemID.Text.Replace(" ", "") == String.Empty &&
                TextBox_ItemName.Text.Replace(" ", "") == String.Empty)
                {
                    TextBox_ItemID.BackColor = Color.Red;
                    TextBox_ItemName.BackColor = Color.Red;
                    objective.ErrorsPresent = true;
                }
                else
                {
                    itemByID = SetItem_NonEmpty(objective);
                }
            }

            SetItemQuantity(objective);
        }
        private void ApplyChanges_Objective()
        {
            TourGuideObjective objective = new TourGuideObjective();
            objective.ErrorsPresent = false;
            objective.ObjectiveIndex = project.SelectedGuide.SelectedObjective.ObjectiveIndex;
            ResetBGColors();

            objective.Label = this.Textbox_ObjectiveLabel.Text;

            SetObjectiveType(objective);
            SetObjectiveCoords(objective);
            SetQuest(objective);
            SetObjectOfInterest(objective);
            SetItem(objective);
            SetItem(objective);
            objective.Notes = TextBox_Notes.Text;
            if (CheckBox_DisableDebug.Checked)
            {
                objective.DisableDebug = true;
            }
            if (CheckBox_ObjectiveInTown.Checked)
            {
                objective.ObjectiveInTown = true;
            }
            if (CheckBox_OptionalObjective.Checked)
            {
                objective.OptionalObjective = true;
            }

            if (!objective.ErrorsPresent)
            {
                if (objective.ItemQuantity < 0)
                    objective.ItemQuantity = 0;
                TextBox_CompiledOutput.Text = objective.CompiledOutput;
                objective.Label = Textbox_ObjectiveLabel.Text;
                project.SelectedGuide.SelectedObjective = objective;
                project.SelectedGuide.Objectives[objective.ObjectiveIndex] = objective;
                project.SelectedGuide.CompileGuide();
                savedRecently = false;
                RefreshWindow();
            }
        }