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:
|
def color_pair(self, number: int) -> int:
|
||||||
return curses.color_pair(number) if self.screen else 0
|
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,
|
def resize(self, y: int, x: int, height: int, width: int,
|
||||||
resize_pad: bool = True) -> None:
|
resize_pad: bool = True) -> None:
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|
|
@ -102,13 +102,17 @@ class MainMenuDisplay(Display):
|
||||||
self.pad = self.newpad(max(self.rows, len(self.title) + 30),
|
self.pad = self.newpad(max(self.rows, len(self.title) + 30),
|
||||||
max(len(self.title[0]) + 5, self.cols))
|
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 = MenuDisplay(self.screen, self.pack)
|
||||||
self.menudisplay.update_menu(self.menu)
|
self.menudisplay.update_menu(self.menu)
|
||||||
|
|
||||||
def display(self) -> None:
|
def display(self) -> None:
|
||||||
for i in range(len(self.title)):
|
for i in range(len(self.title)):
|
||||||
self.addstr(self.pad, 4 + i, max(self.width // 2
|
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.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
||||||
self.height + self.y - 1,
|
self.height + self.y - 1,
|
||||||
self.width + self.x - 1)
|
self.width + self.x - 1)
|
||||||
|
@ -126,6 +130,11 @@ class MainMenuDisplay(Display):
|
||||||
if menuy <= y < menuy + menuheight and menux <= x < menux + menuwidth:
|
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, 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):
|
class PlayerInventoryDisplay(MenuDisplay):
|
||||||
message = _("== INVENTORY ==")
|
message = _("== INVENTORY ==")
|
||||||
|
|
|
@ -236,6 +236,9 @@ class TestGame(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
self.game.state = GameMode.MAINMENU
|
self.game.state = GameMode.MAINMENU
|
||||||
|
|
||||||
|
# Change the color of the artwork
|
||||||
|
self.game.display_actions(DisplayActions.MOUSE, 0, 10)
|
||||||
|
|
||||||
# Settings menu
|
# Settings menu
|
||||||
self.game.display_actions(DisplayActions.MOUSE, 25, 21)
|
self.game.display_actions(DisplayActions.MOUSE, 25, 21)
|
||||||
self.assertEqual(self.game.main_menu.position, 4)
|
self.assertEqual(self.game.main_menu.position, 4)
|
||||||
|
|
Loading…
Reference in New Issue