Esempio n. 1
0
def show_popup(text, title):
    global popup
    lines = [
        string for line in text.split('\n')
        for string in textwrap.wrap(line, width=MAX_MAP_WIDTH - 4)
    ]
    width = max(
        len(string) for string in lines
    ) + 4  # 1 space on each side, plus 1 line for the square on each side
    width = max(width, len(title))
    height = len(lines) + 4  # ditto
    x = (MAX_MAP_WIDTH - width) // 2
    y = (MAX_MAP_HEIGHT - height) // 2
    tcod.console_print_frame(popup, x, y, width, height, fmt=title)
    row = 0
    for line in lines:
        tcod.console_print(popup, x + 2, y + 2 + row, line)
        row += 1
    tcod.console_blit(popup, 0, 0, tcod.console_get_width(popup),
                      tcod.console_get_height(popup), 0, 0, 0)
    tcod.console_flush()
    key = tcod.console_wait_for_keypress(True)

    # destroy the popup
    tcod.console_blit(console, 0, 0, tcod.console_get_width(console),
                      tcod.console_get_height(console), 0, 0, 0)
    tcod.console_flush()
    return key
Esempio n. 2
0
def print_lyrics(panel, lyrics, active_character):
    primary_color = tcod.sea
    primary_color_dark = tcod.darkest_sea

    tcod.console_set_default_foreground(panel, primary_color)
    tcod.console_set_default_background(panel, tcod.black)

    tcod.console_set_color_control(tcod.COLCTRL_1, primary_color_dark,
                                   tcod.black)
    tcod.console_set_color_control(tcod.COLCTRL_2, tcod.black, primary_color)

    lyrics_pre_active = '%c{}%c'.format(
        lyrics[:active_character]) % (tcod.COLCTRL_1, tcod.COLCTRL_STOP)
    lyrics_active = '%c{}%c'.format(
        lyrics[active_character]) % (tcod.COLCTRL_2, tcod.COLCTRL_STOP)
    lyrics_post_active = lyrics[active_character + 1:]
    formatted_lyrics = lyrics_pre_active + lyrics_active + lyrics_post_active

    x = int(tcod.console_get_width(panel) / 2)
    y = 1
    w = tcod.console_get_width(panel) - 8
    h = tcod.console_get_height(panel)

    tcod.console_print_rect_ex(panel, x, y, w, h, tcod.BKGND_SET, tcod.CENTER,
                               formatted_lyrics)
Esempio n. 3
0
def offscreen(console):
    """Return an off-screen console with the same size as the root console."""
    offscreen = libtcodpy.console_new(
        libtcodpy.console_get_width(console),
        libtcodpy.console_get_height(console),
        )
    yield offscreen
    libtcodpy.console_delete(offscreen)
Esempio n. 4
0
 def initGui(self) :
   self._gui = gui.Gui(self.console)
   
   infoWidth = libtcod.console_get_width(self.console) - (2 + self._world.width)
   infoHeight = 10
   
   #Our list of frames
   self._gui.addFrame(0,0,self._world.width + 1, libtcod.console_get_height(self.console), 'Main')
   self._gui.addFrame(self._world.width + 1,0,infoWidth,infoHeight,'Info')
Esempio n. 5
0
def assertConsolesEqual(a, b):
    for y in range(libtcodpy.console_get_height(a)):
        for x in range(libtcodpy.console_get_width(a)):
            assert libtcodpy.console_get_char(a, x, y) == \
                libtcodpy.console_get_char(b, x, y)
            assert libtcodpy.console_get_char_foreground(a, x, y) == \
                libtcodpy.console_get_char_foreground(b, x, y)
            assert libtcodpy.console_get_char_background(a, x, y) == \
                libtcodpy.console_get_char_background(b, x, y)
Esempio n. 6
0
 def __init__(self, width=20, height=10, console_id=None):
     if console_id is None:
         self.console_id = libtcod.console_new(width, height)
         self.width = width
         self.height = height
     else:
         self.console_id = console_id
         self.width = libtcod.console_get_width(console_id)
         self.height = libtcod.console_get_height(console_id)
Esempio n. 7
0
def test_console_buffer(console):
    buffer = libtcodpy.ConsoleBuffer(
        libtcodpy.console_get_width(console),
        libtcodpy.console_get_height(console),
    )
    buffer = buffer.copy()
    buffer.set_fore(0, 0, 0, 0, 0, '@')
    buffer.set_back(0, 0, 0, 0, 0)
    buffer.set(0, 0, 0, 0, 0, 0, 0, 0, '@')
    buffer.blit(console)
Esempio n. 8
0
def render_all(map_knowledge, los_map, player, message_log, turn_state):
    global console
    tcod.console_clear(console)

    render_map(console, map_knowledge, los_map)
    render_ui(console, player, turn_state)
    render_messages(console, message_log, turn_state)

    tcod.console_blit(console, 0, 0, tcod.console_get_width(console),
                      tcod.console_get_height(console), 0, 0, 0)
    tcod.console_flush()
