Files
peko-ios/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameVictoryView.m
2024-06-04 18:10:44 +08:00

163 lines
6.4 KiB
Objective-C

//
// MSRoomGameVictoryView.m
// YuMi
//
// Created by duoban on 2024/5/28.
//
#import "MSRoomGameVictoryView.h"
#import "MSRoomGameVictoryCell.h"
#import "MSRoomGameResultsModel.h"
@interface MSRoomGameVictoryView()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UIView *bgView;
@property(nonatomic,strong) UIView *bgSubView;
@property(nonatomic,strong) UIImageView *topView;
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) UIButton *closeBtn;
@property(nonatomic,strong) UIButton *restartBtn;
@end
@implementation MSRoomGameVictoryView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
[self addSubview:self.bgView];
[self addSubview:self.topView];
[self.bgView addSubview:self.bgSubView];
[self.bgSubView addSubview:self.tableView];
[self.bgSubView addSubview:self.closeBtn];
[self.bgSubView addSubview:self.restartBtn];
}
-(void)installConstraints{
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(312));
make.height.mas_equalTo(kGetScaleWidth(287));
make.center.equalTo(self);
}];
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(kGetScaleWidth(317));
make.leading.mas_equalTo(kGetScaleWidth(0));
make.bottom.equalTo(self.bgView.mas_top).mas_offset(kGetScaleWidth(85));
}];
[self.bgSubView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(297));
make.height.mas_equalTo(kGetScaleWidth(238));
make.top.mas_equalTo(kGetScaleWidth(41));
make.centerX.equalTo(self.bgView);
}];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(134));
make.height.mas_equalTo(kGetScaleWidth(42));
make.leading.mas_equalTo(kGetScaleWidth(13));
make.bottom.mas_equalTo(-kGetScaleWidth(27));
}];
[self.restartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.top.equalTo(self.closeBtn);
make.trailing.mas_equalTo(-kGetScaleWidth(13));
}];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(15));
make.leading.trailing.equalTo(self.bgSubView).inset(kGetScaleWidth(13));
make.bottom.equalTo(self.closeBtn.mas_top).mas_offset(-kGetScaleWidth(5));
}];
}
#pragma mark- UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.resultsList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MSRoomGameVictoryCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MSRoomGameVictoryCell class]) forIndexPath:indexPath];
cell.resultsModel = [self.resultsList safeObjectAtIndex1:indexPath.row];
return cell;
}
-(void)closeBtnAction{
[TTPopup dismiss];
if(self.delegate && [self.delegate respondsToSelector:@selector(closeGameAction)]){
[self.delegate closeGameAction];
}
}
-(void)restartBtnAction{
[TTPopup dismiss];
if(self.delegate && [self.delegate respondsToSelector:@selector(rematchGameAction)]){
[self.delegate rematchGameAction];
}
}
-(void)setResultsList:(NSArray *)resultsList{
_resultsList = resultsList;
MSRoomGameResultsModel *resultsModel = _resultsList.firstObject;
NSString *uid = [AccountInfoStorage instance].getUid;
self.topView.image = [resultsModel.uid isEqualToString:[AccountInfoStorage instance].getUid] ? kImage(@"ms_room_game_victory_top_icon") : kImage(@"ms_room_game_victory_top_fail_icon");
[_tableView reloadData];
}
#pragma mark - 懒加载
- (UIView *)bgView{
if(!_bgView){
_bgView = [UIView new];
_bgView.backgroundColor = UIColorFromRGB(0x1ADCE5);
_bgView.layer.cornerRadius = kGetScaleWidth(16);
_bgView.layer.masksToBounds = YES;
}
return _bgView;
}
- (UIImageView *)topView{
if(!_topView){
_topView = [UIImageView new];
_topView.image = kImage(@"ms_room_game_victory_top_icon");
}
return _topView;
}
- (UIView *)bgSubView{
if(!_bgSubView){
_bgSubView = [UIView new];
_bgSubView.backgroundColor = UIColorFromRGB(0xE2F6FF);
_bgSubView.layer.cornerRadius = kGetScaleWidth(12);
_bgSubView.layer.masksToBounds = YES;
}
return _bgSubView;
}
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.rowHeight = kGetScaleWidth(70);
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_tableView registerClass:[MSRoomGameVictoryCell class] forCellReuseIdentifier:NSStringFromClass([MSRoomGameVictoryCell class])];
}
return _tableView;
}
- (UIButton *)closeBtn{
if(!_closeBtn){
_closeBtn = [UIButton new];
[_closeBtn setBackgroundImage:kImage(@"ms_room_game_victory_close_bg") forState:UIControlStateNormal];
[_closeBtn setTitle:YMLocalizedString(@"XPAnchorPKResultView2") forState:UIControlStateNormal];
[_closeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_closeBtn.titleLabel.font = kFontBold(18);
[_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UIButton *)restartBtn{
if(!_restartBtn){
_restartBtn = [UIButton new];
[_restartBtn setBackgroundImage:kImage(@"ms_room_game_victory_restart_bg") forState:UIControlStateNormal];
[_restartBtn setTitle:YMLocalizedString(@"MSRoomGameVictoryView0") forState:UIControlStateNormal];
[_restartBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_restartBtn.titleLabel.font = kFontBold(18);
[_restartBtn addTarget:self action:@selector(restartBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _restartBtn;
}
@end