From 1beb51cf05926ef594660a9f8f738a2247d7d09f Mon Sep 17 00:00:00 2001 From: psychehose Date: Sat, 10 Jun 2023 14:25:25 +0900 Subject: [PATCH] [#2] ADD: MonsterListItem View, MonsterListInformation View --- RunningRPG.xcodeproj/project.pbxproj | 22 ++++++- RunningRPG/Model/Monster.swift | 20 ++++++ .../MonsterList/Model/MonsterListItem.swift | 63 +++++++++++++++++++ .../Tabbar/MonsterList/MonsterListView.swift | 48 ++------------ .../Subviews/MonsterInformationView.swift | 26 ++++++++ .../Subviews/MonsterListItem.swift | 30 --------- .../Subviews/MonsterListItemView.swift | 22 +++++++ 7 files changed, 154 insertions(+), 77 deletions(-) create mode 100644 RunningRPG/Tabbar/MonsterList/Model/MonsterListItem.swift create mode 100644 RunningRPG/Tabbar/MonsterList/Subviews/MonsterInformationView.swift delete mode 100644 RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItem.swift create mode 100644 RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItemView.swift diff --git a/RunningRPG.xcodeproj/project.pbxproj b/RunningRPG.xcodeproj/project.pbxproj index ec34ce2..277b3ff 100644 --- a/RunningRPG.xcodeproj/project.pbxproj +++ b/RunningRPG.xcodeproj/project.pbxproj @@ -32,8 +32,10 @@ 770A00292A34221900160BD6 /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00282A34221900160BD6 /* Character.swift */; }; 770A002B2A34236700160BD6 /* Equiment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002A2A34236700160BD6 /* Equiment.swift */; }; 770A002D2A34240200160BD6 /* Monster.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002C2A34240200160BD6 /* Monster.swift */; }; - 7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF63E732A342F3A0051985C /* HomeBottomView.swift */; }; 770A00302A34303100160BD6 /* MonsterListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A002F2A34303100160BD6 /* MonsterListItem.swift */; }; + 770A00332A34385A00160BD6 /* MonsterListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00322A34385A00160BD6 /* MonsterListItemView.swift */; }; + 770A00352A34402400160BD6 /* MonsterInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770A00342A34402400160BD6 /* MonsterInformationView.swift */; }; + 7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF63E732A342F3A0051985C /* HomeBottomView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -102,8 +104,10 @@ 770A00282A34221900160BD6 /* Character.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = ""; }; 770A002A2A34236700160BD6 /* Equiment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Equiment.swift; sourceTree = ""; }; 770A002C2A34240200160BD6 /* Monster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Monster.swift; sourceTree = ""; }; - 7DF63E732A342F3A0051985C /* HomeBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBottomView.swift; sourceTree = ""; }; 770A002F2A34303100160BD6 /* MonsterListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterListItem.swift; sourceTree = ""; }; + 770A00322A34385A00160BD6 /* MonsterListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterListItemView.swift; sourceTree = ""; }; + 770A00342A34402400160BD6 /* MonsterInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterInformationView.swift; sourceTree = ""; }; + 7DF63E732A342F3A0051985C /* HomeBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBottomView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -234,6 +238,7 @@ 2A9A06D62A342BD400EC8141 /* MonsterList */ = { isa = PBXGroup; children = ( + 770A00312A34384B00160BD6 /* Model */, 770A002E2A34301B00160BD6 /* Subviews */, 2A9A06CE2A3426B800EC8141 /* MonsterListView.swift */, ); @@ -283,11 +288,20 @@ 770A002E2A34301B00160BD6 /* Subviews */ = { isa = PBXGroup; children = ( - 770A002F2A34303100160BD6 /* MonsterListItem.swift */, + 770A00322A34385A00160BD6 /* MonsterListItemView.swift */, + 770A00342A34402400160BD6 /* MonsterInformationView.swift */, ); path = Subviews; sourceTree = ""; }; + 770A00312A34384B00160BD6 /* Model */ = { + isa = PBXGroup; + children = ( + 770A002F2A34303100160BD6 /* MonsterListItem.swift */, + ); + path = Model; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -450,6 +464,7 @@ buildActionMask = 2147483647; files = ( 3985AB322A344859004F1AA6 /* RunningRPGDynamicIslandLiveActivity.swift in Sources */, + 770A00332A34385A00160BD6 /* MonsterListItemView.swift in Sources */, 7DF63E742A342F3A0051985C /* HomeBottomView.swift in Sources */, 2A9A06DA2A34311A00EC8141 /* HomeTopView.swift in Sources */, 2A9A06A12A3414B500EC8141 /* HomeView.swift in Sources */, @@ -460,6 +475,7 @@ 2A9A069F2A3414B500EC8141 /* RunningRPGApp.swift in Sources */, 3985AB2B2A3447EF004F1AA6 /* RunningRPGDynamicIsland.intentdefinition in Sources */, 770A00292A34221900160BD6 /* Character.swift in Sources */, + 770A00352A34402400160BD6 /* MonsterInformationView.swift in Sources */, 770A002D2A34240200160BD6 /* Monster.swift in Sources */, 770A002B2A34236700160BD6 /* Equiment.swift in Sources */, 3961A9A12A343C9F000745FC /* Avatar.swift in Sources */, diff --git a/RunningRPG/Model/Monster.swift b/RunningRPG/Model/Monster.swift index e744f26..3233523 100644 --- a/RunningRPG/Model/Monster.swift +++ b/RunningRPG/Model/Monster.swift @@ -19,3 +19,23 @@ struct Monster: Hashable, Codable, Identifiable { name } } + +enum MonsterType { + case swordShield + case pizza + case gun + case squirrel + + var urls: String { + switch self { + case .squirrel: + return "monster_ squirrel" + case .gun: + return "monster_gun" + case .pizza: + return "monster_pizza" + case .swordShield: + return "monster_swordshield" + } + } +} diff --git a/RunningRPG/Tabbar/MonsterList/Model/MonsterListItem.swift b/RunningRPG/Tabbar/MonsterList/Model/MonsterListItem.swift new file mode 100644 index 0000000..b306fa5 --- /dev/null +++ b/RunningRPG/Tabbar/MonsterList/Model/MonsterListItem.swift @@ -0,0 +1,63 @@ +// +// MonsterListItem.swift +// RunningRPG +// +// Created by 김호세 on 6/10/23. +// + +import Foundation + +internal final class MonsterListItem: Identifiable { + var monster: Monster + + internal init(monster: Monster) { + self.monster = monster + } +} + + +extension MonsterListItem { + static func generateMonsters() -> [MonsterListItem] { + return [ + MonsterListItem( + monster: Monster.init( + name: "총든 몬스터", + hp: 10.0, + currentHp: 10.0, + avatar: MonsterType.gun.urls, + level: 0, isOpen: true + ) + ), + MonsterListItem( + monster: Monster.init( + name: "다람쥐 몬스터", + hp: 20.0, + currentHp: 20.0, + avatar: MonsterType.squirrel.urls, + level: 1, + isOpen: true + ) + ), + MonsterListItem( + monster: Monster.init( + name: "피자 몬스터", + hp: 30.0, + currentHp: 30.0, + avatar: MonsterType.pizza.urls, + level: 2, + isOpen: true + ) + ), + MonsterListItem( + monster: Monster.init( + name: "칼이랑 방패든 몬스터", + hp: 40.0, + currentHp: 40.0, + avatar: MonsterType.swordShield.urls, + level: 3, + isOpen: true + ) + ), + ] + } +} diff --git a/RunningRPG/Tabbar/MonsterList/MonsterListView.swift b/RunningRPG/Tabbar/MonsterList/MonsterListView.swift index 3168be6..36fa36e 100644 --- a/RunningRPG/Tabbar/MonsterList/MonsterListView.swift +++ b/RunningRPG/Tabbar/MonsterList/MonsterListView.swift @@ -18,55 +18,15 @@ struct MonsterListView: View { List { ForEach(listItems) { item in - NavigationLink { - Text("Hello") - } label: { - Image(systemName: "sun.min") - Text("\(item.monster.name)") - } - + MonsterListItemView(item: item) } } - -// NavigationView { -// List { -// ForEach(listItems) { item in -// NavigationLink { -// Text("Item at \(item.monster., format: Date.FormatStyle(date: .numeric, time: .standard))") -// } label: { -// Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard)) -// } -// } -// .onDelete(perform: deleteItems) -// } -// .toolbar { -// ToolbarItem(placement: .navigationBarTrailing) { -// EditButton() -// } -// ToolbarItem { -// Button(action: addItem) { -// Label("Add Item", systemImage: "plus") -// } -// } -// } -// Text("Select an item") -// } + .listRowSpacing(20) } - private func addItem() { -// withAnimation { -// let newItem = Item(timestamp: Date()) -// modelContext.insert(newItem) -// } - } + private func addItem() {} - private func deleteItems(offsets: IndexSet) { -// withAnimation { -// for index in offsets { -// modelContext.delete(items[index]) -// } -// } - } + private func deleteItems(offsets: IndexSet) { } } #Preview { diff --git a/RunningRPG/Tabbar/MonsterList/Subviews/MonsterInformationView.swift b/RunningRPG/Tabbar/MonsterList/Subviews/MonsterInformationView.swift new file mode 100644 index 0000000..f213711 --- /dev/null +++ b/RunningRPG/Tabbar/MonsterList/Subviews/MonsterInformationView.swift @@ -0,0 +1,26 @@ +// +// MonsterInformationView.swift +// RunningRPG +// +// Created by 김호세 on 6/10/23. +// + +import SwiftUI + +struct MonsterInformationView: View { + + let item: MonsterListItem + + var body: some View { + VStack(alignment: .leading, spacing: 10, content: { + HStack(content: { + Text("\(item.monster.name)") + Spacer() + Text("Level - \(item.monster.level)") + }) + HStack(alignment: .top, spacing: 5, content: { + Text("\(item.monster.currentHp) / \(item.monster.hp)") + }) + }) + } +} diff --git a/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItem.swift b/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItem.swift deleted file mode 100644 index 0db6f18..0000000 --- a/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItem.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// MonsterListItem.swift -// RunningRPG -// -// Created by 김호세 on 6/10/23. -// - -import Foundation - -internal final class MonsterListItem: Identifiable { - var monster: Monster - - internal init(monster: Monster) { - self.monster = monster - } -} - - -extension MonsterListItem { - static func generateMonsters() -> [MonsterListItem] { - return [ - MonsterListItem(monster: Monster.init(name: "Test1", hp: 10.0, currentHp: 10.0, avatar: "URL1", level: 0, isOpen: true)), - MonsterListItem(monster: Monster.init(name: "Test2", hp: 20.0, currentHp: 20.0, avatar: "URL1", level: 1, isOpen: true)), - MonsterListItem(monster: Monster.init(name: "Test3", hp: 30.0, currentHp: 30.0, avatar: "URL1", level: 2, isOpen: true)), - MonsterListItem(monster: Monster.init(name: "Test4", hp: 40.0, currentHp: 40.0, avatar: "URL1", level: 3, isOpen: true)), - MonsterListItem(monster: Monster.init(name: "Test5", hp: 50.0, currentHp: 50.0, avatar: "URL1", level: 4, isOpen: true)), - MonsterListItem(monster: Monster.init(name: "Test6", hp: 60.0, currentHp: 60.0, avatar: "URL1", level: 5, isOpen: true)) - ] - } -} diff --git a/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItemView.swift b/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItemView.swift new file mode 100644 index 0000000..b7d3238 --- /dev/null +++ b/RunningRPG/Tabbar/MonsterList/Subviews/MonsterListItemView.swift @@ -0,0 +1,22 @@ +// +// MonsterListItemView.swift +// RunningRPG +// +// Created by 김호세 on 6/10/23. +// + + +import SwiftUI + +struct MonsterListItemView: View { + + let item: MonsterListItem + + var body: some View { + + HStack(alignment: .center, spacing: 10, content: { + Image(item.monster.avatar).resizable().frame(width: 50, height: 50) + MonsterInformationView(item: item) + }) + } +}