bombsquad-plugin-manager/plugins/utilities/share_replay.py

309 lines
10 KiB
Python
Raw Normal View History

2022-11-07 00:26:16 +05:30
# ba_meta require api 7
from __future__ import annotations
from typing import TYPE_CHECKING, cast
if TYPE_CHECKING:
from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union
2022-11-07 19:58:27 +00:00
from os import listdir, mkdir, path, sep
from shutil import copy, copytree
2022-11-06 21:24:27 +00:00
2022-11-07 00:26:16 +05:30
import ba
import _ba
from bastd.ui.watch import WatchWindow as ww
from bastd.ui.popup import PopupWindow
2022-11-07 19:58:27 +00:00
# mod by ʟօʊքɢǟʀօʊ
# export replays to mods folder and share with your friends or have a backup
def Print(*args, color=None, top=None):
out = ""
2022-11-07 00:26:16 +05:30
for arg in args:
2022-11-07 19:58:27 +00:00
a = str(arg)
2022-11-07 00:26:16 +05:30
out += a
2022-11-07 19:58:27 +00:00
ba.screenmessage(out, color=color, top=top)
2022-11-07 00:26:16 +05:30
def cprint(*args):
2022-11-07 19:58:27 +00:00
out = ""
2022-11-07 00:26:16 +05:30
for arg in args:
2022-11-07 19:58:27 +00:00
a = str(arg)
2022-11-07 00:26:16 +05:30
out += a
_ba.chatmessage(out)
2022-11-06 21:24:27 +00:00
2022-11-19 08:44:56 +05:30
title="SHARE REPLAY"
2022-11-07 19:58:27 +00:00
internal_dir = path.join("ba_data", "..", "..", "..", "files", "bombsquad_config", "replays" + sep)
external_dir = path.join(_ba.env()["python_directory_user"], "replays"+sep)
2022-11-19 08:44:56 +05:30
tab_sel_texture=ba.gettexture("buttonSquare")
tab_unsel_texture=ba.gettexture("chestIconEmpty")
2022-11-19 01:50:31 +05:30
2022-11-07 19:58:27 +00:00
# colors
pink = (1, 0.2, 0.8)
green = (0.4, 1, 0.4)
red = (1, 0, 0)
2022-11-19 08:44:56 +05:30
blue=(0.26, 0.65,0.94)
blue_highlight= (0.4, 0.7,1)
2022-11-07 00:26:16 +05:30
2022-11-08 01:27:06 +05:30
if not path.exists(external_dir):
2022-11-07 00:26:16 +05:30
mkdir(external_dir)
2022-11-07 19:58:27 +00:00
Print("You are ready to share replays", color=pink)
2022-11-19 08:44:56 +05:30
2022-11-07 00:26:16 +05:30
class Help(PopupWindow):
def __init__(self):
uiscale = ba.app.ui.uiscale
2022-11-19 01:50:31 +05:30
self.width = 1000
2022-11-07 00:26:16 +05:30
self.height = 300
2022-11-07 19:58:27 +00:00
2022-11-07 00:26:16 +05:30
PopupWindow.__init__(self,
position=(0.0, 0.0),
size=(self.width, self.height),
scale=1.2,)
2022-11-07 19:58:27 +00:00
ba.containerwidget(edit=self.root_widget, on_outside_click_call=self.close)
ba.textwidget(parent=self.root_widget, position=(0, self.height * 0.6),
2022-11-19 01:50:31 +05:30
text=f"•Replays are exported to\n {external_dir}\n•Copy replays to the above folder to be able to import them into the game")
def close(self):
ba.playsound(ba.getsound('swish'))
ba.containerwidget(edit=self.root_widget, transition="out_right",)
2022-11-19 08:44:56 +05:30
2022-11-19 01:50:31 +05:30
class SyncConfirmation(PopupWindow):
def __init__(self):
uiscale = ba.app.ui.uiscale
2022-11-19 02:15:34 +05:30
self.width = 600
2022-11-19 01:50:31 +05:30
self.height = 300
PopupWindow.__init__(self,
position=(0.0, 0.0),
size=(self.width, self.height),
scale=1.2,)
2022-11-19 08:44:56 +05:30
2022-11-19 02:15:34 +05:30
ba.textwidget(parent=self.root_widget, position=(30, self.height * 0.8),
text=" Are you sure you want to continue\n\nWARNING:replays with same name in mods folder\n will be overwritten")
2022-11-19 08:44:56 +05:30
cancel=ba.buttonwidget(parent=self.root_widget,label=ba.Lstr(resource='cancelText'),size=(200,80),position=(80,50),on_activate_call=self.close)
ba.buttonwidget(parent=self.root_widget,label=ba.Lstr(resource='okText'),size=(200,80),position=(300,50),color=green,on_activate_call=SettingWindow.sync)
ba.containerwidget(edit=self.root_widget, on_outside_click_call=self.close,cancel_button=cancel)
2022-11-07 19:58:27 +00:00
2022-11-07 00:26:16 +05:30
def close(self):
ba.playsound(ba.getsound('swish'))
ba.containerwidget(edit=self.root_widget, transition="out_right",)
class SettingWindow():
def __init__(self):
2022-11-19 01:50:31 +05:30
global internal
2022-11-07 00:26:16 +05:30
self.draw_ui()
2022-11-19 08:44:56 +05:30
ba.containerwidget(edit=self.root,cancel_button=self.close_button)
2022-11-07 19:58:27 +00:00
self.selected_name = None
2022-11-19 08:44:56 +05:30
internal=True
2022-11-19 01:50:31 +05:30
self.on_tab_select(internal)
2022-11-19 08:44:56 +05:30
def on_select_text(self, widget,name):
existing_widgets=self.scroll2.get_children()
2022-11-19 01:50:31 +05:30
for i in existing_widgets:
2022-11-19 08:44:56 +05:30
ba.textwidget(edit=i,color=(1,1,1))
2022-11-07 19:58:27 +00:00
ba.textwidget(edit=widget, color=(1, 1, 0))
2022-11-19 08:44:56 +05:30
self.selected_name=name
def on_tab_select(self,_internal):
global internal
internal=_internal
if internal==True:
dir_list=listdir(internal_dir)
ba.buttonwidget(edit=self.share_button,label="EXPORT",icon=ba.gettexture("upButton"),)
sel=self.internal_tab
unsel=self.external_tab
else:
dir_list=listdir(external_dir)
ba.buttonwidget(edit=self.share_button,label="IMPORT",icon=ba.gettexture("downButton"),)
sel= self.external_tab
unsel= self.internal_tab
ba.buttonwidget(edit=sel,texture=tab_sel_texture,color=blue,size=(120,80))
ba.buttonwidget(edit=unsel,texture=tab_unsel_texture,color=blue,size=(120,100))
dir_list=sorted(dir_list)
existing_widgets=self.scroll2.get_children()
if existing_widgets:
for i in existing_widgets:
i.delete()
height = 900
for i in dir_list:
height -= 40
a = i
i = ba.textwidget(
parent=self.scroll2,
size=(500, 50),
text=i.split(".")[0],
position=(10, height),
selectable=True,
max_chars=40,
click_activate=True,)
ba.textwidget(edit=i, on_activate_call=ba.Call(self.on_select_text, i , a))
2022-11-07 00:26:16 +05:30
def draw_ui(self):
self.uiscale = ba.app.ui.uiscale
2022-11-07 19:58:27 +00:00
self.root = ba.Window(ba.containerwidget(
size=(900, 670), on_outside_click_call=self.close, transition="in_right")).get_root_widget()
2022-11-19 08:44:56 +05:30
self.close_button = ba.buttonwidget(
parent=self.root,
position=(90, 560),
button_type='backSmall',
size=(60, 60),
label=ba.charstr(ba.SpecialChar.BACK),
scale=1.5,
on_activate_call=self.close)
2022-11-07 00:26:16 +05:30
ba.textwidget(
parent=self.root,
size=(200, 100),
2022-11-19 08:44:56 +05:30
position=(350, 550),
2022-11-07 00:26:16 +05:30
scale=2,
selectable=False,
h_align="center",
v_align="center",
2022-11-19 01:50:31 +05:30
text=title,
2022-11-07 00:26:16 +05:30
color=green)
2022-11-07 19:58:27 +00:00
2022-11-07 00:26:16 +05:30
ba.buttonwidget(
parent=self.root,
2022-11-19 08:44:56 +05:30
position=(650, 580),
2022-11-07 19:58:27 +00:00
size=(35, 35),
2022-11-08 01:27:06 +05:30
texture=ba.gettexture("achievementEmpty"),
label="",
2022-11-07 00:26:16 +05:30
on_activate_call=Help)
2022-11-19 08:44:56 +05:30
internal_tab_pos=85,400
internal_tab_size=120,80
external_tab_pos=85,300
external_tab_size=120,80
self.internal_tab=ba.buttonwidget(
2022-11-19 01:50:31 +05:30
parent=self.root,
position=internal_tab_pos,
size=internal_tab_size,
button_type="square",
2022-11-19 02:15:34 +05:30
label="INTERNAL",
2022-11-19 01:50:31 +05:30
text_scale=2,
2022-11-19 08:44:56 +05:30
color=blue_highlight,
texture=tab_sel_texture)
self.external_tab=ba.buttonwidget(
2022-11-19 01:50:31 +05:30
parent=self.root,
position=external_tab_pos,
size=external_tab_size,
button_type="square",
2022-11-19 02:15:34 +05:30
label="EXTERNAL",
2022-11-19 01:50:31 +05:30
text_scale=2,
color=blue,
2022-11-19 08:44:56 +05:30
texture=tab_unsel_texture)
ba.buttonwidget(edit=self.internal_tab,on_activate_call=ba.Call(self.on_tab_select,True))
ba.buttonwidget(edit=self.external_tab,on_activate_call=ba.Call(self.on_tab_select,False))
self.share_button=ba.buttonwidget(
2022-11-07 00:26:16 +05:30
parent=self.root,
2022-11-19 01:50:31 +05:30
position=(720, 400),
size=(110, 50),
2022-11-07 00:26:16 +05:30
scale=1.5,
2022-11-19 01:50:31 +05:30
button_type="square",
2022-11-07 00:26:16 +05:30
label="EXPORT",
2022-11-19 01:50:31 +05:30
text_scale=2,
icon=ba.gettexture("upButton"),
on_activate_call=self.share)
2022-11-19 08:44:56 +05:30
sync_button=ba.buttonwidget(
2022-11-19 01:50:31 +05:30
parent=self.root,
position=(720, 300),
size=(110, 50),
scale=1.5,
button_type="square",
label="SYNC",
text_scale=2,
icon=ba.gettexture("ouyaYButton"),
2022-11-19 08:44:56 +05:30
on_activate_call=SyncConfirmation)
2022-11-07 19:58:27 +00:00
scroll = ba.scrollwidget(
2022-11-07 00:26:16 +05:30
parent=self.root,
2022-11-07 19:58:27 +00:00
size=(500, 400),
2022-11-19 01:50:31 +05:30
position=(200, 100),)
self.scroll2 = ba.columnwidget(parent=scroll, size=(
2022-11-19 08:44:56 +05:30
500, 900))
2022-11-19 01:50:31 +05:30
def share(self):
2022-11-07 19:58:27 +00:00
if self.selected_name is None:
Print("Select a replay", color=red)
return
2022-11-19 08:44:56 +05:30
if internal:self.export()
else:self.importx()
2022-11-07 19:58:27 +00:00
# image={"texture":ba.gettexture("bombColor"),"tint_texture":None,"tint_color":None,"tint2_color":None})
2022-11-19 08:44:56 +05:30
2022-11-19 02:15:34 +05:30
def sync(self=""):
2022-11-19 08:44:56 +05:30
internal_list=listdir(internal_dir)
external_list=listdir(external_dir)
2022-11-19 01:50:31 +05:30
for i in internal_list:
copy(internal_dir+sep+i, external_dir+sep+i)
for i in external_list:
if i in internal_list:
pass
else:
copy(external_dir+sep+i, internal_dir+sep+i)
2022-11-19 08:44:56 +05:30
Print("Synced all replays",color=pink)
2022-11-19 01:50:31 +05:30
def export(self):
2022-11-19 08:44:56 +05:30
copy(internal_dir+self.selected_name, external_dir+self.selected_name)
2022-11-07 19:58:27 +00:00
Print(self.selected_name[0:-4]+" exported", top=True, color=pink)
2022-11-19 08:44:56 +05:30
2022-11-19 01:50:31 +05:30
def importx(self):
copy(external_dir+self.selected_name, internal_dir+self.selected_name)
2022-11-19 08:44:56 +05:30
Print(self.selected_name[0:-4]+" imported", top=True, color=green)
2022-11-07 00:26:16 +05:30
def close(self):
ba.playsound(ba.getsound('swish'))
2022-11-07 19:58:27 +00:00
ba.containerwidget(edit=self.root, transition="out_right",)
2022-11-19 08:44:56 +05:30
2022-11-07 00:26:16 +05:30
# ++++++++++++++++for keyboard navigation++++++++++++++++
2022-11-07 19:58:27 +00:00
#ba.widget(edit=self.enable_button, up_widget=decrease_button, down_widget=self.lower_text,left_widget=save_button, right_widget=save_button)
2022-11-07 00:26:16 +05:30
# --------------------------------------------------------------------------------------------------
2022-11-07 19:58:27 +00:00
ww.__old_init__ = ww.__init__
2022-11-06 21:24:27 +00:00
2022-11-07 19:58:27 +00:00
def new_init(self, transition="in_right", origin_widget=None):
self.__old_init__(transition, origin_widget)
2022-11-07 00:26:16 +05:30
self._share_button = ba.buttonwidget(
parent=self._root_widget,
position=(self._width*0.70, self._height*0.80),
size=(220, 60),
scale=1.0,
color=green,
icon=ba.gettexture('usersButton'),
iconscale=1.5,
2022-11-19 01:50:31 +05:30
label=title,
2022-11-07 00:26:16 +05:30
on_activate_call=SettingWindow)
2022-11-07 19:58:27 +00:00
2022-11-07 00:26:16 +05:30
# ba_meta export plugin
2022-11-08 01:27:06 +05:30
class Loup(ba.Plugin):
2022-11-07 00:26:16 +05:30
def on_app_running(self):
2022-11-07 19:58:27 +00:00
ww.__init__ = new_init
2022-11-07 00:26:16 +05:30
def has_settings_ui(self):
return True
2022-11-07 19:58:27 +00:00
def show_settings_ui(self, button):
2022-11-07 00:26:16 +05:30
SettingWindow()
2022-11-19 08:44:56 +05:30
2022-11-19 01:50:31 +05:30
def on_plugin_manager_prompt(self):
SettingWindow()