yantar/assets/Scripts/ui/equipmentListSwitch.ts
Georgy Shive 989ab48f13 кнопка скрытия/ отображения видимости
была переделана в менеджер отображения
списка, его дальнейшее скрытие будет
вызываться так окном детализации аварии
2025-03-05 18:55:57 +07:00

91 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _decorator, Component, Node, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('equipmentListSwitch')
export class equipmentListSwitch extends Component {
// Узел со списком оборудования
@property(Node)
public equipmentList: Node = null!;
// Узел дополнительной кнопки, которую будем скрывать/показывать
@property(Node)
public extraButton: Node = null!;
// Смещение по оси X для закрытого состояния списка
@property
public offsetX: number = 300;
// Длительность анимации
@property
public animationDuration: number = 0.3;
// Позиции для анимации списка
private openPos: Vec3 = new Vec3();
private closedPos: Vec3 = new Vec3();
// Исходный масштаб дополнительной кнопки (например, (1,1,1))
private buttonOriginalScale: Vec3 = new Vec3();
// Флаг, показывающий текущее состояние списка
isOnToggle: boolean = false;
start() {
// Сохраняем позицию списка как открытое положение
this.openPos = this.equipmentList.getPosition().clone();
// Вычисляем закрытое положение (смещение по оси X)
this.closedPos = new Vec3(this.openPos.x - this.offsetX, this.openPos.y, this.openPos.z);
// Изначально скрываем список, устанавливая его в закрытое положение
this.equipmentList.setPosition(this.closedPos);
this.equipmentList.active = false;
// Сохраняем исходный масштаб дополнительной кнопки
this.buttonOriginalScale = this.extraButton.getScale().clone();
// Предполагаем, что при старте кнопка видна
this.extraButton.active = true;
this.extraButton.setScale(this.buttonOriginalScale);
}
// Метод переключения состояния списка и дополнительной кнопки
public equipmentSwitch() {
if (this.isOnToggle) {
// Если список открыт, закрываем его
this.isOnToggle = false;
// Анимация закрытия списка
tween(this.equipmentList)
.to(this.animationDuration, { position: this.closedPos })
.call(() => {
this.equipmentList.active = false;
})
.start();
// Анимация появления дополнительной кнопки
// Сначала убеждаемся, что кнопка активна и её масштаб равен 0
this.extraButton.active = true;
this.extraButton.setScale(new Vec3(0, 0, 0));
tween(this.extraButton)
.to(this.animationDuration, { scale: this.buttonOriginalScale })
.start();
} else {
// Если список закрыт, открываем его
this.isOnToggle = true;
// Делаем список активным и ставим в закрытое положение перед анимацией
this.equipmentList.active = true;
this.equipmentList.setPosition(this.closedPos);
tween(this.equipmentList)
.to(this.animationDuration, { position: this.openPos })
.start();
// Анимация скрытия дополнительной кнопки: уменьшаем масштаб до 0
tween(this.extraButton)
.to(this.animationDuration, { scale: new Vec3(0, 0, 0) })
.call(() => {
this.extraButton.active = false;
})
.start();
}
}
}