diff --git a/squirrelbattle/display/creditsdisplay.py b/squirrelbattle/display/creditsdisplay.py new file mode 100644 index 0000000..453fe8d --- /dev/null +++ b/squirrelbattle/display/creditsdisplay.py @@ -0,0 +1,76 @@ +# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse +# SPDX-License-Identifier: GPL-3.0-or-later + +import curses + +from ..display.display import Box, Display +from ..game import Game +from ..resources import ResourceManager +from ..translations import gettext as _ + + +class CreditsDisplay(Display): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.box = Box(*args, **kwargs) + self.pad = self.newpad(1, 1) + self.ascii_art_displayed = False + + def display(self) -> None: + self.box.refresh(self.y, self.x, self.height, self.width) + self.box.display() + self.pad.erase() + + messages = [ + _("Credits"), + "", + "Squirrel Battle", + "", + _("Developers:"), + "Yohann \"ÿnérant\" D'ANELLO", + "Mathilde \"eichhornchen\" DÉPRÉS", + "Nicolas \"nicomarg\" MARGULIES", + "Charles \"charsle\" PEYRAT", + "", + _("Translators:"), + "Hugo \"ifugao\" JACOB (español)", + ] + + for i, msg in enumerate(messages): + self.addstr(self.pad, i + (self.height - len(messages)) // 2, + (self.width - len(msg)) // 2, msg, + bold=(i == 0), italic=(":" in msg)) + + if self.ascii_art_displayed: + self.display_ascii_art() + + self.refresh_pad(self.pad, 0, 0, self.y + 1, self.x + 1, + self.height + self.y - 2, + self.width + self.x - 2) + + def display_ascii_art(self): + with open(ResourceManager.get_asset_path("ascii-art-ecureuil.txt"))\ + as f: + ascii_art = f.read().split("\n") + + height, width = len(ascii_art), len(ascii_art[0]) + y_offset, x_offset = (self.height - height) // 2,\ + (self.width - width) // 2 + + for i, line in enumerate(ascii_art): + for j, c in enumerate(line): + bg_color = curses.COLOR_WHITE + fg_color = curses.COLOR_BLACK + if c == '▓': + fg_color = (700, 300, 0) + elif c == '▒': + fg_color = (700, 300, 0) + bg_color = curses.COLOR_BLACK + elif c == '░': + fg_color = (350, 150, 0) + self.addstr(self.pad, y_offset + i, x_offset + j, c, + fg_color, bg_color) + + def handle_click(self, y: int, x: int, game: Game) -> None: + if self.pad.inch(y, x) != ord(" "): + self.ascii_art_displayed = True diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index b9d819c..d87ed9d 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later import curses + +from squirrelbattle.display.creditsdisplay import CreditsDisplay from squirrelbattle.display.display import VerticalSplit, HorizontalSplit, \ Display from squirrelbattle.display.mapdisplay import MapDisplay @@ -30,14 +32,15 @@ class DisplayManager: self.mainmenudisplay = MainMenuDisplay(self.game.main_menu, screen, pack) self.settingsmenudisplay = SettingsMenuDisplay(screen, pack) - self.messagedisplay = MessageDisplay(screen=screen, pack=None) + self.messagedisplay = MessageDisplay(screen, pack) self.hbar = HorizontalSplit(screen, pack) self.vbar = VerticalSplit(screen, pack) + self.creditsdisplay = CreditsDisplay(screen, pack) self.displays = [self.statsdisplay, self.mapdisplay, self.mainmenudisplay, self.settingsmenudisplay, self.logsdisplay, self.messagedisplay, self.playerinventorydisplay, - self.storeinventorydisplay] + self.storeinventorydisplay, self.creditsdisplay] self.update_game_components() def handle_display_action(self, action: DisplayActions, *params) -> None: @@ -123,6 +126,9 @@ class DisplayManager: elif self.game.state == GameMode.SETTINGS: self.settingsmenudisplay.refresh(0, 0, self.rows, self.cols) displays.append(self.settingsmenudisplay) + elif self.game.state == GameMode.CREDITS: + self.creditsdisplay.refresh(0, 0, self.rows, self.cols) + displays.append(self.creditsdisplay) if self.game.message: height, width = 0, 0 diff --git a/squirrelbattle/display/menudisplay.py b/squirrelbattle/display/menudisplay.py index 06bae1d..84a20ff 100644 --- a/squirrelbattle/display/menudisplay.py +++ b/squirrelbattle/display/menudisplay.py @@ -7,7 +7,7 @@ from typing import List from squirrelbattle.menus import Menu, MainMenu from .display import Box, Display -from ..enums import KeyValues +from ..enums import KeyValues, GameMode from ..game import Game from ..resources import ResourceManager from ..translations import gettext as _ @@ -113,6 +113,8 @@ class MainMenuDisplay(Display): self.addstr(self.pad, 4 + i, max(self.width // 2 - len(self.title[0]) // 2 - 1, 0), self.title[i], self.fg_color) + msg = _("Credits") + self.addstr(self.pad, self.height - 1, self.width - 1 - len(msg), msg) self.refresh_pad(self.pad, 0, 0, self.y, self.x, self.height + self.y - 1, self.width + self.x - 1) @@ -133,6 +135,9 @@ class MainMenuDisplay(Display): if y <= len(self.title): self.fg_color = randint(0, 1000), randint(0, 1000), randint(0, 1000) + if y == self.height - 1 and x >= self.width - 1 - len(_("Credits")): + game.state = GameMode.CREDITS + class PlayerInventoryDisplay(MenuDisplay): """ diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index d9b0735..2e1dd64 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -28,6 +28,7 @@ class GameMode(Enum): SETTINGS = auto() INVENTORY = auto() STORE = auto() + CREDITS = auto() class KeyValues(Enum): diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 72bbe2f..03dbfe7 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -103,6 +103,8 @@ class Game: self.settings_menu.handle_key_pressed(key, raw_key, self) elif self.state == GameMode.STORE: self.handle_key_pressed_store(key) + elif self.state == GameMode.CREDITS: + self.state = GameMode.MAINMENU self.display_actions(DisplayActions.REFRESH) def handle_key_pressed_play(self, key: KeyValues) -> None: