forked from Rowland/EG
1.虚拟维修增加退出Bt(但是有Bug)
This commit is contained in:
parent
64df3107fe
commit
d69cff3466
@ -456,6 +456,7 @@ class AssemblyInteractionManager(DirectObject):
|
||||
print(f"✅ 维修系统GUI已启动,模式: {mode}")
|
||||
|
||||
# 如果是考核模式,初始化考核相关数据
|
||||
|
||||
if self.mode == "exam":
|
||||
self.init_exam_mode()
|
||||
# 显示考核开始提示
|
||||
@ -1605,6 +1606,53 @@ class AssemblyInteractionManager(DirectObject):
|
||||
else:
|
||||
QMessageBox.information(None, "训练完成", completion_msg)
|
||||
|
||||
def stop_interaction(self):
|
||||
"""用户主动停止交互"""
|
||||
print("\n🛑 用户主动停止拆装交互")
|
||||
|
||||
try:
|
||||
# 设置为非活动状态
|
||||
self.is_active = False
|
||||
self.ignoreAll()
|
||||
|
||||
# 清理维修系统GUI
|
||||
if self.maintenance_gui:
|
||||
self.maintenance_gui.cleanup_gui()
|
||||
print("✅ 维修系统GUI已清理")
|
||||
|
||||
# 恢复原有的Qt鼠标事件处理
|
||||
print("🔄 恢复原有的Qt鼠标事件处理")
|
||||
if hasattr(self, 'original_mouse_press_event') and hasattr(self.world, 'qtWidget') and self.world.qtWidget:
|
||||
self.world.qtWidget.mousePressEvent = self.original_mouse_press_event
|
||||
self.world.qtWidget.mouseReleaseEvent = self.original_mouse_release_event
|
||||
print("✅ 原有Qt鼠标事件处理已恢复")
|
||||
else:
|
||||
print("⚠️ 没有找到备份的Qt事件处理方法")
|
||||
|
||||
# 关闭步骤对话框
|
||||
if self.step_dialog:
|
||||
self.step_dialog.close()
|
||||
self.step_dialog = None
|
||||
|
||||
# 显示停止确认信息
|
||||
if self.mode == "exam":
|
||||
stop_msg = "🛑 考核已停止\n\n您的考核进度没有被保存。"
|
||||
else:
|
||||
stop_msg = "🛑 训练已停止\n\n您可以随时重新开始训练。"
|
||||
|
||||
if self.maintenance_gui:
|
||||
# 如果GUI还在,显示停止信息
|
||||
self.maintenance_gui.update_step_info(stop_msg)
|
||||
else:
|
||||
QMessageBox.information(None, "操作停止", stop_msg)
|
||||
|
||||
print("✅ 拆装交互已停止")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 停止拆装交互失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def show_exam_results(self):
|
||||
"""显示考核结果"""
|
||||
try:
|
||||
|
||||
@ -10,6 +10,7 @@ from direct.gui.DirectGui import *
|
||||
from direct.gui import DirectGuiGlobals as DGG
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
from direct.task import Task
|
||||
from direct.task.TaskManagerGlobal import taskMgr
|
||||
from panda3d.core import TextNode, Vec3, Vec4
|
||||
|
||||
# 引入全局变量
|
||||
@ -39,9 +40,10 @@ class MaintenanceGUI(DirectObject):
|
||||
self.current_tool_text = None # 当前工具显示文本
|
||||
self.warning_text = None # 警告文本
|
||||
self.tool_buttons = [] # 工具按钮列表
|
||||
self.stop_button = None # 停止按钮
|
||||
|
||||
# 状态
|
||||
self.current_tool = "手" # 当前选择的工具
|
||||
self.current_tool = None # 当前选择的工具,初始为无
|
||||
self.available_tools = [] # 可用工具列表
|
||||
self.current_step_info = "" # 当前步骤信息
|
||||
self.mode = "training" # 模式:training 或 exam
|
||||
@ -82,6 +84,9 @@ class MaintenanceGUI(DirectObject):
|
||||
self.create_tool_buttons()
|
||||
self.create_current_tool_text()
|
||||
|
||||
# 创建停止按钮(训练和考核模式都需要)
|
||||
# self.create_stop_button()
|
||||
|
||||
# 创建警告文本(仅训练模式需要)
|
||||
if mode == "training":
|
||||
self.create_warning_text()
|
||||
@ -439,6 +444,39 @@ class MaintenanceGUI(DirectObject):
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def create_stop_button(self):
|
||||
"""创建停止按钮"""
|
||||
try:
|
||||
if not self.aspect2d:
|
||||
print("❌ aspect2d引用不可用,无法创建停止按钮")
|
||||
return
|
||||
|
||||
# 停止按钮位置:右下角
|
||||
self.stop_button = DirectButton(
|
||||
text="停止",
|
||||
text_align=TextNode.ACenter,
|
||||
text_scale=0.06,
|
||||
text_fg=(1, 1, 1, 1),
|
||||
text_bg=(0, 0, 0, 0),
|
||||
frameColor=(0.8, 0.2, 0.2, 0.9), # 红色背景
|
||||
frameSize=(-0.15, 0.15, -0.08, 0.08),
|
||||
pos=(1.15, 0, -0.85), # 右下角位置
|
||||
parent=self.aspect2d,
|
||||
command=self.on_stop_clicked,
|
||||
relief=DGG.RAISED,
|
||||
borderWidth=(0.01, 0.01),
|
||||
rolloverSound=None,
|
||||
clickSound=None,
|
||||
pressEffect=1
|
||||
)
|
||||
|
||||
print("✅ 停止按钮创建成功")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 创建停止按钮失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def create_warning_text(self):
|
||||
"""创建警告文本"""
|
||||
try:
|
||||
@ -522,6 +560,22 @@ class MaintenanceGUI(DirectObject):
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def on_stop_clicked(self):
|
||||
"""停止按钮点击回调"""
|
||||
try:
|
||||
print("🛑 用户点击停止按钮")
|
||||
|
||||
# 通知拆装交互系统停止
|
||||
if hasattr(self.world, 'assembly_interaction') and self.world.assembly_interaction:
|
||||
self.world.assembly_interaction.stop_interaction()
|
||||
else:
|
||||
print("⚠️ 拆装交互系统不存在,无法停止")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 停止操作失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def update_tool_button_styles(self):
|
||||
"""更新工具按钮样式"""
|
||||
try:
|
||||
@ -955,6 +1009,11 @@ class MaintenanceGUI(DirectObject):
|
||||
button.destroy()
|
||||
self.tool_buttons.clear()
|
||||
|
||||
# 清理停止按钮
|
||||
if hasattr(self, 'stop_button') and self.stop_button:
|
||||
self.stop_button.destroy()
|
||||
self.stop_button = None
|
||||
|
||||
# 取消警告任务
|
||||
if self.warning_task:
|
||||
taskMgr.remove(self.warning_task)
|
||||
@ -986,14 +1045,19 @@ class MaintenanceGUI(DirectObject):
|
||||
self.step_text.show()
|
||||
print(" ✅ 步骤文本已显示")
|
||||
|
||||
if self.mode == "training":
|
||||
if self.current_tool_text:
|
||||
self.current_tool_text.show()
|
||||
print(" ✅ 当前工具文本已显示")
|
||||
|
||||
for i, button in enumerate(self.tool_buttons):
|
||||
button.show()
|
||||
print(f" ✅ 工具按钮 {i+1} 已显示")
|
||||
# 当前工具文本和工具按钮在训练和考核模式都需要显示
|
||||
if self.current_tool_text:
|
||||
self.current_tool_text.show()
|
||||
print(" ✅ 当前工具文本已显示")
|
||||
|
||||
for i, button in enumerate(self.tool_buttons):
|
||||
button.show()
|
||||
print(f" ✅ 工具按钮 {i+1} 已显示")
|
||||
|
||||
# 停止按钮在训练和考核模式都需要显示
|
||||
if self.stop_button:
|
||||
self.stop_button.show()
|
||||
print(" ✅ 停止按钮已显示")
|
||||
|
||||
print("✅ 维修系统GUI显示完成")
|
||||
|
||||
@ -1017,6 +1081,9 @@ class MaintenanceGUI(DirectObject):
|
||||
for button in self.tool_buttons:
|
||||
button.hide()
|
||||
|
||||
if self.stop_button:
|
||||
self.stop_button.hide()
|
||||
|
||||
print("✅ 维修系统GUI隐藏")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user