コード例 #1
0
ファイル: rl.py プロジェクト: N3U2O/The-Passage
 def render(self,
       draw_frame=False, draw_index=False,
       align='left', fgalpha=.9, bgalpha=.3):
   if len(self.opts) > MAX_OPTS:
     raise ValueError('No more than %d options allowed.' % MAX_OPTS)
   # calculate height, set options window, print header
   _w, _h = self.width+2, self.h+2   #total width and height
   window = tl.console_new(_w, _h)
   tl.console_clear(window)
   tl.console_set_default_background(window, tl.violet)
   tl.console_set_default_foreground(window, tl.lightest_grey)
   if draw_frame: tl.console_print_frame(window, 0, 0, _w, _h)
   tl.console_print_rect_ex(window, 1,1, self.width,self.h, tl.BKGND_NONE,tl.LEFT,
               self.header)
   if self.opts != []:  # draw a separator line if options are not empty
     tl.console_hline(window, 1, self.headerHeight+1, self.width)
     if draw_frame:
       tl.console_put_char(window, 0, self.headerHeight+1, tl.CHAR_TEEE)
       tl.console_put_char(window, self.width+1, self.headerHeight+1, tl.CHAR_TEEW)
     # print all options
     n,y = 0,self.headerHeight+2
     sel = self.highlightedItemIdx if self.highlightedItemIdx >= 0 else MAX_OPTS+self.highlightedItemIdx
     for txt in self.opts:
       txt = txt.rjust(self.width) if align=='right'\
         else txt.center(self.width) if align=='center'\
         else '   '+txt.ljust(self.width)[:-3] if draw_index\
         else txt.ljust(self.width)
       if draw_index:
         txt = ' %d %s' % (n, txt)
         txt = '{'+txt[1]+'}'+txt[6:] if sel == n else txt[3:]
       scolor = 'amber' if sel == n else 'light_grey'
       if self.isAnimated and sel == n:
         # hicky-hacky color animation
         scolor = tl.amber*(self.phase/PHASES)
         tl.console_set_color_control(tl.COLCTRL_1, scolor, tl.black)
         txt = '%c%s%c'%(tl.COLCTRL_1,txt.ljust(self.width),tl.COLCTRL_STOP)
       else:
         txt = tc.parse('{{%s}}%s{{stop}}'%(scolor,txt.ljust(self.width)))
       tl.console_print(window, 1, y, txt)
       n += 1; y += 1
   # calculate window position, blit window to screen & flush
   x = SCREEN_W/2 - self.width/2
   y = SCREEN_H/2 - self.h/2
   tl.console_blit(window, 0, 0, _w, _h, 0, x, y, fgalpha, bgalpha)
コード例 #2
0
ファイル: rl.py プロジェクト: N3U2O/The-Passage
##constants
SCREEN_W = 80                               # default screen dimensions
SCREEN_H = 50

INTRO = False                               # show libtcod logo?

MENU_W = 30                                 # default menu width

GAME_TITLE      = ' ~ The Passage ~ '
GAME_AUTHOR     = 'Adeee'
GAME_VERSION    = 'v0.08.01a (24/09/2013)'

# default title color and format
TITLE = tc.parse(
    '{{yellow}}%s{{stop}}'
    % GAME_TITLE.center(MENU_W))

MAX_OPTS = 20                               # limit of menu options list length

WAIT = False                                # 'real-time' mode, baby! ;)
# WAIT = True                               # 'turn-based' mode -->!!buggy!!
LIMFPS = 60                                 # FPS limit
PHASES = LIMFPS/1.5                         # number of blinking animation phases

# A class for a menu object with adjustable header, options, width and optional animation
class Menu:
  # constructor: initializes header, etc.
  def __init__(
      self,
      header='',