Skip to content

Commit

Permalink
Improve localized strings support again.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Jan 13, 2025
1 parent aca3a68 commit eb2d2e6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
21 changes: 3 additions & 18 deletions src/Murder.Editor/CustomEditors/LocalizationAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Murder.Editor.Attributes;
using Murder.Editor.ImGuiExtended;
using Murder.Editor.Reflection;
using Murder.Editor.Services;
using Murder.Editor.Utilities;
using Murder.Editor.Utilities.Serialization;
using System.Numerics;
Expand Down Expand Up @@ -123,7 +124,7 @@ public override void DrawEditor()
ImGuiHelpers.DeleteButton($"delete_{g}");

// == Delete button ==
if (deleteButton && localizedStringData.IsGenerated)
if (deleteButton && !localizedStringData.IsGenerated)
{
_localization.RemoveResource(g, force: true);
_localization.FileChanged = true;
Expand Down Expand Up @@ -230,23 +231,7 @@ private void AddMissingResourcesFromAsset(LocalizationAsset? asset)
private void DrawNotesPopup(Guid g, LocalizedStringData localizedStringData)
{
GameLogger.Verify(_localization is not null);

if (ImGui.BeginPopup($"notes_{g}"))
{
string text = localizedStringData.Notes ?? string.Empty;
if (ImGui.InputText("##notes_name", ref text, 1024, ImGuiInputTextFlags.AutoSelectAll))
{
_localization.SetResource(localizedStringData with { Notes = text });
}

if (ImGui.Button("Ok!") || Game.Input.Pressed(MurderInputButtons.Submit))
{
ImGui.CloseCurrentPopup();
}

ImGui.EndPopup();
}
EditorLocalizationServices.DrawNotesPopup(_localization, g, localizedStringData);
}

}
}
15 changes: 12 additions & 3 deletions src/Murder.Editor/CustomFields/LocalizedStringField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public override (bool modified, object? result) ProcessInput(EditorMember member
return (true, EditorLocalizationServices.AddNewResource());
}
}
else
else if (localizedString.Value.Id is Guid guid)
{
if (ImGuiHelpers.DeleteButton($"localized_{member.Name}"))
{
localization.RemoveResource(localizedString.Value.Id);
localization.RemoveResource(guid);

localizedString = default;
modified = true;
Expand All @@ -65,7 +65,16 @@ public override (bool modified, object? result) ProcessInput(EditorMember member
modified = true;
}

ImGuiHelpers.HelpTooltip("Reset localized string");
ImGuiHelpers.HelpTooltip("Discard localized string without deleting");
ImGui.SameLine();

// == Notes ==
if (ImGuiHelpers.BlueIcon('\uf10d', $"note_b_{guid}"))
{
ImGui.OpenPopup($"notes_{guid}");
}

EditorLocalizationServices.DrawNotesPopup(guid);
ImGui.SameLine();
}

Expand Down
39 changes: 38 additions & 1 deletion src/Murder.Editor/Services/EditorLocalizationServices.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Murder.Assets;
using ImGuiNET;
using Murder.Assets;
using Murder.Assets.Localization;
using Murder.Core.Input;
using Murder.Diagnostics;
using Murder.Editor.ImGuiExtended;
using Murder.Services;
using static Murder.Editor.ImGuiExtended.SearchBox;
Expand Down Expand Up @@ -85,4 +88,38 @@ private static void AddExistingResource(Guid g)
EditorServices.SaveAssetWhenSelectedAssetIsSaved(asset.Guid);
asset.FileChanged = true;
}

/// <summary>
/// Draw pop up with notes for this resource string.
/// </summary>
public static void DrawNotesPopup(Guid g)
{
LocalizationAsset asset = Game.Data.GetDefaultLocalization();
if (asset.TryGetResource(g) is not LocalizedStringData data)
{
return;
}

ImGuiHelpers.HelpTooltip(string.IsNullOrEmpty(data.Notes) ? "(No notes)" : data.Notes);
DrawNotesPopup(asset, g, data);
}

public static void DrawNotesPopup(LocalizationAsset asset, Guid g, LocalizedStringData data)
{
if (ImGui.BeginPopup($"notes_{g}"))
{
string text = data.Notes ?? string.Empty;
if (ImGui.InputText("##notes_name", ref text, 1024, ImGuiInputTextFlags.AutoSelectAll))
{
asset.SetResource(data with { Notes = text });
}

if (ImGui.Button("Ok!") || Game.Input.Pressed(MurderInputButtons.Submit))
{
ImGui.CloseCurrentPopup();
}

ImGui.EndPopup();
}
}
}

0 comments on commit eb2d2e6

Please sign in to comment.