可以滑动的飞船列表

This commit is contained in:
ssssssssboom 2024-05-30 20:19:29 +08:00
parent ffe344d633
commit a58b93644b

View File

@ -154,6 +154,9 @@ class SR1ShipRender(BaseScreen):
)
# Buttons
self.buttons_group = Group(100, parent=main_window.main_group)
self.ships_buttons_group = Group(100, parent=main_window.main_group)
self.enter_game_button = PressEnterGameButton(
window=main_window,
x=500,
@ -162,7 +165,7 @@ class SR1ShipRender(BaseScreen):
height=30,
text="进入游戏",
batch=self.main_batch,
group=main_window.main_group,
group=self.buttons_group,
draw_theme=MinecraftWikiButtonTheme
)
@ -175,7 +178,7 @@ class SR1ShipRender(BaseScreen):
height=30,
text="加载飞船",
batch=self.main_batch,
group=main_window.main_group,
group=self.buttons_group,
draw_theme=MinecraftWikiButtonTheme,
)
@ -205,12 +208,36 @@ class SR1ShipRender(BaseScreen):
height=self.ships_buttons_h,
text=ships_files[i][8:],
batch=self.main_batch,
group=main_window.main_group,
group=self.ships_buttons_group,
draw_theme=MinecraftWikiButtonTheme,
))
main_window.push_handlers(self.ships_buttons[-1])
self.ship_list_line_back = Line(
self.ships_buttons_begin_x - 4,
self.ships_buttons_begin_y,
self.ships_buttons_begin_x - 4,
self.ships_buttons_end_y,
width=5,
color=(100, 100, 100, 255),
batch=self.main_batch,
group=self.ships_buttons_group,
)
self.ship_list_line = Line(
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),
x2 = self.ships_buttons_begin_x,
y2 = self.ships_buttons_end_y,
width=20,
color=(200, 200, 200, 255),
batch=self.main_batch,
group=self.ships_buttons_group,
)
self.ships_buttons_group.visible = False
@property
@ -466,7 +493,7 @@ class SR1ShipRender(BaseScreen):
def on_mouse_scroll(
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)
# 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 \
(self.show_ships_buttons == False or \
(not (self.show_ships_buttons == True \
@ -515,17 +542,17 @@ class SR1ShipRender(BaseScreen):
for ship_button in self.ships_buttons:
min_y = min(min_y, ship_button.y)
max_y = max(max_y, ship_button.y)
if max_y + scroll_y * 50 <= self.height:
scroll_y = (self.height - max_y) / 50
if max_y + scroll_y * 50 <= self.height - self.ships_buttons_h:
scroll_y = (self.height - self.ships_buttons_h - max_y) / 50
if min_y + scroll_y * 50 >= 10:
scroll_y = (10 - min_y) / 50
if min_y + scroll_y * 50 >= 0:
scroll_y = (0 - min_y) / 50
for ship_button in self.ships_buttons:
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)