Payout button disabled until croupier has been set

Fixed potential segfault on startup if focusedPlayer_ is out of bounds.
This commit is contained in:
greek 2024-06-08 12:55:29 +01:00
parent 256d3740f9
commit fd7a8fbd8a
2 changed files with 49 additions and 8 deletions

View file

@ -8,6 +8,7 @@ PlayerAreaModel::PlayerAreaModel(QObject *parent)
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
players.append(defaultValues); players.append(defaultValues);
} }
focusedPlayer_ = 1;
} }
uint PlayerAreaModel::focusedPlayer() uint PlayerAreaModel::focusedPlayer()
@ -85,7 +86,7 @@ void PlayerAreaModel::cancelBet(BetType b, int n)
void PlayerAreaModel::payout() void PlayerAreaModel::payout()
{ {
if (players.at(0).bet1.betType == NONE) { if (players.at(0).bet1.betType == NONE) {
printf("Select where the ball landed\n"); fprintf(stderr, "Select where the ball landed\n");
} else { } else {
int rollSpot = 36 - players.at(0).bet1.betSpot; int rollSpot = 36 - players.at(0).bet1.betSpot;

View file

@ -35,10 +35,9 @@ Window {
Button { Button {
id: payoutButton id: payoutButton
text: "Payout"
font.pointSize: 15
highlighted: false highlighted: false
onClicked: PlayerAreaModel.payout() onClicked: PlayerAreaModel.payout()
enabled: false
anchors { anchors {
left: roulette.left left: roulette.left
@ -46,21 +45,62 @@ Window {
bottomMargin: 20 bottomMargin: 20
} }
contentItem: Text {
text: "Payout"
font.pointSize: 15
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: {
if (enabled == true) {
"#000000"
} else {
"#555555"
}
}
}
background: Rectangle { background: Rectangle {
implicitWidth: 150 implicitWidth: 150
implicitHeight: 60 implicitHeight: 60
opacity: { opacity: {
if (enabled == true) {
if (parent.pressed) { if (parent.pressed) {
1 0.5
} else if (parent.hovered) { } else if (parent.hovered) {
0.2 0.2
} else { } else {
0.3 0.3
} }
} else {
0.3
}
}
color: {
if (enabled == true) {
"#AAAAAA"
} else {
"#444444"
}
} }
color: "#CCCCCC"
border.width: 0 border.width: 0
} }
Connections {
target: PlayerAreaModel
function onBetChanged() {
if (PlayerAreaModel.focusedPlayer == 0) {
payoutButton.enabled = true;
}
}
function onBetRemoved() {
if (PlayerAreaModel.focusedPlayer == 0) {
payoutButton.enabled = false;
}
}
}
} }
Results { Results {