예제 #1
0
 def draw(self, color=rl.white):
     oldColor = rl.console_get_default_foreground(0)  # Store old color.
     rl.console_set_default_foreground(0, color)  # Apply window's color.
     rl.console_rect(0, self.x, self.y, self.w, self.h,
                     True)  # Reset background color for the box.
     # Draw the corners.
     rl.console_put_char_ex(0, self.x, self.y, rl.CHAR_DNW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1, self.y, rl.CHAR_DNE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x, self.y + self.h - 1, rl.CHAR_DSW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1,
                            self.y + self.h - 1, rl.CHAR_DSE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     # Draw the walls.
     for i in range(self.y + 1, self.y + self.h - 1):
         rl.console_put_char_ex(0, self.x, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.x + 1, self.x + self.w - 1):
         rl.console_put_char_ex(0, i, self.y, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 1, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     if self.title != None:  # Draw the title, if present.
         rl.console_print(0, self.x + 2, self.y, " {0} ".format(self.title))
     rl.console_set_default_foreground(
         0, oldColor)  # Revert color before drawing rest of window.
     for i, option in enumerate(
             self.options[self.optOffset:min(self.optOffset +
                                             self.optCap, len(self.options)
                                             )]):  # Draw the options.
         rl.console_print(0, self.x + 4, self.y + 1 + i, option)
     rl.console_print(0, self.x + 2,
                      self.y + 1 + self.selectedOption - self.optOffset,
                      chr(rl.CHAR_ARROW2_E))
     # Draw scroll arrows as needed.
     if int(time.clock() * 2) % 2 == 0:
         if self.optOffset > 0:
             rl.console_print(0, self.x + int(self.w / 2), self.y,
                              chr(rl.CHAR_ARROW2_N))
         if self.optOffset + self.optCap < len(self.options):
             rl.console_print(0, self.x + int(self.w / 2),
                              self.y + self.h - 1, chr(rl.CHAR_ARROW2_S))
예제 #2
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green,
                                      libtcod.black)
    libtcod.console_print(
        stat_con, 1, 1, "Position: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2,
                          "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(
        stat_con, 1, 5, "Mouse: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy,
         libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7,
                          "Current depth: " + str(current_depth))
    libtcod.console_print(
        stat_con, 1, 10,
        "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") %
                               (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
예제 #3
0
def display_text(console, text, x=0, y=0, front=tcod.white, back=tcod.black):
    previous_back = tcod.console_get_default_background(console)
    previous_fore = tcod.console_get_default_foreground(console)
    tcod.console_set_default_background(console, back)
    tcod.console_set_default_foreground(console, front)
    tcod.console_print_ex(console, x, y, tcod.BKGND_SET, tcod.LEFT, text)
    tcod.console_set_default_background(console, previous_back)
    tcod.console_set_default_foreground(console, previous_fore)
예제 #4
0
def display_text(console, text, x=0, y=0, front=tcod.white, back=tcod.black):
    previous_back = tcod.console_get_default_background(console)
    previous_fore = tcod.console_get_default_foreground(console)
    tcod.console_set_default_background(console, back)
    tcod.console_set_default_foreground(console, front)
    tcod.console_print_ex(console, x, y,
                          tcod.BKGND_SET, tcod.LEFT, text)
    tcod.console_set_default_background(console, previous_back)
    tcod.console_set_default_foreground(console, previous_fore)
예제 #5
0
def draw_messages_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(msg_con)
    libtcod.console_set_default_foreground(msg_con, libtcod.gold)
    libtcod.console_hline(msg_con, 0, 0, MSG_PANEL_WIDTH)
    libtcod.console_set_default_foreground(msg_con, old_foreground_color)

    # print the last many messages to the message console that will fit in the console.
    for i, msg_and_color in enumerate(reversed(messages)):
        if (i + 1) > MSG_PANEL_HEIGHT:
            break
        else:
            msg, color = msg_and_color
            libtcod.console_set_default_foreground(msg_con, color)
            libtcod.console_print(msg_con, 1, (i + 1), msg)
            libtcod.console_set_default_foreground(msg_con, old_foreground_color)
예제 #6
0
def draw_messages_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(msg_con)
    libtcod.console_set_default_foreground(msg_con, libtcod.gold)
    libtcod.console_hline(msg_con, 0, 0, MSG_PANEL_WIDTH)
    libtcod.console_set_default_foreground(msg_con, old_foreground_color)

    # print the last many messages to the message console that will fit in the console.
    for i, msg_and_color in enumerate(reversed(messages)):
        if (i + 1) > MSG_PANEL_HEIGHT:
            break
        else:
            msg, color = msg_and_color
            libtcod.console_set_default_foreground(msg_con, color)
            libtcod.console_print(msg_con, 1, (i + 1), msg)
            libtcod.console_set_default_foreground(msg_con,
                                                   old_foreground_color)
예제 #7
0
 def draw(self, color=rl.white):
     oldColor = rl.console_get_default_foreground(0)  # Store old color.
     rl.console_set_default_foreground(0, color)  # Apply window's color.
     # Draw the corners.
     rl.console_put_char_ex(0, self.x, self.y, rl.CHAR_DNW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1, self.y, rl.CHAR_DNE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x, self.y + self.h - 1, rl.CHAR_DSW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1,
                            self.y + self.h - 1, rl.CHAR_DSE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     # Draw the walls.
     for i in range(self.y + 1, self.y + self.h - 1):
         rl.console_put_char_ex(0, self.x, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.x + 1, self.x + self.w - 1):
         rl.console_put_char_ex(0, i, self.y, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 1, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     if self.title != None:  # Draw the title, if present.
         rl.console_print(0, self.x + 2, self.y, " {0} ".format(self.title))
     rl.console_set_default_foreground(
         0, oldColor)  # Revert color before drawing rest of window.
     rl.console_print_rect(0, self.x + 2, self.y + 1, self.w - 4,
                           self.h - 2, self.text)  # Draw the inner text.
예제 #8
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red, libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green, libtcod.black)
    libtcod.console_print(stat_con, 1, 1,
                          "Position: %c(%s, %s)%c" % (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2, "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(stat_con, 1, 5, "Mouse: %c(%s, %s)%c" % (
        libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7, "Current depth: " + str(current_depth))
    libtcod.console_print(stat_con, 1, 10, "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
예제 #9
0
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color,
               back_color):
    old_bg = tcod.console_get_default_background(panel)
    old_fg = tcod.console_get_default_foreground(panel)

    label = '{}: {}/{} '.format(name, value, maximum)
    tcod.console_print(panel, x, y, label)
    x += len(label)
    total_width -= len(label)

    bar_width = int(value / maximum * total_width)

    tcod.console_set_default_background(panel, back_color)
    tcod.console_rect(panel, x, y, total_width, 1, False, tcod.BKGND_SET)

    tcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SET)

    tcod.console_set_default_foreground(panel, tcod.white)

    tcod.console_set_default_background(panel, old_bg)
    tcod.console_set_default_foreground(panel, old_fg)
예제 #10
0
 def get_default_color_fg(self):
     return libtcod.console_get_default_foreground(0)
예제 #11
0
 def get_default_foreground(self):
     return libtcod.console_get_default_foreground(self.console_id)
예제 #12
0
파일: canvas.py 프로젝트: mwerezak/ascii
 def fg_colour(self):
     """ The default foreground colour which is used for functions that do not explicitly ask for one.
     """
     return Colour(0,0,0,struct=dlib.console_get_default_foreground(self._intern))
예제 #13
0
 def draw(self, color=rl.white):
     if self.subBox != None:  # If there is a sub-box, draw that instead.
         self.subBox.draw()
         return
     rl.console_rect(0, self.x, self.y, self.w, self.h,
                     True)  # Reset background color for the box.
     # Draw the corners.
     rl.console_put_char_ex(0, self.x, self.y, rl.CHAR_DNW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1, self.y, rl.CHAR_DNE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x, self.y + self.h - 1, rl.CHAR_DSW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1,
                            self.y + self.h - 1, rl.CHAR_DSE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     # Draw the walls.
     for i in range(self.y + 1, self.y + self.h - 1):
         rl.console_put_char_ex(0, self.x, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.y + 1, self.y + self.h - 4):
         rl.console_put_char_ex(0, self.dividerX, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.x + 1, self.x + self.w - 1):
         rl.console_put_char_ex(0, i, self.y, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 1, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 4, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         # Draw the dividing joints between sections.
         rl.console_put_char_ex(0, self.dividerX, self.y, rl.CHAR_DTEES,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.dividerX, self.y + self.h - 4,
                                rl.CHAR_DTEEN,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x, self.y + self.h - 4,
                                rl.CHAR_DTEEE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, self.y + self.h - 4,
                                rl.CHAR_DTEEW,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     if self.title != None:  # Draw the title, if present.
         rl.console_print(0, self.x + 2, self.y, " {0} ".format(self.title))
     # Draw every option and its current value (or "..." if it leads to a new menu).
     for i, option in enumerate(
             self.menuObj[self.optOffset:min(self.optOffset +
                                             self.optCap, len(self.menuObj)
                                             )]):  # Draw the options.
         if option[0] == None:
             rl.console_print(0, self.x + 4, self.y + 1 + i,
                              option[3][0][3])
         else:
             rl.console_print(0, self.x + 4, self.y + 1 + i, option[0])
         if isinstance(option[3], list):
             rl.console_print(0, self.dividerX + 2, self.y + 1 + i, "...")
         else:
             rl.console_print(
                 0, self.dividerX + 2, self.y + 1 + i,
                 str(option[3])[0:min(len(str(option[3])), 76 -
                                      self.dividerX)])
     # Draw the description of the current option or the current input, whichever is needed.
     color = ""  # The color to draw the input in. Or more specifically, the ascii mid-string color change code. Since the default is white, by default nothing needs to be done here.
     if self.inputMode != "":
         if self.inputIsValid(
                 self.currentInput, self.menuObj[self.selectedOption][1],
                 self.menuObj[self.selectedOption]
             [4]) == False:  # If the input isn't valid, make the color red.
             color = chr(rl.COLCTRL_FORE_RGB) + chr(255) + chr(64) + chr(64)
         if self.inputMode == "Text":
             rl.console_print(
                 0, 2, self.y + self.h - 3,
                 "Input the new value. Max length is {0}\n{2}{1}{3}".format(
                     self.menuObj[self.selectedOption][4],
                     self.currentInput[
                         self.inputOffset:min(self.inputOffset +
                                              76, len(self.currentInput))],
                     color, chr(rl.COLCTRL_STOP)))
         elif self.inputMode == "Number":
             rl.console_print(
                 0, 2, self.y + self.h - 3,
                 "Input the new value. Max value is {0}\n{2}{1}{3}".format(
                     self.menuObj[self.selectedOption][4],
                     self.currentInput[
                         self.inputOffset:min(self.inputOffset +
                                              76, len(self.currentInput))],
                     color, chr(rl.COLCTRL_STOP)))
     else:
         rl.console_print_rect(0, 2, self.y + self.h - 3, 76, 2,
                               self.menuObj[self.selectedOption][2])
         rl.console_print(0, self.x + 2,
                          self.y + 1 + self.selectedOption - self.optOffset,
                          chr(rl.CHAR_ARROW2_E))
     # Draw input cursor.
     if self.inputMode != "":
         rl.console_set_char_background(
             0, 2 + self.cursorPos - self.inputOffset, self.y + self.h - 2,
             rl.white)
         rl.console_set_char_foreground(
             0, 2 + self.cursorPos - self.inputOffset, self.y + self.h - 2,
             rl.black)
     # Draw scroll arrows as needed.
     if int(time.clock() * 2) % 2 == 0:
         if self.optOffset > 0:
             rl.console_print(0, self.x + int(self.w / 2), self.y,
                              chr(rl.CHAR_ARROW2_N))
         if self.optOffset + self.optCap < len(self.menuObj):
             rl.console_print(0, self.x + int(self.w / 2),
                              self.y + self.h - 1, chr(rl.CHAR_ARROW2_S))
         if self.inputOffset > 0:
             rl.console_print(0, self.x, self.y + self.h - 2,
                              chr(rl.CHAR_ARROW2_W))
         if self.inputOffset < len(self.currentInput) - 75:
             rl.console_print(0, self.x + self.w - 1, self.y + self.h - 2,
                              chr(rl.CHAR_ARROW2_E))