From e8d2437a9be0c1d37f1b9dfad7e71ea708612849 Mon Sep 17 00:00:00 2001 From: Vishal Date: Sat, 16 Dec 2023 22:37:52 +0530 Subject: [PATCH] Update party.py --- src/assets/ba_data/python/bauiv1lib/party.py | 60 +++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/assets/ba_data/python/bauiv1lib/party.py b/src/assets/ba_data/python/bauiv1lib/party.py index b4905e1b..9a85dd9e 100644 --- a/src/assets/ba_data/python/bauiv1lib/party.py +++ b/src/assets/ba_data/python/bauiv1lib/party.py @@ -238,10 +238,13 @@ class PartyWindow(bui.Window): if uiscale is bui.UIScale.MEDIUM else 1.23 ), - choices=['unmute' if is_muted else 'mute'], + choices=['unmute' if is_muted else 'mute', 'add_to_favorites'], choices_display=[ bui.Lstr( resource='chatUnMuteText' if is_muted else 'chatMuteText' + ), + bui.Lstr( + resource='AddToFavoritesText' ) ], current_choice='unmute' if is_muted else 'mute', @@ -470,9 +473,64 @@ class PartyWindow(bui.Window): cfg.apply_and_commit() self._display_old_msgs = True self._update() + if choice == 'add_to_favorites': + info = bs.get_connection_to_host_info_2() + if info is not None: + self._add_to_favorites( + name=info.name, + address=info.address, + port_num=info.port, + ) + else: + bui.screenmessage('Not connected to a server') else: print(f'unhandled popup type: {self._popup_type}') + def _add_to_favorites( + self, + name: str, + address: str, + port_num: int + ) -> None: + addr = address + if addr == '': + bui.screenmessage( + bui.Lstr(resource='internal.invalidAddressErrorText'), + color=(1, 0, 0), + ) + bui.getsound('error').play() + return + port = port_num + if port > 65535 or port < 0: + bui.screenmessage( + bui.Lstr(resource='internal.invalidPortErrorText'), + color=(1, 0, 0), + ) + bui.getsound('error').play() + return + config = bui.app.config + + if addr: + if not isinstance(config.get('Saved Servers'), dict): + config['Saved Servers'] = {} + config['Saved Servers'][f'{addr}@{port}'] = { + 'addr': addr, + 'port': port, + 'name': name, + } + config.commit() + bui.getsound('gunCocking').play() + bui.screenmessage( + bui.Lstr(value='Added To Favorites'), + color=(0, 1, 0), + ) + else: + bui.screenmessage( + bui.Lstr(resource='internal.invalidAddressErrorText'), + color=(1, 0, 0), + ) + bui.getsound('error').play() + def popup_menu_closing(self, popup_window: PopupWindow) -> None: """Called when the popup is closing."""