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.
164 lines
7.1 KiB
164 lines
7.1 KiB
|
|
import { Observable, Observer } from "@babylonjs/core"; |
|
import { Game } from "../../game"; |
|
import { BuildingType, BuildingData } from "../../model/data/institution/building/building-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 } from "../../model/info/building/building-info"; |
|
import { GizmoTool } from "../../tool/gizmo-tool"; |
|
import { BuildingUIItem } from "../../view/building-window/building-ui-item"; |
|
import { BuildingWindow } from "../../view/building-window/building-window"; |
|
import { FacilityWindow } from "../../view/facility-window/facility-window"; |
|
import { FacilityInfoInSceneWindow } from "../../view/facilityinfoinscene-window/facilityinfoinscene-window"; |
|
import { MarkWindow } from "../../view/mark-window/mark-window"; |
|
import { ToolbarWindow } from "../../view/toolbar-window/toobar-window"; |
|
|
|
import { DataManager, ModelChangeType } from "../data-manager"; |
|
import { EventManager } from "../event-manager/event-manager"; |
|
import { Event_ChangeFacility } from "../event-manager/events/event-change-facility"; |
|
import { InfoManager } from "../info-manager"; |
|
import { ModeManager, ModeType } from "../mode-manager"; |
|
import { SceneManager } from "../scene-manager"; |
|
import { UIManager } from "../ui-manager"; |
|
import { StatusBase, StatusManager } from "./status-manager"; |
|
|
|
//建筑物外观模式 |
|
export class BuildingStatus extends StatusBase { |
|
buildingWindow: BuildingWindow; |
|
currentBuildingInfo: BuildingInfo; //当前的建筑 |
|
onChangeFacilityObserver: Observer<Event_ChangeFacility>; |
|
|
|
static changeStatusFromUI: boolean = false;//因为ui而切换 |
|
static startEnterObservable: Observable<BuildingUIItem> = new Observable<BuildingUIItem>();//开始切入 |
|
static enterSuccessObservable: Observable<BuildingUIItem> = new Observable<BuildingUIItem>();//进入成功的事件 |
|
|
|
|
|
//#region |
|
/** |
|
* 在数据层创建建筑 |
|
* @param key 唯一key,来自服务器分配 |
|
* @param name 名称,由玩家自定义 |
|
* @param buildingType 建筑类型 |
|
*/ |
|
createOneBuildingInData(key: string, name: string, buildingType: BuildingType): BuildingData { |
|
return DataManager.createBuilding(key, name, buildingType); |
|
} |
|
//#endregion |
|
|
|
//#region 生命周期 |
|
//初始化 |
|
onCreate() { |
|
super.onCreate(); |
|
// this.enterSuccessObservable = new Observable<BuildingUIItem>(); |
|
GizmoTool.init(SceneManager.Instance.scene, UIManager.Instance.uiRoot, SceneManager.Instance.defaultCamera); |
|
InfoManager.init(); |
|
//UIManager.open<InputHintWindow>(InputHintWindow); |
|
UIManager.open<ToolbarWindow>(ToolbarWindow); |
|
} |
|
//进入状态 |
|
onEnter() { |
|
super.onEnter(); |
|
Game.instance.engine.resize(); |
|
|
|
//首次进入 |
|
if (this.buildingWindow == null) { |
|
SceneManager.s_facilityWindow = UIManager.open<FacilityWindow>(FacilityWindow); |
|
if (ModeManager.currentMode == ModeType.Look) { |
|
//此处应改为由前端调用, 退出编辑状态时应调用hide |
|
// SceneManager.s_markWindow = MarkWindow.openWindow(); |
|
} |
|
|
|
this.buildingWindow = UIManager.open<BuildingWindow>(BuildingWindow); |
|
|
|
SceneManager.s_facilityInfoInSceneWindow = UIManager.open<FacilityInfoInSceneWindow>(FacilityInfoInSceneWindow); |
|
|
|
} |
|
else { //从室内返回 |
|
UIManager.show<BuildingWindow>(this.buildingWindow); |
|
if (this.buildingWindow.currentBuidngItem != null) { |
|
this.buildingWindow.currentBuidngItem.select(); |
|
BuildingStatus.startEnterObservable.notifyObservers(this.buildingWindow.currentBuidngItem); |
|
BuildingStatus.enterSuccessObservable.notifyObservers(this.buildingWindow.currentBuidngItem) |
|
if (MarkWindow.s_cameraData == null) { |
|
this.buildingWindow.currentBuidngItem.lookAt(); |
|
} |
|
else { |
|
|
|
MarkWindow.s_cameraData.setDataToCamera(SceneManager.Instance.defaultCamera); |
|
MarkWindow.s_cameraData = null; |
|
} |
|
|
|
FacilityInfoInSceneWindow.instance.createAllFacilities(this.buildingWindow.currentBuidngItem.buildingInfo.ModelInfo.facilityInfos); |
|
if (ModeManager.currentMode == ModeType.Look) { |
|
FacilityInfoInSceneWindow.instance.showFacilityByType(null, false); |
|
} |
|
} |
|
} |
|
|
|
SceneManager.s_facilityWindow.updateAllFacilities(FacilityPosType.Outdoor); |
|
|
|
let instance = this; |
|
this.onChangeFacilityObserver = EventManager.addListener<Event_ChangeFacility>(Event_ChangeFacility, ((eventInfo) => { |
|
instance.onChangeFacility(eventInfo); |
|
})); |
|
|
|
SceneManager.Instance.sunLight.intensity = 3; |
|
} |
|
//退出状态 |
|
onExit() { |
|
UIManager.hide<BuildingWindow>(this.buildingWindow); |
|
// console.log("==退出buildingStatus=="); |
|
EventManager.removeListener(Event_ChangeFacility, this.onChangeFacilityObserver); |
|
super.onExit(); |
|
} |
|
|
|
//#endregion |
|
|
|
//改变当前选中的建筑 |
|
changeCurrentBuilding(buildingInfo: BuildingInfo) { |
|
|
|
if (buildingInfo == this.currentBuildingInfo) { |
|
return; |
|
} |
|
|
|
// console.log("改变当前建筑" + buildingInfo.buildingData.normalData.key); |
|
//FacilityInfoInSceneWindow.instance.clearFacilityInfoUIItemes(); |
|
if (this.currentBuildingInfo != null) { |
|
// this.buildingWindow.clearFacilityInfos(this.currentBuildingInfo); |
|
//隐藏 |
|
this.buildingWindow.showFacilityInfosIcon(this.currentBuildingInfo, false); |
|
} |
|
|
|
this.currentBuildingInfo = buildingInfo; |
|
|
|
|
|
FacilityInfoInSceneWindow.instance.createAllFacilities(buildingInfo.ModelInfo.facilityInfos); |
|
if (this.currentBuildingInfo.ModelInfo.facilityInfos != null && ModeManager.currentMode == ModeType.Edit) { |
|
//判断已经有了就不创建了 |
|
// InfoManager.createFacilityInfos(buildingInfo.buildingData.outdoorData, buildingInfo); |
|
//显示 |
|
this.buildingWindow.showFacilityInfosIcon(this.currentBuildingInfo, true); |
|
} |
|
|
|
} |
|
|
|
//模型变化 |
|
onChangeFacility(eventInfo: Event_ChangeFacility) { |
|
if (eventInfo.modeleData instanceof ModelData_facility) { |
|
let modelEditData: ModelEditData; |
|
if (StatusManager.s_currentStatus instanceof BuildingStatus) { |
|
modelEditData = this.currentBuildingInfo.buildingData.outdoorData; |
|
} |
|
|
|
if (eventInfo.modelChangeType == ModelChangeType.Add) { |
|
modelEditData.addFacility(eventInfo.modeleData); |
|
// console.log("添加设备数据" + eventInfo.modeleData.key); |
|
} |
|
else if (eventInfo.modelChangeType == ModelChangeType.Remove) { |
|
modelEditData.removeFacility(eventInfo.modeleData); |
|
|
|
// console.log("移除设备数据" + eventInfo.modeleData.key); |
|
} |
|
} |
|
} |
|
} |