From 7eb8dfde07460ee9b6618bd2fb85a645754b123e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 20 Feb 2021 18:53:44 -0500 Subject: [PATCH] Basic UI should work fine now! TODO: slight bug with send button not 'clearing' screen? --- .../adventure_game/GameNavigator.py | 26 ++++++++++++++----- Adventure Game/adventure_game/MainMenu.py | 11 ++++++++ Adventure Game/adventure_game/Player.py | 11 ++++++++ Adventure Game/adventure_game/main.py | 22 +++++++--------- Adventure Game/adventure_game/player.py | 7 ----- .../playerdata/defaults/default_player.yaml | 4 +++ 6 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 Adventure Game/adventure_game/MainMenu.py create mode 100644 Adventure Game/adventure_game/Player.py delete mode 100644 Adventure Game/adventure_game/player.py create mode 100644 Adventure Game/adventure_game/playerdata/defaults/default_player.yaml diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 143430c..81fd744 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -1,12 +1,18 @@ -import npyscreen, sys +import npyscreen +import sys -class ExitButton(npyscreen.ButtonPress): + +class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) +class SendButton(npyscreen.ButtonPress): + def whenPressed(self): + self.parent.parentApp.switchForm('GAME') + class GameNavigator(npyscreen.FormBaseNew): - def afterEditing(self): - self.parentApp.setNextForm('GAME') +# def afterEditing(self): +#it self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 @@ -41,7 +47,8 @@ class GameNavigator(npyscreen.FormBaseNew): max_width=inventory_width + art_width, max_height=3, relx=1, - rely=top_division_height + 2) + rely=top_division_height + 2, + editable=False) self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', @@ -50,4 +57,11 @@ class GameNavigator(npyscreen.FormBaseNew): 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 + self.sendButton = self.add(SendButton, + name="Send", + relx=inventory_width + art_width - 7, + rely=top_division_height + 3) + self.quitButton = self.add(QuitButton, + name="Quit", + relx=1, + rely=1) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py new file mode 100644 index 0000000..7afc67d --- /dev/null +++ b/Adventure Game/adventure_game/MainMenu.py @@ -0,0 +1,11 @@ +import npyscreen + +class MainMenu(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm('GAME') + + def create(self): + self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py new file mode 100644 index 0000000..b27cb37 --- /dev/null +++ b/Adventure Game/adventure_game/Player.py @@ -0,0 +1,11 @@ +from yaml_parser import parse_datafile as parse + +class Player: + """ + This class intended to abstract out the actual yaml data into a player.(item) that is more + friendly to handle in code. + """ + def __init__(self, save_location): + self.save_location = save_location + + self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index e99b86b..092fedb 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,20 +1,11 @@ -import npyscreen, sys +import npyscreen from npyscreen import NotEnoughSpaceForWidget from os import system from yaml_parser import parse_datafile as parse from GameNavigator import GameNavigator - - -class MainMenu(npyscreen.Form): - def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm('GAME') - - def create(self): - self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) - self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") - self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) +from MainMenu import MainMenu +from Player import Player class AlphaWarning(npyscreen.Popup): @@ -33,7 +24,9 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup some important 'global' 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 + self.playerSaveLocation = 'playerdata/defaults/default_player.yaml' #TODO: Actually load the player data + + self.player = Player(self.playerSaveLocation) # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] @@ -50,6 +43,9 @@ class AdventureGame(npyscreen.NPSAppManaged): if __name__ == '__main__': + # Set the screen size bigger + system('mode con: cols={0} lines={1}'.format(124, 30)) + # Make a new adventure game if not imported adventure_game = AdventureGame() diff --git a/Adventure Game/adventure_game/player.py b/Adventure Game/adventure_game/player.py deleted file mode 100644 index 81620ec..0000000 --- a/Adventure Game/adventure_game/player.py +++ /dev/null @@ -1,7 +0,0 @@ -from yaml_parser import parse_datafile as parse - -class Player: - def __init__(self, save_location): - self.save_location = save_location - - self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml new file mode 100644 index 0000000..811f696 --- /dev/null +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -0,0 +1,4 @@ +player: + name: 'Default' + location: 'office' + inventory: ['test', 'test2'] \ No newline at end of file