From e79fda1bb9ae9d5b03984949b05bd4f071b3fc04 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:53:12 -0500 Subject: [PATCH] Add a lot of quality of life stuff including exception to handle small screens --- .../adventure_game/gamedata/gamelib.yaml | 7 ++- Adventure Game/adventure_game/main.py | 44 ++++++++++++------- Adventure Game/adventure_game/text.py | 35 +++++++++++++++ 3 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index c1b0624..3ed6da6 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -10,4 +10,9 @@ menu: / ____/ | / |/ / ____/ / / __/ /| | / /|_/ / __/ / /_/ / ___ |/ / / / /___ - \____/_/ |_/_/ /_/_____/ \ No newline at end of file + \____/_/ |_/_/ /_/_____/ + + not_found: | + . / \ + / ! \ + / \ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 91a55c7..cb4e615 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,17 +1,24 @@ import npyscreen +from npyscreen import NotEnoughSpaceForWidget + from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm(None) + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.myName = self.add(npyscreen.TitleText, name='Name') - self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', - values=['Department 1', 'Department 2', 'Department 3']) - self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=2,) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=32, rely=2) + self.artBox.footer = 'Unknown Location' + + #self.myName = self.add(npyscreen.TitleText, name='Name') + #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', + # values=['Department 1', 'Department 2', 'Department 3']) + #self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') class MainMenu(npyscreen.Form): @@ -34,26 +41,29 @@ class AlphaWarning(npyscreen.Popup): 'kitsunehosting.net'], editable=False) - class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): - self.gamelib = parse('gamedata/gamelib.yaml') + # Setup some important 'globa' values we'll need later + self.gamelib = parse( + 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen - # Intalize a game renderer for most game windows - self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') + # Draw game windows + self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game + self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu + self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') # This window is only needed for the ALPHA - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MENU', MainMenu, name='Welcome to the main menu') + # TODO: Create a 'splash screen' or, traditional "main menu" - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') - - #TODO: Create a 'splash screen' or, traditional "main menu" if __name__ == '__main__': # Make a new adventure game if not imported adventure_game = AdventureGame() # Run the game! - adventure_game.run() + try: + adventure_game.run() + except NotEnoughSpaceForWidget: + # This exception should catch if a player tries to play in a screen that is too small. + print('Your screen is too small!\nOr, Joe has not fixed https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues/7') diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py new file mode 100644 index 0000000..53df858 --- /dev/null +++ b/Adventure Game/adventure_game/text.py @@ -0,0 +1,35 @@ +import npyscreen + + +# npyscreen.disableColor() +class TestApp(npyscreen.NPSApp): + def main(self): + F = npyscreen.Form(name="Welcome to Npyscreen", ) + t = F.add(npyscreen.BoxBasic, name="Basic Box:", max_width=30, relx=2, max_height=3) + t.footer = "This is a footer" + + t1 = F.add(npyscreen.BoxBasic, name="Basic Box:", rely=2, relx=32, max_width=30, max_height=3) + + t2 = F.add(npyscreen.BoxTitle, name="Box Title:", max_height=6) + t3 = F.add(npyscreen.BoxTitle, name="Box Title2:", max_height=6, + scroll_exit=True, + contained_widget_arguments={ + 'color': "WARNING", + 'widgets_inherit_color': True, } + ) + + t2.entry_widget.scroll_exit = True + t2.values = ["Hello", + "This is a Test", + "This is another test", + "And here is another line", + "And here is another line, which is really very long. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", + "And one more."] + t3.values = t2.values + + F.edit() + + +if __name__ == "__main__": + App = TestApp() + App.run() \ No newline at end of file