Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-kirkbride authored May 3, 2022
2 parents bd10c5e + 1ffa369 commit 944f390
Showing 1 changed file with 159 additions and 0 deletions.
159 changes: 159 additions & 0 deletions rpg/views/game_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,130 @@
"""

import json
from functools import partial
from turtle import bgcolor, color
from typing import Callable

import arcade
import arcade.gui
import rpg.constants as constants
from arcade.experimental.lights import Light
from pyglet.math import Vec2
from rpg.message_box import MessageBox
from rpg.sprites.player_sprite import PlayerSprite


class DebugMenu(arcade.gui.UIBorder, arcade.gui.UIWindowLikeMixin):
def __init__(
self,
*,
width: float,
height: float,
noclip_callback: Callable,
hyper_callback: Callable,
):

self.off_style = {
"bg_color": arcade.color.BLACK,
}

self.on_style = {
"bg_color": arcade.color.REDWOOD,
}

self.setup_noclip(noclip_callback)
self.setup_hyper(hyper_callback)

space = 10

self._title = arcade.gui.UITextArea(
text="DEBUG MENU",
width=width - space,
height=height - space,
font_size=14,
text_color=arcade.color.BLACK,
)

group = arcade.gui.UIPadding(
bg_color=(255, 255, 255, 255),
child=arcade.gui.UILayout(
width=width,
height=height,
children=[
arcade.gui.UIAnchorWidget(
child=self._title,
anchor_x="left",
anchor_y="top",
align_x=10,
align_y=-10,
),
arcade.gui.UIAnchorWidget(
child=arcade.gui.UIBoxLayout(
x=0,
y=0,
children=[
arcade.gui.UIPadding(
child=self.noclip_button, pading=(5, 5, 5, 5)
),
arcade.gui.UIPadding(
child=self.hyper_button, padding=(5, 5, 5, 5)
),
],
vertical=False,
),
anchor_x="left",
anchor_y="bottom",
align_x=5,
),
],
),
)

# x and y don't seem to actually change where this is created. bug?
# TODO: make this not appear at the complete bottom left (top left would be better?)
super().__init__(border_width=5, child=group)

def setup_noclip(self, callback: Callable):
# disable player collision

def toggle(*args):
# toggle state on click
self.noclip_status = True if not self.noclip_status else False
self.noclip_button._style = (
self.off_style if not self.noclip_status else self.on_style
)
print(self.noclip_status)
print(self.noclip_button.style)
self.noclip_button.clear()

self.noclip_callback

self.noclip_callback = callback
self.noclip_status = False
self.noclip_button = arcade.gui.UIFlatButton(
text="noclip", style=self.off_style
)
self.noclip_button.on_click = toggle # type: ignore

def setup_hyper(self, callback: Callable):
# increase player speed

def toggle(*args):
# toggle state on click
self.hyper_status = True if not self.hyper_status else False
self.hyper_button._style = (
self.off_style if not self.hyper_status else self.on_style
)
self.hyper_button.clear()

callback(status=self.hyper_status)

self.hyper_status = False

self.hyper_button = arcade.gui.UIFlatButton(text="hyper", style=self.off_style)
self.hyper_button.on_click = toggle # type: ignore


class GameView(arcade.View):
"""
Main application class.
Expand All @@ -22,6 +137,11 @@ def __init__(self, map_list):

arcade.set_background_color(arcade.color.AMAZON)

self.debug = False

self.ui_manager = arcade.gui.UIManager()
self.ui_manager.enable()

# Player sprite
self.player_sprite = None
self.player_sprite_list = None
Expand Down Expand Up @@ -112,6 +232,8 @@ def setup(self):
self.switch_map(constants.STARTING_MAP, start_x, start_y)
self.cur_map_name = constants.STARTING_MAP

self.setup_debug_menu()

# Set up the hotbar
self.load_hotbar_sprites()

Expand All @@ -134,6 +256,33 @@ def load_hotbar_sprites(self):
count=816,
margin=1)[first_number_pad_sprite_index:last_number_pad_sprite_index]

def setup_debug_menu(self):
# debug menu stuff
self.debug_menu = DebugMenu(
width=450,
height=200,
noclip_callback=self.noclip,
hyper_callback=self.hyper,
)

self.original_movement_speed = constants.MOVEMENT_SPEED

def enable_debug_menu(self):
self.ui_manager.add(self.debug_menu)

def disable_debug_menu(self):
self.ui_manager.remove(self.debug_menu)

def noclip(self, *args, status: bool):
pass

def hyper(self, *args, status: bool):
constants.MOVEMENT_SPEED = (
int(self.original_movement_speed * 3.5)
if status
else self.original_movement_speed
)

def draw_inventory(self):
capacity = 10
vertical_hotbar_location = 40
Expand Down Expand Up @@ -224,6 +373,9 @@ def on_draw(self):
if self.message_box:
self.message_box.on_draw()

# draw GUI
self.ui_manager.draw()

def scroll_to_player(self, speed=constants.CAMERA_SPEED):
"""Manage Scrolling"""

Expand Down Expand Up @@ -424,6 +576,13 @@ def on_key_press(self, key, modifiers):
cur_map.light_layer.remove(self.player_light)
else:
cur_map.light_layer.add(self.player_light)
elif key == arcade.key.GRAVE: # `
# toggle debug
self.debug = True if not self.debug else False
if self.debug:
self.enable_debug_menu()
else:
self.disable_debug_menu()

def close_message_box(self):
self.message_box = None
Expand Down

0 comments on commit 944f390

Please sign in to comment.