UI enhancements

This commit is contained in:
Daniil Vinogradov 2025-02-16 13:16:39 +01:00
parent 757fb1f6d1
commit df2b17ddd6
2 changed files with 112 additions and 120 deletions

View File

@ -48,15 +48,7 @@ struct GameLibraryView: View {
var body: some View {
iOSNav {
ScrollView {
LazyVStack(alignment: .leading, spacing: 20) {
if !isSearching {
Text("Games")
.font(.system(size: 34, weight: .bold))
.padding(.horizontal)
.padding(.top, 12)
}
List {
if Ryujinx.shared.games.isEmpty {
VStack(spacing: 16) {
Image(systemName: "gamecontroller.fill")
@ -108,7 +100,6 @@ struct GameLibraryView: View {
}
}
} else {
LazyVStack(spacing: 2) {
ForEach(filteredGames) { game in
GameListRow(game: game, startemu: $startemu, games: games, isViewingGameInfo: $isViewingGameInfo, isSelectingGameUpdate: $isSelectingGameUpdate, gameInfo: $gameInfo)
.onTapGesture {
@ -118,7 +109,8 @@ struct GameLibraryView: View {
}
}
}
}
.navigationTitle("Games")
.navigationBarTitleDisplayMode(.large)
.onAppear {
loadRecentGames()
@ -143,9 +135,8 @@ struct GameLibraryView: View {
print(error)
}
}
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
ToolbarItem(placement: .topBarTrailing) {
Button {
isSelectingGameFile.toggle()
} label: {
@ -215,7 +206,6 @@ struct GameLibraryView: View {
}
}
}
.background(Color(.systemGroupedBackground))
.searchable(text: $searchText)
.onChange(of: searchText) { _ in
isSearching = !searchText.isEmpty
@ -296,7 +286,6 @@ struct GameLibraryView: View {
}
}
private func addToRecentGames(_ game: Game) {
recentGames.removeAll { $0.id == game.id }
@ -329,8 +318,7 @@ struct GameLibraryView: View {
}
}
// MARK: - Delete Game Function
// MARK: - Delete Game Function
func deleteGame(game: Game) {
let fileManager = FileManager.default
do {
@ -343,7 +331,7 @@ struct GameLibraryView: View {
}
}
// MARK: -Game Model
// MARK: - Game Model
extension Game: Codable {
enum CodingKeys: String, CodingKey {
case titleName, titleId, developer, version, fileURL
@ -372,7 +360,7 @@ extension Game: Codable {
}
}
// MARK: -Recent Game Card
// MARK: - Recent Game Card
struct RecentGameCard: View {
let game: Game
@Binding var startemu: Game?
@ -419,7 +407,7 @@ struct RecentGameCard: View {
}
}
// MARK: -Game List Item
// MARK: - Game List Item
struct GameListRow: View {
let game: Game
@Binding var startemu: Game?
@ -474,9 +462,6 @@ struct GameListRow: View {
.foregroundColor(.accentColor)
.opacity(0.8)
}
.padding(.horizontal)
.padding(.vertical, 8)
.background(Color(.systemBackground))
.contextMenu {
Section {
Button {
@ -533,4 +518,3 @@ struct GameListRow: View {
}
}
}

View File

@ -18,16 +18,22 @@ struct UpdateManagerSheet: View {
var body: some View {
NavigationView {
VStack {
List(paths, id: \..self) { item in
List(paths, id: \..self, selection: $selectedItem) { item in
Button(action: {
selectItem(item.lastPathComponent)
}) {
HStack {
Text(item.lastPathComponent)
if selectedItem == "\(game!.titleId)/\(item.lastPathComponent)" {
.foregroundStyle(Color(uiColor: .label))
Spacer()
Image(systemName: "checkmark")
if selectedItem == "\(game!.titleId)/\(item.lastPathComponent)" {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(Color.accentColor)
.font(.system(size: 24))
} else {
Image(systemName: "circle")
.foregroundStyle(Color(uiColor: .secondaryLabel))
.font(.system(size: 24))
}
}
}
@ -39,15 +45,15 @@ struct UpdateManagerSheet: View {
}
}
}
}
.onAppear() {
.onAppear {
print(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
loadJSON(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
}
.navigationTitle("\(game!.titleName) Updates")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Button("+") {
Button("Add", systemImage: "plus") {
isSelectingGameUpdate = true
}
}
@ -80,7 +86,8 @@ struct UpdateManagerSheet: View {
let destinationURL = romUpdatedDirectory.appendingPathComponent(url.lastPathComponent)
try? fileManager.copyItem(at: url, to: destinationURL)
Ryujinx.shared.setTitleUpdate(titleId: gameInfo.titleId, updatePath: "\(gameInfo.titleId)/" + url.lastPathComponent)
items.append(gameInfo.titleId + "/" + url.lastPathComponent)
selectItem(url.lastPathComponent)
Ryujinx.shared.games = Ryujinx.shared.loadGames()
loadJSON(jsonURL!)
} catch {
@ -108,6 +115,7 @@ struct UpdateManagerSheet: View {
}
saveJSON(selectedItem: selectedItem ?? "")
Ryujinx.shared.games = Ryujinx.shared.loadGames()
}
func saveJSON(selectedItem: String) {
@ -122,7 +130,6 @@ struct UpdateManagerSheet: View {
}
func loadJSON(_ json: URL) {
self.jsonURL = json
print("Failed to read JSO")
@ -132,16 +139,17 @@ struct UpdateManagerSheet: View {
do {
let data = try Data(contentsOf: jsonURL)
if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let list = jsonDict["paths"] as? [String] {
let list = jsonDict["paths"] as? [String]
{
var urls: [URL] = []
for path in list {
urls.append(URL.documentsDirectory.appendingPathComponent("updates").appendingPathComponent(path))
}
self.items = list
self.paths = urls
self.selectedItem = jsonDict["selected"] as? String
items = list
paths = urls
selectedItem = jsonDict["selected"] as? String
}
} catch {
print("Failed to read JSON: \(error)")
@ -155,8 +163,8 @@ struct UpdateManagerSheet: View {
do {
let newData = try JSONSerialization.data(withJSONObject: defaultData, options: .prettyPrinted)
try newData.write(to: jsonURL)
self.items = []
self.selectedItem = ""
items = []
selectedItem = ""
} catch {
print("Failed to create default JSON: \(error)")
}
@ -183,9 +191,9 @@ struct UpdateManagerSheet: View {
let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
try newData.write(to: jsonURL)
Ryujinx.shared.games = Ryujinx.shared.loadGames()
} catch {
print("Failed to update JSON: \(error)")
}
}
}