Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2025-12-24 11:38:32 -06:00
parent 7234cd718a
commit 1dc64ebf69
6 changed files with 66 additions and 22 deletions

View File

@ -135,7 +135,6 @@ struct GameTableView: View {
balance: state.balance, balance: state.balance,
secondaryInfo: settings.showCardsRemaining ? "\(state.engine.shoe.cardsRemaining)" : nil, secondaryInfo: settings.showCardsRemaining ? "\(state.engine.shoe.cardsRemaining)" : nil,
secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil, secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil,
showReset: false,
onSettings: { showSettings = true }, onSettings: { showSettings = true },
onHelp: { showRules = true }, onHelp: { showRules = true },
onStats: { showStats = true } onStats: { showStats = true }
@ -256,7 +255,6 @@ struct GameTableView: View {
balance: state.balance, balance: state.balance,
secondaryInfo: settings.showCardsRemaining ? "\(state.engine.shoe.cardsRemaining)" : nil, secondaryInfo: settings.showCardsRemaining ? "\(state.engine.shoe.cardsRemaining)" : nil,
secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil, secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil,
showReset: false,
onSettings: { showSettings = true }, onSettings: { showSettings = true },
onHelp: { showRules = true }, onHelp: { showRules = true },
onStats: { showStats = true } onStats: { showStats = true }

View File

@ -97,7 +97,6 @@ struct GameTableView: View {
balance: state.balance, balance: state.balance,
secondaryInfo: settings.showCardsRemaining ? "\(state.engine.cardsRemaining)" : nil, secondaryInfo: settings.showCardsRemaining ? "\(state.engine.cardsRemaining)" : nil,
secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil, secondaryIcon: settings.showCardsRemaining ? "rectangle.portrait.on.rectangle.portrait.fill" : nil,
showReset: false,
onSettings: { showSettings = true }, onSettings: { showSettings = true },
onHelp: { showRules = true }, onHelp: { showRules = true },
onStats: { showStats = true } onStats: { showStats = true }

View File

@ -126,7 +126,26 @@ TopBarView(
balance: 10_500, balance: 10_500,
secondaryInfo: "411", secondaryInfo: "411",
secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill", secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill",
onReset: { resetGame() }, onSettings: { showSettings = true },
onHelp: { showRules = true },
onStats: { showStats = true }
)
```
**TopBarButton** - Add custom buttons to the toolbar.
```swift
// Add game-specific buttons at the front of the toolbar
TopBarView(
balance: 10_500,
leadingButtons: [
TopBarButton(icon: "arrow.counterclockwise", accessibilityLabel: "Reset Game") {
resetGame()
},
TopBarButton(icon: "creditcard", accessibilityLabel: "Buy Chips") {
showBuyChips = true
}
],
onSettings: { showSettings = true }, onSettings: { showSettings = true },
onHelp: { showRules = true }, onHelp: { showRules = true },
onStats: { showStats = true } onStats: { showStats = true }

View File

@ -1558,6 +1558,7 @@
} }
}, },
"Reset Game" : { "Reset Game" : {
"extractionState" : "stale",
"localizations" : { "localizations" : {
"en" : { "en" : {
"stringUnit" : { "stringUnit" : {

View File

@ -7,6 +7,31 @@
import SwiftUI import SwiftUI
/// A button configuration for the top bar toolbar.
public struct TopBarButton: Identifiable {
public let id = UUID()
/// The SF Symbol icon name.
public let icon: String
/// The accessibility label for VoiceOver.
public let accessibilityLabel: String
/// The action to perform when tapped.
public let action: () -> Void
/// Creates a toolbar button configuration.
/// - Parameters:
/// - icon: SF Symbol name for the button icon.
/// - accessibilityLabel: VoiceOver label for the button.
/// - action: Closure to execute when tapped.
public init(icon: String, accessibilityLabel: String, action: @escaping () -> Void) {
self.icon = icon
self.accessibilityLabel = accessibilityLabel
self.action = action
}
}
/// A top bar showing balance and customizable toolbar buttons. /// A top bar showing balance and customizable toolbar buttons.
public struct TopBarView: View { public struct TopBarView: View {
/// The current balance to display. /// The current balance to display.
@ -18,11 +43,8 @@ public struct TopBarView: View {
/// Icon for secondary info. /// Icon for secondary info.
public let secondaryIcon: String? public let secondaryIcon: String?
/// Whether to show the reset button. /// Custom buttons to display at the front of the toolbar (before stats/help/settings).
public let showReset: Bool public let leadingButtons: [TopBarButton]
/// Action when reset is tapped.
public let onReset: (() -> Void)?
/// Action when settings is tapped. /// Action when settings is tapped.
public let onSettings: (() -> Void)? public let onSettings: (() -> Void)?
@ -45,8 +67,7 @@ public struct TopBarView: View {
/// - balance: The current balance. /// - balance: The current balance.
/// - secondaryInfo: Optional secondary info text. /// - secondaryInfo: Optional secondary info text.
/// - secondaryIcon: Optional SF Symbol for secondary info. /// - secondaryIcon: Optional SF Symbol for secondary info.
/// - showReset: Whether to show reset button. /// - leadingButtons: Custom buttons to add at the front of the toolbar.
/// - onReset: Reset button action.
/// - onSettings: Settings button action. /// - onSettings: Settings button action.
/// - onHelp: Help button action. /// - onHelp: Help button action.
/// - onStats: Stats button action. /// - onStats: Stats button action.
@ -54,8 +75,7 @@ public struct TopBarView: View {
balance: Int, balance: Int,
secondaryInfo: String? = nil, secondaryInfo: String? = nil,
secondaryIcon: String? = nil, secondaryIcon: String? = nil,
showReset: Bool = true, leadingButtons: [TopBarButton] = [],
onReset: (() -> Void)? = nil,
onSettings: (() -> Void)? = nil, onSettings: (() -> Void)? = nil,
onHelp: (() -> Void)? = nil, onHelp: (() -> Void)? = nil,
onStats: (() -> Void)? = nil onStats: (() -> Void)? = nil
@ -63,8 +83,7 @@ public struct TopBarView: View {
self.balance = balance self.balance = balance
self.secondaryInfo = secondaryInfo self.secondaryInfo = secondaryInfo
self.secondaryIcon = secondaryIcon self.secondaryIcon = secondaryIcon
self.showReset = showReset self.leadingButtons = leadingButtons
self.onReset = onReset
self.onSettings = onSettings self.onSettings = onSettings
self.onHelp = onHelp self.onHelp = onHelp
self.onStats = onStats self.onStats = onStats
@ -105,6 +124,12 @@ public struct TopBarView: View {
// Toolbar buttons // Toolbar buttons
HStack(spacing: CasinoDesign.Spacing.medium) { HStack(spacing: CasinoDesign.Spacing.medium) {
// Custom leading buttons (game-specific)
ForEach(leadingButtons) { button in
ToolbarButton(icon: button.icon, action: button.action)
.accessibilityLabel(button.accessibilityLabel)
}
if let onStats = onStats { if let onStats = onStats {
ToolbarButton(icon: "chart.bar.fill", action: onStats) ToolbarButton(icon: "chart.bar.fill", action: onStats)
.accessibilityLabel(String(localized: "Statistics", bundle: .module)) .accessibilityLabel(String(localized: "Statistics", bundle: .module))
@ -119,11 +144,6 @@ public struct TopBarView: View {
ToolbarButton(icon: "gearshape.fill", action: onSettings) ToolbarButton(icon: "gearshape.fill", action: onSettings)
.accessibilityLabel(String(localized: "Settings", bundle: .module)) .accessibilityLabel(String(localized: "Settings", bundle: .module))
} }
if showReset, let onReset = onReset {
ToolbarButton(icon: "arrow.counterclockwise", action: onReset)
.accessibilityLabel(String(localized: "Reset Game", bundle: .module))
}
} }
} }
.padding(.horizontal, CasinoDesign.Spacing.large) .padding(.horizontal, CasinoDesign.Spacing.large)
@ -156,7 +176,9 @@ private struct ToolbarButton: View {
balance: 10_500, balance: 10_500,
secondaryInfo: "411", secondaryInfo: "411",
secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill", secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill",
onReset: {}, leadingButtons: [
TopBarButton(icon: "arrow.counterclockwise", accessibilityLabel: "Reset") {}
],
onSettings: {}, onSettings: {},
onHelp: {}, onHelp: {},
onStats: {} onStats: {}

View File

@ -75,7 +75,12 @@ struct GameTableView: View {
balance: state.balance, balance: state.balance,
secondaryInfo: "\(state.engine.shoe.cardsRemaining)", secondaryInfo: "\(state.engine.shoe.cardsRemaining)",
secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill", secondaryIcon: "rectangle.portrait.on.rectangle.portrait.fill",
onReset: { state.resetGame() }, leadingButtons: [
// Add game-specific buttons here (optional)
// TopBarButton(icon: "arrow.counterclockwise", accessibilityLabel: "Reset") {
// state.resetGame()
// }
],
onSettings: { showSettings = true }, onSettings: { showSettings = true },
onHelp: { showRules = true }, onHelp: { showRules = true },
onStats: { showStats = true } onStats: { showStats = true }