Skip to content

Commit

Permalink
faster opening/closing of hip, plat preview
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Dec 5, 2018
1 parent 1ecdda5 commit 318c857
Show file tree
Hide file tree
Showing 19 changed files with 1,111 additions and 183 deletions.

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

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

94 changes: 44 additions & 50 deletions IndustrialPark/ArchiveEditor/ArchiveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public ArchiveEditor(string filePath)
archive = new ArchiveEditorFunctions();
defaultColor = textBoxFindAsset.BackColor;

textBoxFindAsset.AutoCompleteSource = AutoCompleteSource.CustomSource;
archive.SetTextboxForAutocomplete(textBoxFindAsset);

programIsChangingStuff = true;

foreach (LayerType o in Enum.GetValues(typeof(LayerType)))
Expand All @@ -34,9 +37,6 @@ public ArchiveEditor(string filePath)
if (!string.IsNullOrWhiteSpace(filePath))
OpenFile(filePath);

textBoxFindAsset.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxFindAsset.AutoCompleteCustomSource = archive.autoCompleteSource;

MainForm.PopulateTemplateMenusAt(addTemplateToolStripMenuItem, TemplateToolStripMenuItem_Click);
listViewAssets_SizeChanged(null, null);
}
Expand Down Expand Up @@ -95,23 +95,14 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
};
if (openFile.ShowDialog() == DialogResult.OK)
{
Thread t = new Thread(() => OpenFile(openFile.FileName));
t.Start();
OpenFile(openFile.FileName);
}
}

private void OpenFile(string fileName)
{
archive.OpenFile(fileName);

if (!InvokeRequired)
FinishedOpening(fileName);
else
Invoke(new Action<string>(FinishedOpening), fileName);
}

private void FinishedOpening(string fileName)
{
toolStripStatusLabelCurrentFilename.Text = "File: " + fileName;
Text = Path.GetFileName(fileName);
Program.MainForm.SetToolStripItemName(this, Text);
Expand All @@ -129,7 +120,7 @@ private void FinishedOpening(string fileName)
PopulateLayerComboBox();
PopulateAssetList();
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
Save();
Expand Down Expand Up @@ -178,13 +169,13 @@ public void CloseArchiveEditor()
{
archive.Dispose();

Program.MainForm.CloseAssetEditor(this);
Program.MainForm.CloseArchiveEditor(this);
Close();
}

public void DisposeAll()
public void DisposeForClosing()
{
archive.Dispose();
archive.DisposeForClosing();
}

private bool programIsChangingStuff = false;
Expand Down Expand Up @@ -361,40 +352,44 @@ private void PopulateAssetListAndComboBox()

AssetType curType = AssetType.Null;

private void PopulateAssetList(AssetType type = AssetType.Null)
private void PopulateAssetList(AssetType type = AssetType.Null, bool select = false, List<uint> selectionAssetIDs = null)
{
curType = type;
listViewAssets.BeginUpdate();
listViewAssets.Items.Clear();

int ensureVisible = -1;

if (comboBoxLayers.SelectedItem != null)
{
List<uint> assetIDs = archive.DICT.LTOC.LHDRList[comboBoxLayers.SelectedIndex].assetIDlist;
List<ListViewItem> items = new List<ListViewItem>();

for (int i = 0; i < assetIDs.Count(); i++)
{
Asset asset = archive.GetFromAssetID(assetIDs[i]);
if (type == AssetType.Null || asset.AHDR.assetType == type)
listViewAssets.Items.Add(new ListViewItem(asset.ToString())
{ Checked = !asset.isInvisible });
// assetList.Add(new Tuple<bool, string>(!asset.isInvisible, asset.ToString()));
}

//assetList.Sort();

//programIsChangingStuff = true;
{
bool selected = (select == true) && selectionAssetIDs.Contains(asset.AHDR.assetID);
items.Add(new ListViewItem(asset.ToString())
{
Checked = !asset.isInvisible,
Selected = selected
});

//foreach (Tuple<bool, string> t in assetList)
//{
// listViewAssets.Items.Add(new ListViewItem(t.Item2));
// listViewAssets.Items[listViewAssets.Items.Count - 1].Checked = t.Item1;
//}
if (selected)
ensureVisible = items.Count - 1;
}
}

//programIsChangingStuff = false;
listViewAssets.Items.AddRange(items.ToArray());
}

listViewAssets.EndUpdate();

if (select)
listViewAssets.EnsureVisible(ensureVisible);

toolStripStatusLabelSelectionCount.Text = $"{listViewAssets.SelectedItems.Count}/{listViewAssets.Items.Count} assets selected";
}

