diff --git a/Code/gui/conntect.py b/Code/gui/conntect.py deleted file mode 100644 index 0406bce..0000000 --- a/Code/gui/conntect.py +++ /dev/null @@ -1,59 +0,0 @@ -import logging -from pathlib import Path - -import dearpygui.dearpygui as dpg -from api.chat import ChatModule -from DMBotNetwork import Client -from misc import decode_string -from root_path import ROOT_PATH -from systems.loc import Localization as loc - -logger = logging.getLogger("Connect") - -class ConnectManager: - - def create_connect_window(self): - if dpg.does_item_exist("connect_window"): - dpg.focus_item("connect_window") - return - - with dpg.window(label="Connect", tag="connect_window") as settings_window: - dpg.add_text(loc.get_string("connect_main_text")) - - dpg.add_input_text(hint=loc.get_string("connect_login_hint") , tag="connect_login") - dpg.add_input_text(hint=loc.get_string("connect_password_hint"), tag="connect_password", password=True) - dpg.add_input_text(hint=loc.get_string("connect_host_hint") , tag="connect_host") - dpg.add_input_int (label=loc.get_string("connect_port_lable") , tag="connect_port") - - dpg.add_button(label=loc.get_string("connect_button"), callback=self.run_client) - - dpg.add_input_text(hint="send_msg_debug", tag="OOC_CHAT") - dpg.add_button(label="send", callback=self.send_chat_msg) - - async def send_chat_msg(self, *args): - value = dpg.get_value("OOC_CHAT") - await ChatModule.send_ooc(decode_string(value)) - - async def run_client(self, sender, app_data, user_data): - await Client.close_connection() - - login_value = dpg.get_value("connect_login") - password_value = dpg.get_value("connect_password") - host_value = dpg.get_value("connect_host") - port_value = dpg.get_value("connect_port") - - Client.set_login(login_value) - Client.set_password(password_value) - Client.set_host(host_value) - Client.set_port(port_value) - - server_path = Path(ROOT_PATH) / "Content" / "Servers" - Client.set_server_file_path(server_path) - logger.info(f"Set up done. Path: {server_path}, login: {login_value}, password: {password_value}, host: {host_value}, port: {port_value}") - - logger.info("Attempting to connect to the server...") - try: - await Client.connect() - - except Exception as e: - logger.error(f"Connection failed: {e}") diff --git a/Code/gui/fonts.py b/Code/gui/fonts_setup.py similarity index 100% rename from Code/gui/fonts.py rename to Code/gui/fonts_setup.py diff --git a/Code/gui/main_app.py b/Code/gui/main_app.py deleted file mode 100644 index cff2b50..0000000 --- a/Code/gui/main_app.py +++ /dev/null @@ -1,48 +0,0 @@ -import dearpygui.dearpygui as dpg -from dearpygui_async import DearPyGuiAsync -from systems.loc import Localization as loc - -from .conntect import ConnectManager -from .fonts import FontManager - - -class DMClientApp: - def __init__(self): - self.dpg_async = DearPyGuiAsync() - - def setup(self): - dpg.create_context() - FontManager.load_fonts() - dpg.create_viewport(title=loc.get_string("main-app-name"), width=600, height=400) - dpg.setup_dearpygui() - self.create_warning_window() - - self.con_manager = ConnectManager() - - def create_warning_window(self): - with dpg.window(label="Warning", modal=True, tag="warning_window", no_move=True, no_close=True, no_collapse=True): - dpg.add_text(loc.get_string("main_text_warning_window")) - dpg.add_button(label=loc.get_string("yes_warning_window"), callback=self.on_yes) - dpg.add_button(label=loc.get_string("no_warning_window"), callback=self.on_no) - - def on_yes(self, sender, app_data): - dpg.delete_item("warning_window") - self.create_main_window() - - def on_no(self, sender, app_data): - self.stop() - - def create_main_window(self): - with dpg.window(label="Main", tag="main_window"): - dpg.add_button(label=loc.get_string("connect_window_open"), callback=self.con_manager.create_connect_window) - dpg.add_button(label="debug", callback=lambda: dpg.show_debug()) - dpg.add_button(label="demo", callback=lambda: dpg.show_imgui_demo()) - - def run(self): - dpg.show_viewport() - self.dpg_async.run() - dpg.start_dearpygui() - dpg.destroy_context() - - def stop(self): - dpg.stop_dearpygui() diff --git a/Code/gui/map.py b/Code/gui/map.py deleted file mode 100644 index 3fc1b5a..0000000 --- a/Code/gui/map.py +++ /dev/null @@ -1,123 +0,0 @@ -import logging -import os -import time - -import dearpygui.dearpygui as dpg -from DMBotTools import Coordinate - -logger = logging.getLogger("MapRenderer") - -class MapRenderer: - def __init__(self, cell_size=64, window_width=800, window_height=600): - self.cell_size = cell_size - self.window_width = window_width - self.window_height = window_height - self.camera_position = Coordinate(0, 0) - self.textures = {} - self.texture_paths = {} - self.is_dragging = False - self.drag_start_position = Coordinate(0, 0) - self.initial_camera_position = Coordinate(0, 0) - self.movement_speed = 0.1 - self.last_move_time = time.time() - self.active_keys = set() - - def set_texture_paths(self, texture_dict): - self.texture_paths = texture_dict - - def load_texture(self, coord): - if coord not in self.textures: - path = self.texture_paths.get(coord) - if path and os.path.exists(path): - try: - width, height, channels, data = dpg.load_image(path) - tag = f"texture_{coord.x}_{coord.y}" - dpg.add_static_texture(width, height, data, tag=tag) - self.textures[coord] = tag - except Exception as e: - logger.error(f"Ошибка загрузки текстуры {path}: {e}") - self.textures[coord] = f"Error: {os.path.basename(path)}" - else: - logger.warning(f"Текстура не найдена по пути: {path}") - self.textures[coord] = "No Texture" - - def render_visible_objects(self): - if not dpg.does_item_exist("map_window"): - logger.warning("map_window не существует, пропускаем рендеринг.") - return - - if not dpg.does_item_exist("grid_group"): - with dpg.group(tag="grid_group", parent="map_window"): - pass - - dpg.delete_item("grid_group", children_only=True) - - for coord in self.texture_paths.keys(): - screen_x = (coord.x - self.camera_position.x) * self.cell_size - screen_y = (coord.y - self.camera_position.y) * self.cell_size - - if 0 <= screen_x < self.window_width and 0 <= screen_y < self.window_height: - self.load_texture(coord) - texture_tag = self.textures[coord] - if texture_tag.startswith("texture_"): - dpg.add_image(texture_tag, pos=(screen_x, screen_y), parent="grid_group") - else: - dpg.add_text(texture_tag, pos=(screen_x, screen_y), parent="grid_group") - - def create_map_window(self): - if dpg.does_item_exist("map_window"): - dpg.focus_item("map_window") - return - - with dpg.window(label="Map Renderer", tag="map_window", width=self.window_width, height=self.window_height): - with dpg.handler_registry(): - dpg.add_key_press_handler(callback=self.key_down_callback) - dpg.add_key_release_handler(callback=self.key_up_callback) - dpg.add_mouse_drag_handler(button=dpg.mvMouseButton_Left, callback=self.on_mouse_drag) - dpg.add_mouse_release_handler(button=dpg.mvMouseButton_Left, callback=self.on_mouse_release) - - self.render_visible_objects() - - def on_mouse_drag(self, sender, app_data): - if not self.is_dragging: - self.is_dragging = True - self.drag_start_position = Coordinate(app_data[1], app_data[2]) - self.initial_camera_position = self.camera_position - - delta_x = (self.drag_start_position.x - app_data[1]) // self.cell_size - delta_y = (self.drag_start_position.y - app_data[2]) // self.cell_size - self.camera_position = self.initial_camera_position + Coordinate(delta_x, delta_y) - - if dpg.does_item_exist("grid_group"): - self.render_visible_objects() - - def move_camera_slow(self, dx, dy): - current_time = time.time() - if current_time - self.last_move_time > self.movement_speed: - self.camera_position += Coordinate(dx, dy) - self.render_visible_objects() - self.last_move_time = current_time - - def key_down_callback(self, sender, app_data): - self.active_keys.add(app_data) - self.process_movement() - - def key_up_callback(self, sender, app_data): - self.active_keys.discard(app_data) - - def process_movement(self): - dx = dy = 0 - if dpg.mvKey_W in self.active_keys: - dy -= 1 - if dpg.mvKey_S in self.active_keys: - dy += 1 - if dpg.mvKey_A in self.active_keys: - dx -= 1 - if dpg.mvKey_D in self.active_keys: - dx += 1 - - if dx != 0 or dy != 0: - self.move_camera_slow(dx, dy) - - def on_mouse_release(self, sender, app_data): - self.is_dragging = False diff --git a/Code/gui/settings.py b/Code/gui/settings.py deleted file mode 100644 index d198b6e..0000000 --- a/Code/gui/settings.py +++ /dev/null @@ -1,11 +0,0 @@ -import dearpygui.dearpygui as dpg - - -class SettingsManager: - def create_settings_window(self): - if dpg.does_item_exist("settings_window"): - dpg.focus_item("settings_window") - return - - with dpg.window(label="Settings", tag="settings_window") as settings_window: - dpg.add_text("Настройки DM Bot client") diff --git a/Code/gui/start.py b/Code/gui/start.py new file mode 100644 index 0000000..89f4642 --- /dev/null +++ b/Code/gui/start.py @@ -0,0 +1,85 @@ +from pathlib import Path + +import dearpygui.dearpygui as dpg +from dearpygui_async import DearPyGuiAsync +from DMBotNetwork import Client +from misc import decode_string +from root_path import ROOT_PATH +from systems.loc import Localization as loc +from .fonts_setup import FontManager + + +class DMClientApp: + def __init__(self): + self.dpg_async = DearPyGuiAsync() + + def setup(self): + dpg.create_context() + FontManager.load_fonts() + dpg.create_viewport(title=loc.get_string("main-app-name"), width=600, min_width=600, height=400, min_height=400) + dpg.setup_dearpygui() + self._create_warning_window() + + def _create_warning_window(self): + with dpg.window(label="Warning", tag="warning_window", no_move=True, no_close=True, no_collapse=True, width=380, no_resize=True): + dpg.add_text(loc.get_string("main_text_warning_window"), wrap=380) + dpg.add_button(label=loc.get_string("yes_warning_window"), callback=self._on_yes) + dpg.add_button(label=loc.get_string("no_warning_window"), callback=self._on_no) + + def _on_yes(self, *args): + dpg.delete_item("warning_window") + self._create_connect_window() + + def _on_no(self, *args): + self.stop() + + def _create_connect_window(self): + if dpg.does_item_exist("connect_window"): + dpg.focus_item("connect_window") + return + + with dpg.window(label="Connect", tag="connect_window", no_close=True, no_collapse=True, no_move=True, width=380): + dpg.add_text(loc.get_string("connect_main_text")) + + dpg.add_input_text(hint=loc.get_string("connect_login_hint") , tag="connect_login") + dpg.add_input_text(hint=loc.get_string("connect_password_hint"), tag="connect_password", password=True) + dpg.add_input_text(hint=loc.get_string("connect_host_hint") , tag="connect_host") + dpg.add_input_int (label=loc.get_string("connect_port_lable") , tag="connect_port") + dpg.add_button(label=loc.get_string("connect_button"), callback=self._run_client) + + async def _run_client(self, *args): + await Client.close_connection() + + login_value = decode_string(dpg.get_value("connect_login")) + password_value = decode_string(dpg.get_value("connect_password")) + host_value = decode_string(dpg.get_value("connect_host")) + port_value = dpg.get_value("connect_port") + + Client.set_login(login_value) + Client.set_password(password_value) + Client.set_host(host_value) + Client.set_port(port_value) + + server_path = Path(ROOT_PATH) / "Content" / "Servers" + Client.set_server_file_path(server_path) + + await Client.connect() + + if Client._listen_task is None: # FIXME: Так делать нельзя, но проверить законектились ли мы иначе на текущий момент невозможно. Cain. DM-Bot-net v 0.0.12 + with dpg.window(no_title_bar=True, modal=True, width=380) as con_err: + dpg.add_text(loc.get_string("on_connect_error_msg"), wrap=380) + + dpg.add_button(label=loc.get_string("ok"), callback=lambda: dpg.delete_item(con_err)) + + else: + dpg.delete_item("connect_window") + # TODO: Запрос других окон с сервера. + + def run(self): + dpg.show_viewport() + self.dpg_async.run() + dpg.start_dearpygui() + dpg.destroy_context() + + def stop(self): + dpg.stop_dearpygui() diff --git a/Code/main.py b/Code/main.py index 964dac9..7e67b8c 100644 --- a/Code/main.py +++ b/Code/main.py @@ -2,7 +2,7 @@ from api import * from DMBotNetwork import Client -from gui.main_app import DMClientApp +from gui.start import DMClientApp from root_path import ROOT_PATH from systems.loc import Localization as loc diff --git a/Content/Client/loc/rus/connect_window.loc b/Content/Client/loc/rus/connect_window.loc deleted file mode 100644 index 024b034..0000000 --- a/Content/Client/loc/rus/connect_window.loc +++ /dev/null @@ -1,6 +0,0 @@ -connect_main_text = Соединение с сервером -connect_login_hint = Логин -connect_password_hint = Пароль -connect_host_hint = IP -connect_port_lable = Порт -connect_button = Соединиться diff --git a/Content/Client/loc/rus/main_app.loc b/Content/Client/loc/rus/main_app.loc deleted file mode 100644 index 9e4b4f7..0000000 --- a/Content/Client/loc/rus/main_app.loc +++ /dev/null @@ -1,5 +0,0 @@ -main-app-name = DM-Bot Client - -main_text_warning_window = Внимание! Использование DM-Bot разрешено только для пользователей, достигших 18-летнего возраста. -yes_warning_window = Мне 18 или более лет -no_warning_window = Мне нет 18 лет diff --git a/Content/Client/loc/rus/standarts.loc b/Content/Client/loc/rus/standarts.loc new file mode 100644 index 0000000..6bc8330 --- /dev/null +++ b/Content/Client/loc/rus/standarts.loc @@ -0,0 +1,3 @@ +ok = ОК +yes = Да +no = Нет diff --git a/Content/Client/loc/rus/start_app.loc b/Content/Client/loc/rus/start_app.loc new file mode 100644 index 0000000..2885e0b --- /dev/null +++ b/Content/Client/loc/rus/start_app.loc @@ -0,0 +1,14 @@ +main-app-name = DM-Bot Client + +main_text_warning_window = Внимание! Использование DM-Bot разрешено только для пользователей, достигших 18-летнего возраста. +yes_warning_window = Мне 18 или более лет +no_warning_window = Мне нет 18 лет + +connect_main_text = Соединение с сервером +connect_login_hint = Логин +connect_password_hint = Пароль +connect_host_hint = IP +connect_port_lable = Порт +connect_button = Соединиться + +on_connect_error_msg = Ошибка при подключении к серверу. Проверьте пароль/логин или адресс подключении