Files
peko-ios/YuMi/Modules/YMRoom/View/RoomGame/View/SubView/MSRoomGameHeadView.m
2024-05-30 10:58:35 +08:00

209 lines
7.7 KiB
Objective-C

//
// MSRoomGameHeadView.m
// YuMi
//
// Created by duoban on 2024/5/27.
//
#import "MSRoomGameHeadView.h"
#import "MSRoomGameHeadAvatarView.h"
#import "HomePlayRoomModel.h"
@interface MSRoomGameHeadView()
@property(nonatomic,strong) NetImageView *topImageView;
@property(nonatomic,strong) UIButton *backBtn;
@property(nonatomic,strong) UILabel *titleView;
@property(nonatomic,strong) UIImageView *pkImageView;
@property(nonatomic,strong) MSRoomGameHeadAvatarView *mineView;
@property(nonatomic,strong) MSRoomGameHeadAvatarView *rivalView;
@property(nonatomic,strong) UILabel *hintView;
@property(nonatomic,strong) UIImageView *bgCoinView;
@property(nonatomic,strong) UIImageView *coinView;
@property(nonatomic,strong) UILabel *coinNumView;
@end
@implementation MSRoomGameHeadView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self addSubview:self.topImageView];
[self addSubview:self.backBtn];
[self addSubview:self.titleView];
[self addSubview:self.pkImageView];
[self addSubview:self.mineView];
[self addSubview:self.rivalView];
[self addSubview:self.hintView];
[self addSubview:self.bgCoinView];
[self addSubview:self.coinView];
[self.bgCoinView addSubview:self.coinNumView];
}
-(void)installConstraints{
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.width.mas_equalTo(kGetScaleWidth(90));
make.height.mas_equalTo(kGetScaleWidth(80));
make.leading.mas_equalTo(kGetScaleWidth(5));
}];
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(21));
make.trailing.mas_equalTo(-kGetScaleWidth(12));
make.top.equalTo(self.topImageView.mas_top).mas_offset(kGetScaleWidth(22));
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backBtn.mas_bottom).offset(-kGetScaleWidth(9));
make.centerX.equalTo(self);
}];
[self.pkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleView.mas_bottom).mas_offset(kGetScaleWidth(12));
make.width.mas_equalTo(kGetScaleWidth(60));
make.height.mas_equalTo(kGetScaleWidth(53));
make.centerX.equalTo(self);
}];
[self.rivalView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(57));
make.centerY.equalTo(self.pkImageView);
make.leading.equalTo(self.pkImageView.mas_trailing).offset(-kGetScaleWidth(5));
}];
[self.mineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.width.height.equalTo(self.rivalView);
make.trailing.equalTo(self.rivalView.mas_leading).mas_offset(-kGetScaleWidth(52));
}];
[self.hintView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mineView.mas_bottom).mas_offset(kGetScaleWidth(10));
make.leading.trailing.equalTo(self).inset(kGetScaleWidth(10));
}];
[self.bgCoinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(21));
make.width.mas_greaterThanOrEqualTo(kGetScaleWidth(81));
make.height.mas_equalTo(kGetScaleWidth(25));
make.top.equalTo(self.topImageView.mas_bottom).mas_offset(kGetScaleWidth(66));
}];
[self.coinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(26));
make.leading.equalTo(self.bgCoinView.mas_leading).mas_offset(kGetScaleWidth(0));
make.centerY.equalTo(self.bgCoinView);
}];
[self.coinNumView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(40));
make.trailing.mas_equalTo(-kGetScaleWidth(22));
make.centerY.equalTo(self.bgCoinView);
}];
}
-(void)clickBackBtnAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(clickQuitGameAction)]){
[self.delegate clickQuitGameAction];
}
}
-(void)setChooseGameModel:(MSTabbarRoomGameItemModel *)chooseGameModel{
_chooseGameModel = chooseGameModel;
id coin = _chooseGameModel.scores.firstObject;
if(coin != nil){
self.coinNumView.text = [NSString stringWithFormat:@"%@",coin];
}
}
- (void)setRoomGameModel:(MSRoomGameModel *)roomGameModel{
_roomGameModel = roomGameModel;
NSString *uid = [[AccountInfoStorage instance]getUid];
for (MSRoomGameMicModel *obj in _roomGameModel.roomMics) {
if([obj.micUser.uid isEqualToString:uid]){
self.mineView.imageUrl = obj.micUser.avatar;
}else{
self.rivalView.imageUrl = obj.micUser.avatar;
}
}
MSRoomGameInfoModel *data = _roomGameModel.data;
if(data != nil){
_topImageView.imageUrl = data.gameRoomIcon;
if (data.matchStatus == MSRoomGameInfoModelMatchmaking){
_titleView.text = YMLocalizedString(@"MSRoomGameHeadView0");
}else if(data.matchStatus == MSRoomGameInfoModelMatchSuccessfully){
_titleView.text = YMLocalizedString(@"MSRoomGameHeadView1");
}
}
}
#pragma mark - 懒加载
- (NetImageView *)topImageView{
if(!_topImageView){
_topImageView = [NetImageView new];
}
return _topImageView;
}
- (UIButton *)backBtn{
if(!_backBtn){
_backBtn = [UIButton new];
[_backBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_backBtn setImage:kImage(@"ms_room_game_underwa_back_icon") forState:UIControlStateNormal];
[_backBtn addTarget:self action:@selector(clickBackBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _backBtn;
}
- (UILabel *)titleView{
if(!_titleView){
_titleView = [UILabel labelInitWithText:YMLocalizedString(@"MSRoomGameHeadView0") font:kFontBold(18) textColor:[UIColor whiteColor]];
}
return _titleView;
}
- (MSRoomGameHeadAvatarView *)mineView{
if(!_mineView){
_mineView = [[MSRoomGameHeadAvatarView alloc]initWithFrame:CGRectZero];
}
return _mineView;
}
- (UIImageView *)pkImageView{
if(!_pkImageView){
_pkImageView = [UIImageView new];
_pkImageView.image = kImage(@"ms_room_game_underwa_pk_bg");
}
return _pkImageView;
}
- (MSRoomGameHeadAvatarView *)rivalView{
if(!_rivalView){
_rivalView = [[MSRoomGameHeadAvatarView alloc]initWithFrame:CGRectZero];
}
return _rivalView;
}
- (UILabel *)hintView{
if(!_hintView){
_hintView = [UILabel new];
NSMutableAttributedString *attText = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:YMLocalizedString(@"MSRoomGameHeadView0"),@"18"] attributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:[UIColor whiteColor]}];
[attText addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFF6629)} range:[attText.string rangeOfString:@"18金币"]];
_hintView.attributedText = attText;
_hintView.numberOfLines = 0;
_hintView.textAlignment = NSTextAlignmentCenter;
}
return _hintView;
}
- (UIImageView *)bgCoinView{
if(!_bgCoinView){
_bgCoinView = [UIImageView new];
_bgCoinView.image = kImage(@"ms_room_game_underwa_coin_bg");
}
return _bgCoinView;
}
- (UIImageView *)coinView{
if(!_coinView){
_coinView = [UIImageView new];
_coinView.image = kImage(@"ms_room_game_underwa_coin");
}
return _coinView;
}
- (UILabel *)coinNumView{
if(!_coinNumView){
_coinNumView = [UILabel labelInitWithText:@"0" font:kFontBold(17) textColor:[UIColor whiteColor]];
}
return _coinNumView;
}
@end