Add credits menu, see #42
This commit is contained in:
parent
ea5f5c1428
commit
411744bf10
|
@ -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
|
|
@ -2,6 +2,8 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
|
from squirrelbattle.display.creditsdisplay import CreditsDisplay
|
||||||
from squirrelbattle.display.display import VerticalSplit, HorizontalSplit, \
|
from squirrelbattle.display.display import VerticalSplit, HorizontalSplit, \
|
||||||
Display
|
Display
|
||||||
from squirrelbattle.display.mapdisplay import MapDisplay
|
from squirrelbattle.display.mapdisplay import MapDisplay
|
||||||
|
@ -30,14 +32,15 @@ class DisplayManager:
|
||||||
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
||||||
screen, pack)
|
screen, pack)
|
||||||
self.settingsmenudisplay = SettingsMenuDisplay(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.hbar = HorizontalSplit(screen, pack)
|
||||||
self.vbar = VerticalSplit(screen, pack)
|
self.vbar = VerticalSplit(screen, pack)
|
||||||
|
self.creditsdisplay = CreditsDisplay(screen, pack)
|
||||||
self.displays = [self.statsdisplay, self.mapdisplay,
|
self.displays = [self.statsdisplay, self.mapdisplay,
|
||||||
self.mainmenudisplay, self.settingsmenudisplay,
|
self.mainmenudisplay, self.settingsmenudisplay,
|
||||||
self.logsdisplay, self.messagedisplay,
|
self.logsdisplay, self.messagedisplay,
|
||||||
self.playerinventorydisplay,
|
self.playerinventorydisplay,
|
||||||
self.storeinventorydisplay]
|
self.storeinventorydisplay, self.creditsdisplay]
|
||||||
self.update_game_components()
|
self.update_game_components()
|
||||||
|
|
||||||
def handle_display_action(self, action: DisplayActions, *params) -> None:
|
def handle_display_action(self, action: DisplayActions, *params) -> None:
|
||||||
|
@ -123,6 +126,9 @@ class DisplayManager:
|
||||||
elif self.game.state == GameMode.SETTINGS:
|
elif self.game.state == GameMode.SETTINGS:
|
||||||
self.settingsmenudisplay.refresh(0, 0, self.rows, self.cols)
|
self.settingsmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||||
displays.append(self.settingsmenudisplay)
|
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:
|
if self.game.message:
|
||||||
height, width = 0, 0
|
height, width = 0, 0
|
||||||
|
|
|
@ -7,7 +7,7 @@ from typing import List
|
||||||
|
|
||||||
from squirrelbattle.menus import Menu, MainMenu
|
from squirrelbattle.menus import Menu, MainMenu
|
||||||
from .display import Box, Display
|
from .display import Box, Display
|
||||||
from ..enums import KeyValues
|
from ..enums import KeyValues, GameMode
|
||||||
from ..game import Game
|
from ..game import Game
|
||||||
from ..resources import ResourceManager
|
from ..resources import ResourceManager
|
||||||
from ..translations import gettext as _
|
from ..translations import gettext as _
|
||||||
|
@ -113,6 +113,8 @@ class MainMenuDisplay(Display):
|
||||||
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.fg_color)
|
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.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)
|
||||||
|
@ -133,6 +135,9 @@ class MainMenuDisplay(Display):
|
||||||
if y <= len(self.title):
|
if y <= len(self.title):
|
||||||
self.fg_color = randint(0, 1000), randint(0, 1000), randint(0, 1000)
|
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):
|
class PlayerInventoryDisplay(MenuDisplay):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -28,6 +28,7 @@ class GameMode(Enum):
|
||||||
SETTINGS = auto()
|
SETTINGS = auto()
|
||||||
INVENTORY = auto()
|
INVENTORY = auto()
|
||||||
STORE = auto()
|
STORE = auto()
|
||||||
|
CREDITS = auto()
|
||||||
|
|
||||||
|
|
||||||
class KeyValues(Enum):
|
class KeyValues(Enum):
|
||||||
|
|
|
@ -103,6 +103,8 @@ class Game:
|
||||||
self.settings_menu.handle_key_pressed(key, raw_key, self)
|
self.settings_menu.handle_key_pressed(key, raw_key, self)
|
||||||
elif self.state == GameMode.STORE:
|
elif self.state == GameMode.STORE:
|
||||||
self.handle_key_pressed_store(key)
|
self.handle_key_pressed_store(key)
|
||||||
|
elif self.state == GameMode.CREDITS:
|
||||||
|
self.state = GameMode.MAINMENU
|
||||||
self.display_actions(DisplayActions.REFRESH)
|
self.display_actions(DisplayActions.REFRESH)
|
||||||
|
|
||||||
def handle_key_pressed_play(self, key: KeyValues) -> None:
|
def handle_key_pressed_play(self, key: KeyValues) -> None:
|
||||||
|
|
Loading…
Reference in New Issue