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.
282 lines
9.1 KiB
282 lines
9.1 KiB
import { AbstractMesh, Color3, EventState, Mesh } from "@babylonjs/core"; |
|
import { Button, Control, Ellipse, Rectangle, TextBlock, Vector2WithInfo } from "@babylonjs/gui"; |
|
import { ConfigManager } from "src/app/babylon/controller/config-manager"; |
|
import { SceneManager } from "src/app/babylon/controller/scene-manager"; |
|
import { UIManager } from "src/app/babylon/controller/ui-manager"; |
|
import { BabylonUIStyleTool } from "src/app/babylon/tool/babylon-ui-style-tool"; |
|
import { SpeakingTool } from "src/app/babylon/tool/speaking-tool"; |
|
import { TsTool } from "src/app/babylon/tool/ts-tool"; |
|
import { FacilityWindow } from "src/app/babylon/view/facility-window/facility-window"; |
|
import { FacilityInfoInSceneWindow } from "src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window"; |
|
import { PropertyBaseWindow } from "src/app/babylon/view/property-window/property-base-window"; |
|
import { ModelData } from "../../data/model-data/model-data"; |
|
import { FacilityPosType, FacilityShowType, FacilityType, ModelData_facility } from "../../data/model-data/model-data-facility"; |
|
import { BuildingInfo } from "../building/building-info"; |
|
import { AreaInfo } from "./facilityinfo-tool/facility-area"; |
|
|
|
import { ModelInfo } from "./model-info"; |
|
|
|
//设施数据 |
|
export class ModelInfo_facility extends ModelInfo { |
|
|
|
static readonly c_hightLightColor = Color3.Yellow(); |
|
|
|
belongToBuilding: BuildingInfo;//属于哪个建筑 |
|
pickDown: boolean;//按下 |
|
facilityShowType: FacilityShowType;//设备展示状态 |
|
ui_select: Ellipse | Rectangle; |
|
areaInfo: AreaInfo;//区域信息 |
|
isNew: boolean;//是否是新建 |
|
|
|
nameUIRoot: Rectangle; |
|
nameText: TextBlock; |
|
|
|
|
|
constructor( |
|
key: string, |
|
modelData: ModelData, |
|
models: AbstractMesh[], |
|
modelBox: AbstractMesh, |
|
belongToBuilding: BuildingInfo, |
|
isNew: boolean |
|
) { |
|
super(key, modelData, models, modelBox); |
|
this.facilityShowType = ModelData_facility.getShowType((modelData as ModelData_facility).facilityType); |
|
this.belongToBuilding = belongToBuilding; |
|
this.isNew = isNew; |
|
} |
|
|
|
onCreateFollowUI() { |
|
let facilityData = this.modelData as ModelData_facility; |
|
if (!ConfigManager.getFacilityNeedIcon(facilityData.facilityType)) { |
|
return; |
|
} |
|
super.onCreateFollowUI(); |
|
let instance = this; |
|
|
|
let posType = ConfigManager.getPosType(facilityData.facilityType); |
|
let iconPath = ConfigManager.getFacilityIconUrl(facilityData.facilityType, posType); |
|
BabylonUIStyleTool.setStyle_size(this.uiFollowRoot, ConfigManager.c_size_facilityIconSize + "px", ConfigManager.c_size_facilityIconSize + "px"); |
|
this.uiFollowRoot.thickness = 0; |
|
|
|
|
|
this.ui_select = new Ellipse("select"); |
|
|
|
|
|
this.uiFollowRoot.addControl(this.ui_select); |
|
this.ui_select.background = BabylonUIStyleTool.c_color_3d_blue; |
|
this.ui_select.thickness = 0; |
|
this.ui_select.width = 0.8; |
|
this.ui_select.height = 0.8; |
|
this.ui_select.shadowColor = BabylonUIStyleTool.c_color_3d_blue; |
|
this.ui_select.shadowBlur = 3; |
|
this.ui_select.isVisible = false; |
|
|
|
this.uiIconBtn = Button.CreateImageButton("iconPath", "", iconPath); |
|
this.uiIconBtn.thickness = 0; |
|
this.uiIconBtn.image.width = 0.9; |
|
this.uiIconBtn.image.height = 0.9; |
|
this.uiIconBtn.image.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER; |
|
this.uiIconBtn.image.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER; |
|
this.uiFollowRoot.addControl(this.uiIconBtn); |
|
|
|
//BabylonUIStyleTool.addLongPressButtonBehave(this.uiIconBtn, SceneManager.Instance.scene, () => { |
|
// instance.askDelete(instance); |
|
// }, () => { |
|
// // instance.onClickMeshIconBtn(null, null); |
|
// instance.onStopLongPress(null, null); |
|
// }) |
|
|
|
this.uiIconBtn.onPointerClickObservable.add(() => { |
|
instance.onStopLongPress(null, null); |
|
}); |
|
|
|
//双击,拉近镜头 |
|
BabylonUIStyleTool.addDoubleClickButtonBehave(this.uiIconBtn, SceneManager.Instance.scene, () => { |
|
let item = FacilityInfoInSceneWindow.instance.getFacilityItem(instance); |
|
if (item != null) { |
|
item.lookAt(); |
|
} |
|
|
|
}); |
|
|
|
this.uiFollowRoot.zIndex = BabylonUIStyleTool.c_zIndex_facilityIcon; |
|
|
|
if (facilityData.posType == FacilityPosType.In) { |
|
this.showFollowUI(false); //内置设备,默认隐藏 |
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
* 显示名称UI |
|
* @param show |
|
*/ |
|
showNameUI(show: boolean) { |
|
let data = this.modelData as ModelData_facility; |
|
if (this.nameUIRoot == null) { |
|
this.nameUIRoot = new Rectangle("nameRoot"); |
|
this.nameUIRoot.thickness = 0; |
|
this.nameUIRoot.background = BabylonUIStyleTool.c_color_blueBtnBg; |
|
this.nameUIRoot.color = BabylonUIStyleTool.c_color_blue;//"#0CB7F7"; |
|
this.nameUIRoot.alpha = 0.9; |
|
UIManager.Instance.uiRoot.addControl(this.nameUIRoot); |
|
this.nameUIRoot.width = '50px'; |
|
this.nameUIRoot.height = '26px'; |
|
this.nameUIRoot.thickness = 2; |
|
this.nameUIRoot.linkWithMesh(this.head); |
|
|
|
this.nameText = new TextBlock("name", ""); |
|
this.nameUIRoot.addControl(this.nameText); |
|
this.nameText.color = "white"; |
|
this.nameText.resizeToFit = true; |
|
this.nameText.top = "2px"; |
|
this.nameText.fontSize = 16; |
|
this.nameText.textVerticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER; |
|
} |
|
this.nameText.text = data.propertyData.name; |
|
this.nameUIRoot.isVisible = show; |
|
|
|
let instance = this; |
|
setTimeout(() => { |
|
instance.nameUIRoot.widthInPixels = instance.nameText.widthInPixels + 10; |
|
instance.nameUIRoot.heightInPixels = instance.nameText.heightInPixels + 5; |
|
}, 100); |
|
|
|
} |
|
|
|
|
|
//询问删除 |
|
askDelete(modelInfo: ModelInfo_facility, ask = true) { |
|
if (ask) { |
|
// ThreeDimensionalHomeComponent.instance.deleteProperty(() => { |
|
// FacilityWindow.instance.disposeFacility(modelInfo); |
|
// }, modelInfo.key); |
|
} |
|
else { //直接删除 |
|
FacilityWindow.instance.disposeFacility(modelInfo); |
|
} |
|
|
|
} |
|
|
|
//终止长按 |
|
onStopLongPress(eventData: Vector2WithInfo, eventState: EventState) { |
|
// this.onClickMeshIconBtn(eventData,eventState); |
|
FacilityInfoInSceneWindow.instance.selectFacilityInfo(this); |
|
|
|
// SpeakingTool.Instance.speak("你好世界"); |
|
} |
|
|
|
//展示属性 |
|
showProperty() { |
|
PropertyBaseWindow.ShowWindow(this); |
|
} |
|
|
|
onSetModelBox() { |
|
super.onSetModelBox(); |
|
} |
|
|
|
|
|
setEnable(enable: boolean) { |
|
super.setEnable(enable); |
|
if (this.areaInfo != null) { |
|
this.areaInfo.setEnable(enable); |
|
} |
|
|
|
|
|
} |
|
|
|
/** |
|
* 设置选中圈的显示状态 |
|
* @param enable |
|
*/ |
|
setSelectEnable(enable: boolean) { |
|
if (this.ui_select != null) { |
|
this.ui_select.isVisible = enable; |
|
} |
|
|
|
} |
|
|
|
/** |
|
* 设置整个Icon的显示状态 |
|
* @param enable |
|
*/ |
|
setIconEnable(enable: boolean) { |
|
this.showFollowUI(enable); |
|
|
|
if (!enable)//还原选中状态 |
|
{ |
|
this.setSelectEnable(false); |
|
} |
|
} |
|
|
|
/** |
|
* 播放展示动画(高亮) |
|
* @param play false表示停止,并恢复正常 |
|
*/ |
|
playShowAnim(play: boolean) { |
|
this.showFollowUI(play); |
|
if (this.modelBox != null) { |
|
if (play) { |
|
SceneManager.Instance.addToHighLight(this.modelBox as Mesh, ModelInfo_facility.c_hightLightColor); |
|
} |
|
else { |
|
SceneManager.Instance.removeFromHighLight(this.modelBox as Mesh); |
|
} |
|
|
|
let facilityData = this.modelData as ModelData_facility; |
|
|
|
if (facilityData.facilityType == FacilityType.JY_SYGX || facilityData.facilityType == FacilityType.JY_YQHSGX) { |
|
|
|
let allChildren = this.modelBox.getChildMeshes(); |
|
for (let i = 0; i < allChildren.length; i++) { |
|
if (TsTool.stringContain(allChildren[i].name, "UV")) { |
|
allChildren[i].setEnabled(play); |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
|
|
|
|
dispose(disposeMesh?: boolean) { |
|
if (this.areaInfo != null) { |
|
this.areaInfo.dispose(); |
|
|
|
} |
|
|
|
if (this.nameUIRoot != null) { |
|
this.nameUIRoot.dispose(); |
|
this.nameUIRoot = null; |
|
this.nameText = null; |
|
} |
|
|
|
super.dispose(disposeMesh); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据类型划分的设备信息 |
|
export class FacilityInfoByType { |
|
type: FacilityType; |
|
facilityInfo: ModelInfo_facility[]; |
|
|
|
constructor(type: FacilityType) { |
|
this.type = type; |
|
this.facilityInfo = []; |
|
|
|
} |
|
|
|
dispose() { |
|
for (let i = 0; i < this.facilityInfo.length; i++) { |
|
this.facilityInfo[i].dispose(); |
|
} |
|
this.facilityInfo = []; |
|
} |
|
} |