Listen to mouse clicks in the main loop
This commit is contained in:
parent
1afa397fec
commit
d9912cacad
|
@ -50,10 +50,8 @@ class KeyValues(Enum):
|
||||||
"""
|
"""
|
||||||
Translate the raw string key into an enum value that we can use.
|
Translate the raw string key into an enum value that we can use.
|
||||||
"""
|
"""
|
||||||
if key == "KEY_MOUSE":
|
if key in (settings.KEY_DOWN_SECONDARY,
|
||||||
return KeyValues.MOUSE
|
settings.KEY_DOWN_PRIMARY):
|
||||||
elif key in (settings.KEY_DOWN_SECONDARY,
|
|
||||||
settings.KEY_DOWN_PRIMARY):
|
|
||||||
return KeyValues.DOWN
|
return KeyValues.DOWN
|
||||||
elif key in (settings.KEY_LEFT_PRIMARY,
|
elif key in (settings.KEY_LEFT_PRIMARY,
|
||||||
settings.KEY_LEFT_SECONDARY):
|
settings.KEY_LEFT_SECONDARY):
|
||||||
|
|
|
@ -68,8 +68,12 @@ class Game:
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
self.display_actions(DisplayActions.REFRESH)
|
self.display_actions(DisplayActions.REFRESH)
|
||||||
key = screen.getkey()
|
key = screen.getkey()
|
||||||
self.handle_key_pressed(
|
if key == "KEY_MOUSE":
|
||||||
KeyValues.translate_key(key, self.settings), key)
|
_ignored1, x, y, _ignored2, _ignored3 = curses.getmouse()
|
||||||
|
self.display_actions(DisplayActions.MOUSE, y, x)
|
||||||
|
else:
|
||||||
|
self.handle_key_pressed(
|
||||||
|
KeyValues.translate_key(key, self.settings), key)
|
||||||
|
|
||||||
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\
|
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str = '')\
|
||||||
-> None:
|
-> None:
|
||||||
|
@ -82,11 +86,6 @@ class Game:
|
||||||
self.display_actions(DisplayActions.REFRESH)
|
self.display_actions(DisplayActions.REFRESH)
|
||||||
return
|
return
|
||||||
|
|
||||||
if key == KeyValues.MOUSE:
|
|
||||||
_ignored1, x, y, _ignored2, _ignored3 = curses.getmouse()
|
|
||||||
self.display_actions(DisplayActions.MOUSE, y, x)
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.state == GameMode.PLAY:
|
if self.state == GameMode.PLAY:
|
||||||
self.handle_key_pressed_play(key)
|
self.handle_key_pressed_play(key)
|
||||||
elif self.state == GameMode.INVENTORY:
|
elif self.state == GameMode.INVENTORY:
|
||||||
|
|
Loading…
Reference in New Issue