using FSO.Content; using FSO.Files.Formats.IFF.Chunks; using FSO.IDE.EditorComponent; using FSO.IDE.EditorComponent.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text.RegularExpressions; using System.Windows.Forms; namespace FSO.IDE.ResourceBrowser { public partial class SelectTreeDialog : Form { GameIffResource Resource; public List CurrentFullList; public ushort ResultID = 0; public SelectTreeDialog(GameIffResource res) { InitializeComponent(); Resource = res; CurrentFullList = new List(); CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.Private)); CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.SemiGlobal)); CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.Global)); RenderList(); } public List GetAllResource(ScopeSource source) { switch (source) { case ScopeSource.Private: return (Resource is GameGlobalResource)? new List():Resource.List(); case ScopeSource.SemiGlobal: return (Resource.SemiGlobal == null) ? new List():Resource.SemiGlobal.List(); case ScopeSource.Global: return EditorScope.Globals.Resource.List(); default: return new List(); } } public List GetAllSubroutines(ScopeSource source) { var bhavs = GetAllResource(source); if (source == ScopeSource.SemiGlobal && Resource is GameGlobalResource) bhavs = Resource.List(); var output = new List(); if (bhavs == null) return output; foreach (var bhav in bhavs) { output.Add(new InstructionIDNamePair(bhav.ChunkLabel, bhav.ChunkID)); } output = output.OrderBy(o => o.Name).ToList(); return output; } private void RenderList() { var searchString = new Regex(".*" + SearchBox.Text.ToLowerInvariant() + ".*"); PrimitiveList.ClearSelected(); PrimitiveList.Items.Clear(); foreach (var prim in CurrentFullList) { if (searchString.IsMatch(prim.ToString().ToLowerInvariant())) PrimitiveList.Items.Add(prim); } } private void SearchBox_TextChanged(object sender, EventArgs e) { RenderList(); } private void SelectButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; this.Close(); } private void PrimitiveList_SelectedIndexChanged(object sender, EventArgs e) { ResultID = (PrimitiveList.SelectedItem == null)?(ushort)0:((InstructionIDNamePair)PrimitiveList.SelectedItem).ID; SelectButton.Text = "Select " + ((PrimitiveList.SelectedItem == null) ? "None" : ((InstructionIDNamePair)PrimitiveList.SelectedItem).Name); } } }