refactor: uhu

This commit is contained in:
hypercross 2026-03-01 14:34:40 +08:00
parent fa1c6d19e9
commit 306a46b62b
4 changed files with 62 additions and 5 deletions

View File

@ -1,4 +1,6 @@
command,parameter,label,description,insertedText
roll,emmet,2d6,2D6,2d6
roll,emmet,d20,D20,d20
track,emmet,monk,破戒佛爷,"破戒佛爷.bandit.monk[gd=4/4,str=14/14,cla=10,spi=8]"
track,emmet,bandit,龙虎寨山贼,"龙虎寨山贼.bandit[gd=2/2,str=10/10,cla=10,spi=10]"
track,emmet,khitan,契丹护卫,"契丹护卫.khitan.guard[gd=4/4,ap=2,str=14/14,cla=14,spi=14]"
1 command parameter label description insertedText
2 roll emmet 2d6 2D6 2d6
3 roll emmet d20 D20 d20
4 track emmet monk 破戒佛爷 破戒佛爷.bandit.monk[gd=4/4,str=14/14,cla=10,spi=8]
5 track emmet bandit 龙虎寨山贼 龙虎寨山贼.bandit[gd=2/2,str=10/10,cla=10,spi=10]
6 track emmet khitan 契丹护卫 契丹护卫.khitan.guard[gd=4/4,ap=2,str=14/14,cla=14,spi=14]

View File

@ -32,6 +32,24 @@ export const AttributeTooltip: Component<AttributeTooltipProps> = (props) => {
props.onUpdate(attrName, { ...attr, value });
};
// 处理滚轮增减progress 和 count 类型)
const handleWheel = (e: WheelEvent, attrName: string, attr: TrackerAttribute) => {
e.preventDefault();
e.stopPropagation();
if (attr.type === "count") {
const delta = e.deltaY > 0 ? -1 : 1;
const newValue = Math.max(0, (attr.value as number) + delta);
handleUpdate(attrName, newValue);
} else if (attr.type === "progress") {
const val = attr.value as { x: number; y: number };
const delta = e.deltaY > 0 ? -1 : 1;
// 滚轮向上/下调整当前值 x
const newX = Math.max(0, Math.min(val.y, val.x + delta));
handleUpdate(attrName, { x: newX, y: val.y });
}
};
// 添加 class
const handleAddClass = () => {
const className = newClass().trim();
@ -56,7 +74,11 @@ export const AttributeTooltip: Component<AttributeTooltipProps> = (props) => {
return (
<div class="flex flex-col gap-1">
{/* 进度条 */}
<div class="w-full h-4 bg-gray-200 rounded-full overflow-hidden">
<div
class="w-full h-4 bg-gray-200 rounded-full overflow-hidden cursor-pointer"
title="滚动鼠标滚轮增减"
onWheel={(e) => handleWheel(e, attrName, attr)}
>
<div
class="h-full bg-gradient-to-r from-blue-500 to-blue-600 transition-all duration-200"
style={{ width: `${Math.min(100, percentage)}%` }}
@ -68,6 +90,7 @@ export const AttributeTooltip: Component<AttributeTooltipProps> = (props) => {
type="number"
value={val.x}
onChange={(e) => handleUpdate(attrName, { x: parseInt(e.target.value) || 0, y: val.y })}
onWheel={(e) => handleWheel(e, attrName, attr)}
class="w-14 px-1 py-0.5 border border-gray-300 rounded text-center text-sm"
min="0"
/>
@ -87,7 +110,11 @@ export const AttributeTooltip: Component<AttributeTooltipProps> = (props) => {
if (attr.type === "count") {
const value = attr.value as number;
return (
<div class="flex items-center gap-1">
<div
class="flex items-center gap-1"
onWheel={(e) => handleWheel(e, attrName, attr)}
title="滚动鼠标滚轮增减"
>
<button
class="w-7 h-7 flex items-center justify-center bg-gray-200 hover:bg-gray-300 rounded text-lg font-bold transition-colors"
onClick={() => handleUpdate(attrName, value - 1)}
@ -98,6 +125,7 @@ export const AttributeTooltip: Component<AttributeTooltipProps> = (props) => {
type="number"
value={value}
onChange={(e) => handleUpdate(attrName, parseInt(e.target.value) || 0)}
onWheel={(e) => handleWheel(e, attrName, attr)}
class="w-12 px-1 py-0.5 border border-gray-300 rounded text-center text-sm"
min="0"
/>

View File

@ -40,7 +40,7 @@ export const CommanderEntries: Component<CommanderEntriesProps> = (props) => {
<div class="border-l-2 border-gray-300 pl-3 py-1">
<div class="flex items-center justify-between text-xs text-gray-500 mb-1">
<span
class="font-mono cursor-pointer hover:text-blue-600 hover:underline"
class="font-mono cursor-pointer hover:text-blue-600 hover:underline truncate max-w-64"
onClick={() => handleCommandClick(entry.command)}
title="点击复制到输入框"
>

View File

@ -34,6 +34,23 @@ export const TrackerView: Component<TrackerViewProps> = (props) => {
return `${name}=${val}`;
};
// 处理滚轮增减progress 和 count 类型)
const handleWheel = (e: WheelEvent, index: number, attrName: string, attr: TrackerAttribute) => {
e.preventDefault();
e.stopPropagation();
if (attr.type === "count") {
const delta = e.deltaY > 0 ? -1 : 1;
const newValue = Math.max(0, (attr.value as number) + delta);
props.onEditAttribute?.(index, attrName, { ...attr, value: newValue });
} else if (attr.type === "progress") {
const val = attr.value as { x: number; y: number };
const delta = e.deltaY > 0 ? -1 : 1;
const newX = Math.max(0, Math.min(val.y, val.x + delta));
props.onEditAttribute?.(index, attrName, { ...attr, value: { x: newX, y: val.y } });
}
};
const handleTagClick = (e: MouseEvent, index: number) => {
e.preventDefault();
e.stopPropagation();
@ -91,8 +108,18 @@ export const TrackerView: Component<TrackerViewProps> = (props) => {
</Show>
{/* 属性简写显示 */}
<Show when={Object.keys(item.attributes).length > 0}>
<span class="text-xs text-gray-500 font-mono whitespace-nowrap truncate">
[{Object.entries(item.attributes).map(([k, v]) => formatAttributeShort(k, v)).join(" ")}]
<span class="text-xs text-gray-500 font-mono whitespace-nowrap truncate flex gap-2">
<For each={Object.entries(item.attributes)}>
{([name, attr]) => (
<span
class="inline-block cursor-pointer hover:text-blue-600 hover:underline"
title={`${name}: ${formatAttributeValue(attr)} - 滚动鼠标滚轮增减`}
onWheel={(e) => handleWheel(e, index(), name, attr)}
>
{formatAttributeShort(name, attr)}{" "}
</span>
)}
</For>
</span>
</Show>
</div>