Screen is refreshed only when pads are all refreshed, fixes #50
This commit is contained in:
		@@ -159,7 +159,7 @@ class Display:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if last_y >= window_y and last_x >= window_x:
 | 
					        if last_y >= window_y and last_x >= window_x:
 | 
				
			||||||
            # Refresh the pad only if coordinates are valid
 | 
					            # 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:
 | 
					    def display(self) -> None:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,7 @@ class DisplayManager:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def refresh(self) -> List[Display]:
 | 
					    def refresh(self) -> List[Display]:
 | 
				
			||||||
        displays = []
 | 
					        displays = []
 | 
				
			||||||
 | 
					        pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.game.state == GameMode.PLAY \
 | 
					        if self.game.state == GameMode.PLAY \
 | 
				
			||||||
                or self.game.state == GameMode.INVENTORY \
 | 
					                or self.game.state == GameMode.INVENTORY \
 | 
				
			||||||
@@ -93,16 +94,22 @@ class DisplayManager:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if self.game.state == GameMode.INVENTORY:
 | 
					            if self.game.state == GameMode.INVENTORY:
 | 
				
			||||||
                self.playerinventorydisplay.refresh(
 | 
					                self.playerinventorydisplay.refresh(
 | 
				
			||||||
                    self.rows // 10, self.cols // 2,
 | 
					                    self.rows // 10,
 | 
				
			||||||
                    8 * self.rows // 10, 2 * self.cols // 5)
 | 
					                    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)
 | 
					                displays.append(self.playerinventorydisplay)
 | 
				
			||||||
            elif self.game.state == GameMode.STORE:
 | 
					            elif self.game.state == GameMode.STORE:
 | 
				
			||||||
                self.storeinventorydisplay.refresh(
 | 
					                self.storeinventorydisplay.refresh(
 | 
				
			||||||
                    self.rows // 10, self.cols // 2,
 | 
					                    self.rows // 10,
 | 
				
			||||||
                    8 * self.rows // 10, 2 * self.cols // 5)
 | 
					                    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.playerinventorydisplay.refresh(
 | 
				
			||||||
                    self.rows // 10, self.cols // 10,
 | 
					                    self.rows // 10,
 | 
				
			||||||
                    8 * self.rows // 10, 2 * self.cols // 5)
 | 
					                    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.storeinventorydisplay)
 | 
				
			||||||
                displays.append(self.playerinventorydisplay)
 | 
					                displays.append(self.playerinventorydisplay)
 | 
				
			||||||
        elif self.game.state == GameMode.MAINMENU:
 | 
					        elif self.game.state == GameMode.MAINMENU:
 | 
				
			||||||
@@ -117,7 +124,8 @@ class DisplayManager:
 | 
				
			|||||||
            for line in self.game.message.split("\n"):
 | 
					            for line in self.game.message.split("\n"):
 | 
				
			||||||
                height += 1
 | 
					                height += 1
 | 
				
			||||||
                width = max(width, len(line))
 | 
					                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)
 | 
					            self.messagedisplay.refresh(y, x, height, width)
 | 
				
			||||||
            displays.append(self.messagedisplay)
 | 
					            displays.append(self.messagedisplay)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,7 @@ class MapDisplay(Display):
 | 
				
			|||||||
                               self.pack.tile_width * self.map.width + 1)
 | 
					                               self.pack.tile_width * self.map.width + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_pad(self) -> None:
 | 
					    def update_pad(self) -> None:
 | 
				
			||||||
 | 
					        self.pad.resize(500, 500)
 | 
				
			||||||
        self.addstr(self.pad, 0, 0, self.map.draw_string(self.pack),
 | 
					        self.addstr(self.pad, 0, 0, self.map.draw_string(self.pack),
 | 
				
			||||||
                    self.pack.tile_fg_color, self.pack.tile_bg_color)
 | 
					                    self.pack.tile_fg_color, self.pack.tile_bg_color)
 | 
				
			||||||
        for e in self.map.entities:
 | 
					        for e in self.map.entities:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -154,7 +154,7 @@ class PlayerInventoryDisplay(MenuDisplay):
 | 
				
			|||||||
        self.update_menu(game.inventory_menu)
 | 
					        self.update_menu(game.inventory_menu)
 | 
				
			||||||
        self.store_mode = game.state == GameMode.STORE
 | 
					        self.store_mode = game.state == GameMode.STORE
 | 
				
			||||||
        self.selected = game.state == GameMode.INVENTORY \
 | 
					        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:
 | 
					    def update_pad(self) -> None:
 | 
				
			||||||
        self.menubox.update_title(_("INVENTORY"))
 | 
					        self.menubox.update_title(_("INVENTORY"))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,16 +61,18 @@ class Game:
 | 
				
			|||||||
        self.map.spawn_random_entities(randint(3, 10))
 | 
					        self.map.spawn_random_entities(randint(3, 10))
 | 
				
			||||||
        self.inventory_menu.update_player(self.player)
 | 
					        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.
 | 
					        Main infinite loop.
 | 
				
			||||||
        We wait for the player's action, then we do what that should be done
 | 
					        We wait for the player's action, then we do what that should be done
 | 
				
			||||||
        when the given key gets pressed.
 | 
					        when the given key gets pressed.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        while True:  # pragma no cover
 | 
					        screen.refresh()
 | 
				
			||||||
 | 
					        while True:
 | 
				
			||||||
            screen.erase()
 | 
					            screen.erase()
 | 
				
			||||||
            screen.refresh()
 | 
					            screen.noutrefresh()
 | 
				
			||||||
            self.display_actions(DisplayActions.REFRESH)
 | 
					            self.display_actions(DisplayActions.REFRESH)
 | 
				
			||||||
 | 
					            curses.doupdate()
 | 
				
			||||||
            key = screen.getkey()
 | 
					            key = screen.getkey()
 | 
				
			||||||
            if key == "KEY_MOUSE":
 | 
					            if key == "KEY_MOUSE":
 | 
				
			||||||
                _ignored1, x, y, _ignored2, _ignored3 = curses.getmouse()
 | 
					                _ignored1, x, y, _ignored2, _ignored3 = curses.getmouse()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,8 +12,8 @@ class FakePad:
 | 
				
			|||||||
    def addstr(self, y: int, x: int, message: str, color: int = 0) -> None:
 | 
					    def addstr(self, y: int, x: int, message: str, color: int = 0) -> None:
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def refresh(self, pminrow: int, pmincol: int, sminrow: int,
 | 
					    def noutrefresh(self, pminrow: int, pmincol: int, sminrow: int,
 | 
				
			||||||
                smincol: int, smaxrow: int, smaxcol: int) -> None:
 | 
					                    smincol: int, smaxrow: int, smaxcol: int) -> None:
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def erase(self) -> None:
 | 
					    def erase(self) -> None:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user