449 lines
23 KiB
Python
449 lines
23 KiB
Python
# -*- coding: utf-8 -*-
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
import models.i18n as i18n
|
||
from models.i18n import t
|
||
from models.database import Database
|
||
from views.theme import create_img_button, BG_COLOR, FG_COLOR, ACCENT_ORANGE
|
||
from views.resizing_bg import ResizingBG
|
||
|
||
class MultiplayerViews:
|
||
"""Verwaltet alle Menüs für Server-Login, Echtzeit-Raumtabelle und Raum-Warteschlange."""
|
||
|
||
def __init__(self, root_view):
|
||
self.root = root_view
|
||
self.ctrl = root_view.ctrl
|
||
self.assets = root_view.assets
|
||
|
||
self.current_screen = None # "connect", "auth", "browser", "waiting"
|
||
self.all_rooms = [] # Ungefilterte Raumliste vom Server
|
||
self.search_var = None
|
||
self.room_tree = None
|
||
self.waiting_room_data = None
|
||
|
||
def _txt(self, de_str: str, en_str: str) -> str:
|
||
return de_str if i18n.CURRENT_LANG == "DE" else en_str
|
||
|
||
# ------------------------------------------------------------------
|
||
# 1. VERBINDUNG & SERVER-PASSWORT
|
||
# ------------------------------------------------------------------
|
||
def show_connect_screen(self):
|
||
self.current_screen = "connect"
|
||
self.root.clear_window(apply_global_bg=True)
|
||
|
||
box = tk.Frame(self.root, bg=BG_COLOR, highlightbackground=ACCENT_ORANGE, highlightthickness=2, padx=30, pady=25)
|
||
box.place(relx=0.5, rely=0.5, anchor="center", width=480, height=420)
|
||
|
||
tk.Label(
|
||
box, text=self._txt("MIT SERVER VERBINDEN", "CONNECT TO SERVER"),
|
||
font=("Helvetica", 18, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE
|
||
).pack(pady=(0, 18))
|
||
|
||
saved_ip = Database.load_setting("mp_last_ip", "127.0.0.1")
|
||
saved_port = Database.load_setting("mp_last_port", "5555")
|
||
|
||
form = tk.Frame(box, bg=BG_COLOR)
|
||
form.pack(fill="x", pady=5)
|
||
|
||
tk.Label(form, text=self._txt("Server-IP / Host:", "Server IP / Host:"), font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w").pack(fill="x")
|
||
ip_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
ip_entry.insert(0, saved_ip)
|
||
ip_entry.pack(fill="x", pady=(2, 10), ipady=4)
|
||
|
||
tk.Label(form, text=self._txt("Server-Port:", "Server Port:"), font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w").pack(fill="x")
|
||
port_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
port_entry.insert(0, saved_port)
|
||
port_entry.pack(fill="x", pady=(2, 10), ipady=4)
|
||
|
||
tk.Label(form, text=self._txt("Server-Passwort:", "Server Password:"), font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w").pack(fill="x")
|
||
pw_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, show="*", bd=1, relief="solid")
|
||
pw_entry.pack(fill="x", pady=(2, 16), ipady=4)
|
||
|
||
def do_connect(event=None):
|
||
ip_val = ip_entry.get().strip()
|
||
port_val = port_entry.get().strip()
|
||
srv_pw = pw_entry.get().strip()
|
||
if not port_val.isdigit():
|
||
self.root.show_error(t("err_title"), self._txt("Ungültiger Port!", "Invalid port!"))
|
||
return
|
||
Database.save_setting("mp_last_ip", ip_val)
|
||
Database.save_setting("mp_last_port", port_val)
|
||
self.ctrl.mp_connect_and_verify(ip_val, int(port_val), srv_pw)
|
||
|
||
pw_entry.bind("<Return>", do_connect)
|
||
|
||
btn_row = tk.Frame(box, bg=BG_COLOR)
|
||
btn_row.pack(side="bottom", pady=(10, 0))
|
||
create_img_button(btn_row, self._txt("Verbinden", "Connect"), self.assets.btn_orange, self.assets.btn_orange_active, do_connect, min_px_width=170).pack(side="left", padx=8)
|
||
create_img_button(btn_row, t("back_btn"), self.assets.sel_inactive, self.assets.sel_active, self.ctrl.mp_disconnect_to_menu, min_px_width=150).pack(side="left", padx=8)
|
||
|
||
# ------------------------------------------------------------------
|
||
# 2. SPIELER-ACCOUNT LOGIN / REGISTRIERUNG (OHNE DROPDOWN)
|
||
# ------------------------------------------------------------------
|
||
def show_account_auth_screen(self, server_name: str):
|
||
self.current_screen = "auth"
|
||
self.root.clear_window(apply_global_bg=True)
|
||
|
||
box = tk.Frame(self.root, bg=BG_COLOR, highlightbackground=ACCENT_ORANGE, highlightthickness=2, padx=30, pady=25)
|
||
box.place(relx=0.5, rely=0.5, anchor="center", width=500, height=440)
|
||
|
||
tk.Label(
|
||
box, text=server_name.upper(),
|
||
font=("Helvetica", 17, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE
|
||
).pack(pady=(0, 4))
|
||
|
||
tk.Label(
|
||
box, text=self._txt("Spieler-Authentifizierung", "Player Authentication"),
|
||
font=("Helvetica", 11), bg=BG_COLOR, fg="#AAA"
|
||
).pack(pady=(0, 14))
|
||
|
||
mode_var = tk.StringVar(value="LOGIN")
|
||
|
||
# Umschalter: Bestehender Account vs. Neuer Account
|
||
toggle_frame = tk.Frame(box, bg=BG_COLOR)
|
||
toggle_frame.pack(fill="x", pady=(0, 14))
|
||
|
||
rb_style = {
|
||
"bg": BG_COLOR, "fg": FG_COLOR, "selectcolor": "#2A2438",
|
||
"activebackground": BG_COLOR, "activeforeground": ACCENT_ORANGE,
|
||
"font": ("Helvetica", 11, "bold")
|
||
}
|
||
tk.Radiobutton(
|
||
toggle_frame, text=self._txt("Bestehender Account (Login)", "Existing Account (Login)"),
|
||
variable=mode_var, value="LOGIN", **rb_style
|
||
).pack(anchor="w", pady=2)
|
||
tk.Radiobutton(
|
||
toggle_frame, text=self._txt("Neuen Account anlegen", "Create New Account"),
|
||
variable=mode_var, value="REGISTER", **rb_style
|
||
).pack(anchor="w", pady=2)
|
||
|
||
form = tk.Frame(box, bg=BG_COLOR)
|
||
form.pack(fill="x", pady=4)
|
||
|
||
tk.Label(
|
||
form, text=self._txt("Spielername (2-20 Zeichen):", "Player Name (2-20 chars):"),
|
||
font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w"
|
||
).pack(fill="x")
|
||
user_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
if self.ctrl.active_profile:
|
||
user_entry.insert(0, self.ctrl.active_profile.get("name", ""))
|
||
user_entry.pack(fill="x", pady=(2, 12), ipady=4)
|
||
|
||
tk.Label(
|
||
form, text=self._txt("Account-Passwort (mind. 4 Zeichen):", "Account Password (min. 4 chars):"),
|
||
font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w"
|
||
).pack(fill="x")
|
||
pw_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, show="*", bd=1, relief="solid")
|
||
pw_entry.pack(fill="x", pady=(2, 14), ipady=4)
|
||
|
||
def submit_auth(event=None):
|
||
uname = user_entry.get().strip()
|
||
upw = pw_entry.get()
|
||
is_reg = (mode_var.get() == "REGISTER")
|
||
self.ctrl.mp_submit_account_auth(uname, upw, is_register=is_reg)
|
||
|
||
pw_entry.bind("<Return>", submit_auth)
|
||
|
||
btn_row = tk.Frame(box, bg=BG_COLOR)
|
||
btn_row.pack(side="bottom", pady=(10, 0))
|
||
create_img_button(btn_row, self._txt("Fortfahren", "Continue"), self.assets.btn_orange, self.assets.btn_orange_active, submit_auth, min_px_width=170).pack(side="left", padx=8)
|
||
create_img_button(btn_row, self._txt("Trennen", "Disconnect"), self.assets.sel_inactive, self.assets.sel_active, self.ctrl.mp_disconnect_to_menu, min_px_width=150).pack(side="left", padx=8)
|
||
|
||
# ------------------------------------------------------------------
|
||
# 3. ECHTZEIT-RAUMTABELLE (Name | Spieler | Passwort) + SUCHE
|
||
# ------------------------------------------------------------------
|
||
def show_room_browser(self, rooms_list=None):
|
||
self.current_screen = "browser"
|
||
if rooms_list is not None:
|
||
self.all_rooms = rooms_list
|
||
|
||
self.root.clear_window(apply_global_bg=True)
|
||
|
||
container = tk.Frame(self.root, bg=BG_COLOR, highlightbackground=ACCENT_ORANGE, highlightthickness=2, padx=24, pady=20)
|
||
container.place(relx=0.5, rely=0.5, anchor="center", width=720, height=520)
|
||
|
||
# Header
|
||
header_row = tk.Frame(container, bg=BG_COLOR)
|
||
header_row.pack(fill="x", pady=(0, 12))
|
||
|
||
srv_title = f"{self.ctrl.mp_server_name} – {self.ctrl.mp_account_name}"
|
||
tk.Label(header_row, text=srv_title, font=("Helvetica", 16, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE).pack(side="left")
|
||
|
||
# Suchleiste (Echtzeit-Filter)
|
||
search_frame = tk.Frame(container, bg=BG_COLOR)
|
||
search_frame.pack(fill="x", pady=(0, 10))
|
||
tk.Label(search_frame, text=self._txt("Raum suchen:", "Search Room:"), font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR).pack(side="left", padx=(0, 8))
|
||
|
||
self.search_var = tk.StringVar()
|
||
self.search_var.trace_add("write", lambda *args: self._refresh_room_tree())
|
||
search_entry = tk.Entry(search_frame, textvariable=self.search_var, font=("Helvetica", 11), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
search_entry.pack(side="left", fill="x", expand=True, ipady=3)
|
||
|
||
# Treeview-Styling im Goth-Design
|
||
style = ttk.Style()
|
||
style.theme_use("clam")
|
||
style.configure(
|
||
"Goth.Treeview",
|
||
background="#16141F",
|
||
foreground=FG_COLOR,
|
||
fieldbackground="#16141F",
|
||
rowheight=32,
|
||
font=("Helvetica", 11),
|
||
borderwidth=0
|
||
)
|
||
style.configure(
|
||
"Goth.Treeview.Heading",
|
||
background="#262135",
|
||
foreground=ACCENT_ORANGE,
|
||
font=("Helvetica", 11, "bold"),
|
||
relief="flat"
|
||
)
|
||
style.map("Goth.Treeview", background=[("selected", "#3D2B56")], foreground=[("selected", "#FFFFFF")])
|
||
|
||
table_frame = tk.Frame(container, bg="#16141F", highlightbackground="#38304C", highlightthickness=1)
|
||
table_frame.pack(fill="both", expand=True, pady=6)
|
||
|
||
scrollbar = tk.Scrollbar(table_frame)
|
||
scrollbar.pack(side="right", fill="y")
|
||
|
||
cols = ("name", "players", "password")
|
||
self.room_tree = ttk.Treeview(
|
||
table_frame, columns=cols, show="headings",
|
||
style="Goth.Treeview", selectmode="browse", yscrollcommand=scrollbar.set
|
||
)
|
||
self.room_tree.heading("name", text=self._txt("Name", "Name"))
|
||
self.room_tree.heading("players", text=self._txt("Spieler", "Players"))
|
||
self.room_tree.heading("password", text=self._txt("Passwort", "Password"))
|
||
|
||
self.room_tree.column("name", width=360, anchor="w")
|
||
self.room_tree.column("players", width=130, anchor="center")
|
||
self.room_tree.column("password", width=150, anchor="center")
|
||
|
||
self.room_tree.pack(side="left", fill="both", expand=True)
|
||
scrollbar.config(command=self.room_tree.yview)
|
||
|
||
self.room_tree.bind("<Double-1>", lambda e: self._on_join_selected())
|
||
|
||
# Aktions-Buttons unten
|
||
btn_bar = tk.Frame(container, bg=BG_COLOR)
|
||
btn_bar.pack(fill="x", pady=(12, 0))
|
||
|
||
create_img_button(btn_bar, self._txt("+ Raum erstellen", "+ Create Room"), self.assets.btn_orange, self.assets.btn_orange_active, self.show_create_room_modal, min_px_width=175).pack(side="left", padx=5)
|
||
create_img_button(btn_bar, self._txt("Raum beitreten", "Join Room"), self.assets.sel_inactive, self.assets.sel_active, self._on_join_selected, min_px_width=165).pack(side="left", padx=5)
|
||
create_img_button(btn_bar, self._txt("Trennen", "Disconnect"), self.assets.sel_inactive, self.assets.sel_active, self.ctrl.mp_disconnect_to_menu, min_px_width=140).pack(side="right", padx=5)
|
||
|
||
self._refresh_room_tree()
|
||
|
||
def update_room_list_live(self, rooms_list: list):
|
||
"""Wird in Echtzeit aufgerufen, sobald der Server ROOM_LIST_UPDATE sendet."""
|
||
self.all_rooms = rooms_list
|
||
if self.current_screen == "browser":
|
||
self._refresh_room_tree()
|
||
|
||
def _refresh_room_tree(self):
|
||
if not self.room_tree or not self.room_tree.winfo_exists():
|
||
return
|
||
|
||
selected_id = self.room_tree.selection()[0] if self.room_tree.selection() else None
|
||
for item in self.room_tree.get_children():
|
||
self.room_tree.delete(item)
|
||
|
||
query = self.search_var.get().strip().lower() if self.search_var else ""
|
||
free_label = self._txt("Frei", "Free")
|
||
|
||
for r in self.all_rooms:
|
||
r_name = r.get("name", "")
|
||
if query and query not in r_name.lower():
|
||
continue
|
||
r_id = r.get("room_id", "")
|
||
p_str = r.get("players_str", "1/4")
|
||
pw_str = "⚿ PIN" if r.get("locked") else free_label
|
||
self.room_tree.insert("", "end", iid=r_id, values=(r_name, p_str, pw_str))
|
||
|
||
if selected_id and self.room_tree.exists(selected_id):
|
||
self.room_tree.selection_set(selected_id)
|
||
|
||
def _on_join_selected(self):
|
||
if not self.room_tree or not self.room_tree.selection():
|
||
self.root.show_info(t("err_title"), self._txt("Bitte wähle zuerst einen Raum aus der Liste!", "Please select a room from the list first!"))
|
||
return
|
||
|
||
room_id = self.room_tree.selection()[0]
|
||
room_obj = next((r for r in self.all_rooms if r.get("room_id") == room_id), None)
|
||
if not room_obj:
|
||
return
|
||
|
||
if room_obj.get("locked"):
|
||
self._ask_room_pin_modal(room_id, room_obj.get("name", ""))
|
||
else:
|
||
self.ctrl.mp_join_room(room_id, "")
|
||
|
||
def show_create_room_modal(self):
|
||
top = self.root.dialogs._create_styled_modal(self._txt("Raum erstellen", "Create Room"), 460, 320)
|
||
tk.Label(top, text=self._txt("NEUEN RAUM ERSTELLEN", "CREATE NEW ROOM"), font=("Helvetica", 15, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE).pack(pady=(18, 12))
|
||
|
||
form = tk.Frame(top, bg=BG_COLOR, padx=28)
|
||
form.pack(fill="x", expand=True)
|
||
|
||
tk.Label(form, text=self._txt("Raumname (max. 24 Zeichen):", "Room Name (max. 24 chars):"), font=("Helvetica", 11, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w").pack(fill="x")
|
||
name_var = tk.StringVar()
|
||
# Hartes Limit auf 24 Zeichen beim Tippen
|
||
def limit_len(*args):
|
||
val = name_var.get()
|
||
if len(val) > 24:
|
||
name_var.set(val[:24])
|
||
name_var.trace_add("write", limit_len)
|
||
|
||
name_entry = tk.Entry(form, textvariable=name_var, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
name_entry.pack(fill="x", pady=(2, 12), ipady=4)
|
||
name_entry.focus_set()
|
||
|
||
tk.Label(form, text=self._txt("Passwort (optional, genau 4 Ziffern oder leer = Frei):", "Password (optional, 4 digits or empty = Free):"), font=("Helvetica", 10, "bold"), bg=BG_COLOR, fg=FG_COLOR, anchor="w").pack(fill="x")
|
||
pin_entry = tk.Entry(form, font=("Helvetica", 12), bg="#1E1B2E", fg=FG_COLOR, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
pin_entry.pack(fill="x", pady=(2, 12), ipady=4)
|
||
|
||
def create_now(event=None):
|
||
r_name = name_var.get().strip()
|
||
r_pin = pin_entry.get().strip()
|
||
if not r_name:
|
||
self.root.show_error(t("err_title"), self._txt("Bitte gib einen Raumnamen ein!", "Please enter a room name!"))
|
||
return
|
||
if r_pin != "" and not (r_pin.isdigit() and len(r_pin) == 4):
|
||
self.root.show_error(t("err_title"), self._txt("Das Raum-Passwort muss leer (Frei) oder eine 4-stellige Zahl (z.B. 1234) sein!", "Room PIN must be empty (Free) or a 4-digit number (e.g. 1234)!"))
|
||
return
|
||
top.destroy()
|
||
self.ctrl.mp_create_room(r_name, r_pin)
|
||
|
||
pin_entry.bind("<Return>", create_now)
|
||
|
||
btn_frame = tk.Frame(top, bg=BG_COLOR)
|
||
btn_frame.pack(side="bottom", pady=(6, 18))
|
||
create_img_button(btn_frame, self._txt("Erstellen", "Create"), self.assets.btn_orange, self.assets.btn_orange_active, create_now, min_px_width=155).pack(side="left", padx=8)
|
||
create_img_button(btn_frame, t("cancel_btn"), self.assets.sel_inactive, self.assets.sel_active, top.destroy, min_px_width=145).pack(side="left", padx=8)
|
||
|
||
def _ask_room_pin_modal(self, room_id: str, room_name: str):
|
||
top = self.root.dialogs._create_styled_modal(self._txt("Passwort erforderlich", "PIN Required"), 420, 250)
|
||
tk.Label(top, text=f"⚿ {room_name}", font=("Helvetica", 15, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE).pack(pady=(18, 6))
|
||
tk.Label(top, text=self._txt("Bitte 4-stelligen Raum-PIN eingeben:", "Please enter 4-digit room PIN:"), font=("Helvetica", 11), bg=BG_COLOR, fg=FG_COLOR).pack(pady=4)
|
||
|
||
pin_entry = tk.Entry(top, font=("Courier", 16, "bold"), justify="center", width=10, bg="#1E1B2E", fg=ACCENT_ORANGE, insertbackground=FG_COLOR, bd=1, relief="solid")
|
||
pin_entry.pack(pady=10, ipady=4)
|
||
pin_entry.focus_set()
|
||
|
||
def submit_pin(event=None):
|
||
pin_val = pin_entry.get().strip()
|
||
top.destroy()
|
||
self.ctrl.mp_join_room(room_id, pin_val)
|
||
|
||
pin_entry.bind("<Return>", submit_pin)
|
||
|
||
btn_frame = tk.Frame(top, bg=BG_COLOR)
|
||
btn_frame.pack(side="bottom", pady=(6, 18))
|
||
create_img_button(btn_frame, self._txt("Beitreten", "Join"), self.assets.btn_orange, self.assets.btn_orange_active, submit_pin, min_px_width=145).pack(side="left", padx=8)
|
||
create_img_button(btn_frame, t("cancel_btn"), self.assets.sel_inactive, self.assets.sel_active, top.destroy, min_px_width=145).pack(side="left", padx=8)
|
||
|
||
# ------------------------------------------------------------------
|
||
# 4. RAUM-WARTESCHLANGE (HOST KANN STARTEN / BOTS AUFFÜLLEN)
|
||
# ------------------------------------------------------------------
|
||
def show_waiting_room(self, room_data: dict):
|
||
self.current_screen = "waiting"
|
||
self.waiting_room_data = room_data
|
||
self.root.clear_window(apply_global_bg=True)
|
||
|
||
is_host = (room_data.get("host_name") == self.ctrl.mp_account_name)
|
||
max_p = room_data.get("max_players", 4)
|
||
queue_slots = room_data.get("queue", [])
|
||
|
||
box = tk.Frame(self.root, bg=BG_COLOR, highlightbackground=ACCENT_ORANGE, highlightthickness=2, padx=28, pady=22)
|
||
box.place(relx=0.5, rely=0.5, anchor="center", width=560, height=490)
|
||
|
||
lock_badge = " [⚿ PIN]" if room_data.get("locked") else ""
|
||
tk.Label(
|
||
box, text=f"{room_data.get('name', '')}{lock_badge}",
|
||
font=("Helvetica", 18, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE
|
||
).pack(pady=(0, 4))
|
||
|
||
sub_info = self._txt(
|
||
f"Warteschlange ({room_data.get('players_str', '1/4')})",
|
||
f"Room Queue ({room_data.get('players_str', '1/4')})"
|
||
)
|
||
tk.Label(box, text=sub_info, font=("Helvetica", 12, "bold"), bg=BG_COLOR, fg="#AAA").pack(pady=(0, 14))
|
||
|
||
# 4 Spieler-Slots darstellen
|
||
slots_frame = tk.Frame(box, bg=BG_COLOR)
|
||
slots_frame.pack(fill="x", pady=4)
|
||
|
||
for idx in range(max_p):
|
||
slot_row = tk.Frame(slots_frame, bg="#181522", highlightbackground="#38304C", highlightthickness=1, padx=14, pady=8)
|
||
slot_row.pack(fill="x", pady=4)
|
||
|
||
if idx < len(queue_slots):
|
||
member = queue_slots[idx]
|
||
disp = member.get("display_name", member.get("name", ""))
|
||
if member.get("is_host"):
|
||
disp += self._txt(" ♛ [Spielleiter]", " ♛ [Host]")
|
||
col = ACCENT_ORANGE if member.get("is_host") else ("#00E676" if not member.get("is_bot") else "#FF99AA")
|
||
tk.Label(slot_row, text=f"{idx + 1}. {disp}", font=("Helvetica", 12, "bold"), bg="#181522", fg=col, anchor="w").pack(fill="x")
|
||
else:
|
||
empty_txt = self._txt("Warte auf Spieler...", "Waiting for player...")
|
||
tk.Label(slot_row, text=f"{idx + 1}. [ {empty_txt} ]", font=("Helvetica", 11, "italic"), bg="#181522", fg="#666", anchor="w").pack(fill="x")
|
||
|
||
# Falls Host: Bot-Steuerung & Vorzeitiger Spielstart
|
||
if is_host:
|
||
if self.ctrl.mp_server_allows_bots:
|
||
bot_ctrl_frame = tk.Frame(box, bg=BG_COLOR)
|
||
bot_ctrl_frame.pack(fill="x", pady=(12, 4))
|
||
|
||
tk.Label(bot_ctrl_frame, text=self._txt("Bot-Stufe:", "Bot Level:"), font=("Helvetica", 10, "bold"), bg=BG_COLOR, fg=FG_COLOR).pack(side="left", padx=(0, 6))
|
||
lvl_var = tk.StringVar(value="Medium")
|
||
lvl_menu = ttk.Combobox(bot_ctrl_frame, textvariable=lvl_var, values=["Easy", "Medium", "Hard", "Grandmaster"], state="readonly", width=12)
|
||
lvl_menu.pack(side="left", padx=(0, 10))
|
||
|
||
create_img_button(
|
||
bot_ctrl_frame, self._txt("+ Bot", "+ Bot"),
|
||
self.assets.sel_inactive, self.assets.sel_active,
|
||
lambda: self.ctrl.mp_add_bot(lvl_var.get()), min_px_width=105
|
||
).pack(side="left", padx=4)
|
||
|
||
create_img_button(
|
||
bot_ctrl_frame, self._txt("- Bot", "- Bot"),
|
||
self.assets.sel_inactive, self.assets.sel_active,
|
||
self.ctrl.mp_remove_bot, min_px_width=105
|
||
).pack(side="left", padx=4)
|
||
|
||
btn_bottom = tk.Frame(box, bg=BG_COLOR)
|
||
btn_bottom.pack(side="bottom", pady=(10, 0))
|
||
|
||
can_start = room_data.get("can_start", False)
|
||
if can_start:
|
||
create_img_button(
|
||
btn_bottom, self._txt("Spiel starten!", "Start Game!"),
|
||
self.assets.btn_orange, self.assets.btn_orange_active,
|
||
self.ctrl.mp_start_game, min_px_width=185
|
||
).pack(side="left", padx=8)
|
||
else:
|
||
tk.Label(
|
||
btn_bottom, text=self._txt("Mind. 2 Teilnehmer zum Starten nötig", "Need at least 2 participants to start"),
|
||
font=("Helvetica", 10, "bold"), bg=BG_COLOR, fg="#888"
|
||
).pack(side="left", padx=12)
|
||
|
||
create_img_button(
|
||
btn_bottom, self._txt("Raum verlassen", "Leave Room"),
|
||
self.assets.sel_inactive, self.assets.sel_active,
|
||
self.ctrl.mp_leave_room, min_px_width=165
|
||
).pack(side="left", padx=8)
|
||
else:
|
||
# Normale Mitspieler stellen nichts ein -> warten auf Host oder 4/4 Auto-Start
|
||
wait_lbl = self._txt(
|
||
f"Warte auf Spielleiter {room_data.get('host_name', '')}...",
|
||
f"Waiting for host {room_data.get('host_name', '')}..."
|
||
)
|
||
tk.Label(box, text=wait_lbl, font=("Helvetica", 12, "bold"), bg=BG_COLOR, fg=ACCENT_ORANGE).pack(pady=(18, 6))
|
||
|
||
btn_bottom = tk.Frame(box, bg=BG_COLOR)
|
||
btn_bottom.pack(side="bottom", pady=(10, 0))
|
||
create_img_button(
|
||
btn_bottom, self._txt("Raum verlassen", "Leave Room"),
|
||
self.assets.sel_inactive, self.assets.sel_active,
|
||
self.ctrl.mp_leave_room, min_px_width=180
|
||
).pack() |