mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-26 11:25:59 +08:00
装备栏ui
This commit is contained in:
1 parent
1dc79595e8
commit
bde0a4d1c0
24 files changed
+824
-843
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { has } from '../utils';
|
||||
|
||||
/**
|
||||
* 获取所有装备
|
||||
*/
|
||||
export function getEquips() {
|
||||
return Object.entries(core.status.hero.items.equips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取装备增加的属性
|
||||
* @param equip 装备
|
||||
*/
|
||||
export function getAddStatus(equip: Equip) {
|
||||
const toGet = Object.assign({}, equip.value, equip.percentage);
|
||||
const keys = Object.keys(toGet);
|
||||
|
||||
return (
|
||||
<div class="equip-add-detail">
|
||||
{keys.map(v => {
|
||||
const value =
|
||||
(equip.value[v] ?? 0) +
|
||||
core.status.hero[v] * (equip.percentage[v] ?? 0);
|
||||
|
||||
return (
|
||||
<span style="display: flex">
|
||||
<span style="flex-basis: 50%">
|
||||
{core.getStatusLabel(v)}
|
||||
</span>
|
||||
|
||||
<span
|
||||
style={{
|
||||
color: value > 0 ? 'lightgreen' : 'lightsalmon'
|
||||
}}
|
||||
>
|
||||
{value > 0 ? `+${value}` : value}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前勇士属性,如果有选中的装备,会在后面追加显示增加量
|
||||
* @param nowEquip 当前选中的装备
|
||||
*/
|
||||
export function getNowStatus(nowEquip?: Equip) {
|
||||
const toShow = ['hp', 'lv', 'atk', 'def', 'mdef', 'mana', 'hpmax', 'money'];
|
||||
|
||||
return (
|
||||
<div id="hero-status">
|
||||
{toShow.map(v => {
|
||||
let status: string;
|
||||
if (v === 'up') status = core.getNextLvUpNeed()?.toString();
|
||||
else if (v === 'lv') status = core.getLvName() ?? '';
|
||||
else status = core.getRealStatus(v)?.toString();
|
||||
|
||||
let add = 0;
|
||||
if (has(nowEquip)) {
|
||||
add += nowEquip.value[v] ?? 0;
|
||||
const per = nowEquip.percentage[v] * core.getStatus(v);
|
||||
add += isNaN(per) ? 0 : per;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="hero-status-one">
|
||||
<span class="hero-status-label">
|
||||
{core.getStatusLabel(v)}
|
||||
</span>
|
||||
<div class="hero-status-value">
|
||||
<span style="margin-right: 20%">{status}</span>
|
||||
{add !== 0 && (
|
||||
<span
|
||||
style={{
|
||||
color:
|
||||
add > 0
|
||||
? 'lightgreen'
|
||||
: 'lightsalmon'
|
||||
}}
|
||||
>
|
||||
{add > 0 ? '+' + add : '-' + -add}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,9 +2,11 @@ import { sleep } from 'mutate-animate';
|
||||
import { Component, markRaw, ref, Ref, watch } from 'vue';
|
||||
import Book from '../ui/book.vue';
|
||||
import Toolbox from '../ui/toolbox.vue';
|
||||
import Equipbox from '../ui/equipbox.vue';
|
||||
|
||||
export const bookOpened = ref(false);
|
||||
export const toolOpened = ref(false);
|
||||
export const equipOpened = ref(false);
|
||||
|
||||
export const transition = ref(true);
|
||||
|
||||
@@ -13,7 +15,8 @@ let app: HTMLDivElement;
|
||||
/** ui声明列表 */
|
||||
const UI_LIST: [Ref<boolean>, Component][] = [
|
||||
[bookOpened, Book],
|
||||
[toolOpened, Toolbox]
|
||||
[toolOpened, Toolbox],
|
||||
[equipOpened, Equipbox]
|
||||
];
|
||||
|
||||
/** ui栈 */
|
||||
@@ -36,7 +39,7 @@ export default function init() {
|
||||
}
|
||||
});
|
||||
});
|
||||
return { uiStack, bookOpened, toolOpened, transition };
|
||||
return { uiStack, transition, bookOpened, toolOpened, equipOpened };
|
||||
}
|
||||
|
||||
async function showApp() {
|
||||
|
||||
+47
-27
@@ -20,27 +20,38 @@ export const isMobile = matchMedia('(max-width: 600px)').matches;
|
||||
|
||||
/**
|
||||
* 向一个元素添加拖拽事件
|
||||
* @param ele 目标元素
|
||||
* @param ele 目标元素,当为全局拖拽时,传入数组表示所有元素共用一个全局拖拽函数
|
||||
* @param fn 推拽时触发的函数,传入x y和鼠标事件或点击事件
|
||||
* @param ondown 鼠标按下时执行的函数
|
||||
* @param global 是否全局拖拽,即拖拽后鼠标或手指离开元素后是否依然视为正在拖拽
|
||||
*/
|
||||
export function useDrag(
|
||||
ele: HTMLElement,
|
||||
ele: HTMLElement | HTMLElement[],
|
||||
fn: DragFn,
|
||||
ondown?: DragFn,
|
||||
onUp?: (e: MouseEvent | TouchEvent) => void,
|
||||
onup?: (e: MouseEvent | TouchEvent) => void,
|
||||
global: boolean = false
|
||||
) {
|
||||
let down = false;
|
||||
ele.addEventListener('mousedown', e => {
|
||||
|
||||
const md = (e: MouseEvent) => {
|
||||
down = true;
|
||||
if (ondown) ondown(e.clientX, e.clientY, e);
|
||||
});
|
||||
ele.addEventListener('touchstart', e => {
|
||||
};
|
||||
const td = (e: TouchEvent) => {
|
||||
down = true;
|
||||
if (ondown) ondown(e.touches[0].clientX, e.touches[0].clientY, e);
|
||||
});
|
||||
};
|
||||
|
||||
if (ele instanceof Array) {
|
||||
ele.forEach(v => {
|
||||
v.addEventListener('mousedown', md);
|
||||
v.addEventListener('touchstart', td);
|
||||
});
|
||||
} else {
|
||||
ele.addEventListener('mousedown', md);
|
||||
ele.addEventListener('touchstart', td);
|
||||
}
|
||||
|
||||
const target = global ? document : ele;
|
||||
|
||||
@@ -56,35 +67,30 @@ export function useDrag(
|
||||
|
||||
const mouseUp = (e: MouseEvent) => {
|
||||
if (!down) return;
|
||||
onUp && onUp(e);
|
||||
onup && onup(e);
|
||||
down = false;
|
||||
};
|
||||
|
||||
const touchUp = (e: TouchEvent) => {
|
||||
if (!down) return;
|
||||
onUp && onUp(e);
|
||||
onup && onup(e);
|
||||
down = false;
|
||||
};
|
||||
|
||||
target.addEventListener(
|
||||
'mouseup',
|
||||
mouseUp as EventListenerOrEventListenerObject
|
||||
);
|
||||
target.addEventListener(
|
||||
'touchend',
|
||||
touchUp as EventListenerOrEventListenerObject
|
||||
);
|
||||
|
||||
if (target instanceof Array) {
|
||||
target.forEach(v => {
|
||||
v.addEventListener('mouseup', mouseUp);
|
||||
v.addEventListener('touchend', touchUp);
|
||||
v.addEventListener('mousemove', mouseFn);
|
||||
v.addEventListener('touchmove', touchFn);
|
||||
});
|
||||
} else {
|
||||
target.addEventListener('mouseup', mouseUp as EventListener);
|
||||
target.addEventListener('touchend', touchUp as EventListener);
|
||||
target.addEventListener('mousemove', mouseFn as EventListener);
|
||||
target.addEventListener('touchmove', touchFn as EventListener);
|
||||
}
|
||||
dragFnMap.set(fn, [mouseFn, touchFn, mouseUp, touchUp]);
|
||||
|
||||
target.addEventListener(
|
||||
'mousemove',
|
||||
mouseFn as EventListenerOrEventListenerObject
|
||||
);
|
||||
target.addEventListener(
|
||||
'touchmove',
|
||||
touchFn as EventListenerOrEventListenerObject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,3 +137,17 @@ export function useUp(ele: HTMLElement, fn: DragFn): void {
|
||||
fn(e.touches[0].clientX, e.touches[0].clientY, e);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 当鼠标或手指按下时执行函数
|
||||
* @param ele 目标元素
|
||||
* @param fn 当鼠标或手指按下时执行的函数
|
||||
*/
|
||||
export function useDown(ele: HTMLElement, fn: DragFn): void {
|
||||
ele.addEventListener('mousedown', e => {
|
||||
fn(e.clientX, e.clientY, e);
|
||||
});
|
||||
ele.addEventListener('touchstart', e => {
|
||||
fn(e.touches[0].clientX, e.touches[0].clientY, e);
|
||||
});
|
||||
}
|
||||
+10
-3
@@ -73,7 +73,7 @@ export function parseCss(css: string): Partial<Record<CanParseCss, string>> {
|
||||
|
||||
for (const one of styles) {
|
||||
const [key, data] = one.split(':');
|
||||
const cssKey = key.replace(/\-([a-z])/g, $1 =>
|
||||
const cssKey = key.replace(/\-([a-z])/g, (str, $1) =>
|
||||
$1.toUpperCase()
|
||||
) as CanParseCss;
|
||||
res[cssKey] = data;
|
||||
@@ -84,16 +84,22 @@ export function parseCss(css: string): Partial<Record<CanParseCss, string>> {
|
||||
/**
|
||||
* 使用打字机效果显示一段文字
|
||||
* @param str 要打出的字符串
|
||||
* @param time 打出总用时,默认1秒
|
||||
* @param time 打出总用时,默认1秒,当第四个参数是true时,该项为每个字的平均时间
|
||||
* @param timing 打出时的速率曲线,默认为线性变化
|
||||
* @param avr 是否将第二个参数视为每个字的平均时间
|
||||
* @returns 文字的响应式变量
|
||||
*/
|
||||
export function type(
|
||||
str: string,
|
||||
time: number = 1000,
|
||||
timing: TimingFn = n => n
|
||||
timing: TimingFn = n => n,
|
||||
avr: boolean = false
|
||||
): Ref<string> {
|
||||
const toShow = eval('`' + str + '`') as string;
|
||||
if (typeof toShow !== 'string') {
|
||||
throw new TypeError('Error str type in typing!');
|
||||
}
|
||||
if (avr) time *= toShow.length;
|
||||
const ani = new Animation();
|
||||
const content = ref('');
|
||||
const all = toShow.length;
|
||||
@@ -104,6 +110,7 @@ export function type(
|
||||
content.value = toShow.slice(0, Math.floor(now));
|
||||
if (Math.floor(now) === all) {
|
||||
ani.ticker.destroy();
|
||||
content.value = toShow;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user