SleepHunter.Views.FlowerTargetWindow.ValidateFlowerTarget C# (CSharp) Method

ValidateFlowerTarget() private method

private ValidateFlowerTarget ( ) : bool
return bool
        bool ValidateFlowerTarget()
        {
            var selectedMode = GetSelectedMode();
              TimeSpan interval = TimeSpan.Zero;

              #region Check Target Mode
              if (selectedMode == TargetCoordinateUnits.None)
              {
            this.ShowMessageBox("Target Required",
               "Lyliac Plant requires a target.",
               "You must select a target mode from the dropdown list.",
               MessageBoxButton.OK);

            targetModeComboBox.Focus();
            targetModeComboBox.IsDropDownOpen = true;
            return false;
              }
              #endregion

              var characterName = characterComboBox.SelectedValue as string;

              if (selectedMode == TargetCoordinateUnits.Character && string.IsNullOrWhiteSpace(characterName))
              {
            this.ShowMessageBox("Invalid Character",
               "Alternate character cannot be empty.",
               "If the character you are looking for does not show up\nclose this window and try again.",
               MessageBoxButton.OK,
               440, 220);

            return false;
              }

              if ((selectedMode == TargetCoordinateUnits.RelativeRadius || selectedMode == TargetCoordinateUnits.AbsoluteRadius) &&
             innerRadiusUpDown.Value > outerRadiusUpDown.Value)
              {
            this.ShowMessageBox("Invalid Radius",
               "The inner radius must be less than or equal to the outer radius.",
               "You may use zero inner radius to include yourself, one to start from adjacent tiles",
               MessageBoxButton.OK,
               440, 220);

            return false;
              }

              if (intervalCheckBox.IsChecked.Value)
              {
            double intervalSeconds;
            if (string.IsNullOrWhiteSpace(intervalTextBox.Text.Trim()))
              interval = TimeSpan.Zero;
            else if (double.TryParse(intervalTextBox.Text.Trim(), out intervalSeconds) && intervalSeconds >= 0)
              interval = TimeSpan.FromSeconds(intervalSeconds);
            else if (!TimeSpanExtender.TryParse(intervalTextBox.Text.Trim(), out interval) || interval < TimeSpan.Zero)
            {
              this.ShowMessageBox("Invalid Interval",
             "Interval must be a valid positive timespan value.",
             "You may use fractional units of days, hours, minutes, and seconds.\nYou may also leave it blank for continuous.",
             MessageBoxButton.OK,
             420, 240);

              intervalTextBox.Focus();
              intervalTextBox.SelectAll();
              return false;
            }
              }

              if (!intervalCheckBox.IsChecked.Value && !manaThresholdCheckBox.IsChecked.Value)
              {
            this.ShowMessageBox("Missing Condition",
               "You must specify at least one condition to flower on.\nYou may use the time interval or mana conditions, or both.",
               "If you specify both, it will flower if either condition is reached.",
               MessageBoxButton.OK,
               480, 240);

            return false;
              }

              flowerQueueItem.Target.Units = selectedMode;

              if (selectedMode == TargetCoordinateUnits.Character)
            flowerQueueItem.Target.CharacterName = characterName;
              else
            flowerQueueItem.Target.CharacterName = null;

              flowerQueueItem.Target.Location = GetLocationForMode(selectedMode);
              flowerQueueItem.Target.Offset = new Point(offsetXUpDown.Value, offsetYUpDown.Value);

              if (selectedMode == TargetCoordinateUnits.AbsoluteRadius || selectedMode == TargetCoordinateUnits.RelativeRadius)
              {
            flowerQueueItem.Target.InnerRadius = (int)innerRadiusUpDown.Value;
            flowerQueueItem.Target.OuterRadius = (int)outerRadiusUpDown.Value;
              }
              else
              {
            flowerQueueItem.Target.InnerRadius = 0;
            flowerQueueItem.Target.OuterRadius = 0;
              }

              if (intervalCheckBox.IsChecked.Value)
            flowerQueueItem.Interval = interval;
              else
            flowerQueueItem.Interval = null;

              if (manaThresholdUpDown.IsEnabled && manaThresholdCheckBox.IsChecked.Value)
            flowerQueueItem.ManaThreshold = (int)manaThresholdUpDown.Value;
              else
            flowerQueueItem.ManaThreshold = null;

              return true;
        }