This is still a huge mess
This commit is contained in:
parent
a03bfaf3dc
commit
1b73dc208b
|
@ -1,17 +0,0 @@
|
|||
from dashing import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
ui = HSplit(
|
||||
VSplit(
|
||||
Log(title='logs', border_color=5),
|
||||
)
|
||||
)
|
||||
# access a tile by index
|
||||
log = ui.items[0].items[0]
|
||||
log.append("0 -----")
|
||||
log.append("1 Hello")
|
||||
log.append("2 -----")
|
||||
|
||||
# display/refresh the ui
|
||||
ui.display()
|
|
@ -0,0 +1,18 @@
|
|||
import curses, curses.textpad
|
||||
def setup_input():
|
||||
inp = curses.newwin(8,55, 0,0)
|
||||
inp.addstr(1,1, "Please enter your username:")
|
||||
sub = inp.subwin(2,1)
|
||||
sub.border()
|
||||
sub2 = sub.subwin(3,2)
|
||||
global tb
|
||||
tb = curses.textpad.Textbox(sub2)
|
||||
inp.refresh()
|
||||
tb.edit(enter_is_terminate)
|
||||
|
||||
def enter_is_terminate(x):
|
||||
if x == 10:
|
||||
tb.do_command(7)
|
||||
tb.do_command(x)
|
||||
|
||||
setup_input()
|
|
@ -1,73 +1,89 @@
|
|||
from time import sleep, time
|
||||
import math
|
||||
import curses
|
||||
from curses.textpad import Textbox, rectangle
|
||||
|
||||
|
||||
|
||||
def draw_main_menu(stdscr):
|
||||
# Command is the last char the user entered.
|
||||
command = 0
|
||||
|
||||
# Clear, and refresh the screen
|
||||
stdscr.clear()
|
||||
stdscr.refresh()
|
||||
|
||||
# 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)
|
||||
|
||||
while command != ord('q'):
|
||||
# Clear the screen
|
||||
stdscr.clear()
|
||||
# Get the height, and width
|
||||
height, width = stdscr.getmaxyx()
|
||||
|
||||
|
||||
# Temporary strings, replace these with libdocs!
|
||||
title = 'Untitled Adventure Game PRE ALPHA'[:width - 1]
|
||||
subtitle = 'Joe Sedutto'[:width - 1]
|
||||
statusbarstr = "Press 'q' to exit "
|
||||
|
||||
# Centering calculations
|
||||
start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2)
|
||||
start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2)
|
||||
start_y = int((height // 2) - 2)
|
||||
|
||||
# Rendering some text
|
||||
whstr = 'Width: {}, Height: {}'.format(width, height)
|
||||
stdscr.addstr(0, 0, whstr, curses.color_pair(1))
|
||||
|
||||
# Render status bar
|
||||
stdscr.attron(curses.color_pair(3))
|
||||
stdscr.addstr(height - 1, 0, statusbarstr)
|
||||
stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1))
|
||||
stdscr.attroff(curses.color_pair(3))
|
||||
|
||||
# Turning on attributes for title
|
||||
stdscr.attron(curses.color_pair(2))
|
||||
stdscr.attron(curses.A_BOLD)
|
||||
|
||||
# Rendering title
|
||||
stdscr.addstr(start_y, start_x_title, title)
|
||||
|
||||
# Turning off attributes for title
|
||||
stdscr.attroff(curses.color_pair(2))
|
||||
stdscr.attroff(curses.A_BOLD)
|
||||
|
||||
# Print rest of text
|
||||
stdscr.addstr(start_y + 1, start_x_subtitle, subtitle)
|
||||
stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4)
|
||||
|
||||
# Refresh the screen
|
||||
stdscr.refresh()
|
||||
|
||||
# Wait for next input
|
||||
command = stdscr.getch()
|
||||
|
||||
|
||||
def main_textbox(stdscr):
|
||||
stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)")
|
||||
|
||||
editwin = curses.newwin(5,30, 2,1)
|
||||
rectangle(stdscr, 1,0, 1+5+1, 1+30+1)
|
||||
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)
|
||||
|
||||
from dashing import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
ui = HSplit(
|
||||
VSplit(
|
||||
HGauge(val=50, title="only title", border_color=5),
|
||||
HGauge(label="only label", val=20, border_color=5),
|
||||
HGauge(label="only label", val=30, border_color=5),
|
||||
HGauge(label="only label", val=50, border_color=5),
|
||||
HGauge(label="only label", val=80, border_color=5),
|
||||
HGauge(val=20),
|
||||
HGauge(label="label, no border", val=55),
|
||||
HSplit(
|
||||
VGauge(val=0, border_color=2),
|
||||
VGauge(val=5, border_color=2),
|
||||
VGauge(val=30, border_color=2),
|
||||
VGauge(val=50, border_color=2),
|
||||
VGauge(val=80, border_color=2, color=4),
|
||||
VGauge(val=95, border_color=2, color=3),
|
||||
ColorRangeVGauge(
|
||||
val=100,
|
||||
border_color=2,
|
||||
colormap=(
|
||||
(33, 2),
|
||||
(66, 3),
|
||||
(100, 1),
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
VSplit(
|
||||
Text('Hello World,\nthis is dashing.', border_color=2),
|
||||
Log(title='logs', border_color=5),
|
||||
VChart(border_color=2, color=2),
|
||||
HChart(border_color=2, color=2),
|
||||
HBrailleChart(border_color=2, color=2),
|
||||
# HBrailleFilledChart(border_color=2, color=2),
|
||||
),
|
||||
title='Dashing',
|
||||
)
|
||||
log = ui.items[1].items[1]
|
||||
vchart = ui.items[1].items[2]
|
||||
hchart = ui.items[1].items[3]
|
||||
bchart = ui.items[1].items[4]
|
||||
# bfchart = ui.items[1].items[5]
|
||||
log.append("0 -----")
|
||||
log.append("1 Hello")
|
||||
log.append("2 -----")
|
||||
prev_time = time()
|
||||
for cycle in range(0, 200):
|
||||
ui.items[0].items[0].value = int(50 + 49.9 * math.sin(cycle / 80.0))
|
||||
ui.items[0].items[1].value = int(50 + 45 * math.sin(cycle / 20.0))
|
||||
ui.items[0].items[2].value = int(50 + 45 * math.sin(cycle / 30.0 + 3))
|
||||
|
||||
vgauges = ui.items[0].items[-1].items
|
||||
for gaugenum, vg in enumerate(vgauges):
|
||||
vg.value = 50 + 49.9 * math.sin(cycle / 12.0 + gaugenum)
|
||||
|
||||
t = int(time())
|
||||
if t != prev_time:
|
||||
log.append("%s" % t)
|
||||
prev_time = t
|
||||
vchart.append(50 + 50 * math.sin(cycle / 16.0))
|
||||
hchart.append(99.9 * abs(math.sin(cycle / 26.0)))
|
||||
bchart.append(50 + 50 * math.sin(cycle / 6.0))
|
||||
# bfchart.append(50 + 50 * math.sin(cycle / 16.0))
|
||||
ui.display()
|
||||
|
||||
sleep(1.0/25)
|
||||
main()
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
from blessed import Terminal
|
||||
import time
|
||||
|
||||
term = Terminal()
|
||||
|
||||
for x in range(10):
|
||||
for y in range(10):
|
||||
print(term.move_xy(x, y) + '*')
|
||||
time.sleep(0.1)
|
|
@ -0,0 +1,86 @@
|
|||
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