Добавил дополнительные методы для вызова с учетом
состояния активации списка аварий , Добавил методы для закрытия и открытия, добавил кнопку закрытия, добавил анимации на открытие и закрытие
This commit is contained in:
parent
a6a033ae55
commit
8b91fe0657
File diff suppressed because it is too large
Load Diff
@ -62,7 +62,7 @@ export class ErrorManager extends Component {
|
||||
this.currentErrors.push(item.tag);
|
||||
this.errorItems.push(item);
|
||||
this.addErrorToUI(item);
|
||||
updated = true;
|
||||
updated = true;
|
||||
if (this.soundEnabled && this.disabledAlerts.indexOf(item.tag) === -1) {
|
||||
this.playAlertSound();
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { _decorator, Component, Label, Button, Node, Event } from "cc";
|
||||
import { _decorator, Component, Label, Button, Node, Event, systemEvent } from "cc";
|
||||
import { apiSensors } from "../stores/apiSensors";
|
||||
import { EquipmentManager } from "../stores/EquipmentManager";
|
||||
import { PulsatingHighlighter } from "../PulsatingHighlighter";
|
||||
import { CameraMover } from "../CameraMover";
|
||||
import { ErrorLazyLoadList } from "../ui/ErrorLazyLoadList";
|
||||
import { ErrorManager } from "../stores/ErrorManager";
|
||||
import { ToggleListButton } from "./ToggleListButton";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ -167,7 +168,10 @@ export class ItemButton extends Component {
|
||||
* Обработка клика по кнопке с числом аварий для элемента.
|
||||
* @param event Нажатие на кнопку с числом аварий.
|
||||
*/
|
||||
public onErrorClick(event?: Event) {
|
||||
/**
|
||||
* Обработка клика по кнопке с числом аварий для элемента.
|
||||
*/
|
||||
public onErrorClick(event?: Event) {
|
||||
console.log("Нажата кнопка Error для элемента:", this.itemData);
|
||||
if (!this.itemData) return;
|
||||
|
||||
@ -176,6 +180,16 @@ export class ItemButton extends Component {
|
||||
return;
|
||||
}
|
||||
ErrorLazyLoadList.instance.filterBySensor(this.itemData.name);
|
||||
|
||||
// Проверяем состояние списка через синглтон ToggleListButton
|
||||
if (ToggleListButton.instance) {
|
||||
// Если список выключен, включаем его
|
||||
if (!ToggleListButton.instance.equipmentList.active) {
|
||||
ToggleListButton.instance.toggleList();
|
||||
}
|
||||
} else {
|
||||
console.warn("ToggleListButton.instance не инициализирован!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,32 +1,103 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { _decorator, Component, Node, tween, Vec3 } from 'cc';
|
||||
import { ErrorLazyLoadList } from '../ui/ErrorLazyLoadList';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ToggleListButton')
|
||||
export class ToggleListButton extends Component {
|
||||
// Ссылка на узел списка, который нужно показать или скрыть
|
||||
// Синглтон-экземпляр
|
||||
public static instance: ToggleListButton = null!;
|
||||
|
||||
// Узел списка, который нужно показать или скрыть
|
||||
@property(Node)
|
||||
public equipmentList: Node = null!;
|
||||
|
||||
@property(Node)
|
||||
public viewCtrl : Node = null!;
|
||||
|
||||
// Флаг состояния списка (активен/не активен)
|
||||
// Флаг состояния списка (открыт/закрыт)
|
||||
private isListActive: boolean = false;
|
||||
|
||||
// Позиция, когда список виден (запоминается при загрузке)
|
||||
private visiblePos: Vec3 = new Vec3();
|
||||
|
||||
// Позиция, когда список скрыт (справа от видимой позиции)
|
||||
private hiddenPos: Vec3 = new Vec3();
|
||||
|
||||
// Длительность анимации в секундах
|
||||
@property
|
||||
public slideDuration: number = 0.2;
|
||||
|
||||
// Смещение по оси X для скрытого состояния (например, на сколько пикселей список смещается вправо)
|
||||
@property
|
||||
public slideOffset: number = 300;
|
||||
|
||||
onLoad() {
|
||||
// При загрузке сцены скрываем узел списка
|
||||
// Инициализируем синглтон
|
||||
ToggleListButton.instance = this;
|
||||
|
||||
if (this.equipmentList) {
|
||||
// Запоминаем позицию, где список должен находиться, когда он виден
|
||||
this.visiblePos = this.equipmentList.position.clone();
|
||||
// Вычисляем скрытую позицию – смещаем вправо от видимой позиции
|
||||
this.hiddenPos = this.visiblePos.clone();
|
||||
this.hiddenPos.x += this.slideOffset;
|
||||
|
||||
// Изначально помещаем список в скрытое состояние и деактивируем его
|
||||
this.equipmentList.setPosition(this.hiddenPos);
|
||||
this.equipmentList.active = false;
|
||||
this.isListActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Метод, который нужно вызвать при клике на кнопку
|
||||
eventClick() {
|
||||
if (this.equipmentList) {
|
||||
this.isListActive = !this.isListActive;
|
||||
this.equipmentList.active = this.isListActive;
|
||||
ErrorLazyLoadList.instance?.resetFilter();
|
||||
onDestroy() {
|
||||
if (ToggleListButton.instance === this) {
|
||||
ToggleListButton.instance = null!;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Переключение списка с анимацией.
|
||||
* Если список закрыт – открываем его с анимацией выезда.
|
||||
* Если открыт – закрываем его с анимацией заезда.
|
||||
*/
|
||||
public toggleList() {
|
||||
if (!this.equipmentList) return;
|
||||
|
||||
if (!this.equipmentList.active) {
|
||||
// Открываем список: активируем его, ставим в скрытую позицию и запускаем анимацию в видимую позицию
|
||||
this.equipmentList.active = true;
|
||||
this.equipmentList.setPosition(this.hiddenPos);
|
||||
tween(this.equipmentList)
|
||||
.to(this.slideDuration, { position: this.visiblePos })
|
||||
.start();
|
||||
this.isListActive = true;
|
||||
// Если нужно сбросить фильтр при открытии
|
||||
ErrorLazyLoadList.instance?.resetFilter();
|
||||
} else {
|
||||
// Закрываем список: анимируем его в скрытую позицию справа, затем деактивируем
|
||||
tween(this.equipmentList)
|
||||
.to(this.slideDuration, { position: this.hiddenPos })
|
||||
.call(() => {
|
||||
this.equipmentList.active = false;
|
||||
})
|
||||
.start();
|
||||
this.isListActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Гарантированное открытие списка (если он закрыт) и сброс фильтра.
|
||||
*/
|
||||
public openAndResetFilter() {
|
||||
if (!this.equipmentList) return;
|
||||
|
||||
if (!this.equipmentList.active) {
|
||||
// Активируем список, помещаем его в скрытую позицию и анимированно перемещаем в видимое положение
|
||||
this.equipmentList.active = true;
|
||||
this.equipmentList.setPosition(this.hiddenPos);
|
||||
tween(this.equipmentList)
|
||||
.to(this.slideDuration, { position: this.visiblePos })
|
||||
.start();
|
||||
this.isListActive = true;
|
||||
}
|
||||
// Сбрасываем фильтр независимо от состояния списка
|
||||
ErrorLazyLoadList.instance?.resetFilter();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user