每次都得给你format一遍(
This commit is contained in:
parent
88b873ad03
commit
fc88493a98
@ -10,6 +10,8 @@ import traceback
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Dict, Optional, Generator, Tuple
|
from typing import List, Dict, Optional, Generator, Tuple
|
||||||
|
from tkinter import Tk
|
||||||
|
from tkinter import filedialog
|
||||||
|
|
||||||
from pyglet.gl import gl
|
from pyglet.gl import gl
|
||||||
from pyglet.math import Mat4
|
from pyglet.math import Mat4
|
||||||
@ -30,6 +32,13 @@ from Difficult_Rocket.command.line import CommandText
|
|||||||
from Difficult_Rocket.client.screen import BaseScreen
|
from Difficult_Rocket.client.screen import BaseScreen
|
||||||
from Difficult_Rocket.api.camera import CenterGroupCamera
|
from Difficult_Rocket.api.camera import CenterGroupCamera
|
||||||
|
|
||||||
|
from Difficult_Rocket.gui.widget.button import (
|
||||||
|
PressTextButton,
|
||||||
|
MinecraftWikiButtonTheme,
|
||||||
|
ButtonThemeOptions,
|
||||||
|
BaseButtonTheme,
|
||||||
|
)
|
||||||
|
|
||||||
from lib_not_dr import loggers
|
from lib_not_dr import loggers
|
||||||
|
|
||||||
if DR_mod_runtime.use_DR_rust:
|
if DR_mod_runtime.use_DR_rust:
|
||||||
@ -71,6 +80,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
|
|
||||||
name = "DR_game_sr1_ship_render"
|
name = "DR_game_sr1_ship_render"
|
||||||
ships_buttons = []
|
ships_buttons = []
|
||||||
|
|
||||||
def __init__(self, main_window: ClientWindow):
|
def __init__(self, main_window: ClientWindow):
|
||||||
super().__init__(main_window)
|
super().__init__(main_window)
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
@ -166,7 +176,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
text="进入游戏",
|
text="进入游戏",
|
||||||
batch=self.main_batch,
|
batch=self.main_batch,
|
||||||
group=self.buttons_group,
|
group=self.buttons_group,
|
||||||
draw_theme=MinecraftWikiButtonTheme
|
draw_theme=MinecraftWikiButtonTheme,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.select_ship_button = PressSelectShipButton(
|
self.select_ship_button = PressSelectShipButton(
|
||||||
@ -198,7 +208,8 @@ class SR1ShipRender(BaseScreen):
|
|||||||
ships_files = self.scan_all_ships_list(ships_path)
|
ships_files = self.scan_all_ships_list(ships_path)
|
||||||
|
|
||||||
for i in range(len(ships_files)):
|
for i in range(len(ships_files)):
|
||||||
self.ships_buttons.append(PressOpenShipButton(
|
self.ships_buttons.append(
|
||||||
|
PressOpenShipButton(
|
||||||
window=main_window,
|
window=main_window,
|
||||||
ship_path=ships_files[i],
|
ship_path=ships_files[i],
|
||||||
parent_window=self,
|
parent_window=self,
|
||||||
@ -210,7 +221,8 @@ class SR1ShipRender(BaseScreen):
|
|||||||
batch=self.main_batch,
|
batch=self.main_batch,
|
||||||
group=self.ships_buttons_group,
|
group=self.ships_buttons_group,
|
||||||
draw_theme=MinecraftWikiButtonTheme,
|
draw_theme=MinecraftWikiButtonTheme,
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
main_window.push_handlers(self.ships_buttons[-1])
|
main_window.push_handlers(self.ships_buttons[-1])
|
||||||
|
|
||||||
@ -227,7 +239,9 @@ class SR1ShipRender(BaseScreen):
|
|||||||
|
|
||||||
self.ship_list_line = Line(
|
self.ship_list_line = Line(
|
||||||
x=self.ships_buttons_begin_x,
|
x=self.ships_buttons_begin_x,
|
||||||
y = self.ships_buttons_end_y - (self.ships_buttons_end_y - self.ships_buttons_begin_y) ** 2 / ((len(ships_files) + 1) * self.ships_buttons_h),
|
y=self.ships_buttons_end_y
|
||||||
|
- (self.ships_buttons_end_y - self.ships_buttons_begin_y) ** 2
|
||||||
|
/ ((len(ships_files) + 1) * self.ships_buttons_h),
|
||||||
x2=self.ships_buttons_begin_x,
|
x2=self.ships_buttons_begin_x,
|
||||||
y2=self.ships_buttons_end_y,
|
y2=self.ships_buttons_end_y,
|
||||||
width=20,
|
width=20,
|
||||||
@ -238,8 +252,6 @@ class SR1ShipRender(BaseScreen):
|
|||||||
|
|
||||||
self.ships_buttons_group.visible = False
|
self.ships_buttons_group.visible = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self) -> Tuple[int, int]:
|
def size(self) -> Tuple[int, int]:
|
||||||
"""渲染器的渲染大小"""
|
"""渲染器的渲染大小"""
|
||||||
@ -493,14 +505,18 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def on_mouse_scroll(
|
def on_mouse_scroll(
|
||||||
self, x: int, y: int, scroll_x: int, scroll_y: int, window: ClientWindow
|
self, x: int, y: int, scroll_x: int, scroll_y: int, window: ClientWindow
|
||||||
):
|
):
|
||||||
# logger.info(x,y,self.ships_buttons_begin_x,self.ships_buttons_end_x,self.ships_buttons_begin_y,self.ships_buttons_end_y)
|
if self.status.focus and (
|
||||||
if self.status.focus and \
|
not self.show_ships_buttons
|
||||||
(self.show_ships_buttons == False or \
|
or (
|
||||||
(not (self.show_ships_buttons == True \
|
not (
|
||||||
and x >= self.ships_buttons_begin_x \
|
self.show_ships_buttons
|
||||||
and x <= self.ships_buttons_end_x \
|
and x >= self.ships_buttons_begin_x
|
||||||
and y >= self.ships_buttons_begin_y \
|
and x <= self.ships_buttons_end_x
|
||||||
and y <= self.ships_buttons_end_y))):
|
and y >= self.ships_buttons_begin_y
|
||||||
|
and y <= self.ships_buttons_end_y
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
mouse_dx = x - (self.width / 2) + self.dx
|
mouse_dx = x - (self.width / 2) + self.dx
|
||||||
mouse_dy = y - (self.height / 2) + self.dy
|
mouse_dy = y - (self.height / 2) + self.dy
|
||||||
# 鼠标缩放位置相对于屏幕中心的位置
|
# 鼠标缩放位置相对于屏幕中心的位置
|
||||||
@ -532,11 +548,13 @@ class SR1ShipRender(BaseScreen):
|
|||||||
if size_y < 10:
|
if size_y < 10:
|
||||||
size_y = 10
|
size_y = 10
|
||||||
self.size = size_x, size_y
|
self.size = size_x, size_y
|
||||||
elif self.show_ships_buttons == True \
|
elif (
|
||||||
and x >= self.ships_buttons_begin_x \
|
self.show_ships_buttons
|
||||||
and x <= self.ships_buttons_end_x \
|
and x >= self.ships_buttons_begin_x
|
||||||
and y >= self.ships_buttons_begin_y \
|
and x <= self.ships_buttons_end_x
|
||||||
and y <= self.ships_buttons_end_y:
|
and y >= self.ships_buttons_begin_y
|
||||||
|
and y <= self.ships_buttons_end_y
|
||||||
|
):
|
||||||
min_y = 9999999
|
min_y = 9999999
|
||||||
max_y = 0
|
max_y = 0
|
||||||
for ship_button in self.ships_buttons:
|
for ship_button in self.ships_buttons:
|
||||||
@ -552,9 +570,9 @@ class SR1ShipRender(BaseScreen):
|
|||||||
for ship_button in self.ships_buttons:
|
for ship_button in self.ships_buttons:
|
||||||
ship_button.y = ship_button.y + scroll_y * 50
|
ship_button.y = ship_button.y + scroll_y * 50
|
||||||
|
|
||||||
self.ship_list_line.y = self.ship_list_line.y - scroll_y * 50 * (self.ships_buttons_end_y - self.ships_buttons_begin_y) / ((len(self.ships_buttons) + 1) * self.ships_buttons_h)
|
self.ship_list_line.y = self.ship_list_line.y - scroll_y * 50 * (
|
||||||
|
self.ships_buttons_end_y - self.ships_buttons_begin_y
|
||||||
|
) / ((len(self.ships_buttons) + 1) * self.ships_buttons_h)
|
||||||
|
|
||||||
def on_command(self, command: CommandText, window: ClientWindow):
|
def on_command(self, command: CommandText, window: ClientWindow):
|
||||||
"""解析命令"""
|
"""解析命令"""
|
||||||
@ -726,12 +744,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def view(self, value: Mat4):
|
def view(self, value: Mat4):
|
||||||
self.window_pointer.view = value
|
self.window_pointer.view = value
|
||||||
|
|
||||||
from Difficult_Rocket.gui.widget.button import (
|
|
||||||
PressTextButton,
|
|
||||||
MinecraftWikiButtonTheme,
|
|
||||||
ButtonThemeOptions,
|
|
||||||
BaseButtonTheme,
|
|
||||||
)
|
|
||||||
class PressEnterGameButton(PressTextButton):
|
class PressEnterGameButton(PressTextButton):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -752,7 +765,6 @@ class PressEnterGameButton(PressTextButton):
|
|||||||
)
|
)
|
||||||
self.window = window
|
self.window = window
|
||||||
|
|
||||||
|
|
||||||
def on_mouse_release(self, x, y, buttons, modifiers):
|
def on_mouse_release(self, x, y, buttons, modifiers):
|
||||||
if self.pressed and (x, y) in self:
|
if self.pressed and (x, y) in self:
|
||||||
if self.draw_theme:
|
if self.draw_theme:
|
||||||
@ -763,8 +775,8 @@ class PressEnterGameButton(PressTextButton):
|
|||||||
|
|
||||||
logger.info("进入游戏")
|
logger.info("进入游戏")
|
||||||
|
|
||||||
from tkinter import Tk
|
|
||||||
from tkinter import filedialog
|
|
||||||
class PressSelectShipButton(PressTextButton):
|
class PressSelectShipButton(PressTextButton):
|
||||||
path_var = "./assets/builtin/dock1.xml"
|
path_var = "./assets/builtin/dock1.xml"
|
||||||
|
|
||||||
@ -789,7 +801,6 @@ class PressSelectShipButton(PressTextButton):
|
|||||||
self.window = window
|
self.window = window
|
||||||
self.parent_window = parent_window
|
self.parent_window = parent_window
|
||||||
|
|
||||||
|
|
||||||
def on_mouse_release(self, x, y, buttons, modifiers):
|
def on_mouse_release(self, x, y, buttons, modifiers):
|
||||||
if self.pressed and (x, y) in self:
|
if self.pressed and (x, y) in self:
|
||||||
if self.draw_theme:
|
if self.draw_theme:
|
||||||
@ -798,11 +809,11 @@ class PressSelectShipButton(PressTextButton):
|
|||||||
self.back_rec.color = self.touched_color
|
self.back_rec.color = self.touched_color
|
||||||
self.pressed = False
|
self.pressed = False
|
||||||
|
|
||||||
|
|
||||||
root = Tk() # 创建一个Tkinter.Tk()实例
|
root = Tk() # 创建一个Tkinter.Tk()实例
|
||||||
root.withdraw() # 将Tkinter.Tk()实例隐藏
|
root.withdraw() # 将Tkinter.Tk()实例隐藏
|
||||||
file_name= filedialog.askopenfilename(title='选择一个飞船存档',
|
file_name = filedialog.askopenfilename(
|
||||||
initialdir='./' # 打开当前程序工作目录
|
title="选择一个飞船存档",
|
||||||
|
initialdir="./", # 打开当前程序工作目录
|
||||||
)
|
)
|
||||||
self.path_var = file_name
|
self.path_var = file_name
|
||||||
self.parent_window.begin_ship_render_from_path(file_name)
|
self.parent_window.begin_ship_render_from_path(file_name)
|
||||||
@ -812,8 +823,8 @@ class PressSelectShipButton(PressTextButton):
|
|||||||
logger.info("加载飞船from " + self.path_var)
|
logger.info("加载飞船from " + self.path_var)
|
||||||
return self.path_var
|
return self.path_var
|
||||||
|
|
||||||
class PressOpenShipButton(PressTextButton):
|
|
||||||
|
|
||||||
|
class PressOpenShipButton(PressTextButton):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
window: ClientWindow,
|
window: ClientWindow,
|
||||||
@ -836,6 +847,7 @@ class PressOpenShipButton(PressTextButton):
|
|||||||
self.window = window
|
self.window = window
|
||||||
self.parent_window = parent_window
|
self.parent_window = parent_window
|
||||||
self.ship_path = ship_path
|
self.ship_path = ship_path
|
||||||
|
|
||||||
def set_y(self, y):
|
def set_y(self, y):
|
||||||
self.y = y
|
self.y = y
|
||||||
|
|
||||||
@ -852,11 +864,3 @@ class PressOpenShipButton(PressTextButton):
|
|||||||
|
|
||||||
self.parent_window.begin_ship_render_from_path(self.ship_path)
|
self.parent_window.begin_ship_render_from_path(self.ship_path)
|
||||||
logger.info("加载飞船from " + self.ship_path)
|
logger.info("加载飞船from " + self.ship_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from objprint import op
|
|
||||||
|
|
||||||
op(SR1ShipRenderStatus())
|
|
||||||
|
Loading…
Reference in New Issue
Block a user