Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small change #633

Merged
merged 38 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
de698f6
Edit plugins.py
vishal332008 Nov 13, 2023
f1a80d2
Update plugins.py
vishal332008 Nov 13, 2023
c750077
Update plugins.py
vishal332008 Nov 13, 2023
4f28bf0
Update manualtab.py
vishal332008 Nov 13, 2023
897896d
Merge branch 'efroemling:master' into master
vishal332008 Nov 15, 2023
716d014
Update party.py
vishal332008 Nov 15, 2023
abab497
Edit party.py
vishal332008 Nov 16, 2023
5f70cd8
Update party.py
vishal332008 Nov 16, 2023
34cd8ab
Update party.py
vishal332008 Nov 16, 2023
eae497b
Update party.py
vishal332008 Nov 16, 2023
08b1656
Edit manualtab.py
vishal332008 Nov 18, 2023
30ee6ea
Update manualtab.py
vishal332008 Nov 18, 2023
0349fa4
Update manualtab.py
vishal332008 Nov 18, 2023
baefe3d
Merge branch 'efroemling:master' into master
vishal332008 Nov 21, 2023
4a75399
Edit browser.py
vishal332008 Nov 21, 2023
1b595ad
Edit browser.py
vishal332008 Nov 21, 2023
3703b40
Edit edit.py
vishal332008 Nov 23, 2023
426798a
Update edit.py
vishal332008 Nov 23, 2023
c646868
Update browser.py
vishal332008 Nov 24, 2023
5452611
Update browser.py
vishal332008 Nov 24, 2023
7803caf
Update party.py
vishal332008 Nov 26, 2023
81006ed
Update manualtab.py
vishal332008 Nov 27, 2023
2b3bdee
Merge branch 'efroemling:master' into master
vishal332008 Nov 30, 2023
88e28ca
Update edit.py
vishal332008 Nov 30, 2023
c466da4
Update party.py
vishal332008 Nov 30, 2023
f2f13b3
Merge branch 'efroemling:master' into master
vishal332008 Nov 30, 2023
c632941
Update party.py
vishal332008 Nov 30, 2023
add619b
Merge branch 'efroemling:master' into master
vishal332008 Dec 15, 2023
6e06f04
Update manualtab.py
vishal332008 Dec 15, 2023
e8d2437
Update party.py
vishal332008 Dec 16, 2023
e237a37
Update party.py
vishal332008 Dec 16, 2023
50fa53e
Update party.py
vishal332008 Dec 16, 2023
d94e888
Update party.py
vishal332008 Dec 16, 2023
e018066
Update mainmenu.py
vishal332008 Dec 18, 2023
60db121
Update mainmenu.py
vishal332008 Dec 18, 2023
1a99f74
Merge branch 'efroemling:master' into master
vishal332008 Dec 19, 2023
5c2d524
Update watch.py
vishal332008 Dec 19, 2023
4a1ba28
Update browser.py
vishal332008 Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/assets/ba_data/python/bauiv1lib/gather/manualtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(self, window: GatherWindow) -> None:
self._party_edit_name_text: bui.Widget | None = None
self._party_edit_addr_text: bui.Widget | None = None
self._party_edit_port_text: bui.Widget | None = None
self._no_parties_added_text: bui.Widget | None = None

def on_activate(
self,
Expand Down Expand Up @@ -456,6 +457,24 @@ def _build_favorites_tab(self, region_height: float) -> None:
claims_left_right=True,
)

self._no_parties_added_text = bui.textwidget(
parent=self._container,
size=(0, 0),
h_align='center',
v_align='center',
text='',
color=(0.6, 0.6, 0.6),
scale=1.2,
position=(
(
(190 if uiscale is bui.UIScale.SMALL else 225)
+ sub_scroll_width * 0.5
),
v + sub_scroll_height * 0.5
),
glow_type='uniform',
)

self._favorite_selected = None
self._refresh_favorites()

Expand Down Expand Up @@ -698,6 +717,12 @@ def _refresh_favorites(self) -> None:

assert self._favorites_scroll_width is not None
assert self._favorites_connect_button is not None

bui.textwidget(
edit=self._no_parties_added_text,
text='',
)
num_of_fav = 0
for i, server in enumerate(servers):
txt = bui.textwidget(
parent=self._columnwidget,
Expand Down Expand Up @@ -726,6 +751,7 @@ def _refresh_favorites(self) -> None:
left_widget=self._favorites_connect_button,
right_widget=txt,
)
num_of_fav = num_of_fav + 1

