Beispiel #1
0
        /// <summary>
        /// Prompts a dialog box and sets a variable with the result when it's complete.
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <param name="variable"></param>
        public async void InputBoxToVariable(string caption, string title, string variable)
        {
            var win = new InputBoxDialog
            {
                Title   = title,
                Caption = caption
            };

            string value = this.GetVariable(variable);

            if (!string.IsNullOrWhiteSpace(value))
            {
                win.Text = value;
            }

            var result = await win.ShowAsync();

            if (result == ModernWpf.Controls.ContentDialogResult.Primary)
            {
                // Cancel
                return;
            }
            else if (result == ModernWpf.Controls.ContentDialogResult.Secondary)
            {
                // OK
                this.SetVariable(variable, win.Text);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Prompts the user with an input box and returns the string content.
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public async Task <string> InputBox(string caption, string title)
        {
            var win = new InputBoxDialog
            {
                Title   = title,
                Caption = caption
            };

            var result = await win.ShowAsync();

            return(win.Text);
        }
Beispiel #3
0
        /// <summary>
        /// Prompts the user with an input box and returns the string content.
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <param name="prepopulateText"></param>
        public async Task <string> InputBox(string caption, string title, string prepopulateText)
        {
            var win = new InputBoxDialog
            {
                Title   = title,
                Caption = caption,
                Text    = prepopulateText
            };

            _ = await win.ShowAsync();

            return(win.Text);
        }
        /// <summary>
        /// Button event to create a package.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ButtonCreate_Click(object sender, RoutedEventArgs e)
        {
            int count = AliasList.SelectedCount() + TriggerList.SelectedCount() + DirectionList.SelectedCount();

            if (count == 0)
            {
                var msgbox = new MessageBoxDialog()
                {
                    Title   = "Info",
                    Content = "No items were selected to create a package from.",
                };

                await msgbox.ShowAsync();

                return;
            }

            var win = new InputBoxDialog
            {
                Title   = "Author",
                Caption = "Who should be listed as the author of this package?"
            };

            _ = await win.ShowAsync();

            var package = new Package
            {
                Id          = Guid.NewGuid().ToString(),
                GameAddress = App.Settings.ProfileSettings.IpAddress,
                Author      = win.Text ?? ""
            };

            foreach (object obj in AliasList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Alias item)
                {
                    var alias = (Alias)item.Clone();
                    alias.Count     = 0;
                    alias.Character = "";
                    package.AliasList.Add(alias);
                }
            }

            foreach (object obj in TriggerList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Common.Triggers.Trigger item)
                {
                    var trigger = (Common.Triggers.Trigger)item.Clone();
                    trigger.Character   = "";
                    trigger.LastMatched = DateTime.MinValue;
                    trigger.Count       = 0;
                    package.TriggerList.Add(trigger);
                }
            }

            foreach (object obj in DirectionList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Direction item)
                {
                    var direction = (Direction)item.Clone();
                    package.DirectionList.Add(direction);
                }
            }

            var dialog = new SaveFileDialog
            {
                InitialDirectory = App.Settings.AvalonSettings.SaveDirectory,
                Filter           = "JSON files (*.json)|*.json",
                Title            = "Save Package"
            };

            try
            {
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    await File.WriteAllTextAsync(dialog.FileName, Newtonsoft.Json.JsonConvert.SerializeObject(package, Newtonsoft.Json.Formatting.Indented));
                }
            }
            catch (Exception ex)
            {
                var msgbox = new MessageBoxDialog()
                {
                    Title   = "Error",
                    Content = ex.Message,
                };

                await msgbox.ShowAsync();

                return;
            }

            this.Close();
        }