Maybe mouse clicks may use the game
This commit is contained in:
parent
d50f6701f4
commit
089a247b2f
|
@ -5,6 +5,7 @@ import curses
|
|||
from typing import Any, Optional, Union
|
||||
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
from squirrelbattle.game import Game
|
||||
from squirrelbattle.tests.screen import FakePad
|
||||
|
||||
|
||||
|
@ -86,7 +87,7 @@ class Display:
|
|||
def display(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
def handle_click(self, y: int, x: int) -> None:
|
||||
def handle_click(self, y: int, x: int, game: Game) -> None:
|
||||
"""
|
||||
A mouse click was performed on the coordinates (y, x) of the pad.
|
||||
Maybe it can do something.
|
||||
|
|
|
@ -65,7 +65,7 @@ class DisplayManager:
|
|||
# of that display
|
||||
display = d
|
||||
if display:
|
||||
display.handle_click(y - display.y, x - display.x)
|
||||
display.handle_click(y - display.y, x - display.x, self.game)
|
||||
|
||||
def refresh(self) -> List[Display]:
|
||||
displays = []
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import curses
|
||||
from typing import List
|
||||
|
||||
from squirrelbattle.menus import Menu, MainMenu
|
||||
from .display import Display, Box
|
||||
from ..enums import KeyValues
|
||||
from ..game import Game
|
||||
from ..resources import ResourceManager
|
||||
from ..translations import gettext as _
|
||||
|
||||
|
@ -41,12 +44,12 @@ class MenuDisplay(Display):
|
|||
self.height - 2 + self.y,
|
||||
self.width - 2 + self.x)
|
||||
|
||||
def handle_click(self, y: int, x: int) -> None:
|
||||
def handle_click(self, y: int, x: int, game: Game) -> None:
|
||||
"""
|
||||
We can select a menu item with the mouse.
|
||||
"""
|
||||
self.menu.position = y - 1
|
||||
curses.ungetch('\n')
|
||||
game.handle_key_pressed(KeyValues.ENTER)
|
||||
|
||||
@property
|
||||
def truewidth(self) -> int:
|
||||
|
@ -106,13 +109,13 @@ class MainMenuDisplay(Display):
|
|||
menuy, menux, min(self.menudisplay.preferred_height,
|
||||
self.height - menuy), menuwidth)
|
||||
|
||||
def handle_click(self, y: int, x: int) -> None:
|
||||
def handle_click(self, y: int, x: 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)
|
||||
self.menudisplay.handle_click(y - menuy, x - menux, game)
|
||||
|
||||
|
||||
class InventoryDisplay(MenuDisplay):
|
||||
|
|
Loading…
Reference in New Issue