提交 5d2f1f56 编写于 作者: 三月三net's avatar 三月三net

太阳系三体模拟器

上级 d29fab1a
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
# python_version :3.8 # python_version :3.8
# ============================================================================== # ==============================================================================
from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \ from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \
load_texture, held_keys, Button, ButtonList, destroy, scene, distance load_texture, held_keys, Button, ButtonList, destroy, scene, distance, Sequence, Wait, Func
from ursina.prefabs.first_person_controller import FirstPersonController from ursina.prefabs.first_person_controller import FirstPersonController
from common.consts import AU from common.consts import AU
from simulators.ursina.ui_component import UiSlider, SwithButton, UiButton from simulators.ursina.ui_component import UiSlider, SwithButton, UiButton
from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
from ursina import WindowPanel, InputField, Button, Slider, ButtonGroup, Panel from ursina import WindowPanel, InputField, Button, Slider, ButtonGroup, Panel, invoke
class UrsinaUI: class UrsinaUI:
...@@ -121,6 +121,28 @@ class UrsinaUI: ...@@ -121,6 +121,28 @@ class UrsinaUI:
# slider_text = Text(text='自转速度', scale=1, position=(-0.6, 0.3)) # slider_text = Text(text='自转速度', scale=1, position=(-0.6, 0.3))
# slider = Slider(scale=0.5, position=(-0.6, 0), min=0, max=10, step=1, text=slider_text) # slider = Slider(scale=0.5, position=(-0.6, 0), min=0, max=10, step=1, text=slider_text)
def show_message(self, message, close_time=3):
"""
创建消息框
:param message: 消息内容
:param close_time: 定义关闭时间
:return:
"""
# 创建消息框
message_box = Text(text=message, font=UrsinaConfig.CN_FONT, background=True, origin=(0, 0), y=.25)
# 定义关闭函数
def close_message():
destroy(message_box)
s = Sequence(
Wait(3),
Func(close_message)
)
s.start()
# # 使用 time 模块来实现定时关闭
# invoke(close_message, delay=close_time)
def on_off_trail_changed(self): def on_off_trail_changed(self):
if self.on_off_trail.value == self.trail_button_text: if self.on_off_trail.value == self.trail_button_text:
UrsinaConfig.show_trail = True UrsinaConfig.show_trail = True
...@@ -154,6 +176,10 @@ class UrsinaUI: ...@@ -154,6 +176,10 @@ class UrsinaUI:
results = UrsinaEvent.on_searching_bodies() results = UrsinaEvent.on_searching_bodies()
if len(results) > 0: if len(results) > 0:
sub_name, bodies = results[0] sub_name, bodies = results[0]
if len(bodies) == 0:
self.show_message("天体都飞不见了,请重新运行。")
# button_dict = {"天体都飞不见了,请重新运行。": lambda: self.bodies_button_list_click(None)}
return
# print(results[0]) # print(results[0])
button_dict = {"[关闭]": lambda: self.bodies_button_list_click(None)} button_dict = {"[关闭]": lambda: self.bodies_button_list_click(None)}
camera = scene.camera camera = scene.camera
......
...@@ -20,6 +20,7 @@ from common.system import System ...@@ -20,6 +20,7 @@ from common.system import System
import time import time
import datetime import datetime
import math import math
import os
from ursina import EditorCamera, PointLight, SpotLight, AmbientLight, DirectionalLight from ursina import EditorCamera, PointLight, SpotLight, AmbientLight, DirectionalLight
from scenes.func import ursina_run from scenes.func import ursina_run
...@@ -66,7 +67,6 @@ class UrsinaSimulator(Simulator): ...@@ -66,7 +67,6 @@ class UrsinaSimulator(Simulator):
views.append(view) views.append(view)
return views return views
def check_elapsed_time(self): def check_elapsed_time(self):
"""检查时间间隔是否已过""" """检查时间间隔是否已过"""
now = datetime.datetime.now() now = datetime.datetime.now()
...@@ -154,6 +154,17 @@ class UrsinaSimulator(Simulator): ...@@ -154,6 +154,17 @@ class UrsinaSimulator(Simulator):
return lights return lights
def switch_to_english_input_method(self):
pass
# os.system("powershell -Command \"Set-WinUserLanguageList -LanguageList 'en-US', 'zh-CN' -Force\"")
# if os.name == 'nt': # Windows 系统
# os.system('powershell -Command "Set-WinUserLanguageList en-US -Force"')
# elif os.name == 'posix': # macOS 或 Linux 系统
# os.system(
# 'defaults write ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources -array-add \'{ "InputSourceKind" = "Keyboard Layout"; "KeyboardLayout ID" = 252; "KeyboardLayout Name" = "ABC"; }\'')
# os.system('killall cfprefsd') # 重启 CoreFoundation 进程使更改生效
def run(self, dt, **kwargs): def run(self, dt, **kwargs):
window.title = '宇宙模拟器' window.title = '宇宙模拟器'
...@@ -191,7 +202,8 @@ class UrsinaSimulator(Simulator): ...@@ -191,7 +202,8 @@ class UrsinaSimulator(Simulator):
ui = UrsinaUI() ui = UrsinaUI()
EditorCamera(ignore_paused=True) EditorCamera(ignore_paused=True)
# 防止打开中文输入法
# self.switch_to_english_input_method()
self.app.run() self.app.run()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册