# If there's no servers, allow selecting out of the scroll area
bui.containerwidget(
Expand All @@ -738,6 +764,11 @@ def _refresh_favorites(self) -> None:
up_widget=self._favorites_text,
left_widget=self._favorites_connect_button,
)
if num_of_fav == 0:
bui.textwidget(
edit=self._no_parties_added_text,
text=bui.Lstr(resource='noPartiesAddedText'),
)

def on_deactivate(self) -> None:
self._access_check_timer = None
Expand Down Expand Up @@ -803,8 +834,15 @@ def _save_server(
}
config.commit()
bui.getsound('gunCocking').play()
bui.screenmessage(
bui.Lstr(resource='addedToFavoritesText'),
color=(0, 1, 0),
)
else:
bui.screenmessage('Invalid Address', color=(1, 0, 0))
bui.screenmessage(
bui.Lstr(resource='internal.invalidAddressErrorText'),
color=(1, 0, 0),
)
bui.getsound('error').play()

def _host_lookup_result(
Expand Down
106 changes: 98 additions & 8 deletions src/assets/ba_data/python/bauiv1lib/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, origin: Sequence[float] = (0, 0)):
if uiscale is bui.UIScale.MEDIUM
else 600
)
self._display_old_msgs = True
super().__init__(
root_widget=bui.containerwidget(
size=(self._width, self._height),
Expand Down Expand Up @@ -142,12 +143,6 @@ def __init__(self, origin: Sequence[float] = (0, 0)):
)
self._chat_texts: list[bui.Widget] = []

# add all existing messages if chat is not muted
if not bui.app.config.resolve('Chat Muted'):
msgs = bs.get_chat_messages()
for msg in msgs:
self._add_msg(msg)

self._text_field = txt = bui.textwidget(
parent=self._root_widget,
editable=True,
Expand Down Expand Up @@ -242,11 +237,12 @@ def _on_menu_button_press(self) -> None:
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',
delegate=self,
Expand All @@ -269,6 +265,12 @@ def _update(self) -> None:
first.delete()
else:
bui.textwidget(edit=self._muted_text, color=(1, 1, 1, 0.0))
# add all existing messages if chat is not muted
if self._display_old_msgs:
msgs = bs.get_chat_messages()
for msg in msgs:
self._add_msg(msg)
self._display_old_msgs = False

# update roster section
roster = bs.get_game_roster()
Expand Down Expand Up @@ -466,10 +468,98 @@ def popup_menu_selected_choice(
cfg = bui.app.config
cfg['Chat Muted'] = choice == 'mute'
cfg.apply_and_commit()
self._display_old_msgs = True
self._update()
if choice == 'add_to_favorites':
plus = bui.app.plus
assert plus is not None

if plus.get_v1_account_state() == 'signed_in':
plus.add_v1_account_transaction(
{
'type': 'PUBLIC_PARTY_QUERY',
'proto': bs.protocol_version(),
'lang': bui.app.lang.language,
},
callback=bui.WeakCall(self._add_to_favorites),
)
plus.run_v1_account_transactions()
else:
self._add_to_favorites(None)

else:
print(f'unhandled popup type: {self._popup_type}')

def _add_to_favorites(self, result: dict[str, Any] | None) -> None:
if result is None:
return

parties_in = result['l']

assert isinstance(parties_in, list)
info = bs.get_connection_to_host_info()

if info.get('name', '') != '':
title = info['name']
else:
return

for party_in in parties_in:
server_name = party_in['n']
if server_name == title:
assert isinstance(party_in['a'], str)
assert isinstance(party_in['p'], int)
self._save_server(title, party_in['a'], party_in['p'])
return

def _save_server(
self,
name_text: 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
try:
port = port_num
except ValueError:
port = -1
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_text,
}
config.commit()
bui.getsound('gunCocking').play()
bui.screenmessage(
bui.Lstr(resource='addedToFavoritesText'),
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."""

Expand Down
58 changes: 50 additions & 8 deletions src/assets/ba_data/python/bauiv1lib/profile/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ def __init__(
bui.containerwidget(
edit=self._root_widget, selected_child=self._scrollwidget
)
self._columnwidget = bui.columnwidget(
parent=self._scrollwidget, border=2, margin=0
)
self._subcontainer = bui.containerwidget(
parent=self._scrollwidget,
size=(self._scroll_width, 32),
background=False,
)
v -= 255
self._profiles: dict[str, dict[str, Any]] | None = None
self._selected_profile = selected_profile
Expand Down Expand Up @@ -342,8 +344,10 @@ def _back(self) -> None:

def _refresh(self) -> None:
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
from efro.util import asserttype
from bascenev1 import PlayerProfilesChangedMessage
from bascenev1lib.actor import spazappearance

assert bui.app.classic is not None

Expand All @@ -359,14 +363,27 @@ def _refresh(self) -> None:
assert self._profiles is not None
items = list(self._profiles.items())
items.sort(key=lambda x: asserttype(x[0], str).lower())
spazzes = spazappearance.get_appearances()
spazzes.sort()
icon_textures = [
bui.gettexture(bui.app.classic.spaz_appearances[s].icon_texture)
for s in spazzes
]
icon_tint_textures = [
bui.gettexture(
bui.app.classic.spaz_appearances[s].icon_mask_texture
)
for s in spazzes
]
index = 0
y_val = 35 * (len(self._profiles) - 1)
account_name: str | None
if plus.get_v1_account_state() == 'signed_in':
account_name = plus.get_v1_account_display_string()
else:
account_name = None
widget_to_select = None
for p_name, _ in items:
for p_name, p_info in items:
if p_name == '__account__' and account_name is None:
continue
color, _highlight = bui.app.classic.get_player_profile_colors(
Expand All @@ -378,10 +395,29 @@ def _refresh(self) -> None:
if p_name == '__account__'
else bui.app.classic.get_player_profile_icon(p_name) + p_name
)

try:
char_index = spazzes.index(p_info['character'])
except Exception:
char_index = spazzes.index('Spaz')

assert isinstance(tval, str)
character = bui.buttonwidget(
parent=self._subcontainer,
position=(0, y_val),
size=(28, 28),
label='',
color=(1, 1, 1),
mask_texture=bui.gettexture('characterIconMask'),
tint_color=color,
tint2_color=_highlight,
texture=icon_textures[char_index],
tint_texture=icon_tint_textures[char_index],
selectable=False,
)
txtw = bui.textwidget(
parent=self._columnwidget,
position=(0, 32),
parent=self._subcontainer,
position=(35, y_val),
size=((self._width - 210) / scl, 28),
text=bui.Lstr(value=tval),
h_align='left',
Expand All @@ -398,6 +434,7 @@ def _refresh(self) -> None:
bui.widget(edit=txtw, up_widget=self._back_button)
bui.widget(edit=txtw, show_buffer_top=40, show_buffer_bottom=40)
self._profile_widgets.append(txtw)
self._profile_widgets.append(character)

# Select/show this one if it was previously selected
# (but defer till after this loop since our height is
Expand All @@ -406,10 +443,15 @@ def _refresh(self) -> None:
widget_to_select = txtw

index += 1
y_val -= 35

bui.containerwidget(
edit=self._subcontainer,
size=(self._scroll_width, index * 35),
)
if widget_to_select is not None:
bui.columnwidget(
edit=self._columnwidget,
bui.containerwidget(
edit=self._subcontainer,
selected_child=widget_to_select,
visible_child=widget_to_select,
)
Expand Down
30 changes: 28 additions & 2 deletions src/assets/ba_data/python/bauiv1lib/profile/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(
self._clipped_name_text = bui.textwidget(
parent=self._root_widget,
text='',
position=(540 + x_inset, v - 8),
position=(580 + x_inset, v - 8),
flatness=1.0,
shadow=0.0,
scale=0.55,
Expand Down Expand Up @@ -390,6 +390,23 @@ def __init__(
autoselect=True,
on_activate_call=self.upgrade_profile,
)
self._random_name_button = bui.buttonwidget(
parent=self._root_widget,
label='',
size=(20, 20),
position=(500 + x_inset, v - 20),
button_type='square',
color=(0.6, 0.5, 0.65),
autoselect=True,
on_activate_call=self.assign_random_name,
)
bui.imagewidget(
parent=self._root_widget,
size=(20, 20),
draw_controller=self._random_name_button,
position=(501 + x_inset, v - 20),
texture=bui.gettexture('replayIcon'),
)

self._update_clipped_name()
self._clipped_name_timer = bui.AppTimer(
Expand Down Expand Up @@ -498,8 +515,17 @@ def __init__(
)
self._update_character()

def assign_random_name(self) -> None:
"""Assigning a random name to the player."""
names = bs.get_random_names()
name = names[random.randrange(len(names))]
bui.textwidget(
edit=self._text_field,
text=name,
)

def upgrade_profile(self) -> None:
"""Attempt to ugrade the profile to global."""
"""Attempt to upgrade the profile to global."""
from bauiv1lib import account
from bauiv1lib.profile import upgrade as pupgrade

Expand Down
Loading