Skip to content

Commit

Permalink
Add screenshot mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesGameDev committed Apr 9, 2024
1 parent e0dce13 commit cb66e6a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 82 deletions.
4 changes: 4 additions & 0 deletions Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ void SelectPalette(string name, string palette)

ImGui.SameLine();

ImGui.Checkbox("Screenshot Mode", ref viewport.ScreenshotMode);

ImGui.SameLine();

if (ImGui.BeginCombo("Wonder View", viewMode[(int)activeViewport.WonderViewMode], ImGuiComboFlags.WidthFitPreview))
{
for (int n = 0; n < 3; n++)
Expand Down
175 changes: 93 additions & 82 deletions Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ internal class LevelViewport(CourseArea area, GL gl, CourseAreaScene areaScene)

DistantViewManager DistantViewScrollManager = new DistantViewManager(area);

public bool ScreenshotMode;

//TODO make this an ISceneObject? as soon as there's a SceneObj class for each course object
private object? mHoveredObject;

Expand Down Expand Up @@ -1121,13 +1123,16 @@ void DrawAreaContent()
Vector3? newHoveredPoint = null;
object? newHoveredObject = null;

areaScene.ForEach<IViewportDrawable>(obj =>
if (!ScreenshotMode)
{
bool isNewHoveredObj = false;
obj.Draw2D(mEditContext, this, mDrawList, ref isNewHoveredObj);
if (isNewHoveredObj)
newHoveredObject = obj;
});
areaScene.ForEach<IViewportDrawable>(obj =>
{
bool isNewHoveredObj = false;
obj.Draw2D(mEditContext, this, mDrawList, ref isNewHoveredObj);
if (isNewHoveredObj)
newHoveredObject = obj;
});
}

if (mArea.mRailHolder.mRails.Count > 0)
{
Expand Down Expand Up @@ -1233,73 +1238,73 @@ Vector2[] GetPoints()
}
}

