From 43937c9a54d616f956762ebc7db2a247c3721e6d Mon Sep 17 00:00:00 2001
From: unanmed <1319491857@qq.com>
Date: Fri, 1 Dec 2023 21:46:18 +0800
Subject: [PATCH] feat: todo94
---
idea.md | 2 +-
src/panel/enemyCritical.vue | 18 ++++++++++++++----
src/plugin/ui/common.ts | 36 ++++++++++++++++++++++++++++++++++++
src/ui/fly.vue | 9 ++++++++-
4 files changed, 59 insertions(+), 6 deletions(-)
create mode 100644 src/plugin/ui/common.ts
diff --git a/idea.md b/idea.md
index f6f05c8..3cb82ba 100644
--- a/idea.md
+++ b/idea.md
@@ -91,7 +91,7 @@ dam4.png ---- 存档 59
[] 勇士身上显示攻防血
[] 优化地图拖动
[] 楼层转换加入随机小贴士
-[] ui 中如果元素发生改变,那么做出背景亮一下再熄灭的效果
+[x] ui 中如果元素发生改变,那么做出背景亮一下再熄灭的效果
[] 双击怪物手册拐点可以直接在拖动条上定位
[] 重构技能树结构
[] 技能树允许自动升级
diff --git a/src/panel/enemyCritical.vue b/src/panel/enemyCritical.vue
index 8a03d91..430f4be 100644
--- a/src/panel/enemyCritical.vue
+++ b/src/panel/enemyCritical.vue
@@ -45,7 +45,9 @@
isMobile ? '' : ' '
}}
- {{ format(addAtk * ratio) }}
+ {{
+ format(addAtk * ratio)
+ }}
- {{ format(addDef * ratio) }}
+ {{
+ format(addDef * ratio)
+ }}
- {{
(nowDamage[0] as number) < 0 && !has(enemy.damage)
? '=>'
@@ -80,7 +84,9 @@
isMobile ? '' : ' '
}}
- {{ format(nowDamage[1]) }}
+ {{
+ format(nowDamage[1])
+ }}
@@ -93,6 +99,7 @@ import Chart, { ChartConfiguration } from 'chart.js/auto';
import { has, setCanvasSize } from '../plugin/utils';
import { debounce } from 'lodash-es';
import { isMobile } from '../plugin/use';
+import { createChangable } from '@/plugin/ui/common';
const props = defineProps<{
fromBook?: boolean;
@@ -123,6 +130,8 @@ const allDef = ref(originDef);
// 加攻加防数量
const addAtk = ref(0);
const addDef = ref(0);
+const addAtkChangable = createChangable(addAtk).change;
+const addDefChangable = createChangable(addDef).change;
const originDamage = enemy.enemy.calDamage(core.status.hero).damage;
@@ -139,6 +148,7 @@ const nowDamage = computed(() => {
if (!isFinite(originDamage)) return [-dam, dam];
return [originDamage - dam, dam];
});
+const nowDamageChangable = createChangable(nowDamage, 1).change;
function generateChart(ele: HTMLCanvasElement, data: [number, number][]) {
Chart.defaults.color = '#aaa';
diff --git a/src/plugin/ui/common.ts b/src/plugin/ui/common.ts
new file mode 100644
index 0000000..7ebfa8e
--- /dev/null
+++ b/src/plugin/ui/common.ts
@@ -0,0 +1,36 @@
+import { Ref, ref, watch } from 'vue';
+import { nextFrame } from '../utils';
+
+interface ChangableValue {
+ change: Ref;
+ value: Ref;
+ stop: () => void;
+}
+
+/**
+ * 创建一个监听响应式变量更改的,可以用于Changable的监听器
+ * @param value 要监听的值
+ */
+export function createChangable(
+ value: Ref,
+ key?: keyof T
+): ChangableValue {
+ const change = ref(false);
+ const stop = watch(value, (n, o) => {
+ if (key) {
+ if (n[key] === o[key]) return;
+ }
+ if (change.value) {
+ change.value = false;
+ nextFrame(() => (change.value = true));
+ } else {
+ change.value = true;
+ }
+ });
+
+ return {
+ change,
+ value,
+ stop
+ };
+}
diff --git a/src/ui/fly.vue b/src/ui/fly.vue
index e197c3e..2e55398 100644
--- a/src/ui/fly.vue
+++ b/src/ui/fly.vue
@@ -66,7 +66,12 @@
@click="changeFloorByDelta(-1)"
class="button-text"
/>
- {{ title }}
+ {{ title }}
{
return core.status.maps[nowFloor.value].title;
});
+const titleChange = createChangable(title).change;
/**
* 绘制小地图