def render(self, console: tcod.Console, *, fg:Optional[Tuple[int,int,int]]=None, bg:Optional[Tuple[int,int,int]]=None, x=0, y=0 ): console.draw_frame( x=self.x+x, y=self.y+y, title=self.title, width=self.width, height=self.height, fg=fg if fg else self.fg, bg=bg if bg else self.bg, ) console.print_box( x=self.x+1+x,y=self.y+1+y, height=self.height-2, width=self.width-2, fg=fg if fg else self.fg, bg=bg if bg else self.bg, string=self.text ) console.print( x=self.x + 1 + x, y=self.y + 1 + self.index + y - self.offset, string=f"{self.index_items[self.index]:<{self.width_2}}", bg=fg if fg else self.fg, fg=bg if bg else self.bg )
def render(self, console: tcod.Console, *, x:int=0, y:int=0, fg:Optional[Tuple[int,int,int]]=None, bg:Optional[Tuple[int,int,int]]= None, text:Optional[str]=None, alignment:Optional[int]=None ): console.draw_frame( x=x+self.x, y=y+self.y, width=self.width, height=self.height, title=self.title, fg=fg if fg else self.fg, bg=bg if bg else self.bg, ) string_text = text if text is not None else self.text console.print_box( x=x+self.x+1, y=y+self.y+1, height=self.height-2, width=self.width-2, string=string_text, fg=fg if fg else self.fg, bg=bg if bg else self.bg, alignment=alignment if alignment is not None else self.alignment )
def render(self, console: tcod.Console, *, x:int=0, y:int=0, fg:Optional[Tuple[int,int,int]]=None, bg:Optional[Tuple[int,int,int]]= None, text:Optional[str]=None, cursor_position:Optional[int]=None ): fg, bg = (fg if fg else self.fg), (bg if bg else self.bg) console.draw_frame( x=x+self.x, y=y+self.y, width=self.width, height=self.height, title=self.title, fg=fg, bg=bg, ) string_text = text if text is not None else self.text console.print_box( x=x+self.x+1, y=y+self.y+1, height=self.height-2, width=self.width-2, string=string_text, fg=fg, bg=bg, alignment=self.alignment, ) if cursor_position is not None: try: char = string_text[cursor_position] except IndexError: char = " " console.print( x=self.x + 1 + (self.width - 2) + cursor_position - len(string_text) if self.alignment == constants.RIGHT else self.x + 1 + cursor_position, y=self.y+1, string=char, fg=bg, bg=fg, )
def render_position(console: Console, gameData:GameData): w = CONFIG_OBJECT.position_info_end_x - CONFIG_OBJECT.position_info_x h = CONFIG_OBJECT.position_info_end_y - CONFIG_OBJECT.position_info_y console.draw_frame( x=CONFIG_OBJECT.position_info_x, y=CONFIG_OBJECT.position_info_y, width=w, height=h, title=gameData.condition.text, fg=gameData.condition.fg, bg=gameData.condition.bg ) console.print_box( x=CONFIG_OBJECT.position_info_x+1, y=CONFIG_OBJECT.position_info_y+1, string=gameData.info_description, width=w-2, height=h-2 )
def on_render(self, console: tcod.Console) -> None: super().on_render(console) # Draw the main state as the background. log_console = Console(console.width - 6, console.height - 6) # Draw the frame with a custom banner title log_console.draw_frame(0, 0, log_console.width, log_console.height) log_console.print_box(0, 0, log_console.width, 1, "-|Message History|-", alignment=tcod.CENTER) # Render the message log using the cursor param self.engine.message_log.render_messages( log_console, 1, 1, log_console.width - 2, log_console.height - 2, self.engine.message_log.messages[:self.cursor + 1], ) log_console.blit(console, 3, 3)
def render_other_ship_info(console: Console, gamedata:GameData, ship:Optional[Starship]=None): start_x = CONFIG_OBJECT.other_ship_display_x start_y = CONFIG_OBJECT.other_ship_display_y width = CONFIG_OBJECT.other_ship_display_end_x - CONFIG_OBJECT.other_ship_display_x height = CONFIG_OBJECT.other_ship_display_end_y - CONFIG_OBJECT.other_ship_display_y ship_planet_or_star = gamedata.selected_ship_planet_or_star if ship_planet_or_star: if isinstance(ship_planet_or_star, Starship): if not gamedata.ship_scan: gamedata.ship_scan = gamedata.selected_ship_planet_or_star.scan_for_print( gamedata.player.sensors.determin_precision ) print_ship_info( console=console, x=start_x, y=start_y, width=width, height=height, self=ship_planet_or_star, scan=gamedata.ship_scan, precision=gamedata.player.sensors.determin_precision ) elif isinstance(ship_planet_or_star, Planet): console.draw_frame( x=start_x, y=start_y, width=width, height=height, title="Planet" ) console.print( x=start_x+3, y=start_y+4, string=f"Planet at {ship_planet_or_star.local_coords.x}, {ship_planet_or_star.local_coords.y}" ) planet_status = ship_planet_or_star.planet_habbitation.description console.print_box( x=start_x+3, y=start_y+6, width=width-6, height=6, string=f"Planet status: {planet_status}\n\nPlanet development: {ship_planet_or_star.infastructure:.3}" ) elif isinstance(ship_planet_or_star, Star): console.draw_frame( x=start_x, y=start_y, width=width, height=height, title="Star" ) x, y = ship_planet_or_star.local_coords.x, ship_planet_or_star.local_coords.y console.print_rect( x=start_x+3, y=start_y+4, string=f"{ship_planet_or_star.name} star at {x}, {y}", height=4, width=width - (3 + 2) ) else: console.draw_frame( x=start_x, y=start_y, width=width, height=height, title="No Ship/Planet Selected" )
def print_system(console:Console, gamedata:GameData): x = CONFIG_OBJECT.subsector_display_x y = CONFIG_OBJECT.subsector_display_y width = CONFIG_OBJECT.subsector_width heigth = CONFIG_OBJECT.subsector_height player = gamedata.player console.print_box( x=x+1, y=y+1, width=width * 2, height=heigth * 2, string=GRID, fg=colors.blue, ) console.draw_frame( x=x + (player.local_coords.x * 2), y=y + (player.local_coords.y * 2), width=3, height=3, fg=colors.yellow, clear=False ) if player.game_data.selected_ship_planet_or_star is not None: selected = player.game_data.selected_ship_planet_or_star console.draw_frame( x=x + (selected.local_coords.x * 2), y=y + (selected.local_coords.y * 2), height=3, width=3, fg=colors.orange, clear=False ) console.draw_frame( x=x, y=y, width=width * 2 + 1, height=heigth * 2 + 1, title="System", clear=False ) sector:SubSector = player.get_sub_sector for c, star in sector.stars_dict.items(): console.print( x=x + (c.x * 2) + 1, y=y + (c.y * 2) + 1, string="*", fg=star.color,bg=star.bg ) ships = gamedata.visible_ships_in_same_sub_sector_as_player #number_of_ships = len(ships) for c, planet in sector.planets_dict.items(): console.print( x=x + (c.x * 2) + 1, y=y + (c.y * 2) + 1, string="#", fg=planet.player_display_status.color ) for s in ships: if s.ship_status.is_visible: """ console.draw_frame( x=x + (s.local_coords.x * 2), y=y + (s.local_coords.y * 2), width=3, height=3, fg=colors.white ) """ console.print( x=x + (s.local_coords.x * 2) + 1, y=y + (s.local_coords.y * 2) + 1, string=s.ship_class.symbol, fg=s.ship_status.override_color if s.ship_status.override_color else s.ship_class.nation.nation_color ) console.print( x=x + (player.local_coords.x * 2) + 1, y=y + (player.local_coords.y * 2) + 1, string=player.ship_class.symbol, fg=colors.lime)
def print_ship_info( console:Console, x:int, y:int, width:int, height:int, self:Starship, scan:Dict[str,Any], precision:int ): ship_status = self.ship_status try: cloak_is_on = self.cloak.cloak_is_turned_on except AttributeError: cloak_is_on = False frame_fg = ( colors.cloaked if self is self.game_data.player and cloak_is_on else colors.white ) console.draw_frame( x=x, y=y, width=width, height=height, title=self.proper_name, fg=frame_fg, bg=colors.black ) console.print( x=x+2, y=y+2, string=f"Position: {self.local_coords.x}, {self.local_coords.y}", fg=colors.white ) if ship_status == STATUS_HULK: console.print_box( x+2, y=y+3, width=width - 4, height=4, string=f"Remains of the {self.proper_name}", fg=colors.white ) else: add_to_y = 4 for i, n, d, c, m in zip( range(2), ( "Hull:", "Energy:" ), ( scan['hull'][0], scan['energy'][0] ), ( scan['hull'][1], scan['energy'][1] ), ( self.ship_class.max_hull, self.ship_class.max_energy, ) ): console.print(x=x+3, y=y+i+add_to_y, string=f"{n:>16}", fg=colors.white) console.print(x=x+3+16, y=y+i+add_to_y, string=f"{d: =4}", fg=c) console.print(x=x+3+16+4, y=y+i+add_to_y, string=f"/{m: =4}", fg=colors.white) add_to_y += 1 try: n = "Shields:" d = scan['shields'][0] c = scan['shields'][1] m = self.ship_class.max_shields add_to_y += 1 console.print(x=x+3, y=y+add_to_y, string=f"{n:>16}", fg=colors.white) console.print(x=x+3+16, y=y+add_to_y, string=f"{d: =4}", fg=c) console.print(x=x+3+16+4, y=y+add_to_y, string=f"/{m: =4}", fg=colors.white) except KeyError: pass try: n = "Polarization:" d = scan['polarization'][0] c = scan['polarization'][1] m = self.ship_class.polarized_hull add_to_y += 1 console.print(x=x+3, y=y+add_to_y, string=f"{n:>16}", fg=colors.white) console.print(x=x+3+16, y=y+add_to_y, string=f"{d: =4}", fg=c) console.print(x=x+3+16+4, y=y+add_to_y, string=f"/{m: =4}", fg=colors.white) except KeyError: pass try: hd, hc = scan["hull_damage"] n = "Perm. Hull Dam.:" add_to_y+=1 console.print(x=x+3, y=y+i+add_to_y, string=f"{n:>16}", fg=colors.white) console.print(x=x+3+16, y=y+i+add_to_y, string=f"{hd: =4}", fg=hc) except KeyError: pass add_to_y+=1 sys_x_position = (width - 2) // 2 if not self.ship_class.is_automated: try: injured_crew_amount = scan['injured_crew'][0] injured_crew_color = scan['injured_crew'][1] r = 2 if injured_crew_amount else 1 except KeyError: injured_crew_amount=0 injured_crew_color=colors.white r = 1 for i, n, d, c, m in zip( range(r), ( "Able Crew:", "Injured Crew:" ), ( scan['able_crew'][0], injured_crew_amount ), ( scan['able_crew'][1], injured_crew_color ), ( self.ship_class.max_crew, self.ship_class.max_crew ) ): console.print(x=x+3, y=y+i+add_to_y, string=f"{n:>16}", fg=colors.white) console.print(x=x+3+16, y=y+i+add_to_y, string=f"{d: =4}", fg=c) console.print(x=x+3+16+4, y=y+i+add_to_y, string=f"/{m: =4}", fg=colors.white) add_to_y += r try: d_n = scan["cloak_cooldown"][0] d_c = scan["cloak_cooldown"][1] m = self.ship_class.cloak_cooldown console.print(x=x+3, y=y+add_to_y, string=f"{'C. Cooldown:':>16}", fg=colors.white) console.print(x=x+3+16, y=y+add_to_y, string=f"{d_n: =4}", fg=d_c) console.print(x=x+3+16+4, y=y+add_to_y, string=f"/{m: =4}", fg=colors.white) add_to_y+=1 except KeyError: pass try: boarders:Tuple[Nation, Tuple[int,int]] = scan["boarders"] add_to_y+=1 console.print(x=x+sys_x_position, y=y+add_to_y, string=f"{'-- Boarders --'}", alignment=tcod.CENTER, fg=colors.white) add_to_y+=1 for k, v in boarders: console.print(x=x+3, y=y+add_to_y, string=f"{k.name_short} {v[0]} {v[1]}") add_to_y+=1 except KeyError: pass add_to_y+=1 if self.ship_class.ship_type_can_fire_torps: max_torps = self.ship_class.max_torpedos console.print( x=x+3+2, y=y+add_to_y, string=f"Torpedo Tubes:{self.ship_class.torp_tubes: =2}", fg=colors.white ) ''' console.print( x=x+3+3, y=y+add_to_y+1, string=f"Max Torpedos:{max_torps: =2}", fg=colors.white ) ''' add_to_y+=1 for i, t in enumerate(self.ship_class.torp_dict.keys()): console.print( x=x+3, y=y+add_to_y, string=f"{t.cap_name + ':':>16}", fg=colors.white ) console.print( x=x+3+16, y=y+add_to_y, string=f"{self.torpedo_launcher.torps[t]: =2}", fg=scan["torpedo_color"] ) console.print( x=x+3+16+4, y=y+add_to_y, string=f"/{max_torps: =2}", fg=colors.white ) add_to_y+=1 names, keys = self.ship_class.system_names, self.ship_class.system_keys #add_to_y+=1 console.print(x=x+sys_x_position, y=y+add_to_y, string="-- Systems --", alignment=tcod.CENTER, fg=colors.white) add_to_y+=1 for n, k, i in zip(names, keys, range(len(keys))): scanned = scan[k][0] scan_color = scan[k][1] #k = keys[i-(s+3)] #n__n = f"{n:>17}" n__n = scan[k][2] s__s = f"{scanned}" console.print(x=x+3, y=y+i+add_to_y, string=f"{n__n}", fg=colors.white) console.print(x=x+3+17, y=y+i+add_to_y, string=f"{s__s}", fg=scan_color)