Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a main menu with basic UI and a pause menu #2 #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rpg/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion rpg/views/game_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions rpg/views/loading_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"])
56 changes: 53 additions & 3 deletions rpg/views/main_menu_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 80 additions & 0 deletions rpg/views/pause_view.py
Original file line number Diff line number Diff line change
@@ -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"])