예제 #1
0
 def showAlt(self):
     unicurses.waddstr(self.scr.win, "Type a command key: ")
     while True:
         key = chr(self.scr.getch(self.scr.win))
         if key in self.keymap and False not in self.keymap[key]['alt']:
             self.runact(self.keymap[key], self.keymap[key]['alt'])
             break
예제 #2
0
 def showLineEdit(self, sel, quiet):
     maxwidth = 4096
     fw, hw = self.scr.w - 2, (self.scr.w - 2) / 2
     unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ")
     unicurses.noutrefresh(self.scr.win)
     (yn, xn) = unicurses.getyx(self.scr.win)
     buf = unicurses.newpad(1, maxwidth + 1)
     unicurses.keypad(buf, 1)
     offs, length, submit = 0, 0, False
     if not quiet and sel['val'] != None and sel['val'] != (None, ):
         length = len(sel['val'])
         unicurses.waddstr(buf, sel['val'])
         offs = max(0, length / hw - 1)
         (yb, xb) = unicurses.getbegyx(self.scr.win)
         (yp, xp) = (yn + yb, xn + xb)
         unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1)
     unicurses.doupdate()
     while True:
         if quiet: ch = self.scr.getch(buf, redact=True)
         else:
             etc = (buf, 0, offs * hw, yn, xn, yn, xn + fw - 1)
             ch = self.scr.getch(buf, etc)
         (y, x) = unicurses.getyx(buf)
         if ch in (ord('\n'), unicurses.KEY_ENTER):
             sel['val'] = unicurses.mvwinstr(buf, 0, 0, length)
             if sel['val'] != None and len(sel['val']) == 0:
                 sel['val'] = None
             submit = True
             break
         elif ch == ord('\x1b'):
             break
         elif ch == unicurses.KEY_HOME and x > 0:
             unicurses.wmove(buf, y, 0)
         elif ch == unicurses.KEY_END and x < length:
             unicurses.wmove(buf, y, length)
         elif ch == unicurses.KEY_LEFT and x > 0:
             unicurses.wmove(buf, y, x - 1)
         elif ch == unicurses.KEY_RIGHT and x < length:
             unicurses.wmove(buf, y, x + 1)
         elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE,
                     unicurses.KEY_DC) and x > 0:
             unicurses.wmove(buf, y, x - 1)
             unicurses.wdelch(buf)
             length -= 1
         elif ord(' ') <= ch <= ord('~') and length < maxwidth:
             unicurses.winsstr(buf, chr(ch))
             length += 1
             unicurses.wmove(buf, y, x + 1)
         else:
             continue
         if quiet: continue
         oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1] / hw - 1)
         if oldoffs < offs and maxwidth - offs * hw < fw:
             unicurses.wclrtoeol(self.scr.win)
             unicurses.noutrefresh(self.scr.win)
         (yb, xb) = unicurses.getbegyx(self.scr.win)
         (yp, xp) = (yn + yb, xn + xb)
         unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1)
         unicurses.doupdate()
     return submit
예제 #3
0
def write(scrid, text, ypos, xpos, color="white"):
    uni.setsyx(ypos, xpos)
    uni.waddstr(scrid, text)
    uni.setsyx(0, 0)
    uni.refresh()
    uni.update_panels()
    uni.doupdate()
예제 #4
0
    def __init__(self,
                 stdscr,
                 body,
                 foreground=None,
                 background=None,
                 attribute=0):
        self.max_x = stdscr.getmaxyx()[1] - 1
        self.max_y = stdscr.getmaxyx()[0] - 1

        self.x = self.max_x // 2
        self.y = self.max_y // 2

        self.body = body

        del stdscr

        # CREATE --------------------------------
        self.window = curses.newwin(1, 1, self.y, self.x)
        curses.waddstr(self.window, self.body)
        self.panel = curses.new_panel(self.window)

        self.foreground = foreground
        self.background = background

        self.color = 0
        self.attribute = attribute

        if foreground is not None and background is not None:
            self.set_colors(foreground, background)

        self.show_changes()
