// We know this is clumsy, but its a .NET-ism -- // Form widgets can *only* be controlled by the thread that creates them. // Thus, we make this guarantee by wrapping all creation & processing actions // in a method called by just one thread. <sigh> private static void PopupDialogViaDelegate(AsyncCompletionToken completionToken, string toonName, string dialogTitle, string dialogMessage, string expiryActionName, int expiryRemainingInSeconds, bool isBotStopAllowed, bool isStopOnContinue, SystemSound soundCue, int soundPeriodInSeconds) { UserDialogForm dialogForm = new UserDialogForm(completionToken, toonName, dialogTitle, dialogMessage, expiryActionName, expiryRemainingInSeconds, isBotStopAllowed, isStopOnContinue, soundCue, soundPeriodInSeconds); // Popup the window-- // We'd *really* like to make this dialog a child of the main Honorbuddy window. // By doing such, the dialog would be 'brought to the front' any time te Honorbuddy main // window was. // Alas, C#/WindowsForms disallows this because the main HB GUI and this dialog are // on separate threads. dialogForm.TopMost = true; dialogForm.Activate(); dialogForm.ShowDialog(); }
// We know this is clumsy, but its a .NET-ism -- // Form widgets can *only* be controlled by the thread that creates them. // Thus, we make this guarantee by wrapping all creation & processing actions // in a method called by just one thread. <sigh> private static void PopupDialogViaDelegate(AsyncCompletionToken completionToken, string toonName, string dialogTitle, string dialogMessage, string expiryActionName, int expiryRemainingInSeconds, bool isBotStopAllowed, bool isStopOnContinue, SystemSound soundCue, int soundPeriodInSeconds) { UserDialogForm dialogForm = new UserDialogForm(completionToken, toonName, dialogTitle, dialogMessage, expiryActionName, expiryRemainingInSeconds, isBotStopAllowed, isStopOnContinue, soundCue, soundPeriodInSeconds); // Making the main Honorbuddy window the popup's parent-- // This will bring the popup window to the front any time Honorbuddy is brought to the front. Form windowParent = (Form)Control.FromHandle(Process.GetCurrentProcess().MainWindowHandle); // Popup the window dialogForm.Activate(); dialogForm.ShowDialog(windowParent); }
public /*virtual*/ void Dispose(bool isExplicitlyInitiatedDispose) { if (!_isDisposed) { // NOTE: we should call any Dispose() method for any managed or unmanaged // resource, if that resource provides a Dispose() method. // Clean up managed resources, if explicit disposal... if (isExplicitlyInitiatedDispose) { if (_completionToken != null) { _completionToken.Dispose(); } if (_configMemento != null) { _configMemento.Dispose(); } _completionToken = null; _configMemento = null; } // Clean up unmanaged resources (if any) here... BotEvents.OnBotStop -= BotEvents_OnBotStop; // Call parent Dispose() (if it exists) here ... base.Dispose(); } _isDisposed = true; }
public override void OnStart() { // This reports problems, and stops BT processing if there was a problem with attributes... // We had to defer this action, as the 'profile line number' is not available during the element's // constructor call. OnStart_HandleAttributeProblem(); // If the quest is complete, this behavior is already done... // So we don't want to falsely inform the user of things that will be skipped. if (!IsDone) { // The ConfigMemento() class captures the user's existing configuration. // After its captured, we can change the configuration however needed. // When the memento is dispose'd, the user's original configuration is restored. // More info about how the ConfigMemento applies to saving and restoring user configuration // can be found here... // http://www.thebuddyforum.com/mediawiki/index.php?title=Honorbuddy_Programming_Cookbook:_Saving_and_Restoring_User_Configuration _configMemento = new ConfigMemento(); BotEvents.OnBotStop += BotEvents_OnBotStop; // We don't want the bot running around harvesting while the user // is manually controlling it trying to get the task completed. // (We've already captured the existing configuration which will // be restored when this behavior exits, or the bot is stopped. // So there are no worries about destroying user's configuration.) CharacterSettings.Instance.HarvestHerbs = false; CharacterSettings.Instance.HarvestMinerals = false; CharacterSettings.Instance.LootChests = false; CharacterSettings.Instance.LootMobs = false; CharacterSettings.Instance.NinjaSkin = false; CharacterSettings.Instance.SkinMobs = false; _completionToken = new AsyncCompletionToken(StyxWoW.Me.Name, DialogTitle, DialogText, ExpiryActionName, ExpiryTime, IsBotStopAllowed, IsStopOnContinue, SoundCue, SoundCueIntervalInSeconds); TreeRoot.GoalText = "User Attention Required..."; TreeRoot.StatusText = "Waiting for user dialog to close"; } }
public UserDialogForm(AsyncCompletionToken completionToken, string toonName, string dialogTitle, string dialogMessage, string expiryActionName, int expiryRemainingInSeconds, bool isBotStopAllowed, bool isStopOnContinue, SystemSound soundCue, int soundCuePeriodInSeconds) { _completionToken = completionToken; _completionToken.PopdownResponse = PopdownReason.UNKNOWN; _expiryActionHandler = ExpiryActionHandler.GetEnumItemByName(expiryActionName); _expiryRemainingInSeconds = expiryRemainingInSeconds; _isBotStopAllowed = isBotStopAllowed; _isStopOnContinue = isStopOnContinue; _soundCue = soundCue; _soundCuePeriodInSeconds = soundCuePeriodInSeconds; // Dialog creation InitializeComponent(); this.ControlBox = false; // disable close box for this dialog this.MinimizeBox = false; // disable minimize box for this dialog this.MaximizeBox = false; // disable maximize box for this dialog this.FormBorderStyle = FormBorderStyle.FixedDialog; this.FormClosing += new FormClosingEventHandler(dialogForm_FormClosing); heartbeatPulseTimer.Stop(); // Dialog identity this.Text = String.Format("['{0}' UserDialog] {1}", toonName, dialogTitle); this.textBoxMessage.Text = dialogMessage.Replace("\\n", Environment.NewLine).Replace("\\t", "\t"); this.textBoxMessage.SelectionStart = this.textBoxMessage.SelectionLength; this.checkBoxAutoDefend.Checked = _completionToken.IsAutoDefend; this.buttonStopBot.Enabled = isBotStopAllowed; this.labelStatus.Text = ""; // If only 'stop' allowed, convert the normally 'profile continue' button to 'stop' if (_isStopOnContinue) { this.buttonStopBot.Visible = false; this.buttonContinueProfile.Text = "Stop Bot"; } // Setup the Expiry countdown, if enabled-- // Our pulse timer goes off every second to notify the user how much time // remains before the expiry action will be executed. if (_expiryRemainingInSeconds > 0) { _expiryActionHandler.Initialize(this); labelStatus.Text = UtilBuildTimeRemainingStatusText(_expiryActionHandler.ActionAsString(), _expiryRemainingInSeconds); } // Setup the audible warnings -- // Note: *Never* try to set the System.Windows.Forms.Timer.Interval to zero. // Doing so will trigger a Windoze bug that prevents the dialog from // opening. switch (_soundCuePeriodInSeconds) { case 0: // Play no sound--nothing to do _soundPeriodRemaining = 0; this.checkBoxSuppressAudio.Enabled = false; break; case 1: // Play sound once for dialog open _soundPeriodRemaining = 0; soundCue.Play(); this.checkBoxSuppressAudio.Enabled = false; break; default: // Play sound now for dialog open, and // arrange to play the sound at the specified intervals _soundPeriodRemaining = _soundCuePeriodInSeconds; soundCue.Play(); this.checkBoxSuppressAudio.Enabled = true; break; } // Our heartbeat pulse handler looks for things like timer expiry, and dialog close requests. // Polling techniques like this offend us; however, our choices are limited, since // .NET requires the actual processing of a request to occur on the same thread // that created the dialog and its widgets. Yet, .NET provides us with no clean mechanisms // for external event notifications other than through timers. heartbeatPulseTimer.Interval = 1000; // one second heartbeatPulseTimer.Enabled = true; }