Basic UI should work fine now!

TODO: slight bug with send button not 'clearing' screen?
This commit is contained in:
Joe S 2021-02-20 18:53:44 -05:00
parent 5437129a76
commit 7eb8dfde07
6 changed files with 55 additions and 26 deletions

View File

@ -1,12 +1,18 @@
import npyscreen, sys import npyscreen
import sys
class ExitButton(npyscreen.ButtonPress):
class QuitButton(npyscreen.ButtonPress):
def whenPressed(self): def whenPressed(self):
sys.exit(0) sys.exit(0)
class SendButton(npyscreen.ButtonPress):
def whenPressed(self):
self.parent.parentApp.switchForm('GAME')
class GameNavigator(npyscreen.FormBaseNew): class GameNavigator(npyscreen.FormBaseNew):
def afterEditing(self): # def afterEditing(self):
self.parentApp.setNextForm('GAME') #it self.parentApp.setNextForm('GAME')
def create(self): def create(self):
top_division_height = 20 top_division_height = 20
@ -41,7 +47,8 @@ class GameNavigator(npyscreen.FormBaseNew):
max_width=inventory_width + art_width, max_width=inventory_width + art_width,
max_height=3, max_height=3,
relx=1, relx=1,
rely=top_division_height + 2) rely=top_division_height + 2,
editable=False)
self.dialogueBox = self.add(npyscreen.Textfield, self.dialogueBox = self.add(npyscreen.Textfield,
name='Type Here', name='Type Here',
@ -50,4 +57,11 @@ class GameNavigator(npyscreen.FormBaseNew):
relx=2, relx=2,
rely=top_division_height + 3) rely=top_division_height + 3)
self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) 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)

View File

@ -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)

View File

@ -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)

View File

@ -1,20 +1,11 @@
import npyscreen, sys import npyscreen
from npyscreen import NotEnoughSpaceForWidget from npyscreen import NotEnoughSpaceForWidget
from os import system from os import system
from yaml_parser import parse_datafile as parse from yaml_parser import parse_datafile as parse
from GameNavigator import GameNavigator from GameNavigator import GameNavigator
from MainMenu import MainMenu
from Player import Player
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)
class AlphaWarning(npyscreen.Popup): class AlphaWarning(npyscreen.Popup):
@ -33,7 +24,9 @@ class AdventureGame(npyscreen.NPSAppManaged):
# Setup some important 'global' values we'll need later # Setup some important 'global' values we'll need later
self.gamelib = parse( self.gamelib = parse(
'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu '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 # Set screen size before drawing windows
dimensions = self.gamelib['menu']['graphics']['dimensions'] dimensions = self.gamelib['menu']['graphics']['dimensions']
@ -50,6 +43,9 @@ class AdventureGame(npyscreen.NPSAppManaged):
if __name__ == '__main__': 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 # Make a new adventure game if not imported
adventure_game = AdventureGame() adventure_game = AdventureGame()

View File

@ -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)

View File

@ -0,0 +1,4 @@
player:
name: 'Default'
location: 'office'
inventory: ['test', 'test2']