예제 #5
0
 def showAlt(self):
     unicurses.waddstr(self.scr.win, "Type a command key: ")
     while True:
         key = chr(self.scr.getch(self.scr.win))
         if key in self.keymap and False not in self.keymap[key]['alt']:
             self.runact(self.keymap[key], self.keymap[key]['alt'])
             break
예제 #6
0
    def draw_title(self):
        offset_x = 2
        offset_y = 1

        uc.box(self.win_title, 0, 0)
        uc.wmove(self.win_title, offset_y, offset_x)
        uc.waddstr(self.win_title, self.title)
        uc.wrefresh(self.win_title)
예제 #7
0
    def __init__(self):
        self.win = uc.newwin(10, 30, 0, 0)
        uc.box(self.win)
        uc.wmove(self.win, 1, 1)
        uc.waddstr(self.win, "Tile Info")

        panel = uc.new_panel(self.win)
        uc.move_panel(panel, glob.CAM_HEIGHT, 62)
예제 #8
0
 def showLineEdit(self, sel, quiet):
     maxwidth = 4096
     fw, hw = self.scr.w - 2, (self.scr.w - 2)/2
     unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ")
     unicurses.noutrefresh(self.scr.win)
     (yn, xn) = unicurses.getyx(self.scr.win)
     buf = unicurses.newpad(1, maxwidth + 1)
     unicurses.keypad(buf, 1)
     offs, length, submit = 0, 0, False
     if not quiet and sel['val'] != None:
         length = len(sel['val'])
         unicurses.waddstr(buf, sel['val'])
         offs = max(0, length/hw - 1)
         (yb, xb) = unicurses.getbegyx(self.scr.win)
         (yp, xp) = (yn + yb, xn + xb)
         unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1)
     unicurses.doupdate()
     while True:
         if quiet: ch = self.scr.getch(buf)
         else:
             etc = (buf, 0, offs*hw, yn, xn, yn, xn + fw - 1)
             ch = self.scr.getch(buf, etc)
         (y, x) = unicurses.getyx(buf)
         if ch in (ord('\n'), unicurses.KEY_ENTER):
             sel['val'] = unicurses.mvwinstr(buf, 0, 0, length)
             if sel['val'] != None and len(sel['val']) == 0:
                 sel['val'] = None
             submit = True
             break
         elif ch == ord('\x1b'): break
         elif ch == unicurses.KEY_HOME and x > 0:
             unicurses.wmove(buf, y, 0)
         elif ch == unicurses.KEY_END and x < length:
             unicurses.wmove(buf, y, length)
         elif ch == unicurses.KEY_LEFT and x > 0:
             unicurses.wmove(buf, y, x - 1)
         elif ch == unicurses.KEY_RIGHT and x < length:
             unicurses.wmove(buf, y, x + 1)
         elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE,
                     unicurses.KEY_DC) and x > 0:
             unicurses.wmove(buf, y, x - 1)
             unicurses.wdelch(buf)
             length -= 1
         elif ord(' ') <= ch <= ord('~') and length < maxwidth:
             unicurses.winsstr(buf, chr(ch))
             length += 1
             unicurses.wmove(buf, y, x + 1)
         else: continue
         if quiet: continue
         oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1]/hw - 1)
         if oldoffs < offs and maxwidth - offs*hw < fw:
             unicurses.wclrtoeol(self.scr.win)
             unicurses.noutrefresh(self.scr.win)
         (yb, xb) = unicurses.getbegyx(self.scr.win)
         (yp, xp) = (yn + yb, xn + xb)
         unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1)
         unicurses.doupdate()
     return submit
예제 #9
0
    def set_colors(self, foreground, background):
        self.color = make_color(foreground, background)
        self.foreground = foreground
        self.background = background

        curses.waddstr(self.window, self.body,
                       curses.color_pair(self.color) + self.attribute)

        self.show_changes()
예제 #10
0
 def write(self, strings):
     row = 2
     for s in strings:
         s +=(" " * (28-len(s))) #fill extra with spaces
         uc.wmove(self.win, row, 1)
         uc.waddstr(self.win, s)
         row +=1
     #clear the remaining rows
     filler_str = " "*28
     for i in range(row, 10):
         uc.wmove(self.win, row, 1)
         uc.waddstr(self.win, filler_str) 
