godot-psd-training/sceen/total.gd
2024-05-22 16:02:05 +08:00

283 lines
14 KiB
GDScript

extends Node3D
class_name TotalScene
##车来且开屏蔽门和车门
func trainComeAndOpenScreenDoor ()-> void:
if $platform.allScreenDoorClose() :
$train.trainCome()
$BeginTimer.start()
func _on_beginTimer_timeout() -> void:
$train.openLeftTrainDoorALL()
$platform.openScreenDoorALL()
##关屏蔽门和车门且车走
func closeScreenDoorAndTrainLeave ()-> void:
closeScreenDoor()
$EndTimer.start()
func _on_end_timer_timeout() -> void:
trainLeave()
##关屏蔽门和车门
func closeScreenDoor() -> void:
$train.closeLeftTrainDoorALL()
$platform.closeScreenDoorALL()
##车走
func trainLeave(ActionGestureCommandDeparture = false) -> bool:
var InterlockReleaseSwitch=NodeUtils.find_child_by_name($platform.get_node('psl'),'InterlockReleaseSwitch')
var isOpenLight = NodeUtils.find_child_by_name(InterlockReleaseSwitch,'openLight').visible
if $platform.allScreenDoorClose() or isOpenLight or ActionGestureCommandDeparture :
$trainLeaveDelay.start()
return true
return false
func _on_train_leave_delay_timeout() -> void:
$train.trainLeave()
## 屏蔽门名字的枚举
enum ScreenDoor_name{
screenDoor1=1,
screenDoor2,
screenDoor3,
screenDoor4,
}
##设置指定屏蔽门开门故障
func setAssignScreenDoorsOpenFault (screenDoorNames:Array)-> void:
setAssignScreenDoorsFault(screenDoorNames,ScreenDoor.ScreenDoor_Fault_State.openFault)
##设置指定屏蔽门关门故障
func setAssignScreenDoorsCloseFault (screenDoorNames:Array)-> void:
setAssignScreenDoorsFault(screenDoorNames,ScreenDoor.ScreenDoor_Fault_State.closeFault)
##设置指定屏蔽门玻璃破碎故障
func setAssignScreenDoorsGlassBreakageFault (screenDoorNames:Array)-> void:
setAssignScreenDoorsFault(screenDoorNames,ScreenDoor.ScreenDoor_Fault_State.glassBreakage)
##设置指定屏蔽门夹人故障
func setAssignScreenDoorsPinchPeopleFault (screenDoorNames:Array)-> void:
setAssignScreenDoorsFault(screenDoorNames,ScreenDoor.ScreenDoor_Fault_State.pinchPeople)
func setAssignScreenDoorsFault (screenDoorNames:Array,faultType:ScreenDoor.ScreenDoor_Fault_State)-> void:
for child in $platform.screenDoorALL:
var screenDoorName=String(child.name)
var screenDoorIndex=int(screenDoorName[screenDoorName.length() - 1])
if screenDoorIndex in screenDoorNames:
child.setScreenDoorFault(faultType)
##屏蔽门开关门到位信号和lcb状态变化信号
signal screenDoorOpenConfirmSignal(screenDoor:ScreenDoor)
signal screenDoorCloseConfirmSignal(screenDoor:ScreenDoor)
signal screenDoorLcbStateChangeSignal(screenDoor:ScreenDoor,knob_state: LcbWindow.KNOB_STATE)
func emitScreenDoorOpenSignal(screenDoor:ScreenDoor) -> void:
screenDoorOpenConfirmSignal.emit(screenDoor)
func emitScreenDoorCloseSignal(screenDoor:ScreenDoor) -> void:
screenDoorCloseConfirmSignal.emit(screenDoor)
func emitScreenDoorLcbStateChangeSignal(currenScreenDoor: ScreenDoor, knob_state: LcbWindow.KNOB_STATE) -> void:
screenDoorLcbStateChangeSignal.emit(currenScreenDoor,knob_state)
## 实训模式枚举
enum Training_Mode{
Teach,#教学模式
Practice,# 练习模式
Exam,# 考试模式
}
var trainingMode = Training_Mode.Teach
##当前点击和需要点击节点以及校验是否点击正确
var currentClickNode = null
var currenNeedClickNode = null
signal currentClickCheckSignal(isCorrect:bool)
var allLCBKeys = ['LCB_Key1','LCB_Key2','LCB_Key3','LCB_Key4']
func checkCurrentClick() -> bool:
if trainingMode == Training_Mode.Exam:
return true
else :
if currentClickNode == currenNeedClickNode or (currentClickNode in allLCBKeys and currenNeedClickNode in allLCBKeys):
return true
else :
return false
func _on_platform_all_click_platform_signal(equipmentName: String,equipmentInfo=null) -> void:
currentClickNode = equipmentName
var isClickCorrect = checkCurrentClick()
currentClickCheckSignal.emit(isClickCorrect)
equipmentInfo.allowHandle = isClickCorrect
const NodeUtils = preload("res://util/NodeUtils.gd")
##所有交互操作平面坐标
func allClickEquipmentPostion(equipmentName: String) -> Vector2:
if equipmentName in ['LCB_Key1','LCB_Key2','LCB_Key3','LCB_Key4','JJTC_Key','PSL_Key','HSJC_Key','SDJS_Key','confirmUseKey'] : ##钥匙面板
var keysWindow = $platform.get_node('stationKeys')
var lcbWindowPos = keysWindow.position
if equipmentName == 'confirmUseKey':
var confirmUseKeyPos=NodeUtils.find_child_by_name(keysWindow,'Button').get_global_position()
return Vector2(lcbWindowPos.x+confirmUseKeyPos.x+30,lcbWindowPos.y+confirmUseKeyPos.y)
var LCB_KeyPos=NodeUtils.find_child_by_name(keysWindow,equipmentName).get_global_position()
return Vector2(lcbWindowPos.x+LCB_KeyPos.x+70,lcbWindowPos.y+LCB_KeyPos.y+20)
elif equipmentName == 'LCB1' : ##LCB以及LCB面板
return getScreenPosition($platform.get_node('screenDoor1').get_node('LCB').get_node('LCB_body'))
elif equipmentName == 'LCB2' :
return getScreenPosition($platform.get_node('screenDoor2').get_node('LCB').get_node('LCB_body'))
elif equipmentName == 'LCB3' :
return getScreenPosition($platform.get_node('screenDoor3').get_node('LCB').get_node('LCB_body'))
elif equipmentName == 'LCB4' :
return getScreenPosition($platform.get_node('screenDoor4').get_node('LCB').get_node('LCB_body'))
elif equipmentName in ['LCB1LeftRotate','LCB2LeftRotate','LCB3LeftRotate','LCB4LeftRotate'] :
var lcbPos = $platform.get_node('LCB').position
var leftRotatePos = $platform.get_node('LCB').get_node('LCB2_Left_Rotate').get_global_position()
return Vector2(lcbPos.x+leftRotatePos.x,lcbPos.y+leftRotatePos.y)
elif equipmentName in ['LCB1RightRotate','LCB2RightRotate','LCB3RightRotate','LCB4RightRotate'] :
var lcbPos = $platform.get_node('LCB').position
var rightRotatePos = $platform.get_node('LCB').get_node('LCB2_Right_Rotate').get_global_position()
return Vector2(lcbPos.x+rightRotatePos.x,lcbPos.y+rightRotatePos.y)
elif equipmentName in ['removeKeyOfWindowLCB1','removeKeyOfWindowLCB2','removeKeyOfWindowLCB3','removeKeyOfWindowLCB4'] :
var lcbPos = $platform.get_node('LCB').position
var removePos = $platform.get_node('LCB').get_node('TextureRect2').get_global_position()
return Vector2(lcbPos.x+removePos.x-25,lcbPos.y+removePos.y-5)
elif equipmentName == 'PSL' : ##PSL以及PSL面板
return getScreenPosition($platform.get_node('PSL').get_node('PSL_body'))
elif equipmentName in ['PSLAllow','CloseDoorButton','OpenDoorButton','InterlockReleaseSwitch','LightTestButton','trainDepartsButton','interconnectedCloseButton','interconnectedOpenButton','removePSLKeyOfWindowPsl','removeHSJCKeyOfWindowPsl'] :
var pslWindow = $platform.get_node('psl')
var pslWindowPos = pslWindow.position
if equipmentName in ['PSLAllow','InterlockReleaseSwitch']:
var keySwitch=NodeUtils.find_child_by_name(pslWindow,equipmentName)
var rotatePos = NodeUtils.find_child_by_name(keySwitch,'Right_Rotate').get_global_position()
return Vector2(pslWindowPos.x+rotatePos.x,pslWindowPos.y+rotatePos.y)
elif equipmentName == 'removePSLKeyOfWindowPsl':
var PSLAllow=NodeUtils.find_child_by_name(pslWindow,'PSLAllow')
var removeKeyPos = NodeUtils.find_child_by_name(PSLAllow,'Keyhole').get_global_position()
return Vector2(pslWindowPos.x+removeKeyPos.x,pslWindowPos.y+removeKeyPos.y)
elif equipmentName == 'removeHSJCKeyOfWindowPsl':
var InterlockReleaseSwitch=NodeUtils.find_child_by_name(pslWindow,'InterlockReleaseSwitch')
var removeKeyPos = NodeUtils.find_child_by_name(InterlockReleaseSwitch,'Keyhole').get_global_position()
return Vector2(pslWindowPos.x+removeKeyPos.x,pslWindowPos.y+removeKeyPos.y)
var LCB_KeyPos=NodeUtils.find_child_by_name(pslWindow,equipmentName).get_global_position()
return Vector2(pslWindowPos.x+LCB_KeyPos.x,pslWindowPos.y+LCB_KeyPos.y)
elif equipmentName == 'JJTC' : ##JJTC以及JJTC面板
return getScreenPosition($platform.get_node('JJTC').get_node('JJTC_body'))
elif equipmentName in ['JJTCLeftRotate','JJTCRightRotate','JJTCButton','JJTCCloseBox'] :
var jjtcWindow = $platform.get_node('jjtc')
var jjtcWindowPos = jjtcWindow.position
if equipmentName == 'JJTCLeftRotate':
var Close_Click_Area_pos=NodeUtils.find_child_by_name(jjtcWindow,'JJTC_Left_Rotate').get_global_position()
return Vector2(jjtcWindowPos.x+Close_Click_Area_pos.x,jjtcWindowPos.y+Close_Click_Area_pos.y)
elif equipmentName == 'JJTCRightRotate':
var Close_Click_Area_pos=NodeUtils.find_child_by_name(jjtcWindow,'JJTC_Right_Rotate').get_global_position()
return Vector2(jjtcWindowPos.x+Close_Click_Area_pos.x,jjtcWindowPos.y+Close_Click_Area_pos.y)
elif equipmentName == 'JJTCButton':
var Close_Click_Area_pos=NodeUtils.find_child_by_name(jjtcWindow,'JJTC_Button').get_global_position()
return Vector2(jjtcWindowPos.x+Close_Click_Area_pos.x,jjtcWindowPos.y+Close_Click_Area_pos.y)
else :
var Close_Click_Area_pos=NodeUtils.find_child_by_name(jjtcWindow,'Close_Click_Area').get_global_position()
return Vector2(jjtcWindowPos.x+Close_Click_Area_pos.x,jjtcWindowPos.y+Close_Click_Area_pos.y)
elif equipmentName == 'screenDoor1RightClick' : ##屏蔽门右键以及屏蔽门右键面板
return getScreenPosition($platform.get_node('screenDoor1').get_node('left'))
elif equipmentName == 'screenDoor2RightClick' :
return getScreenPosition($platform.get_node('screenDoor2').get_node('left'))
elif equipmentName == 'screenDoor3RightClick' :
return getScreenPosition($platform.get_node('screenDoor3').get_node('left'))
elif equipmentName == 'screenDoor4RightClick' :
return getScreenPosition($platform.get_node('screenDoor4').get_node('left'))
elif equipmentName in ['clickAdhesiveTapeOfscreenDoor1','clickAdhesiveTapeOfscreenDoor2','clickAdhesiveTapeOfscreenDoor3','clickAdhesiveTapeOfscreenDoor4'] :
var ScreenDoorOperateWindow = $platform.get_node('ScreenDoorOperate')
var ScreenDoorOperateWindowPos = ScreenDoorOperateWindow.position
var AdhesiveTapePos = NodeUtils.find_child_by_name(ScreenDoorOperateWindow,'AdhesiveTape').get_global_position()
return Vector2(ScreenDoorOperateWindowPos.x+AdhesiveTapePos.x,ScreenDoorOperateWindowPos.y+AdhesiveTapePos.y)
else:
var ScreenDoorOperateWindow = $platform.get_node('ScreenDoorOperate')
var ScreenDoorOperateWindowPos = ScreenDoorOperateWindow.position
var IsolationStripPos=NodeUtils.find_child_by_name(ScreenDoorOperateWindow,'IsolationStrip').get_global_position()
return Vector2(ScreenDoorOperateWindowPos.x+IsolationStripPos.x,ScreenDoorOperateWindowPos.y+IsolationStripPos.y)
func getScreenPosition(node):
var screenPostion = $Camera3D.unproject_position(node.global_transform.origin)
return screenPostion
##所有交互操作汇总
const allClickEquipmentInfo = {
"LCB_Key1": "请选择LCB钥匙", ##钥匙面板
"LCB_Key2": "请选择LCB钥匙",
"LCB_Key3": "请选择LCB钥匙",
"LCB_Key4": "请选择LCB钥匙",
"JJTC_Key": "请选择紧急停车钥匙",
"PSL_Key": "请选择PSL钥匙",
"HSJC_Key": "请选择互锁解除钥匙",
"SDJS_Key": "请选择手动解锁钥匙",
"confirmUseKey": "请确认使用钥匙",
"LCB1": "请点击打开屏蔽门1的LCB面板", ##LCB以及LCB面板
"LCB2": "请点击打开屏蔽门2的LCB面板",
"LCB3": "请点击打开屏蔽门3的LCB面板",
"LCB4": "请点击打开屏蔽门4的LCB面板",
"LCB1LeftRotate": "请向左旋转LCB钥匙",
"LCB1RightRotate": "请向右旋转LCB钥匙",
"LCB2LeftRotate": "请向左旋转LCB钥匙",
"LCB2RightRotate": "请向右旋转LCB钥匙",
"LCB3LeftRotate": "请向左旋转LCB钥匙",
"LCB3RightRotate": "请向右旋转LCB钥匙",
"LCB4LeftRotate": "请向左旋转LCB钥匙",
"LCB4RightRotate": "请向右旋转LCB钥匙",
"removeKeyOfWindowLCB1": "请移除LCB钥匙",
"removeKeyOfWindowLCB2": "请移除LCB钥匙",
"removeKeyOfWindowLCB3": "请移除LCB钥匙",
"removeKeyOfWindowLCB4": "请移除LCB钥匙",
"PSL": "请打开PSL面板", ##PSL以及PSL面板
"PSLAllow": "请操做允许",
"CloseDoorButton": "请点击关门按钮",
"OpenDoorButton": "请点击开门按钮",
"InterlockReleaseSwitch": "请操作互锁接触开关",
"LightTestButton": "请点击灯测试按钮",
"trainDepartsButton": "请点击发车按钮",
"interconnectedCloseButton": "请点击联动关门按钮",
"interconnectedOpenButton": "请点击联动开按钮",
"removePSLKeyOfWindowPsl": "请移除PSK钥匙",
"removeHSJCKeyOfWindowPsl": "请移除互锁解除钥匙",
"JJTC": "请打开紧急停车面板", ##JJTC以及JJTC面板
"JJTCLeftRotate": "请向左旋转打开紧急停车按钮盒",
"JJTCRightRotate": "请向右旋转拔出紧急停车钥匙",
"JJTCButton": "请点击紧急停车按钮",
"JJTCCloseBox": "请点击盒子边框关闭紧急停车按钮盒",
"screenDoor1RightClick": "请右键点击屏蔽门1", ##屏蔽门右键以及屏蔽门右键面板
"screenDoor2RightClick": "请右键点击屏蔽门2",
"screenDoor3RightClick": "请右键点击屏蔽门3",
"screenDoor4RightClick": "请右键点击屏蔽门4",
"clickAdhesiveTapeOfscreenDoor1": "请选择粘贴胶带",
"clickIsolationStripOfscreenDoor1": "请选择放置隔离带",
"clickAdhesiveTapeOfscreenDoor2": "请选择粘贴胶带",
"clickIsolationStripOfscreenDoor2": "请选择放置隔离带",
"clickAdhesiveTapeOfscreenDoor3": "请选择粘贴胶带",
"clickIsolationStripOfscreenDoor3": "请选择放置隔离带",
"clickAdhesiveTapeOfscreenDoor4": "请选择粘贴胶带",
"clickIsolationStripOfscreenDoor4": "请选择放置隔离带",
}
func _ready():
var stationKeys = $platform.get_node('stationKeys')
var psl = $platform.get_node('psl')
stationKeys.visible = true
stationKeys.position = Vector2(2100,1100)
psl.visible = true
psl.position = Vector2(2100,1100)
$openAllwindow.start()
func _on_open_allwindow_timeout() -> void:
var stationKeys = $platform.get_node('stationKeys')
var psl = $platform.get_node('psl')
stationKeys.visible = false
stationKeys.position = Vector2(1133,325)
psl.visible = false
psl.position = Vector2(568,190)