foreach (CourseRail rail in mArea.mRailHolder.mRails)
if (!ScreenshotMode)
{
if (rail.mPoints.Count == 0)
continue;
foreach (CourseRail rail in mArea.mRailHolder.mRails)
{
if (rail.mPoints.Count == 0)
continue;

bool selected = mEditContext.IsSelected(rail);
var rail_color = selected ? ImGui.ColorConvertFloat4ToU32(new(1, 1, 0, 1)) : color;
bool selected = mEditContext.IsSelected(rail);
var rail_color = selected ? ImGui.ColorConvertFloat4ToU32(new(1, 1, 0, 1)) : color;

List<Vector2> pointsList = [];
List<Vector2> pointsList = [];

var segmentCount = rail.mPoints.Count;
if (!rail.mIsClosed)
segmentCount--;
var segmentCount = rail.mPoints.Count;
if (!rail.mIsClosed)
segmentCount--;

mDrawList.PathLineTo(WorldToScreen(rail.mPoints[0].mTranslate));
for (int i = 0; i < segmentCount; i++)
{
var pointA = rail.mPoints[i];
var pointB = rail.mPoints[(i + 1) % rail.mPoints.Count];
mDrawList.PathLineTo(WorldToScreen(rail.mPoints[0].mTranslate));
for (int i = 0; i < segmentCount; i++)
{
var pointA = rail.mPoints[i];
var pointB = rail.mPoints[(i + 1) % rail.mPoints.Count];

var posA2D = WorldToScreen(pointA.mTranslate);
var posB2D = WorldToScreen(pointB.mTranslate);
var posA2D = WorldToScreen(pointA.mTranslate);
var posB2D = WorldToScreen(pointB.mTranslate);

Vector2 cpOutA2D = posA2D;
Vector2 cpInB2D = posB2D;
Vector2 cpOutA2D = posA2D;
Vector2 cpInB2D = posB2D;

if (pointA.mIsCurve)
cpOutA2D = WorldToScreen(pointA.mControl.mTranslate);
if (pointA.mIsCurve)
cpOutA2D = WorldToScreen(pointA.mControl.mTranslate);

if (pointB.mIsCurve)
//invert control point
cpInB2D = WorldToScreen(pointB.mTranslate - (pointB.mControl.mTranslate - pointB.mTranslate));
if (pointB.mIsCurve)
//invert control point
cpInB2D = WorldToScreen(pointB.mTranslate - (pointB.mControl.mTranslate - pointB.mTranslate));

if (cpOutA2D == posA2D && cpInB2D == posB2D)
{
mDrawList.PathLineTo(posB2D);
continue;
}
if (cpOutA2D == posA2D && cpInB2D == posB2D)
{
mDrawList.PathLineTo(posB2D);
continue;
}

mDrawList.PathBezierCubicCurveTo(cpOutA2D, cpInB2D, posB2D);
}
mDrawList.PathBezierCubicCurveTo(cpOutA2D, cpInB2D, posB2D);
}

float thickness = newHoveredObject == rail ? 3f : 2.5f;
float thickness = newHoveredObject == rail ? 3f : 2.5f;

mDrawList.PathStroke(rail_color, ImDrawFlags.None, thickness);
mDrawList.PathStroke(rail_color, ImDrawFlags.None, thickness);

foreach (CourseRail.CourseRailPoint pnt in rail.mPoints)
{
bool point_selected = mEditContext.IsSelected(pnt) || mEditContext.IsSelected(pnt.mControl);
var rail_point_color = point_selected ? ImGui.ColorConvertFloat4ToU32(new(1, 1, 0, 1)) : color;
var size = (newHoveredObject == pnt || newHoveredObject == pnt.mControl) ? pointSize * 1.5f : pointSize;
foreach (CourseRail.CourseRailPoint pnt in rail.mPoints)
{
bool point_selected = mEditContext.IsSelected(pnt) || mEditContext.IsSelected(pnt.mControl);
var rail_point_color = point_selected ? ImGui.ColorConvertFloat4ToU32(new(1, 1, 0, 1)) : color;
var size = (newHoveredObject == pnt || newHoveredObject == pnt.mControl) ? pointSize * 1.5f : pointSize;

var pos2D = WorldToScreen(pnt.mTranslate);
mDrawList.AddCircleFilled(pos2D, size, rail_point_color, pnt.mIsCurve ? 0:4);
pointsList.Add(pos2D);
var pos2D = WorldToScreen(pnt.mTranslate);
mDrawList.AddCircleFilled(pos2D, size, rail_point_color, pnt.mIsCurve ? 0:4);
pointsList.Add(pos2D);

if (point_selected && pnt.mIsCurve)
{
var contPos2D = WorldToScreen(pnt.mControl.mTranslate);
mDrawList.AddLine(pos2D, contPos2D, rail_point_color, thickness);
mDrawList.AddCircleFilled(contPos2D, size, rail_point_color, 4);
if (point_selected && pnt.mIsCurve)
{
var contPos2D = WorldToScreen(pnt.mControl.mTranslate);
mDrawList.AddLine(pos2D, contPos2D, rail_point_color, thickness);
mDrawList.AddCircleFilled(contPos2D, size, rail_point_color, 4);
}
}
}
}

if (mMultiSelecting && mMultiSelectStartPos != null && mMultiSelectCurrentPos != null)
mDrawList.AddRect(mMultiSelectStartPos.Value, mMultiSelectCurrentPos.Value, MultiSelectBoxColor, 2f, ImDrawFlags.RoundCornersAll, MultiSelectBoxThickness);
}

foreach (CourseActor actor in mArea.GetActors())
Expand Down Expand Up @@ -1375,40 +1380,43 @@ Vector2[] GetPoints()

bool isHovered = mHoveredObject == actor;

switch(drawing)
if (!ScreenshotMode)
{
default:
for (int i = 0; i < 4; i++)
{
mDrawList.AddLine(
s_actorRectPolygon[i],
s_actorRectPolygon[(i+1) % 4 ],
color, isHovered ? 2.5f : 1.5f);
}
break;
case "sphere":
var pos = WorldToScreen(Vector3.Transform(center, transform));
var scale = Matrix4x4.CreateScale(actor.mScale);
Vector2 rad = (WorldToScreen(Vector3.Transform(max, scale))-WorldToScreen(Vector3.Transform(min, scale)))/2;
mDrawList.AddEllipse(pos, Math.Abs(rad.X), Math.Abs(rad.Y), color, -actor.mRotation.Z, 0, isHovered ? 2.5f : 1.5f);
switch(drawing)
{
default:
for (int i = 0; i < 4; i++)
{
mDrawList.AddLine(
s_actorRectPolygon[i],
s_actorRectPolygon[(i+1) % 4 ],
color, isHovered ? 2.5f : 1.5f);
}
break;
case "sphere":
var pos = WorldToScreen(Vector3.Transform(center, transform));
var scale = Matrix4x4.CreateScale(actor.mScale);
Vector2 rad = (WorldToScreen(Vector3.Transform(max, scale))-WorldToScreen(Vector3.Transform(min, scale)))/2;
mDrawList.AddEllipse(pos, Math.Abs(rad.X), Math.Abs(rad.Y), color, -actor.mRotation.Z, 0, isHovered ? 2.5f : 1.5f);

break;
}
if (mEditContext.IsSelected(actor))
{
for (int i = 0; i < 4; i++)
break;
}
if (mEditContext.IsSelected(actor))
{
mDrawList.AddCircleFilled(s_actorRectPolygon[i],
pointSize, color);
if(drawing == "sphere")
for (int i = 0; i < 4; i++)
{
mDrawList.AddLine(
s_actorRectPolygon[i],
s_actorRectPolygon[(i+1) % 4 ],
color, isHovered ? 2.5f : 1.5f);
mDrawList.AddCircleFilled(s_actorRectPolygon[i],
pointSize, color);
if(drawing == "sphere")
{
mDrawList.AddLine(
s_actorRectPolygon[i],
s_actorRectPolygon[(i+1) % 4 ],
color, isHovered ? 2.5f : 1.5f);
}
}
mDrawList.AddEllipse(WorldToScreen(transform.Translation), pointSize*3, pointSize*3, color, -actor.mRotation.Z, 4, 2);
}
mDrawList.AddEllipse(WorldToScreen(transform.Translation), pointSize*3, pointSize*3, color, -actor.mRotation.Z, 4, 2);
}

string name = actor.mPackName;
Expand All @@ -1428,6 +1436,9 @@ Vector2[] GetPoints()
}
}

if (mMultiSelecting && mMultiSelectStartPos != null && mMultiSelectCurrentPos != null)
mDrawList.AddRect(mMultiSelectStartPos.Value, mMultiSelectCurrentPos.Value, MultiSelectBoxColor, 2f, ImDrawFlags.RoundCornersAll, MultiSelectBoxThickness);

mHoveredObject = newHoveredObject;
}
}
Expand Down

0 comments on commit cb66e6a

Please sign in to comment.