예제 #11
0
    def draw_boardareaarea(self):
        uc.werase(self.win_board)

        uc.box(self.win_boardarea, 0, 0)

        uc.wmove(self.win_boardarea, 1, 2)
        if self.on_menu:
            s = self.player.board.__str__()
        else:
            s = self.player.board.show_new_ship(self.new_ship_x,
                                                self.new_ship_y,
                                                self.menu[self.menu_hi].id,
                                                self.menu[self.menu_hi].length,
                                                self.new_ship_hor)

        for chr in s:
            if chr == '~':
                uc.wattron(self.win_board, uc.COLOR_PAIR(11))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(11))
            elif chr == 'O':
                uc.wattron(self.win_board, uc.COLOR_PAIR(12))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(12))
            elif chr == '#':
                uc.wattron(self.win_board, uc.COLOR_PAIR(13))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(13))
            else:
                uc.wattron(self.win_board, uc.COLOR_PAIR(12))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(12))

        uc.wrefresh(self.win_boardarea)
        uc.update_panels()
예제 #12
0
 def showHelp(self):
     string = "Type a command key for contextual help: "
     unicurses.waddstr(self.scr.win, string)
     while True:
         try:
             key = chr(self.scr.getch(self.scr.win))
         except ValueError:
             continue
         if key in self.keymap and self.keymap[key]['help'] != None:
             if self.keymap[key]['help'] == False: break
             unicurses.wclear(self.scr.win)
             err = self.keymap[key]['stat']
             if isinstance(err, basestring):
                 attr = self.scr.attr['err']
                 unicurses.wmove(self.scr.win, self.scr.h - 1, 0)
                 unicurses.waddnstr(self.scr.win, err, self.scr.w, attr)
                 unicurses.wmove(self.scr.win, 0, 0)
             title = self.keymap[key]['text']
             title = ' ' * (self.scr.w - len(title) -
                            6) + title + " Help \n"
             unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl'])
             unicurses.waddstr(self.scr.win, self.keymap[key]['help'])
             string = "\n\nPress 'q' to exit help.\n\n"
             unicurses.waddstr(self.scr.win, string)
             while chr(self.scr.getch(self.scr.win)) != 'q':
                 pass
             break
예제 #13
0
	def draw_board(self):
		uc.wclear(self.win_board1)
		uc.wclear(self.win_baord2)

		uc.box(self.win_boardarea, 0, 0)

		uc.wmove(self.win_boardarea, 1, 2)

		s1 = self.player.board.__str__()
		s2 = self.player_enemy.board.__str__()

		for chr in s1:
			if chr == '~':
				uc.wattron(self.win_board, uc.COLOR_PAIR(11))
				uc.waddstr(self.win_board, chr)
				uc.wattroff(self.win_board, uc.COLOR_PAIR(11))
			elif chr == 'O':
				uc.wattron(self.win_board, uc.COLOR_PAIR(12))
				uc.waddstr(self.win_board, chr)
				uc.wattroff(self.win_board, uc.COLOR_PAIR(12))
			elif chr == '#':
				uc.wattron(self.win_board, uc.COLOR_PAIR(13))
				uc.waddstr(self.win_board, chr)
				uc.wattroff(self.win_board, uc.COLOR_PAIR(13))
			else:
				uc.wattron(self.win_board, uc.COLOR_PAIR(12))
				uc.waddstr(self.win_board, chr)
				uc.wattroff(self.win_board, uc.COLOR_PAIR(12))

		uc.wrefresh(self.win_boardarea)
		uc.update_panels()
예제 #14
0
 def dotstr(self, string, attr, rpad=0):
     if attr == None: attr = unicurses.A_NORMAL
     offs = unicurses.getyx(self.scr.win)[1]
     if len(string) > self.scr.w - offs - rpad:
         lstr = string[:(self.scr.w - offs - rpad)/2 - 1]
         rstr = string[-(self.scr.w - offs - rpad - len(lstr) - 3):]
         unicurses.waddstr(self.scr.win, lstr, attr)
         unicurses.waddstr(self.scr.win, "...")
         unicurses.waddstr(self.scr.win, rstr, attr)
     else: unicurses.waddstr(self.scr.win, string, attr)
