Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Dec 3, 2018
1 parent 1c4ecc8 commit 2920189
Show file tree
Hide file tree
Showing 23 changed files with 776 additions and 140 deletions.
14 changes: 13 additions & 1 deletion IndustrialPark/ArchiveEditor/ArchiveEditor.Designer.cs

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

93 changes: 46 additions & 47 deletions IndustrialPark/ArchiveEditor/ArchiveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void newToolStripMenuItem_Click(object sender, EventArgs e)
exportTXDArchiveToolStripMenuItem.Enabled = true;
hipHopToolExportToolStripMenuItem.Enabled = true;
importHIPArchiveToolStripMenuItem.Enabled = true;
collapseLayersToolStripMenuItem.Enabled = true;

PopulateLayerComboBox();
PopulateAssetList();
Expand Down Expand Up @@ -119,6 +120,7 @@ private void FinishedOpening(string fileName)
importHIPArchiveToolStripMenuItem.Enabled = true;
importTXDArchiveToolStripMenuItem.Enabled = true;
exportTXDArchiveToolStripMenuItem.Enabled = true;
collapseLayersToolStripMenuItem.Enabled = true;

PopulateLayerComboBox();
PopulateAssetList();
Expand Down Expand Up @@ -236,34 +238,31 @@ private void comboBoxLayers_SelectedIndexChanged(object sender, EventArgs e)
buttonArrowDown.Enabled = true;
importMultipleAssetsToolStripMenuItem.Enabled = true;
addTemplateToolStripMenuItem.Enabled = true;
collapseLayersToolStripMenuItem.Enabled = true;

programIsChangingStuff = false;
}

private void comboBoxLayerTypes_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxLayerTypes.SelectedItem == null)
if (comboBoxLayerTypes.SelectedItem == null || programIsChangingStuff)
return;

if (!programIsChangingStuff)
foreach (LayerType o in Enum.GetValues(typeof(LayerType)))
{
foreach (LayerType o in Enum.GetValues(typeof(LayerType)))
if (o.ToString() == (string)comboBoxLayerTypes.SelectedItem)
{
if(o.ToString() == (string)comboBoxLayerTypes.SelectedItem)
{
archive.DICT.LTOC.LHDRList[comboBoxLayers.SelectedIndex].layerType = o;
comboBoxLayers.Items[comboBoxLayers.SelectedIndex] = LayerToString(comboBoxLayers.SelectedIndex);
archive.UnsavedChanges = true;
return;
}
archive.DICT.LTOC.LHDRList[comboBoxLayers.SelectedIndex].layerType = o;
comboBoxLayers.Items[comboBoxLayers.SelectedIndex] = LayerToString(comboBoxLayers.SelectedIndex);
archive.UnsavedChanges = true;
return;
}
throw new Exception("Invalid layer type");
}
throw new Exception("Invalid layer type");
}

private void buttonAddLayer_Click(object sender, EventArgs e)
{
programIsChangingStuff = true;
try
{
archive.DICT.LTOC.LHDRList.Add(new Section_LHDR()
Expand All @@ -273,28 +272,23 @@ private void buttonAddLayer_Click(object sender, EventArgs e)
});
comboBoxLayers.Items.Add(LayerToString(archive.DICT.LTOC.LHDRList.Count - 1));
comboBoxLayers.SelectedIndex = comboBoxLayers.Items.Count - 1;
PopulateAssetListAndComboBox();
archive.UnsavedChanges = true;
}
catch (Exception ex)
{
MessageBox.Show("Unable to add layer: " + ex.Message);
}

programIsChangingStuff = false;
}

