Refactor Game navigator location

also cleanup some unused files
This commit is contained in:
Joe S 2021-02-19 17:13:02 -05:00
parent 04669d0f8f
commit b2466257ce
5 changed files with 70 additions and 120 deletions

View File

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

View File

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

View File

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

View File

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

View File

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