diff --git a/CHANGELOG.md b/CHANGELOG.md index 833ddb9b..c07929cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ### 1.7.4 (20638, 2022-07-07) - Fixed the trophies list showing an incorrect total (Thanks itsre3!) - ba.app.meta.metascan is now ba.app.meta.scanresults +- Cleaned up co-op ui code a bit +- Added a utility function to add custom co-op games in the practice section: `ba.app.add_coop_practice_level`. Also added new workspace template script which uses it to define a new co-op game type. ### 1.7.3 (20634, 2022-07-06) - Fixed an issue with King of the Hill flag regions not working when players entered them (Thanks itsre3!) diff --git a/assets/src/ba_data/python/ba/_app.py b/assets/src/ba_data/python/ba/_app.py index 97cfbdcc..1db3c47c 100644 --- a/assets/src/ba_data/python/ba/_app.py +++ b/assets/src/ba_data/python/ba/_app.py @@ -29,6 +29,7 @@ if TYPE_CHECKING: from ba._cloud import CloudSubsystem from bastd.actor import spazappearance from ba._accountv2 import AccountV2Subsystem + from ba._level import Level class App: @@ -274,6 +275,7 @@ class App: # Co-op Campaigns. self.campaigns: dict[str, ba.Campaign] = {} + self.custom_coop_practice_games: list[str] = [] # Server Mode. self.server: ba.ServerController | None = None @@ -527,6 +529,15 @@ class App: # FIXME: This should not be an actor attr. activity.paused_text = None + def add_coop_practice_level(self, level: Level) -> None: + """Adds an individual level to the 'practice' section in Co-op.""" + + # Assign this level to our catch-all campaign. + self.campaigns['Challenges'].addlevel(level) + + # Make note to add it to our challenges UI. + self.custom_coop_practice_games.append(f'Challenges:{level.name}') + def return_to_main_menu_session_gracefully(self, reset_ui: bool = True) -> None: """Attempt to cleanly get back to the main menu.""" diff --git a/assets/src/ba_data/python/ba/_campaign.py b/assets/src/ba_data/python/ba/_campaign.py index fff28fe2..9a55282a 100644 --- a/assets/src/ba_data/python/ba/_campaign.py +++ b/assets/src/ba_data/python/ba/_campaign.py @@ -49,12 +49,12 @@ class Campaign: """Whether this Campaign's levels must be played in sequence.""" return self._sequential - def addlevel(self, level: ba.Level) -> None: + def addlevel(self, level: ba.Level, index: int = -1) -> None: """Adds a ba.Level to the Campaign.""" if level.campaign is not None: raise RuntimeError('Level already belongs to a campaign.') level.set_campaign(self, len(self._levels)) - self._levels.append(level) + self._levels.insert(index, level) @property def levels(self) -> list[ba.Level]: diff --git a/assets/src/ba_data/python/bastd/ui/coop/browser.py b/assets/src/ba_data/python/bastd/ui/coop/browser.py index 90e35fe8..84d0ccfe 100644 --- a/assets/src/ba_data/python/bastd/ui/coop/browser.py +++ b/assets/src/ba_data/python/bastd/ui/coop/browser.py @@ -720,7 +720,7 @@ class CoopBrowserWindow(ba.Window): self.run_tournament))) v -= 200 - # Custom Games. + # Custom Games. (called 'Practice' in UI these days). v -= 50 ba.textwidget(parent=w_parent, position=(h_base + 27, v + 30 + 198), @@ -751,11 +751,9 @@ class CoopBrowserWindow(ba.Window): 'Challenges:Pro Easter Egg Hunt', ] + items - # add all custom user levels here.. - # items += [ - # 'User:' + l.getname() - # for l in getcampaign('User').getlevels() - # ] + # If we've defined custom games, put them at the beginning. + if ba.app.custom_coop_practice_games: + items = ba.app.custom_coop_practice_games + items self._custom_h_scroll = custom_h_scroll = h_scroll = ba.hscrollwidget( parent=w_parent,