diff --git a/rpg/__main__.py b/rpg/__main__.py index 969c08db..99fbd87b 100644 --- a/rpg/__main__.py +++ b/rpg/__main__.py @@ -8,6 +8,7 @@ from rpg.constants import SCREEN_HEIGHT, SCREEN_TITLE, SCREEN_WIDTH from rpg.views import LoadingView +from rpg.views.main_menu_view import MainMenuView class MyWindow(arcade.Window): @@ -25,7 +26,7 @@ def main(): """Main method""" window = MyWindow() window.center_window() - start_view = LoadingView() + start_view = MainMenuView() start_view.setup() window.show_view(start_view) arcade.run() diff --git a/rpg/views/game_view.py b/rpg/views/game_view.py index f358d6b3..a32a1390 100644 --- a/rpg/views/game_view.py +++ b/rpg/views/game_view.py @@ -278,7 +278,7 @@ def on_key_press(self, key, modifiers): elif key in constants.INVENTORY: self.window.show_view(self.window.views["inventory"]) elif key == arcade.key.ESCAPE: - self.window.show_view(self.window.views["main_menu"]) + self.window.show_view(self.window.views["pause"]) elif key in constants.SEARCH: self.search() elif key == arcade.key.KEY_1: diff --git a/rpg/views/loading_view.py b/rpg/views/loading_view.py index 9f58b54b..96244cde 100644 --- a/rpg/views/loading_view.py +++ b/rpg/views/loading_view.py @@ -6,7 +6,8 @@ from rpg.load_game_map import load_maps from rpg.views.game_view import GameView from rpg.views.inventory_view import InventoryView -from rpg.views.main_menu_view import MainMenuView +from rpg.views.pause_view import PauseView + class LoadingView(arcade.View): @@ -50,11 +51,12 @@ def on_update(self, delta_time: float): if self.started: done, self.progress, self.map_list = load_maps() if done: + + self.window.views["pause"] = PauseView() + self.window.views["pause"].setup() self.window.views["game"] = GameView(self.map_list) self.window.views["game"].setup() self.window.views["inventory"] = InventoryView() self.window.views["inventory"].setup() - self.window.views["main_menu"] = MainMenuView() - self.window.views["main_menu"].setup() self.window.show_view(self.window.views["game"]) diff --git a/rpg/views/main_menu_view.py b/rpg/views/main_menu_view.py index e4dc5d7c..ed248bca 100644 --- a/rpg/views/main_menu_view.py +++ b/rpg/views/main_menu_view.py @@ -2,27 +2,77 @@ Main Menu """ import arcade +import arcade.gui +from rpg.views import * +# For now it does not do anything +class SettingsButton(arcade.gui.UIFlatButton): + def on_click(self, event: arcade.gui.UIOnClickEvent): + pass class MainMenuView(arcade.View): def __init__(self): super().__init__() self.started = False + # We create the buttons here + self.createButtons() arcade.set_background_color(arcade.color.ALMOND) + def createButtons(self): + self.manager = arcade.gui.UIManager() + self.manager.enable() + self.v_box = arcade.gui.UIBoxLayout() + + # Start Button + start_button = arcade.gui.UIFlatButton(text="Start Game", width=200) + self.v_box.add(start_button.with_space_around(bottom=20)) + + #It starts a new game + @start_button.event("on_click") + def on_click_start(event): + self.window.views["main_menu"] = MainMenuView() + self.window.views["main_menu"].setup() + current_view = LoadingView() + current_view.setup() + self.window.show_view(current_view) + + # Settings Button + settings_button = SettingsButton(text="Settings", width=200) + self.v_box.add(settings_button.with_space_around(bottom=20)) + + # Quit Button + quit_button = arcade.gui.UIFlatButton(text="Quit", width=200) + self.v_box.add(quit_button.with_space_around(bottom=20)) + + # It closes the game + @quit_button.event("on_click") + def on_click_quit(event): + arcade.exit() + + + self.manager.add( + arcade.gui.UIAnchorWidget( + anchor_x="center_x", + anchor_y="center_y", + child=self.v_box) + ) + def on_draw(self): arcade.start_render() + # Some simple text to welcome the player arcade.draw_text( - "Main Menu", + "Welcome to the Python Arcade " + "Community RPG Game!", self.window.width / 2, - self.window.height - 50, + self.window.height - 200, arcade.color.ALLOY_ORANGE, - 44, + font_size=30, anchor_x="center", anchor_y="center", align="center", width=self.window.width, ) + self.manager.draw() def setup(self): pass diff --git a/rpg/views/pause_view.py b/rpg/views/pause_view.py new file mode 100644 index 00000000..6d82df5c --- /dev/null +++ b/rpg/views/pause_view.py @@ -0,0 +1,80 @@ +""" +Pause Menu +""" +import arcade +import arcade.gui +from rpg.views import * + +""" +Same approach as the MainMenuView +""" + +# For now it does not do anything +class SettingsButton(arcade.gui.UIFlatButton): + def on_click(self, event: arcade.gui.UIOnClickEvent): + pass + +class PauseView(arcade.View): + def __init__(self): + super().__init__() + self.started = False + # We create the buttons here + self.createButtons() + arcade.set_background_color(arcade.color.ALMOND) + + def createButtons(self): + self.manager = arcade.gui.UIManager() + self.manager.enable() + self.v_box = arcade.gui.UIBoxLayout() + + # Continue Button + continue_button = arcade.gui.UIFlatButton(text="Continue", width=200) + self.v_box.add(continue_button.with_space_around(bottom=20)) + # It continues the game + @continue_button.event("on_click") + def on_click_continue(event): + self.window.show_view(self.window.views["game"]) + # Settings Button + settings_button = SettingsButton(text="Settings", width=200) + self.v_box.add(settings_button.with_space_around(bottom=20)) + # Quit Button + quit_button = arcade.gui.UIFlatButton(text="Quit", width=200) + self.v_box.add(quit_button.with_space_around(bottom=20)) + # It closes the game + @quit_button.event("on_click") + def on_click_quit(event): + arcade.exit() + + self.manager.add( + arcade.gui.UIAnchorWidget( + anchor_x="center_x", + anchor_y="center_y", + child=self.v_box) + ) + + def on_draw(self): + arcade.start_render() + arcade.draw_text( + "Pause Menu", + self.window.width / 2, + self.window.height - 100, + arcade.color.ALLOY_ORANGE, + font_size=44, + anchor_x="center", + anchor_y="center", + align="center", + width=self.window.width, + ) + self.manager.draw() + + def setup(self): + pass + + def on_show_view(self): + arcade.set_background_color(arcade.color.ALMOND) + arcade.set_viewport(0, self.window.width, 0, self.window.height) + + def on_key_press(self, symbol: int, modifiers: int): + # It continues the game if you press escape + if symbol == arcade.key.ESCAPE: + self.window.show_view(self.window.views["game"]) \ No newline at end of file