From 756dfbf55cfee8135dab6101ddc7393938867bff Mon Sep 17 00:00:00 2001 From: hbivnm <47778018+hbivnm@users.noreply.github.com> Date: Sat, 6 Jan 2024 11:36:06 +0100 Subject: [PATCH] Add zoom crosshair as additional setting, minor code cleanup --- VenomCrosshairs/FormMain.Designer.cs | 48 +++++++++--- VenomCrosshairs/FormMain.cs | 110 ++++++++++++++++++--------- VenomCrosshairs/VCUserSettings.cs | 1 + 3 files changed, 113 insertions(+), 46 deletions(-) diff --git a/VenomCrosshairs/FormMain.Designer.cs b/VenomCrosshairs/FormMain.Designer.cs index 7c4ef51..9ed7ff2 100644 --- a/VenomCrosshairs/FormMain.Designer.cs +++ b/VenomCrosshairs/FormMain.Designer.cs @@ -46,7 +46,7 @@ private void InitializeComponent() this.checkBoxAddMiscWeapons = new System.Windows.Forms.CheckBox(); this.lblAdditionalSettings = new System.Windows.Forms.Label(); this.lblStatus = new System.Windows.Forms.Label(); - this.lblNoExplosion = new System.Windows.Forms.Label(); + this.lblExplosionEffect = new System.Windows.Forms.Label(); this.cbExplosionEffect = new System.Windows.Forms.ComboBox(); this.panelSettings = new System.Windows.Forms.Panel(); this.label4 = new System.Windows.Forms.Label(); @@ -71,6 +71,8 @@ private void InitializeComponent() this.btnAddCrosshair = new System.Windows.Forms.Button(); this.pictureBoxCrosshair = new System.Windows.Forms.PictureBox(); this.textBoxDebugger = new System.Windows.Forms.RichTextBox(); + this.cbZoomCrosshair = new System.Windows.Forms.ComboBox(); + this.lblZoomCrosshair = new System.Windows.Forms.Label(); this.panelSettings.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLoading)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCrosshair)).BeginInit(); @@ -248,14 +250,14 @@ private void InitializeComponent() this.lblStatus.TabIndex = 35; this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // lblNoExplosion + // lblExplosionEffect // - this.lblNoExplosion.AutoSize = true; - this.lblNoExplosion.Location = new System.Drawing.Point(352, 74); - this.lblNoExplosion.Name = "lblNoExplosion"; - this.lblNoExplosion.Size = new System.Drawing.Size(85, 13); - this.lblNoExplosion.TabIndex = 32; - this.lblNoExplosion.Text = "Explosion effect:"; + this.lblExplosionEffect.AutoSize = true; + this.lblExplosionEffect.Location = new System.Drawing.Point(352, 74); + this.lblExplosionEffect.Name = "lblExplosionEffect"; + this.lblExplosionEffect.Size = new System.Drawing.Size(85, 13); + this.lblExplosionEffect.TabIndex = 32; + this.lblExplosionEffect.Text = "Explosion effect:"; // // cbExplosionEffect // @@ -270,7 +272,7 @@ private void InitializeComponent() "Spy sapper"}); this.cbExplosionEffect.Location = new System.Drawing.Point(443, 71); this.cbExplosionEffect.Name = "cbExplosionEffect"; - this.cbExplosionEffect.Size = new System.Drawing.Size(120, 21); + this.cbExplosionEffect.Size = new System.Drawing.Size(132, 21); this.cbExplosionEffect.TabIndex = 31; // // panelSettings @@ -534,17 +536,39 @@ private void InitializeComponent() this.textBoxDebugger.TabIndex = 42; this.textBoxDebugger.Text = ""; // + // cbZoomCrosshair + // + this.cbZoomCrosshair.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbZoomCrosshair.FormattingEnabled = true; + this.cbZoomCrosshair.Items.AddRange(new object[] { + "NO CHANGE"}); + this.cbZoomCrosshair.Location = new System.Drawing.Point(443, 98); + this.cbZoomCrosshair.Name = "cbZoomCrosshair"; + this.cbZoomCrosshair.Size = new System.Drawing.Size(132, 21); + this.cbZoomCrosshair.TabIndex = 43; + // + // lblZoomCrosshair + // + this.lblZoomCrosshair.AutoSize = true; + this.lblZoomCrosshair.Location = new System.Drawing.Point(354, 101); + this.lblZoomCrosshair.Name = "lblZoomCrosshair"; + this.lblZoomCrosshair.Size = new System.Drawing.Size(82, 13); + this.lblZoomCrosshair.TabIndex = 44; + this.lblZoomCrosshair.Text = "Zoom crosshair:"; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Control; this.ClientSize = new System.Drawing.Size(1235, 551); + this.Controls.Add(this.cbZoomCrosshair); + this.Controls.Add(this.lblZoomCrosshair); this.Controls.Add(this.textBoxDebugger); this.Controls.Add(this.btnSettings); this.Controls.Add(this.panelSettings); this.Controls.Add(this.cbExplosionEffect); - this.Controls.Add(this.lblNoExplosion); + this.Controls.Add(this.lblExplosionEffect); this.Controls.Add(this.btnReadConfig); this.Controls.Add(this.btnToggleConsole); this.Controls.Add(this.lblStatus); @@ -622,7 +646,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnToggleConsole; private System.Windows.Forms.Button btnHelp; private System.Windows.Forms.Button btnReadConfig; - private System.Windows.Forms.Label lblNoExplosion; + private System.Windows.Forms.Label lblExplosionEffect; private System.Windows.Forms.ComboBox cbExplosionEffect; private System.Windows.Forms.Button btnDarkMode; private System.Windows.Forms.Panel panelSettings; @@ -633,6 +657,8 @@ private void InitializeComponent() private System.Windows.Forms.Label lblDarkMode; private System.Windows.Forms.Button btnSettings; private System.Windows.Forms.RichTextBox textBoxDebugger; + private System.Windows.Forms.ComboBox cbZoomCrosshair; + private System.Windows.Forms.Label lblZoomCrosshair; } } diff --git a/VenomCrosshairs/FormMain.cs b/VenomCrosshairs/FormMain.cs index 61d84b0..9c58d37 100644 --- a/VenomCrosshairs/FormMain.cs +++ b/VenomCrosshairs/FormMain.cs @@ -22,7 +22,7 @@ namespace VenomCrosshairs { public partial class FormMain : Form { - private static readonly string VC_VERSION = "beta13.2"; + private static readonly string VC_VERSION = "beta14.0"; private static readonly string VC_CONFIG_NAME = "_VenomCrosshairsConfig"; @@ -391,6 +391,12 @@ private void onCBCrosshairChangeEvent(object sender, EventArgs e) checkBoxAddMiscWeapons.Enabled = true; } + private void onCBZoomCrosshairChangeEvent(object sender, EventArgs e) + { + gUserSettings.UserZoomCrosshair = cbZoomCrosshair.Text; + File.WriteAllText(PATH_VC_RESOURCES_VC_USERSETTINGS_CFG_FILE, JsonConvert.SerializeObject(gUserSettings)); + } + private void onCheckBoxAddClassWeaponsChangeEvent(object sender, EventArgs e) { if (checkBoxAddOnlyClass.Checked) @@ -467,15 +473,13 @@ private void initVC() cbWeapon.SelectedIndexChanged += new EventHandler(onCBWeaponChangeEvent); // Crosshairs - cbCrosshair.Items.Clear(); - foreach (var crosshair in Directory.GetFiles(PATH_VC_RESOURCES_PREVIEWS, "*.png")) - { - string crosshairName = Path.GetFileNameWithoutExtension(crosshair); - cbCrosshair.Items.Add(crosshairName); - } - setComboBoxDropDownWidthToLongestStringPixelWidth(cbCrosshair); + addCrosshairsToComboBoxFromPath(cbCrosshair, PATH_VC_RESOURCES_PREVIEWS, true); cbCrosshair.SelectedIndexChanged += new EventHandler(onCBCrosshairChangeEvent); + // Zoom crosshair + addCrosshairsToComboBoxFromPath(cbZoomCrosshair, PATH_VC_RESOURCES_PREVIEWS, new string[] { "NO CHANGE" }, true); + cbZoomCrosshair.SelectedIndexChanged += new EventHandler(onCBZoomCrosshairChangeEvent); + // Checkboxes checkBoxAddOnlyClass.CheckStateChanged += new EventHandler(onCheckBoxAddClassWeaponsChangeEvent); @@ -512,6 +516,12 @@ private void initVC() { gUserSettings = JsonConvert.DeserializeObject(File.ReadAllText(PATH_VC_RESOURCES_VC_USERSETTINGS_CFG_FILE)); + // Zoom Crosshair + if (gUserSettings.UserZoomCrosshair != null) + cbZoomCrosshair.Text = gUserSettings.UserZoomCrosshair; + else + cbZoomCrosshair.Text = "NO CHANGE"; + // Explosion effect cbExplosionEffect.SelectedIndex = gUserSettings.UserExplosionEffectIndex; @@ -881,6 +891,7 @@ private void performInstallation(bool removeOldConfig) btnDownload.Enabled = false; cbClass.Enabled = false; cbCrosshair.Enabled = false; + cbZoomCrosshair.Enabled = false; cbWeapon.Enabled = false; btnAddCrosshair.Enabled = false; checkBoxAddOnlyClass.Enabled = false; @@ -924,6 +935,12 @@ private void performInstallation(bool removeOldConfig) writeToDebugger("Copying materials... "); Invoke(new MethodInvoker(delegate () { + if (cbZoomCrosshair.Text != "NO CHANGE") + { + File.Copy($@"{PATH_VC_RESOURCES_MATERIALS}\{cbZoomCrosshair.Text}.vmt", $@"{textBoxTF2Path.Text}\tf\custom\{VC_CONFIG_NAME}\materials\vgui\replay\thumbnails\{cbZoomCrosshair.Text}.vmt", true); + File.Copy($@"{PATH_VC_RESOURCES_MATERIALS}\{cbZoomCrosshair.Text}.vtf", $@"{textBoxTF2Path.Text}\tf\custom\{VC_CONFIG_NAME}\materials\vgui\replay\thumbnails\{cbZoomCrosshair.Text}.vtf", true); + } + foreach (ListViewItem item in listViewChosenCrosshairs.Items) { string crosshair = item.SubItems[0].Text; @@ -940,6 +957,11 @@ private void performInstallation(bool removeOldConfig) foreach (ListViewItem item in listViewChosenCrosshairs.Items) { string crosshair = item.SubItems[0].Text; + + string zoomCrosshair = cbZoomCrosshair.Text; + if (cbZoomCrosshair.Text == "NO CHANGE") + zoomCrosshair = crosshair; + string weaponName = item.SubItems[1].Text; string weaponScriptName = TF2Weapons.getWeaponScriptFromWeaponName(weaponName); string fullScriptPath = $@"{textBoxTF2Path.Text}\tf\custom\{VC_CONFIG_NAME}\scripts\{weaponScriptName}"; @@ -957,6 +979,7 @@ private void performInstallation(bool removeOldConfig) .Replace("VC_PLACEHOLDER_EXPLOSION_PLAYER_EFFECT", getExplosionPlayerEffectParticleName(cbExplosionEffect.Text)) .Replace("VC_PLACEHOLDER_EXPLOSION_WATER_EFFECT", getExplosionWaterEffectParticleName(cbExplosionEffect.Text)) .Replace("VC_PLACEHOLDER", crosshair) + .Replace("VC_ZOOM_PLACEHOLDER", zoomCrosshair) ); } catch (Exception ex) @@ -1022,6 +1045,7 @@ private void performInstallation(bool removeOldConfig) btnDownload.Enabled = true; cbClass.Enabled = true; cbCrosshair.Enabled = true; + cbZoomCrosshair.Enabled = true; cbWeapon.Enabled = true; btnAddCrosshair.Enabled = true; checkBoxAddOnlyClass.Enabled = true; @@ -1053,6 +1077,7 @@ private void reloadCrosshairList() btnDownload.Enabled = false; cbClass.Enabled = false; cbCrosshair.Enabled = false; + cbZoomCrosshair.Enabled = false; cbWeapon.Enabled = false; btnAddCrosshair.Enabled = false; checkBoxAddOnlyClass.Enabled = false; @@ -1130,15 +1155,8 @@ private void reloadCrosshairList() // Add to ComboBox Invoke(new MethodInvoker(delegate () { - cbCrosshair.Items.Clear(); - foreach (var crosshair in Directory.GetFiles(PATH_VC_RESOURCES_PREVIEWS, "*.png")) - { - string crosshairName = Path.GetFileNameWithoutExtension(crosshair); - cbCrosshair.Items.Add(crosshairName); - } - - // Set Crosshair ComboBox width - setComboBoxDropDownWidthToLongestStringPixelWidth(cbCrosshair); + addCrosshairsToComboBoxFromPath(cbCrosshair, PATH_VC_RESOURCES_PREVIEWS, true); + addCrosshairsToComboBoxFromPath(cbZoomCrosshair, PATH_VC_RESOURCES_PREVIEWS, new string[] { "NO CHANGE" }, true); })); Invoke(new MethodInvoker(delegate () @@ -1151,6 +1169,8 @@ private void reloadCrosshairList() cbWeapon.SelectedIndex = -1; cbCrosshair.Enabled = false; cbCrosshair.SelectedIndex = -1; + cbZoomCrosshair.Enabled = true; + cbZoomCrosshair.Text = gUserSettings.UserZoomCrosshair; btnReload.Enabled = true; btnDownload.Enabled = true; btnReadConfig.Enabled = true; @@ -1173,6 +1193,7 @@ private void downloadAndGenerateNewCrosshairs() btnDownload.Enabled = false; cbClass.Enabled = false; cbCrosshair.Enabled = false; + cbZoomCrosshair.Enabled = false; cbWeapon.Enabled = false; btnAddCrosshair.Enabled = false; checkBoxAddOnlyClass.Enabled = false; @@ -1256,15 +1277,8 @@ private void downloadAndGenerateNewCrosshairs() // Add to ComboBox Invoke(new MethodInvoker(delegate () { - cbCrosshair.Items.Clear(); - foreach (var crosshair in Directory.GetFiles(PATH_VC_RESOURCES_PREVIEWS, "*.png")) - { - string crosshairName = Path.GetFileNameWithoutExtension(crosshair); - cbCrosshair.Items.Add(crosshairName); - } - - // Set Crosshair ComboBox width - setComboBoxDropDownWidthToLongestStringPixelWidth(cbCrosshair); + addCrosshairsToComboBoxFromPath(cbCrosshair, PATH_VC_RESOURCES_PREVIEWS, true); + addCrosshairsToComboBoxFromPath(cbZoomCrosshair, PATH_VC_RESOURCES_PREVIEWS, new string[] { "NO CHANGE" }, true); })); _ = isNewCrosshairsAvailable(true); @@ -1285,6 +1299,8 @@ private void downloadAndGenerateNewCrosshairs() cbWeapon.SelectedIndex = -1; cbCrosshair.Enabled = false; cbCrosshair.SelectedIndex = -1; + cbZoomCrosshair.Enabled = true; + cbZoomCrosshair.Text = gUserSettings.UserZoomCrosshair; btnReload.Enabled = true; btnDownload.Enabled = true; btnReadConfig.Enabled = true; @@ -1365,18 +1381,42 @@ private void generateMissingCrosshairs(List missingCrosshairNames) // Add to ComboBox Invoke(new MethodInvoker(delegate () { - cbCrosshair.Items.Clear(); - foreach (var crosshair in Directory.GetFiles(PATH_VC_RESOURCES_PREVIEWS, "*.png")) - { - string crosshairName = Path.GetFileNameWithoutExtension(crosshair); - cbCrosshair.Items.Add(crosshairName); - } - - // Set Crosshair ComboBox width - setComboBoxDropDownWidthToLongestStringPixelWidth(cbCrosshair); + addCrosshairsToComboBoxFromPath(cbCrosshair, PATH_VC_RESOURCES_PREVIEWS, true); + addCrosshairsToComboBoxFromPath(cbZoomCrosshair, PATH_VC_RESOURCES_PREVIEWS, new string[] { "NO CHANGE" }, true); })); } + private void addCrosshairsToComboBoxFromPath(ComboBox cb, string path, string[] prependItems, bool clearComboBoxItems) + { + if (clearComboBoxItems) + cb.Items.Clear(); + + foreach (var item in prependItems) + cb.Items.Add(item); + + foreach (var crosshair in Directory.GetFiles(path, "*.png")) + { + string crosshairName = Path.GetFileNameWithoutExtension(crosshair); + cb.Items.Add(crosshairName); + } + + setComboBoxDropDownWidthToLongestStringPixelWidth(cb); + } + + private void addCrosshairsToComboBoxFromPath(ComboBox cb, string path, bool clearComboBoxItems) + { + if (clearComboBoxItems) + cb.Items.Clear(); + + foreach (var crosshair in Directory.GetFiles(path, "*.png")) + { + string crosshairName = Path.GetFileNameWithoutExtension(crosshair); + cb.Items.Add(crosshairName); + } + + setComboBoxDropDownWidthToLongestStringPixelWidth(cb); + } + private List getCurrentCrosshairNames() { List missingCrosshairs = new List(); diff --git a/VenomCrosshairs/VCUserSettings.cs b/VenomCrosshairs/VCUserSettings.cs index 144b98b..5d36109 100644 --- a/VenomCrosshairs/VCUserSettings.cs +++ b/VenomCrosshairs/VCUserSettings.cs @@ -11,5 +11,6 @@ internal class VCUserSettings public bool IsDarkMode { get; set; } public int UserExplosionEffectIndex { get; set; } public string UserTF2Path { get; set; } + public string UserZoomCrosshair { get; set; } } }