Bombsquad-Ballistica-Modded.../dist/ba_data/python/bauiv1lib/creditslist.py

366 lines
12 KiB
Python
Raw Normal View History

2021-03-29 03:24:13 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""Provides a window to display game credits."""
from __future__ import annotations
2023-08-13 17:21:49 +05:30
import os
import logging
2021-03-29 03:24:13 +05:30
from typing import TYPE_CHECKING
2023-08-13 17:21:49 +05:30
import bauiv1 as bui
2021-03-29 03:24:13 +05:30
if TYPE_CHECKING:
2022-06-30 00:31:52 +05:30
from typing import Sequence
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
class CreditsListWindow(bui.Window):
2021-03-29 03:24:13 +05:30
"""Window for displaying game credits."""
2023-08-13 17:21:49 +05:30
def __init__(self, origin_widget: bui.Widget | None = None):
2021-03-29 03:24:13 +05:30
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
import json
2023-08-13 17:21:49 +05:30
bui.set_analytics_screen('Credits Window')
2021-03-29 03:24:13 +05:30
# if they provided an origin-widget, scale up from that
2022-06-30 00:31:52 +05:30
scale_origin: tuple[float, float] | None
2021-03-29 03:24:13 +05:30
if origin_widget is not None:
self._transition_out = 'out_scale'
scale_origin = origin_widget.get_screen_space_center()
transition = 'in_scale'
else:
self._transition_out = 'out_right'
scale_origin = None
transition = 'in_right'
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
uiscale = bui.app.ui_v1.uiscale
width = 870 if uiscale is bui.UIScale.SMALL else 670
x_inset = 100 if uiscale is bui.UIScale.SMALL else 0
height = 398 if uiscale is bui.UIScale.SMALL else 500
2021-03-29 03:24:13 +05:30
self._r = 'creditsWindow'
super().__init__(
2023-08-13 17:21:49 +05:30
root_widget=bui.containerwidget(
size=(width, height),
transition=transition,
toolbar_visibility='menu_minimal',
scale_origin_stack_offset=scale_origin,
scale=(
2.0
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
else 1.3
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.MEDIUM
else 1.0
),
2023-08-13 17:21:49 +05:30
stack_offset=(0, -8)
if uiscale is bui.UIScale.SMALL
else (0, 0),
)
)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
if bui.app.ui_v1.use_toolbars and uiscale is bui.UIScale.SMALL:
bui.containerwidget(
edit=self._root_widget, on_cancel_call=self._back
)
2021-03-29 03:24:13 +05:30
else:
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(
40 + x_inset,
2023-08-13 17:21:49 +05:30
height - (68 if uiscale is bui.UIScale.SMALL else 62),
),
2021-03-29 03:24:13 +05:30
size=(140, 60),
scale=0.8,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='backText'),
2021-03-29 03:24:13 +05:30
button_type='back',
on_activate_call=self._back,
autoselect=True,
)
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, cancel_button=btn)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
bui.buttonwidget(
2021-03-29 03:24:13 +05:30
edit=btn,
button_type='backSmall',
position=(
40 + x_inset,
2023-08-13 17:21:49 +05:30
height - (68 if uiscale is bui.UIScale.SMALL else 62) + 5,
),
2021-03-29 03:24:13 +05:30
size=(60, 48),
2023-08-13 17:21:49 +05:30
label=bui.charstr(bui.SpecialChar.BACK),
)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=self._root_widget,
2023-08-13 17:21:49 +05:30
position=(0, height - (59 if uiscale is bui.UIScale.SMALL else 54)),
size=(width, 30),
2023-08-13 17:21:49 +05:30
text=bui.Lstr(
resource=self._r + '.titleText',
2023-08-13 17:21:49 +05:30
subs=[('${APP_NAME}', bui.Lstr(resource='titleText'))],
),
h_align='center',
2023-08-13 17:21:49 +05:30
color=bui.app.ui_v1.title_color,
maxwidth=330,
v_align='center',
)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
scroll = bui.scrollwidget(
parent=self._root_widget,
position=(40 + x_inset, 35),
size=(width - (80 + 2 * x_inset), height - 100),
capture_arrows=True,
)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
if bui.app.ui_v1.use_toolbars:
bui.widget(
2022-10-01 14:51:35 +05:30
edit=scroll,
2023-08-13 17:21:49 +05:30
right_widget=bui.get_special_widget('party_button'),
)
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL:
bui.widget(
2022-10-01 14:51:35 +05:30
edit=scroll,
2023-08-13 17:21:49 +05:30
left_widget=bui.get_special_widget('back_button'),
)
2021-03-29 03:24:13 +05:30
def _format_names(names2: Sequence[str], inset: float) -> str:
sval = ''
# measure a series since there's overlaps and stuff..
space_width = (
2023-08-13 17:21:49 +05:30
bui.get_string_width(' ' * 10, suppress_warning=True) / 10.0
)
2021-03-29 03:24:13 +05:30
spacing = 330.0
col1 = inset
col2 = col1 + spacing
col3 = col2 + spacing
line_width = 0.0
nline = ''
for name in names2:
# move to the next column (or row) and print
if line_width > col3:
sval += nline + '\n'
nline = ''
line_width = 0
if line_width > col2:
target = col3
elif line_width > col1:
target = col2
else:
target = col1
spacingstr = ' ' * int((target - line_width) / space_width)
nline += spacingstr
nline += name
2023-08-13 17:21:49 +05:30
line_width = bui.get_string_width(nline, suppress_warning=True)
2021-03-29 03:24:13 +05:30
if nline != '':
sval += nline + '\n'
return sval
2023-08-13 17:21:49 +05:30
sound_and_music = bui.Lstr(
resource=self._r + '.songCreditText'
).evaluate()
sound_and_music = sound_and_music.replace(
'${TITLE}', "'William Tell (Trumpet Entry)'"
)
2021-03-29 03:24:13 +05:30
sound_and_music = sound_and_music.replace(
'${PERFORMER}', 'The Apollo Symphony Orchestra'
)
2021-03-29 03:24:13 +05:30
sound_and_music = sound_and_music.replace(
'${PERFORMER}', 'The Apollo Symphony Orchestra'
)
2021-03-29 03:24:13 +05:30
sound_and_music = sound_and_music.replace(
'${COMPOSER}', 'Gioacchino Rossini'
)
2021-03-29 03:24:13 +05:30
sound_and_music = sound_and_music.replace('${ARRANGER}', 'Chris Worth')
sound_and_music = sound_and_music.replace('${PUBLISHER}', 'BMI')
sound_and_music = sound_and_music.replace(
'${SOURCE}', 'www.AudioSparx.com'
)
2021-03-29 03:24:13 +05:30
spc = ' '
sound_and_music = spc + sound_and_music.replace('\n', '\n' + spc)
names = [
'HubOfTheUniverseProd',
'Jovica',
'LG',
'Leady',
'Percy Duke',
'PhreaKsAccount',
'Pogotron',
'Rock Savage',
'anamorphosis',
'benboncan',
'cdrk',
'chipfork',
'guitarguy1985',
'jascha',
'joedeshon',
'loofa',
'm_O_m',
'mich3d',
'sandyrb',
'shakaharu',
'sirplus',
'stickman',
'thanvannispen',
'virotic',
'zimbot',
2021-03-29 03:24:13 +05:30
]
names.sort(key=lambda x: x.lower())
freesound_names = _format_names(names, 90)
try:
2023-08-13 17:21:49 +05:30
with open(
os.path.join(
bui.app.data_directory, 'ba_data', 'data', 'langdata.json'
),
encoding='utf-8',
) as infile:
translation_contributors = json.loads(infile.read())[
'translation_contributors'
]
2021-03-29 03:24:13 +05:30
except Exception:
2023-08-13 17:21:49 +05:30
logging.exception('Error reading translation contributors.')
2021-03-29 03:24:13 +05:30
translation_contributors = []
translation_names = _format_names(translation_contributors, 60)
# Need to bake this out and chop it up since we're passing our
# 65535 vertex limit for meshes..
# We can remove that limit once we drop support for GL ES2.. :-/
# (or add mesh splitting under the hood)
credits_text = (
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.codingGraphicsAudioText')
.evaluate()
.replace('${NAME}', 'Eric Froemling')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.additionalAudioArtIdeasText')
.evaluate()
.replace('${NAME}', 'Raphael Suter')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.soundAndMusicText').evaluate()
+ '\n'
2021-03-29 03:24:13 +05:30
'\n' + sound_and_music + '\n'
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.publicDomainMusicViaText')
.evaluate()
.replace('${NAME}', 'Musopen.com')
+ '\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.thanksEspeciallyToText')
.evaluate()
.replace('${NAME}', 'the US Army, Navy, and Marine Bands')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.additionalMusicFromText')
.evaluate()
.replace('${NAME}', 'The YouTube Audio Library')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.soundsText')
.evaluate()
.replace('${SOURCE}', 'Freesound.org')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n' + freesound_names + '\n'
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(
resource=self._r + '.languageTranslationsText'
).evaluate()
+ '\n'
'\n'
+ '\n'.join(translation_names.splitlines()[:146])
+ '\n'.join(translation_names.splitlines()[146:])
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
2022-07-16 17:59:14 +05:30
' Shout Out to Awesome Mods / Modders / Contributors:\n\n'
2021-03-29 03:24:13 +05:30
' BombDash ModPack\n'
' TheMikirog & SoK - BombSquad Joyride Modpack\n'
' Mrmaxmeier - BombSquad-Community-Mod-Manager\n'
2022-07-16 17:59:14 +05:30
' Ritiek Malhotra \n'
' Dliwk\n'
' vishal332008\n'
' itsre3\n'
' Drooopyyy\n'
2021-03-29 03:24:13 +05:30
'\n'
' Holiday theme vector art designed by Freepik\n'
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.specialThanksText').evaluate()
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' Todd, Laura, and Robert Froemling\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.allMyFamilyText')
.evaluate()
.replace('\n', '\n ')
+ '\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(
resource=self._r + '.whoeverInventedCoffeeText'
).evaluate()
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
2023-08-13 17:21:49 +05:30
' ' + bui.Lstr(resource=self._r + '.legalText').evaluate() + '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
2023-08-13 17:21:49 +05:30
+ bui.Lstr(resource=self._r + '.softwareBasedOnText')
.evaluate()
.replace('${NAME}', 'the Khronos Group')
+ '\n'
2021-03-29 03:24:13 +05:30
'\n'
' '
' www.ballistica.net\n'
)
2021-03-29 03:24:13 +05:30
txt = credits_text
lines = txt.splitlines()
line_height = 20
scale = 0.55
self._sub_width = width - 80
self._sub_height = line_height * len(lines) + 40
2023-08-13 17:21:49 +05:30
container = self._subcontainer = bui.containerwidget(
2021-03-29 03:24:13 +05:30
parent=scroll,
size=(self._sub_width, self._sub_height),
background=False,
claims_left_right=False,
claims_tab=False,
)
2021-03-29 03:24:13 +05:30
voffs = 0
for line in lines:
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=container,
padding=4,
color=(0.7, 0.9, 0.7, 1.0),
scale=scale,
flatness=1.0,
size=(0, 0),
position=(0, self._sub_height - 20 + voffs),
h_align='left',
v_align='top',
2023-08-13 17:21:49 +05:30
text=bui.Lstr(value=line),
)
2021-03-29 03:24:13 +05:30
voffs -= line_height
def _back(self) -> None:
2023-08-13 17:21:49 +05:30
from bauiv1lib.mainmenu import MainMenuWindow
2023-08-13 17:21:49 +05:30
bui.containerwidget(
edit=self._root_widget, transition=self._transition_out
)
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
MainMenuWindow(transition='in_left').get_root_widget()
)