Skip to content

Commit

Permalink
env, tssm events, transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Sep 28, 2018
1 parent c2a192e commit 90cb0a6
Show file tree
Hide file tree
Showing 30 changed files with 1,331 additions and 267 deletions.
63 changes: 19 additions & 44 deletions IndustrialPark/ArchiveEditor/ArchiveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ private void closeToolStripMenuItem_Click(object sender, EventArgs e)
}

archive.Dispose();

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

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

private bool programIsChangingStuff = false;

public bool HasAsset(uint assetID)
Expand Down Expand Up @@ -330,7 +336,6 @@ private void buttonRemoveAsset_Click(object sender, EventArgs e)
{
if (listBoxAssets.SelectedIndex < 0) return;

RemoveInternalEditor(CurrentlySelectedAssetID());
archive.RemoveAsset(CurrentlySelectedAssetID());
comboBoxLayers.Items[comboBoxLayers.SelectedIndex] = LayerToString(comboBoxLayers.SelectedIndex);

Expand Down Expand Up @@ -359,7 +364,6 @@ private void buttonEditAsset_Click(object sender, EventArgs e)
if (success)
{
UnsavedChanges = true;
RemoveInternalEditor(oldAssetID);
archive.RemoveAsset(oldAssetID);

while (archive.ContainsAsset(AHDR.assetID))
Expand All @@ -382,43 +386,11 @@ private void buttonEditAsset_Click(object sender, EventArgs e)
}
}

private List<IInternalEditor> internalEditors = new List<IInternalEditor>();

public void RemoveInternalEditor(IInternalEditor i)
{
internalEditors.Remove(i);
}

public void RemoveInternalEditor(uint assetID)
{
for (int i = 0; i < internalEditors.Count; i++)
if (internalEditors[i].GetAssetID() == assetID)
internalEditors[i].Close();
}

private void buttonInternalEdit_Click(object sender, EventArgs e)
{
if (listBoxAssets.SelectedItem != null)
{
Asset asset = archive.GetFromAssetID(CurrentlySelectedAssetID());

for (int i = 0; i < internalEditors.Count; i++)
if (internalEditors[i].GetAssetID() == asset.AHDR.assetID)
internalEditors[i].Close();

if (asset is AssetCAM CAM)
internalEditors.Add(new InternalCamEditor(CAM, this));
else if (asset is AssetDYNA DYNA)
internalEditors.Add(new InternalDynaEditor(DYNA, this));
else if (asset is AssetTEXT TEXT)
internalEditors.Add(new InternalTextEditor(TEXT, this));
else if (asset.AHDR.assetType == AssetType.SND | asset.AHDR.assetType == AssetType.SNDS)
internalEditors.Add(new InternalSoundEditor(asset, this));
else
internalEditors.Add(new InternalAssetEditor(asset, this));

internalEditors.Last().Show();

archive.OpenInternalEditor();
UnsavedChanges = true;
}
}
Expand Down Expand Up @@ -499,23 +471,21 @@ private void listBoxAssets_SelectedIndexChanged(object sender, EventArgs e)
}
}

public void ScreenClicked(Ray ray, bool isMouseDown)
public static void ScreenClicked(Ray ray, bool isMouseDown)
{
if (isMouseDown)
archive.GizmoSelect(ray);
else if (archive.FinishedMovingGizmo)
archive.FinishedMovingGizmo = false;
ArchiveEditorFunctions.GizmoSelect(ray);
else
{
uint assetID = archive.GetClickedAssetID(ray);
uint assetID = ArchiveEditorFunctions.GetClickedAssetID(ray);
if (assetID != 0)
SetSelectedIndex(assetID);
Program.MainForm.SetSelectedIndex(assetID);
}
}

public void ScreenUnclicked()
public static void ScreenUnclicked()
{
archive.ScreenUnclicked();
ArchiveEditorFunctions.ScreenUnclicked();
}

public void MouseMoveX(SharpCamera camera, int deltaX)
Expand All @@ -528,10 +498,14 @@ public void MouseMoveY(SharpCamera camera, int deltaY)
archive.MouseMoveY(camera, deltaY);
}

