LNRoomProfileSkillView.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // LNRoomProfileSkillView.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/16.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNRoomProfileSkillView: UIView {
  11. private let stackView = UIStackView()
  12. weak var panel: LNPopupView?
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. let scrollView = UIScrollView()
  16. scrollView.showsHorizontalScrollIndicator = false
  17. scrollView.alwaysBounceHorizontal = true
  18. scrollView.contentInset = .init(top: 0, left: 12, bottom: 0, right: 0)
  19. addSubview(scrollView)
  20. scrollView.snp.makeConstraints { make in
  21. make.horizontalEdges.equalToSuperview()
  22. make.verticalEdges.equalToSuperview().inset(10)
  23. }
  24. stackView.axis = .horizontal
  25. stackView.spacing = 6
  26. scrollView.addSubview(stackView)
  27. stackView.snp.makeConstraints { make in
  28. make.edges.equalToSuperview()
  29. make.height.equalToSuperview()
  30. }
  31. }
  32. func update(_ userInfo: LNUserProfileVO, _ skills: [LNGameMateSkillVO]) {
  33. stackView.arrangedSubviews.forEach {
  34. stackView.removeArrangedSubview($0)
  35. $0.removeFromSuperview()
  36. }
  37. for (index, skill) in skills.enumerated() {
  38. let itemView = LNRoomProfileSkillItemView()
  39. itemView.update(userInfo, skill)
  40. itemView.onTap { [weak self] in
  41. guard let self else { return }
  42. panel?.dismiss()
  43. let panel = LNCreateOrderPanel()
  44. panel.update(skill, user: userInfo)
  45. panel.editable = true
  46. panel.scene = .room
  47. panel.popup(self)
  48. }
  49. stackView.addArrangedSubview(itemView)
  50. if index == 0 {
  51. LNRoomOrderGuideView.orderCardView = itemView
  52. }
  53. }
  54. }
  55. required init?(coder: NSCoder) {
  56. fatalError("init(coder:) has not been implemented")
  57. }
  58. }
  59. private class LNRoomProfileSkillItemView: UIView {
  60. private let iconView = UIImageView()
  61. private let titleLabel = UILabel()
  62. private let priceLabel = UILabel()
  63. private let unitLabel = UILabel()
  64. override init(frame: CGRect) {
  65. super.init(frame: frame)
  66. setupViews()
  67. }
  68. func update(_ user: LNUserProfileVO, _ item: LNGameMateSkillVO) {
  69. titleLabel.text = item.name
  70. priceLabel.text = item.price.toDisplay
  71. unitLabel.text = "/\(item.unit)"
  72. iconView.sd_setImage(with: URL(string: item.icon))
  73. }
  74. required init?(coder: NSCoder) {
  75. fatalError("init(coder:) has not been implemented")
  76. }
  77. }
  78. private extension LNRoomProfileSkillItemView {
  79. func setupViews() {
  80. backgroundColor = UIColor.fill.withAlphaComponent(0.1)
  81. layer.cornerRadius = 12
  82. clipsToBounds = true
  83. snp.makeConstraints { make in
  84. make.width.equalTo(169)
  85. make.height.equalTo(68)
  86. }
  87. iconView.backgroundColor = UIColor.fill.withAlphaComponent(0.2)
  88. iconView.layer.borderWidth = 0.5
  89. iconView.layer.borderColor = UIColor.fill.withAlphaComponent(0.3).cgColor
  90. iconView.layer.cornerRadius = 20
  91. iconView.clipsToBounds = true
  92. iconView.contentMode = .scaleAspectFill
  93. addSubview(iconView)
  94. iconView.snp.makeConstraints { make in
  95. make.centerY.equalToSuperview()
  96. make.leading.equalToSuperview().offset(10)
  97. make.height.width.equalTo(40)
  98. }
  99. let infoView = UIView()
  100. addSubview(infoView)
  101. infoView.snp.makeConstraints { make in
  102. make.centerY.equalToSuperview()
  103. make.leading.equalTo(iconView.snp.trailing).offset(5)
  104. make.trailing.equalToSuperview().offset(-10)
  105. }
  106. titleLabel.font = .heading_h4
  107. titleLabel.textColor = .text_1
  108. titleLabel.lineBreakMode = .byTruncatingTail
  109. infoView.addSubview(titleLabel)
  110. titleLabel.snp.makeConstraints { make in
  111. make.horizontalEdges.equalToSuperview()
  112. make.top.equalToSuperview()
  113. }
  114. let priceView = UIView()
  115. infoView.addSubview(priceView)
  116. priceView.snp.makeConstraints { make in
  117. make.horizontalEdges.equalToSuperview()
  118. make.bottom.equalToSuperview()
  119. make.top.equalTo(titleLabel.snp.bottom).offset(4)
  120. }
  121. let coinIconView = UIImageView.coinImageView()
  122. priceView.addSubview(coinIconView)
  123. coinIconView.snp.makeConstraints { make in
  124. make.centerY.equalToSuperview()
  125. make.leading.equalToSuperview()
  126. }
  127. priceLabel.font = .heading_h5
  128. priceLabel.textColor = .text_1
  129. priceView.addSubview(priceLabel)
  130. priceLabel.snp.makeConstraints { make in
  131. make.leading.equalTo(coinIconView.snp.trailing).offset(3)
  132. make.verticalEdges.equalToSuperview()
  133. }
  134. unitLabel.font = .body_s
  135. unitLabel.textColor = .text_2
  136. priceView.addSubview(unitLabel)
  137. unitLabel.snp.makeConstraints { make in
  138. make.leading.equalTo(priceLabel.snp.trailing)
  139. make.centerY.equalTo(priceLabel)
  140. make.trailing.lessThanOrEqualToSuperview().offset(-10)
  141. }
  142. }
  143. }