Expand Down Expand Up @@ -792,13 +787,10 @@ public void MouseMoveGeneric(Matrix viewProjection, int deltaX, int deltaY)

public void SetSelectedIndices(List<uint> assetIDs, bool newlyAddedObjects, bool add = false)
{
listViewAssets.BeginUpdate();

if (assetIDs.Contains(0) && !add)
{
listViewAssets.SelectedIndices.Clear();
ArchiveEditorFunctions.UpdateGizmoPosition();
listViewAssets.EndUpdate();
return;
}

Expand All @@ -812,43 +804,45 @@ public void SetSelectedIndices(List<uint> assetIDs, bool newlyAddedObjects, bool
if (add)
assetIDs.AddRange(CurrentlySelectedAssetIDs());

listViewAssets.SelectedIndices.Clear();

AssetType assetType = AssetType.Null;

foreach (uint u in assetIDs)
{
assetType = archive.GetFromAssetID(u).AHDR.assetType;
comboBoxLayers.SelectedIndex = archive.GetLayerFromAssetID(u);
if (archive.GetLayerFromAssetID(u) != comboBoxLayers.SelectedIndex)
comboBoxLayers.SelectedIndex = archive.GetLayerFromAssetID(u);
break;
}

foreach (uint u in assetIDs)
if (archive.GetFromAssetID(u).AHDR.assetType != assetType)
{
assetType = AssetType.Null;
comboBoxAssetTypes.SelectedIndex = 0;
break;
}

if (curType != assetType || newlyAddedObjects)
{
comboBoxAssetTypes.SelectedItem = assetType;
PopulateAssetList(assetType);
}
if (assetType == AssetType.Null)
comboBoxAssetTypes.SelectedIndex = 0;
else
comboBoxAssetTypes.SelectedItem = assetType;

int last = 0;
foreach (uint u in assetIDs)
PopulateAssetList(assetType, true, assetIDs);
return;
}
else
{
listViewAssets.SelectedIndices.Clear();
int last = 0;
for (int i = 0; i < listViewAssets.Items.Count; i++)
if (GetAssetIDFromName(listViewAssets.Items[i].Text) == u)
if (assetIDs.Contains(GetAssetIDFromName(listViewAssets.Items[i].Text)))
{
listViewAssets.SelectedIndices.Add(i);
last = i;
}
listViewAssets.EnsureVisible(last);
}
listViewAssets.EndUpdate();
listViewAssets.EnsureVisible(last);
}

System.Drawing.Color defaultColor;
Expand All @@ -869,10 +863,10 @@ private void textBoxFindAsset_TextChanged(object sender, EventArgs e)
if (assetID != 0 && archive.ContainsAsset(assetID))
SetSelectedIndices(new List<uint>() { assetID }, false);
else
foreach (ListViewItem v in listViewAssets.Items)
if (v.Text.ToLower().Contains(textBoxFindAsset.Text.ToLower()) && (v.Selected == false))
foreach (Asset a in archive.GetAllAssets())
if (a.AHDR.ADBG.assetName.ToLower().Contains(textBoxFindAsset.Text.ToLower()) && !a.isSelected)
{
SetSelectedIndices(new List<uint>() { GetAssetIDFromName(v.Text) }, false);
SetSelectedIndices(new List<uint>() { a.AHDR.assetID }, false);
return;
}
}
Expand Down
Loading

0 comments on commit 318c857

Please sign in to comment.