Screen is refreshed only when pads are all refreshed, fixes #50

This commit is contained in:
Yohann D'ANELLO 2020-12-18 16:40:52 +01:00
parent 5ae49e71ff
commit 77f52b6276
6 changed files with 25 additions and 14 deletions

View File

@ -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:
"""

View File

@ -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)

View File

@ -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:

View File

@ -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"))

View File

@ -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()

View File

@ -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: