Update keybindings and enhance loading screen functionality

- Refactor keybindings for gas spawning across multiple configurations
- Implement new loading screen updates during game initialization
- Add tests to ensure all weapon actions are exposed in keybinding profiles
- Introduce new assets for explosion effects
This commit is contained in:
2026-05-09 13:29:32 +02:00
parent 310dc0dca9
commit d9d7a4ac82
16 changed files with 306 additions and 21 deletions
+16 -1
View File
@@ -278,6 +278,9 @@ class KeyBindings:
def spawn_new_nuclear_bomb(self):
self.spawn_nuclear_bomb(self.pointer)
def spawn_new_gas(self):
self.spawn_gas()
def toggle_audio(self):
self.render_engine.audio = not self.render_engine.audio
self.audio = self.render_engine.audio
@@ -287,7 +290,19 @@ class KeyBindings:
self.render_engine.stop_sound()
def toggle_pause(self):
self.game_status = "paused" if self.game_status == "game" else "game"
if getattr(self, "game_end", (False, None))[0]:
return
if self.game_status == "game":
self.game_status = "paused"
return
if self.game_status == "paused":
self.game_status = "game"
return
if self.game_status == "start_menu" and getattr(self, "menu_screen", None) == "start":
self.reset_game()
def toggle_full_screen(self):
self.full_screen = not self.full_screen
+31
View File
@@ -9,6 +9,12 @@ class Graphics():
def load_assets(self):
theme_index = self.get_theme_index()
print(f"[gfx] load_assets requested: level={self.current_level + 1} theme={theme_index}")
if getattr(self, "startup_loading_active", False):
self._update_startup_loading(
"Loading graphics",
detail=f"Preparing theme {theme_index}",
progress=0.3,
)
if not hasattr(self, "theme_assets_cache"):
self.theme_assets_cache = {}
if not hasattr(self, "blood_layer_sprites"):
@@ -18,6 +24,12 @@ class Graphics():
if not getattr(self, "common_assets_loaded", False):
print("Loading graphics assets...")
if getattr(self, "startup_loading_active", False):
self._update_startup_loading(
"Loading graphics",
detail="Decoding sprites and tiles",
progress=0.4,
)
self.rat_assets = {}
self.rat_assets_textures = {}
self.rat_image_sizes = {}
@@ -56,6 +68,12 @@ class Graphics():
)
print("Pre-generating blood stain pool...")
if getattr(self, "startup_loading_active", False):
self._update_startup_loading(
"Loading graphics",
detail="Generating blood pool",
progress=0.58,
)
self.blood_stain_textures = []
for _ in range(10):
blood_surface = self.render_engine.generate_blood_surface()
@@ -70,6 +88,12 @@ class Graphics():
if theme_index not in self.theme_assets_cache:
print(f"Loading theme assets {theme_index}...")
if getattr(self, "startup_loading_active", False):
self._update_startup_loading(
"Loading graphics",
detail=f"Loading theme {theme_index} art",
progress=0.74,
)
self.theme_assets_cache[theme_index] = {
"floor_tile": self.render_engine.create_color_surface((128, 128, 128)),
"tunnel": self.render_engine.load_image("Rat/BMP_TUNNEL.png"),
@@ -122,6 +146,13 @@ class Graphics():
else:
print(f"[gfx] theme cache hit -> reusing theme {theme_index}")
if getattr(self, "startup_loading_active", False):
self._update_startup_loading(
"Loading graphics",
detail="Finishing render setup",
progress=0.84,
)
self.loaded_theme_index = theme_index
theme_assets = self.theme_assets_cache[theme_index]
self.floor_tile = theme_assets["floor_tile"]
+53
View File
@@ -35,6 +35,9 @@ CONTROLLER_BUTTON_NAMES = {
sdl2.SDL_CONTROLLER_BUTTON_DPAD_RIGHT: "dpad_right",
}
if hasattr(sdl2, "SDL_CONTROLLER_BUTTON_MISC1"):
CONTROLLER_BUTTON_NAMES[sdl2.SDL_CONTROLLER_BUTTON_MISC1] = "misc1"
def _decode_sdl_string(value):
if not value:
@@ -92,6 +95,8 @@ class GameWindow:
# Font system
self.fonts = self.generate_fonts("assets/decterm.ttf")
self.show_loading_screen("Loading Mice!", detail="Initializing renderer", progress=0.02)
# Initial loading dialog
# self.dialog("Loading assets...")
@@ -377,6 +382,54 @@ class GameWindow:
else:
self.renderer.draw_rect((x, y, width, height), sdl2.ext.Color(*outline))
def show_loading_screen(self, message="Loading Mice!", detail=None, progress=None):
"""Render a simple loading splash while startup work is in progress."""
self.window.show()
target_width, target_height = self.target_size
panel_width = min(720, max(420, target_width - 120))
panel_height = 230 if detail or progress is not None else 190
panel_x = (target_width - panel_width) // 2
panel_y = (target_height - panel_height) // 2
clamped_progress = None
if progress is not None:
clamped_progress = max(0.0, min(1.0, float(progress)))
self.renderer.clear()
self.draw_rectangle(0, 0, target_width, target_height, "loading-bg", filling=(10, 12, 18))
self.draw_rectangle(panel_x, panel_y, panel_width, panel_height, "loading-panel", filling=(24, 29, 38))
self.draw_rectangle(panel_x, panel_y, panel_width, panel_height, "loading-panel-outline", outline=(90, 98, 112))
self.draw_rectangle(panel_x, panel_y, panel_width, 6, "loading-panel-accent", filling=(241, 196, 92))
self.draw_text("MICE!", self.fonts[52], ("center", panel_y + 28), (240, 240, 240))
self.draw_text(message, self.fonts[28], ("center", panel_y + 102), (241, 196, 92))
if detail:
self.draw_text(detail, self.fonts[18], ("center", panel_y + 146), (208, 212, 218))
if clamped_progress is not None:
bar_width = panel_width - 80
bar_height = 18
bar_x = panel_x + 40
bar_y = panel_y + panel_height - 48
self.draw_rectangle(bar_x, bar_y, bar_width, bar_height, "loading-bar-track", filling=(54, 60, 72))
self.draw_rectangle(bar_x, bar_y, bar_width, bar_height, "loading-bar-outline", outline=(90, 98, 112))
fill_width = int((bar_width - 4) * clamped_progress)
if fill_width > 0:
self.draw_rectangle(
bar_x + 2,
bar_y + 2,
fill_width,
bar_height - 4,
"loading-bar-fill",
filling=(241, 196, 92),
)
self.renderer.present()
sdl2.SDL_PumpEvents()
def draw_pointer(self, x, y):
"""Draw a red pointer rectangle at specified coordinates"""
x = x + self.w_offset