109 lines
4.6 KiB
Python
109 lines
4.6 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import tkinter as tk
|
||
|
|
from tkinter import ttk
|
||
|
|
from resources.code_res.game_constants import (
|
||
|
|
ACCENT_GOLD, ACCENT_GOTH, BG_COLOR, BORDER_COLOR, FG_COLOR, INPUT_BG, MUTED_FG, SUBTLE_BORDER
|
||
|
|
)
|
||
|
|
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=40, pady=32,
|
||
|
|
highlightthickness=1, highlightbackground=SUBTLE_BORDER
|
||
|
|
)
|
||
|
|
main_frame.place(relx=0.5, rely=0.5, anchor="center")
|
||
|
|
|
||
|
|
# Titeltext direkt AUF die violette title1.png Plakette setzen
|
||
|
|
title_photo = self.assets.get_scaled_photo("title_login", self.assets.raw_title, (420, 96))
|
||
|
|
if title_photo:
|
||
|
|
title_lbl = tk.Label(
|
||
|
|
main_frame,
|
||
|
|
image=title_photo,
|
||
|
|
text="GOTH CARD\nCOLLECTION",
|
||
|
|
compound="center",
|
||
|
|
font=("Georgia", 18, "bold"),
|
||
|
|
fg=ACCENT_GOLD,
|
||
|
|
bg=BG_COLOR,
|
||
|
|
bd=0,
|
||
|
|
)
|
||
|
|
title_lbl.image = title_photo
|
||
|
|
title_lbl.pack(pady=(0, 20))
|
||
|
|
else:
|
||
|
|
tk.Label(
|
||
|
|
main_frame, text=t("app_title").upper(),
|
||
|
|
font=("Georgia", 22, "bold"), fg=ACCENT_GOTH, bg=BG_COLOR
|
||
|
|
).pack(pady=(0, 20))
|
||
|
|
|
||
|
|
if profiles:
|
||
|
|
tk.Label(
|
||
|
|
main_frame, text=t("login_select_lbl"),
|
||
|
|
font=("Helvetica", 10), fg=MUTED_FG, bg=BG_COLOR
|
||
|
|
).pack(anchor="w", padx=10)
|
||
|
|
|
||
|
|
frame = tk.Frame(main_frame, bg=BG_COLOR)
|
||
|
|
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(main_frame, bg=SUBTLE_BORDER, height=1).pack(fill="x", padx=10, pady=14)
|
||
|
|
|
||
|
|
tk.Label(
|
||
|
|
main_frame, text=t("login_create_lbl"),
|
||
|
|
font=("Helvetica", 10), fg=MUTED_FG, bg=BG_COLOR
|
||
|
|
).pack(anchor="w", padx=10)
|
||
|
|
|
||
|
|
new_frame = tk.Frame(main_frame, bg=BG_COLOR)
|
||
|
|
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)
|