中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

127 lines
4.7 KiB

import { Observable, Observer } from "@babylonjs/core";
import { BuildingData_Normal } from "../../model/data/institution/building/building-data";
import { ModelData } from "../../model/data/model-data/model-data";
import { FacilityPosType, ModelData_facility } from "../../model/data/model-data/model-data-facility";
import { ModelEditData } from "../../model/data/model-data/model-edit-data";
import { BuildingInfo_Normal } from "../../model/info/building/building-info-normal";
import { GizmoTool } from "../../tool/gizmo-tool";
import { IndoorFloorUIItem } from "../../view/indoor-window/indoor-floorui-item";
import { IndoorWindow } from "../../view/indoor-window/indoor-window";
import { ModelChangeType } from "../data-manager";
import { EventManager } from "../event-manager/event-manager";
import { Event_ChangeFacility } from "../event-manager/events/event-change-facility";
import { SceneManager } from "../scene-manager";
import { UIManager } from "../ui-manager";
import { StatusBase, StatusManager } from "./status-manager";
//室内模式
export class IndoorStatus extends StatusBase {
buildingInfo: BuildingInfo_Normal;
indoorWindow: IndoorWindow;
//indoorInfos:BuildingInfo[];//室内信息(运行时)
indoorData: BuildingData_Normal; //室内信息(纯数据)
onChangeFacilityObserver: Observer<Event_ChangeFacility>;
static changeStatusFromUI: boolean = false;//因为ui而切换
static startEnterObservable: Observable<IndoorFloorUIItem> = new Observable<IndoorFloorUIItem>();//开始切入
static enterSuccessObservable: Observable<IndoorFloorUIItem> = new Observable<IndoorFloorUIItem>();//进入成功的事件
//初始化
onCreate() {
super.onCreate();
// this.enterSuccessObservable = new Observable<IndoorFloorUIItem>();
}
//进入状态
onEnter() {
super.onEnter();
if (this.indoorWindow == null) {
this.indoorWindow = UIManager.open<IndoorWindow>(IndoorWindow);
} else {
UIManager.show<IndoorWindow>(this.indoorWindow);
}
let instance = this;
this.onChangeFacilityObserver = EventManager.addListener<Event_ChangeFacility>(Event_ChangeFacility, (eventInfo) => {
instance.onChangeFacility(eventInfo);
})
GizmoTool.onPickMeshInfoObservable.notifyObservers(null);//取消之前的选中
SceneManager.s_facilityInfoInSceneWindow.clearFacilityInfoUIItemes();//先清空
SceneManager.s_facilityWindow.updateAllFacilities(FacilityPosType.Indoor);
SceneManager.Instance.sunLight.intensity = 1;
}
//退出状态
onExit() {
EventManager.removeListener(Event_ChangeFacility, this.onChangeFacilityObserver);
UIManager.hide<IndoorWindow>(this.indoorWindow);
this.clearIndoorInfo();
super.onExit();
}
init(buildingInfo: BuildingInfo_Normal, key: string) {
this.buildingInfo = buildingInfo;
this.indoorData = buildingInfo.buildingData as BuildingData_Normal;
this.indoorWindow.initAllFloor(this.indoorData.indoorsData, key);
}
//清空室内运行时信息
clearIndoorInfo() {
console.log('清空室内');
this.indoorWindow.clearAllFloorUIItem();
if (this.indoorWindow.currentFloorUIItem != null &&
this.indoorWindow.currentFloorUIItem.buildingInfo != null) {
GizmoTool.leaveTheGizmoAim(this.indoorWindow.currentFloorUIItem.buildingInfo.ModelInfo);
}
this.indoorWindow.currentFloorUIItem = null;
}
//模型Data数据变化
onChangeFacility(eventInfo: Event_ChangeFacility) {
if (eventInfo.modeleData instanceof ModelData_facility) {
let modelEditData: ModelEditData;
modelEditData = (StatusManager.s_currentStatus as IndoorStatus)
.indoorWindow.currentFloorUIItem.modelEditData;
if (eventInfo.modelChangeType == ModelChangeType.Add) {
modelEditData.addFacility(eventInfo.modeleData);
} else if (eventInfo.modelChangeType == ModelChangeType.Remove) {
modelEditData.removeFacility(eventInfo.modeleData);
}
}
}
//创建新的室内数据
newIndoorData(key: string, name: string, isRefugeFloor: boolean): ModelEditData {
let newIndoorData = new ModelEditData();
newIndoorData.modelData = new ModelData();
newIndoorData.modelData.key = key;
newIndoorData.modelData.name = name;
newIndoorData.isRefugeFloor = isRefugeFloor;
return newIndoorData;
}
//将新的室内添加到当前建筑中
addNewIndoorToBuilding(newIndoorData: ModelEditData) {
let buildingData = this.buildingInfo.buildingData as BuildingData_Normal;
if (buildingData.indoorsData == null) {
buildingData.indoorsData = [];
}
newIndoorData.index = buildingData.getNextIndoorIndex();
//设置index为最大+1
buildingData.indoorsData.push(newIndoorData);
}
}