diff --git a/source/gui/app.py b/source/gui/app.py index 99b6df9..488c7bd 100644 --- a/source/gui/app.py +++ b/source/gui/app.py @@ -1,3 +1,4 @@ +from cgitb import enable import tkinter as tk import os from functools import partial @@ -65,7 +66,14 @@ def __init__(self) -> None: partial( self.__switch_context, screen=self.leaderboard_screen, - funcs=(self.leaderboard_screen.refresh_scores,), + # When switching to leaderboard from welcome screen: refresh scores, disable back btn, enable main menu btn + funcs=( + self.leaderboard_screen.refresh_scores, + partial(self.leaderboard_screen.set_back_btn_state, enabled=False), + partial( + self.leaderboard_screen.set_mainmenu_btn_state, enabled=True + ), + ), ) ) @@ -77,10 +85,31 @@ def __init__(self) -> None: partial(self.__switch_context, previous=True) ) - self.gameboard_screen.set_back_cmd( - partial(self.__switch_context, previous=True) + self.gameboard_screen.set_mainmenu_cmd( + partial(self.__switch_context, screen=self.welcome_screen) ) + self.gameboard_screen.set_highscores_cmd( + partial( + self.__switch_context, + screen=self.leaderboard_screen, + # When switching to leaderboard from welcome screen: refresh scores, enable back btn, disable main menu btn + funcs=( + self.leaderboard_screen.refresh_scores, + partial(self.leaderboard_screen.set_back_btn_state, enabled=True), + partial( + self.leaderboard_screen.set_mainmenu_btn_state, enabled=False + ), + ), + ) + ) + + self.gameboard_screen.set_help_cmd( + partial(self.__switch_context, screen=self.help_screen) + ) + + self.help_screen.set_back_cmd(partial(self.__switch_context, previous=True)) + # Set welcome screen as current context and try to import/use theme self.__switch_context(self.welcome_screen) self.__import_theme() diff --git a/source/gui/gameboard.py b/source/gui/gameboard.py index d838545..f6e96e1 100644 --- a/source/gui/gameboard.py +++ b/source/gui/gameboard.py @@ -1,6 +1,7 @@ -from tkinter import ttk, Tk +from tkinter import ttk, Tk, messagebox from functools import partial from gui.base import AppGuiBase +from localization import localizer class Gameboard(AppGuiBase): @@ -11,27 +12,77 @@ class Gameboard(AppGuiBase): def __init__(self, master, *args, **kwargs) -> None: AppGuiBase.__init__(self, master, *args, **kwargs) - self.label = ttk.Label( + self.rowconfigure(index=0, weight=5, minsize=100) + self.rowconfigure(index=1, weight=90, minsize=100) + self.rowconfigure(index=2, weight=5, minsize=100) + # Title + self.title = ttk.Label( self, - padding=(10, 10), justify="center", - font=("-size", 45, "-weight", "bold"), - text="TODO: GAMEBOARD SCREEN", + font=("-size", 30, "-weight", "bold"), + text=localizer.get("GAME_TITLE"), ) - self.label.pack() + self.title.grid(row=0, column=1, padx=(10, 10), pady=(20, 10), sticky="n") - self.back_btn = ttk.Button( - self, text="BACK", command=partial(print, "TODO: GOTO WELCOME") + self.timer = ttk.Label( + self, + justify="center", + font=("-size", 18, "-weight", "bold"), + text="Timer: 00:00", + ) + self.timer.grid(row=0, column=0, padx=(10, 10), pady=(20, 10), sticky="sw") + + self.help_btn = ttk.Button( + self, text="HELP", command=partial(print, "TODO: GOTO HELP") + ) + self.help_btn.grid(row=0, column=2, padx=(10, 10), sticky="se") + + # Middle panel + self.scores_panel = ttk.Labelframe( + self, + padding=(5, 5), + ) + self.scores_panel.grid( + row=1, column=0, columnspan=self.num_columns, sticky="nsew" + ) + + # Bottom Buttons + self.mainmenu_btn = ttk.Button( + self, + text=localizer.get("ARROW_LEFT") + localizer.get("MAIN_MENU_BUTTON"), + command=partial( + self.__confirm_quit, partial(print, "TODO: RETURN MAIN MENU") + ), + ) + self.mainmenu_btn.grid(row=2, column=0, padx=(10, 10), pady=(10, 10)) + + self.highscores_btn = ttk.Button( + self, + text=localizer.get("HIGHSCORES_BUTTON") + localizer.get("ARROW_RIGHT"), + command=partial(print, "TODO: GOTO LAST CONTEXT"), ) - self.back_btn.pack() + self.highscores_btn.grid(row=2, column=2, padx=(10, 10), pady=(10, 10)) + + def __confirm_quit(self, func) -> None: + ret = messagebox.askyesno( + title="Are you sure?", message="Are you sure you want to quit?" + ) + if ret: + func() + + def set_mainmenu_cmd(self, command) -> None: + self.mainmenu_btn.configure(command=partial(self.__confirm_quit, command)) + + def set_highscores_cmd(self, command) -> None: + self.highscores_btn.configure(command=command) - def set_back_cmd(self, command) -> None: - self.back_btn.configure(command=command) + def set_help_cmd(self, command) -> None: + self.help_btn.configure(command=command) if __name__ == "__main__": root = Tk() - app = Gameboard(master=root, rows=3, columns=3) + app = Gameboard(master=root, rows=3, columns=3, theme=None, name="") app.pack(fill="both", expand=True) root.update() diff --git a/source/gui/help.py b/source/gui/help.py index 506e39d..044caf9 100644 --- a/source/gui/help.py +++ b/source/gui/help.py @@ -1,5 +1,6 @@ from tkinter import ttk from gui.base import AppGuiBase +from functools import partial class Help(AppGuiBase): @@ -10,6 +11,23 @@ class Help(AppGuiBase): def __init__(self, master, *args, **kwargs) -> None: AppGuiBase.__init__(self, master, *args, **kwargs) + self.label = ttk.Label( + self, + padding=(10, 10), + justify="center", + font=("-size", 45, "-weight", "bold"), + text="TODO: HELP SCREEN", + ) + self.label.pack() + + self.back_btn = ttk.Button( + self, text="BACK", command=partial(print, "TODO: GOTO WELCOME") + ) + self.back_btn.pack() + + def set_back_cmd(self, command) -> None: + self.back_btn.configure(command=command) + if __name__ == "__main__": app = Help(master=None) diff --git a/source/gui/leaderboard.py b/source/gui/leaderboard.py index 5d6b654..cbd5935 100644 --- a/source/gui/leaderboard.py +++ b/source/gui/leaderboard.py @@ -61,14 +61,14 @@ def __init__(self, master, *args, **kwargs) -> None: # Bottom Buttons self.mainmenu_btn = ttk.Button( self, - text=localizer.get("MAIN_MENU_BUTTON"), + text=localizer.get("ARROW_LEFT") + localizer.get("MAIN_MENU_BUTTON"), command=partial(print, "TODO: GOTO MAIN MENU"), ) self.mainmenu_btn.grid(row=2, column=0, padx=(10, 10), pady=(10, 10)) self.back_btn = ttk.Button( self, - text=localizer.get("BACK_BUTTON"), + text=localizer.get("BACK_BUTTON") + localizer.get("ARROW_RIGHT"), command=partial(print, "TODO: GOTO LAST CONTEXT"), ) self.back_btn.grid(row=2, column=2, padx=(10, 10), pady=(10, 10)) @@ -96,7 +96,15 @@ def set_back_cmd(self, command) -> None: def set_mainmenu_cmd(self, command) -> None: self.mainmenu_btn.configure(command=command) + def set_back_btn_state(self, enabled: bool) -> None: + self.back_btn.configure(state="enabled" if enabled else "disabled") + + def set_mainmenu_btn_state(self, enabled: bool) -> None: + self.mainmenu_btn.configure(state="enabled" if enabled else "disabled") + def refresh_scores(self) -> None: + self.scores_table.delete(*self.scores_table.get_children()) + scores = self.__read_scores() for i, score in enumerate(scores): self.scores_table.insert( diff --git a/source/localization/localizer_en.py b/source/localization/localizer_en.py index d081cd9..ba6909b 100644 --- a/source/localization/localizer_en.py +++ b/source/localization/localizer_en.py @@ -11,8 +11,11 @@ THEME_COPYRIGHT = "© 2021 rdbende" THEME_NAME = "Sun-Valley-ttk-theme" LEADERBOARD_TITLE = "High Scores" -MAIN_MENU_BUTTON = "<< Return to Main Menu" -BACK_BUTTON = "Go Back >>" +MAIN_MENU_BUTTON = "Return to Main Menu" +BACK_BUTTON = "Go Back" + +ARROW_LEFT = "<< " +ARROW_RIGHT = " >>" WELCOME_SCREEN = "Main Menu" GAMEBOARD_SCREEN = "Game"