Tool windows redesign and the Novel Editor workspace

Tool windows:
- Every editor (scenario, scene builder, map, interactive objects,
  lighting, catalog export) is rebuilt on the interface ToolWindow chrome
  and the denser ToolTheme: header with title/close, status bar, Ctrl+S,
  dirty-state confirmation.
- Shared building blocks in src/Common: ToolUi (rows, buttons, sections),
  CollapsibleSection, FilteredList, ModFileSelector, DragHandle and
  BackgroundCanvas (scene background with pan/zoom).
- The map, interactive and light editors draw on canvases
  (MapEditorCanvas, InteractiveEditorCanvas, LightEditorCanvas) instead of
  one Control "handle" node per object; the *Handle classes are removed.
- Scenario editor: tab data model (TabData), automatic graph layout
  (ScenarioGraphLayout), file tree/info/thumbnail panel updates.
- Services: ModFileService (mod file listing and writing),
  SceneBackgroundService; MapFileService/ModResourceService follow.
- Catalog export: per-language name/description editing.
- Locale (en/ru) regrouped under tools/*; unused keys removed.

Novel Editor:
- collections/novel_editor.json: a "game" whose entry scene is an
  authoring workspace over the novel engine and the story content.
- NovelEditorHub (scenes/novel_editor_hub.tscn) lists every installed
  tool through IToolProvider.AddMenuButton; ToolsInitializer registers it
  as the logical scene "novel_editor".
This commit is contained in:
cthangover committed 2026-10-17 14:29:14 +00:00
1 parent 578ba7c5d5
commit 8742aa3da5
45 files changed
+4718 -3463

No files matched your search

+5 -101
View File
@@ -1,102 +1,21 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using Cthangover.Core.Mods;
using Cthangover.Core.Mods.Providers;
using Cthangover.Mods.Map;
using Cthangover.Core.Utils;
namespace Cthangover.Tools.Services
{
/// <summary>
/// Static service for discovering, reading and writing world map zone files
/// (<c>mods/&lt;mod&gt;/map/*.json</c>) from the map editor. Follows
/// <see cref="ScenarioFileService"/>: reading goes through the mod file
/// provider abstraction so zip mods are visible, writing is deliberately
/// limited to folder-backed mods because zip archives are read-only.
/// <para/>
/// New files are created through the provider's <c>RootPath</c> rather than
/// <c>GetFileSystemPath</c>, which reports <c>null</c> for files that do not
/// exist yet — the editor must be able to author a brand-new map file, not
/// only overwrite an existing one.
/// (De)serialisation of world map zone files (<c>mods/&lt;mod&gt;/map/*.json</c>)
/// for the map editor. File access itself goes through
/// <see cref="ModFileService"/>.
/// </summary>
public static class MapFileService
{
private const string MapDir = "map";
private const string JsonExtension = ".json";
/// <summary>
/// IDs of every loaded mod that can be written to (folder-backed).
/// Zip mods are skipped silently: they appear in the game but the editor
/// cannot save into them.
/// </summary>
public static List<string> ListWritableMods()
{
var result = new List<string>();
var manager = ModManager.Instance;
if (manager?.Mods == null)
return result;
foreach (var pair in manager.Mods)
{
if (pair.Value?.FileProvider is FolderModFileProvider)
result.Add(pair.Key);
}
result.Sort(StringComparer.OrdinalIgnoreCase);
return result;
}
/// <summary>
/// Mod-relative paths of all <c>.json</c> files under the mod's
/// <c>map/</c> directory, including nested subdirectories. Returns an
/// empty list for unknown mods.
/// </summary>
public static List<string> ListMapFiles(string modId)
{
var result = new List<string>();
if (string.IsNullOrEmpty(modId))
return result;
CollectJsonFiles(modId, MapDir, result);
result.Sort(StringComparer.OrdinalIgnoreCase);
return result;
}
/// <summary>Reads a map file through the mod provider; <c>null</c> when missing.</summary>
public static string ReadFile(string modId, string relativePath)
{
return ModManager.Instance.ReadFileText(modId, relativePath);
}
/// <summary>
/// Writes a map file into a folder-backed mod, creating the
/// <c>map/</c> directory and any missing parents. Returns <c>false</c>
/// for zip mods, unknown mods and empty paths.
/// </summary>
public static bool WriteFile(string modId, string relativePath, string text)
{
if (string.IsNullOrEmpty(modId) || string.IsNullOrEmpty(relativePath))
return false;
var mod = ModManager.Instance.GetMod(modId);
if (mod?.FileProvider is not FolderModFileProvider provider)
return false;
var root = provider.RootPath;
if (string.IsNullOrEmpty(root))
return false;
var absolute = Path.GetFullPath(Path.Combine(root, relativePath.Replace('\\', '/')));
var directory = Path.GetDirectoryName(absolute);
if (!string.IsNullOrEmpty(directory))
Directory.CreateDirectory(directory);
File.WriteAllText(absolute, text);
return true;
}
/// <summary>Folder of map zone files inside a mod.</summary>
public const string MapDir = "map";
/// <summary>
/// Parses the standard <c>{"Items": [...]}</c> envelope into zones.
@@ -122,20 +41,5 @@ namespace Cthangover.Tools.Services
var data = new FileData<MapZone> { Items = zones?.ToList() ?? new List<MapZone>() };
return JsonSerializer.Serialize(data, JsonOptionsProvider.WriteIndentedIgnoreNullOptions);
}
private static void CollectJsonFiles(string modId, string directory, List<string> result)
{
foreach (var entry in ModManager.Instance.ListFiles(modId, directory))
{
if (entry.EndsWith("/"))
{
CollectJsonFiles(modId, entry.TrimEnd('/'), result);
continue;
}
if (entry.EndsWith(JsonExtension, StringComparison.OrdinalIgnoreCase))
result.Add(entry.Replace('\\', '/'));
}
}
}
}