Exemplo n.º 1
0
        private async void btnSaveStockpile_Click(object sender, EventArgs e)
        {
            Stockpile sks    = new Stockpile(dgvStockpile);
            var       ghForm = UI_CanvasForm.GetExtraForm("Glitch Harvester");

            try
            {
                UICore.SetHotkeyTimer(false);
                //We do this here and invoke because our unlock runs at the end of the awaited method, but there's a chance an error occurs
                //Thus, we want this to happen within the try block
                SyncObjectSingleton.FormExecute(() =>
                {
                    UICore.LockInterface(false, true);
                    S.GET <UI_SaveProgress_Form>().Dock = DockStyle.Fill;
                    ghForm?.OpenSubForm(S.GET <UI_SaveProgress_Form>());
                });

                await Task.Run(() => { saveStockpile(sks, StockpileManager_UISide.CurrentStockpile.Filename); });
            }
            finally
            {
                SyncObjectSingleton.FormExecute(() =>
                {
                    ghForm?.CloseSubForm();
                    UICore.UnlockInterface();
                    UICore.SetHotkeyTimer(true);
                });
            }
        }
Exemplo n.º 2
0
        public async void btnSaveStockpileAs_Click(object sender, EventArgs e)
        {
            if (dgvStockpile.Rows.Count == 0)
            {
                MessageBox.Show("You cannot save the Stockpile because it is empty");
                return;
            }

            var ghForm = UI_CanvasForm.GetExtraForm("Glitch Harvester");

            try
            {
                UICore.SetHotkeyTimer(false);
                string         path            = "";
                SaveFileDialog saveFileDialog1 = new SaveFileDialog
                {
                    DefaultExt       = "sks",
                    Title            = "Save Stockpile File",
                    Filter           = "SKS files|*.sks",
                    RestoreDirectory = true
                };

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    path = saveFileDialog1.FileName;
                }
                else
                {
                    return;
                }

                Stockpile sks = new Stockpile(dgvStockpile);
                //We do this here and invoke because our unlock runs at the end of the awaited method, but there's a chance an error occurs
                //Thus, we want this to happen within the try block
                SyncObjectSingleton.FormExecute(() =>
                {
                    UICore.LockInterface(false, true);
                    S.GET <UI_SaveProgress_Form>().Dock = DockStyle.Fill;
                    ghForm?.OpenSubForm(S.GET <UI_SaveProgress_Form>());
                });

                await Task.Run(() =>
                {
                    saveStockpile(sks, path);
                });
            }
            finally
            {
                SyncObjectSingleton.FormExecute(() =>
                {
                    ghForm?.CloseSubForm();
                    UICore.UnlockInterface();
                    UICore.SetHotkeyTimer(true);
                });
            }
        }
Exemplo n.º 3
0
        private async void LoadStockpile(string fileName)
        {
            try
            {
                //We do this here and invoke because our unlock runs at the end of the awaited method, but there's a chance an error occurs
                //Thus, we want this to happen within the try block
                UICore.SetHotkeyTimer(false);
                UICore.LockInterface(false, true);
                S.GET <UI_SaveProgress_Form>().Dock = DockStyle.Fill;
                UI_CoreForm.cfForm?.OpenSubForm(S.GET <UI_SaveProgress_Form>());

                StockpileManager_UISide.ClearCurrentStockpile();

                //Clear out the DGVs
                S.GET <RTC_StockpileManager_Form>().dgvStockpile.Rows.Clear(); // Clear the stockpile manager
                dgvStockpile.Rows.Clear();                                     // Clear the stockpile player

                var r = await Task.Run(() => Stockpile.Load(fileName));

                if (r.Failed)
                {
                    MessageBox.Show($"Loading the stockpile failed!\n" +
                                    $"{r.GetErrorsFormatted()}");
                }
                else
                {
                    var sks = r.Result;
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        foreach (StashKey key in sks.StashKeys) //Populate the dgv
                        {
                            dgvStockpile?.Rows.Add(key, key.GameName, key.SystemName, key.SystemCore, key.Note);
                        }
                    });
                }

                List <StashKey> keys = dgvStockpile.Rows.Cast <DataGridViewRow>().Select(x => (StashKey)x.Cells["Item"].Value).ToList();
                foreach (var sk in keys)
                {
                    StockpileManager_UISide.CheckAndFixMissingReference(sk, false, keys);
                }

                dgvStockpile.ClearSelection();
                RefreshNoteIcons();
            }
            finally
            {
                UI_CoreForm.cfForm?.CloseSubForm();
                UICore.UnlockInterface();
                UICore.SetHotkeyTimer(true);
            }
        }
Exemplo n.º 4
0
        private async void btnImportStockpile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                DefaultExt       = "*",
                Title            = "Select stockpile to import",
                Filter           = "Any file|*.sks",
                RestoreDirectory = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var ghForm = UI_CanvasForm.GetExtraForm("Glitch Harvester");
                try
                {
                    UICore.SetHotkeyTimer(false);
                    //We do this here and invoke because our unlock runs at the end of the awaited method, but there's a chance an error occurs
                    //Thus, we want this to happen within the try block
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        UICore.LockInterface(false, true);
                        S.GET <UI_SaveProgress_Form>().Dock = DockStyle.Fill;
                        ghForm?.OpenSubForm(S.GET <UI_SaveProgress_Form>());
                    });

                    await Task.Run(() =>
                    {
                        if (Stockpile.Import(ofd.FileName, dgvStockpile))
                        {
                            UnsavedEdits = true;
                        }
                    });
                }
                finally
                {
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        ghForm?.CloseSubForm();
                        UICore.UnlockInterface();
                        UICore.SetHotkeyTimer(true);
                        RefreshNoteIcons();
                    });
                }
            }
        }
Exemplo n.º 5
0
 private void RTC_SettingsHotkeyConfig_Form_GotFocus(object sender, EventArgs e)
 {
     UICore.SetHotkeyTimer(false);
     DoFocus();
 }