Difficult-Rocket/Difficult_Rocket/client/screen.py

51 lines
1.7 KiB
Python
Raw Permalink 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.clock import get_frequency
2023-06-22 01:44:53 +08:00
from pyglet.graphics import Batch, Group
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
2022-12-25 23:15:49 +08:00
from Difficult_Rocket.api.screen import BaseScreen
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
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"
2023-04-19 00:42:31 +08:00
def draw_update(self, tick: float, window: "ClientWindow"):
self.update_label(window)
2022-12-25 23:15:49 +08:00
2023-04-19 00:42:31 +08:00
def update_label(self, window: "ClientWindow"):
2022-12-25 23:15:49 +08:00
now_FPS = get_frequency()
2023-01-27 21:09:37 +08:00
self.fps_label.text = (
2023-04-19 00:42:31 +08:00
f'FPS: {window.fps_log.fps: >5.1f}('
f'{window.fps_log.middle_fps: >5.1f})[{now_FPS: >.7f}]\n '
f'{window.fps_log.max_fps: >7.1f} '
f'{window.fps_log.min_fps:>5.1f}'
2023-01-27 21:09:37 +08:00
)
2022-12-25 23:15:49 +08:00
2023-04-19 00:42:31 +08:00
def on_resize(self, width, height, window: "ClientWindow"):
2022-12-25 23:15:49 +08:00
self.fps_label.y = height - 10
2023-04-19 00:42:31 +08:00
def on_draw(self, *dt, window: "ClientWindow"):
2022-12-25 23:15:49 +08:00
self.main_batch.draw()