forked from Rowland/EG
139 lines
4.1 KiB
Python
139 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
快速GUI测试
|
||
验证主程序中的GUI修复是否有效
|
||
"""
|
||
|
||
import warnings
|
||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||
|
||
import sys
|
||
from direct.showbase.ShowBase import ShowBase
|
||
from direct.gui.DirectGui import *
|
||
from direct.gui.OnscreenText import OnscreenText
|
||
from panda3d.core import *
|
||
|
||
# 配置Panda3D
|
||
loadPrcFileData("", """
|
||
win-size 800 600
|
||
window-title Quick GUI Test
|
||
""")
|
||
|
||
class QuickGUITest(ShowBase):
|
||
def __init__(self):
|
||
ShowBase.__init__(self)
|
||
|
||
print("=== 快速GUI测试 ===")
|
||
|
||
# 设置背景色
|
||
self.setBackgroundColor(0.2, 0.2, 0.3)
|
||
|
||
# 调整相机位置
|
||
self.cam.setPos(0, -10, 5)
|
||
self.cam.lookAt(0, 0, 0)
|
||
|
||
self.gui_elements = []
|
||
|
||
# 尝试加载中文字体
|
||
try:
|
||
self.chinese_font = self.loader.loadFont('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc')
|
||
except:
|
||
self.chinese_font = None
|
||
|
||
# 创建标题
|
||
self.title = OnscreenText(
|
||
text="快速GUI测试 - 验证修复效果",
|
||
pos=(0, 0.9),
|
||
scale=0.08,
|
||
fg=(1, 1, 1, 1),
|
||
align=TextNode.ACenter,
|
||
font=self.chinese_font if self.chinese_font else None
|
||
)
|
||
|
||
# 立即创建GUI元素测试
|
||
self.createTestGUI()
|
||
|
||
def createTestGUI(self):
|
||
"""创建测试GUI元素"""
|
||
print("\n创建测试GUI元素...")
|
||
|
||
# 使用和主程序相同的方法创建GUI
|
||
# 测试不同的坐标值
|
||
test_coords = [
|
||
(0, 0, 0), # 中心
|
||
(-10, 0, 0), # 左侧
|
||
(10, 0, 0), # 右侧
|
||
(0, 0, 10), # 上方
|
||
(0, 0, -10), # 下方
|
||
]
|
||
|
||
print("使用新的0.05缩放比例...")
|
||
|
||
# 创建按钮测试
|
||
for i, pos in enumerate(test_coords):
|
||
gui_pos = (pos[0] * 0.05, 0, pos[2] * 0.05)
|
||
|
||
button = DirectButton(
|
||
text=f"按钮{i+1}",
|
||
pos=gui_pos,
|
||
scale=0.08,
|
||
frameColor=(0.2, 0.6, 0.8, 1),
|
||
text_font=self.chinese_font if self.chinese_font else None,
|
||
rolloverSound=None,
|
||
clickSound=None
|
||
)
|
||
|
||
self.gui_elements.append(button)
|
||
print(f"按钮{i+1}: 逻辑坐标{pos} -> 屏幕坐标{gui_pos}")
|
||
|
||
# 创建标签测试
|
||
label_coords = [
|
||
(0, 0, -15), # 下方
|
||
(-15, 0, -5), # 左下
|
||
(15, 0, -5), # 右下
|
||
]
|
||
|
||
for i, pos in enumerate(label_coords):
|
||
gui_pos = (pos[0] * 0.05, 0, pos[2] * 0.05)
|
||
|
||
label = DirectLabel(
|
||
text=f"标签{i+1}",
|
||
pos=gui_pos,
|
||
scale=0.06,
|
||
frameColor=(0, 0, 0, 0),
|
||
text_fg=(1, 1, 1, 1),
|
||
text_font=self.chinese_font if self.chinese_font else None
|
||
)
|
||
|
||
self.gui_elements.append(label)
|
||
print(f"标签{i+1}: 逻辑坐标{pos} -> 屏幕坐标{gui_pos}")
|
||
|
||
# 创建3D元素作为对比
|
||
textNode = TextNode('3d-text')
|
||
textNode.setText("3D文本对比")
|
||
textNode.setAlign(TextNode.ACenter)
|
||
if self.chinese_font:
|
||
textNode.setFont(self.chinese_font)
|
||
|
||
text3D = self.render.attachNewNode(textNode)
|
||
text3D.setPos(0, 5, 2)
|
||
text3D.setScale(0.5)
|
||
text3D.setColor(1, 1, 0, 1)
|
||
text3D.setBillboardAxis()
|
||
|
||
print(f"\n创建完成!GUI元素总数: {len(self.gui_elements)}")
|
||
print("如果你能看到按钮和标签,说明修复成功!")
|
||
print("如果只能看到黄色的3D文本,说明2D GUI仍有问题。")
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("启动快速GUI测试...")
|
||
|
||
# 创建并运行应用
|
||
app = QuickGUITest()
|
||
app.run()
|
||
|
||
if __name__ == "__main__":
|
||
main() |