Skip to content

Commit

Permalink
Add zoom crosshair as additional setting, minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hbivnm committed Jan 6, 2024
1 parent 6b92d57 commit 756dfbf
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 46 deletions.
48 changes: 37 additions & 11 deletions VenomCrosshairs/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 75 additions & 35 deletions VenomCrosshairs/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -512,6 +516,12 @@ private void initVC()
{
gUserSettings = JsonConvert.DeserializeObject<VCUserSettings>(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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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}";
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ()
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -1365,18 +1381,42 @@ private void generateMissingCrosshairs(List<string> 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<string> getCurrentCrosshairNames()
{
List<string> missingCrosshairs = new List<string>();
Expand Down
1 change: 1 addition & 0 deletions VenomCrosshairs/VCUserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}

0 comments on commit 756dfbf

Please sign in to comment.