craml/main.py

370 lines
15 KiB
Python
Raw Permalink Normal View History

2024-05-06 02:27:06 +08:00
from PySide2.QtGui import QCloseEvent
from module import *
class Login_Window_app(QWidget):
def __init__(self):
super().__init__()
self.run_myapp()
self.run_app()
def run_app(self):
self.setWindowTitle(apps.window_title_apps_name)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(250, 110)
hbox = QHBoxLayout()
self.title = QLabel(text="正在启动 CRA-SERVER CLIENT")
self.title.setStyleSheet("font-size: 15px;")
hbox.addWidget(self.title, alignment=Qt.AlignCenter | Qt.AlignCenter)
self.setLayout(hbox)
def run_myapp(self):
self.th_start_config = apps.Thread_appcode_login_user()
self.th_start_config.data_th.connect(self.run_th_app)
self.th_start_config.start()
return None
def run_th_app(self, data_config: dict):
self.destroy()
2024-05-21 23:33:06 +08:00
if data_config.get("code") == 9:
error_str = data_config.get("data_config")
message_error = apps.Message_yes_no(message="在启动客户端时发生严重错误,请复制以下错误信息发送给开发者或管理员,单击确定即可复制\n\n" + error_str.get("error"))
if message_error.value() is True:
pyperclip.copy(error_str.get("error"))
return sys.exit(0)
2024-05-06 02:27:06 +08:00
if data_config.get("code") == 2:
apps.Message_ok(message="网络出问题了,请检查完网络连接再来哦主人")
return sys.exit(0)
if data_config.get("code") != 1:
self.start_cramc_server_client_myapp = My_APP_Window(data=data_config.get("data_config"), code=data_config.get("code"))
self.start_cramc_server_client_myapp.show()
return None
2024-05-17 13:13:58 +08:00
os.remove(apps.login_json_file)
2024-05-06 02:27:06 +08:00
apps.Message_ok(message="CRA-USER已过期请重新登录")
self.login_user_window = Login_users_window_app()
self.login_user_window.show()
return None
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
class Login_users_window_app(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name + " - 登录")
self.draggable = False
self.offset = None
window_box = QGridLayout()
title_hbox = QHBoxLayout()
title_hbox.addWidget(QLabel(apps.window_title_apps_name), alignment=Qt.AlignLeft | Qt.AlignTop)
close_app_button = QToolButton()
close_app_button.setIcon(QIcon("style/exit.png"))
close_app_button.clicked.connect(self.close_apps_button_ttols)
title_hbox.addWidget(close_app_button, alignment=Qt.AlignRight | Qt.AlignTop)
login_user_box_hbox = QVBoxLayout()
login_user_box_hbox.setContentsMargins(250, 0, 250, 0)
login_user_box = QGridLayout()
login_user_box.setSpacing(15)
login_user_box.addWidget(QLabel(text="用户名:"), 0, 0, alignment=Qt.AlignTop)
self.username = QLineEdit()
2024-05-17 13:13:58 +08:00
self.username.setPlaceholderText("请输入CRA-USER用户名")
2024-05-06 02:27:06 +08:00
login_user_box.addWidget(self.username, 0, 1, alignment=Qt.AlignTop)
login_user_box.addWidget(QLabel(text="密码:"), 1, 0, alignment=Qt.AlignTop)
self.password = QLineEdit()
2024-05-17 13:13:58 +08:00
self.password.setPlaceholderText("请输入CRA-USER密码")
2024-05-06 02:27:06 +08:00
self.password.setEchoMode(QLineEdit.Password)
login_user_box.addWidget(self.password, 1, 1, alignment=Qt.AlignTop)
login_user_button = QPushButton(text="登录")
login_user_button.clicked.connect(self.login_users_mcgames)
login_user_box.addWidget(login_user_button, 2, 0, 1, 0)
register_user = QToolButton(text="注册")
2024-05-07 00:59:50 +08:00
register_user.clicked.connect(lambda: os.startfile(apps.register_web_page))
2024-05-06 02:27:06 +08:00
reload_password = QToolButton(text="忘记密码?")
2024-05-07 00:59:50 +08:00
reload_password.clicked.connect(lambda: os.startfile(apps.reload_password_page))
2024-05-06 02:27:06 +08:00
login_user_box.addWidget(register_user, 3, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
login_user_box.addWidget(reload_password, 3, 1, alignment=Qt.AlignTop | Qt.AlignRight)
login_user_box_hbox.addLayout(login_user_box)
window_box.addLayout(title_hbox, 0, 0, alignment=Qt.AlignTop)
window_box.addLayout(login_user_box_hbox, 1, 0, alignment=Qt.AlignTop | Qt.AlignCenter)
self.setLayout(window_box)
def login_users_mcgames(self):
if self.username.text() == "" or self.password.text() == "":
return apps.Message_ok(message="请填写完整的账号信息用户名和密码")
login_json = {
"username": self.username.text(),
"password": self.password.text()
}
url_https_mc_login = requests.post(url=apps.aotu_user_url + "authserver/authenticate", headers=apps.login_headers, json=login_json)
url_https_mc_login_json = url_https_mc_login.json()
if url_https_mc_login_json.get("error") == "ForbiddenOperationException":
return apps.Message_ok(message=url_https_mc_login_json.get("errorMessage"))
data_login_file = {
"accessToken": url_https_mc_login_json.get("accessToken"),
"clientToken": url_https_mc_login_json.get("clientToken"),
"id": url_https_mc_login_json["selectedProfile"]["id"],
"name": url_https_mc_login_json["selectedProfile"]["name"]
}
with open(file=apps.login_json_file, mode='w', encoding="UTF-8", newline='') as f_write:
json.dump(data_login_file, f_write)
self.destroy()
2024-05-07 00:44:15 +08:00
self.login_user_window = Login_Window_app()
self.login_user_window.show()
2024-05-06 02:27:06 +08:00
return None
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
def close_apps_button_ttols(self):
self.destroy()
return sys.exit(0)
class My_APP_Window(QTabWidget):
def __init__(self, data: dict, code: int):
super().__init__()
self.data = data
self.code = code
2024-05-17 13:13:58 +08:00
self.server_list_dict: dict = self.data.get("server_list")
self.server_id_dict_list: dict = self.data.get("server_id_list")
2024-05-06 02:27:06 +08:00
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(apps.window_size_int[0], apps.window_size_int[1])
self.setWindowTitle(apps.window_title_apps_name)
self.draggable = False
self.offset = None
self.run_my_gui()
def run_my_gui(self):
gui_box_grid = QGridLayout()
gui_box_grid.setColumnMinimumWidth(0, 0)
title_name = QLabel(text=apps.window_title_apps_name)
gui_box_grid.addWidget(title_name, 0, 0, alignment=Qt.AlignTop | Qt.AlignLeft)
zxh_button = QToolButton()
zxh_button.setIcon(QIcon("style/zxh.png"))
zxh_button.clicked.connect(self.zxh_apps)
exit_button = QToolButton()
exit_button.setIcon(QIcon("style/exit.png"))
exit_button.clicked.connect(self.exit_window_apps)
window_header_gridbox = QHBoxLayout()
window_header_gridbox.setContentsMargins(0, 0, 0, 0)
window_header_gridbox.addStretch(0)
window_header_gridbox.addWidget(zxh_button, alignment=Qt.AlignTop | Qt.AlignRight)
window_header_gridbox.addWidget(exit_button, alignment=Qt.AlignTop | Qt.AlignRight)
gui_box_grid.addLayout(window_header_gridbox, 0, 1)
self.index_home = QWidget()
self.craserver_client_settings = Craserver_client_settings()
2024-05-17 13:13:58 +08:00
self.craserver_client_game_settings = App_settings_tab()
2024-05-06 02:27:06 +08:00
self.craserver_client_user_settings = QWidget()
self.header_tab = QTabWidget()
self.header_tab.setContentsMargins(0, 0, 0, 0)
self.header_tab.addTab(self.index_home, "主页")
self.header_tab.addTab(self.craserver_client_settings, "管理")
self.header_tab.addTab(self.craserver_client_game_settings, "设置")
self.header_tab.addTab(self.craserver_client_user_settings, "CRA-USER")
gui_box_grid.addWidget(self.header_tab, 1, 0, 1, 0)
self.setLayout(gui_box_grid)
self.index_home_page()
self.craserver_client_user_settings_page()
def craserver_client_user_settings_page(self):
2024-05-17 13:13:58 +08:00
self.gamer_name_user = self.data.get("name")
v_box = QVBoxLayout()
v_box.setSpacing(25)
login_user_panel_button = QPushButton(text="控制台")
login_user_panel_button.setFixedSize(250, 35)
login_user_panel_button.clicked.connect(lambda: os.startfile("https://login.mc-user.com:233/account/index"))
exit_user_login_button = QPushButton(text="退出登录")
exit_user_login_button.setFixedSize(250, 35)
exit_user_login_button.clicked.connect(self.exit_user_apps)
v_box.addWidget(QLabel(text=self.gamer_name_user), alignment=Qt.AlignCenter | Qt.AlignCenter)
user_button_hbox = QHBoxLayout()
user_button_hbox.setContentsMargins(200, 0, 200, 300)
user_button_hbox.addWidget(login_user_panel_button, alignment=Qt.AlignTop | Qt.AlignCenter)
user_button_hbox.addWidget(exit_user_login_button, alignment=Qt.AlignTop | Qt.AlignCenter)
v_box.addLayout(user_button_hbox)
join_qq_group = QPushButton(text="加入QQ群")
join_kook = QPushButton(text="加入KOOK")
self.craserver_client_user_settings.setLayout(v_box)
def exit_user_apps(self):
message = apps.Message_yes_no(message="确定要退出登录吗?")
if message.value() is True:
with open(file=apps.login_json_file, mode='r', encoding="UTF-8", newline='') as f:
data_json = json.load(f)
data_exit_user = {
"accessToken": data_json.get("accessToken"),
"clientToken": data_json.get("clientToken")
}
requests.post(url=apps.aotu_user_url + "authserver/invalidate", headers=apps.login_headers, json=data_exit_user)
os.remove(apps.login_json_file)
self.destroy()
self.login_window_user_app = Login_users_window_app()
self.login_window_user_app.show()
return None
2024-05-06 02:27:06 +08:00
def index_home_page(self):
index_home_grid_box = QGridLayout()
2024-05-17 13:13:58 +08:00
search_box = QHBoxLayout()
self.search_lineedit = QLineEdit()
self.search_lineedit.setPlaceholderText("输入服务器名称或ID搜索")
search_button = QPushButton(text="搜索")
search_button.setFixedWidth(120)
reload_server_list_button = QPushButton(text="显示全部")
reload_server_list_button.setFixedWidth(120)
search_box.addWidget(self.search_lineedit)
search_box.addWidget(search_button)
search_box.addWidget(reload_server_list_button)
index_home_grid_box.addLayout(search_box, 0, 0, alignment=Qt.AlignTop | Qt.AlignTop)
2024-05-06 02:27:06 +08:00
self.server_list = QListWidget()
2024-05-20 16:23:36 +08:00
self.server_ip_list = QListWidget()
self.server_ip_list.setFixedSize(500, 55)
self.server_ip_list.setFlow(QListView.LeftToRight)
index_home_grid_box.addWidget(self.server_ip_list, 2, 0, alignment=Qt.AlignLeft | Qt.AlignBottom)
2024-05-17 13:13:58 +08:00
self.start_game_button = QPushButton(text="启动游戏")
2024-05-06 02:27:06 +08:00
self.start_game_button.clicked.connect(self.start_games_apps)
self.start_game_button.setFixedSize(200, 55)
2024-05-17 13:13:58 +08:00
index_home_grid_box.addWidget(self.server_list, 1, 0)
index_home_grid_box.addWidget(self.start_game_button, 2, 0, alignment=Qt.AlignRight | Qt.AlignBottom)
2024-05-06 02:27:06 +08:00
2024-05-17 13:13:58 +08:00
for i_server_list_for in self.server_list_dict:
2024-05-20 16:23:36 +08:00
item = apps.customQListWidgetItem(image=i_server_list_for.get("image"), names=i_server_list_for.get("servername"), tests=i_server_list_for.get("summary"))
2024-05-06 02:27:06 +08:00
self.server_list.addItem(item)
self.server_list.setItemWidget(item, item.item_widget)
self.index_home.setLayout(index_home_grid_box)
def start_games_apps(self):
if self.server_list.currentRow() == -1:
return apps.Message_ok(message="请先选择需要加入的服务器")
2024-05-20 16:23:36 +08:00
if self.server_ip_list.currentRow() == -1:
return apps.Message_ok(message="请选择一条线路")
2024-05-17 13:13:58 +08:00
start_game_name = self.server_id_dict_list[self.server_list.currentRow()]
2024-05-20 16:23:36 +08:00
return None
def stop_rungame_apps(self):
2024-05-06 02:27:06 +08:00
return None
def zxh_apps(self):
return self.showMinimized()
def exit_window_apps(self):
self.destroy()
return sys.exit(0)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
if self.draggable:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
self.draggable = False
def closeEvent(self, event: QCloseEvent) -> None:
self.destroy()
return sys.exit(0)
2024-05-17 13:13:58 +08:00
class App_settings_tab(QTabWidget):
def __init__(self):
super().__init__()
self.game_settings = QWidget()
self.app_settings = QWidget()
self.addTab(self.game_settings, "游戏")
self.addTab(self.app_settings, "客户端")
self.game_settings_page()
self.app_settings_page()
def game_settings_page(self):
pass
def app_settings_page(self):
pass
2024-05-06 02:27:06 +08:00
class Craserver_client_settings(QTabWidget):
def __init__(self):
super().__init__()
self.mods_settings = QWidget()
self.sh_settings = QWidget()
self.addTab(self.mods_settings, "MODS列表")
self.addTab(self.sh_settings, "光影管理")
self.mods_settings_page()
self.sh_settings_page()
def mods_settings_page(self):
pass
def sh_settings_page(self):
pass
if __name__ == '__main__':
is_json_none = False
QGuiApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication()
if os.path.exists("config_app") is False:
os.mkdir("config_app")
if os.path.isfile(apps.login_json_file) is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True:
with open(file=apps.login_json_file, mode='r', encoding="UTF-8", newline='') as f_read:
json_test = json.load(f_read)
is_json_none = all(json_test)
if is_json_none is False:
window = Login_users_window_app()
if os.path.isfile(apps.login_json_file) is True & is_json_none is True:
window = Login_Window_app()
window.show()
sys.exit(app.exec_())