mirror of
https://github.com/Shu-Ying/noname-shuying.git
synced 2026-11-23 21:50:01 +08:00
fixed # 优化角色选择界面
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 785 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
+14
-7
@@ -115,6 +115,7 @@ import { chooseRewardPackage } from "./ui/reward-package.js";
|
|||||||
import { applyStoryOutcome, getAvailableStoryChoices } from "./progression/story.js";
|
import { applyStoryOutcome, getAvailableStoryChoices } from "./progression/story.js";
|
||||||
import { playDialogue } from "./ui/dialogue.js";
|
import { playDialogue } from "./ui/dialogue.js";
|
||||||
import { chooseButtons } from "./ui/flow-ui.js";
|
import { chooseButtons } from "./ui/flow-ui.js";
|
||||||
|
import { chooseCharacterCards } from "./ui/character-select.js";
|
||||||
import { chooseRest } from "./ui/rest-ui.js";
|
import { chooseRest } from "./ui/rest-ui.js";
|
||||||
import { chooseShop } from "./ui/shop-ui.js";
|
import { chooseShop } from "./ui/shop-ui.js";
|
||||||
import { openModeSelection } from "./ui/navigation.js";
|
import { openModeSelection } from "./ui/navigation.js";
|
||||||
@@ -179,12 +180,18 @@ const chooseRun = async savedRun => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const chooseCharacter = async (backLabel = "返回存档选择") => {
|
const chooseCharacter = async (backLabel = "返回存档选择") => {
|
||||||
const choices = config.characters.filter(name => lib.character[name]).map(name => ({
|
const playable = config.characters.filter(id => lib.character[id]).map(id => {
|
||||||
id: name,
|
const { group, img } = lib.character[id];
|
||||||
name: get.translation(name),
|
return {
|
||||||
description: lib.translate[`${name}_title`] || "作为本次征程的角色",
|
id,
|
||||||
}));
|
name: get.translation(id),
|
||||||
return chooseButtons("选择出征武将", [...(choices.length ? choices : [{ id: "mengsan_liubei_shuying", name: "刘备" }]), { id: "back", name: backLabel, description: "不会修改现有征程" }], "此武将将陪伴你完成本次征程。", { back: "back", eyebrow: "出征准备" });
|
faction: group,
|
||||||
|
factionName: get.translation(group),
|
||||||
|
portrait: img ? lib.assetURL + img : "",
|
||||||
|
description: lib.translate[`${id}_title`] || "作为本次征程的角色",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return chooseCharacterCards(playable, STYLE_PATH, backLabel);
|
||||||
};
|
};
|
||||||
|
|
||||||
const chooseDefeatAction = async run => chooseButtons("角色阵亡", [
|
const chooseDefeatAction = async run => chooseButtons("角色阵亡", [
|
||||||
@@ -2049,7 +2056,7 @@ export async function createMengsanMode() {
|
|||||||
[245, 196, 193, 1], [192, 85, 91, 1],
|
[245, 196, 193, 1], [192, 85, 91, 1],
|
||||||
] });
|
] });
|
||||||
}
|
}
|
||||||
await Promise.all(["style", "shop", "rest"].map(name => new Promise(resolve => {
|
await Promise.all(["style", "shop", "rest", "character-select"].map(name => new Promise(resolve => {
|
||||||
const style = lib.init.css(`${STYLE_PATH}/ui`, name, resolve);
|
const style = lib.init.css(`${STYLE_PATH}/ui`, name, resolve);
|
||||||
style.addEventListener("error", resolve, { once: true });
|
style.addEventListener("error", resolve, { once: true });
|
||||||
})));
|
})));
|
||||||
|
|||||||
@@ -0,0 +1,199 @@
|
|||||||
|
.mengsan-flow-overlay-shuying.mengsan-character-overlay-shuying {
|
||||||
|
background: radial-gradient(ellipse at 48% 12%, #35403c, #111819 76%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mengsan-character-panel-shuying {
|
||||||
|
--character-paper: #f5ead6;
|
||||||
|
--character-gold: #e6c493;
|
||||||
|
--character-line: #706047;
|
||||||
|
--character-panel-padding: clamp(12px, 3vw, 30px);
|
||||||
|
--character-panel-gap: clamp(12px, 2vw, 20px);
|
||||||
|
--character-title-size: clamp(22px, 3.6vw, 38px);
|
||||||
|
/* Overlay padding, heading, and footer consume this space before the portraits. */
|
||||||
|
--character-controls-height: calc(192px + 2 * var(--character-panel-padding)
|
||||||
|
+ 2 * var(--character-panel-gap) + 1.15 * var(--character-title-size));
|
||||||
|
gap: var(--character-panel-gap);
|
||||||
|
width: min(1000px, 100%) !important;
|
||||||
|
max-height: 100% !important;
|
||||||
|
padding: var(--character-panel-padding);
|
||||||
|
border: 1px solid var(--character-line);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: radial-gradient(ellipse at 50% 0, #30362c, transparent 72%), #151d1d;
|
||||||
|
color: var(--character-paper);
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-character-header,
|
||||||
|
.ms-character-footer {
|
||||||
|
display: flex;
|
||||||
|
flex: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-character-header {
|
||||||
|
padding-bottom: 12px;
|
||||||
|
border-bottom: 1px solid var(--character-line);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-character-heading { position: relative; min-width: 0; }
|
||||||
|
.ms-character-eyebrow,
|
||||||
|
.ms-character-title,
|
||||||
|
.ms-character-status { margin: 0; }
|
||||||
|
.ms-character-eyebrow {
|
||||||
|
margin-bottom: 3px;
|
||||||
|
color: var(--character-gold);
|
||||||
|
font-size: 12px;
|
||||||
|
letter-spacing: .16em;
|
||||||
|
}
|
||||||
|
.ms-character-title {
|
||||||
|
font: 700 var(--character-title-size)/1.15 "KaiTi", "STKaiti", "SimSun", serif;
|
||||||
|
letter-spacing: .08em;
|
||||||
|
}
|
||||||
|
.ms-character-status { color: #d4c9b6; font-size: 13px; }
|
||||||
|
|
||||||
|
.ms-character-button {
|
||||||
|
flex: none;
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 6px clamp(8px, 1.6vw, 16px);
|
||||||
|
border: 1px solid var(--character-line);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #1b2120;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
.ms-character-button:hover { background: #322f25; }
|
||||||
|
.ms-character-confirm {
|
||||||
|
min-width: 7.5em;
|
||||||
|
border-color: var(--character-gold);
|
||||||
|
background: var(--character-gold);
|
||||||
|
color: #251b12;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.ms-character-confirm:hover:not(:disabled) { background: #f8d9a7; }
|
||||||
|
.ms-character-confirm:disabled {
|
||||||
|
border-color: var(--character-line);
|
||||||
|
background: #252c2b;
|
||||||
|
color: #c5bfad;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-character-list {
|
||||||
|
display: grid;
|
||||||
|
flex: none;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: clamp(7px, 1.8vw, 17px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-character-card {
|
||||||
|
--character-accent: #c9b894;
|
||||||
|
--character-deep: #554629;
|
||||||
|
position: relative;
|
||||||
|
isolation: isolate;
|
||||||
|
overflow: hidden;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: clamp(132px, min(46vw, calc(100vh - var(--character-controls-height))), 404px);
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid var(--character-line);
|
||||||
|
border-color: color-mix(in srgb, var(--character-accent) 45%, #3e3e36);
|
||||||
|
border-radius: 5px;
|
||||||
|
background: #171c1d;
|
||||||
|
color: #fff3dd;
|
||||||
|
font: inherit;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
.ms-character-card[data-faction="han"] { --character-accent: #df8979; --character-deep: #883b36; }
|
||||||
|
.ms-character-card[data-faction="wei"] { --character-accent: #99c3ed; --character-deep: #34577f; }
|
||||||
|
.ms-character-card[data-faction="wu"] { --character-accent: #9acb91; --character-deep: #3a694a; }
|
||||||
|
.ms-character-card::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(0deg, #121715, #151817db 14%, #16181730 54%, transparent 78%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.ms-character-card:hover,
|
||||||
|
.ms-character-card[aria-pressed="true"] { border-color: var(--character-accent); }
|
||||||
|
.ms-character-card[aria-pressed="true"] {
|
||||||
|
box-shadow: 0 0 0 1px var(--character-accent), 0 0 24px color-mix(in srgb, var(--character-accent) 18%, transparent);
|
||||||
|
}
|
||||||
|
.ms-character-panel-shuying button:focus-visible {
|
||||||
|
outline: 2px solid var(--character-gold);
|
||||||
|
outline-offset: 3px;
|
||||||
|
}
|
||||||
|
.ms-character-portrait {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
object-position: center 17%;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.ms-character-faction,
|
||||||
|
.ms-character-picked,
|
||||||
|
.ms-character-caption {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.ms-character-faction {
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
min-width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
border: 1px solid var(--character-accent);
|
||||||
|
border-radius: 2px;
|
||||||
|
background: var(--character-deep);
|
||||||
|
font: 700 18px/1 "KaiTi", "STKaiti", "SimSun", serif;
|
||||||
|
}
|
||||||
|
.ms-character-picked {
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
padding: 2px 5px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: #121715;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
.ms-character-picked[hidden] { display: none; }
|
||||||
|
.ms-character-caption {
|
||||||
|
right: 10px;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
}
|
||||||
|
.ms-character-name {
|
||||||
|
display: block;
|
||||||
|
font: 700 clamp(19px, 3.8vw, 36px)/1.14 "KaiTi", "STKaiti", "SimSun", serif;
|
||||||
|
}
|
||||||
|
.ms-character-description {
|
||||||
|
display: block;
|
||||||
|
min-height: 2.6em;
|
||||||
|
margin-top: 5px;
|
||||||
|
color: #f0e7d8;
|
||||||
|
font-size: clamp(11px, 1.5vw, 13px);
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 520px) {
|
||||||
|
.mengsan-character-overlay-shuying { padding-inline: 10px; }
|
||||||
|
.ms-character-faction { top: 6px; left: 6px; min-width: 25px; height: 25px; }
|
||||||
|
.ms-character-picked { top: 7px; right: 5px; }
|
||||||
|
.ms-character-caption { right: 5px; bottom: 7px; left: 6px; }
|
||||||
|
.ms-character-button { font-size: 12px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-height: 440px) {
|
||||||
|
.mengsan-flow-overlay-shuying.mengsan-character-overlay-shuying { padding-block: 62px 10px; }
|
||||||
|
.mengsan-character-panel-shuying { gap: 8px; padding: 10px; }
|
||||||
|
.ms-character-header { padding-bottom: 4px; }
|
||||||
|
.ms-character-title { font-size: 22px; }
|
||||||
|
.ms-character-card { min-height: clamp(114px, calc(100vh - 210px), 190px); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { chooseFlow } from "./flow-ui.js";
|
||||||
|
import { mountMenu } from "./navigation.js";
|
||||||
|
|
||||||
|
const featuredCharacters = [
|
||||||
|
{ id: "mengsan_liubei_shuying", name: "刘备", faction: "han", factionName: "汉", file: "liubei-portrait.jpg" },
|
||||||
|
{ id: "mengsan_caocao_shuying", name: "曹操", faction: "wei", factionName: "魏", file: "caocao-portrait.jpg" },
|
||||||
|
{ id: "mengsan_sunquan_shuying", name: "孙权", faction: "wu", factionName: "吴", file: "sunquan-portrait.jpg" },
|
||||||
|
];
|
||||||
|
|
||||||
|
function element(tag, className, text = "") {
|
||||||
|
const node = document.createElement(tag);
|
||||||
|
node.className = className;
|
||||||
|
if (text) node.textContent = text;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function chooseCharacterCards(playable, assetBase, backLabel) {
|
||||||
|
const available = new Map(playable.map(character => [character.id, character]));
|
||||||
|
const featuredIds = new Set(featuredCharacters.map(character => character.id));
|
||||||
|
const roster = featuredCharacters.map(character => {
|
||||||
|
const registered = available.get(character.id);
|
||||||
|
return {
|
||||||
|
...character,
|
||||||
|
name: registered?.name || character.name,
|
||||||
|
portrait: registered?.portrait || `${assetBase}/assets/portraits/${character.file}`,
|
||||||
|
description: registered?.description,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
roster.push(...playable.filter(character => !featuredIds.has(character.id)));
|
||||||
|
const title = "选择出征武将";
|
||||||
|
|
||||||
|
return chooseFlow(title, (overlay, finish) => {
|
||||||
|
overlay.classList.add("mengsan-character-overlay-shuying");
|
||||||
|
const panel = element("section", "mengsan-panel-shuying mengsan-character-panel-shuying");
|
||||||
|
const header = element("header", "ms-character-header");
|
||||||
|
const heading = element("div", "ms-character-heading");
|
||||||
|
heading.append(
|
||||||
|
element("p", "ms-character-eyebrow", "梦三 · 出征准备"),
|
||||||
|
element("h1", "ms-character-title", title),
|
||||||
|
);
|
||||||
|
const back = element("button", "ms-character-button", backLabel);
|
||||||
|
back.type = "button";
|
||||||
|
back.addEventListener("click", () => finish("back"));
|
||||||
|
header.append(heading, back);
|
||||||
|
|
||||||
|
const list = element("section", "ms-character-list");
|
||||||
|
list.setAttribute("aria-label", "武将");
|
||||||
|
const footer = element("footer", "ms-character-footer");
|
||||||
|
const status = element("p", "ms-character-status");
|
||||||
|
status.setAttribute("role", "status");
|
||||||
|
const confirm = element("button", "ms-character-button ms-character-confirm", "确认出征");
|
||||||
|
confirm.type = "button";
|
||||||
|
footer.append(status, confirm);
|
||||||
|
panel.append(header, list, footer);
|
||||||
|
overlay.appendChild(panel);
|
||||||
|
|
||||||
|
let selected = roster.find(character => available.has(character.id)) || roster[0];
|
||||||
|
const cards = roster.map(character => {
|
||||||
|
const button = element("button", "ms-character-card");
|
||||||
|
button.type = "button";
|
||||||
|
button.dataset.faction = character.faction;
|
||||||
|
if (character.portrait) {
|
||||||
|
const portrait = element("img", "ms-character-portrait");
|
||||||
|
portrait.alt = "";
|
||||||
|
portrait.draggable = false;
|
||||||
|
portrait.src = character.portrait;
|
||||||
|
button.appendChild(portrait);
|
||||||
|
}
|
||||||
|
const seal = element("span", "ms-character-faction", character.factionName);
|
||||||
|
const mark = element("span", "ms-character-picked", "已选");
|
||||||
|
mark.setAttribute("aria-hidden", "true");
|
||||||
|
const caption = element("span", "ms-character-caption");
|
||||||
|
caption.append(
|
||||||
|
element("strong", "ms-character-name", character.name),
|
||||||
|
element("span", "ms-character-description", available.has(character.id) ? character.description : "玩法待定"),
|
||||||
|
);
|
||||||
|
button.append(seal, mark, caption);
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
selected = character;
|
||||||
|
updateSelection();
|
||||||
|
});
|
||||||
|
list.appendChild(button);
|
||||||
|
return { character, button, mark };
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateSelection() {
|
||||||
|
for (const { character, button, mark } of cards) {
|
||||||
|
const isSelected = character === selected;
|
||||||
|
button.setAttribute("aria-pressed", String(isSelected));
|
||||||
|
mark.hidden = !isSelected;
|
||||||
|
}
|
||||||
|
const canDepart = available.has(selected.id);
|
||||||
|
confirm.disabled = !canDepart;
|
||||||
|
confirm.textContent = canDepart ? "确认出征" : "玩法待定";
|
||||||
|
status.textContent = `${canDepart ? "已选" : "正在查看"}${selected.name} · ${selected.factionName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm.addEventListener("click", () => {
|
||||||
|
if (available.has(selected.id)) finish(selected.id);
|
||||||
|
});
|
||||||
|
updateSelection();
|
||||||
|
mountMenu(overlay);
|
||||||
|
return cards.find(({ character }) => character === selected).button;
|
||||||
|
}, { back: "back" });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user