选择目标提示 (#366)

This commit is contained in:
Ho-spair 2024-09-19 00:00:58 +08:00 committed by GitHub
parent e8aacf1888
commit 7b66e304ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 88 additions and 11 deletions

View File

@ -619,11 +619,15 @@ function processPrompt(prompt) {
if (raw.match("%src")) if (raw.match("%src"))
raw = raw.replace(/%src/g, getPlayerStr(src)); raw = raw.replace(/%src/g, getPlayerStr(src));
if (raw.match("%dest")) if (raw.match("%dest"))
raw = raw.replace(/%dest/g, getPlayerStr(dest)); raw = raw.replace(/%dest/g, luatr(getPhoto(dest).general));
if (raw.match("%arg2"))
raw = raw.replace(/%arg2/g, luatr(data[4])); if (data.length > 3) {
if (raw.match("%arg")) for (let i = data.length - 1; i > 3; i--) {
raw = raw.replace(/%arg/g, luatr(data[3])); raw = raw.replace(new RegExp("%arg" + (i - 2), "g"), luatr(data[i]));
}
raw = raw.replace(new RegExp("%arg", "g"), luatr(data[3]));
}
return raw; return raw;
} }
@ -727,6 +731,15 @@ function enableTargets(card) {
const ret = lcall("CanUseCardToTarget", card, id, selected_targets, const ret = lcall("CanUseCardToTarget", card, id, selected_targets,
JSON.stringify(roomScene.extra_data)); JSON.stringify(roomScene.extra_data));
photo.selectable = ret; photo.selectable = ret;
let tipText = lcall("GetUseCardTargetTip", card, id, selected_targets,
ret, JSON.stringify(roomScene.extra_data));
if (tipText) {
photo.targetTip = tipText;
} else {
photo.targetTip = [];
}
if (roomScene.extra_data instanceof Object) { if (roomScene.extra_data instanceof Object) {
const must = roomScene.extra_data.must_targets; const must = roomScene.extra_data.must_targets;
const included = roomScene.extra_data.include_targets; const included = roomScene.extra_data.include_targets;
@ -771,6 +784,7 @@ function enableTargets(card) {
} }
} else { } else {
all_photos.forEach(photo => { all_photos.forEach(photo => {
photo.targetTip = [];
photo.state = "normal"; photo.state = "normal";
photo.selected = false; photo.selected = false;
}); });
@ -839,10 +853,19 @@ function updateSelectedTargets(playerid, selected) {
} }
all_photos.forEach(photo => { all_photos.forEach(photo => {
if (photo.selected) return;
const id = photo.playerid; const id = photo.playerid;
const ret = lcall("CanUseCardToTarget", card, id, selected_targets, const ret = lcall("CanUseCardToTarget", card, id, selected_targets,
JSON.stringify(roomScene.extra_data)); JSON.stringify(roomScene.extra_data));
let tipText = lcall("GetUseCardTargetTip", card, id, selected_targets,
ret, JSON.stringify(roomScene.extra_data));
if (tipText) {
photo.targetTip = tipText;
} else {
photo.targetTip = [];
}
if (photo.selected) return;
photo.selectable = ret; photo.selectable = ret;
if (roomScene.extra_data instanceof Object) { if (roomScene.extra_data instanceof Object) {
const must = roomScene.extra_data.must_targets; const must = roomScene.extra_data.must_targets;
@ -892,6 +915,7 @@ function updateSelectedTargets(playerid, selected) {
} }
} else { } else {
all_photos.forEach(photo => { all_photos.forEach(photo => {
photo.targetTip = [];
photo.state = "normal"; photo.state = "normal";
photo.selected = false; photo.selected = false;
}); });

View File

@ -58,6 +58,8 @@ Item {
property bool playing: false property bool playing: false
property bool surrendered: false property bool surrendered: false
property var targetTip: []
onPlayingChanged: { onPlayingChanged: {
if (playing) { if (playing) {
animPlaying.start(); animPlaying.start();
@ -749,6 +751,53 @@ Item {
} }
} }
RowLayout {
anchors.centerIn: parent
spacing: 5
Repeater {
model: root.targetTip
Item {
Layout.alignment: Qt.AlignHCenter
width: 30
GlowText {
anchors.centerIn: parent
visible: modelData.type === "normal"
text: Util.processPrompt(modelData.content)
font.family: fontLibian.name
color: "#F7F589"
font.pixelSize: 30
font.bold: true
glow.color: "black"
glow.spread: 0.3
glow.radius: 5
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WrapAnywhere
width: 30
}
Text {
anchors.centerIn: parent
visible: modelData.type === "warning"
font.family: fontLibian.name
font.pixelSize: 24
opacity: 0.9
horizontalAlignment: Text.AlignHCenter
lineHeight: 24
lineHeightMode: Text.FixedHeight
color: "#EAC28A"
width: 24
wrapMode: Text.WrapAnywhere
style: Text.Outline
styleColor: "#83231F"
text: Util.processPrompt(modelData.content)
}
}
}
}
onGeneralChanged: { onGeneralChanged: {
if (!roomScene.isStarted) return; if (!roomScene.isStarted) return;
const text = luatr(general); const text = luatr(general);

View File

@ -34,11 +34,15 @@ function processPrompt(prompt) {
if (raw.match("%src")) if (raw.match("%src"))
raw = raw.replace(/%src/g, getPlayerStr(src)); raw = raw.replace(/%src/g, getPlayerStr(src));
if (raw.match("%dest")) if (raw.match("%dest"))
raw = raw.replace(/%dest/g, getPlayerStr(dest)); raw = raw.replace(/%dest/g, luatr(getPhoto(dest).general));
if (raw.match("%arg2"))
raw = raw.replace(/%arg2/g, luatr(data[4])); if (data.length > 3) {
if (raw.match("%arg")) for (let i = 4; i < data.length; i++) {
raw = raw.replace(/%arg/g, luatr(data[3])); raw = raw.replace(new RegExp("%arg" + (i - 2), "g"), data[i]);
}
raw = raw.replace(new RegExp("%arg", "g"), data[3]);
}
return raw; return raw;
} }