2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
2023-06-23 14:18:11 +00:00
|
|
|
import QtQuick.Layouts
|
2022-09-14 05:01:10 +00:00
|
|
|
import Qt5Compat.GraphicalEffects
|
2023-05-19 02:08:36 +00:00
|
|
|
import Fk
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
/* Layout of card:
|
|
|
|
* +--------+
|
|
|
|
* num -|5 |
|
|
|
|
* suit-|s |
|
|
|
|
* | img |
|
|
|
|
* | |
|
|
|
|
* |footnote|
|
|
|
|
* +--------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
|
|
|
width: 93
|
|
|
|
height: 130
|
|
|
|
|
|
|
|
// properties for the view
|
|
|
|
property string suit: "club"
|
|
|
|
property int number: 7
|
|
|
|
property string name: "slash"
|
2023-02-15 11:54:35 +00:00
|
|
|
property string extension: ""
|
|
|
|
property string virt_name: ""
|
2023-07-02 12:39:42 +00:00
|
|
|
property int type: 0
|
2022-04-30 07:27:56 +00:00
|
|
|
property string subtype: ""
|
|
|
|
property string color: "" // only use when suit is empty
|
|
|
|
property string footnote: "" // footnote, e.g. "A use card to B"
|
2023-01-29 10:11:41 +00:00
|
|
|
property bool footnoteVisible: false
|
2023-09-19 06:27:54 +00:00
|
|
|
property string prohibitReason: ""
|
2022-04-30 07:27:56 +00:00
|
|
|
property bool known: true // if false it only show a card back
|
|
|
|
property bool enabled: true // if false the card will be grey
|
|
|
|
property alias card: cardItem
|
|
|
|
property alias glow: glowItem
|
2023-06-23 14:18:11 +00:00
|
|
|
property var mark: ({})
|
2023-09-19 06:27:54 +00:00
|
|
|
property alias chosenInBox: chosen.visible
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
function getColor() {
|
|
|
|
if (suit != "")
|
|
|
|
return (suit == "heart" || suit == "diamond") ? "red" : "black";
|
|
|
|
else return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
// properties for animation and game system
|
|
|
|
property int cid: 0
|
|
|
|
property bool selectable: true
|
|
|
|
property bool selected: false
|
|
|
|
property bool draggable: false
|
|
|
|
property bool autoBack: true
|
2023-05-18 23:45:21 +00:00
|
|
|
property bool showDetail: false
|
2022-04-30 07:27:56 +00:00
|
|
|
property int origX: 0
|
|
|
|
property int origY: 0
|
2023-07-02 12:39:42 +00:00
|
|
|
property int initialZ: 0
|
|
|
|
property int maxZ: 0
|
2022-04-30 07:27:56 +00:00
|
|
|
property real origOpacity: 1
|
2023-03-18 07:34:42 +00:00
|
|
|
// property bool isClicked: false
|
2022-04-30 07:27:56 +00:00
|
|
|
property bool moveAborted: false
|
|
|
|
property alias goBackAnim: goBackAnimation
|
|
|
|
property int goBackDuration: 500
|
2023-01-29 10:11:41 +00:00
|
|
|
property bool busy: false // whether there is a running emotion on the card
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
|
|
signal toggleDiscards()
|
|
|
|
signal clicked()
|
2023-02-15 11:54:35 +00:00
|
|
|
signal rightClicked()
|
2022-04-30 07:27:56 +00:00
|
|
|
signal doubleClicked()
|
|
|
|
signal thrown()
|
|
|
|
signal released()
|
|
|
|
signal entered()
|
|
|
|
signal exited()
|
|
|
|
signal moveFinished()
|
|
|
|
signal generalChanged() // For choose general freely
|
|
|
|
signal hoverChanged(bool enter)
|
|
|
|
|
2023-05-18 23:45:21 +00:00
|
|
|
onRightClicked: {
|
|
|
|
if (!showDetail) return;
|
2023-05-19 02:08:36 +00:00
|
|
|
roomScene.startCheat("CardDetail", { card: this });
|
2023-05-18 23:45:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
RectangularGlow {
|
|
|
|
id: glowItem
|
|
|
|
anchors.fill: parent
|
|
|
|
glowRadius: 8
|
|
|
|
spread: 0
|
|
|
|
color: "#88FFFFFF"
|
|
|
|
cornerRadius: 8
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Image {
|
|
|
|
id: cardItem
|
2023-05-20 08:00:03 +00:00
|
|
|
source: known ? SkinBank.getCardPicture(cid || name)
|
2022-04-30 07:27:56 +00:00
|
|
|
: (SkinBank.CARD_DIR + "card-back")
|
|
|
|
anchors.fill: parent
|
|
|
|
fillMode: Image.PreserveAspectCrop
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: suitItem
|
|
|
|
visible: known
|
2024-01-24 19:23:29 +00:00
|
|
|
source: (suit !== "" && suit !== "nosuit") ? SkinBank.CARD_SUIT_DIR + suit
|
|
|
|
: ""
|
2022-04-30 07:27:56 +00:00
|
|
|
x: 3
|
|
|
|
y: 19
|
|
|
|
width: 21
|
|
|
|
height: 17
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: numberItem
|
|
|
|
visible: known
|
|
|
|
source: (suit != "" && number > 0) ? SkinBank.CARD_DIR
|
|
|
|
+ "number/" + root.getColor() + "/" + number : ""
|
|
|
|
x: 0
|
|
|
|
y: 0
|
|
|
|
width: 27
|
|
|
|
height: 28
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: colorItem
|
2024-01-24 19:23:29 +00:00
|
|
|
visible: known && (suit === "" || suit === "nosuit")
|
|
|
|
// && number <= 0 // <- FIXME: 需要区分“黑色有点数”和“无色有点数”
|
|
|
|
source: (visible && color !== "") ? SkinBank.CARD_SUIT_DIR + "/" + color
|
|
|
|
: ""
|
2022-04-30 07:27:56 +00:00
|
|
|
x: 1
|
|
|
|
}
|
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
Rectangle {
|
2023-06-09 18:18:51 +00:00
|
|
|
id: virt_rect
|
2023-12-10 10:56:50 +00:00
|
|
|
visible: root.virt_name !== "" && root.virt_name !== root.name
|
2023-02-15 11:54:35 +00:00
|
|
|
width: parent.width
|
2023-06-09 18:18:51 +00:00
|
|
|
height: 20
|
|
|
|
y: 40
|
|
|
|
color: "snow"
|
|
|
|
opacity: 0.8
|
|
|
|
radius: 4
|
|
|
|
border.color: "black"
|
|
|
|
border.width: 1
|
2023-02-15 11:54:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 18:18:51 +00:00
|
|
|
Text {
|
|
|
|
visible: virt_rect.visible
|
|
|
|
anchors.centerIn: virt_rect
|
|
|
|
font.pixelSize: 16
|
|
|
|
font.family: fontLibian.name
|
|
|
|
font.letterSpacing: -0.6
|
2024-01-24 19:23:29 +00:00
|
|
|
text: luatr(root.virt_name)
|
2023-06-09 18:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
2022-04-30 07:27:56 +00:00
|
|
|
id: footnoteItem
|
|
|
|
text: footnote
|
2023-06-09 18:18:51 +00:00
|
|
|
x: 0
|
|
|
|
y: parent.height - height - 10
|
2022-04-30 07:27:56 +00:00
|
|
|
width: root.width - x * 2
|
|
|
|
color: "#E4D5A0"
|
2023-06-09 18:18:51 +00:00
|
|
|
// color: "white"
|
2022-04-30 07:27:56 +00:00
|
|
|
visible: footnoteVisible
|
2023-06-09 18:18:51 +00:00
|
|
|
style: Text.Outline
|
2022-04-30 07:27:56 +00:00
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2022-05-01 10:37:13 +00:00
|
|
|
font.family: fontLibian.name
|
2022-04-30 07:27:56 +00:00
|
|
|
font.pixelSize: 14
|
2023-06-09 18:18:51 +00:00
|
|
|
// glow.color: "black"
|
|
|
|
// glow.spread: 1
|
|
|
|
// glow.radius: 1
|
2022-09-14 05:01:10 +00:00
|
|
|
//glow.samples: 12
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 14:18:11 +00:00
|
|
|
Component {
|
|
|
|
id: cardMarkDelegate
|
|
|
|
Item {
|
|
|
|
width: root.width / 2
|
|
|
|
height: 16
|
|
|
|
Rectangle {
|
|
|
|
id: mark_rect
|
|
|
|
width: mark_text.width + 12
|
|
|
|
height: 16
|
|
|
|
// color: "#A50330"
|
|
|
|
radius: 4
|
|
|
|
// border.color: "snow"
|
|
|
|
// border.width: 1
|
|
|
|
gradient: Gradient {
|
|
|
|
orientation: Gradient.Horizontal
|
|
|
|
GradientStop { position: 0.7; color: "#A50330" }
|
|
|
|
GradientStop { position: 1.0; color: "transparent" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: mark_text
|
|
|
|
x: 2
|
|
|
|
font.pixelSize: 16
|
|
|
|
font.family: fontLibian.name
|
|
|
|
font.letterSpacing: -0.6
|
|
|
|
text: {
|
2024-01-24 19:23:29 +00:00
|
|
|
let ret = luatr(modelData.k);
|
2023-06-23 14:18:11 +00:00
|
|
|
if (!modelData.k.startsWith("@@")) {
|
|
|
|
ret += modelData.v.toString();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
color: "white"
|
|
|
|
style: Text.Outline
|
|
|
|
styleColor: "purple"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
width: root.width
|
|
|
|
y: 60
|
|
|
|
columns: 2
|
|
|
|
rowSpacing: 1
|
|
|
|
columnSpacing: 0
|
|
|
|
Repeater {
|
|
|
|
model: mark
|
|
|
|
delegate: cardMarkDelegate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
Image {
|
|
|
|
id: chosen
|
|
|
|
visible: false
|
|
|
|
source: SkinBank.CARD_DIR + "chosen"
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
y: 90
|
|
|
|
scale: 1.25
|
2023-12-28 04:11:24 +00:00
|
|
|
z: 1
|
2023-09-19 06:27:54 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Rectangle {
|
|
|
|
visible: !root.selectable
|
|
|
|
anchors.fill: parent
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.5)
|
|
|
|
opacity: 0.7
|
2023-12-28 04:11:24 +00:00
|
|
|
z: 2
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
Text {
|
|
|
|
id: prohibitText
|
|
|
|
visible: !root.selectable
|
|
|
|
anchors.centerIn: parent
|
|
|
|
font.family: fontLibian.name
|
|
|
|
font.pixelSize: 18
|
|
|
|
opacity: 0.9
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
lineHeight: 18
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
color: "snow"
|
|
|
|
width: 20
|
|
|
|
wrapMode: Text.WrapAnywhere
|
|
|
|
style: Text.Outline
|
|
|
|
styleColor: "red"
|
|
|
|
text: prohibitReason
|
|
|
|
}
|
|
|
|
|
2023-03-18 07:34:42 +00:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.NoButton
|
2023-03-18 15:37:21 +00:00
|
|
|
gesturePolicy: TapHandler.WithinBounds
|
2023-03-18 07:34:42 +00:00
|
|
|
|
|
|
|
onTapped: (p, btn) => {
|
|
|
|
if (btn === Qt.LeftButton || btn === Qt.NoButton) {
|
|
|
|
selected = selectable ? !selected : false;
|
|
|
|
parent.clicked();
|
|
|
|
} else if (btn === Qt.RightButton) {
|
|
|
|
parent.rightClicked();
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
2023-03-18 07:34:42 +00:00
|
|
|
onLongPressed: {
|
|
|
|
parent.rightClicked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DragHandler {
|
|
|
|
enabled: draggable
|
2023-04-09 03:44:19 +00:00
|
|
|
grabPermissions: PointHandler.TakeOverForbidden
|
2023-03-18 07:34:42 +00:00
|
|
|
xAxis.enabled: true
|
|
|
|
yAxis.enabled: true
|
|
|
|
|
|
|
|
onGrabChanged: (transtition, point) => {
|
|
|
|
if (transtition !== PointerDevice.UngrabExclusive) return;
|
2022-04-30 07:27:56 +00:00
|
|
|
parent.released();
|
|
|
|
if (autoBack)
|
|
|
|
goBackAnimation.start();
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2023-03-18 07:34:42 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-03-18 07:34:42 +00:00
|
|
|
HoverHandler {
|
|
|
|
id: hover
|
|
|
|
onHoveredChanged: {
|
|
|
|
if (!draggable) return;
|
|
|
|
if (hovered) {
|
2022-04-30 07:27:56 +00:00
|
|
|
glow.visible = true;
|
2023-07-02 12:39:42 +00:00
|
|
|
|
|
|
|
root.z = root.maxZ ? root.maxZ + 1 : root.z + 1;
|
2023-03-18 07:34:42 +00:00
|
|
|
} else {
|
2022-04-30 07:27:56 +00:00
|
|
|
glow.visible = false;
|
2023-07-02 12:39:42 +00:00
|
|
|
|
|
|
|
root.z = root.initialZ ? root.initialZ : root.z - 1
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
ParallelAnimation {
|
|
|
|
id: goBackAnimation
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
PropertyAnimation {
|
|
|
|
target: root
|
|
|
|
property: "x"
|
|
|
|
to: origX
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: goBackDuration
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
PropertyAnimation {
|
|
|
|
target: root
|
|
|
|
property: "y"
|
|
|
|
to: origY
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: goBackDuration
|
2022-03-30 06:14:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAnimation {
|
|
|
|
target: root
|
|
|
|
property: "opacity"
|
|
|
|
to: 1
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: goBackDuration * 0.8
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyAnimation {
|
|
|
|
target: root
|
|
|
|
property: "opacity"
|
|
|
|
to: origOpacity
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: goBackDuration * 0.2
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
onStopped: {
|
|
|
|
if (!moveAborted)
|
|
|
|
root.moveFinished();
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setData(data)
|
|
|
|
{
|
|
|
|
cid = data.cid;
|
|
|
|
name = data.name;
|
|
|
|
suit = data.suit;
|
|
|
|
number = data.number;
|
|
|
|
color = data.color;
|
2023-07-02 12:39:42 +00:00
|
|
|
type = data.type ? data.type : 0
|
2023-02-15 13:20:40 +00:00
|
|
|
subtype = data.subtype ? data.subtype : "";
|
|
|
|
virt_name = data.virt_name ? data.virt_name : "";
|
2023-06-23 14:18:11 +00:00
|
|
|
mark = data.mark ?? {};
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toData()
|
|
|
|
{
|
2023-06-09 09:23:02 +00:00
|
|
|
const data = {
|
2022-04-30 07:27:56 +00:00
|
|
|
cid: cid,
|
|
|
|
name: name,
|
|
|
|
suit: suit,
|
|
|
|
number: number,
|
2023-02-15 13:20:40 +00:00
|
|
|
color: color,
|
2023-07-02 12:39:42 +00:00
|
|
|
type: type,
|
2023-02-15 13:20:40 +00:00
|
|
|
subtype: subtype,
|
|
|
|
virt_name: virt_name,
|
2023-06-23 14:18:11 +00:00
|
|
|
mark: mark,
|
2022-04-30 07:27:56 +00:00
|
|
|
};
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function goBack(animated)
|
|
|
|
{
|
|
|
|
if (animated) {
|
|
|
|
moveAborted = true;
|
|
|
|
goBackAnimation.stop();
|
|
|
|
moveAborted = false;
|
|
|
|
goBackAnimation.start();
|
|
|
|
} else {
|
|
|
|
x = origX;
|
|
|
|
y = origY;
|
|
|
|
opacity = origOpacity;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function destroyOnStop()
|
|
|
|
{
|
|
|
|
root.moveFinished.connect(function(){
|
|
|
|
root.destroy();
|
|
|
|
});
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|