LNOrderRoomApplySeatPanel.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // LNOrderRoomApplySeatPanel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/11.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNOrderRoomApplySeatPanel: LNPopupView {
  11. private let titleLabel = UILabel()
  12. private let avatarView = UIImageView()
  13. private let nameLabel = UILabel()
  14. private let applyButton = UIButton()
  15. private weak var roomSession: LNRoomSession?
  16. private var targetSeat: LNOrderRoomSeatNum?
  17. override init(frame: CGRect) {
  18. super.init(frame: frame)
  19. setupViews()
  20. }
  21. func update(_ room: LNRoomSession?, seat: LNOrderRoomSeatNum? = nil) {
  22. roomSession = room
  23. targetSeat = seat
  24. }
  25. required init?(coder: NSCoder) {
  26. fatalError("init(coder:) has not been implemented")
  27. }
  28. }
  29. extension LNOrderRoomApplySeatPanel {
  30. private func setupViews() {
  31. container.backgroundColor = .fill_7
  32. let header = buildHeader()
  33. container.addSubview(header)
  34. header.snp.makeConstraints { make in
  35. make.top.horizontalEdges.equalToSuperview()
  36. make.height.equalTo(52)
  37. }
  38. avatarView.sd_setImage(with: URL(string: myUserInfo.avatar))
  39. avatarView.clipsToBounds = true
  40. avatarView.contentMode = .scaleAspectFill
  41. avatarView.layer.cornerRadius = 38
  42. avatarView.layer.borderWidth = 1
  43. avatarView.layer.borderColor = .fill
  44. container.addSubview(avatarView)
  45. avatarView.snp.makeConstraints { make in
  46. make.top.equalTo(header.snp.bottom).offset(20)
  47. make.centerX.equalToSuperview()
  48. make.width.height.equalTo(76)
  49. }
  50. nameLabel.text = myUserInfo.nickname
  51. nameLabel.font = .heading_h2
  52. nameLabel.textColor = .text_1
  53. nameLabel.textAlignment = .center
  54. container.addSubview(nameLabel)
  55. nameLabel.snp.makeConstraints { make in
  56. make.horizontalEdges.equalToSuperview()
  57. make.top.equalTo(avatarView.snp.bottom).offset(13)
  58. }
  59. applyButton.setTitle(.init(key: "A00322"), for: .normal)
  60. applyButton.setTitleColor(.text_1, for: .normal)
  61. applyButton.titleLabel?.font = .heading_h3
  62. applyButton.setBackgroundImage(.primary_8, for: .normal)
  63. applyButton.layer.cornerRadius = 23.5
  64. applyButton.clipsToBounds = true
  65. applyButton.addAction(UIAction(handler: { [weak self] _ in
  66. guard let self else { return }
  67. guard let roomSession else { return }
  68. let seatNum: LNOrderRoomSeatNum = targetSeat ?? (myUserInfo.playmate ? .none : .guest)
  69. roomSession.applySeat(index: seatNum.rawValue) { [weak self] success in
  70. guard let self else { return }
  71. guard success else { return }
  72. dismiss()
  73. }
  74. }), for: .touchUpInside)
  75. container.addSubview(applyButton)
  76. applyButton.snp.makeConstraints { make in
  77. make.horizontalEdges.equalToSuperview().inset(16)
  78. make.top.equalTo(nameLabel.snp.bottom).offset(46)
  79. make.height.equalTo(47)
  80. make.bottom.equalToSuperview().offset(commonBottomInset)
  81. }
  82. }
  83. private func buildHeader() -> UIView {
  84. let header = UIView()
  85. titleLabel.font = .heading_h3
  86. titleLabel.textColor = .text_1
  87. titleLabel.text = .init(key: "A00330")
  88. header.addSubview(titleLabel)
  89. titleLabel.snp.makeConstraints { make in
  90. make.center.equalToSuperview()
  91. }
  92. return header
  93. }
  94. }