private void buttonRemoveLayer_Click(object sender, EventArgs e)
{
programIsChangingStuff = true;

int previndex = comboBoxLayers.SelectedIndex;

archive.RemoveLayer(comboBoxLayers.SelectedIndex);

PopulateLayerComboBox();

programIsChangingStuff = false;

if (comboBoxLayers.Items.Count > 0)
comboBoxLayers.SelectedIndex = Math.Max(previndex - 1, 0);
else
Expand All @@ -308,6 +302,7 @@ private void buttonRemoveLayer_Click(object sender, EventArgs e)
buttonAddAsset.Enabled = false;
buttonPaste.Enabled = false;
buttonRemoveLayer.Enabled = false;
collapseLayersToolStripMenuItem.Enabled = false;
buttonArrowUp.Enabled = false;
buttonArrowDown.Enabled = false;
importMultipleAssetsToolStripMenuItem.Enabled = false;
Expand Down Expand Up @@ -368,34 +363,33 @@ private void PopulateAssetList(AssetType type = AssetType.Null)
listViewAssets.BeginUpdate();
listViewAssets.Items.Clear();

if (comboBoxLayers.SelectedItem == null) return;

List<uint> assetIDs = archive.DICT.LTOC.LHDRList[comboBoxLayers.SelectedIndex].assetIDlist;
List<Tuple<bool, string>> assetList = new List<Tuple<bool, string>>();
for (int i = 0; i < assetIDs.Count(); i++)
if (comboBoxLayers.SelectedItem != null)
{
Asset asset = archive.GetFromAssetID(assetIDs[i]);
if (type == AssetType.Null)
assetList.Add(new Tuple<bool, string>(!asset.isInvisible, asset.ToString()));
else
List<uint> assetIDs = archive.DICT.LTOC.LHDRList[comboBoxLayers.SelectedIndex].assetIDlist;

for (int i = 0; i < assetIDs.Count(); i++)
{
if (asset.AHDR.assetType == type)
assetList.Add(new Tuple<bool, string>(!asset.isInvisible, asset.ToString()));
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();
//assetList.Sort();

programIsChangingStuff = true;
//programIsChangingStuff = true;

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

//programIsChangingStuff = false;
}
listViewAssets.EndUpdate();

programIsChangingStuff = false;
listViewAssets.EndUpdate();

toolStripStatusLabelSelectionCount.Text = $"{listViewAssets.SelectedItems.Count}/{listViewAssets.Items.Count} assets selected";
}
Expand All @@ -408,14 +402,7 @@ private void checkedListBoxAssets_ItemCheck(object sender, ItemCheckEventArgs e)
private void comboBoxAssetTypes_SelectedIndexChanged(object sender, EventArgs e)
{
if (!programIsChangingStuff)
{
if (comboBoxAssetTypes.SelectedIndex == 0)
PopulateAssetList();
else
PopulateAssetList((AssetType)comboBoxAssetTypes.SelectedItem);

listViewAssets.Refresh();
}
PopulateAssetList(comboBoxAssetTypes.SelectedIndex == 0 ? AssetType.Null : (AssetType)comboBoxAssetTypes.SelectedItem);
}

private void buttonAddAsset_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -802,6 +789,7 @@ 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();
Expand Down Expand Up @@ -835,6 +823,7 @@ public void SetSelectedIndices(List<uint> assetIDs, bool newlyAddedObjects, bool
if (archive.GetFromAssetID(u).AHDR.assetType != assetType)
{
assetType = AssetType.Null;
comboBoxAssetTypes.SelectedIndex = 0;
break;
}

Expand Down Expand Up @@ -873,8 +862,18 @@ private void textBoxFindAsset_TextChanged(object sender, EventArgs e)
textBoxFindAsset.BackColor = System.Drawing.Color.Red;
}

if (assetID != 0 & archive.ContainsAsset(assetID))
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()))
SetSelectedIndices(new List<uint>() { GetAssetIDFromName(v.Text) }, false);
}

private void collapseLayersToolStripMenuItem_Click(object sender, EventArgs e)
{
archive.CollapseLayers();
PopulateLayerComboBox();
}

private void hipHopToolExportToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void ExportTextureDictionary(string fileName)
foreach (TextureNative_0015 tn in td.textureNativeList)
{
fileVersion = tn.renderWareVersion;
tn.textureNativeStruct.textureName = RWTX.AHDR.ADBG.assetName;
tn.textureNativeStruct.textureName = RWTX.AHDR.ADBG.assetName.Replace(".RW3", "");
textNativeList.Add(tn);
}
}
Expand Down Expand Up @@ -634,5 +634,31 @@ public static AHDRFlags AHDRFlagsFromAssetType(AssetType assetType)
}
}

public void CollapseLayers()
{
Dictionary<LayerType, Section_LHDR> layers = new Dictionary<LayerType, Section_LHDR>();

foreach (Section_LHDR LHDR in DICT.LTOC.LHDRList)
{
if (layers.ContainsKey(LHDR.layerType))
{
layers[LHDR.layerType].assetIDlist.AddRange(LHDR.assetIDlist);
}
else
{
layers.Add(LHDR.layerType, LHDR);
}
}

DICT.LTOC.LHDRList = new List<Section_LHDR>();

if (layers.ContainsKey(LayerType.TEXTURE))
{
DICT.LTOC.LHDRList.Add(layers[LayerType.TEXTURE]);
layers.Remove(LayerType.TEXTURE);
}

DICT.LTOC.LHDRList.AddRange(layers.Values.ToList());
}
}
}
Loading

0 comments on commit 2920189

Please sign in to comment.