예제 #15
0
    def incrementTurn(self):
        self.turn +=1
        
        uc.wmove(self.status_win, 1, 6) #6 is pos after string "Turn "
        uc.waddstr(self.status_win, str(self.turn))

        worker_old = self.world.entities[0].my_tile

        self.world.moveEntities()

        worker_new = self.world.entities[0].my_tile
        self.painter.updateTileCenter(worker_old)
        self.painter.updateTileEdges(worker_old)
        self.painter.updateTileCenter(worker_new)

        self.painter.drawWindow()

        showChanges()
예제 #16
0
 def dotstr(self, string, attr, rpad=0):
     if attr == None: attr = unicurses.A_NORMAL
     offs = unicurses.getyx(self.scr.win)[1]
     if len(string) > self.scr.w - offs - rpad:
         lstr = string[:(self.scr.w - offs - rpad) / 2 - 1]
         rstr = string[-(self.scr.w - offs - rpad - len(lstr) - 3):]
         unicurses.waddstr(self.scr.win, lstr, attr)
         unicurses.waddstr(self.scr.win, "...")
         unicurses.waddstr(self.scr.win, rstr, attr)
     else:
         unicurses.waddstr(self.scr.win, string, attr)
예제 #17
0
파일: window.py 프로젝트: Chiel92/tfate
    def draw_string(self, string, attributes=0, wrapping=False, silent=True):
        """Try to draw a string with given attributes."""
        if wrapping:
            returncode = curses.waddnstr(self.win, string, self.width, attributes)
        else:
            returncode = curses.waddstr(self.win, string, attributes)

        # End of window reached
        if returncode == curses.ERR and not silent:
            raise EndOfWin()
예제 #18
0
    def draw_statusbar(self):
        uc.wclear(self.win_statusbar)
        s = '[q] quit   '

        if self.on_menu:
            s += '[\u2191\u2193] move   '
            s += '[\u21B5] select   '
        else:
            s += '[\u2190\u2191\u2192\u2193] move   '
            s += '[r] rotate   '
            s += '[s] suggest   '
            s += '[\u21B5] commit   '

        s += f'{self.num_ships_set}/{len(self.player.ship_list)} set'

        uc.waddstr(self.win_statusbar, s)
        uc.init_pair(4, uc.COLOR_WHITE, uc.COLOR_BLUE)
        uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(4))
        uc.wrefresh(self.win_statusbar)
예제 #19
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN)

        dude = curses.newwin(1, 1, 10, 30)
        curses.waddstr(dude, "@", curses.color_pair(2) + curses.A_BOLD)
        dude_panel = curses.new_panel(dude)

        grass = curses.newwin(10, 50, 5, 5)
        grass.bkgd(" ", curses.color_pair(1))
        grass_panel = curses.new_panel(grass)

        curses.top_panel(dude_panel)

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #20
0
 def renderProgress(self, done, total):
     perc = '0%'
     if total != 0:
         perc = str(int(round(float(100*done)/float(total)))) + '%'
     rpad = self.scr.w/2 - 3
     lpad = self.scr.w - len(perc) - rpad - 2
     bar = ' '*lpad + perc + ' '*rpad
     fill = 0
     if total != 0:
         fill = int(round(float((self.scr.w - 2)*done)/float(total)))
     unicurses.waddstr(self.scr.win, " ")
     unicurses.waddstr(self.scr.win, bar[:fill], self.scr.attr['pfg'])
     unicurses.waddstr(self.scr.win, bar[fill:], self.scr.attr['pbg'])
     unicurses.waddstr(self.scr.win, "\n")
