diff --git a/squirrelbattle/display/display.py b/squirrelbattle/display/display.py index 023ad6e..6257427 100644 --- a/squirrelbattle/display/display.py +++ b/squirrelbattle/display/display.py @@ -159,7 +159,7 @@ class Display: if last_y >= window_y and last_x >= window_x: # Refresh the pad only if coordinates are valid - pad.refresh(top_y, top_x, window_y, window_x, last_y, last_x) + pad.noutrefresh(top_y, top_x, window_y, window_x, last_y, last_x) def display(self) -> None: """ diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index 3481348..70879b1 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -71,6 +71,7 @@ class DisplayManager: def refresh(self) -> List[Display]: displays = [] + pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK) if self.game.state == GameMode.PLAY \ or self.game.state == GameMode.INVENTORY \ @@ -93,16 +94,22 @@ class DisplayManager: if self.game.state == GameMode.INVENTORY: self.playerinventorydisplay.refresh( - self.rows // 10, self.cols // 2, - 8 * self.rows // 10, 2 * self.cols // 5) + self.rows // 10, + pack.tile_width * (self.cols // (2 * pack.tile_width)), + 8 * self.rows // 10, + pack.tile_width * (2 * self.cols // (5 * pack.tile_width))) displays.append(self.playerinventorydisplay) elif self.game.state == GameMode.STORE: self.storeinventorydisplay.refresh( - self.rows // 10, self.cols // 2, - 8 * self.rows // 10, 2 * self.cols // 5) + self.rows // 10, + pack.tile_width * (self.cols // (2 * pack.tile_width)), + 8 * self.rows // 10, + pack.tile_width * (2 * self.cols // (5 * pack.tile_width))) self.playerinventorydisplay.refresh( - self.rows // 10, self.cols // 10, - 8 * self.rows // 10, 2 * self.cols // 5) + self.rows // 10, + pack.tile_width * (self.cols // (10 * pack.tile_width)), + 8 * self.rows // 10, + pack.tile_width * (2 * self.cols // (5 * pack.tile_width))) displays.append(self.storeinventorydisplay) displays.append(self.playerinventorydisplay) elif self.game.state == GameMode.MAINMENU: @@ -117,7 +124,8 @@ class DisplayManager: for line in self.game.message.split("\n"): height += 1 width = max(width, len(line)) - y, x = (self.rows - height) // 2, (self.cols - width) // 2 + y = pack.tile_width * (self.rows - height) // (2 * pack.tile_width) + x = pack.tile_width * ((self.cols - width) // (2 * pack.tile_width)) self.messagedisplay.refresh(y, x, height, width) displays.append(self.messagedisplay) diff --git a/squirrelbattle/display/mapdisplay.py b/squirrelbattle/display/mapdisplay.py index b10619e..7e21adb 100644 --- a/squirrelbattle/display/mapdisplay.py +++ b/squirrelbattle/display/mapdisplay.py @@ -18,6 +18,7 @@ class MapDisplay(Display): self.pack.tile_width * self.map.width + 1) def update_pad(self) -> None: + self.pad.resize(500, 500) self.addstr(self.pad, 0, 0, self.map.draw_string(self.pack), self.pack.tile_fg_color, self.pack.tile_bg_color) for e in self.map.entities: diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index 9140ca7..c71142e 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -154,7 +154,7 @@ class PlayerInventoryDisplay(MenuDisplay): self.update_menu(game.inventory_menu) self.store_mode = game.state == GameMode.STORE self.selected = game.state == GameMode.INVENTORY \ - or self.store_mode and not game.is_in_store_menu + or (self.store_mode and not game.is_in_store_menu) def update_pad(self) -> None: self.menubox.update_title(_("INVENTORY")) diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index b0a65f4..0553d2e 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -61,16 +61,18 @@ class Game: self.map.spawn_random_entities(randint(3, 10)) self.inventory_menu.update_player(self.player) - def run(self, screen: Any) -> None: + def run(self, screen: Any) -> None: # pragma no cover """ Main infinite loop. We wait for the player's action, then we do what that should be done when the given key gets pressed. """ - while True: # pragma no cover + screen.refresh() + while True: screen.erase() - screen.refresh() + screen.noutrefresh() self.display_actions(DisplayActions.REFRESH) + curses.doupdate() key = screen.getkey() if key == "KEY_MOUSE": _ignored1, x, y, _ignored2, _ignored3 = curses.getmouse() diff --git a/squirrelbattle/tests/screen.py b/squirrelbattle/tests/screen.py index 9a8afe6..470aeef 100644 --- a/squirrelbattle/tests/screen.py +++ b/squirrelbattle/tests/screen.py @@ -12,8 +12,8 @@ class FakePad: def addstr(self, y: int, x: int, message: str, color: int = 0) -> None: pass - def refresh(self, pminrow: int, pmincol: int, sminrow: int, - smincol: int, smaxrow: int, smaxcol: int) -> None: + def noutrefresh(self, pminrow: int, pmincol: int, sminrow: int, + smincol: int, smaxrow: int, smaxcol: int) -> None: pass def erase(self) -> None: