New Game is a two-pane scenario picker: names by group, selected brief/seed/ambient, one Launch, arrows and Enter

MainMenu.AddScenarios and the per-scenario launching buttons are deleted; the seven Clear+Title pairs collapse into Next. The main menu EventSystem no longer deselects on background click so the arrows keep working.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-22 20:02:16 +02:00
commit 3bfac25027
3 changed files with 162 additions and 38 deletions

View file

@ -525,7 +525,7 @@ MonoBehaviour:
type: 3}
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_DeselectOnBackgroundClick: 1
m_DeselectOnBackgroundClick: 0
m_PointerBehavior: 0
--- !u!114 &553528108
MonoBehaviour:

View file

@ -23,7 +23,7 @@ public class MainMenu : MonoBehaviour
public float FadeAlphaExponent = 2;
public float FadePositionExponent = 2;
private (PropertiesPanel panel, CanvasGroup group) _currentMenu, _nextMenu;
private (PropertiesPanel panel, CanvasGroup group, PropertiesPanel detail) _currentMenu, _nextMenu;
private bool _fadeFromRight;
private float _fadeLerp;
private bool _fading;
@ -38,10 +38,14 @@ public class MainMenu : MonoBehaviour
_panelPosition = PanelPrototype.transform.position;
var panel1 = PanelPrototype.Instantiate<PropertiesPanel>();
_currentMenu = (panel1, panel1.GetComponent<CanvasGroup>());
var detail1 = PanelPrototype.Instantiate<PropertiesPanel>();
ScenarioPicker.Dock(detail1, panel1);
_currentMenu = (panel1, panel1.GetComponent<CanvasGroup>(), detail1);
var panel2 = PanelPrototype.Instantiate<PropertiesPanel>();
_nextMenu = (panel2, panel2.GetComponent<CanvasGroup>());
var detail2 = PanelPrototype.Instantiate<PropertiesPanel>();
ScenarioPicker.Dock(detail2, panel2);
_nextMenu = (panel2, panel2.GetComponent<CanvasGroup>(), detail2);
_currentMenu.panel.gameObject.SetActive(false);
//_saveDirectory = ActionGameManager.GameDataDirectory.CreateSubdirectory("Saves");
@ -74,7 +78,7 @@ public class MainMenu : MonoBehaviour
}
}
private string TitleSubtitle(string title, string subtitle) => $"{title}\n<smallcaps><size=50%>{subtitle}";
public static string TitleSubtitle(string title, string subtitle) => $"{title}\n<smallcaps><size=50%>{subtitle}";
private void Fade(bool fromRight)
{
@ -87,10 +91,18 @@ public class MainMenu : MonoBehaviour
private static bool _exclusionsShown;
private void ShowMain()
// Starts the next screen on an empty panel with a title and its scenario detail pane hidden and empty.
private void Next(string title)
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("aetheria", "terminus");
_nextMenu.panel.Title.text = title;
_nextMenu.detail.Clear();
_nextMenu.detail.gameObject.SetActive(false);
}
private void ShowMain()
{
Next(TitleSubtitle("aetheria", "terminus"));
if (ActionGameManager.CurrentGalaxy == null)
{
// No run is live: at the title, after death, or after a new run failed to start. A saved run exists only as
@ -131,31 +143,18 @@ public class MainMenu : MonoBehaviour
// to set up a run and the test arenas are listed only in editor and development builds.
private void ShowScenarios()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("new game", "scenarios");
AddScenarios(Scenarios.Modes);
Next(TitleSubtitle("new game", "scenarios"));
var groups = new List<(string label, Scenario[] scenarios)> { ("modes", Scenarios.Modes) };
if (Debug.isDebugBuild)
{
_nextMenu.panel.AddSection("development");
AddScenarios(Scenarios.Development);
_nextMenu.panel.AddSection("test arenas");
AddScenarios(Scenarios.Tests);
groups.Add(("development", Scenarios.Development));
groups.Add(("test arenas", Scenarios.Tests));
}
_nextMenu.panel.AddButton("Back",
() =>
{
ShowMain();
Fade(false);
});
}
private void AddScenarios(IEnumerable<Scenario> scenarios)
{
foreach (var scenario in scenarios)
ScenarioPicker.Show(_nextMenu.panel, _nextMenu.detail, groups, Launch, () =>
{
_nextMenu.panel.AddButton(scenario.Name, () => Launch(scenario));
_nextMenu.panel.AddProperty(() => scenario.Brief);
}
ShowMain();
Fade(false);
});
}
// The only way into a new run: generates the scenario's galaxy off the main thread and enters the game, where
@ -263,8 +262,7 @@ public class MainMenu : MonoBehaviour
private void ShowSettings()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = "settings";
Next("settings");
_nextMenu.panel.AddButton("Gameplay",
() =>
{
@ -299,8 +297,7 @@ public class MainMenu : MonoBehaviour
private void ShowGameplaySettings()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("gameplay", "settings");
Next(TitleSubtitle("gameplay", "settings"));
_nextMenu.panel.AddField("Name",
() => ActionGameManager.PlayerSettings.Name,
s => ActionGameManager.PlayerSettings.Name = s);
@ -322,8 +319,7 @@ public class MainMenu : MonoBehaviour
private void ShowGraphicsSettings()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("graphics", "settings");
Next(TitleSubtitle("graphics", "settings"));
_nextMenu.panel.AddField("Nebula Quality",
() => (int)ActionGameManager.PlayerSettings.GraphicsSettings.NebulaQuality,
i =>
@ -347,8 +343,7 @@ public class MainMenu : MonoBehaviour
private void ShowInputSettings()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("input", "settings");
Next(TitleSubtitle("input", "settings"));
_nextMenu.panel.AddButton("Back",
() =>
{
@ -359,8 +354,7 @@ public class MainMenu : MonoBehaviour
private void ShowAudioSettings()
{
_nextMenu.panel.Clear();
_nextMenu.panel.Title.text = TitleSubtitle("audio", "settings");
Next(TitleSubtitle("audio", "settings"));
_nextMenu.panel.AddButton("Back",
() =>
{

View file

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
// The New Game screen: scenario names on the left pane by group, the selected scenario's brief, seed and ambient on a
// docked right pane, one Launch. This class owns which scenario is selected (one index into the rows it built);
// everything the screen shows about a scenario, and what Launch and Enter launch, reads that index. Keys arrive only as
// Input System UI events on the focused Launch button, so Enter and a mouse click are the same Button.onClick.
public sealed class ScenarioPicker
{
private readonly List<Scenario> _scenarios = new List<Scenario>();
private readonly List<string> _groupLabels = new List<string>();
private readonly List<Button> _rows = new List<Button>();
private readonly List<ColorBlock> _rowColors = new List<ColorBlock>();
private readonly PropertiesPanel _detail;
private readonly Action<Scenario> _launch;
private readonly Action _back;
private Button _launchButton;
private int _selected;
private ScenarioPicker(PropertiesPanel detail, Action<Scenario> launch, Action back)
{
_detail = detail;
_launch = launch;
_back = back;
}
// The scenario the detail pane describes and Launch will launch.
public Scenario Selected => _scenarios[_selected];
// Parks the detail pane beside the list pane: a child of it, outside its layout, hidden until Show.
public static void Dock(PropertiesPanel detail, PropertiesPanel list, float width = 480, float gap = 16)
{
var rect = (RectTransform) detail.transform;
rect.SetParent(list.transform, false);
detail.gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
rect.anchorMin = new Vector2(1, 0);
rect.anchorMax = new Vector2(1, 1);
rect.pivot = new Vector2(0, .5f);
rect.anchoredPosition = new Vector2(gap, 0);
rect.sizeDelta = new Vector2(width, 0);
detail.gameObject.SetActive(false);
}
// Builds both panes for the groups, shows the detail pane, selects the first scenario and focuses Launch.
public static ScenarioPicker Show(PropertiesPanel list, PropertiesPanel detail,
IReadOnlyList<(string label, Scenario[] scenarios)> groups, Action<Scenario> launch, Action back)
{
var picker = new ScenarioPicker(detail, launch, back);
foreach (var group in groups)
{
if (groups.Count > 1) list.AddSection(group.label);
foreach (var scenario in group.scenarios)
{
var index = picker._scenarios.Count;
picker._scenarios.Add(scenario);
picker._groupLabels.Add(group.label);
var row = list.AddButton(scenario.Name, () => picker.Select(index));
picker.Track(row.Button);
picker._rows.Add(row.Button);
picker._rowColors.Add(row.Button.colors);
}
}
picker.Track(list.AddButton("Back", picker.Back).Button);
detail.Clear();
detail.gameObject.SetActive(true);
detail.AddProperty(() => picker.Selected.Brief);
detail.AddProperty("Seed", () => picker.Selected.Seed == 0 ? "new each launch" : picker.Selected.Seed.ToString());
detail.AddProperty("Ambient", () => picker.Selected.Ambient ? "on" : "off");
picker._launchButton = detail.AddButton("Launch", picker.Activate).Button;
picker.Track(picker._launchButton);
picker._launchButton.OnMoveAsObservable().Subscribe(move =>
{
if (move.moveDir == MoveDirection.Up) picker.Step(-1);
else if (move.moveDir == MoveDirection.Down) picker.Step(1);
});
picker._launchButton.OnCancelAsObservable().Subscribe(_ => picker.Back());
picker.Select(0);
return picker;
}
// Takes a button out of Unity's navigation so a click never moves focus and Move never walks automatic navigation.
private void Track(Button button) => button.navigation = new Navigation { mode = Navigation.Mode.None };
// Moves the selection one row, stopping at either end.
private void Step(int delta) => Select(_selected + delta);
// Makes one row the selection: clamps the index, redraws the highlight and title, and returns focus to Launch.
private void Select(int index)
{
_selected = Mathf.Clamp(index, 0, _scenarios.Count - 1);
for (var i = 0; i < _rows.Count; i++)
{
var colors = _rowColors[i];
if (i == _selected)
{
colors.normalColor = colors.highlightedColor;
colors.selectedColor = colors.highlightedColor;
}
_rows[i].colors = colors;
}
_detail.Title.text = MainMenu.TitleSubtitle(Selected.Name, _groupLabels[_selected]);
Focus(_launchButton.gameObject);
}
// Launches the selection; focus is cleared first so a repeated Enter or a second click cannot launch twice.
private void Activate()
{
Focus(null);
_launch(Selected);
}
// Leaves the screen; the same path for the Back button and Cancel.
private void Back()
{
Focus(null);
_back();
}
private static void Focus(GameObject target)
{
if (EventSystem.current != null) EventSystem.current.SetSelectedGameObject(target);
}
}