Skip to content

Commit

Permalink
v1.1.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesGameDev committed Apr 12, 2024
1 parent 0d31815 commit ceb06f7
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 56 deletions.
8 changes: 4 additions & 4 deletions Fushigi/DRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static void Dispose(object? sender, EventArgs e)
mClient?.Dispose();
}

static void SetPresence(string details, string state)
static void SetPresence(string details, string state, string imageKey)
{
if (mClient == null)
{
Expand All @@ -46,7 +46,7 @@ static void SetPresence(string details, string state)
State = state,
Assets = new Assets()
{
LargeImageKey = "icon",
LargeImageKey = imageKey,
LargeImageText = "Fushigi"
},
Timestamps = new Timestamps()
Expand All @@ -56,9 +56,9 @@ static void SetPresence(string details, string state)
});
}

public static void SetEditingCourse(string courseID, string courseName)
public static void SetEditingCourse(string courseID, string courseName, int worldNumber)
{
SetPresence($"Editing {courseID}", courseName);
SetPresence($"Editing {courseID}", courseName, "icon" + worldNumber);
}

class RPCLogger : ILogger
Expand Down
27 changes: 27 additions & 0 deletions Fushigi/Fushigi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@
<None Update="res\Icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon6.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon7.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon8.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\icon9.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="res\imgui.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
6 changes: 4 additions & 2 deletions Fushigi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

internal class Program
{
public const string Version = "v1.1.5.3";
public const string Version = "v1.1.5.4";

public static MainWindow MainWindow { get; private set; }

private static void Main(string[] args)
{
Expand Down Expand Up @@ -40,7 +42,7 @@ private static void Main(string[] args)

DRPC.Initialize();

_ = new MainWindow();
MainWindow = new MainWindow();
WindowManager.Run();

Logger.CloseLogger();
Expand Down
21 changes: 10 additions & 11 deletions Fushigi/RomFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private static void CacheCourseFiles()
var path = Path.Combine(GetRoot(), "Mals", "USen.Product.100.sarc.zs");


Dictionary<string, string> courseNames = new();
Dictionary<string, string> worldNames = new();
Dictionary<string, string> courseNames = [];
Dictionary<string, string> worldNames = [];

if (File.Exists(path))
{
Expand All @@ -104,8 +104,10 @@ private static void CacheCourseFiles()
if (worldNames.TryGetValue(worldKey, out string? value))
worldEntry.name = value;

Logger.Logger.LogMessage("RomFS", worldName);

Dictionary<string, WorldEntry.CourseEntry> courseLocationList = new();
Byml.Byml byml = new Byml.Byml(new MemoryStream(File.ReadAllBytes(loadFile)));
Byml.Byml byml = new(new MemoryStream(File.ReadAllBytes(loadFile)));
var root = (BymlHashTable)byml.Root;
var courseList = (BymlArrayNode)root["CourseTable"];
for (int i = 0; i < courseList.Length; i++)
Expand All @@ -122,16 +124,16 @@ private static void CacheCourseFiles()
courseNames.TryGetValue(courseInfo.CourseNameLabel, out string? courseName))
{
courseEntry.name = courseName;
if (!CourseNames.ContainsKey(courseInfo.GlobalCourseId))
CourseNames.Add(courseInfo.GlobalCourseId, courseName);
CourseNames.TryAdd(courseInfo.GlobalCourseId, courseName);
}
else
{
courseEntry.name = "Name not found";
if (!CourseNames.ContainsKey(courseInfo.GlobalCourseId))
CourseNames.Add(courseInfo.GlobalCourseId, courseEntry.name);
CourseNames.TryAdd(courseInfo.GlobalCourseId, courseEntry.name);
}

CourseWorlds.TryAdd(courseInfo.GlobalCourseId, int.Parse(worldName.Split("World")[1]));

courseLocationList.Add(courseLocation, courseEntry);
}

Expand All @@ -144,9 +146,7 @@ private static void CacheCourseFiles()
public static void CacheCourseThumbnails(GL gl)
{
foreach (var world in sCourseEntries.Keys)
{
CacheCourseThumbnails(gl, world);
}
}

public static void CacheCourseThumbnails(GL gl, string world)
Expand All @@ -157,9 +157,7 @@ public static void CacheCourseThumbnails(GL gl, string world)
{
// Skip the process if this course's thumbnail is already cached
if (sCourseEntries[world].courseEntries![course].thumbnail != null)
{
continue;
}

var path = Path.Combine(thumbnailFolder, $"{course}.bntx.zs");

Expand Down Expand Up @@ -193,5 +191,6 @@ public class CourseEntry
private static string sRomFSRoot = "";
private static readonly Dictionary<string, WorldEntry> sCourseEntries = [];
public static readonly Dictionary<int, string> CourseNames = [];
public static readonly Dictionary<int, int> CourseWorlds = [];
}
}
8 changes: 4 additions & 4 deletions Fushigi/course/distance_view/DistantViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void Calc(Vector3 camera_pos)
//Place via base locator pos + camera