Esempio n. 9
0
def session_console():
    libtcodpy.console_set_custom_font(FONT_FILE)
    console = libtcodpy.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER)

    assert libtcodpy.console_get_width(console) == WIDTH
    assert libtcodpy.console_get_height(console) == HEIGHT
    assert libtcodpy.console_is_fullscreen() == FULLSCREEN
    libtcodpy.console_set_window_title(TITLE)
    assert not libtcodpy.console_is_window_closed()

    libtcodpy.sys_get_current_resolution()
    libtcodpy.sys_get_char_size()
    libtcodpy.sys_set_renderer(RENDERER)
    libtcodpy.sys_get_renderer()

    yield console
    libtcodpy.console_delete(console)
Esempio n. 10
0
def test_console_fill(console):
    width = libtcodpy.console_get_width(console)
    height = libtcodpy.console_get_height(console)
    fill = [i % 256 for i in range(width * height)]
    libtcodpy.console_fill_background(console, fill, fill, fill)
    libtcodpy.console_fill_foreground(console, fill, fill, fill)
    libtcodpy.console_fill_char(console, fill)

    # verify fill
    bg, fg, ch = [], [], []
    for y in range(height):
        for x in range(width):
            bg.append(libtcodpy.console_get_char_background(console, x, y)[0])
            fg.append(libtcodpy.console_get_char_foreground(console, x, y)[0])
            ch.append(libtcodpy.console_get_char(console, x, y))
    assert fill == bg
    assert fill == fg
    assert fill == ch
Esempio n. 11
0
def test_console_fill_numpy(console):
    width = libtcodpy.console_get_width(console)
    height = libtcodpy.console_get_height(console)
    fill = numpy.zeros((height, width), dtype=numpy.intc)
    for y in range(height):
        fill[y, :] = y % 256

    libtcodpy.console_fill_background(console, fill, fill, fill)
    libtcodpy.console_fill_foreground(console, fill, fill, fill)
    libtcodpy.console_fill_char(console, fill)

    # verify fill
    bg = numpy.zeros((height, width), dtype=numpy.intc)
    fg = numpy.zeros((height, width), dtype=numpy.intc)
    ch = numpy.zeros((height, width), dtype=numpy.intc)
    for y in range(height):
        for x in range(width):
            bg[y, x] = libtcodpy.console_get_char_background(console, x, y)[0]
            fg[y, x] = libtcodpy.console_get_char_foreground(console, x, y)[0]
            ch[y, x] = libtcodpy.console_get_char(console, x, y)
    fill = fill.tolist()
    assert fill == bg.tolist()
    assert fill == fg.tolist()
    assert fill == ch.tolist()
Esempio n. 12
0
def width(): return dlib.console_get_width(None)

def height(): return dlib.console_get_height(None)
Esempio n. 13
0
File: ui.py Progetto: vedun-z/ggrl
 def get_console_width(console):        
     return libtcod.console_get_width(console)
Esempio n. 14
0
 def draw(self, con):
     lbt.console_print_ex(con,
                          lbt.console_get_width(con) / 2,
                          lbt.console_get_height(con) / 2,
                          lbt.BKGND_NONE, lbt.CENTER, 
                          "Start the game by pressing enter!")
Esempio n. 15
0
 def draw(self, con):
     lbt.console_print_ex(con,
                          lbt.console_get_width(con) / 2,
                          lbt.console_get_height(con) / 2, 
                          lbt.BKGND_NONE, lbt.CENTER,
                          "You have lost! Press enter to restart!")
Esempio n. 16
0
 def render(self, console=False, export=False):
     
     if not self._displayWidth or not self._displayHeight:
         print ('ERROR: Display dimensions not set, can not render Map.')
         sys.exit()
     if (self.width < self._displayWidth or self.height < self._displayHeight):
         print ('ERROR: Map size smaller than display size.')
         sys.exit()
     
     
     if console == False:
         console = self._displayCon
     
     if export:
         _offsetX = 0
         _offsetY = 0
         zoom = 0
     else:
         _offsetX = self._offsetX
         _offsetY = self._offsetY
         zoom = self._zoomLevel
     
     
     for cy in range(0, tcod.console_get_height(console) ):
         for cx in range(0, tcod.console_get_width(console) ):
             
             mx = cx + _offsetX
             my = cy + _offsetY
             
             c = self.coords[mx][my]
             
             tcod.console_put_char_ex(
                 console, cx, cy, 
                 c.char, 
                 c.fg(), c.bg())
             
             
             if (self._displayOverlay != None):
                 #TODO: generate overlays once, and move this stuff to the display layer.
                 if (self._displayOverlay == self.OVERLAY_TEMP):
                     
                     bgOverlay = c.tempColor
                 
                 elif (self._displayOverlay == self.OVERLAY_SALT):
                     
                     bgOverlay = c.saltColor
                 
                 elif (self._displayOverlay == self.OVERLAY_RAIN):
                     
                     bgOverlay = c.rainColor
                 
                 elif (self._displayOverlay == self.OVERLAY_BIOME):
                     
                     bgOverlay = c.biome.overlayColor
                 
                 
                 tcod.console_set_back(console, cx, cy, bgOverlay, tcod.BKGND_ALPHA(0.8))
             
             
     if not export:
         
         if ( self._zoomLevel == 0):
             height = self.height
             width = self.width
         elif (self._zoomLevel == 1):
             height = self.height/self.zoomFactor # / self.zoomLevel, right??
             width = self.width/self.zoomFactor
         
         if (self._selectedY <= self._displayHeight/2):
             self._hudY = self._selectedY
         elif (self._selectedY >= height - self._displayHeight/2):
             self._hudY = \
                 self._displayHeight/2 + (self._selectedY - (height - self._displayHeight/2))
         
         if ( self.showCrosshair ):
             if (self._selectedX <= self._displayWidth/2):
                 self._hudX = self._selectedX
             elif (self._selectedX >= width - self._displayWidth/2):
                 self._hudX = self._displayWidth - (width - self._selectedX)
             
             tcod.console_put_char(console, self._hudX, self._hudY, 'X', tcod.BKGND_NONE)
             tcod.console_set_fore(console, self._hudX, self._hudY, tcod.Color(255, 0, 127))
         
         
         if (self._displayStats):
             self._printStats(console)
     
     return console