예제 #21
0
    def draw_shipmenu(self):
        uc.wclear(self.win_shipmenu)

        offset_x = 2
        offset_y = 1

        uc.box(self.win_shipmenu, 0, 0)
        uc.wmove(self.win_shipmenu, offset_y, offset_x)
        uc.waddstr(self.win_shipmenu, 'ship menu:')
        offset_y += 2

        for ele in self.menu:
            if (self.on_menu and self.menu_hi == self.menu.index(ele)):
                uc.wattron(self.win_shipmenu, uc.A_REVERSE)
                uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele)
                uc.wattroff(self.win_shipmenu, uc.A_REVERSE)
                offset_y += 2
            else:
                uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele)
                offset_y += 2

        uc.wrefresh(self.win_shipmenu)
예제 #22
0
 def renderStep(self, step):
     name, done, total, errors, artifacts = step
     stat, color = None, None
     if errors > 0: stat, color = " ! ", 'err'
     elif done >= total: stat, color = " + ", 'val'
     elif done <= 0: stat, color = "   ", 'val'
     else: stat, color = " ~ ", 'slp'
     unicurses.waddstr(self.scr.win, stat, self.scr.attr[color])
     stat = name + ' '*(15 - len(name)) + str(done) + '/' + str(total)
     if artifacts != None: stat += ", " + str(artifacts) + " Total"
     if errors > 0: stat += ", "
     unicurses.waddstr(self.scr.win, stat)
     if errors > 0:
         stat = str(errors) + " Errors"
         unicurses.waddstr(self.scr.win, stat, self.scr.attr['err'])
     unicurses.waddstr(self.scr.win, "\n")
예제 #23
0
 def showHelp(self):
     string = "Type a command key for contextual help: "
     unicurses.waddstr(self.scr.win, string)
     while True:
         key = chr(self.scr.getch(self.scr.win))
         if key in self.keymap and self.keymap[key]['help'] != None:
             if self.keymap[key]['help'] == False: break
             unicurses.wclear(self.scr.win)
             title = self.keymap[key]['text']
             title = ' '*(self.scr.w - len(title) - 6) + title + " Help \n"
             unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl'])
             unicurses.waddstr(self.scr.win, self.keymap[key]['help'])
             string = "\n\nPress 'q' to exit help.\n\n"
             unicurses.waddstr(self.scr.win, string)
             while chr(self.scr.getch(self.scr.win)) != 'q': pass
             break
예제 #24
0
 def showHelp(self):
     string = "Type a command key for contextual help: "
     unicurses.waddstr(self.scr.win, string)
     while True:
         key = chr(self.scr.getch(self.scr.win))
         if key in self.keymap and self.keymap[key]['help'] != None:
             if self.keymap[key]['help'] == False: break
             unicurses.wclear(self.scr.win)
             title = self.keymap[key]['text']
             title = ' ' * (self.scr.w - len(title) - 6) + title + " Help "
             unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl'])
             unicurses.waddstr(self.scr.win, self.keymap[key]['help'])
             string = "\n\nPress 'q' to exit help.\n\n"
             unicurses.waddstr(self.scr.win, string)
             while chr(self.scr.getch(self.scr.win)) != 'q':
                 pass
             break
예제 #25
0
    def draw_board(self):
        uc.wclear(self.win_board)

        offset_x = 2
        offset_y = 1

        uc.box(self.win_boardarea, 0, 0)

        uc.wmove(self.win_boardarea, offset_y, offset_x)
        if self.on_menu:
            s = self.player.board.__str__()
        else:
            s = self.player.board.show_new_ship(self.new_ship_x,
                                                self.new_ship_y,
                                                self.menu[self.menu_hi].id,
                                                self.menu[self.menu_hi].length,
                                                self.new_ship_hor)

        uc.init_pair(11, uc.COLOR_BLUE, uc.COLOR_BLACK)
        uc.init_pair(12, uc.COLOR_WHITE, uc.COLOR_BLACK)
        uc.init_pair(13, uc.COLOR_RED, uc.COLOR_BLACK)

        for chr in s:
            if chr == '~':
                uc.wattron(self.win_board, uc.COLOR_PAIR(11))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(11))
            elif chr == 'O':
                uc.wattron(self.win_board, uc.COLOR_PAIR(12))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(12))
            elif chr == '#':
                uc.wattron(self.win_board, uc.COLOR_PAIR(13))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(13))
            else:
                uc.wattron(self.win_board, uc.COLOR_PAIR(12))
                uc.waddstr(self.win_board, chr)
                uc.wattroff(self.win_board, uc.COLOR_PAIR(12))

        uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(11))

        uc.wrefresh(self.win_boardarea)
        uc.update_panels()
