2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-04-04 16:49:54 +00:00
|
|
|
import QtQuick
|
2023-05-19 02:08:36 +00:00
|
|
|
import Fk.Pages
|
2023-04-04 16:49:54 +00:00
|
|
|
|
|
|
|
MetroButton {
|
|
|
|
id: root
|
|
|
|
property string skill
|
|
|
|
property var choices: []
|
2023-07-16 07:29:20 +00:00
|
|
|
property var all_choices: []
|
2023-04-04 16:49:54 +00:00
|
|
|
property string default_choice
|
|
|
|
property string answer: default_choice
|
2023-06-15 13:19:57 +00:00
|
|
|
property bool detailed: false
|
2023-05-20 08:00:03 +00:00
|
|
|
|
|
|
|
function processPrompt(prompt) {
|
|
|
|
const data = prompt.split(":");
|
|
|
|
let raw = Backend.translate(data[0]);
|
|
|
|
const src = parseInt(data[1]);
|
|
|
|
const dest = parseInt(data[2]);
|
2023-07-11 15:16:46 +00:00
|
|
|
if (raw.match("%src")) raw = raw.replace(/%src/g, Backend.translate(getPhoto(src).general));
|
|
|
|
if (raw.match("%dest")) raw = raw.replace(/%dest/g, Backend.translate(getPhoto(dest).general));
|
|
|
|
if (raw.match("%arg2")) raw = raw.replace(/%arg2/g, Backend.translate(data[4]));
|
2023-07-14 14:17:54 +00:00
|
|
|
if (raw.match("%arg")) raw = raw.replace(/%arg/g, Backend.translate(data[3]));
|
2023-05-20 08:00:03 +00:00
|
|
|
return raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
text: processPrompt(answer)
|
2023-04-04 16:49:54 +00:00
|
|
|
|
|
|
|
onAnswerChanged: {
|
|
|
|
if (!answer) return;
|
|
|
|
Backend.callLuaFunction(
|
|
|
|
"SetInteractionDataOfSkill",
|
|
|
|
[skill, JSON.stringify(answer)]
|
|
|
|
);
|
|
|
|
roomScene.dashboard.startPending(skill);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
2023-06-15 13:19:57 +00:00
|
|
|
if (detailed) {
|
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/DetailedChoiceBox.qml");
|
|
|
|
} else {
|
|
|
|
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/ChoiceBox.qml");
|
|
|
|
}
|
2023-06-09 09:23:02 +00:00
|
|
|
const box = roomScene.popupBox.item;
|
2023-04-04 16:49:54 +00:00
|
|
|
box.options = choices;
|
2023-07-16 07:29:20 +00:00
|
|
|
box.all_options = all_choices;
|
2023-04-04 16:49:54 +00:00
|
|
|
box.accepted.connect(() => {
|
|
|
|
answer = choices[box.result];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|