Difficult-Rocket/Difficult_Rocket/client/screen.py

59 lines
2.0 KiB
Python
Raw Normal View History

2022-05-11 11:11:39 +08:00
# -------------------------------
# Difficult Rocket
2023-01-20 14:08:12 +08:00
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
2022-05-11 11:11:39 +08:00
# All rights reserved
# -------------------------------
2022-11-26 21:48:55 +08:00
import typing
2022-05-11 11:11:39 +08:00
2022-12-25 23:15:49 +08:00
from pyglet.text import Label
from pyglet.graphics import Batch, Group
from pyglet.clock import get_frequency
2022-12-13 00:01:38 +08:00
# Difficult Rocket function
2023-01-02 17:19:57 +08:00
from Difficult_Rocket.api.types import Fonts
2023-02-25 09:18:41 +08:00
# from Difficult_Rocket.utils import translate
2022-12-25 23:15:49 +08:00
from Difficult_Rocket.api.screen import BaseScreen
2023-02-25 09:18:41 +08:00
# from Difficult_Rocket.command.tree import CommandTree
2022-05-11 11:11:39 +08:00
2022-11-26 21:48:55 +08:00
if typing.TYPE_CHECKING:
from Difficult_Rocket.client import ClientWindow
2022-05-11 11:11:39 +08:00
class DRScreen(BaseScreen):
2022-11-26 21:48:55 +08:00
def __init__(self, main_window: "ClientWindow"):
2022-05-11 11:11:39 +08:00
super().__init__(main_window)
class DRDEBUGScreen(BaseScreen):
2022-11-26 21:48:55 +08:00
def __init__(self, main_window: "ClientWindow"):
super().__init__(main_window)
2022-12-25 23:15:49 +08:00
self.main_batch = Batch()
self.main_group = Group(order=1)
self.fps_label = Label(x=10, y=main_window.height - 10,
width=main_window.width - 20, height=20,
anchor_x='left', anchor_y='top',
2023-01-02 17:19:57 +08:00
font_name=Fonts.微软等宽无线, font_size=20,
2022-12-25 23:15:49 +08:00
multiline=True,
batch=self.main_batch, group=self.main_group)
self.fps_label.text = "11111114514"
def draw_update(self, tick: float):
self.update_label()
def update_label(self):
now_FPS = get_frequency()
2023-01-27 21:09:37 +08:00
self.fps_label.text = (
f'FPS: {self.window_pointer.fps_log.fps: >5.1f}('
f'{self.window_pointer.fps_log.middle_fps: >5.1f})[{now_FPS: >.7f}]\n '
f'{self.window_pointer.fps_log.max_fps: >7.1f} '
f'{self.window_pointer.fps_log.min_fps:>5.1f}'
)
2022-12-25 23:15:49 +08:00
def on_resize(self, width, height):
self.fps_label.y = height - 10
def on_draw(self, *dt):
self.main_batch.draw()
# print(self.window_pointer.try_if_runs)