//Distance between dv locator and camera
Vector2 distance = new Vector2(camera_pos.X - locator_pos.X, camera_pos.Y - locator_pos.Y);
Vector2 movement_ratio = new Vector2(1.0f) - scroll_config;
Vector2 scroll_time_rate = new Vector2(1.0f - ScrollSpeedX, 1.0f - ScrollSpeedY);
Vector2 distance = new(camera_pos.X - locator_pos.X, camera_pos.Y - locator_pos.Y);
Vector2 movement_ratio = new Vector2(1f, 1f) - scroll_config;
Vector2 scroll_time_rate = new(0.960f - ScrollSpeedX, 1.9f - ScrollSpeedY);

float posX = 0, posY = 0;

Expand All @@ -79,7 +79,7 @@ public void Calc(Vector3 camera_pos)
if (scroll_config.X != 1 && scroll_time_rate.Y != 0)
posY = distance.Y * movement_ratio.Y * scroll_time_rate.Y;

LayerMatrices[layer] = Matrix4x4.CreateTranslation(posX, posY, 0);
LayerMatrices[layer] = Matrix4x4.CreateTranslation(posX + movement_ratio.X * scroll_time_rate.X * 2, movement_ratio.Y * scroll_time_rate.Y, 0);
}
}
}
Expand Down
File renamed without changes
Binary file added Fushigi/res/icon2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Fushigi/res/icon9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions Fushigi/ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using Fushigi.util;
using Fushigi.windowing;
using ImGuiNET;
using Silk.NET.Core;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using System.Numerics;
using System.Runtime.InteropServices;

Expand All @@ -21,14 +24,38 @@ public partial class MainWindow : IPopupModalHost
private ImFontPtr mDefaultFont;
private readonly ImFontPtr mIconFont;

private static readonly Dictionary<int, RawImage> Icons = [];

