Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes, MiniMap Tweaks, & Wonder View #109

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Fushigi/course/CourseActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace Fushigi.course
{
public enum WonderViewType{
Normal,
WonderOff,
WonderOnly
}
public class CourseActor
{
public CourseActor(BymlHashTable actorNode)
Expand Down Expand Up @@ -222,6 +227,8 @@ public BymlHashTable BuildNode(CourseLinkHolder linkHolder)
public string mPackName;
public string mName;
public string mLayer;
public WonderViewType mWonderView = WonderViewType.Normal;
public bool wonderVisible = true;
public System.Numerics.Vector3 mStartingTrans;
public System.Numerics.Vector3 mTranslation;
public System.Numerics.Vector3 mRotation;
Expand Down Expand Up @@ -260,7 +267,7 @@ public CourseActor this[ulong hash]
get
{
bool exists = TryGetActor(hash, out CourseActor? actor);
Debug.Assert(exists);
//Debug.Assert(exists);
return actor!;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/env/EnvPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Load(string name)
string file_path = FileUtil.FindContentPath(local_path);
if (!File.Exists(file_path))
{
Debug.Fail(null);
//Debug.Fail(null);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion Fushigi/gl/Bfres/BfresRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ internal void Render(GL gl, BfresRender render, Matrix4x4 transform, Camera came
{
foreach (var mesh in Meshes)
{
mesh.LodMeshes[0].BoundingBox.Transform(transform);
var m = mesh.LodMeshes[0].BoundingBox;
m.Transform(transform);
BoundingBox.Include(mesh.LodMeshes[0].BoundingBox);
}

Expand Down
2 changes: 1 addition & 1 deletion Fushigi/gl/Bfres/TileBfresRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public void Load(CourseUnitHolder unitHolder)

public void Render(GL gl, Camera camera)
{
NoCollisionModel.Render(gl, camera);
SolidModel.Render(gl, camera);
SemisolidModel.Render(gl, camera);
NoCollisionModel.Render(gl, camera);
BridgeModel.Render(gl, camera);
}

Expand Down
10 changes: 6 additions & 4 deletions Fushigi/ui/CourseAreaEditContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ public void AddLink(CourseLink link)
LogAdding<CourseLink>($": {link.mSource} -{link.mLinkName}-> {link.mDest}");

//Checks if the the source actor already has links
if(linkList.Any(x => x.mSource == link.mSource)){
if (linkList.Any(x => x.mSource == link.mSource)){

//Looks through the source actor's links
//Then looks through it's links of the same type (If it has any)
//Placing the new link in the right spot
var index = linkList.FindLastIndex(x => x.mSource == link.mSource &&
(!linkList.Any(y => x.mLinkName == link.mLinkName) ||
x.mLinkName == link.mLinkName));

CommitAction(
area.mLinkHolder.mLinks.RevertableInsert(link,
linkList.FindLastIndex(x => x.mSource == link.mSource
&& ((!linkList.Any(y => y.mLinkName == link.mLinkName)) || x.mLinkName == link.mLinkName))+1,
area.mLinkHolder.mLinks.RevertableInsert(link, index+1,
$"{IconUtil.ICON_PLUS_CIRCLE} Add {link.mLinkName} Link")
);
return;
Expand Down
69 changes: 53 additions & 16 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class CourseScene

CourseLink? mSelectedGlobalLink = null;

string[] viewMode = [
"View All Actors",
"View Normal Actors",
"View Wonder Actors"];

string[] linkTypes = [
"BasicSignal",
"Create",
Expand Down Expand Up @@ -242,8 +247,6 @@ public void DrawUI(GL gl, double deltaSeconds)

ImGui.SameLine();

ImGui.SameLine();

string current_palette = area.mInitEnvPalette == null ? "" : area.mInitEnvPalette.Name;

void SelectPalette(string name, string palette)
Expand All @@ -262,8 +265,8 @@ void SelectPalette(string name, string palette)
ImGui.SetItemDefaultFocus();
}

ImGui.PushItemWidth(30);
if (ImGui.BeginCombo($"##EnvPalette", $"{IconUtil.ICON_PALETTE}", ImGuiComboFlags.NoArrowButton))
var flags = ImGuiComboFlags.NoArrowButton | ImGuiComboFlags.WidthFitPreview;
if (ImGui.BeginCombo($"##EnvPalette", $"{IconUtil.ICON_PALETTE}", flags))
{
SelectPalette($"Default Palette", area.mAreaParams.EnvPaletteSetting.InitPaletteBaseName);

Expand All @@ -284,7 +287,6 @@ void SelectPalette(string name, string palette)
}
ImGui.EndCombo();
}
ImGui.PopItemWidth();

ImGui.SameLine();

Expand All @@ -294,6 +296,18 @@ void SelectPalette(string name, string palette)
UserSettings.SetGameShaders(useGameShaders);
}

ImGui.SameLine();

if (ImGui.BeginCombo("Wonder View", viewMode[(int)activeViewport.WonderViewMode], ImGuiComboFlags.WidthFitPreview))
{
for (int n = 0; n < 3; n++)
{
if (ImGui.Selectable(viewMode[n]))
viewport.WonderViewMode = (WonderViewType)n;
}
ImGui.EndCombo();
}

ImGui.PopStyleColor(1);

ImGui.EndChild();
Expand Down Expand Up @@ -498,8 +512,6 @@ private void LocalLinksPanel()
{
ImGui.Begin("Local Links");

ImGui.Checkbox("Wonder View", ref activeViewport.IsWonderView);

ImGui.Separator();

AreaLocalLinksView(selectedArea);
Expand Down Expand Up @@ -1337,7 +1349,7 @@ BGUnitRailSceneObj GetRailSceneObj(object courseObject)

if (ImGui.Selectable(name, editContext.IsSelected(unit)))
{
editContext.DeselectAllOfType<CourseUnit>();
editContext.DeselectAll();
editContext.Select(unit);
}
if (expanded)
Expand Down Expand Up @@ -1573,7 +1585,8 @@ private void AreaLocalLinksView(CourseArea area)
ImGui.EndChild();
}

private void RecursiveLinkFind(CourseArea area, CourseLinkHolder links, CourseAreaEditContext editContext, float em, IEnumerable<CourseActor> linkList)
private void RecursiveLinkFind(CourseArea area, CourseLinkHolder links,
CourseAreaEditContext editContext, float em, IEnumerable<CourseActor> linkList)
{
foreach (CourseActor actor in linkList)
{
Expand Down Expand Up @@ -1601,6 +1614,8 @@ private void RecursiveLinkFind(CourseArea area, CourseLinkHolder links, CourseAr
if (!isVisible)
ImGui.BeginDisabled();

UpdateWonderVisibility(actor, links, area);

if (expanded)
{
foreach (var link in links.GetDestHashesFromSrc(actor.mHash))
Expand All @@ -1610,10 +1625,6 @@ private void RecursiveLinkFind(CourseArea area, CourseLinkHolder links, CourseAr
{
var reLinks = area.GetActors().Where(x => link.Value.Contains(x.mHash));
RecursiveLinkFind(area, links, editContext, em, reLinks);
// foreach (CourseActor linkActor in )
// {
//
// }
ImGui.TreePop();
}
ImGui.PopID();
Expand Down Expand Up @@ -1670,6 +1681,34 @@ private void RecursiveLinkFind(CourseArea area, CourseLinkHolder links, CourseAr
}
}

private void UpdateWonderVisibility(CourseActor actor, CourseLinkHolder links, CourseArea area)
{
foreach (var link in links.GetDestHashesFromSrc(actor.mHash))
{
var reLinks = area.GetActors().Where(x => link.Value.Contains(x.mHash));
if (!link.Key.Contains("CreateRelative") &&
(link.Key.Contains("Create") ||
link.Key.Contains("PopUp") ||
link.Key.Contains("Delete") ||
link.Key.Contains("BasicSignal")))
{
foreach (CourseActor linkActor in reLinks)
{
if ((actor.mPackName == "ObjectWonderTag" || actor.mWonderView == WonderViewType.WonderOnly) &&
(!link.Key.Contains("BasicSignal") || (linkActor.mActorPack?.Category.Contains("Tag") ?? false)))
{
if (link.Key.Contains("Delete"))
linkActor.mWonderView = WonderViewType.WonderOff;
else
linkActor.mWonderView = WonderViewType.WonderOnly;
}
else
linkActor.mWonderView = WonderViewType.Normal;
}
}
}
}

private void UpdateAllLayerVisiblity()
{
foreach (string layer in mLayersVisibility.Keys)
Expand Down Expand Up @@ -1950,7 +1989,7 @@ private void CourseMiniView()
dl.AddRectFilled(
MapPointPixelAligned(pos),
MapPointPixelAligned(pos + Vector2.One),
0xFF444444);
0xFF666688);
}
}

Expand All @@ -1961,7 +2000,6 @@ private void CourseMiniView()
.SelectMany(x => x.mTileSubUnits)
.OrderBy(x => x.mOrigin.Z);

var t = 0;
foreach (var subUnit in foregroundSubUnits)
{
var type = foregroundTileUnits.First(x => x.mTileSubUnits.Contains(subUnit)).mModelType;
Expand Down Expand Up @@ -2007,7 +2045,6 @@ private void CourseMiniView()
}
}


dl.AddRect(lvlRectTopLeft,
lvlRectTopLeft + lvlRectSize,
ImGui.ColorConvertFloat4ToU32(ImGui.GetStyle().Colors[(int)ImGuiCol.Text]),6,0,3);
Expand Down
45 changes: 27 additions & 18 deletions Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void DefaultSelect(CourseAreaEditContext ctx, object selectable)
{
ctx.Select(selectable);
}
else if(!ctx.IsSelected(selectable))
else if(!ctx.IsSelected(selectable))
{
ctx.WithSuspendUpdateDo(() =>
{
Expand Down Expand Up @@ -82,13 +82,14 @@ internal class LevelViewport(CourseArea area, GL gl, CourseAreaScene areaScene)

public bool IsViewportHovered;
public bool IsViewportActive;
public bool IsWonderView;
public WonderViewType WonderViewMode = WonderViewType.Normal;
public bool PlayAnimations = false;
public bool ShowGrid = true;

Vector2 mSize = Vector2.Zero;

public ulong prevSelectVersion { get; private set; } = 0;
public bool dragRelease;
private IDictionary<string, bool>? mLayersVisibility;
Vector2 mTopLeft = Vector2.Zero;

Expand Down Expand Up @@ -359,9 +360,14 @@ TileBfresRender CreateTileRendererForSkin(SkinDivision division, string skinName

foreach (var actor in this.mArea.GetActors())
{
if (actor.mActorPack == null || mLayersVisibility.ContainsKey(actor.mLayer) && !mLayersVisibility[actor.mLayer])
continue;
actor.wonderVisible = WonderViewMode == actor.mWonderView ||
WonderViewMode == WonderViewType.Normal ||
actor.mWonderView == WonderViewType.Normal;

if (actor.mActorPack == null || (mLayersVisibility.ContainsKey(actor.mLayer) && !mLayersVisibility[actor.mLayer]) ||
!actor.wonderVisible)
continue;

RenderActor(actor, actor.mActorPack.ModelInfoRef);
RenderActor(actor, actor.mActorPack.DrawArrayModelInfoRef);
}
Expand Down Expand Up @@ -808,22 +814,25 @@ void InteractionWithFocus(KeyboardModifier modifiers)
}
}

if(mHoveredObject != null && mHoveredObject is CourseActor &&
ImGui.IsMouseReleased(ImGuiMouseButton.Left))
if (ImGui.IsMouseDown(0))
dragRelease = ImGui.IsMouseDragging(0);

if(mHoveredObject != null &&
mHoveredObject is CourseActor &&
!dragRelease &&
ImGui.IsMouseReleased(0))
{
if (ImGui.GetIO().MouseDragMaxDistanceSqr[0] <= ImGui.GetIO().MouseDragThreshold)
if(ImGui.IsKeyDown(ImGuiKey.LeftShift) &&
prevSelectVersion == mEditContext.SelectionVersion)
{
if(ImGui.IsKeyDown(ImGuiKey.LeftShift)
&& prevSelectVersion == mEditContext.SelectionVersion)
{
mEditContext.Deselect(mHoveredObject!);
}
else if(!ImGui.IsKeyDown(ImGuiKey.LeftShift))
{
mEditContext.DeselectAll();
IViewportSelectable.DefaultSelect(mEditContext, mHoveredObject);
}
mEditContext.Deselect(mHoveredObject!);
}
else if(!ImGui.IsKeyDown(ImGuiKey.LeftShift))
{
mEditContext.DeselectAll();
IViewportSelectable.DefaultSelect(mEditContext, mHoveredObject);
}
dragRelease = false;
}

if (ImGui.IsKeyPressed(ImGuiKey.Delete))
Expand Down Expand Up @@ -1107,7 +1116,7 @@ Vector2[] GetPoints()

string layer = actor.mLayer;

if (mLayersVisibility!.TryGetValue(layer, out bool isVisible) && isVisible)
if (mLayersVisibility!.TryGetValue(layer, out bool isVisible) && isVisible && actor.wonderVisible)
{
Matrix4x4 transform =
Matrix4x4.CreateScale(actor.mScale.X, actor.mScale.Y, actor.mScale.Z
Expand Down
Loading