コード例 #1
0
        internal void RegisterEvents()
        {
            // Register Events
            // run buttons
            runXCOM2ToolStripMenuItem.Click          += (a, b) => { RunGame(); };
            runWarOfTheChosenToolStripMenuItem.Click += (a, b) => { RunWotC(); };
            runChallengeModeToolStripMenuItem.Click  += (a, b) => { RunChallengeMode(); };

            // save on close
            //Shown += MainForm_Shown;
            //FormClosing += MainForm_FormClosing;

            // Menu
            // -> File
            saveToolStripMenuItem.Click   += delegate { Save(Settings.Instance.LastLaunchedWotC); };
            reloadToolStripMenuItem.Click += delegate
            {
                // Confirmation dialog
                var r = MessageBox.Show("Unsaved changes will be lost.\r\nAre you sure?", "Reload mod list?", MessageBoxButtons.OKCancel);
                if (r != DialogResult.OK)
                {
                    return;
                }

                Reset();
            };
            searchForModsToolStripMenuItem.Click += delegate { Settings.ImportMods(); };
            updateEntriesToolStripMenuItem.Click += delegate
            {
                if (_updateWorker.IsBusy)
                {
                    return;
                }

                CheckSteamForUpdates();
            };
            // -> Settings
            // show hidden
            showHiddenModsToolStripMenuItem.Click += delegate
            {
                Settings.ShowHiddenElements = showHiddenModsToolStripMenuItem.Checked;
                olvcHidden.IsVisible        = showHiddenModsToolStripMenuItem.Checked;
                RefreshModList(true);
            };

            // Edit
            editOptionsToolStripMenuItem.Click += delegate
            {
                var result = new SettingsDialog(Settings).ShowDialog();

                if (result == DialogResult.OK)
                {
                    RefreshModList();
                    ShowQuickLaunchArgsBasedOnSettings();
                    showHiddenModsToolStripMenuItem.Checked = Settings.ShowHiddenElements;
                    NoRedscreensLaunchArgument.UpdateFromSettings();
                    LogLaunchArgument.UpdateFromSettings();
                }
            };

            manageCategoriesToolStripMenuItem.Click += ManageCategoriesToolStripMenuItem_Click;

            exitToolStripMenuItem.Click += (sender, e) => { Close(); };

            // -> Tools
            cleanModsToolStripMenuItem.Click        += delegate { new CleanModsForm(Settings).ShowDialog(); };
            importActiveModsToolStripMenuItem.Click += delegate
            {
                XCOM2.ImportActiveMods(Settings);
                RefreshModList();
            };

            resubscribeToModsToolStripMenuItem.Click += delegate
            {
                var modsToDownload = Mods.All.Where(m => m.State.HasFlag(ModState.NotInstalled) && m.Source == ModSource.SteamWorkshop).ToList();
                var choice         = false;

                if (modsToDownload.Count == 0)
                {
                    MessageBox.Show("No uninstalled workshop mods were found.");
                }
                else if (modsToDownload.Count == 1)
                {
                    choice = MessageBox.Show($"Are you sure you want to download the mod {modsToDownload[0].Name}?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }
                else
                {
                    choice = MessageBox.Show($"Are you sure you want to download {modsToDownload.Count} mods?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }

                if (choice)
                {
                    foreach (var m in modsToDownload)
                    {
                        Workshop.Subscribe((ulong)m.WorkshopID);
                        Workshop.DownloadItem((ulong)m.WorkshopID);
                    }
                    MessageBox.Show("Launch XCOM 2 after the download is finished in order to use the mod" + (modsToDownload.Count == 1 ? "." : "s."));
                }
            };

            // RichTextBox clickable links
            //modinfo_readme_RichTextBox.LinkClicked += ControlLinkClicked;
            //modinfo_info_DescriptionRichTextBox.LinkClicked += ControlLinkClicked;
            //export_richtextbox.LinkClicked += ControlLinkClicked;
            //modinfo_changelog_richtextbox.LinkClicked += ControlLinkClicked;

            // Tab Controls
            //main_tabcontrol.Selected += MainTabSelected;
            //modinfo_tabcontrol.Selected += ModInfoTabSelected;

            // Mod Updater
            _updateWorker.DoWork             += Updater_DoWork;
            _updateWorker.ProgressChanged    += Updater_ProgressChanged;
            _updateWorker.RunWorkerCompleted += Updater_RunWorkerCompleted;

            // Steam Events
            Workshop.OnItemDownloaded += Resubscribe_OnItemDownloaded;

#if DEBUG
            Workshop.OnItemDownloaded += SteamWorkshop_OnItemDownloaded;
#endif

            // Main Tabs
            // Export
            export_workshop_link_checkbox.CheckedChanged += ExportCheckboxCheckedChanged;
            export_group_checkbox.CheckedChanged         += ExportCheckboxCheckedChanged;
            export_save_button.Click += ExportSaveButtonClick;
            export_load_button.Click += ExportLoadButtonClick;
        }
コード例 #2
0
        internal void RegisterEvents()
        {
            // Register Events
            // run buttons
            runXCOM2ToolStripMenuItem.Click          += (a, b) => { RunGame(); };
            runWarOfTheChosenToolStripMenuItem.Click += (a, b) => { RunWotC(); };
            runChallengeModeToolStripMenuItem.Click  += (a, b) => { RunChallengeMode(); };

            #region Menu->File

            saveToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Save settings");
                Save(Settings.Instance.LastLaunchedWotC);
            };

            reloadToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Reset settings");
                // Confirmation dialog
                var r = MessageBox.Show("Unsaved changes will be lost.\r\nAre you sure?", "Reload settings?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (r != DialogResult.OK)
                {
                    return;
                }

                Reset();
            };
            searchForModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Search for new mods");
                Settings.ImportMods();
            };

            updateEntriesToolStripMenuItem.Click += delegate
            {
                if (_updateWorker.IsBusy)
                {
                    return;
                }

                Log.Info("Menu->File->Update mod info");
                CheckSteamForUpdates();
            };

            exitToolStripMenuItem.Click += (sender, e) =>
            {
                Log.Info("Menu->Close");
                Close();
            };

            #endregion Menu->File

            #region Menu->Options

            // show hidden
            showHiddenModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Update mod info");
                Settings.ShowHiddenElements = showHiddenModsToolStripMenuItem.Checked;
                olvcHidden.IsVisible        = showHiddenModsToolStripMenuItem.Checked;
                RefreshModList(true);
            };

            // open Settings
            editOptionsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Options->Settings");
                var dialog = new SettingsDialog(Settings);

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // refresh/update settings dependent functions
                    RefreshModList();
                    showHiddenModsToolStripMenuItem.Checked = Settings.ShowHiddenElements;
                    UpdateQuickArgumentsMenu();

                    if (dialog.IsRestartRequired)
                    {
                        appRestartPendingLabel.Visible = true;
                        MessageBox.Show("Some changes won't take effect, until after the application has been restarted.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            };

            manageCategoriesToolStripMenuItem.Click += ManageCategoriesToolStripMenuItem_Click;

            #endregion Menu->Options

            #region Menu->Tools

            // -> Tools
            cleanModsToolStripMenuItem.Click += delegate { new CleanModsForm(Settings).ShowDialog(); };

            importFromXCOM2ToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Tools->Import vanilla");
                XCOM2.ImportActiveMods(Settings, false);
                RefreshModList();
            };

            importFromWotCToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Tools->Import WotC");
                XCOM2.ImportActiveMods(Settings, true);
                RefreshModList();
            };

            resubscribeToModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Tools->Resubscribe");
                var modsToDownload = Mods.All.Where(m => m.State.HasFlag(ModState.NotInstalled) && m.Source == ModSource.SteamWorkshop).ToList();
                var choice         = false;

                if (modsToDownload.Count == 0)
                {
                    MessageBox.Show("No uninstalled workshop mods were found.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (modsToDownload.Count == 1)
                {
                    choice = MessageBox.Show($"Are you sure you want to download the mod {modsToDownload[0].Name}?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }
                else
                {
                    choice = MessageBox.Show($"Are you sure you want to download {modsToDownload.Count} mods?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }

                if (choice)
                {
                    foreach (var m in modsToDownload)
                    {
                        Log.Info("Subscribe and download " + m.ID);
                        Workshop.Subscribe((ulong)m.WorkshopID);
                        Workshop.DownloadItem((ulong)m.WorkshopID);
                    }

                    MessageBox.Show("Launch XCOM 2 after the download is finished in order to use the mod" + (modsToDownload.Count == 1 ? "." : "s."), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };

            #endregion Menu->Tools

            #region Menu->About

            infoToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->About->About");
                AboutBox about = new AboutBox();
                about.ShowDialog();
            };

            checkForUpdatesToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->About->Check Update");

                if (!Program.CheckForUpdate())
                {
                    MessageBox.Show("No updates available", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };

            openHomepageToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://github.com/X2CommunityCore/xcom2-launcher"); };

            amlWikiToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://github.com/X2CommunityCore/xcom2-launcher/wiki"); };

            openDiscordToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://discord.gg/QHSVGRn"); };

            #endregion

            // RichTextBox clickable links
            //modinfo_readme_RichTextBox.LinkClicked += ControlLinkClicked;
            //modinfo_info_DescriptionRichTextBox.LinkClicked += ControlLinkClicked;
            //export_richtextbox.LinkClicked += ControlLinkClicked;
            //modinfo_changelog_richtextbox.LinkClicked += ControlLinkClicked;

            // Tab Controls
            //main_tabcontrol.Selected += MainTabSelected;
            //modinfo_tabcontrol.Selected += ModInfoTabSelected;

            // Mod Updater
            _updateWorker.DoWork             += Updater_DoWork;
            _updateWorker.ProgressChanged    += Updater_ProgressChanged;
            _updateWorker.RunWorkerCompleted += Updater_RunWorkerCompleted;

            // Steam Events
            Workshop.OnItemDownloaded += Resubscribe_OnItemDownloaded;

#if DEBUG
            Workshop.OnItemDownloaded += SteamWorkshop_OnItemDownloaded;
#endif

            // Main Tabs
            // Export
            export_workshop_link_checkbox.CheckedChanged += ExportCheckboxCheckedChanged;
            export_group_checkbox.CheckedChanged         += ExportCheckboxCheckedChanged;
            export_save_button.Click += ExportSaveButtonClick;
            export_load_button.Click += ExportLoadButtonClick;
        }
コード例 #3
0
        private void CheckSteamForNewMods()
        {
            status_toolstrip_label.Text = "Checking for new mods...";

            ulong[] subscribedIDs;
            try
            {
                subscribedIDs = Workshop.GetSubscribedItems();
            }
            catch (InvalidOperationException)
            {
                // Steamworks not initialized?
                // Game taking over?
                status_toolstrip_label.Text = "Error checking for new mods.";
                return;
            }

            var change = false;

            foreach (var id in subscribedIDs)
            {
                var status = Workshop.GetDownloadStatus(id);

                if (status.HasFlag(EItemState.k_EItemStateInstalled))
                {
                    // already installed
                    continue;
                }

                if (Downloads.Any(d => d.WorkshopID == (long)id))
                {
                    // already observing
                    continue;
                }

                // Get info
                var detailsRequest = new ItemDetailsRequest(id).Send().WaitForResult();
                var details        = detailsRequest.Result;
                var link           = detailsRequest.GetPreviewURL();

                var downloadMod = new ModEntry
                {
                    Name        = details.m_rgchTitle,
                    DateCreated = DateTimeOffset.FromUnixTimeSeconds(details.m_rtimeCreated).DateTime,
                    DateUpdated = DateTimeOffset.FromUnixTimeSeconds(details.m_rtimeUpdated).DateTime,
                    Path        = Path.Combine(Settings.GetWorkshopPath(), "" + id),
                    Image       = link,
                    Source      = ModSource.SteamWorkshop,
                    WorkshopID  = (int)id,
                    State       = ModState.New | ModState.NotInstalled
                };

                // Start download
                Workshop.DownloadItem(id);
                //
                Downloads.Add(downloadMod);
                change = true;
            }

            if (change)
            {
                RefreshModList();
            }

            status_toolstrip_label.Text = StatusBarIdleString;
        }
コード例 #4
0
        internal void RegisterEvents()
        {
            // Register Events
            // run buttons
            runXCOM2ToolStripMenuItem.Click          += (a, b) => { RunVanilla(); };
            runWarOfTheChosenToolStripMenuItem.Click += (a, b) => { RunWotC(); };
            runChallengeModeToolStripMenuItem.Click  += (a, b) => { RunChallengeMode(); };
            runChimeraSquadToolStripMenuItem.Click   += (sender, args) => RunChimeraSquad();

            #region Menu->File

            saveToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Save settings");
                Save(Settings.Instance.LastLaunchedWotC);
            };

            reloadToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Reset settings");
                // Confirmation dialog
                var r = MessageBox.Show("Unsaved changes will be lost.\r\nAre you sure?", "Reload settings?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (r != DialogResult.OK)
                {
                    return;
                }

                Reset();
            };

            searchForModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Search for new mods");

                if (IsModUpdateTaskRunning)
                {
                    ShowModUpdateRunningMessageBox();
                    return;
                }

                var importedMods = Settings.ImportMods();

                if (importedMods.Any())
                {
                    UpdateMods(importedMods, () =>
                    {
                        Invoke(new Action(() =>
                        {
                            RefreshModList();
                            modlist_ListObjectListView.EnsureModelVisible(importedMods.FirstOrDefault());
                        }));
                    });
                }
            };

            updateEntriesToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Update mod info");

                if (IsModUpdateTaskRunning)
                {
                    ShowModUpdateRunningMessageBox();
                    return;
                }

                SetStatus("Updating all mods...");

                var mods = Settings.Mods.All.ToList();
                UpdateMods(mods);
            };

            exitToolStripMenuItem.Click += (sender, e) =>
            {
                Log.Info("Menu->Close");
                Close();
            };

            #endregion Menu->File

            #region Menu->Options

            // show hidden
            showHiddenModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->File->Update mod info");
                Settings.ShowHiddenElements = showHiddenModsToolStripMenuItem.Checked;
                olvcHidden.IsVisible        = showHiddenModsToolStripMenuItem.Checked;
                RefreshModList(true);
            };

            // open Settings
            editOptionsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Options->Settings");
                var dialog = new SettingsDialog(Settings);

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // If the duplicate mod workaround is disabled, make sure that all mod info files are enabled.
                    if (!Settings.EnableDuplicateModIdWorkaround)
                    {
                        foreach (var mod in Mods.All)
                        {
                            mod.EnableModFile();
                        }

                        Mods.MarkDuplicates();
                    }

                    // refresh/update settings dependent functions
                    RefreshModList();
                    showHiddenModsToolStripMenuItem.Checked            = Settings.ShowHiddenElements;
                    modlist_ListObjectListView.UseTranslucentSelection = Settings.UseTranslucentModListSelection;
                    olvRequiredMods.UseTranslucentSelection            = Settings.UseTranslucentModListSelection;
                    olvDependentMods.UseTranslucentSelection           = Settings.UseTranslucentModListSelection;
                    cShowPrimaryDuplicates.Visible = Settings.EnableDuplicateModIdWorkaround;
                    InitQuickArgumentsMenu(Settings);

                    if (dialog.IsRestartRequired)
                    {
                        appRestartPendingLabel.Visible = true;
                        MessageBox.Show("Some changes won't take effect, until after the application has been restarted.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            };

            manageCategoriesToolStripMenuItem.Click += ManageCategoriesToolStripMenuItem_Click;

            #endregion Menu->Options

            #region Menu->Tools

            // -> Tools
            cleanModsToolStripMenuItem.Click += delegate { new CleanModsForm(Settings).ShowDialog(); };

            importFromXCOM2ToolStripMenuItem.Click += delegate
            {
                if (Program.XEnv is Xcom2Env x2Env)
                {
                    x2Env.UseWotC = false;
                    Log.Info("Menu->Tools->Import vanilla");
                    Program.XEnv.ImportActiveMods(Settings);
                    RefreshModList();
                }
            };

            importFromWotCToolStripMenuItem.Click += delegate
            {
                if (Program.XEnv is Xcom2Env x2Env)
                {
                    x2Env.UseWotC = true;
                    Log.Info("Menu->Tools->Import WotC");
                    Program.XEnv.ImportActiveMods(Settings);
                    RefreshModList();
                }
            };

            importFromChimeraSquadToolStripMenuItem.Click += delegate
            {
                if (Program.XEnv.Game == GameId.ChimeraSquad)
                {
                    Log.Info("Menu->Tools->Import Chimera Squad");
                    Program.XEnv.ImportActiveMods(Settings);
                    RefreshModList();
                }
            };

            resubscribeToModsToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->Tools->Resubscribe");
                var modsToDownload = Mods.All.Where(m => m.State.HasFlag(ModState.NotInstalled) && m.Source == ModSource.SteamWorkshop).ToList();
                var choice         = false;

                if (modsToDownload.Count == 0)
                {
                    MessageBox.Show("No uninstalled workshop mods were found.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (modsToDownload.Count == 1)
                {
                    choice = MessageBox.Show($"Are you sure you want to download the mod {modsToDownload[0].Name}?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }
                else
                {
                    choice = MessageBox.Show($"Are you sure you want to download {modsToDownload.Count} mods?", "Confirm Download", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK;
                }

                if (choice)
                {
                    foreach (var m in modsToDownload)
                    {
                        Log.Info("Subscribe and download " + m.ID);
                        Workshop.Subscribe((ulong)m.WorkshopID);
                        Workshop.DownloadItem((ulong)m.WorkshopID);
                    }

                    MessageBox.Show("Launch XCOM after the download is finished in order to use the mod" + (modsToDownload.Count == 1 ? "." : "s."), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };

            #endregion Menu->Tools

            #region Menu->About

            infoToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->About->About");
                AboutBox about = new AboutBox();
                about.ShowDialog();
            };

            checkForUpdatesToolStripMenuItem.Click += delegate
            {
                Log.Info("Menu->About->Check Update");

                if (!Program.CheckForUpdate())
                {
                    MessageBox.Show("No updates available", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };

            openHomepageToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://github.com/X2CommunityCore/xcom2-launcher"); };

            amlWikiToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://github.com/X2CommunityCore/xcom2-launcher/wiki"); };

            openDiscordToolStripMenuItem.Click += delegate { Tools.StartProcess(@"https://discord.gg/QHSVGRn"); };

            #endregion

            // RichTextBox clickable links
            //modinfo_readme_RichTextBox.LinkClicked += ControlLinkClicked;
            //modinfo_info_DescriptionRichTextBox.LinkClicked += ControlLinkClicked;
            //export_richtextbox.LinkClicked += ControlLinkClicked;
            //modinfo_changelog_richtextbox.LinkClicked += ControlLinkClicked;

            // Tab Controls
            //main_tabcontrol.Selected += MainTabSelected;
            //modinfo_tabcontrol.Selected += ModInfoTabSelected;

            // Steam Events
            Workshop.OnItemDownloaded += Resubscribe_OnItemDownloaded;

            // Main Tabs
            // Export
            export_workshop_link_checkbox.CheckedChanged += ExportCheckboxCheckedChanged;
            export_group_checkbox.CheckedChanged         += ExportCheckboxCheckedChanged;
            export_save_button.Click += ExportSaveButtonClick;
            export_load_button.Click += ExportLoadButtonClick;

            horizontal_splitcontainer.Paint += (sender, args) =>
            {
                if (sender is SplitContainer s)
                {
                    // Make the "splitter" from the SplitContainer slightly visible.
                    args.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), s.SplitterRectangle);
                }
            };
        }