mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-10-11 05:31:47 +08:00
refactor: 标题按钮操作添加索引参数
This commit is contained in:
parent
234ea701b7
commit
9139552e17
@ -38,8 +38,7 @@ import { adjustCover } from '../utils';
|
|||||||
const enum TitleButton {
|
const enum TitleButton {
|
||||||
StartGame,
|
StartGame,
|
||||||
LoadGame,
|
LoadGame,
|
||||||
Replay,
|
Replay
|
||||||
HardBack = -114514
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ButtonItem {
|
interface ButtonItem {
|
||||||
@ -54,7 +53,6 @@ interface ButtonOption {
|
|||||||
name: string;
|
name: string;
|
||||||
hard: string;
|
hard: string;
|
||||||
colorTrans: ITransitionedController<string>;
|
colorTrans: ITransitionedController<string>;
|
||||||
scale: ITransitionedController<number>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GameTitleProps extends DefaultProps, UIComponentProps {}
|
export interface GameTitleProps extends DefaultProps, UIComponentProps {}
|
||||||
@ -127,12 +125,11 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
});
|
});
|
||||||
// 返回按钮
|
// 返回按钮
|
||||||
hard.push({
|
hard.push({
|
||||||
code: TitleButton.HardBack,
|
code: -1,
|
||||||
color: '#aaa',
|
color: '#aaa',
|
||||||
name: '返回',
|
name: '返回',
|
||||||
hard: '',
|
hard: '',
|
||||||
colorTrans: transitionedColor('#fff', 400, hyper('sin', 'out'))!,
|
colorTrans: transitionedColor('#fff', 400, hyper('sin', 'out'))!
|
||||||
scale: transitioned(1, 400, hyper('sin', 'out'))!
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 声音设置按钮的颜色 */
|
/** 声音设置按钮的颜色 */
|
||||||
@ -216,13 +213,14 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
* 点击按钮时触发
|
* 点击按钮时触发
|
||||||
* @param code 选中的按钮的代码
|
* @param code 选中的按钮的代码
|
||||||
*/
|
*/
|
||||||
const clickButton = (code: number) => {
|
const clickButton = (code: number, index: number) => {
|
||||||
if (selectHard.value) {
|
if (selectHard.value) {
|
||||||
if (code === TitleButton.HardBack) {
|
if (index === hard.length - 1) {
|
||||||
|
// 选中了最后一个按钮
|
||||||
toggleHard();
|
toggleHard();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const item = hard.find(v => v.code === code)!;
|
const item = hard[index];
|
||||||
startGame(item.name);
|
startGame(item.name);
|
||||||
} else {
|
} else {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@ -278,7 +276,11 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
{ type: 'down' }
|
{ type: 'down' }
|
||||||
)
|
)
|
||||||
.realize('confirm', () => {
|
.realize('confirm', () => {
|
||||||
clickButton(selected.value);
|
if (selectHard.value) {
|
||||||
|
clickButton(hard[selected.value].code, selected.value);
|
||||||
|
} else {
|
||||||
|
clickButton(buttons[selected.value].code, selected.value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region 鼠标操作
|
//#region 鼠标操作
|
||||||
@ -294,10 +296,8 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
buttons.forEach((v, i) => {
|
buttons.forEach((v, i) => {
|
||||||
if (index !== i) {
|
if (index !== i) {
|
||||||
v.colorTrans.set('#fff');
|
v.colorTrans.set('#fff');
|
||||||
v.scale.set(1);
|
|
||||||
} else {
|
} else {
|
||||||
v.colorTrans.set(v.color);
|
v.colorTrans.set(v.color);
|
||||||
v.scale.set(1.1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
selected.value = index;
|
selected.value = index;
|
||||||
@ -390,7 +390,7 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
filter={buttonFilter}
|
filter={buttonFilter}
|
||||||
fillStyle={v.colorTrans.ref.value}
|
fillStyle={v.colorTrans.ref.value}
|
||||||
onEnter={() => enterMain(i)}
|
onEnter={() => enterMain(i)}
|
||||||
onClick={() => clickButton(v.code)}
|
onClick={() => clickButton(v.code, i)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -413,7 +413,7 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
|
|||||||
filter={buttonFilter}
|
filter={buttonFilter}
|
||||||
fillStyle={v.colorTrans.ref.value}
|
fillStyle={v.colorTrans.ref.value}
|
||||||
onEnter={() => enterHard(i)}
|
onEnter={() => enterHard(i)}
|
||||||
onClick={() => clickButton(v.code)}
|
onClick={() => clickButton(v.code, i)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
Loading…
Reference in New Issue
Block a user