public MainWindow()
{
Logger.Logger.LogMessage("MainWindow", "Loading icons");

unsafe
{
for (int i = 1; i < 10; i++)
{
using var image = SixLabors.ImageSharp.Image.Load<Rgba32>(Path.Combine("res", $"icon{i}.png"));
var memoryGroup = image.GetPixelMemoryGroup();
Memory<byte> array = new byte[memoryGroup.TotalLength * sizeof(Rgba32)];
var block = MemoryMarshal.Cast<byte, Rgba32>(array.Span);
foreach (var memory in memoryGroup)
{
memory.Span.CopyTo(block);
block = block[memory.Length..];
}

Icons.Add(i, new RawImage(image.Width, image.Height, array));
}
}

WindowManager.CreateWindow(out mWindow,
onConfigureIO: () =>
{
Logger.Logger.LogMessage("MainWindow", "Initializing Window");
unsafe
{
SetWindowIcon(1);

var io = ImGui.GetIO();
io.ConfigFlags = ImGuiConfigFlags.NavEnableKeyboard;

Expand Down Expand Up @@ -89,6 +116,12 @@ public MainWindow()
mWindow.Closing += Close;
}

public void SetWindowIcon(int id)
{
var icon = Icons[id];
mWindow.SetWindowIcon(ref icon);
}

public async Task<bool> TryCloseCourse()
{
if (mSelectedCourseScene is not null &&
Expand Down
6 changes: 5 additions & 1 deletion Fushigi/ui/widgets/CourseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ void UpdateDRPC()
if (int.TryParse(sCourseID, out int courseID))
{
if (RomFS.CourseNames.TryGetValue(courseID, out string? courseName))
DRPC.SetEditingCourse(selectedArea.GetName(), courseName);
{
RomFS.CourseWorlds.TryGetValue(courseID, out int worldID);
DRPC.SetEditingCourse(selectedArea.GetName(), courseName, worldID);
Program.MainWindow.SetWindowIcon(worldID);
}
else
Logger.Logger.LogWarning("CourseScene", $"Failed to get course name for {course.GetName()}");

Expand Down
35 changes: 19 additions & 16 deletions Fushigi/ui/widgets/LevelViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,27 +715,30 @@ public void Draw(Vector2 size, double deltaSeconds, IDictionary<string, bool> la

CourseActor[] selectedActors = areaScene.EditContext.GetSelectedObjects<CourseActor>().ToArray();

if (selectedActors.Length != 0 &&
ImGui.IsKeyPressed(ImGuiKey.C) && modifiers == KeyboardModifier.CtrlCmd)
if (ImGui.IsWindowHovered())
{
CopiedObjects = new CourseActor[selectedActors.Length];
for (int i = 0; i < CopiedObjects.Length; i++)
CopiedObjects[i] = selectedActors[i].Clone(mArea);
}
bool ctrlOrCtrlShift = (modifiers == KeyboardModifier.CtrlCmd || modifiers == (KeyboardModifier.CtrlCmd | KeyboardModifier.Shift));
bool ctrlAndShift = modifiers == (KeyboardModifier.CtrlCmd | KeyboardModifier.Shift);
if (CopiedObjects.Length != 0 &&
ImGui.IsKeyPressed(ImGuiKey.V) && ctrlOrCtrlShift)
{
DoPaste(freshCopy: ctrlAndShift);
}
if (selectedActors.Length != 0 &&
!ImGui.IsAnyItemActive() &&
ImGui.IsKeyPressed(ImGuiKey.C) && modifiers == KeyboardModifier.CtrlCmd)
{
CopiedObjects = new CourseActor[selectedActors.Length];
for (int i = 0; i < CopiedObjects.Length; i++)
CopiedObjects[i] = selectedActors[i].Clone(mArea);
}
bool ctrlOrCtrlShift = (modifiers == KeyboardModifier.CtrlCmd || modifiers == (KeyboardModifier.CtrlCmd | KeyboardModifier.Shift));
bool ctrlAndShift = modifiers == (KeyboardModifier.CtrlCmd | KeyboardModifier.Shift);
if (CopiedObjects.Length != 0 &&
ImGui.IsKeyPressed(ImGuiKey.V) && ctrlOrCtrlShift)
{
DoPaste(freshCopy: ctrlAndShift);
}

if (hoveredActor != null && ImGui.IsMouseClicked(0) && ctrlOrCtrlShift)
DoImmediatePaste(freshCopy: ctrlAndShift);
}
if (ImGui.IsWindowFocused())
InteractionWithFocus(modifiers);

if (hoveredActor != null && ImGui.IsMouseClicked(0) && ctrlOrCtrlShift)
DoImmediatePaste(freshCopy: ctrlAndShift);

ImGui.PopClipRect();
}

Expand Down
19 changes: 1 addition & 18 deletions Fushigi/windowing/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using Silk.NET.Maths;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using System.Runtime.InteropServices;

namespace Fushigi.windowing
{
Expand All @@ -24,7 +21,7 @@ private record struct WindowResources(ImGuiController ImguiController, IInputCon
private static readonly List<IWindow> sPendingInits = [];
private static readonly List<(IWindow window, WindowResources res)> sWindows = [];

public static unsafe void CreateWindow(out IWindow window, Vector2D<int>? initialWindowSize = null, Action? onConfigureIO = null)
public static void CreateWindow(out IWindow window, Vector2D<int>? initialWindowSize = null, Action? onConfigureIO = null)
{
var options = WindowOptions.Default;
options.Title = $"Fushigi {Program.Version}";
Expand Down Expand Up @@ -58,20 +55,6 @@ public static unsafe void CreateWindow(out IWindow window, Vector2D<int>? initia
//update
_window.Update += ds => imguiController.Update((float)ds);

Logger.Logger.LogMessage("WindowManager", "Loading icon");
using var image = SixLabors.ImageSharp.Image.Load<Rgba32>(Path.Combine("res", "Icon.png"));
var memoryGroup = image.GetPixelMemoryGroup();
Memory<byte> array = new byte[memoryGroup.TotalLength * sizeof(Rgba32)];
var block = MemoryMarshal.Cast<byte, Rgba32>(array.Span);
foreach (var memory in memoryGroup)
{
memory.Span.CopyTo(block);
block = block[memory.Length..];
}

var icon = new RawImage(image.Width, image.Height, array);
_window.SetWindowIcon(ref icon);

sWindows.Add((_window, new WindowResources(imguiController, input, sGL, false)));
};

Expand Down

0 comments on commit ceb06f7

Please sign in to comment.