Maybe mouse clicks may use the game
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user