Slice 2: menu class picker (Warrior / Ranger)
MainMenuController gains a 2-class picker that sets WorldLauncher.SelectedClass; WorldLauncher seeds a ClassSelection singleton into the client world at session start, which GoInGameClientSystem carries on the spawn RPC. Default Warrior. Completes the Slice 2 loop: pick a class in the menu -> spawn with its kit. Editor-default boot stays Warrior (the menu path drives the choice). 348/348. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ namespace ProjectM.Client
|
|||||||
VisualElement _mainPanel;
|
VisualElement _mainPanel;
|
||||||
VisualElement _settingsPanel;
|
VisualElement _settingsPanel;
|
||||||
TextField _ipField;
|
TextField _ipField;
|
||||||
|
Label _classLabel;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,17 @@ namespace ProjectM.Client
|
|||||||
_mainPanel = MenuUi.FullScreenRoot(true);
|
_mainPanel = MenuUi.FullScreenRoot(true);
|
||||||
var card = MenuUi.Card("PROJECT M");
|
var card = MenuUi.Card("PROJECT M");
|
||||||
card.Add(MenuUi.Caption("Frontier colony — co-op"));
|
card.Add(MenuUi.Caption("Frontier colony — co-op"));
|
||||||
|
// Slice 2: class picker -> sets WorldLauncher.SelectedClass for the next session (Warrior melee / Ranger ranged).
|
||||||
|
_classLabel = new Label(ClassName(WorldLauncher.SelectedClass));
|
||||||
|
_classLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
|
||||||
|
_classLabel.style.marginTop = 6; _classLabel.style.marginBottom = 2;
|
||||||
|
card.Add(_classLabel);
|
||||||
|
var classRow = new VisualElement();
|
||||||
|
classRow.style.flexDirection = FlexDirection.Row;
|
||||||
|
classRow.style.justifyContent = Justify.Center;
|
||||||
|
classRow.Add(MenuUi.Button("Warrior", () => SelectClass((byte)CharacterId.Warrior)));
|
||||||
|
classRow.Add(MenuUi.Button("Ranger", () => SelectClass((byte)CharacterId.Ranger)));
|
||||||
|
card.Add(classRow);
|
||||||
|
|
||||||
card.Add(MenuUi.Button("Single Player", () => Launch(SessionMode.Single, false)));
|
card.Add(MenuUi.Button("Single Player", () => Launch(SessionMode.Single, false)));
|
||||||
|
|
||||||
@@ -79,6 +91,14 @@ namespace ProjectM.Client
|
|||||||
WorldLauncher.StartSession(mode, ip, loadSave);
|
WorldLauncher.StartSession(mode, ip, loadSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SelectClass(byte classId)
|
||||||
|
{
|
||||||
|
WorldLauncher.SelectedClass = classId;
|
||||||
|
if (_classLabel != null) _classLabel.text = ClassName(classId);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ClassName(byte classId) => classId == (byte)CharacterId.Ranger ? "CLASS: Ranger (ranged)" : "CLASS: Warrior (melee)";
|
||||||
|
|
||||||
void ShowSettings()
|
void ShowSettings()
|
||||||
{
|
{
|
||||||
_mainPanel.style.display = DisplayStyle.None;
|
_mainPanel.style.display = DisplayStyle.None;
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ namespace ProjectM.Client
|
|||||||
|
|
||||||
public static bool Busy { get; private set; }
|
public static bool Busy { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>Slice 2: the class chosen in the menu (a CharacterId byte), seeded into the client world at session start.</summary>
|
||||||
|
public static byte SelectedClass = (byte)CharacterId.Warrior;
|
||||||
|
|
||||||
public static void StartSession(SessionMode mode, string joinIp, bool loadSave)
|
public static void StartSession(SessionMode mode, string joinIp, bool loadSave)
|
||||||
{
|
{
|
||||||
if (Busy) return;
|
if (Busy) return;
|
||||||
@@ -51,6 +54,7 @@ namespace ProjectM.Client
|
|||||||
|
|
||||||
World server = null;
|
World server = null;
|
||||||
World client = ClientServerBootstrap.CreateClientWorld("ClientWorld");
|
World client = ClientServerBootstrap.CreateClientWorld("ClientWorld");
|
||||||
|
SeedClass(client, SelectedClass); // Slice 2: stage the chosen class for GoInGameClientSystem -> spawn
|
||||||
|
|
||||||
if (mode == SessionMode.Join)
|
if (mode == SessionMode.Join)
|
||||||
{
|
{
|
||||||
@@ -101,6 +105,15 @@ namespace ProjectM.Client
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SeedClass(World world, byte classId)
|
||||||
|
{
|
||||||
|
if (world is not { IsCreated: true }) return;
|
||||||
|
var em = world.EntityManager;
|
||||||
|
using var q = em.CreateEntityQuery(ComponentType.ReadWrite<ClassSelection>());
|
||||||
|
Entity e = q.IsEmptyIgnoreFilter ? em.CreateEntity(typeof(ClassSelection)) : q.GetSingletonEntity();
|
||||||
|
em.SetComponentData(e, new ClassSelection { ClassId = classId });
|
||||||
|
}
|
||||||
|
|
||||||
static void StagePendingSave(World server)
|
static void StagePendingSave(World server)
|
||||||
{
|
{
|
||||||
var data = SaveService.Load();
|
var data = SaveService.Load();
|
||||||
|
|||||||
Reference in New Issue
Block a user