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

View file

@ -35,10 +35,9 @@ Window {
Button {
id: payoutButton
text: "Payout"
font.pointSize: 15
highlighted: false
onClicked: PlayerAreaModel.payout()
enabled: false
anchors {
left: roulette.left
@ -46,21 +45,62 @@ Window {
bottomMargin: 20
}
contentItem: Text {
text: "Payout"
font.pointSize: 15
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: {
if (enabled == true) {
"#000000"
} else {
"#555555"
}
}
}
background: Rectangle {
implicitWidth: 150
implicitHeight: 60
opacity: {
if (parent.pressed) {
1
} else if (parent.hovered) {
0.2
if (enabled == true) {
if (parent.pressed) {
0.5
} else if (parent.hovered) {
0.2
} else {
0.3
}
} else {
0.3
}
}
color: "#CCCCCC"
color: {
if (enabled == true) {
"#AAAAAA"
} else {
"#444444"
}
}
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 {