Skip to content

Commit

Permalink
fuck
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Sep 28, 2024
1 parent 6b8cba7 commit 2ebe9af
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
81 changes: 45 additions & 36 deletions Code/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ChatMessageType:

def __init__(
self,
message_type: Literal["ooc", "admin", "ic"],
message_type: Literal["ooc", "admin"],
message: str,
sender: Optional[str] = None,
) -> None:
Expand All @@ -24,13 +24,14 @@ def message_type(self) -> str:
return self._message_type

@message_type.setter
def message_type(self, value: Literal["ooc", "admin", "ic"]) -> None:
def message_type(self, value: Literal["ooc", "admin"]) -> None:
self._message_type = value


class ChatClientModule:
messages: List[ChatMessageType] = []
filters = {"ooc": True, "admin": True, "ic": True}
filters = {"ooc": True, "admin": True}
current_chat_type: str = "ooc" # Текущий выбранный чат по умолчанию

@staticmethod
async def send_chat_message(chat_message_type: ChatMessageType) -> None:
Expand All @@ -46,16 +47,17 @@ async def net_get_chat_message(
message: str, message_type: str, sender: Optional[str] = None
) -> None:
"""Получает сообщение и добавляет его в чат."""
ChatClientModule.messages.append(ChatMessageType(message_type, message, sender)) # type: ignore Кладём хуй на проверку с сервера)
ChatClientModule.messages.append(ChatMessageType(message_type, message, sender)) # type: ignore
ChatClientModule.update_chat_display()

@classmethod
async def _iternal_send_message(cls, sender, app_data, user_data) -> None:
"""Асинхронная отправка сообщения через UI."""
message = dpg_tools.decode_string(dpg.get_value("chat_input"))
message_type = dpg.get_value("message_type_selector")
chat_message = ChatMessageType(message_type, message)
raw_message = dpg_tools.decode_string(dpg.get_value("chat_input"))
message_type = dpg.get_value("chat_type_selector")
chat_message = ChatMessageType(message_type, raw_message.strip()) # type: ignore
await cls.send_chat_message(chat_message)
dpg.set_value("chat_input", "")

@classmethod
def create_window(cls, sender, app_data, user_data):
Expand All @@ -70,45 +72,52 @@ def create_window(cls, sender, app_data, user_data):
width=400,
height=400,
):
with dpg.group(horizontal=True):
dpg.add_checkbox(
label="OOC",
default_value=True,
callback=cls.update_filter,
user_data="ooc",
tag="ooc_filter",
)

dpg.add_checkbox(
label="Admin",
default_value=True,
callback=cls.update_filter,
user_data="admin",
tag="admin_filter",
)

dpg.add_checkbox(
label="IC",
default_value=True,
callback=cls.update_filter,
user_data="ic",
tag="ic_filter",
)
with dpg.menu_bar():
with dpg.menu(label=loc.get_string("chat_filter")):
dpg.add_menu_item(
label="OOC",
callback=cls.update_filter,
user_data="ooc",
check=True,
default_value=True,
)
dpg.add_menu_item(
label="Admin",
callback=cls.update_filter,
user_data="admin",
check=True,
default_value=True,
)

dpg.add_child_window(
label="Chat Display", autosize_x=True, height=200, tag="chat_display"
)

with dpg.group(horizontal=True):
dpg.add_combo(
items=["ooc", "admin", "ic"],
items=["ooc", "admin"],
default_value="ooc",
tag="message_type_selector",
width=70,
tag="chat_type_selector",
width=80,
)
dpg.add_input_text(width=300, tag="chat_input")

dpg.add_button(label="Отправить", callback=cls._iternal_send_message)
dpg.add_input_text(
width=270,
tag="chat_input",
hint=loc.get_string("chat_input_hint"),
on_enter=True,
callback=cls._iternal_send_message,
)

dpg.add_key_press_handler(
parent="main_registry", callback=cls.key_press_callback
)

@classmethod
def key_press_callback(cls, sender, app_data):
"""Обрабатывает нажатие клавиш."""
if app_data == ord("T"): # TODO Сделать ебаные настройки уже
dpg.focus_item("chat_input")

@classmethod
def update_filter(cls, sender, app_data, user_data):
Expand Down
5 changes: 4 additions & 1 deletion Code/gui/dm_client_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ async def setup_start_windows(cls) -> None:
)
)
access = await Client.req_get_data("get_access", None, login=Client.get_login())

dpg.add_handler_registry(tag='main_registry')

dpg.add_viewport_menu_bar(tag="main_bar")

dpg.add_menu_item(
Expand All @@ -222,7 +225,7 @@ async def setup_start_windows(cls) -> None:
enabled=False,
)

# При всём желании, проверка прав проходит на сервере. Даже не пытайтесь.
# При всём желании, проверка прав проходит на сервере. Даже не пытайтесь якобы взломать игру.
if "full_access" in access:
await admin_menu_setup()

Expand Down
6 changes: 6 additions & 0 deletions Code/gui/windows/user/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ async def user_menu_setup():
parent="main_bar",
)

dpg.add_menu_item(
label=loc.get_string("toggle_viewport_fullscreen"),
parent="user_menu_bar",
callback=lambda: dpg.toggle_viewport_fullscreen(),
)

dpg.add_menu_item(
label=loc.get_string("chat_window_lable"),
parent="user_menu_bar",
Expand Down
3 changes: 1 addition & 2 deletions Content/Client/loc/rus/admin.loc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# For main
admin_control_menu = Админ панель


# For user managment
confirm_deletion_text = Вы уверены что хотите удалить пользователя? Это действие не обратимо
Expand Down
3 changes: 3 additions & 0 deletions Content/Client/loc/rus/chat.loc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chat_window_lable = Чат
chat_filter = Фильтр
chat_input_hint = Введите сообщение
4 changes: 4 additions & 0 deletions Content/Client/loc/rus/menu.loc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# For main
admin_control_menu = Админ панель
user_menu = Меню пользователя
toggle_viewport_fullscreen = Переключить полный экран

0 comments on commit 2ebe9af

Please sign in to comment.