-
Notifications
You must be signed in to change notification settings - Fork 32
/
ultra_party_window.py
2755 lines (2552 loc) · 120 KB
/
ultra_party_window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__author__ = 'Droopy'
__version__ = 4.0
# ba_meta require api 7
import datetime
import json
import math
import os
import pickle
import random
import time
import urllib.request
import weakref
from threading import Thread
from typing import List, Tuple, Sequence, Optional, Dict, Any, cast
from hashlib import md5
import _ba
import ba
import bastd.ui.party
from bastd.ui.colorpicker import ColorPickerExact
from bastd.ui.confirm import ConfirmWindow
from bastd.ui.mainmenu import MainMenuWindow
from bastd.ui.popup import PopupMenuWindow, PopupWindow, PopupMenu
_ip = '127.0.0.1'
_port = 43210
_ping = '-'
url = 'http://bombsquadprivatechat.ml'
last_msg = None
my_directory = _ba.env()['python_directory_user'] + '/UltraPartyWindowFiles/'
quick_msg_file = my_directory + 'QuickMessages.txt'
cookies_file = my_directory + 'cookies.txt'
saved_ids_file = my_directory + 'saved_ids.json'
my_location = my_directory
def initialize():
config_defaults = {'Party Chat Muted': False,
'Chat Muted': False,
'ping button': True,
'IP button': True,
'copy button': True,
'Direct Send': False,
'Colorful Chat': True,
'Custom Commands': [],
'Message Notification': 'bottom',
'Self Status': 'online',
'Translate Source Language': '',
'Translate Destination Language': 'en',
'Pronunciation': True
}
config = ba.app.config
for key in config_defaults:
if key not in config:
config[key] = config_defaults[key]
if not os.path.exists(my_directory):
os.makedirs(my_directory)
if not os.path.exists(cookies_file):
with open(cookies_file, 'wb') as f:
pickle.dump({}, f)
if not os.path.exists(saved_ids_file):
with open(saved_ids_file, 'w') as f:
data = {}
json.dump(data, f)
def display_error(msg=None):
if msg:
ba.screenmessage(msg, (1, 0, 0))
else:
ba.screenmessage('Failed!', (1, 0, 0))
ba.playsound(ba.getsound('error'))
def display_success(msg=None):
if msg:
ba.screenmessage(msg, (0, 1, 0))
else:
ba.screenmessage('Successful!', (0, 1, 0))
class Translate(Thread):
def __init__(self, data, callback):
super().__init__()
self.data = data
self._callback = callback
def run(self):
_ba.pushcall(ba.Call(ba.screenmessage, 'Translating...'), from_other_thread=True)
response = messenger._send_request(f'{url}/translate', self.data)
if response:
_ba.pushcall(ba.Call(self._callback, response), from_other_thread=True)
class ColorTracker:
def __init__(self):
self.saved = {}
def _get_safe_color(self, sender):
while True:
color = (random.random(), random.random(), random.random())
s = 0
background = ba.app.config.get('PartyWindow Main Color', (0.5, 0.5, 0.5))
for i, j in zip(color, background):
s += (i - j) ** 2
if s > 0.1:
self.saved[sender] = color
if len(self.saved) > 20:
self.saved.pop(list(self.saved.keys())[0])
break
time.sleep(0.1)
def _get_sender_color(self, sender):
if sender not in self.saved:
self.thread = Thread(target=self._get_safe_color, args=(sender,))
self.thread.start()
return (1, 1, 1)
else:
return self.saved[sender]
class PrivateChatHandler:
def __init__(self):
self.pvt_msgs = {}
self.login_id = None
self.last_msg_id = None
self.logged_in = False
self.cookieProcessor = urllib.request.HTTPCookieProcessor()
self.opener = urllib.request.build_opener(self.cookieProcessor)
self.filter = 'all'
self.pending_messages = []
self.friends_status = {}
self.error = ''
Thread(target=self._ping).start()
def _load_ids(self):
with open(saved_ids_file, 'r') as f:
saved = json.load(f)
if self.myid in saved:
self.saved_ids = saved[self.myid]
else:
self.saved_ids = {'all': '<all>'}
def _dump_ids(self):
with open(saved_ids_file, 'r') as f:
saved = json.load(f)
with open(saved_ids_file, 'w') as f:
saved[self.myid] = self.saved_ids
json.dump(saved, f)
def _ping(self):
self.server_online = False
response = self._send_request(url=f'{url}')
if not response:
self.error = 'Server offline'
elif response:
try:
self.server_online = True
version = float(response.replace('v', ''))
except:
self.error = 'Server offline'
def _signup(self, registration_key):
data = dict(pb_id=self.myid, registration_key=registration_key)
response = self._send_request(url=f'{url}/signup', data=data)
if response:
if response == 'successful':
display_success('Account Created Successfully')
self._login(registration_key=registration_key)
return True
display_error(response)
def _save_cookie(self):
with open(cookies_file, 'rb') as f:
cookies = pickle.load(f)
with open(cookies_file, 'wb') as f:
for c in self.cookieProcessor.cookiejar:
cookie = pickle.dumps(c)
break
cookies[self.myid] = cookie
pickle.dump(cookies, f)
def _cookie_login(self):
self.myid = ba.internal.get_v1_account_misc_read_val_2('resolvedAccountID', '')
try:
with open(cookies_file, 'rb') as f:
cookies = pickle.load(f)
except:
return False
if self.myid in cookies:
cookie = pickle.loads(cookies[self.myid])
self.cookieProcessor.cookiejar.set_cookie(cookie)
self.opener = urllib.request.build_opener(self.cookieProcessor)
response = self._send_request(url=f'{url}/login')
if response.startswith('logged in as'):
self.logged_in = True
self._load_ids()
display_success(response)
return True
def _login(self, registration_key):
self.myid = ba.internal.get_v1_account_misc_read_val_2('resolvedAccountID', '')
data = dict(pb_id=self.myid, registration_key=registration_key)
response = self._send_request(url=f'{url}/login', data=data)
if response == 'successful':
self.logged_in = True
self._load_ids()
self._save_cookie()
display_success('Account Logged in Successfully')
return True
else:
display_error(response)
def _query(self, pb_id=None):
if not pb_id:
pb_id = self.myid
response = self._send_request(url=f'{url}/query/{pb_id}')
if response == 'exists':
return True
return False
def _send_request(self, url, data=None):
try:
if not data:
response = self.opener.open(url)
else:
response = self.opener.open(url, data=json.dumps(data).encode())
if response.getcode() != 200:
display_error(response.read().decode())
return None
else:
return response.read().decode()
except:
return None
def _save_id(self, account_id, nickname='<default>', verify=True):
# display_success(f'Saving {account_id}. Please wait...')
if verify:
url = 'http://bombsquadgame.com/accountquery?id=' + account_id
response = json.loads(urllib.request.urlopen(url).read().decode())
if 'error' in response:
display_error('Enter valid account id')
return False
self.saved_ids[account_id] = {}
name = None
if nickname == '<default>':
name_html = response['name_html']
name = name_html.split('>')[1]
nick = name if name else nickname
else:
nick = nickname
self.saved_ids[account_id] = nick
self._dump_ids()
display_success(f'Account added: {nick}({account_id})')
return True
def _remove_id(self, account_id):
removed = self.saved_ids.pop(account_id)
self._dump_ids()
ba.screenmessage(f'Removed successfully: {removed}({account_id})', (0, 1, 0))
ba.playsound(ba.getsound('shieldDown'))
def _format_message(self, msg):
filter = msg['filter']
if filter in self.saved_ids:
if self.filter == 'all':
message = '[' + self.saved_ids[filter] + ']' + msg['message']
else:
message = msg['message']
else:
message = '[' + msg['filter'] + ']: ' + \
'Message from unsaved id. Save id to view message.'
return message
def _get_status(self, id, type='status'):
info = self.friends_status.get(id, {})
if not info:
return '-'
if type == 'status':
return info['status']
else:
last_seen = info["last_seen"]
last_seen = _get_local_time(last_seen)
ba.screenmessage(f'Last seen on: {last_seen}')
def _get_local_time(utctime):
d = datetime.datetime.strptime(utctime, '%d-%m-%Y %H:%M:%S')
d = d.replace(tzinfo=datetime.timezone.utc)
d = d.astimezone()
return d.strftime('%B %d,\t\t%H:%M:%S')
def update_status():
if messenger.logged_in:
if ba.app.config['Self Status'] == 'online':
host = _ba.get_connection_to_host_info().get('name', '')
if host:
my_status = f'Playing in {host}'
else:
my_status = 'in Lobby'
ids_to_check = [i for i in messenger.saved_ids if i != 'all']
response = messenger._send_request(url=f'{url}/updatestatus',
data=dict(self_status=my_status, ids=ids_to_check))
if response:
messenger.friends_status = json.loads(response)
else:
messenger.friends_status = {}
def messenger_thread():
counter = 0
while True:
counter += 1
time.sleep(0.6)
check_new_message()
if counter > 5:
counter = 0
update_status()
def check_new_message():
if messenger.logged_in:
if messenger.login_id != messenger.myid:
response = messenger._send_request(f'{url}/first')
if response:
messenger.pvt_msgs = json.loads(response)
if messenger.pvt_msgs['all']:
messenger.last_msg_id = messenger.pvt_msgs['all'][-1]['id']
messenger.login_id = messenger.myid
else:
response = messenger._send_request(f'{url}/new/{messenger.last_msg_id}')
if response:
new_msgs = json.loads(response)
if new_msgs:
for msg in new_msgs['messages']:
if msg['id'] > messenger.last_msg_id:
messenger.last_msg_id = msg['id']
messenger.pvt_msgs['all'].append(
dict(id=msg['id'], filter=msg['filter'], message=msg['message'], sent=msg['sent']))
if len(messenger.pvt_msgs['all']) > 40:
messenger.pvt_msgs['all'].pop(0)
if msg['filter'] not in messenger.pvt_msgs:
messenger.pvt_msgs[msg['filter']] = [
dict(id=msg['id'], filter=msg['filter'], message=msg['message'], sent=msg['sent'])]
else:
messenger.pvt_msgs[msg['filter']].append(
dict(id=msg['id'], filter=msg['filter'], message=msg['message'], sent=msg['sent']))
if len(messenger.pvt_msgs[msg['filter']]) > 20:
messenger.pvt_msgs[msg['filter']].pop(0)
messenger.pending_messages.append(
(messenger._format_message(msg), msg['filter'], msg['sent']))
def display_message(msg, msg_type, filter=None, sent=None):
flag = None
notification = ba.app.config['Message Notification']
if _ba.app.ui.party_window:
if _ba.app.ui.party_window():
if _ba.app.ui.party_window()._private_chat:
flag = 1
if msg_type == 'private':
if messenger.filter == filter or messenger.filter == 'all':
_ba.app.ui.party_window().on_chat_message(msg, sent)
else:
if notification == 'top':
ba.screenmessage(msg, (1, 1, 0), True, ba.gettexture('coin'))
else:
ba.screenmessage(msg, (1, 1, 0), False)
else:
ba.screenmessage(msg, (0.2, 1.0, 1.0), True, ba.gettexture('circleShadow'))
else:
flag = 1
if msg_type == 'private':
if notification == 'top':
ba.screenmessage(msg, (1, 1, 0), True, ba.gettexture('coin'))
else:
ba.screenmessage(msg, (1, 1, 0), False)
if not flag:
if msg_type == 'private':
if notification == 'top':
ba.screenmessage(msg, (1, 1, 0), True, ba.gettexture('coin'))
else:
ba.screenmessage(msg, (1, 1, 0), False)
else:
ba.screenmessage(msg, (0.2, 1.0, 1.0), True, ba.gettexture('circleShadow'))
def msg_displayer():
for msg in messenger.pending_messages:
display_message(msg[0], 'private', msg[1], msg[2])
messenger.pending_messages.remove(msg)
if ba.app.config['Chat Muted'] and not ba.app.config['Party Chat Muted']:
global last_msg
last = _ba.get_chat_messages()
lm = last[-1] if last else None
if lm != last_msg:
last_msg = lm
display_message(lm, 'public')
class SortQuickMessages:
def __init__(self):
uiscale = ba.app.ui.uiscale
bg_color = ba.app.config.get('PartyWindow Main Color', (0.5, 0.5, 0.5))
self._width = 750 if uiscale is ba.UIScale.SMALL else 600
self._height = (300 if uiscale is ba.UIScale.SMALL else
325 if uiscale is ba.UIScale.MEDIUM else 350)
self._root_widget = ba.containerwidget(
size=(self._width, self._height),
transition='in_right',
on_outside_click_call=self._save,
color=bg_color,
parent=_ba.get_special_widget('overlay_stack'),
scale=(2.0 if uiscale is ba.UIScale.SMALL else
1.3 if uiscale is ba.UIScale.MEDIUM else 1.0),
stack_offset=(0, -16) if uiscale is ba.UIScale.SMALL else (0, 0))
ba.textwidget(parent=self._root_widget,
position=(-10, self._height - 50),
size=(self._width, 25),
text='Sort Quick Messages',
color=ba.app.ui.title_color,
scale=1.05,
h_align='center',
v_align='center',
maxwidth=270)
b_textcolor = (0.4, 0.75, 0.5)
up_button = ba.buttonwidget(parent=self._root_widget,
position=(10, 170),
size=(75, 75),
on_activate_call=self._move_up,
label=ba.charstr(ba.SpecialChar.UP_ARROW),
button_type='square',
color=bg_color,
textcolor=b_textcolor,
autoselect=True,
repeat=True)
down_button = ba.buttonwidget(parent=self._root_widget,
position=(10, 75),
size=(75, 75),
on_activate_call=self._move_down,
label=ba.charstr(ba.SpecialChar.DOWN_ARROW),
button_type='square',
color=bg_color,
textcolor=b_textcolor,
autoselect=True,
repeat=True)
self._scroll_width = self._width - 150
self._scroll_height = self._height - 110
self._scrollwidget = ba.scrollwidget(
parent=self._root_widget,
size=(self._scroll_width, self._scroll_height),
color=bg_color,
position=(100, 40))
self._columnwidget = ba.columnwidget(
parent=self._scrollwidget,
border=2,
margin=0)
with open(quick_msg_file, 'r') as f:
self.msgs = f.read().split('\n')
self._msg_selected = None
self._refresh()
ba.containerwidget(edit=self._root_widget,
on_cancel_call=self._save)
def _refresh(self):
for child in self._columnwidget.get_children():
child.delete()
for msg in enumerate(self.msgs):
txt = ba.textwidget(
parent=self._columnwidget,
size=(self._scroll_width - 10, 30),
selectable=True,
always_highlight=True,
on_select_call=ba.Call(self._on_msg_select, msg),
text=msg[1],
h_align='left',
v_align='center',
maxwidth=self._scroll_width)
if msg == self._msg_selected:
ba.columnwidget(edit=self._columnwidget,
selected_child=txt,
visible_child=txt)
def _on_msg_select(self, msg):
self._msg_selected = msg
def _move_up(self):
index = self._msg_selected[0]
msg = self._msg_selected[1]
if index:
self.msgs.insert((index - 1), self.msgs.pop(index))
self._msg_selected = (index - 1, msg)
self._refresh()
def _move_down(self):
index = self._msg_selected[0]
msg = self._msg_selected[1]
if index + 1 < len(self.msgs):
self.msgs.insert((index + 1), self.msgs.pop(index))
self._msg_selected = (index + 1, msg)
self._refresh()
def _save(self) -> None:
try:
with open(quick_msg_file, 'w') as f:
f.write('\n'.join(self.msgs))
except:
ba.print_exception()
ba.screenmessage('Error!', (1, 0, 0))
ba.containerwidget(
edit=self._root_widget,
transition='out_right')
class TranslationSettings:
def __init__(self):
uiscale = ba.app.ui.uiscale
height = (300 if uiscale is ba.UIScale.SMALL else
350 if uiscale is ba.UIScale.MEDIUM else 400)
width = (500 if uiscale is ba.UIScale.SMALL else
600 if uiscale is ba.UIScale.MEDIUM else 650)
self._transition_out: Optional[str]
scale_origin: Optional[Tuple[float, float]]
self._transition_out = 'out_scale'
scale_origin = 10
transition = 'in_scale'
scale_origin = None
cancel_is_selected = False
cfg = ba.app.config
bg_color = cfg.get('PartyWindow Main Color', (0.5, 0.5, 0.5))
LANGUAGES = {
'': 'Auto-Detect',
'af': 'afrikaans',
'sq': 'albanian',
'am': 'amharic',
'ar': 'arabic',
'hy': 'armenian',
'az': 'azerbaijani',
'eu': 'basque',
'be': 'belarusian',
'bn': 'bengali',
'bs': 'bosnian',
'bg': 'bulgarian',
'ca': 'catalan',
'ceb': 'cebuano',
'ny': 'chichewa',
'zh-cn': 'chinese (simplified)',
'zh-tw': 'chinese (traditional)',
'co': 'corsican',
'hr': 'croatian',
'cs': 'czech',
'da': 'danish',
'nl': 'dutch',
'en': 'english',
'eo': 'esperanto',
'et': 'estonian',
'tl': 'filipino',
'fi': 'finnish',
'fr': 'french',
'fy': 'frisian',
'gl': 'galician',
'ka': 'georgian',
'de': 'german',
'el': 'greek',
'gu': 'gujarati',
'ht': 'haitian creole',
'ha': 'hausa',
'haw': 'hawaiian',
'iw': 'hebrew',
'he': 'hebrew',
'hi': 'hindi',
'hmn': 'hmong',
'hu': 'hungarian',
'is': 'icelandic',
'ig': 'igbo',
'id': 'indonesian',
'ga': 'irish',
'it': 'italian',
'ja': 'japanese',
'jw': 'javanese',
'kn': 'kannada',
'kk': 'kazakh',
'km': 'khmer',
'ko': 'korean',
'ku': 'kurdish (kurmanji)',
'ky': 'kyrgyz',
'lo': 'lao',
'la': 'latin',
'lv': 'latvian',
'lt': 'lithuanian',
'lb': 'luxembourgish',
'mk': 'macedonian',
'mg': 'malagasy',
'ms': 'malay',
'ml': 'malayalam',
'mt': 'maltese',
'mi': 'maori',
'mr': 'marathi',
'mn': 'mongolian',
'my': 'myanmar (burmese)',
'ne': 'nepali',
'no': 'norwegian',
'or': 'odia',
'ps': 'pashto',
'fa': 'persian',
'pl': 'polish',
'pt': 'portuguese',
'pa': 'punjabi',
'ro': 'romanian',
'ru': 'russian',
'sm': 'samoan',
'gd': 'scots gaelic',
'sr': 'serbian',
'st': 'sesotho',
'sn': 'shona',
'sd': 'sindhi',
'si': 'sinhala',
'sk': 'slovak',
'sl': 'slovenian',
'so': 'somali',
'es': 'spanish',
'su': 'sundanese',
'sw': 'swahili',
'sv': 'swedish',
'tg': 'tajik',
'ta': 'tamil',
'te': 'telugu',
'th': 'thai',
'tr': 'turkish',
'uk': 'ukrainian',
'ur': 'urdu',
'ug': 'uyghur',
'uz': 'uzbek',
'vi': 'vietnamese',
'cy': 'welsh',
'xh': 'xhosa',
'yi': 'yiddish',
'yo': 'yoruba',
'zu': 'zulu'}
self.root_widget = ba.containerwidget(
size=(width, height),
color=bg_color,
transition=transition,
toolbar_visibility='menu_minimal_no_back',
parent=_ba.get_special_widget('overlay_stack'),
on_outside_click_call=self._cancel,
scale=(2.1 if uiscale is ba.UIScale.SMALL else
1.5 if uiscale is ba.UIScale.MEDIUM else 1.0),
scale_origin_stack_offset=scale_origin)
ba.textwidget(parent=self.root_widget,
position=(width * 0.5, height - 45),
size=(20, 20),
h_align='center',
v_align='center',
text="Text Translation",
scale=0.9,
color=(5, 5, 5))
cbtn = btn = ba.buttonwidget(parent=self.root_widget,
autoselect=True,
position=(30, height - 60),
size=(30, 30),
label=ba.charstr(ba.SpecialChar.BACK),
button_type='backSmall',
on_activate_call=self._cancel)
source_lang_text = ba.textwidget(parent=self.root_widget,
position=(40, height - 110),
size=(20, 20),
h_align='left',
v_align='center',
text="Source Language : ",
scale=0.9,
color=(1, 1, 1))
source_lang_menu = PopupMenu(
parent=self.root_widget,
position=(330 if uiscale is ba.UIScale.SMALL else 400, height - 115),
width=200,
scale=(2.8 if uiscale is ba.UIScale.SMALL else
1.8 if uiscale is ba.UIScale.MEDIUM else 1.2),
current_choice=cfg['Translate Source Language'],
choices=LANGUAGES.keys(),
choices_display=(ba.Lstr(value=i) for i in LANGUAGES.values()),
button_size=(130, 35),
on_value_change_call=self._change_source)
destination_lang_text = ba.textwidget(parent=self.root_widget,
position=(40, height - 165),
size=(20, 20),
h_align='left',
v_align='center',
text="Destination Language : ",
scale=0.9,
color=(1, 1, 1))
destination_lang_menu = PopupMenu(
parent=self.root_widget,
position=(330 if uiscale is ba.UIScale.SMALL else 400, height - 170),
width=200,
scale=(2.8 if uiscale is ba.UIScale.SMALL else
1.8 if uiscale is ba.UIScale.MEDIUM else 1.2),
current_choice=cfg['Translate Destination Language'],
choices=list(LANGUAGES.keys())[1:],
choices_display=list(ba.Lstr(value=i) for i in LANGUAGES.values())[1:],
button_size=(130, 35),
on_value_change_call=self._change_destination)
try:
translation_mode_text = ba.textwidget(parent=self.root_widget,
position=(40, height - 215),
size=(20, 20),
h_align='left',
v_align='center',
text="Translate Mode",
scale=0.9,
color=(1, 1, 1))
decoration = ba.textwidget(parent=self.root_widget,
position=(40, height - 225),
size=(20, 20),
h_align='left',
v_align='center',
text="________________",
scale=0.9,
color=(1, 1, 1))
language_char_text = ba.textwidget(parent=self.root_widget,
position=(85, height - 273),
size=(20, 20),
h_align='left',
v_align='center',
text='Normal Translation',
scale=0.6,
color=(1, 1, 1))
pronunciation_text = ba.textwidget(parent=self.root_widget,
position=(295, height - 273),
size=(20, 20),
h_align='left',
v_align='center',
text="Show Prononciation",
scale=0.6,
color=(1, 1, 1))
from bastd.ui.radiogroup import make_radio_group
cur_val = ba.app.config.get('Pronunciation', True)
cb1 = ba.checkboxwidget(
parent=self.root_widget,
position=(250, height - 275),
size=(20, 20),
maxwidth=300,
scale=1,
autoselect=True,
text="")
cb2 = ba.checkboxwidget(
parent=self.root_widget,
position=(40, height - 275),
size=(20, 20),
maxwidth=300,
scale=1,
autoselect=True,
text="")
make_radio_group((cb1, cb2), (True, False), cur_val,
self._actions_changed)
except Exception as e:
print(e)
pass
ba.containerwidget(edit=self.root_widget, cancel_button=btn)
def _change_source(self, choice):
cfg = ba.app.config
cfg['Translate Source Language'] = choice
cfg.apply_and_commit()
def _change_destination(self, choice):
cfg = ba.app.config
cfg['Translate Destination Language'] = choice
cfg.apply_and_commit()
def _actions_changed(self, v: str) -> None:
cfg = ba.app.config
cfg['Pronunciation'] = v
cfg.apply_and_commit()
def _cancel(self) -> None:
ba.containerwidget(edit=self.root_widget, transition='out_scale')
SettingsWindow()
class SettingsWindow:
def __init__(self):
uiscale = ba.app.ui.uiscale
height = (300 if uiscale is ba.UIScale.SMALL else
350 if uiscale is ba.UIScale.MEDIUM else 400)
width = (500 if uiscale is ba.UIScale.SMALL else
600 if uiscale is ba.UIScale.MEDIUM else 650)
scroll_h = (200 if uiscale is ba.UIScale.SMALL else
250 if uiscale is ba.UIScale.MEDIUM else 270)
scroll_w = (450 if uiscale is ba.UIScale.SMALL else
550 if uiscale is ba.UIScale.MEDIUM else 600)
self._transition_out: Optional[str]
scale_origin: Optional[Tuple[float, float]]
self._transition_out = 'out_scale'
scale_origin = 10
transition = 'in_scale'
scale_origin = None
cancel_is_selected = False
cfg = ba.app.config
bg_color = cfg.get('PartyWindow Main Color', (0.5, 0.5, 0.5))
self.root_widget = ba.containerwidget(
size=(width, height),
color=bg_color,
transition=transition,
toolbar_visibility='menu_minimal_no_back',
parent=_ba.get_special_widget('overlay_stack'),
on_outside_click_call=self._cancel,
scale=(2.1 if uiscale is ba.UIScale.SMALL else
1.5 if uiscale is ba.UIScale.MEDIUM else 1.0),
scale_origin_stack_offset=scale_origin)
ba.textwidget(parent=self.root_widget,
position=(width * 0.5, height - 45),
size=(20, 20),
h_align='center',
v_align='center',
text="Custom Settings",
scale=0.9,
color=(5, 5, 5))
cbtn = btn = ba.buttonwidget(parent=self.root_widget,
autoselect=True,
position=(30, height - 60),
size=(30, 30),
label=ba.charstr(ba.SpecialChar.BACK),
button_type='backSmall',
on_activate_call=self._cancel)
scroll_position = (30 if uiscale is ba.UIScale.SMALL else
40 if uiscale is ba.UIScale.MEDIUM else 50)
self._scrollwidget = ba.scrollwidget(parent=self.root_widget,
position=(30, scroll_position),
simple_culling_v=20.0,
highlight=False,
size=(scroll_w, scroll_h),
selection_loops_to_parent=True)
ba.widget(edit=self._scrollwidget, right_widget=self._scrollwidget)
self._subcontainer = ba.columnwidget(parent=self._scrollwidget,
selection_loops_to_parent=True)
ip_button = ba.checkboxwidget(
parent=self._subcontainer,
size=(300, 30),
maxwidth=300,
textcolor=((0, 1, 0) if cfg['IP button'] else (0.95, 0.65, 0)),
scale=1,
value=cfg['IP button'],
autoselect=True,
text="IP Button",
on_value_change_call=self.ip_button)
ping_button = ba.checkboxwidget(
parent=self._subcontainer,
size=(300, 30),
maxwidth=300,
textcolor=((0, 1, 0) if cfg['ping button'] else (0.95, 0.65, 0)),
scale=1,
value=cfg['ping button'],
autoselect=True,
text="Ping Button",
on_value_change_call=self.ping_button)
copy_button = ba.checkboxwidget(
parent=self._subcontainer,
size=(300, 30),
maxwidth=300,
textcolor=((0, 1, 0) if cfg['copy button'] else (0.95, 0.65, 0)),
scale=1,
value=cfg['copy button'],
autoselect=True,
text="Copy Text Button",
on_value_change_call=self.copy_button)
direct_send = ba.checkboxwidget(
parent=self._subcontainer,
size=(300, 30),
maxwidth=300,
textcolor=((0, 1, 0) if cfg['Direct Send'] else (0.95, 0.65, 0)),
scale=1,
value=cfg['Direct Send'],
autoselect=True,
text="Directly Send Custom Commands",
on_value_change_call=self.direct_send)
colorfulchat = ba.checkboxwidget(
parent=self._subcontainer,
size=(300, 30),
maxwidth=300,
textcolor=((0, 1, 0) if cfg['Colorful Chat'] else (0.95, 0.65, 0)),
scale=1,
value=cfg['Colorful Chat'],
autoselect=True,
text="Colorful Chat",
on_value_change_call=self.colorful_chat)
msg_notification_text = ba.textwidget(parent=self._subcontainer,
scale=0.8,
color=(1, 1, 1),
text='Message Notifcation:',
size=(100, 30),
h_align='left',
v_align='center')
msg_notification_widget = PopupMenu(
parent=self._subcontainer,
position=(100, height - 1200),
width=200,
scale=(2.8 if uiscale is ba.UIScale.SMALL else
1.8 if uiscale is ba.UIScale.MEDIUM else 1.2),
choices=['top', 'bottom'],
current_choice=ba.app.config['Message Notification'],
button_size=(80, 25),
on_value_change_call=self._change_notification)
self_status_text = ba.textwidget(parent=self._subcontainer,
scale=0.8,
color=(1, 1, 1),
text='Self Status:',
size=(100, 30),
h_align='left',
v_align='center')
self_status_widget = PopupMenu(
parent=self._subcontainer,
position=(50, height - 1000),
width=200,
scale=(2.8 if uiscale is ba.UIScale.SMALL else
1.8 if uiscale is ba.UIScale.MEDIUM else 1.2),
choices=['online', 'offline'],
current_choice=ba.app.config['Self Status'],
button_size=(80, 25),
on_value_change_call=self._change_status)
ba.containerwidget(edit=self.root_widget, cancel_button=btn)
ba.containerwidget(edit=self.root_widget,
selected_child=(cbtn if cbtn is not None
and cancel_is_selected else None),
start_button=None)
self._translation_btn = ba.buttonwidget(parent=self._subcontainer,
scale=1.2,
position=(100, 1200),
size=(150, 50),
label='Translate Settings',
on_activate_call=self._translaton_btn,
autoselect=True)
def ip_button(self, value: bool):
cfg = ba.app.config
cfg['IP button'] = value
cfg.apply_and_commit()
if cfg['IP button']:
ba.screenmessage("IP Button is now enabled", color=(0, 1, 0))
else:
ba.screenmessage("IP Button is now disabled", color=(1, 0.7, 0))
def ping_button(self, value: bool):
cfg = ba.app.config
cfg['ping button'] = value
cfg.apply_and_commit()
if cfg['ping button']:
ba.screenmessage("Ping Button is now enabled", color=(0, 1, 0))
else:
ba.screenmessage("Ping Button is now disabled", color=(1, 0.7, 0))
def copy_button(self, value: bool):
cfg = ba.app.config
cfg['copy button'] = value
cfg.apply_and_commit()
if cfg['copy button']:
ba.screenmessage("Copy Text Button is now enabled", color=(0, 1, 0))
else:
ba.screenmessage("Copy Text Button is now disabled", color=(1, 0.7, 0))
def direct_send(self, value: bool):
cfg = ba.app.config
cfg['Direct Send'] = value
cfg.apply_and_commit()
def colorful_chat(self, value: bool):
cfg = ba.app.config
cfg['Colorful Chat'] = value
cfg.apply_and_commit()
def _change_notification(self, choice):
cfg = ba.app.config
cfg['Message Notification'] = choice
cfg.apply_and_commit()
def _change_status(self, choice):
cfg = ba.app.config
cfg['Self Status'] = choice
cfg.apply_and_commit()
def _translaton_btn(self):