Skip to content

Commit

Permalink
Rebranded to AudioHotkey Soundboard
Browse files Browse the repository at this point in the history
Changed a lot of stuff
  • Loading branch information
753 authored and 753 committed Apr 18, 2020
1 parent a53e7b9 commit 7f2b985
Show file tree
Hide file tree
Showing 29 changed files with 10,429 additions and 32,362 deletions.
212 changes: 81 additions & 131 deletions AddEditHotkeyForm.Designer.cs

Large diffs are not rendered by default.

171 changes: 69 additions & 102 deletions AddEditHotkeyForm.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace JNSoundboard
namespace AudioHotkeySoundboard
{
public partial class AddEditHotkeyForm : Form
{
internal class ListViewItemComparer : IComparer
{
private int col;

public ListViewItemComparer()
{
col = 0;
}

public ListViewItemComparer(int column)
{
col = column;
}

public int Compare(object x, object y)
{
return string.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
}
}

internal string[] editStrings = null;
internal int editIndex = -1;

Expand All @@ -46,67 +27,26 @@ private void AddEditSoundKeys_Load(object sender, EventArgs e)
{
if (SettingsForm.addingEditingLoadXMLFile)
{
//hide window restriction
gbWindowRestriction.Visible = false;
this.MinimumSize = new Size(375, 170);
this.Size = new Size(375, 170);

settingsForm = Application.OpenForms[1] as SettingsForm;

this.Text = "Add/edit keys and XML location";

if (editIndex != -1)
{
tbKeys.Text = editStrings[0];
tbLocation.Text = editStrings[1];
tbLocation.Text = editStrings[0];
tbKeys.Text = editStrings[1];
}
}
else
{
mainForm = Application.OpenForms[0] as MainForm;

labelLoc.Text += " (use a semi-colon (;) to seperate multiple locations)";

loadWindows();
//labelLoc.Text += " (use a semi-colon (;) to separate multiple locations)";

if (editIndex != -1)
{
tbKeys.Text = editStrings[0];

if (editStrings[1] != "")
{
cbEnableRestrictWindow.Checked = true;

int index = cbWindows.Items.IndexOf(editStrings[1]);

if (index != -1) cbWindows.SelectedIndex = index;
else
{
cbWindows.Items.Add(editStrings[1]);
cbWindows.SelectedIndex = cbWindows.Items.Count - 1;
}
}

tbLocation.Text = editStrings[2];
}


}
}

private void loadWindows()
{
cbWindows.Items.Clear();

cbWindows.Items.Add("");

Process[] processlist = Process.GetProcesses();

foreach (Process process in processlist)
{
if (!string.IsNullOrEmpty(process.MainWindowTitle))
{
cbWindows.Items.Add(process.MainWindowTitle);
tbLocation.Text = editStrings[0];
tbKeys.Text = editStrings[1];
}
}
}
Expand All @@ -130,7 +70,7 @@ private void btnOK_Click(object sender, EventArgs e)

if (!SettingsForm.addingEditingLoadXMLFile)
{
if (!SettingsForm.addingEditingLoadXMLFile && Helper.soundLocsArrayFromString(tbLocation.Text, out soundLocs, out errorMessage))
if (Helper.soundLocsArrayFromString(tbLocation.Text, out soundLocs, out errorMessage))
{
if (soundLocs.Any(x => string.IsNullOrWhiteSpace(x) || !File.Exists(x)))
{
Expand All @@ -157,59 +97,51 @@ private void btnOK_Click(object sender, EventArgs e)
{
if (editIndex != -1)
{
settingsForm.lvKeysLocs.Items[editIndex].Text = tbKeys.Text;
settingsForm.lvKeysLocs.Items[editIndex].SubItems[1].Text = tbLocation.Text;
settingsForm.dgvSoundboardFiles.Rows[editIndex].Cells[0].Value = tbLocation.Text;
settingsForm.dgvSoundboardFiles.Rows[editIndex].Cells[1].Value = tbKeys.Text;

settingsForm.loadXMLFilesList[editIndex].Keys = keysArr;
settingsForm.loadXMLFilesList[editIndex].XMLLocation = tbLocation.Text;
}
else
{
var item = new ListViewItem(tbKeys.Text);
item.SubItems.Add(tbLocation.Text);
object[] newRow = new object[2];
newRow[0] = Helper.fileNamesFromLocations(tbLocation.Text);
newRow[1] = tbKeys.Text;

settingsForm.lvKeysLocs.Items.Add(item);
settingsForm.dgvSoundboardFiles.Rows.Add(newRow);

settingsForm.loadXMLFilesList.Add(new XMLSettings.LoadXMLFile(keysArr, tbLocation.Text));
}
}
else
{
string windowText = "";
if (cbEnableRestrictWindow.Checked && (string)cbWindows.SelectedItem != "") windowText = (string)cbWindows.SelectedItem;

if (editIndex > -1)
{
mainForm.lvKeySounds.Items[editIndex].Text = tbKeys.Text;
mainForm.lvKeySounds.Items[editIndex].SubItems[1].Text = windowText;
mainForm.lvKeySounds.Items[editIndex].SubItems[2].Text = tbLocation.Text;
mainForm.dgvKeySounds.Rows[editIndex].Cells[0].Value = Helper.fileNamesFromLocations(tbLocation.Text);
mainForm.dgvKeySounds.Rows[editIndex].Cells[1].Value = tbKeys.Text;

mainForm.soundHotkeys[editIndex] = new XMLSettings.SoundHotkey(keysArr, windowText, soundLocs);
mainForm.soundHotkeys[editIndex] = new XMLSettings.SoundHotkey(keysArr, soundLocs);
}
else
{
var newItem = new ListViewItem(tbKeys.Text);
newItem.SubItems.Add(windowText);
newItem.SubItems.Add(tbLocation.Text);
object[] newRow = new object[2];
newRow[0] = Helper.fileNamesFromLocations(tbLocation.Text);
newRow[1] = tbKeys.Text;

mainForm.lvKeySounds.Items.Add(newItem);
mainForm.dgvKeySounds.Rows.Add(newRow);

mainForm.soundHotkeys.Add(new XMLSettings.SoundHotkey(keysArr, windowText, soundLocs));
mainForm.soundHotkeys.Add(new XMLSettings.SoundHotkey(keysArr, soundLocs));
}

mainForm.lvKeySounds.ListViewItemSorter = new ListViewItemComparer(0);
mainForm.lvKeySounds.Sort();

mainForm.dgvKeySounds.Sort(mainForm.dgvKeySounds.Columns[0], ListSortDirection.Ascending);
mainForm.soundHotkeys.Sort(delegate (XMLSettings.SoundHotkey x, XMLSettings.SoundHotkey y)
{
if (x.Keys == null && y.Keys == null) return 0;
else if (x.Keys == null) return -1;
else if (y.Keys == null) return 1;
else return Helper.keysToString(x.Keys).CompareTo(Helper.keysToString(y.Keys));
if (x.SoundClips == null && y.SoundClips == null) return 0;
else if (x.SoundClips == null) return -1;
else if (y.SoundClips == null) return 1;
else return x.SoundClips.CompareTo(y.SoundClips);
});

mainForm.chKeys.Width = -2;
mainForm.chSoundLoc.Width = -2;
}

this.Close();
Expand Down Expand Up @@ -238,10 +170,17 @@ private void btnBrowseSoundLoc_Click(object sender, EventArgs e)
{
string fileName = diag.FileNames[i];

if (fileName != "") text += (i == 0 ? "" : ";") + fileName;
if (fileName != "") text += (i == 0 ? "" : " > ") + fileName;
}

tbLocation.Text = text;
if (!SettingsForm.addingEditingLoadXMLFile)
{
if (text.Contains(">"))
{
labelLoc.Text = "Location of file (multiple locations mean one will be selected at random on play)";
}
}
}
}

Expand Down Expand Up @@ -273,7 +212,7 @@ private void timer1_Tick(object sender, EventArgs e)

foreach (Keys key in Enum.GetValues(typeof(Keys)))
{
if (Keyboard.IsKeyDown(key))
if (Keyboard.IsKeyDown(key) && key.ToString() != "LButton" && key.ToString() != "RButton")
{
amountPressed++;
pressedKeys.Add(key);
Expand All @@ -289,15 +228,43 @@ private void timer1_Tick(object sender, EventArgs e)
}
}

private void cbEnableRestrictWindow_CheckedChanged(object sender, EventArgs e)
int lastAmountPressed2 = 0;

private void timer2_Tick(object sender, EventArgs e)
{
cbWindows.Enabled = cbEnableRestrictWindow.Checked;
btnReloadWindows.Enabled = cbEnableRestrictWindow.Checked;
int amountPressed = 0;

if (Keyboard.IsKeyDown(Keys.Escape))
{
lastAmountPressed2 = 50;

tbKeys.Text = "";
}
else
{
var pressedKeys = new List<Keys>();

foreach (Keys key in Enum.GetValues(typeof(Keys)))
{
if (Keyboard.IsKeyDown(key) && key.ToString() != "LButton" && key.ToString() != "RButton")
{
amountPressed++;
pressedKeys.Add(key);
}
}

if (amountPressed > lastAmountPressed2)
{
tbKeys.Text = Helper.keysToString(pressedKeys.ToArray());
}

lastAmountPressed2 = amountPressed;
}
}

private void btnReloadWindows_Click(object sender, EventArgs e)
private void ButtonClear_Click(object sender, EventArgs e)
{
loadWindows();
tbKeys.Text = "";
}
}
}
Loading

0 comments on commit 7f2b985

Please sign in to comment.