CodeWalker/Project/Panels/EditAudioEmitterListPanel.cs

151 lines
4.3 KiB
C#
Raw Normal View History

2018-12-25 19:40:49 +08:00
using CodeWalker.GameFiles;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodeWalker.Project.Panels
{
public partial class EditAudioEmitterListPanel : ProjectPanel
{
public ProjectForm ProjectForm;
public Dat151AmbientEmitterList CurrentEmitterList { get; set; }
2018-12-27 18:37:44 +08:00
private bool populatingui = false;
2018-12-25 19:40:49 +08:00
public EditAudioEmitterListPanel(ProjectForm owner)
{
ProjectForm = owner;
InitializeComponent();
}
public void SetEmitterList(Dat151AmbientEmitterList list)
{
CurrentEmitterList = list;
2018-12-26 21:20:39 +08:00
Tag = list;
2018-12-25 19:40:49 +08:00
UpdateFormTitle();
2018-12-27 18:37:44 +08:00
UpdateUI();
2018-12-25 19:40:49 +08:00
}
private void UpdateFormTitle()
{
Text = CurrentEmitterList?.NameHash.ToString() ?? "";
}
2018-12-27 18:37:44 +08:00
private void UpdateUI()
{
if (CurrentEmitterList == null)
{
//AddToProjectButton.Enabled = false;
//DeleteButton.Enabled = false;
populatingui = true;
NameTextBox.Text = string.Empty;
HashesTextBox.Text = string.Empty;
populatingui = false;
}
else
{
//AddToProjectButton.Enabled = CurrentZoneList?.Rel != null ? !ProjectForm.AudioFileExistsInProject(CurrentZoneList.Rel) : false;
//DeleteButton.Enabled = !AddToProjectButton.Enabled;
populatingui = true;
var el = CurrentEmitterList;
NameTextBox.Text = el.NameHash.ToString();
StringBuilder sb = new StringBuilder();
if (el.EmitterHashes != null)
{
foreach (var hash in el.EmitterHashes)
{
sb.AppendLine(hash.ToString());
}
}
HashesTextBox.Text = sb.ToString();
populatingui = false;
}
}
private void ProjectItemChanged()
{
if (CurrentEmitterList?.Rel != null)
{
ProjectForm.SetAudioFileHasChanged(true);
}
}
private void NameTextBox_TextChanged(object sender, EventArgs e)
{
if (populatingui) return;
if (CurrentEmitterList == null) return;
uint hash = 0;
string name = NameTextBox.Text;
if (!uint.TryParse(name, out hash))//don't re-hash hashes
{
hash = JenkHash.GenHash(name);
JenkIndex.Ensure(name);
}
//NameHashLabel.Text = "Hash: " + hash.ToString();
if (CurrentEmitterList.NameHash != hash)
{
CurrentEmitterList.Name = NameTextBox.Text;
CurrentEmitterList.NameHash = hash;
ProjectItemChanged();
UpdateFormTitle();
}
}
private void HashesTextBox_TextChanged(object sender, EventArgs e)
{
if (populatingui) return;
if (CurrentEmitterList == null) return;
var hashstrs = HashesTextBox.Text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
if (hashstrs?.Length > 0)
{
var hashlist = new List<MetaHash>();
foreach (var hashstr in hashstrs)
{
uint hash = 0;
if (!uint.TryParse(hashstr, out hash))//don't re-hash hashes
{
hash = JenkHash.GenHash(hashstr);
JenkIndex.Ensure(hashstr);
}
hashlist.Add(hash);
}
CurrentEmitterList.EmitterHashes = hashlist.ToArray();
CurrentEmitterList.EmitterCount = (byte)hashlist.Count;
ProjectItemChanged();
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
ProjectForm.SetProjectItem(CurrentEmitterList);
ProjectForm.DeleteAudioEmitterList();
}
2018-12-25 19:40:49 +08:00
}
}