From b2466257ceb48e98015a99fcf4f532150d97ae87 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:13:02 -0500 Subject: [PATCH] Refactor Game navigator location also cleanup some unused files --- .../adventure_game/GameNavigator.py | 53 ++++++++++++++++ Adventure Game/adventure_game/example.py | 32 ---------- .../adventure_game/gamedata/gamelib.yaml | 9 +++ Adventure Game/adventure_game/main.py | 61 +++---------------- Adventure Game/adventure_game/text.py | 35 ----------- 5 files changed, 70 insertions(+), 120 deletions(-) create mode 100644 Adventure Game/adventure_game/GameNavigator.py delete mode 100644 Adventure Game/adventure_game/example.py delete mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py new file mode 100644 index 0000000..a342861 --- /dev/null +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -0,0 +1,53 @@ +import npyscreen, sys + +class ExitButton(npyscreen.ButtonPress): + def whenPressed(self): + sys.exit(0) + +class GameNavigator(npyscreen.Form): + def afterEditing(self): + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. + + def create(self): + top_division_height = 20 + inventory_width = 20 + art_width = 100 + + self.artBox = self.add(npyscreen.BoxBasic, + name='ArtBox', + max_width=art_width, + max_height=top_division_height, + rely=2, + relx=inventory_width + 1, + editable=False) + self.artContent = self.add(npyscreen.MultiLineEdit, + rely=3, + relx=inventory_width + 2, + max_width=art_width - 2, + max_height=top_division_height - 2, + value=self.parentApp.gamelib['menu']['graphics']['not_found'], + editable=False) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) + + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=3, + relx=1, + rely=top_division_height + 2) + + self.dialogueBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 7, + max_height=1, + relx=2, + rely=top_division_height + 3) + + self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) \ No newline at end of file diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py deleted file mode 100644 index 6cf4ea8..0000000 --- a/Adventure Game/adventure_game/example.py +++ /dev/null @@ -1,32 +0,0 @@ -# encoding: utf-8 - -import npyscreen - - -class TestApp(npyscreen.NPSApp): - def main(self): - # These lines create the form and populate it with widgets. - # A fairly complex screen in only 8 or so lines of code - a line for each control. - F = npyscreen.Form(name="Welcome to Npyscreen", ) - t = F.add(npyscreen.TitleText, name="Text:", ) - fn = F.add(npyscreen.TitleFilename, name="Filename:") - fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:") - dt = F.add(npyscreen.TitleDateCombo, name="Date:") - s = F.add(npyscreen.TitleSlider, out_of=12, name="Slider") - ml = F.add(npyscreen.MultiLineEdit, - value="""try typing here!\nMutiline text, press ^R to reformat.\n""", - max_height=5, rely=9) - ms = F.add(npyscreen.TitleSelectOne, max_height=4, value=[1, ], name="Pick One", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - ms2 = F.add(npyscreen.TitleMultiSelect, max_height=-2, value=[1, ], name="Pick Several", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - - # This lets the user interact with the Form. - F.edit() - - print(ms.get_selected_objects()) - - -if __name__ == "__main__": - App = TestApp() - App.run() diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index dc5deff..d817750 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -31,3 +31,12 @@ menu: -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- + dimensions: + inventory_width: 23 + inventory_height: 20 + art_width: 101 + art_height: 20 + dialogue_width: 122 + dialogue_height: 20 + entry_box_width: 122 + entry_box_height: 3 diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 90e3fef..e99b86b 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,60 +1,9 @@ import npyscreen, sys from npyscreen import NotEnoughSpaceForWidget +from os import system from yaml_parser import parse_datafile as parse - -class ExitButton(npyscreen.ButtonPress): - def whenPressed(self): - sys.exit(0) - - -class GameNavigator(npyscreen.Form): - def afterEditing(self): - self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. - - def create(self): - top_division_height = 20 - inventory_width = 20 - art_width = 100 - - self.artBox = self.add(npyscreen.BoxBasic, - name='ArtBox', - max_width=art_width, - max_height=top_division_height, - rely=2, - relx=inventory_width + 1, - editable=False) - self.artContent = self.add(npyscreen.MultiLineEdit, - rely=3, - relx=inventory_width + 2, - max_width=art_width - 2, - max_height=top_division_height - 2, - value=self.parentApp.gamelib['menu']['graphics']['not_found'], - editable=False) - self.artBox.footer = 'Unknown Location' - - self.artBox = self.add(npyscreen.BoxBasic, - name='Inventory', - max_width=inventory_width, - max_height=top_division_height, - relx=1, - rely=2, - editable=False) - - self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, - max_width=inventory_width + art_width, - max_height=3, - relx=1, - rely=top_division_height + 2) - - self.dialogueBox = self.add(npyscreen.Textfield, - name='Type Here', - max_width=inventory_width + art_width - 7, - max_height=1, - relx=2, - rely=top_division_height + 3) - - self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) +from GameNavigator import GameNavigator class MainMenu(npyscreen.Form): @@ -86,6 +35,12 @@ class AdventureGame(npyscreen.NPSAppManaged): '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 + # Set screen size before drawing windows + dimensions = self.gamelib['menu']['graphics']['dimensions'] + system('mode con: cols={0} lines={1}'.format( + dimensions['inventory_width']+dimensions['art_width'], + 30)) # TODO: Finish setting this up. + # 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 diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py deleted file mode 100644 index 53df858..0000000 --- a/Adventure Game/adventure_game/text.py +++ /dev/null @@ -1,35 +0,0 @@ -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