fix multibuy!!! mminor ui fixes

This commit is contained in:
neon443
2024-12-29 13:13:45 +00:00
parent 7fc593f156
commit 7280d79cea
3 changed files with 40 additions and 56 deletions

View File

@@ -410,7 +410,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 18.0; IPHONEOS_DEPLOYMENT_TARGET = 18.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 15.1; MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.CookieSwifter; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.CookieSwifter;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -451,7 +451,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 18.0; IPHONEOS_DEPLOYMENT_TARGET = 18.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 15.1; MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.CookieSwifter; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.CookieSwifter;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -56,8 +56,8 @@
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@@ -17,13 +17,6 @@ struct ContentView: View {
var body: some View { var body: some View {
VStack { VStack {
HStack {
Text("Game Name")
.font(.caption)
.bold()
TextField("", text: $gameName)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
HStack { HStack {
Text("\(game.cookies)") Text("\(game.cookies)")
.font(.largeTitle) .font(.largeTitle)
@@ -47,7 +40,6 @@ struct ContentView: View {
ScrollView(.vertical) { ScrollView(.vertical) {
ItemsListView(game: game, buyQuantity: $buyQuantity) ItemsListView(game: game, buyQuantity: $buyQuantity)
} }
// Spacer()
} label: { } label: {
Image(systemName: "star.fill") Image(systemName: "star.fill")
Text("Items") Text("Items")
@@ -63,25 +55,20 @@ struct ContentView: View {
} }
Tab { Tab {
HStack { List {
VStack { Text("Game Name")
.font(.caption)
.bold()
TextField("", text: $gameName)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button("Save Game") { Button("Save Game") {
let saveDate = "Saved \(Date().formatted())" let saveDate = "Saved \(Date().formatted())"
game.saveGame(name: gameName+saveDate) game.saveGame(name: gameName+saveDate)
} }
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(10)
Button("Load Game") { Button("Load Game") {
showSavedGames = true showSavedGames = true
} }
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
.sheet(isPresented: $showSavedGames) { .sheet(isPresented: $showSavedGames) {
SavedGamesListView(game: game, selectedSave: $selectedSave) SavedGamesListView(game: game, selectedSave: $selectedSave)
} }
@@ -90,16 +77,7 @@ struct ContentView: View {
game.loadGame(named: saveName) game.loadGame(named: saveName)
} }
} }
Spacer()
VStack {
CookieTapView(game: game)
Text("CPS: \(game.cps)")
.font(.headline)
} }
}
} label: { } label: {
Image(systemName: "gear") Image(systemName: "gear")
Text("Settings") Text("Settings")
@@ -108,11 +86,12 @@ struct ContentView: View {
ScrollView(.vertical) { ScrollView(.vertical) {
AchievementsView(achievements: game.achievements) AchievementsView(achievements: game.achievements)
} }
} label: { } label: {
Image(systemName: "trophy.fill") Image(systemName: "trophy.fill")
.badge(game.achievements.count)
Text("hi") Text("hi")
} }
.badge(game.achievements.count)
} }
} }
} }
@@ -184,7 +163,7 @@ struct ItemsListView: View {
.padding(.horizontal, 5) .padding(.horizontal, 5)
VStack { VStack {
ForEach(game.items.indices, id: \.self) { index in ForEach(game.items.indices, id: \.self) { index in
ItemView(game: game, buyQuantity: buyQuantity, index: index) ItemView(game: game, buyQuantity: $buyQuantity, index: index)
} }
} }
} }
@@ -192,26 +171,30 @@ struct ItemsListView: View {
struct ItemView: View { struct ItemView: View {
@ObservedObject var game: CookieGame @ObservedObject var game: CookieGame
@State var buyQuantity: Int @Binding var buyQuantity: Int
@State var index: Int @State var index: Int
var body: some View { var body: some View {
let canBuy = !(game.cookies < game.totalCost(of: index, quantity: buyQuantity))
let thisItem = game.items[index]
HStack(spacing: 5) { HStack(spacing: 5) {
Button(action: { Button(action: {
game.buyItem(at: index, quantity: buyQuantity) game.buyItem(at: index, quantity: buyQuantity)
}) { }) {
HStack { HStack {
Text("\(game.items[index].count) x \(game.items[index].name)") Text("\(thisItem.count) x")
Text("\(thisItem.name)")
.bold() .bold()
Text("🍪\(thisItem.cps) per second")
Spacer() Spacer()
Text("🍪\(game.totalCost(of: index, quantity: buyQuantity))") Text("🍪\(game.totalCost(of: index, quantity: buyQuantity))")
.font(.caption2) .font(.caption)
} }
.padding(5) .padding(5)
.background(Color.blue.opacity(0.2)) .background(Color.blue.opacity(canBuy ? 0.5 : 0.2))
.cornerRadius(10) .cornerRadius(10)
} }
.disabled(game.cookies < game.totalCost(of: index, quantity: buyQuantity)) .disabled(!canBuy)
SellButton( SellButton(
game: game, game: game,
index: $index, index: $index,
@@ -227,15 +210,17 @@ struct SellButton: View {
@Binding var buyQuantity: Int @Binding var buyQuantity: Int
var body: some View { var body: some View {
let canSell = !(game.items[index].count < buyQuantity)
Button(action: { Button(action: {
game.sellItem(at: index, quantity: buyQuantity) game.sellItem(at: index, quantity: buyQuantity)
}) { }) {
Text("🍪\(game.totalCost(of: index, quantity: buyQuantity) / 2)") Text("🍪\(game.totalCost(of: index, quantity: buyQuantity) / 2)")
.padding(5) .padding(5)
.background(Color.red.opacity(0.2)) .background(Color.red.opacity(canSell ? 0.5 : 0.2))
.cornerRadius(10) .cornerRadius(10)
.font(.caption)
} }
.disabled(game.items[index].count < buyQuantity) .disabled(!canSell)
} }
} }
@@ -245,21 +230,20 @@ struct UpgradesListView: View {
var body: some View { var body: some View {
VStack(spacing: 10) { VStack(spacing: 10) {
Text("Upgrades")
.font(.footnote)
ForEach(game.upgrades.indices, id: \.self) { index in ForEach(game.upgrades.indices, id: \.self) { index in
let thisUpgrade = game.upgrades[index]
Button(action: { Button(action: {
game.purchaseUpgrade(at: index) game.purchaseUpgrade(at: index)
}) { }) {
HStack { HStack {
Text(game.upgrades[index].name) Text(thisUpgrade.name)
.bold() .bold()
Text(game.upgrades[index].description) Text(thisUpgrade.description)
Spacer() Spacer()
Text("🍪 \(game.upgrades[index].cost)") Text("🍪\(thisUpgrade.cost)")
} }
.padding(5) .padding(5)
.background(game.upgrades[index].isPurchased ? Color.green.opacity(0.2) : Color.gray.opacity(0.2)) .background(thisUpgrade.isPurchased ? Color.green.opacity(0.2) : Color.gray.opacity(0.2))
.cornerRadius(10) .cornerRadius(10)
} }
.disabled(game.cookies < game.upgrades[index].cost || game.upgrades[index].isPurchased) .disabled(game.cookies < game.upgrades[index].cost || game.upgrades[index].isPurchased)