LNRoomGiftPanel.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // LNRoomGiftPanel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/23.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNRoomGiftPanel: LNPopupView {
  11. private let headerView = LNRoomGiftHeaderView()
  12. private let listView = LNRoomGiftListView()
  13. private let bottomView = LNRoomGiftBottomView()
  14. private weak var roomSession: LNRoomViewModel?
  15. override init(frame: CGRect) {
  16. super.init(frame: frame)
  17. setupViews()
  18. }
  19. func update(_ room: LNRoomViewModel?, selectedUid: String? = nil) {
  20. roomSession = room
  21. headerView.update(room, selectedUid: selectedUid)
  22. listView.update(room)
  23. }
  24. required init?(coder: NSCoder) {
  25. fatalError("init(coder:) has not been implemented")
  26. }
  27. }
  28. extension LNRoomGiftPanel: LNRoomGiftListViewDelegate {
  29. func onRoomGiftListView(_ view: LNRoomGiftListView, didSelect index: Int) {
  30. checkSendEnable()
  31. }
  32. }
  33. extension LNRoomGiftPanel: LNRoomGiftBottomViewDelegate {
  34. func onRoomGiftBottomViewDidTapBalance(_ view: LNRoomGiftBottomView) {
  35. dismiss()
  36. pushToDiamondView()
  37. }
  38. func onRoomGiftBottomViewDidTapSend(_ view: LNRoomGiftBottomView) {
  39. if headerView.selection.isEmpty {
  40. showToast(.init(key: "A00391"))
  41. return
  42. }
  43. guard let gift = listView.selectedGift else {
  44. return
  45. }
  46. roomSession?.sendGift(gift: gift, to: headerView.selection, count: bottomView.curCount) { _ in }
  47. }
  48. }
  49. extension LNRoomGiftPanel {
  50. private func checkSendEnable() {
  51. bottomView.enable = listView.selectedGift != nil
  52. }
  53. private func setupViews() {
  54. touchOutsideToCancel = true
  55. container.backgroundColor = .fill_7
  56. container.addSubview(headerView)
  57. headerView.snp.makeConstraints { make in
  58. make.top.equalToSuperview().offset(12)
  59. make.horizontalEdges.equalToSuperview()
  60. }
  61. let separator = UIView()
  62. separator.backgroundColor = .text_1.withAlphaComponent(0.12)
  63. container.addSubview(separator)
  64. separator.snp.makeConstraints { make in
  65. make.top.equalTo(headerView.snp.bottom).offset(10)
  66. make.horizontalEdges.equalToSuperview().inset(10)
  67. make.height.equalTo(0.5)
  68. }
  69. listView.delegate = self
  70. container.addSubview(listView)
  71. listView.snp.makeConstraints { make in
  72. make.top.equalTo(separator.snp.bottom).offset(10)
  73. make.horizontalEdges.equalToSuperview()
  74. make.height.equalTo(256)
  75. }
  76. bottomView.delegate = self
  77. container.addSubview(bottomView)
  78. bottomView.snp.makeConstraints { make in
  79. make.top.equalTo(listView.snp.bottom)
  80. make.horizontalEdges.equalToSuperview()
  81. make.bottom.equalToSuperview().offset(commonBottomInset + 12)
  82. }
  83. }
  84. }