Capture all mouse events and take into account mouse attributes, fixes #58
This commit is contained in:
		@@ -92,6 +92,6 @@ class CreditsDisplay(Display):
 | 
			
		||||
                self.addstr(self.pad, y_offset + i, x_offset + j, c,
 | 
			
		||||
                            fg_color, bg_color, bold=bold)
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        if self.pad.inch(y - 1, x - 1) != ord(" "):
 | 
			
		||||
            self.ascii_art_displayed = True
 | 
			
		||||
 
 | 
			
		||||
@@ -187,12 +187,11 @@ class Display:
 | 
			
		||||
        """
 | 
			
		||||
        raise NotImplementedError
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        A mouse click was performed on the coordinates (y, x) of the pad.
 | 
			
		||||
        Maybe it should do something.
 | 
			
		||||
        """
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def rows(self) -> int:
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ class DisplayManager:
 | 
			
		||||
            d.pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
 | 
			
		||||
            d.update(self.game)
 | 
			
		||||
 | 
			
		||||
    def handle_mouse_click(self, y: int, x: int) -> None:
 | 
			
		||||
    def handle_mouse_click(self, y: int, x: int, attr: int) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Handles the mouse clicks.
 | 
			
		||||
        """
 | 
			
		||||
@@ -76,7 +76,7 @@ class DisplayManager:
 | 
			
		||||
                # of that display
 | 
			
		||||
                display = d
 | 
			
		||||
        if display:
 | 
			
		||||
            display.handle_click(y - display.y, x - display.x, self.game)
 | 
			
		||||
            display.handle_click(y - display.y, x - display.x, attr, self.game)
 | 
			
		||||
 | 
			
		||||
    def refresh(self) -> List[Display]:
 | 
			
		||||
        """
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ class MenuDisplay(Display):
 | 
			
		||||
                         self.height - 2 + self.y,
 | 
			
		||||
                         self.width - 2 + self.x)
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        We can select a menu item with the mouse.
 | 
			
		||||
        """
 | 
			
		||||
@@ -134,13 +134,13 @@ class MainMenuDisplay(Display):
 | 
			
		||||
    def update(self, game: Game) -> None:
 | 
			
		||||
        self.menudisplay.update_menu(game.main_menu)
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        menuwidth = min(self.menudisplay.preferred_width, self.width)
 | 
			
		||||
        menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
 | 
			
		||||
        menuheight = min(self.menudisplay.preferred_height, self.height - menuy)
 | 
			
		||||
 | 
			
		||||
        if menuy <= y < menuy + menuheight and menux <= x < menux + menuwidth:
 | 
			
		||||
            self.menudisplay.handle_click(y - menuy, x - menux, game)
 | 
			
		||||
            self.menudisplay.handle_click(y - menuy, x - menux, attr, game)
 | 
			
		||||
 | 
			
		||||
        if y <= len(self.title):
 | 
			
		||||
            self.fg_color = randint(0, 1000), randint(0, 1000), randint(0, 1000)
 | 
			
		||||
@@ -189,7 +189,7 @@ class PlayerInventoryDisplay(MenuDisplay):
 | 
			
		||||
    def trueheight(self) -> int:
 | 
			
		||||
        return 2 + super().trueheight
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        We can select a menu item with the mouse.
 | 
			
		||||
        """
 | 
			
		||||
@@ -232,7 +232,7 @@ class StoreInventoryDisplay(MenuDisplay):
 | 
			
		||||
    def trueheight(self) -> int:
 | 
			
		||||
        return 2 + super().trueheight
 | 
			
		||||
 | 
			
		||||
    def handle_click(self, y: int, x: int, game: Game) -> None:
 | 
			
		||||
    def handle_click(self, y: int, x: int, attr: int, game: Game) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        We can select a menu item with the mouse.
 | 
			
		||||
        """
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user