private void SetSelectedIndex(uint assetID)
public void SetSelectedIndex(uint assetID)
{
if (!archive.ContainsAsset(assetID))
{
archive.SelectAsset(0);
listBoxAssets.SelectedIndex = -1;
return;
}

try
{
Expand All @@ -554,6 +528,7 @@ private void SetSelectedIndex(uint assetID)
}

System.Drawing.Color defaultColor;

private void textBoxFindAsset_TextChanged(object sender, EventArgs e)
{
uint assetID = 0;
Expand Down
84 changes: 70 additions & 14 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace IndustrialPark
{
public class ArchiveEditorFunctions
{
public static HashSet<IRenderableAsset> renderableAssetSet = new HashSet<IRenderableAsset>();
public static HashSet<IRenderableAsset> renderableAssetSetCommon = new HashSet<IRenderableAsset>();
public static HashSet<IRenderableAsset> renderableAssetSetTrans = new HashSet<IRenderableAsset>();
public static HashSet<AssetJSP> renderableAssetSetJSP = new HashSet<AssetJSP>();
public static Dictionary<uint, IAssetWithModel> renderingDictionary = new Dictionary<uint, IAssetWithModel>();

public static void AddToRenderingDictionary(uint key, IAssetWithModel value)
Expand Down Expand Up @@ -188,6 +190,12 @@ private void AddAssetToDictionary(Section_AHDR AHDR)
assetDictionary.Add(AHDR.assetID, newAsset);
}
break;
case AssetType.ENV:
{
AssetENV newAsset = new AssetENV(AHDR);
assetDictionary.Add(AHDR.assetID, newAsset);
}
break;
case AssetType.FOG:
{
AssetFOG newAsset = new AssetFOG(AHDR);
Expand Down Expand Up @@ -340,7 +348,6 @@ private void AddAssetToDictionary(Section_AHDR AHDR)
case AssetType.DTRK:
case AssetType.DUPC:
case AssetType.EGEN:
case AssetType.ENV:
case AssetType.GRSM:
case AssetType.GUST:
case AssetType.HANG:
Expand Down Expand Up @@ -419,6 +426,8 @@ public void AddAssetWithUniqueID(int layerIndex, Section_AHDR AHDR)

public void RemoveAsset(uint assetID)
{
CloseInternalEditor(currentlySelectedAssetID);

for (int i = 0; i < DICT.LTOC.LHDRList.Count; i++)
if (DICT.LTOC.LHDRList[i].assetIDlist.Contains(assetID))
DICT.LTOC.LHDRList[i].assetIDlist.Remove(assetID);
Expand All @@ -438,8 +447,14 @@ public void RemoveAsset(uint assetID)
private void DisposeAsset(uint key)
{
if (assetDictionary[key] is IRenderableAsset ra)
if (renderableAssetSet.Contains(ra))
renderableAssetSet.Remove(ra);
{
if (renderableAssetSetCommon.Contains(ra))
renderableAssetSetCommon.Remove(ra);
else if (renderableAssetSetTrans.Contains(ra))
renderableAssetSetTrans.Remove(ra);
else if (renderableAssetSetJSP.Contains(ra))
renderableAssetSetJSP.Remove((AssetJSP)ra);
}

if (renderingDictionary.ContainsKey(key))
renderingDictionary.Remove(key);
Expand All @@ -466,6 +481,7 @@ public void SelectAsset(uint assetID)
if (assetDictionary.ContainsKey(currentlySelectedAssetID))
assetDictionary[currentlySelectedAssetID].isSelected = false;
currentlySelectedAssetID = assetID;

if (currentlySelectedAssetID != 0)
{
assetDictionary[currentlySelectedAssetID].isSelected = true;
Expand All @@ -474,7 +490,6 @@ public void SelectAsset(uint assetID)
else
ClearGizmos();
}
else ClearGizmos();
}

public int GetLayerFromAssetID(uint assetID)
Expand All @@ -486,12 +501,49 @@ public int GetLayerFromAssetID(uint assetID)
throw new Exception($"Asset ID {assetID.ToString("X8")} is not present in any layer.");
}

public uint GetClickedAssetID(Ray ray)
private List<IInternalEditor> internalEditors = new List<IInternalEditor>();

public void CloseInternalEditor(IInternalEditor i)
{
internalEditors.Remove(i);
}

public void CloseInternalEditor(uint assetID)
{
for (int i = 0; i < internalEditors.Count; i++)
if (internalEditors[i].GetAssetID() == assetID)
internalEditors[i].Close();
}

public void OpenInternalEditor()
{
Asset asset = GetFromAssetID(currentlySelectedAssetID);

for (int i = 0; i < internalEditors.Count; i++)
if (internalEditors[i].GetAssetID() == asset.AHDR.assetID)
internalEditors[i].Close();

if (asset is AssetCAM CAM)
internalEditors.Add(new InternalCamEditor(CAM, this));
else if (asset is AssetDYNA DYNA)
internalEditors.Add(new InternalDynaEditor(DYNA, this));
else if (asset is AssetTEXT TEXT)
internalEditors.Add(new InternalTextEditor(TEXT, this));
else if (asset.AHDR.assetType == AssetType.SND | asset.AHDR.assetType == AssetType.SNDS)
internalEditors.Add(new InternalSoundEditor(asset, this));
else
internalEditors.Add(new InternalAssetEditor(asset, this));

internalEditors.Last().Show();
}

public static uint GetClickedAssetID(Ray ray)
{
List<IRenderableAsset> l = new List<IRenderableAsset>();
try
{
l.AddRange(renderableAssetSet);
l.AddRange(renderableAssetSetCommon);
l.AddRange(renderableAssetSetTrans);
}
catch { return 0; }

Expand All @@ -516,14 +568,18 @@ public uint GetClickedAssetID(Ray ray)

public void RecalculateAllMatrices()
{
foreach (IRenderableAsset a in renderableAssetSet)
foreach (IRenderableAsset a in renderableAssetSetCommon)
a.CreateTransformMatrix();
foreach (IRenderableAsset a in renderableAssetSetTrans)
a.CreateTransformMatrix();
foreach (AssetJSP a in renderableAssetSetJSP)
a.CreateTransformMatrix();
}

// Gizmos
private static Gizmo[] gizmos;
private static Gizmo[] gizmos = new Gizmo[0];
private static bool DrawGizmos = false;
public bool FinishedMovingGizmo = false;
public static bool FinishedMovingGizmo = false;

public static void RenderGizmos(SharpRenderer renderer)
{
Expand All @@ -538,19 +594,19 @@ public void UpdateGizmoPosition()
UpdateGizmoPosition(currentAsset.GetGizmoCenter(), currentAsset.GetGizmoRadius());
}

private void UpdateGizmoPosition(Vector3 position, float distance)
private static void UpdateGizmoPosition(Vector3 position, float distance)
{
DrawGizmos = true;
foreach (Gizmo g in gizmos)
g.SetPosition(position, distance);
}

private void ClearGizmos()
private static void ClearGizmos()
{
DrawGizmos = false;
}

public void GizmoSelect(Ray r)
public static void GizmoSelect(Ray r)
{
if (!DrawGizmos)
return;
Expand All @@ -577,7 +633,7 @@ public void GizmoSelect(Ray r)
gizmos[index].isSelected = true;
}

public void ScreenUnclicked()
public static void ScreenUnclicked()
{
foreach (Gizmo g in gizmos)
g.isSelected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ namespace IndustrialPark
{
public partial class InternalAssetEditor : Form, IInternalEditor
{
public InternalAssetEditor(Asset asset, ArchiveEditor archiveEditor)
public InternalAssetEditor(Asset asset, ArchiveEditorFunctions archive)
{
InitializeComponent();
TopMost = true;

this.asset = asset;
this.archiveEditor = archiveEditor;
this.archive = archive;

propertyGridAsset.SelectedObject = asset;
labelAssetName.Text = $"[{asset.AHDR.assetType.ToString()}] {asset.ToString()}";
}

private void InternalAssetEditor_FormClosing(object sender, FormClosingEventArgs e)
{
archiveEditor.RemoveInternalEditor(this);
archive.CloseInternalEditor(this);
}

private Asset asset;
private ArchiveEditor archiveEditor;
private ArchiveEditorFunctions archive;

public uint GetAssetID()
{
Expand Down
Loading

0 comments on commit 90cb0a6

Please sign in to comment.