流程完善

This commit is contained in:
kron
2025-07-15 17:10:41 +08:00
parent 95426ffd07
commit 0edf259fb0
7 changed files with 76 additions and 31 deletions

View File

@@ -194,4 +194,15 @@ button::after {
padding-top: 20px; padding-top: 20px;
position: relative; position: relative;
} }
.half-time-tip {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.half-time-tip > text:last-child {
margin-top: 20px;
color: #fff9;
}
</style> </style>

View File

@@ -42,6 +42,7 @@ defineProps({
> >
<Avatar <Avatar
:src="player.avatar" :src="player.avatar"
:rankLvl="player.rankLvl"
:size="40" :size="40"
:rank="showRank ? index + 1 : 0" :rank="showRank ? index + 1 : 0"
/> />

View File

@@ -17,14 +17,16 @@ const seats = new Array(props.total).fill(1);
<view v-for="(_, index) in seats" :key="index"> <view v-for="(_, index) in seats" :key="index">
<image src="../static/player-bg.png" mode="widthFix" /> <image src="../static/player-bg.png" mode="widthFix" />
<image <image
v-if="players[index]" v-if="players[index] && players[index].name"
:src="players[index].avatar || '../static/user-icon.png'" :src="players[index].avatar || '../static/user-icon.png'"
mode="widthFix" mode="widthFix"
/> />
<view v-else class="player-unknow"> <view v-else class="player-unknow">
<image src="../static/question-mark.png" mode="widthFix" /> <image src="../static/question-mark.png" mode="widthFix" />
</view> </view>
<text v-if="players[index]">{{ players[index].name }}</text> <text v-if="players[index] && players[index].name">{{
players[index].name
}}</text>
<text v-else :style="{ color: '#fff9' }">虚位以待</text> <text v-else :style="{ color: '#fff9' }">虚位以待</text>
<view v-if="index === 0" class="founder">创建者</view> <view v-if="index === 0" class="founder">创建者</view>
<image <image

View File

@@ -2,6 +2,10 @@
import { ref, watch, onMounted, onUnmounted } from "vue"; import { ref, watch, onMounted, onUnmounted } from "vue";
import audioManager from "@/audioManager"; import audioManager from "@/audioManager";
import { MESSAGETYPES } from "@/constants"; import { MESSAGETYPES } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const props = defineProps({ const props = defineProps({
start: { start: {
type: Boolean, type: Boolean,
@@ -27,6 +31,10 @@ const props = defineProps({
type: String, type: String,
default: "", default: "",
}, },
melee: {
type: Boolean,
default: false,
},
}); });
const barColor = ref("#fed847"); const barColor = ref("#fed847");
@@ -36,6 +44,7 @@ const sound = ref(true);
const currentSound = ref(""); const currentSound = ref("");
const currentRound = ref(props.currentRound); const currentRound = ref(props.currentRound);
const currentRoundEnded = ref(!props.battleId); const currentRoundEnded = ref(!props.battleId);
const halfTimeTip = ref(false);
watch( watch(
() => props.tips, () => props.tips,
@@ -125,6 +134,7 @@ async function onReceiveMessage(messages = []) {
(props.battleId && msg.constructor === MESSAGETYPES.ShootResult) || (props.battleId && msg.constructor === MESSAGETYPES.ShootResult) ||
(!props.battleId && msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) (!props.battleId && msg.constructor === MESSAGETYPES.ShootSyncMeArrowID)
) { ) {
if (props.melee && msg.userId !== user.value.id) return;
if (msg.target) { if (msg.target) {
currentSound.value = msg.target.ring currentSound.value = msg.target.ring
? `${msg.target.ring}` ? `${msg.target.ring}`
@@ -134,10 +144,11 @@ async function onReceiveMessage(messages = []) {
} else if (msg.constructor === MESSAGETYPES.AllReady) { } else if (msg.constructor === MESSAGETYPES.AllReady) {
audioManager.play("比赛开始"); audioManager.play("比赛开始");
} else if (msg.constructor === MESSAGETYPES.MeleeAllReady) { } else if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
audioManager.play("比赛开始"); if (!halfTimeTip.value) audioManager.play("比赛开始");
} else if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) { } else if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
currentRoundEnded.value = true; currentRoundEnded.value = true;
} else if (msg.constructor === MESSAGETYPES.HalfTimeOver) { } else if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
halfTimeTip.value = true;
audioManager.play("中场休息"); audioManager.play("中场休息");
} else if (msg.constructor === MESSAGETYPES.MatchOver) { } else if (msg.constructor === MESSAGETYPES.MatchOver) {
audioManager.play("比赛结束"); audioManager.play("比赛结束");

View File

@@ -19,7 +19,7 @@ onLoad(async (options) => {
battleId.value = options.battleId; battleId.value = options.battleId;
const result = await getGameAPI( const result = await getGameAPI(
// options.battleId || "BATTLE-1750867490990424058-718" // options.battleId || "BATTLE-1750867490990424058-718"
options.battleId || "BATTLE-1750688536849458226-518" options.battleId || "BATTLE-1752563964391008873-624"
); );
data.value = result; data.value = result;
if (result.mode === 1 && result.redPlayers[user.value.id]) { if (result.mode === 1 && result.redPlayers[user.value.id]) {
@@ -285,8 +285,8 @@ const checkBowData = () => {
margin: 0 20px; margin: 0 20px;
} }
.players { .players {
flex-wrap: wrap;
display: flex; display: flex;
flex-direction: column;
overflow: auto; overflow: auto;
width: calc(100% - 60px); width: calc(100% - 60px);
color: #fff6; color: #fff6;

View File

@@ -16,6 +16,7 @@ import SModal from "@/components/SModal.vue";
import ScreenHint from "@/components/ScreenHint.vue"; import ScreenHint from "@/components/ScreenHint.vue";
import RoundEndTip from "@/components/RoundEndTip.vue"; import RoundEndTip from "@/components/RoundEndTip.vue";
import TestDistance from "@/components/TestDistance.vue"; import TestDistance from "@/components/TestDistance.vue";
import PlayerScore from "@/components/PlayerScore.vue";
import { getRoomAPI, destroyRoomAPI, exitRoomAPI, startRoomAPI } from "@/apis"; import { getRoomAPI, destroyRoomAPI, exitRoomAPI, startRoomAPI } from "@/apis";
import { MESSAGETYPES, roundsName, getMessageTypeName } from "@/constants"; import { MESSAGETYPES, roundsName, getMessageTypeName } from "@/constants";
import useStore from "@/store"; import useStore from "@/store";
@@ -53,7 +54,7 @@ const playersScores = ref({});
const showModal = ref(false); const showModal = ref(false);
const halfTimeTip = ref(false); const halfTimeTip = ref(false);
const isFinalShoot = ref(false); const isFinalShoot = ref(false);
const total = ref(90); const total = ref(15);
watch( watch(
() => [players.value, playersScores.value], () => [players.value, playersScores.value],
@@ -132,7 +133,7 @@ onLoad(async (options) => {
}, 300); }, 300);
} else if (remain > 90 && remain <= 110) { } else if (remain > 90 && remain <= 110) {
halfTimeTip.value = true; halfTimeTip.value = true;
countDown.value = 20; total.value = 20;
tips.value = "准备下半场"; tips.value = "准备下半场";
setTimeout(() => { setTimeout(() => {
uni.$emit("update-ramain", 110 - remain); uni.$emit("update-ramain", 110 - remain);
@@ -162,7 +163,6 @@ onLoad(async (options) => {
return false; return false;
}); });
if (result.battleType === 1) { if (result.battleType === 1) {
total.value = 15;
if (user.value.id !== owner.value.id) { if (user.value.id !== owner.value.id) {
opponent.value = { opponent.value = {
id: user.value.id, id: user.value.id,
@@ -183,12 +183,21 @@ onLoad(async (options) => {
}); });
} }
} else if (result.battleType === 2) { } else if (result.battleType === 2) {
result.members.forEach((m) => { const ownerIndex = result.members.findIndex(
players.value.push(m.userInfo); (m) => m.userInfo.id === result.creator
);
if (ownerIndex !== -1) {
players.value.push(result.members[ownerIndex].userInfo);
} else {
players.value.push({});
}
result.members.forEach((m, index) => {
if (ownerIndex !== index) players.value.push(m.userInfo);
}); });
} }
} }
}); });
const startGame = async () => { const startGame = async () => {
const result = await startRoomAPI(room.value.number); const result = await startRoomAPI(room.value.number);
timerSeq.value += 1; timerSeq.value += 1;
@@ -208,11 +217,19 @@ async function onReceiveMessage(messages = []) {
// 这里会掉多次; // 这里会掉多次;
timerSeq.value += 1; timerSeq.value += 1;
battleId.value = msg.id; battleId.value = msg.id;
step.value = 2;
if (room.value.battleType === 1) { if (room.value.battleType === 1) {
redTeam.value = msg.groupUserStatus.redTeam; redTeam.value = msg.groupUserStatus.redTeam;
blueTeam.value = msg.groupUserStatus.blueTeam; blueTeam.value = msg.groupUserStatus.blueTeam;
} else if (room.value.battleType === 2) {
players.value = [
...msg.groupUserStatus.redTeam,
...msg.groupUserStatus.blueTeam,
];
players.value.forEach((p) => {
playersScores.value[p.id] = [];
});
} }
step.value = 2;
} }
if (msg.roomNumber === roomNumber.value) { if (msg.roomNumber === roomNumber.value) {
if (msg.constructor === MESSAGETYPES.UserEnterRoom) { if (msg.constructor === MESSAGETYPES.UserEnterRoom) {
@@ -232,11 +249,19 @@ async function onReceiveMessage(messages = []) {
} }
} }
if (room.value.battleType === 2) { if (room.value.battleType === 2) {
players.value.push({ if (room.value.creator === msg.userId) {
id: msg.userId, players.value[0] = {
name: msg.name, id: msg.userId,
avatar: msg.avatar, name: msg.name,
}); avatar: msg.avatar,
};
} else {
players.value.push({
id: msg.userId,
name: msg.name,
avatar: msg.avatar,
});
}
} }
} }
if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) { if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) {
@@ -281,14 +306,17 @@ async function onReceiveMessage(messages = []) {
redArrows: [], redArrows: [],
blueArrows: [], blueArrows: [],
}); });
total.value = 15;
} }
if (msg.constructor === MESSAGETYPES.MeleeAllReady) { if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
start.value = true; start.value = true;
startCount.value = true; startCount.value = true;
step.value = 3;
seq.value += 1; seq.value += 1;
timerSeq.value = 0; timerSeq.value = 0;
tips.value = "请连续射出6支箭"; tips.value = "请连续射出6支箭";
scores.value = []; scores.value = [];
total.value = 90;
} }
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) { if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
if (room.value.battleType === 1) { if (room.value.battleType === 1) {
@@ -373,6 +401,7 @@ async function onReceiveMessage(messages = []) {
} }
if (msg.constructor === MESSAGETYPES.HalfTimeOver) { if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
startCount.value = false; startCount.value = false;
total.value = 20;
halfTimeTip.value = true; halfTimeTip.value = true;
tips.value = "准备下半场"; tips.value = "准备下半场";
} }
@@ -488,7 +517,7 @@ onUnmounted(() => {
> >
<SButton <SButton
v-if="user.id === owner.id && room.battleType === 2" v-if="user.id === owner.id && room.battleType === 2"
:disabled="players.length < 2" :disabled="players.length < 3"
:onClick="startGame" :onClick="startGame"
>进入大乱斗</SButton >进入大乱斗</SButton
> >
@@ -504,7 +533,7 @@ onUnmounted(() => {
/> />
<TestDistance :guide="false" /> <TestDistance :guide="false" />
</view> </view>
<view v-if="step === 3"> <view v-if="step === 3" :style="{ width: '100%' }">
<ShootProgress <ShootProgress
:tips="tips" :tips="tips"
:seq="seq" :seq="seq"
@@ -512,6 +541,7 @@ onUnmounted(() => {
:total="total" :total="total"
:currentRound="currentRound" :currentRound="currentRound"
:battleId="battleId" :battleId="battleId"
:melee="room.battleType === 2"
/> />
<PlayersRow <PlayersRow
v-if="room.battleType === 1" v-if="room.battleType === 1"
@@ -529,13 +559,13 @@ onUnmounted(() => {
:blueScores="blueScores" :blueScores="blueScores"
/> />
<BattleFooter <BattleFooter
v-if="room.battleType === 1" v-if="roundResults.length"
:roundResults="roundResults" :roundResults="roundResults"
:redPoints="redPoints" :redPoints="redPoints"
:bluePoints="bluePoints" :bluePoints="bluePoints"
/> />
<PlayerScore <PlayerScore
v-if="room.battleType === 2" v-if="playersSorted.length"
v-for="(player, index) in playersSorted" v-for="(player, index) in playersSorted"
:key="index" :key="index"
:name="player.name" :name="player.name"

View File

@@ -195,6 +195,7 @@ onUnmounted(() => {
:start="start" :start="start"
:tips="tips" :tips="tips"
:total="countDown" :total="countDown"
:melee="true"
/> />
<view v-if="start" class="user-row"> <view v-if="start" class="user-row">
<Avatar :src="user.avatar" :size="35" /> <Avatar :src="user.avatar" :size="35" />
@@ -248,15 +249,4 @@ onUnmounted(() => {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.half-time-tip {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.half-time-tip > text:last-child {
margin-top: 20px;
color: #fff9;
}
</style> </style>