the_goth_cardgame_collection/view/menus/login_view.py

111 lines
4.6 KiB
Python
Raw Normal View History

2026-11-14 04:25:51 +00:00
# -*- coding: utf-8 -*-
# view/menus/login_view.py
2026-11-14 04:25:51 +00:00
import tkinter as tk
from tkinter import ttk
from resources.code_res.game_constants import (
ACCENT_GOTH, BG_COLOR, BORDER_COLOR, FG_COLOR, INPUT_BG, MUTED_FG, SUBTLE_BORDER
2026-11-14 04:25:51 +00:00
)
from resources.code_res.i18n import t
from view.dialogs.audio_settings_dialog import AudioSettingsDialog
from view.widgets.image_button import ImageButton
class LoginView:
def __init__(self, root_view):
self.root = root_view
self.ctrl = root_view.ctrl
self.assets = root_view.assets
self.sounds = root_view.ctrl.sounds
self.profile_var = None
self.new_name_var = None
def show(self, profiles: list[str], preselect_name: str = ""):
self.root.clear_window(apply_global_bg=True)
# Weiter eingerückt, damit die Spinnennetze in der Ecke frei bleiben
top_controls = tk.Frame(self.root, bg=BG_COLOR)
top_controls.place(relx=0.93, rely=0.07, anchor="ne")
ImageButton(
top_controls, t("btn_lang"), self.assets.raw_sel, self.assets.raw_sel_active,
lambda: self.ctrl.toggle_language(), sound_mgr=self.sounds, width=115, height=36, font=("Helvetica", 10, "bold")
).pack(side="left", padx=(0, 8))
ImageButton(
top_controls, t("btn_audio"), self.assets.raw_sel, self.assets.raw_sel_active,
lambda: AudioSettingsDialog.open(self.root, self.assets, self.sounds),
sound_mgr=self.sounds, width=105, height=36, font=("Helvetica", 10, "bold")
).pack(side="left")
main_frame = tk.Frame(
self.root, bg=BG_COLOR, padx=36, pady=28,
2026-11-14 04:25:51 +00:00
highlightthickness=1, highlightbackground=SUBTLE_BORDER
)
main_frame.place(relx=0.5, rely=0.5, anchor="center")
# Breites Panorama-Banner title.jpg proportional (560px breit -> ~140px hoch) ohne Text-Overlay
title_photo = self.assets.get_proportional_photo("title_login_banner", self.assets.raw_title, 560)
2026-11-14 04:25:51 +00:00
if title_photo:
title_lbl = tk.Label(
main_frame,
image=title_photo,
bg=BG_COLOR,
bd=0,
highlightthickness=1,
highlightbackground=BORDER_COLOR,
2026-11-14 04:25:51 +00:00
)
title_lbl.image = title_photo
title_lbl.pack(pady=(0, 22))
2026-11-14 04:25:51 +00:00
else:
tk.Label(
main_frame, text=t("app_title"),
font=("Georgia", 26, "bold"), fg=ACCENT_GOTH, bg=BG_COLOR
2026-11-14 04:25:51 +00:00
).pack(pady=(0, 20))
form_box = tk.Frame(main_frame, bg=BG_COLOR)
form_box.pack()
2026-11-14 04:25:51 +00:00
if profiles:
tk.Label(
form_box, text=t("login_select_lbl"),
2026-11-14 04:25:51 +00:00
font=("Helvetica", 10), fg=MUTED_FG, bg=BG_COLOR
).pack(anchor="w", padx=4)
2026-11-14 04:25:51 +00:00
frame = tk.Frame(form_box, bg=BG_COLOR)
2026-11-14 04:25:51 +00:00
frame.pack(pady=(4, 12))
initial_prof = preselect_name if preselect_name in profiles else profiles[0]
self.profile_var = tk.StringVar(value=initial_prof)
cb = ttk.Combobox(
frame, textvariable=self.profile_var, values=profiles,
state="readonly", font=("Helvetica", 12), width=19, style="Goth.TCombobox"
)
cb.grid(row=0, column=0, padx=(0, 12), ipady=3)
ImageButton(
frame, t("login_btn"), self.assets.raw_btn, self.assets.raw_btn_active,
lambda: self.ctrl.do_login(self.profile_var.get()), sound_mgr=self.sounds, width=155, height=40
).grid(row=0, column=1)
tk.Frame(form_box, bg=SUBTLE_BORDER, height=1).pack(fill="x", padx=4, pady=14)
2026-11-14 04:25:51 +00:00
tk.Label(
form_box, text=t("login_create_lbl"),
2026-11-14 04:25:51 +00:00
font=("Helvetica", 10), fg=MUTED_FG, bg=BG_COLOR
).pack(anchor="w", padx=4)
2026-11-14 04:25:51 +00:00
new_frame = tk.Frame(form_box, bg=BG_COLOR)
2026-11-14 04:25:51 +00:00
new_frame.pack(pady=(4, 4))
self.new_name_var = tk.StringVar()
entry = tk.Entry(
new_frame, textvariable=self.new_name_var, font=("Helvetica", 13),
bg=INPUT_BG, fg=FG_COLOR, bd=0, width=20,
highlightthickness=1, highlightbackground=BORDER_COLOR, insertbackground="white"
)
entry.grid(row=0, column=0, padx=(0, 12), ipady=6)
entry.bind("<Return>", lambda e: self.ctrl.do_create_profile(self.new_name_var.get().strip()))
if not profiles:
entry.focus_set()
ImageButton(
new_frame, t("new_profile_btn"), self.assets.raw_btn, self.assets.raw_btn_active,
lambda: self.ctrl.do_create_profile(self.new_name_var.get().strip()), sound_mgr=self.sounds, width=155, height=40
).grid(row=0, column=1)