Stll broke
This commit is contained in:
parent
1b73dc208b
commit
e87c70e04f
|
@ -2,88 +2,85 @@ import curses
|
||||||
from curses.textpad import Textbox, rectangle
|
from curses.textpad import Textbox, rectangle
|
||||||
|
|
||||||
|
|
||||||
|
class AdventureGame:
|
||||||
|
def __init__(self, stdscr):
|
||||||
|
# Self.stdrscr is our parent standard screen
|
||||||
|
self.stdscr = stdscr
|
||||||
|
|
||||||
def draw_main_menu(stdscr):
|
# This is just done once at startup to get inital windows sizes
|
||||||
# Command is the last char the user entered.
|
# TODO: handle live window resize!
|
||||||
command = 0
|
self.height, self.width = self.stdscr.getmaxyx()
|
||||||
|
|
||||||
# Clear, and refresh the screen
|
self.command = 0
|
||||||
stdscr.clear()
|
|
||||||
stdscr.refresh()
|
|
||||||
|
|
||||||
# Start some curses colors
|
# Clear and refresh the screen
|
||||||
curses.start_color()
|
self.stdscr.clear()
|
||||||
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
self.stdscr.refresh()
|
||||||
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
|
|
||||||
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
|
||||||
|
|
||||||
while command != ord('q'):
|
# Setup some colors!
|
||||||
# Clear the screen
|
# Start some curses colors
|
||||||
stdscr.clear()
|
curses.start_color()
|
||||||
# Get the height, and width
|
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
||||||
height, width = stdscr.getmaxyx()
|
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
|
||||||
|
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
||||||
|
|
||||||
|
# Setup art_win
|
||||||
|
art_win_width = int((self.width / 3) * 2)
|
||||||
|
art_win_begin_x = int(self.width - art_win_width)
|
||||||
|
art_win_begin_y = 1 # Must be at least 1 (to allow header)
|
||||||
|
art_win_height = int(self.height / 2)
|
||||||
|
|
||||||
# Temporary strings, replace these with libdocs!
|
art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x)
|
||||||
title = 'Untitled Adventure Game PRE ALPHA'[:width - 1]
|
|
||||||
subtitle = 'Joe Sedutto'[:width - 1]
|
|
||||||
statusbarstr = "Press 'q' to exit "
|
|
||||||
|
|
||||||
# Centering calculations
|
# Setup dialogue_win
|
||||||
start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2)
|
dialogue_win_width = self.width
|
||||||
start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2)
|
dialogue_win_begin_x = 0
|
||||||
start_y = int((height // 2) - 2)
|
dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above.
|
||||||
|
dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box,
|
||||||
|
|
||||||
# Rendering some text
|
dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y,
|
||||||
whstr = 'Width: {}, Height: {}'.format(width, height)
|
dialogue_win_begin_x)
|
||||||
stdscr.addstr(0, 0, whstr, curses.color_pair(1))
|
|
||||||
|
|
||||||
# Render status bar
|
while self.command != ord('q'):
|
||||||
stdscr.attron(curses.color_pair(3))
|
# Get the height of everything
|
||||||
stdscr.addstr(height - 1, 0, statusbarstr)
|
self.height, self.width = self.stdscr.getmaxyx()
|
||||||
stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1))
|
|
||||||
stdscr.attroff(curses.color_pair(3))
|
|
||||||
|
|
||||||
# Turning on attributes for title
|
self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1]
|
||||||
stdscr.attron(curses.color_pair(2))
|
self.statusbarstr = "Press 'q' to exit "
|
||||||
stdscr.attron(curses.A_BOLD)
|
|
||||||
|
|
||||||
# Rendering title
|
# Render status bar
|
||||||
stdscr.addstr(start_y, start_x_title, title)
|
self.stdscr.attron(curses.color_pair(3))
|
||||||
|
self.stdscr.addstr(self.height - 1, 0, self.statusbarstr)
|
||||||
|
self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1))
|
||||||
|
self.stdscr.attroff(curses.color_pair(3))
|
||||||
|
|
||||||
# Turning off attributes for title
|
# Render major game windows
|
||||||
stdscr.attroff(curses.color_pair(2))
|
self.draw_art_window(art_win)
|
||||||
stdscr.attroff(curses.A_BOLD)
|
self.command = self.draw_dialogue_box(dialogue_win)
|
||||||
|
|
||||||
# Print rest of text
|
# Refresh the screen
|
||||||
stdscr.addstr(start_y + 1, start_x_subtitle, subtitle)
|
self.stdscr.refresh()
|
||||||
stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4)
|
|
||||||
|
|
||||||
# Refresh the screen
|
# Wait for next input
|
||||||
stdscr.refresh()
|
# self.command = self.stdscr.getch()
|
||||||
|
curses.echo()
|
||||||
|
#self.command = self.stdscr.getstr(0, 0)
|
||||||
|
|
||||||
# Wait for next input
|
def draw_main_menu(self):
|
||||||
command = stdscr.getch()
|
pass
|
||||||
|
|
||||||
|
def draw_art_window(self, window):
|
||||||
|
window.addstr(0, 0, "Wip")
|
||||||
|
window.box()
|
||||||
|
window.refresh()
|
||||||
|
|
||||||
def main_textbox(stdscr):
|
def draw_dialogue_box(self, window):
|
||||||
stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)")
|
window.box()
|
||||||
|
window.refresh()
|
||||||
|
|
||||||
editwin = curses.newwin(5,30, 2,1)
|
textbox = Textbox(window)
|
||||||
rectangle(stdscr, 1,0, 1+5+1, 1+30+1)
|
return textbox.gather()
|
||||||
stdscr.refresh()
|
|
||||||
|
|
||||||
box = Textbox(editwin)
|
|
||||||
|
|
||||||
# Let the user edit until Ctrl-G is struck.
|
|
||||||
box.edit()
|
|
||||||
|
|
||||||
# Get resulting contents
|
|
||||||
message = box.gather()
|
|
||||||
|
|
||||||
def main():
|
|
||||||
curses.wrapper(main_textbox)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
curses.wrapper(AdventureGame)
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
import curses
|
|
||||||
from curses.textpad import Textbox, rectangle
|
|
||||||
|
|
||||||
|
|
||||||
class AdventureGame:
|
|
||||||
def __init__(self, stdscr):
|
|
||||||
# Self.stdrscr is our parent standard screen
|
|
||||||
self.stdscr = stdscr
|
|
||||||
|
|
||||||
# This is just done once at startup to get inital windows sizes
|
|
||||||
# TODO: handle live window resize!
|
|
||||||
self.height, self.width = self.stdscr.getmaxyx()
|
|
||||||
|
|
||||||
self.command = 0
|
|
||||||
|
|
||||||
# Clear and refresh the screen
|
|
||||||
self.stdscr.clear()
|
|
||||||
self.stdscr.refresh()
|
|
||||||
|
|
||||||
# Setup some colors!
|
|
||||||
# Start some curses colors
|
|
||||||
curses.start_color()
|
|
||||||
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
|
||||||
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
|
|
||||||
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
|
||||||
|
|
||||||
# Setup art_win
|
|
||||||
art_win_width = int((self.width / 3) * 2)
|
|
||||||
art_win_begin_x = int(self.width - art_win_width)
|
|
||||||
art_win_begin_y = 1 # Must be at least 1 (to allow header)
|
|
||||||
art_win_height = int(self.height / 2)
|
|
||||||
|
|
||||||
art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x)
|
|
||||||
|
|
||||||
# Setup dialogue_win
|
|
||||||
dialogue_win_width = self.width
|
|
||||||
dialogue_win_begin_x = 0
|
|
||||||
dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above.
|
|
||||||
dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box,
|
|
||||||
|
|
||||||
dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y,
|
|
||||||
dialogue_win_begin_x)
|
|
||||||
|
|
||||||
while self.command != 'q':
|
|
||||||
# Get the height of everything
|
|
||||||
self.height, self.width = self.stdscr.getmaxyx()
|
|
||||||
|
|
||||||
self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1]
|
|
||||||
self.statusbarstr = "Press 'q' to exit "
|
|
||||||
|
|
||||||
# Render status bar
|
|
||||||
self.stdscr.attron(curses.color_pair(3))
|
|
||||||
self.stdscr.addstr(self.height - 1, 0, self.statusbarstr)
|
|
||||||
self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1))
|
|
||||||
self.stdscr.attroff(curses.color_pair(3))
|
|
||||||
|
|
||||||
# Render major game windows
|
|
||||||
self.draw_art_window(art_win)
|
|
||||||
self.command = self.draw_dialogue_box(dialogue_win)
|
|
||||||
|
|
||||||
# Refresh the screen
|
|
||||||
self.stdscr.refresh()
|
|
||||||
|
|
||||||
# Wait for next input
|
|
||||||
# self.command = self.stdscr.getch()
|
|
||||||
curses.echo()
|
|
||||||
#self.command = self.stdscr.getstr(0, 0)
|
|
||||||
|
|
||||||
def draw_main_menu(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def draw_art_window(self, window):
|
|
||||||
window.addstr(0, 0, "Wip")
|
|
||||||
window.box()
|
|
||||||
window.refresh()
|
|
||||||
|
|
||||||
def draw_dialogue_box(self, window):
|
|
||||||
window.box()
|
|
||||||
window.refresh()
|
|
||||||
|
|
||||||
textbox = Textbox(window)
|
|
||||||
return textbox.gather()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
curses.wrapper(AdventureGame)
|
|
Loading…
Reference in New Issue