Enhance HUD with inspector and spawner hints

- Added localization for inspector (F1) and spawner (F9) hints in both English and Russian.
- Updated the WorldScene to display a new HUD card that includes date/time/season and control hints.
- Refactored HudSystem to streamline the display of date/time/season information, removing seed and FPS from the HUD.

This update improves user experience by providing clearer control hints and a more informative HUD layout.
This commit is contained in:
Leonid Pershin
2026-06-16 14:45:21 +03:00
parent d0a0714563
commit 010d401b75
4 changed files with 37 additions and 26 deletions
+2
View File
@@ -7,6 +7,8 @@
"season.autumn": "autumn",
"season.winter": "winter",
"hud.controls": "WASD — camera, wheel — zoom, LMB — select, ` — console, F1 — inspector",
"hud.inspector": "F1 — inspector",
"hud.spawner": "F9 — spawner",
"inspect.tab.overview": "Overview",
"inspect.tab.genes": "Genes",
"inspect.tab.products": "Products",
+2
View File
@@ -7,6 +7,8 @@
"season.autumn": "осень",
"season.winter": "зима",
"hud.controls": "WASD — камера, колесо — зум, ЛКМ — выбрать, ` — консоль, F1 — инспектор",
"hud.inspector": "F1 — инспектор",
"hud.spawner": "F9 — спавнер",
"inspect.tab.overview": "Обзор",
"inspect.tab.genes": "Гены",
"inspect.tab.products": "Продукты",
+26 -13
View File
@@ -20,6 +20,7 @@ using MrGameEng.Lighting;
using MrGameEng.Tilemaps;
using MrGameEng.UI;
using Myra.Graphics2D;
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI;
namespace LittleSim.Scenes;
@@ -163,7 +164,7 @@ public sealed class WorldScene : Scene
// HUD, полоса скорости и меню-пауза в одной корневой панели.
var desktop = this.UseScaledUI();
var hudLabel = new Label { Left = 10, Top = 8 };
var hudLabel = new Label { TextColor = Ui.Accent }; // дата/время/сезон — заполняет HudSystem
var speedBar = BuildSpeedBar(content);
_pause = new PauseMenu(
Context,
@@ -218,7 +219,29 @@ public sealed class WorldScene : Scene
Margin = new Thickness(0, 8, 12, 0),
};
var hudChildren = new List<Widget> { hudLabel, _inspect.Panel, speedBar, _pause.Root };
// Карточка статуса (верх-слева): строка даты/времени/сезона + краткие подсказки клавиш. Спавнер
// (F9) — только в дев-режиме; инспектор (F1) доступен всегда.
var hint = content.Languages.Get("hud.inspector");
if (spawner is not null)
{
hint += " · " + content.Languages.Get("hud.spawner");
}
var hudCard = new VerticalStackPanel
{
Spacing = 3,
Padding = new Thickness(12, 8),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(10, 8, 0, 0),
Background = new SolidBrush(new Color(10, 13, 18, 210)),
Border = new SolidBrush(new Color(96, 134, 168)),
BorderThickness = new Thickness(1),
};
hudCard.Widgets.Add(hudLabel);
hudCard.Widgets.Add(new Label { Text = hint, TextColor = Ui.Muted });
var hudChildren = new List<Widget> { hudCard, _inspect.Panel, speedBar, _pause.Root };
if (spawner is not null)
{
hudChildren.Add(spawner.Panel);
@@ -448,17 +471,7 @@ public sealed class WorldScene : Scene
_perf?.Refresh();
})
);
UpdateSystems.Add(
new HudSystem(
Context,
content.Languages,
hudLabel,
"hud.world",
_config.Seed,
calendar,
climate
)
);
UpdateSystems.Add(new HudSystem(Context, content.Languages, hudLabel, calendar, climate));
UpdateSystems.Add(new CallbackSystem(() => Hotkeys(input)));
// Все системы добавлены — включаем per-system мониторинг (дев-режим), чтобы команда `perf`
+7 -13
View File
@@ -180,15 +180,14 @@ public sealed class GodCameraSystem(
}
/// <summary>
/// Строка статуса в HUD: заголовок сцены (ключ локализации с сидом, датой/временем календаря и
/// FPS) и подсказка управления. Обновляется 4 раза в секунду; смена языка подхватывается сама.
/// Строка даты/времени/сезона в HUD (верх-слева). Обновляется ~4 раза в секунду; смена языка
/// подхватывается сама. Сид и FPS убраны (сид виден в меню, FPS — в окне производительности),
/// подсказки управления вынесены отдельной строкой сцены.
/// </summary>
public sealed class HudSystem(
MrGameEng.Core.EngineContext context,
MrGameEng.Mods.LanguageManager languages,
Myra.Graphics2D.UI.Label label,
string titleKey,
int seed,
MrGameEng.Core.Calendar? calendar = null,
MrGameEng.Core.Climate? climate = null
) : BaseSystem
@@ -198,7 +197,6 @@ public sealed class HudSystem(
private static readonly string[] SeasonKeys = BuildSeasonKeys();
private float _accumulated;
private int _frames;
private static string[] BuildSeasonKeys()
{
@@ -215,27 +213,23 @@ public sealed class HudSystem(
protected override void OnUpdateGroup()
{
_accumulated += context.Clock.UnscaledDeltaTime;
_frames++;
if (_accumulated < 0.25f)
{
return;
}
var fps = (int)MathF.Round(_frames / _accumulated);
_accumulated = 0f;
_frames = 0;
var when = calendar is null
var text = calendar is null
? ""
: languages.Format("hud.datetime", calendar.Day, calendar.Hour, calendar.Minute);
if (climate is not null)
{
var season = languages.Get(SeasonKeys[(int)climate.Season]);
when +=
" | "
text +=
" · "
+ languages.Format("hud.climate", season, (int)MathF.Round(climate.Temperature));
}
label.Text =
languages.Format(titleKey, seed, when, fps) + "\n" + languages.Get("hud.controls");
label.Text = text;
}
}