예제 #26
0
 def renderStep(self, stepn, step):
     name, done, total, errors, artifacts = step
     stat, color = None, None
     if errors > 0: stat, color = " ! ", 'err'
     elif stepn < self.currentstep: stat, color = " + ", 'val'
     elif stepn > self.currentstep: stat, color = "   ", 'val'
     else: stat, color = " ~ ", 'slp'
     unicurses.waddstr(self.scr.win, stat, self.scr.attr[color])
     stats = []
     stat = name + ' '*(15 - len(name))
     if total != None: stats.append(str(done) + '/' + str(total))
     if artifacts != None: stats.append(str(artifacts) + " Total")
     stat += ", ".join(stats)
     if errors > 0 and len(stats) > 0: stat += ", "
     unicurses.waddstr(self.scr.win, stat)
     if errors > 0:
         stat = str(errors) + " Errors"
         unicurses.waddstr(self.scr.win, stat, self.scr.attr['err'])
     unicurses.waddstr(self.scr.win, "\n")
예제 #27
0
 def renderStep(self, step):
     name, done, total, errors, artifacts = step
     stat, color = None, None
     if errors > 0: stat, color = " ! ", 'err'
     elif done == True or (not isinstance(done, bool) and done >= total):
         stat, color = " + ", 'val'
     elif done == False or (not isinstance(done, bool) and done <= 0):
         stat, color = "   ", 'val'
     else:
         stat, color = " ~ ", 'slp'
     unicurses.waddstr(self.scr.win, stat, self.scr.attr[color])
     stats = []
     stat = name + ' ' * (15 - len(name))
     if total != None: stats.append(str(done) + '/' + str(total))
     if artifacts != None: stats.append(str(artifacts) + " Total")
     stat += ", ".join(stats)
     if errors > 0 and len(stats) > 0: stat += ", "
     unicurses.waddstr(self.scr.win, stat)
     if errors > 0:
         stat = str(errors) + " Errors"
         unicurses.waddstr(self.scr.win, stat, self.scr.attr['err'])
     unicurses.waddstr(self.scr.win, "\n")
예제 #28
0
 def showHelp(self):
     string = "Type a command key for contextual help: "
     unicurses.waddstr(self.scr.win, string)
     while True:
         try:
             key = chr(self.scr.getch(self.scr.win))
         except ValueError: continue
         if key in self.keymap and self.keymap[key]['help'] != None:
             if self.keymap[key]['help'] == False: break
             unicurses.wclear(self.scr.win)
             err = self.keymap[key]['stat']
             if isinstance(err, basestring):
                 attr = self.scr.attr['err']
                 unicurses.wmove(self.scr.win, self.scr.h - 1, 0)
                 unicurses.waddnstr(self.scr.win, err, self.scr.w, attr)
                 unicurses.wmove(self.scr.win, 0, 0)
             title = self.keymap[key]['text']
             title = ' '*(self.scr.w - len(title) - 6) + title + " Help \n"
             unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl'])
             unicurses.waddstr(self.scr.win, self.keymap[key]['help'])
             string = "\n\nPress 'q' to exit help.\n\n"
             unicurses.waddstr(self.scr.win, string)
             while chr(self.scr.getch(self.scr.win)) != 'q': pass
             break
