/// <summary>
 /// Logic for the <see cref="ClearBuildTemplate"/> command.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The execution arguments.</param>
 private void ClearBuildTemplate_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     Debug.Assert(e.Parameter is BuildTemplateViewModel);
     BuildTemplateViewModel model = (BuildTemplateViewModel)e.Parameter;
     if (model.BuildTemplate != null)
     {
         BuildLibrary.DeleteBuildTemplate(model.Index);
         SyncModels();
     }
 }
 /// <summary>
 /// Logic for the <see cref="ExitRenameMode"/> command.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The execution arguments.</param>
 private void ExitRenameMode_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (renameTarget != null && bool.TryParse(e.Parameter as string, out bool setName))
     {
         PART_RenameInputDialog.Visibility = Visibility.Collapsed;
         if (setName)
             BuildLibrary.SetBuildTemplateName(renameTarget.Index, PART_RenameTextInput.Text);
         PART_RenameTextInput.Clear();
         renameTarget = null;
     }
 }
        /// <summary>
        /// Logic for the <see cref="StoreOrRecallBuildTemplate"/> command.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The execution arguments.</param>
        private void StoreOrRecallBuildTemplate_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Parameter is BuildTemplateViewModel model)
            {
                if (model.BuildTemplate == null)
                {
                    BuildLibrary.CreateBuildTemplate(model.Index, Clipboard.GetText());
                    SyncModels();
                }
                else
                {
                    Clipboard.SetText(model.BuildTemplate.BuildData);
                }

                // If we are in quick mode then we exit after this interaction
                if (BuildLibrary.Settings.QuickMode)
                    Application.Current.Shutdown(0);
            }
            else
            {
                Debug.Fail("Unexpected model type.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Raises the System.Windows.Application.Startup event.
        /// </summary>
        /// <param name="e">A System.Windows.StartupEventArgs that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            BuildLibrarySettings settings = new BuildLibrarySettings();
            string exportLocation         = null,
                   importLocation         = null;

            options = new OptionSet()
            {
                // Overlay Mode
                {
                    "o|overlay",
                    "Overlay Mode",
                    v => settings.OverlayMode = v != null
                },

                // Full Screen Mode
                {
                    "f|full-screen",
                    "Full Screen Mode",
                    v => settings.FullScreenMode = v != null
                },

                // Quick Mode
                {
                    "q|quick",
                    "Quick Mode",
                    v => settings.QuickMode = v != null
                },

                // No Save Window State
                {
                    "no-save-window-state",
                    "No Save Window State",
                    v => settings.SaveWindowState = v == null
                },

                // Profession Filter
                {
                    "profession=",
                    "Profession Filter",
                    v => settings.ProfessionFilter = ParseProfessionFilter(v)
                },

                // Export Builds
                {
                    "export=",
                    "Export",
                    v => exportLocation = v
                },

                // Import Builds
                {
                    "import=",
                    "Import",
                    v => importLocation = v
                },

                // Help
                {
                    "h|?|help",
                    "Help",
                    v => ShowHelp = v != null
                },
            };

            try
            {
                options.Parse(e.Args);
            }
            catch (OptionException ex)
            {
                MessageBox.Show($"Error: {ex.Message}",
                                "Option Parsing Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                Shutdown(-1);
                return;
            }

            if (ShowHelp)
            {
                // Show the help message and exit
                ShowHelpMessage();
                Shutdown(0);
                return;
            }

            BuildLibrary = new BuildLibrary(settings);

            bool shutdown = false;

            if (!string.IsNullOrEmpty(importLocation))
            {
                // Load the additional templates
                BuildLibrary.Load(importLocation, loadWindowState: false);
            }

            if (!string.IsNullOrEmpty(exportLocation))
            {
                // Save the library without window data to the specified location then shutdown the application
                BuildLibrary.Save(exportLocation, saveWindowState: false);
                shutdown = true;
            }

            if (shutdown)
            {
                Shutdown(0);
            }
            else
            {
                base.OnStartup(e);
            }
        }
        /// <summary>
        /// Raises the System.Windows.Window.Closed event.
        /// </summary>
        /// <param name="e">An System.EventArgs that contains the event data.</param>
        protected override void OnClosed(EventArgs e)
        {
            BuildLibrary?.UpdateWindowStateForSaving(WindowState, RenderSize, Left, Top);

            base.OnClosed(e);
        }
        /// <summary>
        /// Synchronises the view models for the build templates with the templates in the library.
        /// </summary>
        private void SyncModels()
        {
            Debug.Assert(BuildLibrary != null, "No BuildLibrary instance was set.");
            if (BuildLibrary == null)
                return;

            // Ensure there is a model for every slot
            while (BuildTemplateModels.Count < BuildTemplateItems.ItemCount)
            {
                BuildTemplateModels.Add(new BuildTemplateViewModel());
            }
            // And no more
            while (BuildTemplateModels.Count > BuildTemplateItems.ItemCount)
            {
                BuildTemplateModels.RemoveAt(BuildTemplateModels.Count - 1);
            }

            int pageOffset = BuildTemplateItems.ItemCount * (CurrentPage - 1);
            if (ProfessionFilter == Profession.None)
            {
                /* No filter applied so just show the builds as they are
                 * All models are used and empty ones allow for storing more builds
                 */
                for (int modelIndex = 0; modelIndex < BuildTemplateItems.ItemCount; modelIndex++)
                {
                    BuildTemplateViewModel model = BuildTemplateModels[modelIndex];
                    BuildTemplate build = BuildLibrary.GetBuildTemplate(modelIndex + pageOffset);
                    model.BuildTemplate = build;
                    model.Index = build?.Index ?? (modelIndex + pageOffset);
                    model.IsHidden = false;
                }
            }
            else
            {
                // If a filter is applied then get all templates and only create models for those that match
                List<BuildTemplate> buildTemplates = BuildLibrary.GetAllBuildTemplates(ProfessionFilter)
                    .OrderBy(b => b.Index).ToList();

                int modelIndex;
                for (modelIndex = 0; modelIndex < BuildTemplateItems.ItemCount
                    && (modelIndex + pageOffset) < buildTemplates.Count; modelIndex++)
                {
                    BuildTemplateViewModel model = BuildTemplateModels[modelIndex];
                    BuildTemplate build = buildTemplates[modelIndex + pageOffset];
                    model.BuildTemplate = build;
                    model.Index = build.Index;
                    model.IsHidden = false;
                }

                // Ensure there is an empty slot after the filtered results if there is room
                if (modelIndex < BuildTemplateModels.Count)
                {
                    BuildTemplateViewModel model = BuildTemplateModels[modelIndex];
                    model.BuildTemplate = null;
                    model.Index = BuildLibrary.GetNextFreeIndex();
                    model.IsHidden = false;
                    modelIndex++;
                }

                // Instead of deleting models, tell them to hide
                for (; modelIndex < BuildTemplateItems.ItemCount; modelIndex++)
                {
                    BuildTemplateViewModel model = BuildTemplateModels[modelIndex];
                    model.IsHidden = true;
                    model.BuildTemplate = null;
                }
            }
        }