示例#1
0
        /// <summary>
        /// Makes sure a message box is managed by this manager.
        /// </summary>
        /// <param name="wmb"></param>
        private CustomMessageBox Accept(WF.Player.Core.MessageBox wmb)
        {
            // Ignore if the engine is not ready.
            if (!App.Current.Model.Core.IsReady)
            {
                System.Diagnostics.Debug.WriteLine("MessageBoxManager: Ignored Wherigo message box because Engine is not ready.");
                return(null);
            }

            CustomMessageBox cmb = null;

            // Checks if this instance already manages this message box.
            // If not, starts to manage the box.
            KeyValuePair <CustomMessageBox, WF.Player.Core.MessageBox> pair = _wherigoMessageBoxes.SingleOrDefault(kv => kv.Value == wmb);

            if (pair.Value == wmb)
            {
                // The target message box exists already.
                cmb = pair.Key;
            }
            else
            {
                // Creates a target message box.
                cmb = new CustomMessageBox()
                {
                    Caption = App.Current.Model.Core.Cartridge.Name,
                    //Message = wmb.Text,
                    Content = new Controls.WherigoMessageBoxContentControl()
                    {
                        MessageBox = wmb
                    },
                    LeftButtonContent  = wmb.FirstButtonLabel ?? "OK",
                    RightButtonContent = wmb.SecondButtonLabel
                };

                // Registers events.
                RegisterEventHandlersForWig(cmb);

                // Adds the pair to the dictionary.
                bool hadMessageBoxes;
                lock (_syncRoot)
                {
                    hadMessageBoxes = HasMessageBox;
                    _wherigoMessageBoxes.Add(cmb, wmb);
                }

                // Sends an event if it changed.
                if (!hadMessageBoxes)
                {
                    RaiseHasMessageBoxChanged();
                }
            }

            return(cmb);
        }
示例#2
0
        /// <summary>
        /// Displays a message box from a Wherigo game.
        /// If a message box is on-screen, it is dismissed.
        /// </summary>
        /// <param name="mbox"></param>
        public void Show(WF.Player.Core.MessageBox mbox)
        {
            if (mbox == null)
            {
                throw new ArgumentNullException("mbox");
            }

            CustomMessageBox mb = Accept(mbox);

            if (mb != null)
            {
                mb.Show();
            }
        }