mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 11:25:56 +00:00
UI: translate Players, Companions, Client cards
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9dee0ce8b1
commit
488a1a45c6
8 files changed
+307
-43
No files matched your search
+21
-18
@@ -3,8 +3,11 @@ import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { api, asUiError, type ClientInfo, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
|
||||
export function ClientCard({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [info, setInfo] = useState<ClientInfo | null | undefined>(undefined);
|
||||
const [error, setError] = useState<UiError | null>(null);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
@@ -31,7 +34,7 @@ export function ClientCard({ serverId }: { serverId: string }) {
|
||||
}
|
||||
|
||||
async function choose() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose your game client folder" });
|
||||
const picked = await open({ directory: true, multiple: false, title: t("client.dialogTitle") });
|
||||
if (typeof picked === "string") await run(async () => void (await api.setClient(serverId, picked)));
|
||||
}
|
||||
|
||||
@@ -40,48 +43,48 @@ export function ClientCard({ serverId }: { serverId: string }) {
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Game client</h2>
|
||||
{info === undefined && <p className="mt-2 text-sm text-muted">Looking…</p>}
|
||||
<h2 className="font-semibold">{t("client.title")}</h2>
|
||||
{info === undefined && <p className="mt-2 text-sm text-muted">{t("client.looking")}</p>}
|
||||
{info === null && (
|
||||
<>
|
||||
<p className="mt-1 text-sm text-muted">Tell Manager where your game is installed to get a PLAY button. Your game files are never changed except the server address and the companion addon.</p>
|
||||
<Button className="mt-4" onClick={() => void choose()} disabled={busy}>Choose game folder…</Button>
|
||||
<p className="mt-1 text-sm text-muted">{t("client.intro")}</p>
|
||||
<Button className="mt-4" onClick={() => void choose()} disabled={busy}>{t("client.chooseFolder")}</Button>
|
||||
</>
|
||||
)}
|
||||
{info && (
|
||||
<>
|
||||
<p className="selectable mt-1 break-all text-sm text-muted">{info.path}</p>
|
||||
<dl className="mt-4 grid grid-cols-[auto_1fr] gap-x-6 gap-y-2 text-sm">
|
||||
<dt className="text-muted">Connects to</dt>
|
||||
<dt className="text-muted">{t("client.connectsTo")}</dt>
|
||||
<dd>
|
||||
{hosts.length ? hosts.filter(Boolean).join(", ") : "—"}
|
||||
{pointsLocal ? <span className="ml-2 text-ok">✓ this computer</span> : <span className="ml-2 text-warn">not this server</span>}
|
||||
{pointsLocal ? <span className="ml-2 text-ok">{t("client.thisComputer")}</span> : <span className="ml-2 text-warn">{t("client.notThisServer")}</span>}
|
||||
</dd>
|
||||
<dt className="text-muted">Companion addon</dt>
|
||||
<dt className="text-muted">{t("client.addon")}</dt>
|
||||
<dd>
|
||||
{info.addon.installed ? `Installed${info.addon.version ? ` (version ${info.addon.version})` : ""}` : "Not installed"}
|
||||
{info.addon.up_to_date === false && <span className="ml-2 text-warn">an update is available</span>}
|
||||
{info.addon.installed ? (info.addon.version ? t("client.installedVersion", { v: info.addon.version }) : t("client.installed")) : t("client.addonNotInstalled")}
|
||||
{info.addon.up_to_date === false && <span className="ml-2 text-warn">{t("client.updateAvailable")}</span>}
|
||||
</dd>
|
||||
<dt className="text-muted">Other addons</dt>
|
||||
<dd>{info.other_addons} — left exactly as they are</dd>
|
||||
<dt className="text-muted">{t("client.otherAddons")}</dt>
|
||||
<dd>{t("client.leftAsIs", { n: info.other_addons })}</dd>
|
||||
</dl>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{!pointsLocal && (
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.setRealmlist(serverId, "127.0.0.1"); return "The game now connects to this computer. The previous address was saved."; })}>
|
||||
Point the game at this server
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.setRealmlist(serverId, "127.0.0.1"); return t("client.pointedNote"); })}>
|
||||
{t("client.pointLocal")}
|
||||
</Button>
|
||||
)}
|
||||
{(!info.addon.installed || info.addon.up_to_date === false) && (
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.installAddon(serverId); return "Companion addon installed. Other addons were not touched."; })}>
|
||||
{info.addon.installed ? "Update companion addon" : "Install companion addon"}
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.installAddon(serverId); return t("client.addonNote"); })}>
|
||||
{info.addon.installed ? t("client.updateAddon") : t("client.installAddon")}
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" variant="ghost" disabled={busy} onClick={() => void choose()}>Change folder…</Button>
|
||||
<Button size="sm" variant="ghost" disabled={busy} onClick={() => void choose()}>{t("client.changeFolder")}</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : error.human.message}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,11 @@ import { Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type CompanionSizes, type Population, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
|
||||
export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [sizes, setSizes] = useState<CompanionSizes | null>(null);
|
||||
const [pop, setPop] = useState<Population | null>(null);
|
||||
const [running, setRunning] = useState(false);
|
||||
@@ -33,7 +36,7 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
}, [serverId]);
|
||||
|
||||
const count = choice === "custom" ? Number(custom) : (sizes?.sizes.find((s) => s.id === choice)?.bots ?? 0);
|
||||
const warning = choice === "custom" ? (count > 500 ? "Large populations may need more CPU and memory. Increase gradually." : null) : (sizes?.sizes.find((s) => s.id === choice)?.warning ?? null);
|
||||
const warning = choice === "custom" ? (count > 500 ? t("comp.largeWarning") : null) : (sizes?.sizes.find((s) => s.id === choice)?.warning ?? null);
|
||||
const valid = Number.isInteger(count) && count >= 1 && count <= 2000;
|
||||
|
||||
async function add() {
|
||||
@@ -42,7 +45,7 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
setNote(null);
|
||||
try {
|
||||
const r = await api.addCompanions(serverId, count);
|
||||
setNote(r.spawned ? `Creating ${count} companions. They appear gradually over the next minutes.` : `Saved. ${count} companions will log in when the server starts.`);
|
||||
setNote(r.spawned ? t("comp.spawned", { n: count }) : t("comp.saved", { n: count }));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
@@ -52,17 +55,17 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">AI companions</h2>
|
||||
<h2 className="font-semibold">{t("comp.title")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
{pop
|
||||
? `${pop.bots_online} online now · ${pop.bots_total} created in total`
|
||||
? t("comp.population", { online: pop.bots_online, total: pop.bots_total })
|
||||
: running
|
||||
? "Reading the current population…"
|
||||
: "Start the server to see how many companions are online."}
|
||||
? t("comp.reading")
|
||||
: t("comp.startToSee")}
|
||||
</p>
|
||||
|
||||
<fieldset className="mt-4">
|
||||
<legend className="text-sm text-muted">Would you like more companions?</legend>
|
||||
<legend className="text-sm text-muted">{t("comp.wantMore")}</legend>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{sizes?.sizes.map((s) => (
|
||||
<label key={s.id} className={`cursor-pointer rounded-md border px-3 py-2 text-sm ${choice === s.id ? "border-gold bg-gold/10" : "border-line hover:bg-white/5"}`}>
|
||||
@@ -72,26 +75,26 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
))}
|
||||
<label className={`cursor-pointer rounded-md border px-3 py-2 text-sm ${choice === "custom" ? "border-gold bg-gold/10" : "border-line hover:bg-white/5"}`}>
|
||||
<input type="radio" name="size" className="sr-only" checked={choice === "custom"} onChange={() => setChoice("custom")} />
|
||||
Custom
|
||||
{t("comp.custom")}
|
||||
</label>
|
||||
{choice === "custom" && (
|
||||
<input aria-label="Number of companions" value={custom} onChange={(e) => setCustom(e.target.value)} inputMode="numeric" className="w-24 rounded-md border border-line bg-bg px-3 py-2 text-right text-sm outline-none focus:border-gold" />
|
||||
<input aria-label={t("comp.numberLabel")} value={custom} onChange={(e) => setCustom(e.target.value)} inputMode="numeric" className="w-24 rounded-md border border-line bg-bg px-3 py-2 text-right text-sm outline-none focus:border-gold" />
|
||||
)}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{warning && <p className="mt-3 text-sm text-warn" role="status">{warning}</p>}
|
||||
{sizes && <p className="mt-2 text-xs text-muted">This computer: {sizes.hardware.cores} cores, {sizes.hardware.ram_gb.toFixed(0)} GB memory.</p>}
|
||||
{sizes && <p className="mt-2 text-xs text-muted">{t("comp.hardware", { cores: sizes.hardware.cores, ram: sizes.hardware.ram_gb.toFixed(0) })}</p>}
|
||||
|
||||
<div className="mt-4 flex items-center gap-3">
|
||||
<Button variant="primary" disabled={busy || !valid} onClick={() => void add()}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
Add {valid ? count : ""} companions
|
||||
{valid ? t("comp.add", { n: count }) : t("comp.addPlain")}
|
||||
</Button>
|
||||
{!running && <span className="text-xs text-muted">The server is stopped: they will be created the next time it runs.</span>}
|
||||
{!running && <span className="text-xs text-muted">{t("comp.stoppedHint")}</span>}
|
||||
</div>
|
||||
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : error.human.message}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
+15
-12
@@ -2,8 +2,11 @@ import { useEffect, useState } from "react";
|
||||
import { api, asUiError, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
|
||||
export function PlayersPage({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [online, setOnline] = useState<boolean | null>(null);
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
@@ -42,37 +45,37 @@ export function PlayersPage({ serverId }: { serverId: string }) {
|
||||
const input = "w-72 rounded-md border border-line bg-bg px-3 py-2.5 text-[15px] outline-none focus:border-gold";
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
<h1 className="text-2xl font-semibold">Players</h1>
|
||||
<p className="mt-1 text-muted">Who is playing right now?</p>
|
||||
<h1 className="text-2xl font-semibold">{t("players.title")}</h1>
|
||||
<p className="mt-1 text-muted">{t("q.players")}</p>
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Create your account</h2>
|
||||
<p className="mt-1 text-sm text-muted">This is the name and password you use to log in to the game.</p>
|
||||
{online === false && <p className="mt-3 text-sm text-warn">Start the server first — accounts are created while it is running.</p>}
|
||||
<h2 className="font-semibold">{t("players.createTitle")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("players.createText")}</p>
|
||||
{online === false && <p className="mt-3 text-sm text-warn">{t("players.startFirst")}</p>}
|
||||
<div className="mt-4 flex flex-col gap-3">
|
||||
<div>
|
||||
<label htmlFor="acc-user" className="text-sm text-muted">Username</label>
|
||||
<label htmlFor="acc-user" className="text-sm text-muted">{t("players.username")}</label>
|
||||
<input id="acc-user" className={input + " mt-1 block"} value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="off" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="acc-pass" className="text-sm text-muted">Password</label>
|
||||
<label htmlFor="acc-pass" className="text-sm text-muted">{t("players.password")}</label>
|
||||
<input id="acc-pass" type="password" className={input + " mt-1 block"} value={password} onChange={(e) => setPassword(e.target.value)} autoComplete="new-password" />
|
||||
</div>
|
||||
<label className="flex cursor-pointer items-start gap-2 text-sm">
|
||||
<input type="checkbox" checked={admin} onChange={(e) => setAdmin(e.target.checked)} className="mt-1" />
|
||||
<span>
|
||||
Make this account an administrator
|
||||
<span className="block text-xs text-muted">Administrators can use game-master commands in the game. Only do this for accounts you trust.</span>
|
||||
{t("players.admin")}
|
||||
<span className="block text-xs text-muted">{t("players.adminHint")}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<Button className="mt-5" variant="primary" disabled={busy || !online || !username || !password} onClick={() => void create()}>
|
||||
Create account
|
||||
{t("players.create")}
|
||||
</Button>
|
||||
{done && <p className="mt-3 text-sm text-ok" role="status">Account “{done}” created. You can log in to the game with it now.</p>}
|
||||
{done && <p className="mt-3 text-sm text-ok" role="status">{t("players.created", { name: done })}</p>}
|
||||
{error && (
|
||||
<p className="mt-3 text-sm text-bad" role="alert">
|
||||
{error.human.code === "unknown" ? error.technical : error.human.message}
|
||||
{error.human.code === "unknown" ? error.technical : human(error.human).message}
|
||||
</p>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
Reference in new issue
Block a user