예제 #29
0
 def render(self, result=None):
     unicurses.wclear(self.scr.win)
     unicurses.waddstr(self.scr.win, self.title, self.scr.attr['ttl'])
     tdone, ttotal, terror, = 0, 0, 0
     mdone, mtotal, mname, mset = 0, 0, None, False
     for step in self.steps:
         n, d, t, e, a = step
         tdone += d
         ttotal += t
         terror += e
         if mdone >= mtotal and d > 0 and not mset:
             mdone, mtotal, mname = d, t, n
         else: mset = True
         self.renderStep(step)
     unicurses.waddstr(self.scr.win, "\n Total Progress:\n")
     self.renderProgress(tdone, ttotal)
     if result != None:
         timerep = self.drawTime(int(round(time.time() - self.started)))
         msg = "\n Migration Successful!"
         unicurses.waddstr(self.scr.win, msg, self.scr.attr['val'])
         msg = "\n Completed in " + timerep
         msg += "\n\n Press 'q' to continue.\n\n"
         unicurses.waddstr(self.scr.win, msg)
         unicurses.flushinp()
         while chr(self.scr.getch(self.scr.win)) != 'q': pass
     elif mname != None:
         unicurses.waddstr(self.scr.win, "\n " + mname + " Progress:\n")
         self.renderProgress(mdone, mtotal)
         if self.current != None:
             unicurses.waddstr(self.scr.win, self.current + "\n")
         if self.currentartifact != None:
             unicurses.waddstr(self.scr.win, self.currentartifact + "\n")
         unicurses.waddstr(self.scr.win, "\n")
     else: unicurses.waddstr(self.scr.win, "\n")
예제 #30
0
    def __init__(self):
        self.turn =1
        
        #Create debugging display
        debug_win = uc.newwin(15, 30, 0, 0)
        uc.box(debug_win)
        uc.wmove(debug_win, 1, 1)
        uc.waddstr(debug_win, "Debug:")
        uc.wmove(debug_win, 2, 1)

        debug_pnl = uc.new_panel(debug_win)
        uc.move_panel(debug_pnl, glob.CAM_HEIGHT, 32)

        #Generate the world
        self.world = Map(glob.N_HEX_ROWS, glob.N_HEX_COLS, debug_win)

        #map_height: 3 + 2*(rows-1) + 2 for border
        #map_width: 5 + 4*cols + 2 for border
        map_win = uc.newwin(glob.CAM_HEIGHT, glob.CAM_WIDTH, 0, 0)


        self.painter = Painter(glob.N_HEX_ROWS, glob.N_HEX_COLS, map_win)
        self.painter.updateAllTiles(self.world)

        #Put world window into a panel
        map_pnl = uc.new_panel(map_win)
        uc.move_panel(map_pnl, 1, 1)

        uc.top_panel(debug_pnl)

        self.status_win = uc.newwin(10, 30, 0, 0)
        uc.box(self.status_win)
        uc.wmove(self.status_win, 1, 1)
        uc.waddstr(self.status_win, "Turn " + str(self.turn))

        status_pnl = uc.new_panel(self.status_win)
        uc.move_panel(status_pnl, glob.CAM_HEIGHT, 2)

        self.tile_window = TileWindow()

        self.painter.drawWindow()
        showChanges()

        
        
        #input loop
        while True:
            sys.stdout.flush()
            ch = uc.getch()
            uc.waddstr(debug_win, str(ch))
            #Exit Key
            if ch == Key.ESC:
                break
            #Movement Keys
            elif ch == Key.E:
                self.movePlayer(HexDir.UL)
            elif ch == Key.R:
                self.movePlayer(HexDir.UR)
            elif ch == Key.S:
                self.movePlayer(HexDir.L)
            elif ch == Key.G:
                self.movePlayer(HexDir.R)
            elif ch == Key.D:
                self.movePlayer(HexDir.DL)
            elif ch == Key.F:
                self.movePlayer(HexDir.DR)
            #End Turn Key
            elif ch == Key.SPACE:
                self.incrementTurn()
            #Camera Scrolling Keys
            #TBD: Remaining order checks
            elif ch == uc.KEY_UP:
                self.painter.moveCamera(0, -1*glob.CAM_SPEED)
            elif ch == uc.KEY_DOWN:
                self.painter.moveCamera(0, glob.CAM_SPEED)
            elif ch == uc.KEY_LEFT:
                self.painter.moveCamera(-1*glob.CAM_SPEED, 0)
            elif ch == uc.KEY_RIGHT:
                self.painter.moveCamera(glob.CAM_SPEED, 0)
            #Toggle drawing borders
            elif ch == Key.B:
                self.painter.draw_borders = not self.painter.draw_borders
                self.painter.updateAllTileBorders(self.world)
                self.painter.drawWindow()
