roulette-payout/PlayerAreaView.qml

212 lines
6.4 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import roulette
Item {
anchors {
left: parent.left
leftMargin: 10
}
2024-06-01 14:46:10 +01:00
Text {
id: croupier
2024-06-07 10:06:28 +01:00
font.pointSize: 18
2024-06-01 14:46:10 +01:00
text: "Croupier"
2024-06-07 10:06:28 +01:00
color: {
if (tapHandler.pressed) {
"#99000000"
} else {
"#000000"
}
}
TapHandler {
id: tapHandler
onSingleTapped: {
PlayerAreaModel.focusedPlayer = 0
}
}
Rectangle {
id: indicator
color: "red"
height: 10
width: 10
opacity: 0.5
visible: PlayerAreaModel.focusedPlayer == 0
anchors {
verticalCenter: parent.verticalCenter
right: parent.left
rightMargin: 5
}
}
Text {
id: roll
anchors {
top: parent.top
topMargin: 8
left: parent.right
leftMargin: 5
}
}
Connections {
target: PlayerAreaModel
function onBetChanged(b, n, bet) {
if (PlayerAreaModel.focusedPlayer == 0) {
const betTypes = ["NONE", "Red", "Black", "Odd", "Even", "Low", "High",
"Dozen", "Street", "Single", "Column", "Split"]
if (b < 7) {
roll.text = betTypes[b]
} else {
roll.text = betTypes[b] + " " + (n + 1)
}
}
}
function onBetRemoved(b, n) {
if (PlayerAreaModel.focusedPlayer == 0) {
roll.text = ""
}
}
}
2024-06-01 14:46:10 +01:00
}
ColumnLayout {
2024-06-01 14:46:10 +01:00
anchors {
top: croupier.bottom
topMargin: 20
}
2024-06-01 14:46:10 +01:00
spacing: 60
/*
* A repeater can only have one delegate model
* i.e. it can only have one object template defined in it.
* To repeat both a Text, and Rectangle AND a TextField, we put them inside an Item
* and use anchors to sort them inside the Item
*/
2024-06-01 14:46:10 +01:00
Repeater {
model: 7
Item {
Text {
id: label
text: "Player " + (index + 1)
}
Rectangle {
id: indicator
color: "red"
height: 10
width: 10
/*
* This check will run once when the object is created, but then only refresh
* when the NOTIFY signal for .focusedPlayer is sent
*/
2024-06-07 10:06:28 +01:00
visible: PlayerAreaModel.focusedPlayer - 1 == index
opacity: 0.5
anchors {
verticalCenter: inputField.verticalCenter
right: inputField.left
rightMargin: 5
}
}
2024-06-01 14:46:10 +01:00
TextField {
id: inputField
anchors {
top: label.bottom
topMargin: 6
}
2024-06-01 14:46:10 +01:00
2024-06-08 00:41:25 +01:00
onTextEdited: PlayerAreaModel.setPlayerName(text, index + 1)
onActiveFocusChanged: {
/* focusReason 0, 1 and 2 are mouse, tab forward, and tab backward, respectively */
if (activeFocus && (focusReason == 0 || focusReason == 1 || focusReason == 2)) {
2024-06-07 10:06:28 +01:00
PlayerAreaModel.focusedPlayer = index + 1
}
}
2024-06-01 14:46:10 +01:00
}
Text {
property int betType
property int n
id: currentBet1
anchors {
verticalCenter: inputField.verticalCenter
left: inputField.right
leftMargin: 5
}
text: ""
}
Text {
property int betType
property int n
id: currentBet2
anchors {
verticalCenter: inputField.verticalCenter
left: currentBet1.right
leftMargin: 5
}
text: ""
}
Connections {
target: PlayerAreaModel
function onBetChanged(b, n, bet) {
2024-06-07 10:06:28 +01:00
if (PlayerAreaModel.focusedPlayer - 1 == index) {
const betTypes = ["NONE", "Red", "Black", "Odd", "Even", "Low", "High",
"Dozen", "Street", "Single", "Column", "Split"]
if (currentBet1.text == "") {
currentBet1.betType = b
currentBet1.n = n
if (b < 7) {
currentBet1.text = betTypes[b] + ": " + bet + "g"
} else {
currentBet1.text = betTypes[b] + " " + (n + 1) + ": " + bet + "g"
}
} else {
currentBet2.betType = b
currentBet2.n = n
if (b < 7) {
currentBet2.text = betTypes[b] + ": " + bet + "g"
} else {
currentBet2.text = betTypes[b] + " " + (n + 1) + ": " + bet + "g"
}
}
}
}
function onBetRemoved(b, n) {
2024-06-07 10:06:28 +01:00
if (PlayerAreaModel.focusedPlayer - 1 == index) {
if (currentBet1.betType == b && currentBet1.n == n) {
currentBet1.text = ""
} else if (currentBet2.betType == b && currentBet2.n == n) {
currentBet2.text = ""
}
}
}
}
2024-06-01 14:46:10 +01:00
}
}
}
}