Esempio n. 17
0
 def initGui(self) :
   self._gui = gui.Gui(self.console)
   self._gui.addFrame(0,0,libtcod.console_get_width(self.console) - 1, libtcod.console_get_height(self.console), 'You have died!')
   self._gui.frames['You have died!'].setFrameColor('white')
Esempio n. 18
0
def message(msg, color=libtcod.white, console=msg_con):
    msg_width = libtcod.console_get_width(console)
    msg_lines = textwrap.wrap(msg, msg_width)

    for line in reversed(msg_lines):
        messages.append((line, color))
Esempio n. 19
0
 def width(self):
     return dlib.console_get_width(self._intern)
Esempio n. 20
0
def message(msg, color=libtcod.white, console=msg_con):
    msg_width = libtcod.console_get_width(console)
    msg_lines = textwrap.wrap(msg, msg_width)

    for line in reversed(msg_lines):
        messages.append((line, color))
Esempio n. 21
0
def renderWires(ww):
    con = ww.getConsole()
    conW = libtcod.console_get_width(con)
    conH = libtcod.console_get_height(con)
    root = 0
    libtcod.console_blit(con, 0, 0, conW, conH, root, 0, 0)
Esempio n. 22
0
    def render(self, console=False, export=False):

        if not self._displayWidth or not self._displayHeight:
            print('ERROR: Display dimensions not set, can not render Map.')
            sys.exit()
        if (self.width < self._displayWidth
                or self.height < self._displayHeight):
            print('ERROR: Map size smaller than display size.')
            sys.exit()

        if console == False:
            console = self._displayCon

        if export:
            _offsetX = 0
            _offsetY = 0
            zoom = 0
        else:
            _offsetX = self._offsetX
            _offsetY = self._offsetY
            zoom = self._zoomLevel

        for cy in range(0, tcod.console_get_height(console)):
            for cx in range(0, tcod.console_get_width(console)):

                mx = cx + _offsetX
                my = cy + _offsetY

                c = self.coords[mx][my]

                tcod.console_put_char_ex(console, cx, cy, c.char, c.fg(),
                                         c.bg())

                if (self._displayOverlay != None):
                    #TODO: generate overlays once, and move this stuff to the display layer.
                    if (self._displayOverlay == self.OVERLAY_TEMP):

                        bgOverlay = c.tempColor

                    elif (self._displayOverlay == self.OVERLAY_SALT):

                        bgOverlay = c.saltColor

                    elif (self._displayOverlay == self.OVERLAY_RAIN):

                        bgOverlay = c.rainColor

                    elif (self._displayOverlay == self.OVERLAY_BIOME):

                        bgOverlay = c.biome.overlayColor

                    tcod.console_set_back(console, cx, cy, bgOverlay,
                                          tcod.BKGND_ALPHA(0.8))

        if not export:

            if (self._zoomLevel == 0):
                height = self.height
                width = self.width
            elif (self._zoomLevel == 1):
                height = self.height / self.zoomFactor  # / self.zoomLevel, right??
                width = self.width / self.zoomFactor

            if (self._selectedY <= self._displayHeight / 2):
                self._hudY = self._selectedY
            elif (self._selectedY >= height - self._displayHeight / 2):
                self._hudY = \
                    self._displayHeight/2 + (self._selectedY - (height - self._displayHeight/2))

            if (self.showCrosshair):
                if (self._selectedX <= self._displayWidth / 2):
                    self._hudX = self._selectedX
                elif (self._selectedX >= width - self._displayWidth / 2):
                    self._hudX = self._displayWidth - (width - self._selectedX)

                tcod.console_put_char(console, self._hudX, self._hudY, 'X',
                                      tcod.BKGND_NONE)
                tcod.console_set_fore(console, self._hudX, self._hudY,
                                      tcod.Color(255, 0, 127))

            if (self._displayStats):
                self._printStats(console)

        return console