Skip to content

Commit

Permalink
增加小组件皮肤选择功能,顺便加了几个皮肤
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperzlib committed Aug 20, 2024
1 parent 8c3228e commit 9648064
Show file tree
Hide file tree
Showing 23 changed files with 900 additions and 272 deletions.
3 changes: 2 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta charset="UTF-8">
<meta name="color-scheme" content="light dark">
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>战败惩罚</title>
Expand Down
53 changes: 53 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@primevue/themes": "4.0.0-rc.2",
"eventemitter3": "^5.0.1",
"pinia": "^2.2.2",
"primeicons": "^7.0.0",
"primevue": "4.0.0-rc.2",
"unplugin-auto-import": "^0.17.6",
Expand Down
25 changes: 20 additions & 5 deletions frontend/src/pages/Viewer.vue → frontend/src/ViewerApp.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { SocketApi } from '../apis/socketApi';
import { ServerInfoResData, webApi } from '../apis/webApi';
import { handleApiResponse } from '../utils/response';
import { SocketApi } from './apis/socketApi';
import { ServerInfoResData, webApi } from './apis/webApi';
import { handleApiResponse } from './utils/response';
const state = reactive({
strength: 0,
Expand Down Expand Up @@ -96,13 +96,28 @@ onMounted(async () => {

<template>
<div class="w-full h-full">
<StatusChart
<!-- <StatusChart
:val-low="chartVal.valLow"
:val-high="chartVal.valHigh"
:val-limit="chartVal.valLimit"
:running="state.gameStarted"
readonly
/>
/> -->
<RouterView>
<template #default="{ Component }">
<Component
:is="Component"
:valLimit="chartVal.valLimit"
:valLow="chartVal.valLow"
:valHigh="chartVal.valHigh"
:strength="state.strength"
:randomStrength="state.randomStrength"
:tempStrength="state.tempStrength"
:strengthLimit="state.strengthLimit"
:running="state.gameStarted"
/>
</template>
</RouterView>
<Transition name="fade">
<div class="fixed w-full h-full left-0 top-0 error-cover" v-if="state.error">
<div class="flex flex-col items-center justify-center h-full">
Expand Down
170 changes: 170 additions & 0 deletions frontend/src/charts/Bar1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<script lang="ts" setup>
const pillsNum = 40;
const pillWidth = 5;
const pillOffset = 4;
const props = withDefaults(defineProps<{
valLow?: number;
valHigh?: number;
valLimit?: number;
readonly?: boolean;
running?: boolean;
darkMode?: boolean;
}>(), {
valLow: 5,
valHigh: 10,
valLimit: 50,
readonly: false,
running: false,
});
const progressToPillsWidth = (progress: number) => {
// 计算进度条在第几个pill
let pillIndex = Math.floor(progress * pillsNum);
// 计算进度条在第几个pill的偏移量
let lastPillFill = (progress * pillsNum - pillIndex) * pillWidth;
console.log('final: ', pillIndex * (pillWidth + pillOffset) + lastPillFill);
return pillIndex * (pillWidth + pillOffset) + lastPillFill;
}
const progressWidth = computed(() => {
if (props.valLimit === 0) {
return {
valLow: 0,
valHigh: 0,
};
} else {
return {
valLow: progressToPillsWidth(props.valLow / props.valLimit),
valHigh: progressToPillsWidth(props.valHigh / props.valLimit),
};
}
});
</script>

<template>
<div class="bar-chart">
<div class="progress">
<div
class="progress-bar progress-bar--low"
:style="{ width: progressWidth.valLow + 'px' }"
role="progressbar"
:aria-valuenow="props.valLow"
aria-valuemin="0"
:aria-valuemax="props.valHigh"
></div>
<div
class="progress-bar progress-bar--high"
:style="{ width: progressWidth.valHigh + 'px' }"
role="progressbar"
:aria-valuenow="props.valHigh"
aria-valuemin="0"
:aria-valuemax="props.valHigh"
></div>
</div>
<div class="mt-2 pr-2 flex justify-between items-center value-text">
<div class="flex gap-2 items-center">
<span class="color-low">{{ props.valLow }}</span> - <span class="color-high">{{ props.valHigh }}</span>

<svg t="1719514976614" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
p-id="9374" style="display: block; width: 2rem; height: 2rem; margin: 0 auto" v-if="!props.running">
<path d="M752.113937 512.104171v383.973957h-176.04883V512.104171z" fill="#00C9CA" p-id="9375"></path>
<path d="M752.113937 127.921872V512.104171h-176.04883V127.921872z" fill="#00A1A2" p-id="9376"></path>
<path d="M447.934893 512.104171v383.973957h-175.840488V512.104171z" fill="#00C9CA" p-id="9377"></path>
<path d="M447.934893 127.921872V512.104171h-175.840488V127.921872z" fill="#00A1A2" p-id="9378"></path>
</svg>
</div>
<div>
MAX: <span class="color-max">{{ props.valLimit }}</span>
</div>
</div>
</div>
</template>

<style lang="scss" scoped>
.bar-chart {
width: 400px;
padding: 20px;
}
.progress {
display: flex;
overflow: hidden;
font-size: 0.75rem;
background-color: #fff;
position: relative;
-webkit-mask-image: url('./bar1/pills-mask.svg');
-webkit-mask-size: contain;
mask-image: url('./bar1/pills-mask.svg');
mask-size: contain;
mask-repeat: repeat-x;
--progress-height: 25px;
width: 360px;
height: var(--progress-height);
}
.progress-bar {
height: var(--progress-height);
display: flex;
flex-direction: column;
justify-content: center;
color: #fff;
text-align: center;
white-space: nowrap;
background-color: #007bff;
transition: width 0.6s ease;
position: absolute;
top: 0;
left: 0;
}
.progress-bar--low {
z-index: 1;
}
.progress-bar--high {
background-color: #ffc107;
}
.value-text {
font-size: 1.6rem;
font-weight: bolder;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
.color-low {
color: #007bff;
}
.color-high {
color: #ffc107;
}
.color-max {
color: #9725f4;
}
@keyframes pulse {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
.icon {
animation: pulse 1.5s infinite;
}
</style>
Loading

0 comments on commit 9648064

Please sign in to comment.