Skip to content

Commit

Permalink
Show num of selected assets on the status bar
Browse files Browse the repository at this point in the history
Adds #81
  • Loading branch information
ItsPepperpot committed Sep 28, 2024
1 parent d48e911 commit 54b417c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 25 deletions.
39 changes: 26 additions & 13 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -117,7 +118,7 @@ public bool New()
{
Dispose();

currentlySelectedAssets = new List<Asset>();
CurrentlySelectedAssets = new ObservableCollection<Asset>();
currentlyOpenFilePath = null;
assetDictionary.Clear();

Expand Down Expand Up @@ -153,7 +154,7 @@ public void OpenFile(string fileName, bool displayProgressBar, Platform scoobyPl

assetDictionary = new Dictionary<uint, Asset>();

currentlySelectedAssets = new List<Asset>();
CurrentlySelectedAssets = new ObservableCollection<Asset>();
currentlyOpenFilePath = fileName;

HipFile hipFile;
Expand Down Expand Up @@ -573,7 +574,7 @@ public void Dispose(bool showProgress = true)
public void DisposeOfAsset(uint assetID)
{
var asset = assetDictionary[assetID];
currentlySelectedAssets.Remove(asset);
CurrentlySelectedAssets.Remove(asset);
CloseInternalEditor(assetID);
CloseInternalEditorMulti(assetID);

Expand Down Expand Up @@ -1393,7 +1394,7 @@ public void DuplicateSelectedAssets(out List<uint> finalIndices)
Dictionary<uint, uint> referenceUpdate = new Dictionary<uint, uint>();
var newAHDRs = new List<Section_AHDR>();

foreach (var asset in currentlySelectedAssets)
foreach (var asset in CurrentlySelectedAssets)
{
string serializedObject = JsonConvert.SerializeObject(asset.BuildAHDR(platform.Endianness()));
Section_AHDR AHDR = JsonConvert.DeserializeObject<Section_AHDR>(serializedObject);
Expand All @@ -1416,7 +1417,7 @@ public void CopyAssetsToClipboard()
{
var clipboard = new AssetClipboard();

foreach (Asset asset in currentlySelectedAssets)
foreach (Asset asset in CurrentlySelectedAssets)
{
Section_AHDR AHDR = JsonConvert.DeserializeObject<Section_AHDR>(JsonConvert.SerializeObject(asset.BuildAHDR(platform.Endianness())));

Expand Down Expand Up @@ -1583,15 +1584,23 @@ public List<uint> ImportMultipleAssets(List<Section_AHDR> AHDRs, bool overwrite)
return assetIDs;
}

private List<Asset> currentlySelectedAssets = new List<Asset>();
public ObservableCollection<Asset> CurrentlySelectedAssets { get; private set; } = new ObservableCollection<Asset>();


private static List<Asset> allCurrentlySelectedAssets
private static IList<Asset> allCurrentlySelectedAssets
{
get
{
List<Asset> currentlySelectedAssets = new List<Asset>();
IList<Asset> currentlySelectedAssets = new ObservableCollection<Asset>();
foreach (ArchiveEditor ae in Program.MainForm.archiveEditors)
currentlySelectedAssets.AddRange(ae.archive.currentlySelectedAssets);
{
foreach (Asset assetToAdd in ae.archive.CurrentlySelectedAssets)
{
if (!currentlySelectedAssets.Contains(assetToAdd))
currentlySelectedAssets.Add(assetToAdd);
}
}

return currentlySelectedAssets;
}
}
Expand All @@ -1606,16 +1615,20 @@ public void SelectAssets(List<uint> assetIDs)
continue;

assetDictionary[assetID].isSelected = true;
currentlySelectedAssets.Add(assetDictionary[assetID]);
CurrentlySelectedAssets.Add(assetDictionary[assetID]);
}
}

public IEnumerable<uint> GetCurrentlySelectedAssetIDs() => currentlySelectedAssets.Select(a => a.assetID);
public IEnumerable<uint> GetCurrentlySelectedAssetIDs() => CurrentlySelectedAssets.Select(a => a.assetID);

public int GetNumberOfSelectedAssets => CurrentlySelectedAssets.Count;

public void ClearSelectedAssets()
{
currentlySelectedAssets.ForEach(a => a.isSelected = false);
currentlySelectedAssets.Clear();
foreach (var asset in CurrentlySelectedAssets)
asset.isSelected = false;

CurrentlySelectedAssets.Clear();
}

public void ResetModels(SharpRenderer renderer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ where asset is AssetUI || asset is AssetUIFT

public void DropSelectedAssets(SharpRenderer renderer)
{
foreach (var a in from Asset a in currentlySelectedAssets where a is IClickableAsset select (IClickableAsset)a)
foreach (var a in from Asset a in CurrentlySelectedAssets where a is IClickableAsset select (IClickableAsset)a)
{
if ((a is AssetTRIG trig && trig.Shape == TriggerShape.Box) || (a is AssetVOLU volu && volu.Shape == VolumeType.Box))
continue;
Expand Down
12 changes: 6 additions & 6 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions_Gizmos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void MouseMoveForPosition(Matrix viewProjection, int distanceX, int dista
{
if (positionGizmos[0].isSelected || positionGizmos[1].isSelected || positionGizmos[2].isSelected)
{
var selectedClickableAssets = from Asset a in currentlySelectedAssets where a is IClickableAsset ica select (IClickableAsset)a;
var selectedClickableAssets = from Asset a in CurrentlySelectedAssets where a is IClickableAsset ica select (IClickableAsset)a;
if (!selectedClickableAssets.Any())
return;

Expand Down Expand Up @@ -468,8 +468,8 @@ public void MouseMoveForPosition(Matrix viewProjection, int distanceX, int dista
|| triggerPositionGizmos[3].isSelected || triggerPositionGizmos[4].isSelected || triggerPositionGizmos[5].isSelected)
{
var selectedVolumes = new List<IVolumeAsset>();
selectedVolumes.AddRange((from a in currentlySelectedAssets where a is AssetTRIG trig && trig.Shape == TriggerShape.Box select (AssetTRIG)a).ToList());
selectedVolumes.AddRange((from a in currentlySelectedAssets where a is AssetVOLU volu && volu.VolumeShape is VolumeBox select (VolumeBox)((AssetVOLU)a).VolumeShape).ToList());
selectedVolumes.AddRange((from a in CurrentlySelectedAssets where a is AssetTRIG trig && trig.Shape == TriggerShape.Box select (AssetTRIG)a).ToList());
selectedVolumes.AddRange((from a in CurrentlySelectedAssets where a is AssetVOLU volu && volu.VolumeShape is VolumeBox select (VolumeBox)((AssetVOLU)a).VolumeShape).ToList());

if (!selectedVolumes.Any())
return;
Expand Down Expand Up @@ -640,7 +640,7 @@ public void MouseMoveForRotation(Matrix viewProjection, int distanceX, bool grid
{
if (rotationGizmos[0].isSelected || rotationGizmos[1].isSelected || rotationGizmos[2].isSelected)
{
var selectedRotatableAssets = from Asset a in currentlySelectedAssets where a is IRotatableAsset ica select (IRotatableAsset)a;
var selectedRotatableAssets = from Asset a in CurrentlySelectedAssets where a is IRotatableAsset ica select (IRotatableAsset)a;
if (!selectedRotatableAssets.Any())
return;

Expand Down Expand Up @@ -709,7 +709,7 @@ public void MouseMoveForScale(Matrix viewProjection, int distanceX, int distance
{
if (scaleGizmos[0].isSelected || scaleGizmos[1].isSelected || scaleGizmos[2].isSelected || scaleGizmos[3].isSelected)
{
var selectedScalableAssets = from Asset a in currentlySelectedAssets where a is IScalableAsset ica select (IScalableAsset)a;
var selectedScalableAssets = from Asset a in CurrentlySelectedAssets where a is IScalableAsset ica select (IScalableAsset)a;
if (!selectedScalableAssets.Any())
return;

Expand Down Expand Up @@ -769,7 +769,7 @@ public void MouseMoveForPositionLocal(Matrix viewProjection, int distanceX, int
{
if (positionLocalGizmos[0].isSelected || positionLocalGizmos[1].isSelected || positionLocalGizmos[2].isSelected)
{
var selectedClickableAssets = from Asset a in currentlySelectedAssets where a is IClickableAsset ica select (IClickableAsset)a;
var selectedClickableAssets = from Asset a in CurrentlySelectedAssets where a is IClickableAsset ica select (IClickableAsset)a;
if (!selectedClickableAssets.Any())
return;

Expand Down
19 changes: 17 additions & 2 deletions IndustrialPark/MainForm/MainForm.Designer.cs

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

19 changes: 19 additions & 0 deletions IndustrialPark/MainForm/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SharpDX.Direct3D11;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -820,6 +821,7 @@ public void AddArchiveEditor(string filePath = null, Platform scoobyPlatform = P
archiveEditorToolStripMenuItem.DropDownItems.Add(tempMenuItem);

ae.archive.ChangesMade += UpdateTitleBar;
ae.archive.CurrentlySelectedAssets.CollectionChanged += UpdateSelectedAssetStatusBarItem;
ae.EditorUpdate += EditorUpdate;
UpdateTitleBar();
SetupAssetVisibilityButtons();
Expand Down Expand Up @@ -1089,6 +1091,23 @@ public void SetSelectedIndex(uint? assetID)
ae.SetSelectedIndex(assetID ?? 0, false, add);
}

/// <summary>
/// Gets the number of currently selected assets across all archive Editors.
/// </summary>
/// <returns>The number of selected assets</returns>
private int GetNumberOfSelectedAssets()
{
return archiveEditors.Sum(ae => ae.archive.GetNumberOfSelectedAssets);
}

/// <summary>
/// Updates the status bar to show the number of selected assets.
/// </summary>
private void UpdateSelectedAssetStatusBarItem(object sender, NotifyCollectionChangedEventArgs e)
{
toolStripStatusLabelNumSelected.Text = $"{GetNumberOfSelectedAssets()} selected";
}

private void OpenInternalEditors()
{
foreach (ArchiveEditor ae in archiveEditors)
Expand Down
30 changes: 27 additions & 3 deletions IndustrialPark/MainForm/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,19 @@
<value>Use Legacy Asset Type &amp;Format</value>
</data>
<data name="defaultToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
<value>123, 22</value>
</data>
<data name="defaultToolStripMenuItem.Text" xml:space="preserve">
<value>Default</value>
</data>
<data name="crosshairToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
<value>123, 22</value>
</data>
<data name="crosshairToolStripMenuItem.Text" xml:space="preserve">
<value>Crosshair</value>
</data>
<data name="hiddenToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
<value>123, 22</value>
</data>
<data name="hiddenToolStripMenuItem.Text" xml:space="preserve">
<value>Hidden</value>
Expand Down Expand Up @@ -687,6 +687,18 @@
<data name="toolStripStatusLabelTemplate.Size" type="System.Drawing.Size, System.Drawing">
<value>0, 17</value>
</data>
<data name="toolStripStatusLabel4.Size" type="System.Drawing.Size, System.Drawing">
<value>10, 17</value>
</data>
<data name="toolStripStatusLabel4.Text" xml:space="preserve">
<value>|</value>
</data>
<data name="toolStripStatusLabelNumSelected.Size" type="System.Drawing.Size, System.Drawing">
<value>59, 17</value>
</data>
<data name="toolStripStatusLabelNumSelected.Text" xml:space="preserve">
<value>0 selected</value>
</data>
<data name="statusStrip1.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 659</value>
</data>
Expand Down Expand Up @@ -3089,6 +3101,18 @@
<data name="&gt;&gt;toolStripComboBoxUserTemplate.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripStatusLabel4.Name" xml:space="preserve">
<value>toolStripStatusLabel4</value>
</data>
<data name="&gt;&gt;toolStripStatusLabel4.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripStatusLabelNumSelected.Name" xml:space="preserve">
<value>toolStripStatusLabelNumSelected</value>
</data>
<data name="&gt;&gt;toolStripStatusLabelNumSelected.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>MainForm</value>
</data>
Expand Down

0 comments on commit 54b417c

Please sign in to comment.