Fix up/down arrow select in project window, Fix selecting project audio placements

This commit is contained in:
dexy 2024-07-27 13:40:12 +10:00
parent 76d0ac224c
commit 3d22e9b2a4
3 changed files with 247 additions and 215 deletions

View File

@ -86,6 +86,22 @@ namespace CodeWalker.World
} }
public AudioPlacement FindPlacement(RelFile relfile, Dat151RelData reldata)
{
if (relfile == null) return null;
if (reldata == null) return null;
if (PlacementsDict.TryGetValue(relfile, out var placements))
{
foreach (var placement in placements)
{
if (placement.AmbientZone == reldata) return placement;
if (placement.AmbientRule == reldata) return placement;
if (placement.StaticEmitter == reldata) return placement;
}
}
return null;
}
} }

View File

@ -114,6 +114,7 @@ namespace CodeWalker.Project
private List<YmapEntityDef> interiorslist = new List<YmapEntityDef>(); //used for handling interiors ybns private List<YmapEntityDef> interiorslist = new List<YmapEntityDef>(); //used for handling interiors ybns
private bool ShowProjectItemInProcess = false; private bool ShowProjectItemInProcess = false;
private bool WorldSelectionChangeInProcess = false;
public ProjectForm(WorldForm worldForm = null) public ProjectForm(WorldForm worldForm = null)
@ -886,13 +887,13 @@ namespace CodeWalker.Project
if (CurrentAudioAmbientRule?.AmbientRule == null) CurrentAudioAmbientRule = null; if (CurrentAudioAmbientRule?.AmbientRule == null) CurrentAudioAmbientRule = null;
if (CurrentAudioStaticEmitter?.StaticEmitter == null) CurrentAudioStaticEmitter = null; if (CurrentAudioStaticEmitter?.StaticEmitter == null) CurrentAudioStaticEmitter = null;
//need to create a temporary AudioPlacement wrapper for these, since AudioPlacements usually come from WorldForm
var daz = item as Dat151AmbientZone; var daz = item as Dat151AmbientZone;//need to get these from WorldForm, project tree only contains the Dat151Rel items
var dae = item as Dat151AmbientRule; var dae = item as Dat151AmbientRule;
var dse = item as Dat151StaticEmitter; var dse = item as Dat151StaticEmitter;
if (daz != null) CurrentAudioAmbientZone = new AudioPlacement(daz.Rel, daz); if (daz != null) CurrentAudioAmbientZone = WorldForm?.GetAudioPlacement(daz.Rel, daz);
if (dae != null) CurrentAudioAmbientRule = new AudioPlacement(dae.Rel, dae); if (dae != null) CurrentAudioAmbientRule = WorldForm?.GetAudioPlacement(dae.Rel, dae);
if (dse != null) CurrentAudioStaticEmitter = new AudioPlacement(dse.Rel, dse); if (dse != null) CurrentAudioStaticEmitter = WorldForm?.GetAudioPlacement(dse.Rel, dse);
@ -7610,231 +7611,235 @@ namespace CodeWalker.Project
public void OnWorldSelectionChanged(MapSelection sel) public void OnWorldSelectionChanged(MapSelection sel)
{ {
if (WorldSelectionChangeInProcess) return;
if (InvokeRequired)
{
BeginInvoke(new Action(() => { OnWorldSelectionChanged(sel); }));
return;
}
WorldSelectionChangeInProcess = true;
try try
{ {
if (InvokeRequired) var wasmult = (CurrentMulti != null);
if ((sel.MultipleSelectionItems != null) && (sel.MultipleSelectionItems.Length > 0))
{ {
BeginInvoke(new Action(() => { OnWorldSelectionChanged(sel); })); SetObject(ref sel.MultipleSelectionItems[sel.MultipleSelectionItems.Length - 1]);
SetObject(ref sel);
ProjectExplorer?.DeselectNode();
ShowProjectItemInProcess = true;
ShowCurrentProjectItem(false);
ShowProjectItemInProcess = false;
WorldSelectionChangeInProcess = false;
return;
} }
else else
{ {
var wasmult = (CurrentMulti != null); CurrentMulti = null;
if ((sel.MultipleSelectionItems != null) && (sel.MultipleSelectionItems.Length > 0)) }
var mlo = sel.MloEntityDef;
var room = sel.MloRoomDef;
var ent = sel.EntityDef;
var cargen = sel.CarGenerator;
var lodlight = sel.LodLight;
var boxoccluder = sel.BoxOccluder;
var occludetri = sel.OccludeModelTri;
var grassbatch = sel.GrassBatch;
var collvert = sel.CollisionVertex;
var collpoly = sel.CollisionPoly;
var collbound = sel.CollisionBounds ?? collpoly?.Owner ?? collvert?.Owner;
var pathnode = sel.PathNode;
var pathlink = sel.PathLink;
var navpoly = sel.NavPoly;
var navpoint = sel.NavPoint;
var navportal = sel.NavPortal;
var trainnode = sel.TrainTrackNode;
var scenariond = sel.ScenarioNode;
var scenarioedge = sel.ScenarioEdge;
var audiopl = sel.Audio;
Archetype arch = mlo?.Archetype ?? ent?.MloParent?.Archetype ?? ent?.Archetype;
YtypFile ytyp = mlo?.Archetype?.Ytyp ?? ent?.MloParent?.Archetype?.Ytyp ?? ent?.Archetype?.Ytyp ?? room?.OwnerMlo?.Ytyp;
YmapFile ymap = ent?.Ymap ?? cargen?.Ymap ?? lodlight?.Ymap ?? boxoccluder?.Ymap ?? occludetri?.Ymap ?? grassbatch?.Ymap ?? mlo?.Ymap;
YbnFile ybn = collbound?.GetRootYbn();
YndFile ynd = pathnode?.Ynd;
YnvFile ynv = navpoly?.Ynv ?? navpoint?.Ynv ?? navportal?.Ynv;
TrainTrack traintrack = trainnode?.Track;
YmtFile scenario = scenariond?.Ymt ?? scenarioedge?.Region?.Ymt;
RelFile audiofile = audiopl?.RelFile;
bool showcurrent = false;
if (YmapExistsInProject(ymap) && (ybn == null))
{
if (wasmult || (ent != CurrentEntity))
{ {
SetObject(ref sel.MultipleSelectionItems[sel.MultipleSelectionItems.Length - 1]); ProjectExplorer?.TrySelectEntityTreeNode(ent);
SetObject(ref sel);
ProjectExplorer?.DeselectNode();
ShowProjectItemInProcess = true;
ShowCurrentProjectItem(false);
ShowProjectItemInProcess = false;
return;
} }
else if (wasmult || (cargen != CurrentCarGen))
{ {
CurrentMulti = null; ProjectExplorer?.TrySelectCarGenTreeNode(cargen);
}
if (wasmult || (lodlight != CurrentLodLight))
{
ProjectExplorer?.TrySelectLodLightTreeNode(lodlight);
}
if (wasmult || (boxoccluder != CurrentBoxOccluder))
{
ProjectExplorer?.TrySelectBoxOccluderTreeNode(boxoccluder);
}
if (wasmult || (occludetri != CurrentOccludeModelTri))
{
ProjectExplorer?.TrySelectOccludeModelTriangleTreeNode(occludetri);
}
if (wasmult || (grassbatch != CurrentGrassBatch))
{
ProjectExplorer?.TrySelectGrassBatchTreeNode(grassbatch);
} }
var mlo = sel.MloEntityDef; }
var room = sel.MloRoomDef; else if (YtypExistsInProject(ytyp))
var ent = sel.EntityDef; {
var cargen = sel.CarGenerator; if (wasmult || (arch != CurrentArchetype))
var lodlight = sel.LodLight; {
var boxoccluder = sel.BoxOccluder; ProjectExplorer?.TrySelectArchetypeTreeNode(mlo?.Archetype);
var occludetri = sel.OccludeModelTri; }
var grassbatch = sel.GrassBatch; if (wasmult || (ent != CurrentEntity))
var collvert = sel.CollisionVertex; {
var collpoly = sel.CollisionPoly; MloInstanceData mloInstance = ent.MloParent?.MloInstance;
var collbound = sel.CollisionBounds ?? collpoly?.Owner ?? collvert?.Owner; if (mloInstance != null)
var pathnode = sel.PathNode; {
var pathlink = sel.PathLink; MCEntityDef entityDef = mloInstance.TryGetArchetypeEntity(ent);
var navpoly = sel.NavPoly; ProjectExplorer?.TrySelectMloEntityTreeNode(entityDef);
var navpoint = sel.NavPoint; }
var navportal = sel.NavPortal; }
var trainnode = sel.TrainTrackNode; if (wasmult || (room != CurrentMloRoom))
var scenariond = sel.ScenarioNode; {
var scenarioedge = sel.ScenarioEdge; ProjectExplorer?.TrySelectMloRoomTreeNode(room);
var audiopl = sel.Audio; }
Archetype arch = mlo?.Archetype ?? ent?.MloParent?.Archetype ?? ent?.Archetype; }
YtypFile ytyp = mlo?.Archetype?.Ytyp ?? ent?.MloParent?.Archetype?.Ytyp ?? ent?.Archetype?.Ytyp ?? room?.OwnerMlo?.Ytyp; else if (YbnExistsInProject(ybn))
YmapFile ymap = ent?.Ymap ?? cargen?.Ymap ?? lodlight?.Ymap ?? boxoccluder?.Ymap ?? occludetri?.Ymap ?? grassbatch?.Ymap ?? mlo?.Ymap; {
YbnFile ybn = collbound?.GetRootYbn(); if ((collvert != null) && (wasmult || (collvert != CurrentCollisionVertex)))
YndFile ynd = pathnode?.Ynd; {
YnvFile ynv = navpoly?.Ynv ?? navpoint?.Ynv ?? navportal?.Ynv; ProjectExplorer?.TrySelectCollisionVertexTreeNode(collvert);
TrainTrack traintrack = trainnode?.Track; }
YmtFile scenario = scenariond?.Ymt ?? scenarioedge?.Region?.Ymt; else if ((collpoly != null) && (wasmult || (collpoly != CurrentCollisionPoly)))
RelFile audiofile = audiopl?.RelFile; {
bool showcurrent = false; ProjectExplorer?.TrySelectCollisionPolyTreeNode(collpoly);
}
else if (wasmult || (collbound != CurrentCollisionBounds))
{
ProjectExplorer?.TrySelectCollisionBoundsTreeNode(collbound);
}
}
else if (YndExistsInProject(ynd))
{
if (wasmult || (pathnode != CurrentPathNode))
{
ProjectExplorer?.TrySelectPathNodeTreeNode(pathnode);
}
}
else if (YnvExistsInProject(ynv))
{
if (wasmult || (navpoly != CurrentNavPoly))
{
ProjectExplorer?.TrySelectNavPolyTreeNode(navpoly);
}
if (wasmult || (navpoint != CurrentNavPoint))
{
ProjectExplorer?.TrySelectNavPointTreeNode(navpoint);
}
if (wasmult || (navportal != CurrentNavPortal))
{
ProjectExplorer?.TrySelectNavPortalTreeNode(navportal);
}
}
else if (TrainTrackExistsInProject(traintrack))
{
if (wasmult || (trainnode != CurrentTrainNode))
{
ProjectExplorer?.TrySelectTrainNodeTreeNode(trainnode);
}
}
else if (ScenarioExistsInProject(scenario))
{
if ((scenariond != null) && (wasmult || (scenariond != CurrentScenarioNode)))
{
ProjectExplorer?.TrySelectScenarioNodeTreeNode(scenariond);
}
}
else if (AudioFileExistsInProject(audiofile))
{
if ((audiopl?.AmbientZone != null) && (wasmult || (audiopl != CurrentAudioAmbientZone)))
{
ProjectExplorer?.TrySelectAudioAmbientZoneTreeNode(audiopl);
}
if ((audiopl?.AmbientRule != null) && (wasmult || (audiopl != CurrentAudioAmbientRule)))
{
ProjectExplorer?.TrySelectAudioAmbientRuleTreeNode(audiopl);
}
if ((audiopl?.StaticEmitter != null) && (wasmult || (audiopl != CurrentAudioStaticEmitter)))
{
ProjectExplorer?.TrySelectAudioStaticEmitterTreeNode(audiopl);
}
}
else
{
ProjectExplorer?.DeselectNode();
if (YmapExistsInProject(ymap) && (ybn == null)) showcurrent = true;
{ }
if (wasmult || (ent != CurrentEntity))
{
ProjectExplorer?.TrySelectEntityTreeNode(ent);
}
if (wasmult || (cargen != CurrentCarGen))
{
ProjectExplorer?.TrySelectCarGenTreeNode(cargen);
}
if (wasmult || (lodlight != CurrentLodLight))
{
ProjectExplorer?.TrySelectLodLightTreeNode(lodlight);
}
if (wasmult || (boxoccluder != CurrentBoxOccluder))
{
ProjectExplorer?.TrySelectBoxOccluderTreeNode(boxoccluder);
}
if (wasmult || (occludetri != CurrentOccludeModelTri))
{
ProjectExplorer?.TrySelectOccludeModelTriangleTreeNode(occludetri);
}
if (wasmult || (grassbatch != CurrentGrassBatch))
{
ProjectExplorer?.TrySelectGrassBatchTreeNode(grassbatch);
}
} CurrentMloRoom = room;
else if (YtypExistsInProject(ytyp)) CurrentMloPortal = null;
{ CurrentMloEntitySet = null;
if (wasmult || (arch != CurrentArchetype)) CurrentYmapFile = ymap;
{ CurrentYtypFile = ytyp;
ProjectExplorer?.TrySelectArchetypeTreeNode(mlo?.Archetype); CurrentArchetype = arch;
} CurrentEntity = ent ?? mlo;
if (wasmult || (ent != CurrentEntity)) CurrentCarGen = cargen;
{ CurrentLodLight = lodlight;
MloInstanceData mloInstance = ent.MloParent?.MloInstance; CurrentBoxOccluder = boxoccluder;
if (mloInstance != null) CurrentOccludeModelTri = occludetri;
{ CurrentOccludeModel = occludetri?.Model;
MCEntityDef entityDef = mloInstance.TryGetArchetypeEntity(ent); CurrentGrassBatch = grassbatch;
ProjectExplorer?.TrySelectMloEntityTreeNode(entityDef); CurrentYbnFile = ybn;
} CurrentCollisionVertex = collvert;
} CurrentCollisionPoly = collpoly;
if (wasmult || (room != CurrentMloRoom)) CurrentCollisionBounds = collbound;
{ CurrentYndFile = ynd;
ProjectExplorer?.TrySelectMloRoomTreeNode(room); CurrentPathNode = pathnode;
} CurrentPathLink = pathlink;
} CurrentYnvFile = ynv;
else if (YbnExistsInProject(ybn)) CurrentNavPoly = navpoly;
{ CurrentNavPoint = navpoint;
if ((collvert != null) && (wasmult || (collvert != CurrentCollisionVertex))) CurrentNavPortal = navportal;
{ CurrentTrainTrack = traintrack;
ProjectExplorer?.TrySelectCollisionVertexTreeNode(collvert); CurrentTrainNode = trainnode;
} CurrentScenario = scenario;
else if ((collpoly != null) && (wasmult || (collpoly != CurrentCollisionPoly))) CurrentScenarioNode = scenariond;
{ CurrentScenarioChainEdge = scenarioedge;
ProjectExplorer?.TrySelectCollisionPolyTreeNode(collpoly); CurrentAudioFile = audiofile;
} CurrentAudioAmbientZone = (audiopl?.AmbientZone != null) ? audiopl : null;
else if (wasmult || (collbound != CurrentCollisionBounds)) CurrentAudioAmbientRule = (audiopl?.AmbientRule != null) ? audiopl : null;
{ CurrentAudioStaticEmitter = (audiopl?.StaticEmitter != null) ? audiopl : null;
ProjectExplorer?.TrySelectCollisionBoundsTreeNode(collbound); CurrentAudioAmbientZoneList = null;
} CurrentAudioStaticEmitterList = null;
} CurrentYdrFile = null;
else if (YndExistsInProject(ynd)) CurrentYddFile = null;
{ CurrentYftFile = null;
if (wasmult || (pathnode != CurrentPathNode)) CurrentYtdFile = null;
{ RefreshUI();
ProjectExplorer?.TrySelectPathNodeTreeNode(pathnode); if (showcurrent)
} {
} ShowProjectItemInProcess = true;
else if (YnvExistsInProject(ynv)) ShowCurrentProjectItem(false);
{ ShowProjectItemInProcess = false;
if (wasmult || (navpoly != CurrentNavPoly))
{
ProjectExplorer?.TrySelectNavPolyTreeNode(navpoly);
}
if (wasmult || (navpoint != CurrentNavPoint))
{
ProjectExplorer?.TrySelectNavPointTreeNode(navpoint);
}
if (wasmult || (navportal != CurrentNavPortal))
{
ProjectExplorer?.TrySelectNavPortalTreeNode(navportal);
}
}
else if (TrainTrackExistsInProject(traintrack))
{
if (wasmult || (trainnode != CurrentTrainNode))
{
ProjectExplorer?.TrySelectTrainNodeTreeNode(trainnode);
}
}
else if (ScenarioExistsInProject(scenario))
{
if ((scenariond != null) && (wasmult || (scenariond != CurrentScenarioNode)))
{
ProjectExplorer?.TrySelectScenarioNodeTreeNode(scenariond);
}
}
else if (AudioFileExistsInProject(audiofile))
{
if ((audiopl?.AmbientZone != null) && (wasmult || (audiopl != CurrentAudioAmbientZone)))
{
ProjectExplorer?.TrySelectAudioAmbientZoneTreeNode(audiopl);
}
if ((audiopl?.AmbientRule != null) && (wasmult || (audiopl != CurrentAudioAmbientRule)))
{
ProjectExplorer?.TrySelectAudioAmbientRuleTreeNode(audiopl);
}
if ((audiopl?.StaticEmitter != null) && (wasmult || (audiopl != CurrentAudioStaticEmitter)))
{
ProjectExplorer?.TrySelectAudioStaticEmitterTreeNode(audiopl);
}
}
else
{
ProjectExplorer?.DeselectNode();
showcurrent = true;
}
CurrentMloRoom = room;
CurrentMloPortal = null;
CurrentMloEntitySet = null;
CurrentYmapFile = ymap;
CurrentYtypFile = ytyp;
CurrentArchetype = arch;
CurrentEntity = ent ?? mlo;
CurrentCarGen = cargen;
CurrentLodLight = lodlight;
CurrentBoxOccluder = boxoccluder;
CurrentOccludeModelTri = occludetri;
CurrentOccludeModel = occludetri?.Model;
CurrentGrassBatch = grassbatch;
CurrentYbnFile = ybn;
CurrentCollisionVertex = collvert;
CurrentCollisionPoly = collpoly;
CurrentCollisionBounds = collbound;
CurrentYndFile = ynd;
CurrentPathNode = pathnode;
CurrentPathLink = pathlink;
CurrentYnvFile = ynv;
CurrentNavPoly = navpoly;
CurrentNavPoint = navpoint;
CurrentNavPortal = navportal;
CurrentTrainTrack = traintrack;
CurrentTrainNode = trainnode;
CurrentScenario = scenario;
CurrentScenarioNode = scenariond;
CurrentScenarioChainEdge = scenarioedge;
CurrentAudioFile = audiofile;
CurrentAudioAmbientZone = (audiopl?.AmbientZone != null) ? audiopl : null;
CurrentAudioAmbientRule = (audiopl?.AmbientRule != null) ? audiopl : null;
CurrentAudioStaticEmitter = (audiopl?.StaticEmitter != null) ? audiopl : null;
CurrentAudioAmbientZoneList = null;
CurrentAudioStaticEmitterList = null;
CurrentYdrFile = null;
CurrentYddFile = null;
CurrentYftFile = null;
CurrentYtdFile = null;
RefreshUI();
if (showcurrent)
{
ShowProjectItemInProcess = true;
ShowCurrentProjectItem(false);
ShowProjectItemInProcess = false;
}
} }
} }
catch { } catch { }
WorldSelectionChangeInProcess = false;
} }
public void OnWorldSelectionModified(MapSelection sel) public void OnWorldSelectionModified(MapSelection sel)
{ {

View File

@ -2038,6 +2038,17 @@ namespace CodeWalker
{ {
audiozones.PlacementsDict.Remove(rel); //should cause a rebuild to add/remove items audiozones.PlacementsDict.Remove(rel); //should cause a rebuild to add/remove items
} }
public AudioPlacement GetAudioPlacement(RelFile rel, Dat151RelData reldata)
{
var placement = audiozones.FindPlacement(rel, reldata);
if (placement == null)
{
if (reldata is Dat151AmbientZone az) placement = new AudioPlacement(rel, az);
if (reldata is Dat151AmbientRule ar) placement = new AudioPlacement(rel, ar);
if (reldata is Dat151StaticEmitter se) placement = new AudioPlacement(rel, se);
}
return placement;
}
public void SetCameraTransform(Vector3 pos, Quaternion rot) public void SetCameraTransform(Vector3 pos, Quaternion rot)
@ -3619,7 +3630,7 @@ namespace CodeWalker
if (change) if (change)
{ {
// If an item has been selected the user is likely to use a keybind. We need focus! // If an item has been selected the user is likely to use a keybind. We need focus!
Focus(); //Focus();//DISABLED THIS due to causing problems with using arrows to select in project window!
} }
} }
public void SelectMulti(MapSelection[] items, bool addSelection = false, bool notifyProject = true) public void SelectMulti(MapSelection[] items, bool addSelection = false, bool notifyProject = true)