游戏中用户去掉礼物特效

This commit is contained in:
huangjian
2021-12-13 16:07:43 +08:00
parent 7f92b9d1f0
commit f3d3e913cf
5 changed files with 145 additions and 126 deletions

View File

@@ -537,7 +537,7 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi
ButtonItem buttonItem1 = new ButtonItem("退出房间", new ButtonItem.OnClickListener() {
@Override
public void onClick() {
if (AvRoomDataManager.get().isGamePlaying(AvRoomDataManager.get().getMicPosition(AuthModel.get().getCurrentUid()))){
if (AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())){
getDialogManager().showOkCancelDialog("游戏中退出房间默认逃跑,确定进行此操作?", false,
() -> ((AVRoomActivity) getActivity()).toBack());
return;
@@ -576,7 +576,7 @@ public class HomePartyFragment extends AbsRoomFragment implements View.OnClickLi
ButtonItem buttonItem2 = new ButtonItem("最小化房间", new ButtonItem.OnClickListener() {
@Override
public void onClick() {
if (AvRoomDataManager.get().isGamePlaying(AvRoomDataManager.get().getMicPosition(AuthModel.get().getCurrentUid()))){
if (AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())){
getDialogManager().showOkCancelDialog("游戏中最小化房间默认逃跑,确定进行此操作?", false,
() -> ((AVRoomActivity) getActivity()).toBack());
return;

View File

@@ -29,6 +29,7 @@ import com.yizhuan.erban.R;
import com.yizhuan.erban.common.widget.CircleImageView;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.bean.RoomQueueInfo;
import com.yizhuan.xchat_android_core.gift.GiftModel;
import com.yizhuan.xchat_android_core.gift.bean.GiftEffectInfo;
@@ -66,14 +67,6 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
private boolean isAnim;
public interface GiftEffectListener {
void onGiftEffectEnd();
}
public boolean isAnim() {
return isAnim;
}
public GiftEffectView(Context context) {
super(context);
init();
@@ -89,6 +82,10 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
init();
}
public boolean isAnim() {
return isAnim;
}
public void setGiftEffectListener(GiftEffectListener giftEffectListener) {
this.giftEffectListener = giftEffectListener;
}
@@ -184,7 +181,10 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
}
private void drawSvgaEffect(String url) throws MalformedURLException {
if (!AvRoomDataManager.get().mIsNeedGiftEffect) return;
if (!AvRoomDataManager.get().mIsNeedGiftEffect ||
AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
return;
}
SVGAParser.Companion.shareParser().decodeFromURL(new URL(url), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@Nullable SVGAVideoEntity videoItem) {
@@ -201,7 +201,7 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
public void onError() {
}
},null);
}, null);
}
@@ -225,27 +225,6 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
objectAnimator1.start();
}
private static class EffectHandler extends Handler {
private WeakReference<GiftEffectView> mReference;
EffectHandler(GiftEffectView giftEffectView) {
mReference = new WeakReference<>(giftEffectView);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (mReference != null) {
final GiftEffectView giftEffectView = mReference.get();
if (giftEffectView != null) {
if (msg.what == 0) {
giftEffectView.deleteAnim();
}
}
}
}
}
public void release() {
effectHandler.removeMessages(0);
}
@@ -269,4 +248,29 @@ public class GiftEffectView extends RelativeLayout implements SVGACallback {
public void onStep(int i, double v) {
}
public interface GiftEffectListener {
void onGiftEffectEnd();
}
private static class EffectHandler extends Handler {
private WeakReference<GiftEffectView> mReference;
EffectHandler(GiftEffectView giftEffectView) {
mReference = new WeakReference<>(giftEffectView);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (mReference != null) {
final GiftEffectView giftEffectView = mReference.get();
if (giftEffectView != null) {
if (msg.what == 0) {
giftEffectView.deleteAnim();
}
}
}
}
}
}

View File

@@ -167,7 +167,8 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
private void drawMagicAnimation(List<MagicReceivedInfo> magicReceivedInfos) {
if (!AvRoomDataManager.get().mIsNeedGiftEffect) {
if (!AvRoomDataManager.get().mIsNeedGiftEffect ||
AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
return;
}
@@ -300,7 +301,8 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
List<GiftReceiver> targetUsers = new ArrayList<>();
int totalCoin = 0;
if (AvRoomDataManager.get().mIsNeedGiftEffect) {
if (AvRoomDataManager.get().mIsNeedGiftEffect &&
!AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
SVGAImageView imageView = playLuckyBagAnim(svgaUrl);
handler.postDelayed(() -> {
removeView(imageView);
@@ -385,10 +387,10 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
};
if (TextUtils.isEmpty(svgaUrl)) {
SVGAParser.Companion.shareParser().decodeFromAssets(path, parseCompletion,null);
SVGAParser.Companion.shareParser().decodeFromAssets(path, parseCompletion, null);
} else {
try {
SVGAParser.Companion.shareParser().decodeFromURL(new URL(svgaUrl), parseCompletion,null);
SVGAParser.Companion.shareParser().decodeFromURL(new URL(svgaUrl), parseCompletion, null);
} catch (MalformedURLException e) {
e.printStackTrace();
}
@@ -448,65 +450,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
}
private static class UiHandler extends Handler {
private WeakReference<GiftV2View> mReference;
UiHandler(GiftV2View giftV2View) {
this.mReference = new WeakReference<>(giftV2View);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
Activity activity = (Activity) giftV2View.context;
if (activity == null || activity.isDestroyed()) return;
if (msg.what == 0) {
// 播放礼物动效
GiftEffectInfo giftEffectInfo = (GiftEffectInfo) msg.obj;
giftV2View.drawGiftEffect(giftEffectInfo);
} else if (msg.what == 1) {
// 播放魔法svga
if (msg.obj == null) return;
MagicReceivedInfo explodeSvga = (MagicReceivedInfo) msg.obj;
String animationUrl = giftV2View.getValidExplodeAnimationUrl(explodeSvga.getMagicId(),
explodeSvga.getExplodeAnim());
if (TextUtils.isEmpty(animationUrl)) return;
giftV2View.startSvgaAnimation(animationUrl, new SimpleParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity svgaVideoEntity) {
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
giftV2View.cacheSvgaVideoItem(animationUrl, svgaVideoEntity);
SVGAImageView imageView = giftV2View.mMagicExplodeView;
SVGADrawable drawable = new SVGADrawable(svgaVideoEntity);
imageView.setLoops(1);
imageView.setImageDrawable(drawable);
imageView.setClearsAfterStop(true);
imageView.startAnimation();
imageView.setCallback(new SimpleSvgaCallback(giftV2View) {
@Override
public void onFinished() {
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
// 移除上一次播放的爆炸特效
giftV2View.mMagicReceivedInfos.remove(0);
int size = giftV2View.mMagicReceivedInfos.size();
if (size > 0) {
Message message = Message.obtain();
message.what = 1;
message.obj = giftV2View.mMagicReceivedInfos.get(0);
sendMessage(message);
}
}
});
}
});
}
}
}
private boolean isCenter(MagicReceivedInfo magicReceivedInfo) {
int magicId = magicReceivedInfo.getMagicId();
MagicInfo magicInfo = MagicModel.get().getMagicInfo(magicId);
@@ -514,6 +457,13 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
return magicInfo.getPosition() == MagicInfo.POS_CENTER;
}
private String getValidPathAnimationUrl(int magicId, String url) {
if (!TextUtils.isEmpty(url)) return url;
MagicInfo magicInfo = MagicModel.get().getMagicInfo(magicId);
if (magicInfo == null) return "";
return magicInfo.getPathAnim();
}
// private boolean isCenter(MonsterAttackReceiveInfo monsterAttackReceiveInfo) {
// int magicId = Integer.parseInt(monsterAttackReceiveInfo.getMagicId());
// MagicInfo magicInfo = MagicModel.get().getMagicInfo(magicId);
@@ -521,13 +471,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
// return magicInfo.getPosition() == MagicInfo.POS_CENTER;
// }
private String getValidPathAnimationUrl(int magicId, String url) {
if (!TextUtils.isEmpty(url)) return url;
MagicInfo magicInfo = MagicModel.get().getMagicInfo(magicId);
if (magicInfo == null) return "";
return magicInfo.getPathAnim();
}
private String getValidExplodeAnimationUrl(int magicId, String url) {
if (!TextUtils.isEmpty(url)) return url;
MagicInfo magicInfo = MagicModel.get().getMagicInfo(magicId);
@@ -581,7 +524,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
}
private void drawGiftEffect(GiftEffectInfo giftEffectInfo) {
giftEffectInfoList.add(giftEffectInfo);
if (!giftEffectView.isAnim()) {
@@ -590,7 +532,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
}
/**
* 打怪兽时使用的动画效果
*
@@ -659,7 +600,10 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
private void drawMagicView(Point senderPoint, Point receivePoint, MagicReceivedInfo magicReceivedInfo) {
if (!AvRoomDataManager.get().mIsNeedGiftEffect) return;
if (!AvRoomDataManager.get().mIsNeedGiftEffect ||
AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
return;
}
if (senderPoint == null)
senderPoint = new Point(mScreenWidth - giftWidth, mScreenHeight - UIUtil.dip2px(context, 50));
@@ -718,7 +662,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
} else {
System.out.println(TAG + ", 用io");
URL url = new URL(animation);
mSVGAParser.decodeFromURL(url, parseCompletion,null);
mSVGAParser.decodeFromURL(url, parseCompletion, null);
}
} catch (Exception e) {
e.printStackTrace();
@@ -726,7 +670,8 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
private void drawGiftView(Point senderPoint, Point receivePoint, GiftReceiveInfo giftReceiveInfo) {
if (!AvRoomDataManager.get().mIsNeedGiftEffect) {
if (!AvRoomDataManager.get().mIsNeedGiftEffect ||
AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
return;
}
if (giftReceiveInfo == null) {
@@ -792,7 +737,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
mMagicViewPool.shutdown();
}
@Override
public void onGiftEffectEnd() {
if (giftEffectInfoList != null && giftEffectInfoList.size() > 0) {
@@ -808,6 +752,73 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
System.out.println(TAG + "onDetachedFromWindow: " + dettached);
}
private SVGAVideoEntity popSvgaVideoItem(String url) {
return mSVGAVideoEntityMap.get(url);
}
private void cacheSvgaVideoItem(String url, SVGAVideoEntity videoEntity) {
mSVGAVideoEntityMap.put(url, videoEntity);
}
private static class UiHandler extends Handler {
private WeakReference<GiftV2View> mReference;
UiHandler(GiftV2View giftV2View) {
this.mReference = new WeakReference<>(giftV2View);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
Activity activity = (Activity) giftV2View.context;
if (activity == null || activity.isDestroyed()) return;
if (msg.what == 0) {
// 播放礼物动效
GiftEffectInfo giftEffectInfo = (GiftEffectInfo) msg.obj;
giftV2View.drawGiftEffect(giftEffectInfo);
} else if (msg.what == 1) {
// 播放魔法svga
if (msg.obj == null) return;
MagicReceivedInfo explodeSvga = (MagicReceivedInfo) msg.obj;
String animationUrl = giftV2View.getValidExplodeAnimationUrl(explodeSvga.getMagicId(),
explodeSvga.getExplodeAnim());
if (TextUtils.isEmpty(animationUrl)) return;
giftV2View.startSvgaAnimation(animationUrl, new SimpleParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity svgaVideoEntity) {
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
giftV2View.cacheSvgaVideoItem(animationUrl, svgaVideoEntity);
SVGAImageView imageView = giftV2View.mMagicExplodeView;
SVGADrawable drawable = new SVGADrawable(svgaVideoEntity);
imageView.setLoops(1);
imageView.setImageDrawable(drawable);
imageView.setClearsAfterStop(true);
imageView.startAnimation();
imageView.setCallback(new SimpleSvgaCallback(giftV2View) {
@Override
public void onFinished() {
GiftV2View giftV2View = mReference.get();
if (giftV2View == null) return;
// 移除上一次播放的爆炸特效
giftV2View.mMagicReceivedInfos.remove(0);
int size = giftV2View.mMagicReceivedInfos.size();
if (size > 0) {
Message message = Message.obtain();
message.what = 1;
message.obj = giftV2View.mMagicReceivedInfos.get(0);
sendMessage(message);
}
}
});
}
});
}
}
}
private static class SimpleSvgaCallback implements SVGACallback {
private SVGAImageView mImageView;
private WeakReference<GiftV2View> mReference;
@@ -859,15 +870,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}
}
private SVGAVideoEntity popSvgaVideoItem(String url) {
return mSVGAVideoEntityMap.get(url);
}
private void cacheSvgaVideoItem(String url, SVGAVideoEntity videoEntity) {
mSVGAVideoEntityMap.put(url, videoEntity);
}
private static class SimpleParseCompletion implements SVGAParser.ParseCompletion {
@Override

View File

@@ -673,7 +673,8 @@ public class RoomEffectView extends FrameLayout {
&& userInfo.getCarInfo() != null
&& userInfo.getCarInfo().isUsing()
&& userInfo.getCarInfo().getStatus() == CarInfo.STATUS_USER_CAN_USE) {
if (AvRoomDataManager.get().mIsNeedGiftEffect) {
if (AvRoomDataManager.get().mIsNeedGiftEffect &&
!AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
mCarEffectList.add(userInfo.getCarInfo().getEffect());
}
// 非贵族人员,进来后要播放座驾动画
@@ -702,7 +703,8 @@ public class RoomEffectView extends FrameLayout {
});
} else {
if (TextUtils.isEmpty(effect)) return;
if (AvRoomDataManager.get().mIsNeedGiftEffect) {
if (AvRoomDataManager.get().mIsNeedGiftEffect &&
!AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
mCarEffectList.add(effect);
}
if (!binding.roomCarSvga.isAnimating() && !isSvgaPlaying) {
@@ -719,7 +721,10 @@ public class RoomEffectView extends FrameLayout {
*/
private void playCarSvagEnterRoom(String effect) {
if (TextUtils.isEmpty(effect)) return;
if (!AvRoomDataManager.get().mIsNeedGiftEffect) return;
if (!AvRoomDataManager.get().mIsNeedGiftEffect ||
AvRoomDataManager.get().isGamePlaying(AuthModel.get().getCurrentUid())) {
return;
}
isSvgaPlaying = true;
try {
SVGAParser.Companion.shareParser().decodeFromURL(new URL(effect),
@@ -767,8 +772,8 @@ public class RoomEffectView extends FrameLayout {
private void showRoomPKNotify(ChatRoomMessage chatRoomMessage) {
RoomPkBean roomPkBean = ((RoomPKAttachment) chatRoomMessage.getAttachment()).getRoomPkBean();
View rootView = LayoutInflater.from(mContext).inflate(R.layout.layout_room_pk_notify, null);
((TextView) rootView.findViewById(R.id.tv_title_left)).setText(StringExtensionKt.subAndReplaceDot(roomPkBean.getWinTitle(),7));
((TextView) rootView.findViewById(R.id.tv_title_right)).setText(StringExtensionKt.subAndReplaceDot(roomPkBean.getFailTitle(),7));
((TextView) rootView.findViewById(R.id.tv_title_left)).setText(StringExtensionKt.subAndReplaceDot(roomPkBean.getWinTitle(), 7));
((TextView) rootView.findViewById(R.id.tv_title_right)).setText(StringExtensionKt.subAndReplaceDot(roomPkBean.getFailTitle(), 7));
((TextView) rootView.findViewById(R.id.tv_win_text)).setText(roomPkBean.getMsg());
ImageLoadUtils.loadImage(getContext(), roomPkBean.getWinAvatar(), rootView.findViewById(R.id.iv_avatar_left));
ImageLoadUtils.loadImage(getContext(), roomPkBean.getFailAvatar(), rootView.findViewById(R.id.iv_avatar_right));

View File

@@ -621,7 +621,7 @@ public final class AvRoomDataManager {
}
/**
* 获取坑上没人且没上锁且最大6个坑位的位置
* 当前房间是否正在游戏中
*/
public boolean isGamePlaying() {
if (!isOpenGame()) return false;
@@ -638,13 +638,21 @@ public final class AvRoomDataManager {
}
/**
* 获取坑上没人且没上锁且最大6个坑位的位置
* 是否正在游戏中
*/
public boolean isGamePlaying(long uid) {
return isGamePlaying(AvRoomDataManager.get().getMicPosition(uid));
}
/**
* 是否正在游戏中
*/
public boolean isGamePlaying(int micPosition) {
if (!isOpenGame()) return false;
if (mMicQueueMemberMap != null && mMicQueueMemberMap.size() >= 6) {
RoomQueueInfo roomQueueInfo = mMicQueueMemberMap.get(micPosition);
return roomQueueInfo!=null &&
return roomQueueInfo != null &&
roomQueueInfo.mChatRoomMember != null &&
roomQueueInfo.mChatRoomMember.getGameStatus() == GameStatus.STATUS_PLAYING;
}