2023-07-08 15:21:36 +05:30
|
|
|
# -*- coding: utf-8 -*-
|
2023-07-04 11:57:58 +05:30
|
|
|
# ba_meta require api 8
|
2023-07-08 15:21:36 +05:30
|
|
|
'''
|
|
|
|
|
Server Switch Plugin by My.Smoothy
|
|
|
|
|
Let you switch recently joined servers very quickly
|
|
|
|
|
+ Added button to quicky look into public server list without leaving current game.
|
|
|
|
|
|
|
|
|
|
discord: mr.smoothy
|
|
|
|
|
https://discord.gg/ucyaesh
|
|
|
|
|
Youtube : Hey Smoothy
|
|
|
|
|
Download more mods from
|
|
|
|
|
https://bombsquad-community.web.app/mods
|
|
|
|
|
'''
|
2023-07-04 11:57:58 +05:30
|
|
|
import babase
|
2023-07-08 15:21:36 +05:30
|
|
|
import bauiv1lib.mainmenu as bastd_ui_mainmenu
|
2023-07-04 11:57:58 +05:30
|
|
|
import bauiv1 as bui
|
|
|
|
|
import bascenev1 as bs
|
2023-07-08 15:21:36 +05:30
|
|
|
current_server_ip = "127.0.0.1"
|
|
|
|
|
current_server_port = 43210
|
|
|
|
|
servers = []
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
|
2023-07-08 15:21:36 +05:30
|
|
|
def _refresh_in_game(func):
|
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
|
returnValue = func(self, *args, **kwargs)
|
|
|
|
|
uiscale = bui.app.ui_v1.uiscale
|
|
|
|
|
bui.containerwidget(
|
|
|
|
|
edit=self._root_widget,
|
2023-07-08 09:56:30 +00:00
|
|
|
size=(self._width*2, self._height), # double the width
|
2023-07-08 15:21:36 +05:30
|
|
|
scale=(
|
|
|
|
|
2.15
|
|
|
|
|
if uiscale is bui.UIScale.SMALL
|
|
|
|
|
else 1.6
|
|
|
|
|
if uiscale is bui.UIScale.MEDIUM
|
|
|
|
|
else 1.0
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
h = 125
|
|
|
|
|
v = self._height - 60.0
|
|
|
|
|
bui.textwidget(
|
2023-07-08 09:56:30 +00:00
|
|
|
parent=self._root_widget,
|
|
|
|
|
draw_controller=None,
|
|
|
|
|
text="IP: "+current_server_ip+" PORT: "+str(current_server_port),
|
|
|
|
|
position=(h-self._button_width/2 + 130, v+60),
|
|
|
|
|
h_align='center',
|
|
|
|
|
v_align='center',
|
|
|
|
|
size=(20, 60),
|
|
|
|
|
scale=0.6)
|
2023-07-08 15:21:36 +05:30
|
|
|
self._public_servers = bui.buttonwidget(
|
2023-07-08 09:56:30 +00:00
|
|
|
color=(0.8, 0.45, 1),
|
|
|
|
|
parent=self._root_widget,
|
|
|
|
|
position=(h+self._button_width-10, v+60+20),
|
|
|
|
|
size=(self._button_width/4, self._button_height/2),
|
|
|
|
|
scale=1.0,
|
|
|
|
|
autoselect=self._use_autoselect,
|
|
|
|
|
label="~~~",
|
|
|
|
|
on_activate_call=bs.Call(public_servers))
|
2023-07-08 15:21:36 +05:30
|
|
|
for server in servers:
|
|
|
|
|
self._server_button = bui.buttonwidget(
|
|
|
|
|
color=(0.8, 0, 1),
|
2022-09-17 22:06:42 +05:30
|
|
|
parent=self._root_widget,
|
2023-07-08 09:56:30 +00:00
|
|
|
position=((h - self._button_width / 2) + self._button_width + 20, v),
|
2022-09-17 16:39:03 +00:00
|
|
|
size=(self._button_width, self._button_height),
|
2023-07-08 15:21:36 +05:30
|
|
|
scale=1.0,
|
2022-09-17 22:06:42 +05:30
|
|
|
autoselect=self._use_autoselect,
|
2023-07-08 15:21:36 +05:30
|
|
|
label=server["name"][0:22],
|
|
|
|
|
on_activate_call=bs.Call(bs.connect_to_party, server["ip"], server["port"]))
|
2023-07-08 09:56:30 +00:00
|
|
|
|
2023-07-08 15:21:36 +05:30
|
|
|
v -= 50
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
return returnValue
|
2023-07-08 15:21:36 +05:30
|
|
|
return wrapper
|
2022-09-17 16:39:03 +00:00
|
|
|
|
2023-07-08 09:56:30 +00:00
|
|
|
|
2023-07-08 15:21:36 +05:30
|
|
|
connect = bs.connect_to_party
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
|
2023-07-08 15:21:36 +05:30
|
|
|
def connect_to_party(address, port=43210, print_progress=False):
|
|
|
|
|
global current_server_ip
|
|
|
|
|
global current_server_port
|
|
|
|
|
if (bs.get_connection_to_host_info() != {}):
|
|
|
|
|
bs.disconnect_from_host()
|
|
|
|
|
current_server_ip = address
|
|
|
|
|
current_server_port = port
|
|
|
|
|
connect(address, port, print_progress)
|
|
|
|
|
babase.apptimer(1, check_connect_status)
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
|
2023-07-08 15:21:36 +05:30
|
|
|
def check_connect_status():
|
|
|
|
|
global servers
|
|
|
|
|
global current_server_ip
|
|
|
|
|
global current_server_port
|
|
|
|
|
if (bs.get_connection_to_host_info() != {}):
|
|
|
|
|
if (not bs.get_connection_to_host_info()['name']):
|
|
|
|
|
babase.apptimer(1, check_connect_status)
|
|
|
|
|
return
|
2023-07-08 09:56:30 +00:00
|
|
|
new_server = {"name": bs.get_connection_to_host_info(
|
|
|
|
|
)['name'], "ip": current_server_ip, "port": current_server_port}
|
2023-07-08 15:21:36 +05:30
|
|
|
if new_server not in servers:
|
|
|
|
|
servers.append(new_server)
|
|
|
|
|
servers = servers[-3:]
|
2022-09-17 16:39:03 +00:00
|
|
|
else:
|
2023-07-08 15:21:36 +05:30
|
|
|
print("connection failed falling back to gather window")
|
|
|
|
|
public_servers()
|
2022-09-17 22:06:42 +05:30
|
|
|
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
def public_servers(origin=None):
|
2023-07-08 15:21:36 +05:30
|
|
|
from bauiv1lib.gather import GatherWindow
|
2023-07-08 09:56:30 +00:00
|
|
|
bui.app.ui_v1.set_main_menu_window(GatherWindow(origin_widget=origin).get_root_widget())
|
2022-09-17 22:06:42 +05:30
|
|
|
|
2023-07-04 11:57:58 +05:30
|
|
|
# ba_meta export plugin
|
2023-07-08 09:56:30 +00:00
|
|
|
|
|
|
|
|
|
2023-07-04 11:57:58 +05:30
|
|
|
class bySmoothy(babase.Plugin):
|
2022-09-17 22:06:42 +05:30
|
|
|
def __init__(self):
|
2023-07-08 09:56:30 +00:00
|
|
|
bastd_ui_mainmenu.MainMenuWindow._refresh_in_game = _refresh_in_game(
|
|
|
|
|
bastd_ui_mainmenu.MainMenuWindow._refresh_in_game)
|
2023-07-08 15:21:36 +05:30
|
|
|
bs.connect_to_party = connect_to_party
|