def __init__(self, debug_console, panel, ship, font): self.debug_console = debug_console self.panel = panel self.event = self.panel.event self.ship = ship self.font = font self.buttons = [] self.add_crew = TextBox(pygame.Rect(20, 50, 250, 45), Color.d_gray, border_color=None, highlight_color=Color.white, active_color=None, message='Add Crew', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.add_crew) self.add_shield = TextBox(pygame.Rect(20, 100, 250, 45), Color.d_gray, highlight_color=Color.white, message='Add Shield', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.add_shield) self.spam_console = TextBox(pygame.Rect(20, 150, 250, 45), Color.d_gray, highlight_color=Color.white, message='Spam Debug', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.spam_console) self.damage_shield = TextBox(pygame.Rect(20, 200, 250, 45), Color.d_gray, highlight_color=Color.white, message='Damage Ship Shields', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.damage_shield) self.enter_battle = TextBox(pygame.Rect(20, 250, 250, 45), Color.d_gray, highlight_color=Color.white, message="Enter Battle", text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.enter_battle)
def __init__(self, screen_width, screen_height, subject=None, message=None, font=None, small_font=None): self.big_font_size = 24 self.small_font_size = 16 self.large_font = font self.small_font = small_font if not self.large_font: self.large_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.big_font_size) if not self.small_font: self.large_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.small_font_size) self.subject = subject self.message = message self.body_width = screen_width self.body_height = screen_height self.email_screen = pygame.Surface(size=(self.body_width, self.body_height)) self.subject_box = TextBox(pygame.Rect(10, 10, 10, 50), box_color=Color.blue, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, text_color=Color.white, text_outline=Color.white, font=self.large_font) self.message_box = TextBox(pygame.Rect(10, 40, 10, 50), text_color=Color.white, text_outline=Color.white, font=self.small_font) if self.subject: self.subject_box.message = self.subject else: self.subject_box.message = 'FW: Get big peen now!' if self.message: self.message_box.message = self.message else: self.message_box.message = 'FW: Get big peen now!'
def __init__( self, rect, box_color=None, border_color=None, highlight_color=None, active_color=None, message="", text_color=None, font=None, text_limit=None, allowed_characters=None, ): TextBox.__init__( self, rect, box_color=box_color, border_color=border_color, highlight_color=highlight_color, active_color=active_color, message=message, text_color=text_color, font=font, ) self.active = False self.text_limit = text_limit self.allowed_characters = allowed_characters
class Debug(object): def __init__(self, debug_console, panel, ship, font): self.debug_console = debug_console self.panel = panel self.event = self.panel.event self.ship = ship self.font = font self.buttons = [] self.add_crew = TextBox(pygame.Rect(20, 50, 250, 45), Color.d_gray, border_color=None, highlight_color=Color.white, active_color=None, message='Add Crew', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.add_crew) self.add_shield = TextBox(pygame.Rect(20, 100, 250, 45), Color.d_gray, highlight_color=Color.white, message='Add Shield', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.add_shield) self.spam_console = TextBox(pygame.Rect(20, 150, 250, 45), Color.d_gray, highlight_color=Color.white, message='Spam Debug', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.spam_console) self.damage_shield = TextBox(pygame.Rect(20, 200, 250, 45), Color.d_gray, highlight_color=Color.white, message='Damage Ship Shields', text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.damage_shield) self.enter_battle = TextBox(pygame.Rect(20, 250, 250, 45), Color.d_gray, highlight_color=Color.white, message="Enter Battle", text_color=Color.white, text_outline=True, font=self.font) self.buttons.append(self.enter_battle) def draw(self, screen): for button in self.buttons: button.draw(screen) def update(self, key, mouse, offset=(0, 0)): if self.add_crew.update(key, mouse, offset): self.ship.add_crew(Pawn(name='FooBar', age='Female', race='Compooter', bio='Stop all the downloadin!', profile=(os.path.join(settings.main_path, 'res', 'face', 'joe.png')))) self.debug_console.add_message(">> Added crew member.") if self.add_shield.update(key, mouse, offset): self.ship.add_component(Component("shield", name="Mk I Shield", stats={"shield": 100, "power": -10})) self.debug_console.add_message(">> Mk I Shield added to inventory.") if self.spam_console.update(key, mouse, offset): self.debug_console.add_message('>> BLAH BLAH BLAH') if self.damage_shield.update(key, mouse, offset): self.ship.current_shield -= 10 self.debug_console.add_message('>> Ship shield depleted by 10 to {0}'.format(self.ship.current_shield)) if self.enter_battle.update(key, mouse, offset): self.event.adhoc_event(battle={"Bad": "guy", "enemies": [{"ship_file": "data/enemy_1.shp"}, {"ship_file": "data/enemy_1.shp"}]})
def __init__(self, battle): self.battle = battle self.attack_but = TextBox(pygame.Rect(20, 50, 100, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='Attack Button', message='ATTACK', text_color=Color.red, text_outline=True, font=self.battle.font) self.defend_but = TextBox(pygame.Rect(20, 100, 100, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='Defend Button', message='DEFEND', text_color=Color.blue, text_outline=True, font=self.battle.font)
class Warp(object): def __init__(self, panel, font, small_font): self.panel = panel self.font = font self.small_font = small_font self.x_cord_box = InputBox(pygame.Rect(75, 200, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.y_cord_box = InputBox(pygame.Rect(75, 250, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.generate_button = TextBox(pygame.Rect(125, 300, 100, 50), (20, 150, 30), Color.gray, highlight_color=Color.white, active_color=Color.blue, message=u'\u304D', text_color=Color.white, font=self.font) def draw(self, screen): Text.draw_text(screen, self.font, 'Warp to System', Color.white, (105, 14)) Text.draw_text(screen, self.font, 'X:', Color.white, (40, 200)) Text.draw_text(screen, self.font, 'Y:', Color.white, (40, 250)) self.x_cord_box.draw(screen) self.y_cord_box.draw(screen) self.generate_button.draw(screen) def update(self, key, mouse, offset=(0, 0)): self.x_cord_box.update(key, mouse, offset) self.y_cord_box.update(key, mouse, offset) # check for generate if self.generate_button.update(key, mouse, offset): if len(self.x_cord_box.message) != 0: x = int(self.x_cord_box.message) else: x = 0 if len(self.y_cord_box.message) != 0: y = int(self.y_cord_box.message) else: y = 0 self.panel.warp_to_system(x, y)
class SpaceBattlePanel(object): def __init__(self, battle): self.battle = battle self.attack_but = TextBox(pygame.Rect(20, 50, 100, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='Attack Button', message='ATTACK', text_color=Color.red, text_outline=True, font=self.battle.font) self.defend_but = TextBox(pygame.Rect(20, 100, 100, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='Defend Button', message='DEFEND', text_color=Color.blue, text_outline=True, font=self.battle.font) def update(self, key, mouse, offset=(0, 0)): if self.attack_but.update(key=key, mouse=mouse, offset=offset): if self.battle.target is None: print 'You need a f****n target mate' else: print 'Gonna attack {0} then'.format(self.battle.target) # attack stuff self.battle.target = None def draw(self, screen): self.attack_but.draw(screen) self.defend_but.draw(screen)
def __init__(self, font, screen_width=800, screen_height=600): self.font = font title_image = pygame.image.load(os.path.join(settings.main_path, 'res', 'tyrra_title.png')) pygame.mixer.music.load(os.path.join(settings.main_path, 'res', 'tyrra_bit.ogg')) self.title_image = Box(rect=pygame.Rect(10, 10, screen_width-20, screen_height-20), border_color=Color.white, highlight_color=Color.white, active_color=Color.white, border=4, image=title_image) self.new_game = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+20, 120, 30), highlight_color=Color.gray, active_color=Color.blue, name='new', message='New Game', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.load_game = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+60, 120, 30), highlight_color=Color.gray, active_color=Color.blue, name='load', message='Load Game', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.options = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+100, 100, 30), highlight_color=Color.gray, active_color=Color.blue, name='options', message='Options', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.quit = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+140, 80, 30), highlight_color=Color.gray, active_color=Color.blue, name='quit', message='Quit', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.buttons = [self.new_game, self.load_game, self.options, self.quit]
def __init__(self, panel, font, small_font): self.panel = panel self.font = font self.small_font = small_font self.x_cord_box = InputBox(pygame.Rect(75, 200, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.y_cord_box = InputBox(pygame.Rect(75, 250, 200, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, message='0', text_color=Color.white, font=self.font, text_limit=10, allowed_characters=range(48, 58)) self.generate_button = TextBox(pygame.Rect(125, 300, 100, 50), (20, 150, 30), Color.gray, highlight_color=Color.white, active_color=Color.blue, message=u'\u304D', text_color=Color.white, font=self.font)
class Title(object): def __init__(self, font, screen_width=800, screen_height=600): self.font = font title_image = pygame.image.load(os.path.join(settings.main_path, 'res', 'tyrra_title.png')) pygame.mixer.music.load(os.path.join(settings.main_path, 'res', 'tyrra_bit.ogg')) self.title_image = Box(rect=pygame.Rect(10, 10, screen_width-20, screen_height-20), border_color=Color.white, highlight_color=Color.white, active_color=Color.white, border=4, image=title_image) self.new_game = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+20, 120, 30), highlight_color=Color.gray, active_color=Color.blue, name='new', message='New Game', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.load_game = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+60, 120, 30), highlight_color=Color.gray, active_color=Color.blue, name='load', message='Load Game', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.options = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+100, 100, 30), highlight_color=Color.gray, active_color=Color.blue, name='options', message='Options', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.quit = TextBox(rect=pygame.Rect(screen_width/2-40, screen_height/2+140, 80, 30), highlight_color=Color.gray, active_color=Color.blue, name='quit', message='Quit', text_color=Color.white, text_outline=True, font=font, highlight_text=True, highlight_box=False) self.buttons = [self.new_game, self.load_game, self.options, self.quit] @staticmethod def play_title_music(): pygame.mixer.music.set_volume(0.1) pygame.mixer.music.play() @staticmethod def stop_title_music(): pygame.mixer.music.fadeout(500) def update(self, key, mouse): for button in self.buttons: if button.update(key=key, mouse=mouse): return button.name def draw(self, screen): self.title_image.draw(screen) self.new_game.draw(screen) self.load_game.draw(screen) self.options.draw(screen) self.quit.draw(screen)
def __init__(self, big_font, font, small_font, screen_height=800, screen_width=600): self.big_font = big_font self.font = font self.small_font = small_font self.box = Box(pygame.Rect(int(screen_width * 0.1), int(screen_height * 0.1), int(screen_width * 0.8), int(screen_height * 0.8)), box_color=Color.black, border_color=Color.white, border=4, highlight_box=False, name='Character Creation Box') box_x = self.box.rect.x box_y = self.box.rect.y # build portrait roster self.portrait_roster = [] self.portrait_index = 0 for face in os.listdir(settings.face_path): if face.endswith('.png'): path = os.path.join(settings.face_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) for face in os.listdir(settings.mod_path): if face.endswith('.png'): path = os.path.join(settings.mod_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) self.portrait = None self.portrait_box = Box(pygame.Rect(int(box_x + self.box.rect.width / 10), int(box_y + self.box.rect.height / 7), 250, 250), box_color=Color.black, border_color=Color.white, highlight_box=False, name='Portrait Box') self.update_roster_portrait_box() self.left_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x - 35, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_left', message='<', text_color=Color.white, text_outline=True, font=self.font) self.right_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width + 10, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_right', message='>', text_color=Color.white, text_outline=True, font=self.font) # character name self.name = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/7, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Flash', text_color=Color.white, font=self.font, text_limit=32) # character age self.age = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2.7, 70, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='25', text_color=Color.white, font=self.font, text_limit=5, allowed_characters=range(48, 58)) # character race self.race = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/4, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Human', text_color=Color.white, font=self.font, text_limit=32) # character bio self.bio = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2, 400, 50), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='A little bit about myself', text_color=Color.white, font=self.font, text_limit=300) # profession stuff self.profession_list = ['Pilot', 'Guns', 'Engineer', 'Medic', 'Scientist'] self.profession = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.portrait_box.rect.y + self.portrait_box.rect.width + 20, 100, 20), highlight_color=Color.white, active_color=Color.gray, border=0, name='Profession', message=self.profession_list[0], text_color=Color.gray, font=self.small_font, highlight_box=False, highlight_text=True) self.skills = {} self.update_profession_stats() # done self.done = TextBox(pygame.Rect(box_x + self.box.rect.width - 150, box_y + self.box.rect.height - 100, 100, 50), box_color=Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='done', message='START', text_color=Color.white, text_outline=True, font=self.font)
def draw(self, screen): TextBox.draw(self, screen) if self.active: TextCursor.draw(screen, (self.rect.left + self.font.size(self.message)[0], self.rect.top), self.font)
def update(self, key, mouse, offset=(0, 0)): if key[0] or key[1]: self.poll(key) return TextBox.update(self, key, mouse, offset)
def __init__(self, main_window_width=800, main_window_height=600, main_white_space=50, side_window_width=350, side_window_height=650, side_white_space=50, font=None, small_font=None): self.big_font_size = 24 self.small_font_size = 16 self.main_window = None self.main_width = main_window_width self.main_height = main_window_height self.console_height = 120 self.side_window = None self.font = font self.small_font = small_font # keeps buttons from being pressed when they aren't supposed to self.window_lock = False # some events consants self.intro_event_file = os.path.join(settings.main_path, 'data', 'intro.eve') self.intro_event_id = 'INTRO_1' self.station = None self.window_dict = {'console': False, 'Messages': True, 'email': False, 'Ship': True, 'System': True, 'planet': False, 'Battle': False, 'Warp': True, 'Debug': True, 'Station': True} self.window_list = {} self.sidebar_list = {} for window in self.window_dict: self.window_list[window] = Window((main_white_space, main_white_space), (main_window_width, main_window_height-self.console_height), name=window) self.sidebar_list[window] = Window((main_white_space + main_window_width + side_white_space, side_white_space), (side_window_width, side_window_height), name=window, border_color=Color.d_gray) # console self.the_big_board = Box(pygame.Rect(0, 0, main_window_width, main_window_height-self.console_height), box_color=None, border_color=None, highlight_color=None, active_color=None) self.board_bottom = Box(pygame.Rect(main_white_space, main_white_space+main_window_height-self.console_height, main_window_width, self.console_height), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.gray, active_color=Color.gray, border=3, name='Console-back') self.console = TextBoxList(pygame.Rect(main_white_space+10, main_white_space+main_window_height - self.console_height+10, main_window_width, self.console_height), name='Console', text_color=Color.white, text_outline=True, font=self.small_font, list_size=5, line_size=20) self.event = Event(panel=self, picture=self.the_big_board, text=self.console) self.window_list['console'].sprites.append(self.the_big_board) # self.window_list['console'].sprites.append(self.board_bottom) # self.window_list['console'].sprites.append(self.console) # main navigation buttons self.nav_button = {} y_offset = 0 # self.big_font_size+4)/2*len(window) for window, visible in self.window_dict.iteritems(): if visible: self.nav_button[window] = TextBox(pygame.Rect(20, 50+y_offset, 200, 45), Color.d_gray, border_color=None, highlight_color=Color.white, active_color=None, message=window, text_color=Color.white, text_outline=True, font=self.font) y_offset += 55 for button in self.nav_button: self.sidebar_list['console'].components.append(self.nav_button[button]) self.back_to_console = TextBox(pygame.Rect(10, 10, 50, 30), Color.d_gray, border_color=None, highlight_color=Color.blue, active_color=None, message='< <', text_color=Color.white, font=self.font) # email client construct # self.email = EmailClient() self.sidebar_list['Messages'].components.append(self.back_to_console) # ship construct self.ship = Ship(size_x=40, size_y=40) self.window_list['Ship'].components.append(self.ship.main_screen) self.sidebar_list['Ship'].components.append(self.ship) self.sidebar_list['Ship'].components.append(self.back_to_console) # system construct self.system = None self.warp_to_system(x=6541, y=43322) self.screen_title = None self.switch_window('console') # battle screen self.space_battle = None ''' self.space_battle = SpaceBattle(player_ship=self.ship, font=self.font, small_font=self.small_font, window_size=(main_window_width, main_window_height - self.console_height)) self.window_list['Battle'].components.append(self.space_battle) self.sidebar_list['Battle'].components.append(self.space_battle.side_panel) ''' # warp menu self.sidebar_list['Warp'].components.append(self.back_to_console) self.warp = Warp(self, font=self.font, small_font=self.small_font) self.sidebar_list['Warp'].components.append(self.warp) # self.window_list['Warp'].sprites.append(self.board_bottom) # self.window_list['Warp'].sprites.append(self.console) # debug self.debug_console = TextBoxList(pygame.Rect(10, main_window_height-300, main_window_width, 300), name='D_con', text_color=Color.white, text_outline=True, font=self.small_font, list_size=14, line_size=20) self.debug = Debug(self.debug_console, self, self.ship, self.font) self.window_list['Debug'].sprites.append(Box(pygame.Rect(5, main_window_height-310, main_window_width-10, 5), box_color=Color.white, name='LINE')) self.window_list['Debug'].sprites.append(self.debug_console) self.sidebar_list['Debug'].components.append(self.debug) self.sidebar_list['Debug'].components.append(self.back_to_console)
class ControlPanel(object): def __init__(self, main_window_width=800, main_window_height=600, main_white_space=50, side_window_width=350, side_window_height=650, side_white_space=50, font=None, small_font=None): self.big_font_size = 24 self.small_font_size = 16 self.main_window = None self.main_width = main_window_width self.main_height = main_window_height self.console_height = 120 self.side_window = None self.font = font self.small_font = small_font # keeps buttons from being pressed when they aren't supposed to self.window_lock = False # some events consants self.intro_event_file = os.path.join(settings.main_path, 'data', 'intro.eve') self.intro_event_id = 'INTRO_1' self.station = None self.window_dict = {'console': False, 'Messages': True, 'email': False, 'Ship': True, 'System': True, 'planet': False, 'Battle': False, 'Warp': True, 'Debug': True, 'Station': True} self.window_list = {} self.sidebar_list = {} for window in self.window_dict: self.window_list[window] = Window((main_white_space, main_white_space), (main_window_width, main_window_height-self.console_height), name=window) self.sidebar_list[window] = Window((main_white_space + main_window_width + side_white_space, side_white_space), (side_window_width, side_window_height), name=window, border_color=Color.d_gray) # console self.the_big_board = Box(pygame.Rect(0, 0, main_window_width, main_window_height-self.console_height), box_color=None, border_color=None, highlight_color=None, active_color=None) self.board_bottom = Box(pygame.Rect(main_white_space, main_white_space+main_window_height-self.console_height, main_window_width, self.console_height), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.gray, active_color=Color.gray, border=3, name='Console-back') self.console = TextBoxList(pygame.Rect(main_white_space+10, main_white_space+main_window_height - self.console_height+10, main_window_width, self.console_height), name='Console', text_color=Color.white, text_outline=True, font=self.small_font, list_size=5, line_size=20) self.event = Event(panel=self, picture=self.the_big_board, text=self.console) self.window_list['console'].sprites.append(self.the_big_board) # self.window_list['console'].sprites.append(self.board_bottom) # self.window_list['console'].sprites.append(self.console) # main navigation buttons self.nav_button = {} y_offset = 0 # self.big_font_size+4)/2*len(window) for window, visible in self.window_dict.iteritems(): if visible: self.nav_button[window] = TextBox(pygame.Rect(20, 50+y_offset, 200, 45), Color.d_gray, border_color=None, highlight_color=Color.white, active_color=None, message=window, text_color=Color.white, text_outline=True, font=self.font) y_offset += 55 for button in self.nav_button: self.sidebar_list['console'].components.append(self.nav_button[button]) self.back_to_console = TextBox(pygame.Rect(10, 10, 50, 30), Color.d_gray, border_color=None, highlight_color=Color.blue, active_color=None, message='< <', text_color=Color.white, font=self.font) # email client construct # self.email = EmailClient() self.sidebar_list['Messages'].components.append(self.back_to_console) # ship construct self.ship = Ship(size_x=40, size_y=40) self.window_list['Ship'].components.append(self.ship.main_screen) self.sidebar_list['Ship'].components.append(self.ship) self.sidebar_list['Ship'].components.append(self.back_to_console) # system construct self.system = None self.warp_to_system(x=6541, y=43322) self.screen_title = None self.switch_window('console') # battle screen self.space_battle = None ''' self.space_battle = SpaceBattle(player_ship=self.ship, font=self.font, small_font=self.small_font, window_size=(main_window_width, main_window_height - self.console_height)) self.window_list['Battle'].components.append(self.space_battle) self.sidebar_list['Battle'].components.append(self.space_battle.side_panel) ''' # warp menu self.sidebar_list['Warp'].components.append(self.back_to_console) self.warp = Warp(self, font=self.font, small_font=self.small_font) self.sidebar_list['Warp'].components.append(self.warp) # self.window_list['Warp'].sprites.append(self.board_bottom) # self.window_list['Warp'].sprites.append(self.console) # debug self.debug_console = TextBoxList(pygame.Rect(10, main_window_height-300, main_window_width, 300), name='D_con', text_color=Color.white, text_outline=True, font=self.small_font, list_size=14, line_size=20) self.debug = Debug(self.debug_console, self, self.ship, self.font) self.window_list['Debug'].sprites.append(Box(pygame.Rect(5, main_window_height-310, main_window_width-10, 5), box_color=Color.white, name='LINE')) self.window_list['Debug'].sprites.append(self.debug_console) self.sidebar_list['Debug'].components.append(self.debug) self.sidebar_list['Debug'].components.append(self.back_to_console) def load_event(self, event_file, event_name): self.event.read_event_file(event_file) self.event.run_event(event_name) def new_game(self, captain=None): self.ship.load(os.path.join(settings.main_path, 'data', 'start.shp')) if captain is not None: del self.ship.crew[:] self.ship.add_crew(captain) self.load_event(event_file=self.intro_event_file, event_name=self.intro_event_id) def warp_to_system(self, x, y): del self.window_list['System'].components[:] del self.sidebar_list['System'].components[:] self.station = None self.system = System(panel=self, font=self.font, small_font=self.small_font, x=x, y=y, add_station=True) self.window_list['System'].components.append(self.system.system_map) self.sidebar_list['System'].components.append(self.system) # self.system_map_index = len(self.window_list['System'].components)-1 self.sidebar_list['System'].components.append(self.back_to_console) self.event.adhoc_event(picture=self.system.family_portrait(), text='Warped to system: {0}'.format(self.system.name), goto='console') def dock_with_station(self, station=None): if station: self.station = station self.event.adhoc_event(picture=self.station.image, text='You have docked with {0}'.format(self.station.name), goto='console') def start_space_battle(self, battle_params=None): del self.window_list["Battle"].components[:] del self.sidebar_list["Battle"].components[:] enemies = None if battle_params: if "enemies" in battle_params: enemies = battle_params["enemies"] self.space_battle = SpaceBattle(player_ship=self.ship, font=self.font, small_font=self.small_font, window_size=(self.main_width, self.main_height - self.console_height), enemies=enemies) self.window_list["Battle"].components.append(self.space_battle) self.sidebar_list["Battle"].components.append(self.space_battle.side_panel) self.switch_window(new_window="Battle") def switch_window(self, new_window): self.window_lock = True try: self.main_window = self.window_list[new_window] self.side_window = self.sidebar_list[new_window] sleep(0.1) except Exception as e: print e pass self.screen_title = self.main_window.name self.window_lock = False def always(self): self.main_window.always() def update(self, key, mouse): if not self.window_lock: self.main_window.update(key=key, mouse=mouse) self.side_window.update(key=key, mouse=mouse) if self.back_to_console.update(key=key, mouse=mouse, offset=self.side_window.position): self.switch_window('console') if self.screen_title == 'console': for button in self.nav_button: if self.nav_button[button].update(key=key, mouse=mouse, offset=self.side_window.position): if button == 'Station' and self.station is None: self.event.adhoc_event(text='You are currently not docked at a station.') else: self.switch_window(button) def draw(self, screen): self.main_window.draw(screen) # always draw console probably self.board_bottom.draw(screen) self.console.draw(screen) self.side_window.draw(screen)
def __init__(self, size_x=16, size_y=16): self.big_font_size = 24 self.small_font_size = 16 self.font = pygame.font.Font(pygame.font.match_font('kaiti'), self.big_font_size) self.small_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.small_font_size) self.name = 'Tyrra' self.crew = [Pawn()] self.panel_mode = 'stats' self.ship_grid = ShipGrid(self, size_x, size_y) self.ship_preview = self.ship_grid.preview_window self.stat_screen = ShipStats(self, self.font, self.small_font) self.crew_profile = CrewProfile(self, self.crew[0], self.font, self.small_font) self.main_screen = ShipMainScreen(self.stat_screen, self.ship_grid, self.crew_profile) self.box = Box(self.get_ship_rect(), border_color=Color.blue, highlight_color=Color.green, active_color=Color.red, name='Ship Hit Box') # easy dictionary to store stats probably self.ship_stats = {'crew_capacity': 1, 'attack': 0, 'armor': 0, 'speed': 0, 'power': 0, 'shield': 0, 'component_capacity': 4} self.current_shield = 0 # objects are drawn on side bar self.name_box = InputBox(pygame.Rect(70, 10, 250, 50), box_color=None, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.gray, message=self.name, text_color=Color.white, font=self.font, text_limit=16) # nav self.stats_button = TextBox(pygame.Rect(25, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Stats', text_color=Color.white, text_outline=True, font=self.font) self.edit_button = TextBox(pygame.Rect(120, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Edit', text_color=Color.white, text_outline=True, font=self.font) self.crew_button = TextBox(pygame.Rect(210, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Crew', text_color=Color.white, text_outline=True, font=self.font) # floors self.floor_dictionary = {'blank': 0, 'floor': 1, 'armor': 2, 'engine': 3, 'gun': 4, 'power': 5, 'shield': 7} self.floor_stats = {'blank': (0, 0, 0, 0), 'floor': (0, -1, -1, -1), 'armor': (0, 10, -2, 0), 'engine': (0, 0, 10, -5), 'gun': (10, 0, -1, -5), 'power': (0, 0, -1, 10), 'shield': (0, 0, 0, -10)} self.floors = [] self.floors.append(Box(pygame.Rect(25, 140, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='blank')) self.floors.append(Box(pygame.Rect(55, 140, 25, 25), Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='floor')) self.floors.append(Box(pygame.Rect(85, 140, 25, 25), Color.d_gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='armor')) self.ship_grid.selected_cell_type = self.floor_dictionary['blank'] # Parts self.floors.append(TextBox(pygame.Rect(25, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='engine', message='E1', text_color=Color.blue, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(55, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='gun', message='G1', text_color=Color.red, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(85, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='power', message='P1', text_color=Color.green, text_outline=True, font=self.small_font)) # components (inventory / installed are actual objects; lists are just the text boxes) self.selected_component = None self.component_inventory = [] self.component_list = [] self.installed_components = [] self.installed_list = [] self.make_installed_component_list() # debug load button self.load_box = TextBox(pygame.Rect(230, 610, 75, 40), Color.blue, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='LOAD', text_color=Color.white, text_outline=True, font=self.font) # debug save button self.save_box = TextBox(pygame.Rect(230, 650, 75, 40), Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='SAVE', text_color=Color.white, text_outline=True, font=self.font) # crew screen self.crew_list = [] self.make_crew_list()
class Ship(object): def __init__(self, size_x=16, size_y=16): self.big_font_size = 24 self.small_font_size = 16 self.font = pygame.font.Font(pygame.font.match_font('kaiti'), self.big_font_size) self.small_font = pygame.font.Font(pygame.font.match_font('kaiti'), self.small_font_size) self.name = 'Tyrra' self.crew = [Pawn()] self.panel_mode = 'stats' self.ship_grid = ShipGrid(self, size_x, size_y) self.ship_preview = self.ship_grid.preview_window self.stat_screen = ShipStats(self, self.font, self.small_font) self.crew_profile = CrewProfile(self, self.crew[0], self.font, self.small_font) self.main_screen = ShipMainScreen(self.stat_screen, self.ship_grid, self.crew_profile) self.box = Box(self.get_ship_rect(), border_color=Color.blue, highlight_color=Color.green, active_color=Color.red, name='Ship Hit Box') # easy dictionary to store stats probably self.ship_stats = {'crew_capacity': 1, 'attack': 0, 'armor': 0, 'speed': 0, 'power': 0, 'shield': 0, 'component_capacity': 4} self.current_shield = 0 # objects are drawn on side bar self.name_box = InputBox(pygame.Rect(70, 10, 250, 50), box_color=None, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.gray, message=self.name, text_color=Color.white, font=self.font, text_limit=16) # nav self.stats_button = TextBox(pygame.Rect(25, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Stats', text_color=Color.white, text_outline=True, font=self.font) self.edit_button = TextBox(pygame.Rect(120, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Edit', text_color=Color.white, text_outline=True, font=self.font) self.crew_button = TextBox(pygame.Rect(210, 70, 80, 30), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.d_blue, message='Crew', text_color=Color.white, text_outline=True, font=self.font) # floors self.floor_dictionary = {'blank': 0, 'floor': 1, 'armor': 2, 'engine': 3, 'gun': 4, 'power': 5, 'shield': 7} self.floor_stats = {'blank': (0, 0, 0, 0), 'floor': (0, -1, -1, -1), 'armor': (0, 10, -2, 0), 'engine': (0, 0, 10, -5), 'gun': (10, 0, -1, -5), 'power': (0, 0, -1, 10), 'shield': (0, 0, 0, -10)} self.floors = [] self.floors.append(Box(pygame.Rect(25, 140, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='blank')) self.floors.append(Box(pygame.Rect(55, 140, 25, 25), Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='floor')) self.floors.append(Box(pygame.Rect(85, 140, 25, 25), Color.d_gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='armor')) self.ship_grid.selected_cell_type = self.floor_dictionary['blank'] # Parts self.floors.append(TextBox(pygame.Rect(25, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='engine', message='E1', text_color=Color.blue, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(55, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='gun', message='G1', text_color=Color.red, text_outline=True, font=self.small_font)) self.floors.append(TextBox(pygame.Rect(85, 180, 25, 25), Color.black, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=1, name='power', message='P1', text_color=Color.green, text_outline=True, font=self.small_font)) # components (inventory / installed are actual objects; lists are just the text boxes) self.selected_component = None self.component_inventory = [] self.component_list = [] self.installed_components = [] self.installed_list = [] self.make_installed_component_list() # debug load button self.load_box = TextBox(pygame.Rect(230, 610, 75, 40), Color.blue, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='LOAD', text_color=Color.white, text_outline=True, font=self.font) # debug save button self.save_box = TextBox(pygame.Rect(230, 650, 75, 40), Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.white, message='SAVE', text_color=Color.white, text_outline=True, font=self.font) # crew screen self.crew_list = [] self.make_crew_list() def add_crew(self, crew): self.crew.append(crew) self.make_crew_list() self.crew_profile.pawn = self.crew[0] def make_crew_list(self): del self.crew_list[:] y_offset = 0 for pawn in self.crew: self.crew_list.append(TextBox(pygame.Rect(50, 150+y_offset, 250, 40), box_color=Color.gray, border_color=Color.d_gray, highlight_color=Color.white, active_color=Color.blue, border=2, message=pawn.name, text_color=Color.white, text_outline=True, font=self.font)) y_offset += 55 def add_component(self, component): self.component_inventory.append(component) self.make_component_list() def make_component_list(self): del self.component_list[:] y_offset = 0 for component in self.component_inventory: self.component_list.append(TextBox(pygame.Rect(25, 150+y_offset, 250, 40), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.red, active_color=Color.gray, border=2, name=self.component_inventory.index(component), message=component.name, text_color=Color.white, text_outline=True, font=self.font)) y_offset += 55 def install_component(self, index): if self.component_inventory[index].component_type is not 'empty': self.installed_components.append(index) self.make_installed_component_list() def remove_component(self, index): if len(self.installed_components) > index: del self.installed_components[index] self.make_installed_component_list() def make_installed_component_list(self): del self.installed_list[:] for i in range(1, self.ship_stats['component_capacity'] + 1): if len(self.installed_components) > i - 1: index = self.installed_components[i - 1] self.installed_list.append(TextBox(pygame.Rect(25, 250 + ((i - 1) * 50), 300, 40), Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, border=2, name=i, message=self.component_inventory[index].name, text_color=Color.gray, text_outline=True, font=self.font)) else: self.installed_list.append(TextBox(pygame.Rect(25, 250+((i-1)*50), 300, 40), Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, border=2, name=i, message='EMPTY {0}'.format(i), text_color=Color.gray, text_outline=True, font=self.font)) def update(self, key, mouse, offset=(0, 0)): self.name_box.update(key, mouse, offset) if self.stats_button.update(key, mouse, offset): self.panel_mode = 'stats' self.main_screen.mode = 'stats' if self.edit_button.update(key, mouse, offset): self.panel_mode = 'edit' self.main_screen.mode = 'edit' if self.crew_button.update(key, mouse, offset): self.panel_mode = 'crew' self.main_screen.mode = 'crew' if self.panel_mode is 'component': self.update_component_panel(key, mouse, offset) elif self.panel_mode is 'edit': self.update_edit_panel(key, mouse, offset) elif self.panel_mode is 'crew': self.update_crew_panel(key, mouse, offset) # self.ship_grid.update(key=key, mouse=mouse) # get stats self.update_stats() def update_edit_panel(self, key, mouse, offset=(0, 0)): for tile in self.floors: tile.update(key, mouse, offset) if tile.active: self.ship_grid.selected_cell_type = self.floor_dictionary[tile.name] self.ship_grid.selected_cell_stats = self.floor_stats[tile.name] for component in self.installed_list: if component.update(key, mouse, offset): self.selected_component = component.name-1 self.panel_mode = 'component' if self.load_box.update(key, mouse, offset): self.load('{0}data/save.shp'.format(settings.main_path)) if self.save_box.update(key, mouse, offset): self.save('{0}data/save.shp'.format(settings.main_path)) def update_component_panel(self, key, mouse, offset=(0, 0)): for component in self.component_list: if len(self.component_inventory) > 0: index = int(component.name) else: index = 0 if index not in self.installed_components: if component.update(key, mouse, offset): print "index is {0}".format(index) self.remove_component(index) self.install_component(index) self.panel_mode = 'edit' def update_crew_panel(self, key, mouse, offset=(0, 0)): for crew in self.crew_list: if crew.update(key, mouse, offset): for pawn in self.crew: if pawn.name == crew.message: if self.crew_profile is not None: self.crew_profile.pawn = pawn break def update_stats(self): attack, armor, speed, power = self.ship_grid.get_stats() self.ship_stats['attack'] = attack self.ship_stats['armor'] = armor self.ship_stats['speed'] = speed self.ship_stats['power'] = power self.ship_stats['shield'] = 0 for index in self.installed_components: component = self.component_inventory[index] if component.stats: for stat, value in component.stats.iteritems(): if stat in self.ship_stats: self.ship_stats[stat] += value # reset shield HP self.current_shield = self.ship_stats['shield'] def draw(self, screen): screen.fill(Color.black) self.name_box.draw(screen) self.stats_button.draw(screen) self.edit_button.draw(screen) self.crew_button.draw(screen) if self.panel_mode is 'edit': self.draw_edit_panel(screen) elif self.panel_mode is 'component': self.draw_component_panel(screen) elif self.panel_mode is 'crew': self.draw_crew_panel(screen) def draw_crew_panel(self, screen): for box in self.crew_list: box.draw(screen) def draw_edit_panel(self, screen): Text.draw_text(screen, self.small_font, 'Floors:', Color.white, position=(25, 110)) for tile in self.floors: tile.draw(screen) Text.draw_text(screen, self.small_font, 'Components:', Color.white, position=(25, 220)) for box in self.installed_list: box.draw(screen) self.load_box.draw(screen) self.save_box.draw(screen) Text.draw_text(screen, self.small_font, 'Preview:', Color.white, position=(25, 460)) Text.draw_text(screen, self.small_font, 'Attack:', Color.red, position=(230, 485)) Text.draw_text(screen, self.small_font, self.ship_stats['attack'], Color.red, position=(300, 485)) Text.draw_text(screen, self.small_font, 'Armor:', Color.gray, position=(230, 510)) Text.draw_text(screen, self.small_font, self.ship_stats['armor'], Color.gray, position=(300, 510)) Text.draw_text(screen, self.small_font, 'Speed:', Color.blue, position=(230, 535)) Text.draw_text(screen, self.small_font, self.ship_stats['speed'], Color.blue, position=(300, 535)) Text.draw_text(screen, self.small_font, 'Power:', Color.yellow, position=(230, 560)) Text.draw_text(screen, self.small_font, self.ship_stats['power'], Color.yellow, position=(300, 560)) Text.draw_text(screen, self.small_font, 'Shield:', Color.green, position=(230, 585)) Text.draw_text(screen, self.small_font, self.ship_stats['shield'], Color.green, position=(300, 585)) self.ship_preview.draw_border(screen) self.ship_preview.draw(screen) def draw_component_panel(self, screen): Text.draw_text(screen, self.small_font, 'Components:', Color.white, position=(25, 110)) for component in self.component_list: component.draw(screen) def draw_ship(self, screen, position, color=None, zoom=2): if color is None: color = Color.white self.box.rect = self.get_ship_rect(position=position, zoom=zoom) # self.ship_grid.update_bounds() x = 0 for row in self.ship_grid.grid[self.ship_grid.ship_bounds['left']:self.ship_grid.ship_bounds['right']+1]: y = 0 for node in row[self.ship_grid.ship_bounds['top']:self.ship_grid.ship_bounds['bottom']+1]: if node.type is not 0: pygame.draw.rect(screen, color, pygame.Rect(position[0] + x*zoom, position[1] + y*zoom, zoom, zoom)) y += 1 x += 1 # self.box.draw(screen) def get_ship_rect(self, position=None, zoom=1): self.ship_grid.update_bounds() if position is None: position = (0, 0) return pygame.Rect(position[0], position[1], self.get_ship_size(zoom)[0], self.get_ship_size(zoom)[1]) def get_ship_size(self, zoom=1): self.ship_grid.update_bounds() w = (self.ship_grid.ship_bounds['right'] - self.ship_grid.ship_bounds['left'] + 1) * zoom h = (self.ship_grid.ship_bounds['bottom'] - self.ship_grid.ship_bounds['top'] + 1) * zoom return w, h def load(self, file_name): try: with open(file_name) as data_file: data = json.load(data_file) self.name_box.message = data['NAME'] index = 0 for row in self.ship_grid.grid: for node in row: node.type = data['GRID'][index][0] node.set_stats(data['GRID'][index][1]) index += 1 # components del self.component_inventory[:] self.make_component_list() self.add_component(Component('empty', name='REMOVE')) if "C_INV" in data: for inventory in data["C_INV"]: self.add_component(Component(component_type=inventory["TYPE"], name=inventory["NAME"], stats=inventory["STATS"])) del self.installed_components[:] if "C_ACT" in data: self.installed_components = data["C_ACT"] self.make_installed_component_list() # crew del self.crew[:] if "CREW" in data: for crew in data["CREW"]: self.add_crew(Pawn(name=crew["NAME"], age=crew["AGE"], race=crew["RACE"], bio=crew["BIO"], profile=crew["PICTURE"], ship_skills=crew["SKILLS"], battle_skills=crew["STATS"])) self.update_stats() except Exception as e: print "Failed to load ship file {0} : {1}".format(file_name, e) def save(self, file_name): dump = {'NAME': self.name_box.message} grid = [] for row in self.ship_grid.grid: for node in row: grid.append((node.type, node.get_stats())) dump['GRID'] = grid # components component_list = [] for component in self.component_inventory: if self.component_inventory.index(component) != 0: component_list.append(component.component_dict()) dump["C_INV"] = component_list dump["C_ACT"] = self.installed_components # crew crew_list = [] for crew in self.crew: crew_list.append(crew.get_data()) dump["CREW"] = crew_list with open(file_name, 'w') as outfile: json.dump(dump, outfile) print 'saved to file'
class CreateCharacter(object): def __init__(self, big_font, font, small_font, screen_height=800, screen_width=600): self.big_font = big_font self.font = font self.small_font = small_font self.box = Box(pygame.Rect(int(screen_width * 0.1), int(screen_height * 0.1), int(screen_width * 0.8), int(screen_height * 0.8)), box_color=Color.black, border_color=Color.white, border=4, highlight_box=False, name='Character Creation Box') box_x = self.box.rect.x box_y = self.box.rect.y # build portrait roster self.portrait_roster = [] self.portrait_index = 0 for face in os.listdir(settings.face_path): if face.endswith('.png'): path = os.path.join(settings.face_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) for face in os.listdir(settings.mod_path): if face.endswith('.png'): path = os.path.join(settings.mod_path, face) self.portrait_roster.append({"PATH": path, "IMAGE": pygame.image.load(path)}) self.portrait = None self.portrait_box = Box(pygame.Rect(int(box_x + self.box.rect.width / 10), int(box_y + self.box.rect.height / 7), 250, 250), box_color=Color.black, border_color=Color.white, highlight_box=False, name='Portrait Box') self.update_roster_portrait_box() self.left_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x - 35, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_left', message='<', text_color=Color.white, text_outline=True, font=self.font) self.right_portrait = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width + 10, self.portrait_box.rect.y + self.portrait_box.rect.height/3, 25, 40), box_color=Color.d_gray, border_color=Color.white, highlight_color=Color.gray, active_color=Color.white, name='p_right', message='>', text_color=Color.white, text_outline=True, font=self.font) # character name self.name = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/7, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Flash', text_color=Color.white, font=self.font, text_limit=32) # character age self.age = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2.7, 70, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='25', text_color=Color.white, font=self.font, text_limit=5, allowed_characters=range(48, 58)) # character race self.race = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/4, 400, 35), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='Human', text_color=Color.white, font=self.font, text_limit=32) # character bio self.bio = InputBox(pygame.Rect(box_x + self.box.rect.width / 2.4, box_y + self.box.rect.height/2, 400, 50), box_color=Color.d_gray, border_color=Color.gray, highlight_color=Color.white, active_color=Color.blue, message='A little bit about myself', text_color=Color.white, font=self.font, text_limit=300) # profession stuff self.profession_list = ['Pilot', 'Guns', 'Engineer', 'Medic', 'Scientist'] self.profession = TextBox(pygame.Rect(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.portrait_box.rect.y + self.portrait_box.rect.width + 20, 100, 20), highlight_color=Color.white, active_color=Color.gray, border=0, name='Profession', message=self.profession_list[0], text_color=Color.gray, font=self.small_font, highlight_box=False, highlight_text=True) self.skills = {} self.update_profession_stats() # done self.done = TextBox(pygame.Rect(box_x + self.box.rect.width - 150, box_y + self.box.rect.height - 100, 100, 50), box_color=Color.red, border_color=Color.gray, highlight_color=Color.white, active_color=Color.gray, name='done', message='START', text_color=Color.white, text_outline=True, font=self.font) def return_character(self): pawn = Pawn(name=self.name.message, age=self.age.message, race=self.race.message, bio=self.bio.message, profile=self.portrait_roster[self.portrait_index]["PATH"], battle_skills=self.skills) pawn.ship_skills[self.profession.message] = 1 return pawn def update_roster_portrait_box(self): self.portrait = self.portrait_roster[self.portrait_index]["IMAGE"] self.portrait_box.image = self.portrait def update_profession_stats(self): if self.profession.message == 'Pilot': self.skills = {'Melee': 2, 'Ranged': 1, 'Defense': 1, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Guns': self.skills = {'Melee': 1, 'Ranged': 2, 'Defense': 1, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Engineer': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 1, 'Intelligence': 1, 'Speed': 2} elif self.profession.message == 'Medic': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 2, 'Intelligence': 1, 'Speed': 1} elif self.profession.message == 'Scientist': self.skills = {'Melee': 1, 'Ranged': 1, 'Defense': 1, 'Intelligence': 2, 'Speed': 1} def update(self, key, mouse, offset=(0, 0)): if self.portrait_index > 0 and self.left_portrait.update(key=key, mouse=mouse, offset=offset): self.portrait_index -= 1 self.update_roster_portrait_box() if self.portrait_index < len(self.portrait_roster)-1 \ and self.right_portrait.update(key=key, mouse=mouse, offset=offset): self.portrait_index += 1 self.update_roster_portrait_box() self.name.update(key=key, mouse=mouse, offset=offset) self.age.update(key=key, mouse=mouse, offset=offset) self.race.update(key=key, mouse=mouse, offset=offset) self.bio.update(key=key, mouse=mouse, offset=offset) # if self.profession.update(key=key, mouse=mouse, offset=offset): if self.profession.message == self.profession_list[-1]: self.profession.message = self.profession_list[0] else: self.profession.message = self.profession_list[self.profession_list.index(self.profession.message)+1] self.update_profession_stats() # if self.done.update(key=key, mouse=mouse, offset=offset): return self.return_character() return def draw(self, screen): self.box.draw(screen) # non-interactive title = 'Create Your Character' title_width = self.big_font.size(title)[0] Text.draw_text(screen, self.big_font, text=title, color=Color.blue, position=(self.box.rect.x+(self.box.rect.width - title_width)/2, self.box.rect.y + 5)) Text.draw_text(screen, self.small_font, text='Name:', color=Color.green, position=(self.name.rect.x, self.name.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Race:', color=Color.green, position=(self.race.rect.x, self.race.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Age:', color=Color.green, position=(self.age.rect.x, self.age.rect.y - 20)) Text.draw_text(screen, self.small_font, text='Biography:', color=Color.green, position=(self.bio.rect.x, self.bio.rect.y - 20)) # profession box Text.draw_text(screen, self.small_font, text='Profession:', color=Color.l_gray, position=(self.portrait_box.rect.x, self.profession.rect.y)) # stats i = 25 for key, value in self.skills.iteritems(): Text.draw_text(screen, self.small_font, text=key, color=Color.l_gray, position=(self.portrait_box.rect.x, self.profession.rect.y + i)) Text.draw_text(screen, self.small_font, text=value, color=Color.l_gray, position=(self.portrait_box.rect.x + self.portrait_box.rect.width/2, self.profession.rect.y + i)) i += 25 # buttons and things self.portrait_box.draw(screen) self.left_portrait.draw(screen) self.right_portrait.draw(screen) # boxes self.name.draw(screen) self.race.draw(screen) self.age.draw(screen) self.bio.draw(screen) # self.profession.draw(screen) # self.done.draw(screen)