Skip to content

Commit

Permalink
Allow using existing DEFAULT layer when importing model
Browse files Browse the repository at this point in the history
Extra checkbox on the Import Model form. Checkbox doesn't appear if No Layers is on.
  • Loading branch information
ItsPepperpot committed Sep 20, 2024
1 parent 06a7b04 commit 43d3a5d
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 29 deletions.
11 changes: 9 additions & 2 deletions IndustrialPark/ArchiveEditor/ArchiveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,15 +731,22 @@ private void importMultipleAssetsToolStripMenuItem_Click(object sender, EventArg

private void importModelsToolStripMenuItem_Click(object sender, EventArgs e)
{
(List<Section_AHDR> AHDRs, bool overwrite, bool makeSimps, bool ledgeGrabSimps, bool piptVcolors, bool solidSimps, bool jsp) = ImportModel.GetModels(archive.game);
(List<Section_AHDR> AHDRs,
bool overwrite,
bool makeSimps,
bool ledgeGrabSimps,
bool piptVcolors,
bool solidSimps,
bool jsp,
bool placeOnExistingDefaultLayer) = ImportModel.GetModels(archive.game, archive.NoLayers);

if (AHDRs != null)
{
List<uint> assetIDs = archive.ImportMultipleAssets(AHDRs, overwrite);
if (piptVcolors)
archive.MakePiptVcolors(assetIDs);
if (makeSimps)
assetIDs.AddRange(archive.MakeSimps(assetIDs, solidSimps, ledgeGrabSimps));
assetIDs.AddRange(archive.MakeSimps(assetIDs, solidSimps, ledgeGrabSimps, placeOnExistingDefaultLayer));
PopulateLayerComboBox();
OnEditorUpdate();
SetSelectedIndices(assetIDs, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,32 @@ public void ApplyScale(Vector3 factor, IEnumerable<AssetType> assetTypes = null,
RecalculateAllMatrices();
}

public List<uint> MakeSimps(List<uint> assetIDs, bool solid, bool ledgeGrabSimps)
public List<uint> MakeSimps(List<uint> assetIDs, bool solid, bool ledgeGrabSimps, bool placeOnExistingDefaultLayer)
{
if (!NoLayers)
{
AddLayer();
SelectedLayerIndex = Layers.Count - 1;
bool defaultLayerExists = false;

if (placeOnExistingDefaultLayer)
{
// Check every layer to see whether it is of type default
for (int i = 0; i < Layers.Count; i++)
{
if (Layers[i].Type != LayerType.DEFAULT) continue;

// If the layer is a default layer, select it.
// Pick the first default layer found.
defaultLayerExists = true;
SelectedLayerIndex = i;
break;
}
}

if (!placeOnExistingDefaultLayer || !defaultLayerExists)
{
AddLayer();
SelectedLayerIndex = Layers.Count - 1;
}
}

List<uint> outAssetIDs = new List<uint>();
Expand Down
13 changes: 12 additions & 1 deletion IndustrialPark/ArchiveEditor/Dialogs/ImportModel.Designer.cs

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

33 changes: 18 additions & 15 deletions IndustrialPark/ArchiveEditor/Dialogs/ImportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace IndustrialPark
{
public partial class ImportModel : Form
{
public ImportModel()
public ImportModel(bool noLayers)
{
InitializeComponent();

Expand All @@ -21,6 +21,7 @@ public ImportModel()
comboBoxAssetTypes.Items.Add(AssetType.BSP);
// comboBoxAssetTypes.Items.Add(AssetType.JSP);
comboBoxAssetTypes.SelectedItem = AssetType.Model;
checkBoxUseExistingDefaultLayer.Visible = !noLayers;
}

List<string> filePaths = new List<string>();
Expand Down Expand Up @@ -66,21 +67,15 @@ private void buttonOK_Click(object sender, EventArgs e)
Close();
}

public static (List<Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeGrab, bool piptVColors, bool solidSimps, bool jsp) GetModels(Game game)
public static (List<Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeGrab, bool piptVColors, bool solidSimps, bool jsp, bool useExistingDefaultLayer) GetModels(Game game, bool noLayers)
{
using (ImportModel a = new ImportModel())
using (ImportModel a = new ImportModel(noLayers))
if (a.ShowDialog() == DialogResult.OK)
{
List<Section_AHDR> AHDRs = new List<Section_AHDR>();

AssetType assetType = (AssetType)a.comboBoxAssetTypes.SelectedItem;

if (assetType == AssetType.Model)
{
if (a.checkBoxGenSimps.Checked)
MessageBox.Show("a SIMP for each imported MODL will be generated and placed on a new DEFAULT layer.");
}

foreach (string filePath in a.filePaths)
{
string assetName;
Expand Down Expand Up @@ -110,15 +105,15 @@ public static (List<Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeG
"Error Importing Model",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (null, false, false, false, false, false, false);
return (null, false, false, false, false, false, false, false);
}
catch (Exception)
{
MessageBox.Show("Model could not be imported.",
"Error Importing Model",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (null, false, false, false, false, false, false);
return (null, false, false, false, false, false, false, false);
}
}
else if (assetType == AssetType.BSP)
Expand All @@ -142,15 +137,15 @@ public static (List<Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeG
"Error Importing Model",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (null, false, false, false, false, false, false);
return (null, false, false, false, false, false, false, false);
}
catch (Exception)
{
MessageBox.Show("Model could not be imported.",
"Error Importing Model",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (null, false, false, false, false, false, false);
return (null, false, false, false, false, false, false, false);
}

}
Expand All @@ -165,16 +160,24 @@ public static (List<Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeG
assetData));
}

return (AHDRs, a.checkBoxOverwrite.Checked, a.checkBoxGenSimps.Checked, a.checkBoxLedgeGrab.Checked, a.checkBoxEnableVcolors.Checked, a.checkBoxSolidSimps.Checked, assetType == AssetType.JSP);
return (AHDRs,
a.checkBoxOverwrite.Checked,
a.checkBoxGenSimps.Checked,
a.checkBoxLedgeGrab.Checked,
a.checkBoxEnableVcolors.Checked,
a.checkBoxSolidSimps.Checked,
assetType == AssetType.JSP,
a.checkBoxUseExistingDefaultLayer.Checked);
}

return (null, false, false, false, false, false, false);
return (null, false, false, false, false, false, false, false);
}

private void checkBoxGenSimps_CheckedChanged(object sender, EventArgs e)
{
checkBoxLedgeGrab.Enabled = checkBoxGenSimps.Checked;
checkBoxSolidSimps.Enabled = checkBoxGenSimps.Checked;
checkBoxUseExistingDefaultLayer.Enabled = checkBoxGenSimps.Checked;
}

private void comboBoxAssetTypes_SelectedIndexChanged(object sender, EventArgs e)
Expand Down
49 changes: 41 additions & 8 deletions IndustrialPark/ArchiveEditor/Dialogs/ImportModel.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<value>6</value>
</data>
<data name="buttonOK.Location" type="System.Drawing.Point, System.Drawing">
<value>295, 231</value>
<value>296, 248</value>
</data>
<data name="buttonOK.Size" type="System.Drawing.Size, System.Drawing">
<value>92, 23</value>
Expand All @@ -213,7 +213,7 @@
<value>5</value>
</data>
<data name="buttonCancel.Location" type="System.Drawing.Point, System.Drawing">
<value>393, 231</value>
<value>394, 248</value>
</data>
<data name="buttonCancel.Size" type="System.Drawing.Size, System.Drawing">
<value>92, 23</value>
Expand Down Expand Up @@ -360,7 +360,7 @@
<value>grpSIMP</value>
</data>
<data name="&gt;&gt;checkBoxGenSimps.ZOrder" xml:space="preserve">
<value>0</value>
<value>1</value>
</data>
<data name="checkBoxEnableVcolors.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
Expand Down Expand Up @@ -444,7 +444,7 @@
<value>grpSIMP</value>
</data>
<data name="&gt;&gt;checkBoxLedgeGrab.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<data name="checkBoxSolidSimps.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
Expand Down Expand Up @@ -474,7 +474,7 @@
<value>grpSIMP</value>
</data>
<data name="&gt;&gt;checkBoxSolidSimps.ZOrder" xml:space="preserve">
<value>1</value>
<value>2</value>
</data>
<data name="grpImportSettings.Location" type="System.Drawing.Point, System.Drawing">
<value>225, 68</value>
Expand All @@ -500,11 +500,45 @@
<data name="&gt;&gt;grpImportSettings.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="checkBoxUseExistingDefaultLayer.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.Location" type="System.Drawing.Point, System.Drawing">
<value>43, 73</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.Size" type="System.Drawing.Size, System.Drawing">
<value>183, 17</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.TabIndex" type="System.Int32, mscorlib">
<value>18</value>
</data>
<data name="checkBoxUseExistingDefaultLayer.Text" xml:space="preserve">
<value>Place on existing DEFAULT layer</value>
</data>
<data name="&gt;&gt;checkBoxUseExistingDefaultLayer.Name" xml:space="preserve">
<value>checkBoxUseExistingDefaultLayer</value>
</data>
<data name="&gt;&gt;checkBoxUseExistingDefaultLayer.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;checkBoxUseExistingDefaultLayer.Parent" xml:space="preserve">
<value>grpSIMP</value>
</data>
<data name="&gt;&gt;checkBoxUseExistingDefaultLayer.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="grpSIMP.Location" type="System.Drawing.Point, System.Drawing">
<value>225, 140</value>
</data>
<data name="grpSIMP.Size" type="System.Drawing.Size, System.Drawing">
<value>261, 82</value>
<value>261, 102</value>
</data>
<data name="grpSIMP.TabIndex" type="System.Int32, mscorlib">
<value>19</value>
Expand All @@ -531,9 +565,8 @@
<value>6, 13</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>497, 266</value>
<value>497, 283</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
<value>CenterScreen</value>
</data>
Expand Down

0 comments on commit 43d3a5d

Please sign in to comment.