Example #1
0
        /// <summary>
        /// Copies a bitmap to the correct file directory.
        /// </summary>
        /// <returns>The string of the location of new bitmap relative to the project directory.</returns>
        /// <exception cref="ArgumentException"></exception>
        public static string SaveBitmap(ObjectOfAlbertrizal obj, string fileNameAddition)
        {
            try
            {
                FileDialog dialog       = new FileDialog(FileDialog.DialogOptions.Open, "PNG File | *.png");
                string     fullPath     = CopyImageToProjectDirectory(dialog.GetPath(), fileNameAddition, obj);
                string     relativePath = GetRelativePath(fullPath, GameBase.CurrentMapLocation);
                return(relativePath);
            }
            catch (ArgumentNullException)
            {
                throw new ArgumentException();
            }
            catch (IOException e)
            {
                MessageBoxResult result = MessageBox.Show("File cannot be read or is busy. Try again?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error);

                if (result == MessageBoxResult.Yes)
                {
                    return(SaveBitmap(obj, fileNameAddition));
                }
                else
                {
                    return("");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Opens a file dialog to load a custom map (loads current map).
        /// </summary>
        /// <param name="editing">If true, this will call the load method on the static map instead of the current map.</param>
        /// <exception cref="IOException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public static void LoadCustomCampaign(bool editing)
        {
            string mapName;

            if (editing)
            {
                mapName = "map-static.xml";
            }
            else
            {
                mapName = "map.xml";
            }

            FileDialog dialog = new FileDialog(FileDialog.DialogOptions.Open, $"XAML File | {mapName}");

            GameBase.CurrentMapLocation = Path.GetDirectoryName(dialog.GetPath()) + "\\map.xml";
            GameBase.StaticMapLocation  = Path.GetDirectoryName(dialog.GetPath()) + "\\map-static.xml";

            try
            {
                if (editing)
                {
                    GameBase.StaticGame = LoadMap(GameBase.StaticMapLocation);
                    GameBase.StaticGame.Load(GameBase.StaticGame);
                }
                else
                {
                    GameBase.CurrentGame = LoadMap(GameBase.CurrentMapLocation);
                    GameBase.CurrentGame.Load(GameBase.CurrentGame);
                }
            }
            catch (InvalidOperationException)
            {
                throw;
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IOException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public static void CreateCustomCampaign()
        {
            FileDialog dialog = new FileDialog(FileDialog.DialogOptions.Save, "XAML File|.xml", "map-static");

            GameBase.NewCustomCampaign(dialog.GetPath());
        }