Clicking on the main image changes its color
This commit is contained in:
parent
81de0d8eb0
commit
777668848e
|
@ -48,6 +48,10 @@ class Display:
|
|||
def color_pair(self, number: int) -> int:
|
||||
return curses.color_pair(number) if self.screen else 0
|
||||
|
||||
def init_color(self, number: int, red: int, green: int, blue: int) -> None:
|
||||
return curses.init_color(number, red, green, blue) \
|
||||
if self.screen else None
|
||||
|
||||
def resize(self, y: int, x: int, height: int, width: int,
|
||||
resize_pad: bool = True) -> None:
|
||||
self.x = x
|
||||
|
|
|
@ -102,13 +102,17 @@ class MainMenuDisplay(Display):
|
|||
self.pad = self.newpad(max(self.rows, len(self.title) + 30),
|
||||
max(len(self.title[0]) + 5, self.cols))
|
||||
|
||||
self.init_color(42, 1000, 1000, 1000)
|
||||
self.init_pair(42, 42, curses.COLOR_BLACK)
|
||||
|
||||
self.menudisplay = MenuDisplay(self.screen, self.pack)
|
||||
self.menudisplay.update_menu(self.menu)
|
||||
|
||||
def display(self) -> None:
|
||||
for i in range(len(self.title)):
|
||||
self.addstr(self.pad, 4 + i, max(self.width // 2
|
||||
- len(self.title[0]) // 2 - 1, 0), self.title[i])
|
||||
- len(self.title[0]) // 2 - 1, 0), self.title[i],
|
||||
self.color_pair(42))
|
||||
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
||||
self.height + self.y - 1,
|
||||
self.width + self.x - 1)
|
||||
|
@ -126,6 +130,11 @@ class MainMenuDisplay(Display):
|
|||
if menuy <= y < menuy + menuheight and menux <= x < menux + menuwidth:
|
||||
self.menudisplay.handle_click(y - menuy, x - menux, game)
|
||||
|
||||
if y <= len(self.title):
|
||||
from random import randint
|
||||
self.init_color(42, randint(0, 1000), randint(0, 1000),
|
||||
randint(0, 1000))
|
||||
|
||||
|
||||
class PlayerInventoryDisplay(MenuDisplay):
|
||||
message = _("== INVENTORY ==")
|
||||
|
|
|
@ -236,6 +236,9 @@ class TestGame(unittest.TestCase):
|
|||
"""
|
||||
self.game.state = GameMode.MAINMENU
|
||||
|
||||
# Change the color of the artwork
|
||||
self.game.display_actions(DisplayActions.MOUSE, 0, 10)
|
||||
|
||||
# Settings menu
|
||||
self.game.display_actions(DisplayActions.MOUSE, 25, 21)
|
||||
self.assertEqual(self.game.main_menu.position, 4)
|
||||
|
|
Loading…
Reference in New Issue