예제 #31
0
 def render(self):
     unicurses.wclear(self.scr.win)
     if self.scr.msg != None:
         unicurses.wmove(self.scr.win, self.scr.h - 1, 0)
         if isinstance(self.scr.msg, basestring):
             unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w)
         elif isinstance(self.scr.msg, tuple):
             attr = self.scr.attr[self.scr.msg[0]]
             msg = self.scr.msg[1]
             unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr)
         unicurses.wmove(self.scr.win, 0, 0)
     unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl'])
     for opt in self.curropts:
         if opt == None:
             unicurses.waddstr(self.scr.win, "\n")
             continue
         key = opt['key'] + ": "
         unicurses.waddstr(self.scr.win, key, self.scr.attr['key'])
         if not isinstance(opt['val'], basestring):
             pad = 2 if opt['stat'] == False else 0
             if opt['wait'] == True or opt['val'] == True: pad += 2
             self.dotstr(opt['text'], None, pad)
         else: unicurses.waddstr(self.scr.win, opt['text'])
         attr = self.scr.attr['val']
         if opt['stat'] == False:
             attr = self.scr.attr['err']
             unicurses.waddstr(self.scr.win, " !", attr)
         if opt['wait'] == True:
             unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp'])
         elif opt['val'] == True:
             unicurses.waddstr(self.scr.win, " +", attr)
         elif isinstance(opt['val'], (basestring, list)):
             if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ")
             value = opt['val']
             if isinstance(value, list): value = ','.join(value)
             if '*' in opt['act']: value = '*'*len(value)
             self.dotstr(value, attr)
         if unicurses.getyx(self.scr.win)[1] > 0:
             unicurses.waddstr(self.scr.win, "\n")
     unicurses.waddstr(self.scr.win, "\n")
예제 #32
0
 def draw_title(self):
     uc.box(self.win_title, 0, 0)
     uc.wmove(self.win_title, 1, 2)
     uc.waddstr(self.win_title, self.str_title)
     uc.wrefresh(self.win_title)
예제 #33
0
 def render(self):
     unicurses.wclear(self.scr.win)
     if self.scr.msg != None:
         unicurses.wmove(self.scr.win, self.scr.h - 1, 0)
         if isinstance(self.scr.msg, basestring):
             unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w)
         elif isinstance(self.scr.msg, tuple):
             attr = self.scr.attr[self.scr.msg[0]]
             msg = self.scr.msg[1]
             unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr)
         unicurses.wmove(self.scr.win, 0, 0)
     unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl'])
     for opt in self.curropts:
         if opt == None:
             unicurses.waddstr(self.scr.win, "\n")
             continue
         key = opt['key'] + ": "
         unicurses.waddstr(self.scr.win, key, self.scr.attr['key'])
         if not isinstance(opt['val'], basestring):
             pad = 2 if opt['stat'] != True else 0
             if opt['wait'] == True or opt['val'] == True: pad += 2
             self.dotstr(opt['text'], None, pad)
         else:
             unicurses.waddstr(self.scr.win, opt['text'])
         attr = self.scr.attr['val']
         if opt['stat'] != True:
             attr = self.scr.attr['err']
             unicurses.waddstr(self.scr.win, " !", attr)
         if opt['wait'] == True:
             unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp'])
         elif opt['val'] == True:
             unicurses.waddstr(self.scr.win, " +", attr)
         elif opt['val'] == (None, ):
             unicurses.waddstr(self.scr.win, " unchanged",
                               self.scr.attr['slp'])
         elif isinstance(opt['val'], (basestring, list)):
             if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ")
             value = opt['val']
             if isinstance(value, list): value = ','.join(value)
             if '*' in opt['act']: value = '*' * len(value)
             self.dotstr(value, attr)
         if unicurses.getyx(self.scr.win)[1] > 0:
             unicurses.waddstr(self.scr.win, "\n")
     unicurses.waddstr(self.scr.win, "\n")