Example #1
0
        private void B_LoadDesign_Click(object sender, EventArgs e)
        {
            var original = SAV.Main.GetDesign(PatternIndex);
            var name     = original.DesignName;

            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Design Pattern (*.nhd)|*.nhd|All files (*.*)|*.*",
                      FileName = $"{name}.nhd",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var file         = ofd.FileName;
            var expectLength = original.Data.Length;
            var fi           = new FileInfo(file);

            if (fi.Length != expectLength)
            {
                var msg = string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength);
                WinFormsUtil.Error(MessageStrings.MsgCanceling, msg);
                return;
            }

            var data    = File.ReadAllBytes(ofd.FileName);
            var d       = new DesignPattern(data);
            var player0 = SAV.Players[0].Personal;

            if (!d.IsOriginatedFrom(player0))
            {
                var notHost = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName);
                var result  = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, notHost, MessageStrings.MsgAskUpdateValues);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    d.ChangeOrigins(player0, d.Data);
                }
            }

            SAV.Main.SetDesign(d, PatternIndex);
            LoadPattern(d);
        }
Example #2
0
        private void B_LoadDesign_Click(object sender, EventArgs e)
        {
            var original = SAV.Main.GetDesign(PatternIndex);
            var name     = original.DesignName;

            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Design Pattern (*.nhd)|*.nhd|All files (*.*)|*.*",
                      FileName = $"{name}.nhd",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var file         = ofd.FileName;
            var expectLength = original.Data.Length;
            var fi           = new FileInfo(file);

            if (fi.Length != expectLength)
            {
                var msg = $"Imported Design Pattern's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X}).";
                WinFormsUtil.Error("Cancelling:", msg);
                return;
            }

            var data    = File.ReadAllBytes(ofd.FileName);
            var d       = new DesignPattern(data);
            var player0 = SAV.Players[0].Personal;

            if (!d.IsOriginatedFrom(player0))
            {
                var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel,
                                                 $"Imported Design Pattern did not originate from Villager0 ({player0.PlayerName})'s data.", "Update values?");
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    d.ChangeOrigins(player0, d.Data);
                }
            }

            SAV.Main.SetDesign(d, PatternIndex);
            LoadPattern(d);
        }
Example #3
0
        private void B_LoadDesign_Click(object sender, EventArgs e)
        {
            if (sender == B_LoadDesignAll)
            {
                using var fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var dir = Path.GetDirectoryName(fbd.SelectedPath);
                if (dir == null || !Directory.Exists(dir))
                {
                    return;
                }
                var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MessageStrings.MsgAskUpdateValues);
                Patterns.Load(fbd.SelectedPath, result == DialogResult.Yes);
                LoadPattern(Patterns[Index]);
                RepopulateList(Index);
                return;
            }

            var original = Patterns[Index];
            var name     = original.DesignName;

            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Design Pattern (*.nhd)|*.nhd|All files (*.*)|*.*",
                      FileName = $"{name}.nhd",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var file         = ofd.FileName;
            var expectLength = original.Data.Length;
            var fi           = new FileInfo(file);

            if (fi.Length != expectLength)
            {
                var msg = string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength);
                WinFormsUtil.Error(MessageStrings.MsgCanceling, msg);
                return;
            }

            var data    = File.ReadAllBytes(ofd.FileName);
            var d       = new DesignPattern(data);
            var player0 = original;

            if (!d.IsOriginatedFrom(player0))
            {
                var notHost = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName);
                var result  = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, notHost, MessageStrings.MsgAskUpdateValues);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    d.ChangeOrigins(player0, d.Data);
                }
            }

            Patterns[Index] = d;
            LoadPattern(d);
            RepopulateList(Index);
        }