def draw(menu): _y_mod = 0 _yy_mod = 0 for item_id in menu['items']: _item = menu['items'][item_id] _text = ' %s ' % _item['text'] if ACTIVE_MENU == menu and menu['index'] == _y_mod: _back_color = (65, 65, 65) else: _back_color = _item['back_color'] for i in range(-1, 2): if i: display.write_string(menu['surface'], menu['x'], menu['y'] + _y_mod + _yy_mod, ' ' * len(_text), fore_color=_item['fore_color'], back_color=_back_color) else: display.write_string(menu['surface'], menu['x'], menu['y'] + _y_mod + _yy_mod, _text, fore_color=_item['fore_color'], back_color=_back_color) _yy_mod += 1 _yy_mod -= 1 _y_mod += 1
def draw_mission_details(): for mission_id in PLAYER['missions']['active']: _mission = entities.get_entity(mission_id) _valid_goals = [g for g in _mission['goals']] _y_mod = constants.MAP_VIEW_HEIGHT - len(_valid_goals) - 1 display.write_string('ui', 1, _y_mod - 2, _mission['title'], fore_color=(200, 200, 200), back_color=(10, 10, 10)) for goal_id in _valid_goals: _goal = entities.get_entity(goal_id) entities.trigger_event(_goal, 'get_message', member_id=PLAYER['_id']) if not _goal['draw']: continue if PLAYER['missions']['active'][mission_id]['goals'][goal_id]['complete']: _fore_color = (200, 200, 200) _text = '+ %s' % _goal['message'] else: _fore_color = (255, 255, 255) _text = '- %s' % _goal['message'] display.write_string('ui', 1, _y_mod, _text, fore_color=_fore_color, back_color=(30, 30, 30)) _y_mod += 1
def draw_item_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_items = entities.get_entity_group('items') else: _draw_items = [item for _items in PLAYER['ai']['visible_items'].values() for item in _items] for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _label = _entity['stats']['name'] _render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label)) _render_y = numbers.clip(_y + 2, 0, _height) if _render_y == _y: _render_y -= 1 display.write_string('ui', _render_x, _render_y, _label)
def clear_bar(): for y in range(constants.WINDOW_HEIGHT - constants.STRAT_MAP_HEIGHT): display.write_string('ui_bar', 0, y, ' ' * constants.WINDOW_WIDTH, back_color=(30, 30, 30))
def draw_turn_bar(): if not ai_flow.is_flow_active(): return _squad = entities.get_entity(ai_flow.get_active_squad()) _current_action_points = sum([entities.get_entity(m)['stats']['action_points'] for m in _squad['members']]) _max_action_points = sum([entities.get_entity(m)['stats']['action_points_max'] for m in _squad['members']]) _mod = _current_action_points / float(_max_action_points) _filled_value = int(round(constants.MAP_VIEW_WIDTH * _mod)) if _squad['faction'] == 'Rogues': _message = 'Action points: %s' % _current_action_points _fore_color = (0, 200, 0) _back_color = (0, 50, 0) elif entities.get_entity(_squad['leader'])['ai']['faction'] in ai_factions.FACTIONS['Rogues']['enemies']: _message = 'Enemy' _fore_color = (200, 0, 0) _back_color = (50, 0, 0) else: _message = 'Friendly' _fore_color = (0, 200, 200) _back_color = (0, 50, 50) _n = len(_message) _string = _message + ('=' * (_filled_value-_n)) + (' ' * ((constants.MAP_VIEW_WIDTH-_filled_value-1))) display.write_string('nodes', 0, 0, _string[:constants.MAP_VIEW_WIDTH], fore_color=_fore_color, back_color=_back_color)
def flavor_print(x, y, lines): _y = y for _favor_text in lines: display.write_string("ui_bar", x, _y, _favor_text[0]) display.write_string("ui_bar", x + len(_favor_text[0]), _y, _favor_text[1], fore_color=_favor_text[2]) _y += 1
def draw_news(news): _chr = chr(65 + 1) _text_y_mod = 0 for text, fore_color, back_color in news: display.write_string("ui_bar", 1, 1 + _text_y_mod, text, fore_color=fore_color, back_color=back_color) _text_y_mod += 1
def _draw_message(): _minutes = int(round(TIME)) _time = '%s:%02d' % (_minutes / 60, _minutes - ((_minutes / 60) * 60)) _message = 'Day 1 - %s' % _time display.write_string('map_squads', (constants.STRAT_MAP_WIDTH / 2) - len(_message) / 2, constants.STRAT_MAP_HEIGHT / 2, _message)
def draw_time(): _minutes = int(round(world_strategy.TIME)) _time = '%s:%02d' % (_minutes / 60, _minutes - ((_minutes / 60) * 60)) display.write_string('ui_bar', constants.WINDOW_WIDTH - len(_time) - 1, 1, _time, back_color=(30, 30, 30))
def draw_money(): _money = ai_factions.FACTIONS["Rogues"]["money"] _money_string = "%s" % int(round(_money)) display.write_string("ui_bar", constants.WINDOW_WIDTH - len(_money_string) - 3, 2, "$") display.write_string( "ui_bar", constants.WINDOW_WIDTH - len(_money_string) - 1, 2, _money_string, fore_color=(60, 200, 60) )
def draw_life_memory(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life = set() _can_see_life = set() _last_seen_locations = {} for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _can_see_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _draw_life.update(_member['ai']['targets'] - _member['ai']['visible_life']) for memory_id in _member['ai']['life_memory'].keys(): if not member_id in _last_seen_locations and _member['ai']['life_memory'][memory_id]['last_seen_at']: _last_seen_locations[memory_id] = _member['ai']['life_memory'][memory_id]['last_seen_at'] _draw_life = list(_draw_life) for entity_id in _draw_life: if entity_id in _can_see_life or not entity_id in entities.ENTITIES: continue if not entity_id in _last_seen_locations: continue _entity = entities.get_entity(entity_id) _x, _y = _last_seen_locations[entity_id] _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue if time.time() % 1 >= .5: _char = _entity['tile']['char'] _fore_color = _entity['tile']['fore_color'] else: _char = '!' _fore_color = (255, 0, 0) _render_x = numbers.clip(_x - len(_char)/2, 0, _width - len(_char) - 1) _render_y = numbers.clip(_y, 0, _height) #if _x - len(_char)/2 < 0 or _x + len(_char)/2 >= _width: # continue if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _char, fore_color=_fore_color)
def flavor_print(x, y, lines): _y = y for _favor_text in lines: display.write_string('ui_bar', x, _y, _favor_text[0]) display.write_string('ui_bar', x + len(_favor_text[0]), _y, _favor_text[1], fore_color=_favor_text[2]) _y += 1
def draw_money(): _money = ai_factions.FACTIONS['Rogues']['money'] _money_string = '%s' % int(round(_money)) display.write_string('ui_bar', constants.WINDOW_WIDTH - len(_money_string) - 3, 2, '$') display.write_string('ui_bar', constants.WINDOW_WIDTH - len(_money_string) - 1, 2, _money_string, fore_color=(60, 200, 60))
def draw_news(news): _chr = chr(65 + 1) _text_y_mod = 0 for text, fore_color, back_color in news: display.write_string('ui_bar', 1, 1 + _text_y_mod, text, fore_color=fore_color, back_color=back_color) _text_y_mod += 1
def loop(): global UNSCRAMBLE_TO, WHITE_VALUE, SUBTITLE_COLOR for i in range(len(COMPANY_STRING)): if i > UNSCRAMBLE_TO: _char = random.choice(COMPANY_STRING) _gray_color = int(round(255 * (UNSCRAMBLE_TO / i))) + random.randint(-15, 15) _fore_color = (_gray_color, _gray_color, _gray_color) else: _char = COMPANY_STRING[i] _r = numbers.clip(WHITE_VALUE - random.randint(0, 90), 0, 255) _g = _r _b = _r _fore_color = _r, _g, _b display.write_char( "text", (constants.WINDOW_WIDTH / 2) + i - (len(COMPANY_STRING) / 2), (constants.WINDOW_HEIGHT / 2) - 1, _char, fore_color=_fore_color, ) display.write_string( "text", (constants.WINDOW_WIDTH / 2) - (len(SUBTITLE_TEXT) / 2), (constants.WINDOW_HEIGHT / 2) + 1, SUBTITLE_TEXT, fore_color=(SUBTITLE_COLOR, SUBTITLE_COLOR, SUBTITLE_COLOR), ) if UNSCRAMBLE_TO > 6: SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR + 2, 0, 255) if UNSCRAMBLE_TO > 25: WHITE_VALUE -= 2 SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR - 6, 0, 255) if UNSCRAMBLE_TO > 38: return False display.blit_surface("text") events.trigger_event("draw") UNSCRAMBLE_TO += 0.1 return True
def draw_long_range_life(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life_targets = set() if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _draw_life.add(member_id) _draw_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _draw_life_targets.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and _member['ai']['life_memory'][i]['is_target'] and i in entities.ENTITIES]) _draw_life = list(_draw_life) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: _x = numbers.clip(_x, 0, _width-1) _y = numbers.clip(_y, 0, _height-1) else: continue if time.time() % 1 >= .5: _char = 'X' else: _char = 'O' if entity_id in _draw_life_targets: _fore_color = (255, 0, 0) _back_color = (100, 0, 0) else: _fore_color = (255, 255, 255) _back_color = (100, 100, 100) display.write_string('ui', _x, _y, _char, fore_color=_fore_color, back_color=_back_color)
def loop(): global UNSCRAMBLE_TO, WHITE_VALUE, SUBTITLE_COLOR for i in range(len(COMPANY_STRING)): if i > UNSCRAMBLE_TO: _char = random.choice(COMPANY_STRING) _gray_color = int(round( 255 * (UNSCRAMBLE_TO / i))) + random.randint(-15, 15) _fore_color = (_gray_color, _gray_color, _gray_color) else: _char = COMPANY_STRING[i] _r = numbers.clip(WHITE_VALUE - random.randint(0, 90), 0, 255) _g = _r _b = _r _fore_color = _r, _g, _b display.write_char('text', (constants.WINDOW_WIDTH / 2) + i - (len(COMPANY_STRING) / 2), (constants.WINDOW_HEIGHT / 2) - 1, _char, fore_color=_fore_color) display.write_string( 'text', (constants.WINDOW_WIDTH / 2) - (len(SUBTITLE_TEXT) / 2), (constants.WINDOW_HEIGHT / 2) + 1, SUBTITLE_TEXT, fore_color=(SUBTITLE_COLOR, SUBTITLE_COLOR, SUBTITLE_COLOR)) if UNSCRAMBLE_TO > 6: SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR + 2, 0, 255) if UNSCRAMBLE_TO > 25: WHITE_VALUE -= 2 SUBTITLE_COLOR = numbers.clip(SUBTITLE_COLOR - 6, 0, 255) if UNSCRAMBLE_TO > 38: return False display.blit_surface('text') events.trigger_event('draw') UNSCRAMBLE_TO += .1 return True
def draw_life_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = [ i for i in PLAYER['ai']['life_memory'] if PLAYER['ai']['life_memory'][i]['can_see'] ] if PLAYER['_id'] in entities.ENTITIES: _draw_life.append(PLAYER['_id']) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _back_color = None if settings.OBSERVER_MODE: _label = _entity['ai']['current_action'] else: _label = life.get_status_string(_entity) if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][ entity_id]['mission_related'] and time.time() % 1 >= .5: _back_color = (200, 0, 0) _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label)) _render_y = numbers.clip(_y - 2, 0, _height) if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _label, back_color=_back_color)
def draw_status_bar(planning=False, executing=False, execute_speed='', selecting=False): _x = 0 if planning: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'PLANNING', back_color=(15, 15, 15)) _x += len('PLANNING') + 1 if executing: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'EXECUTING', back_color=(15, 15, 15)) _x += len('EXECUTING') + 1 if execute_speed: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, execute_speed, back_color=(15, 15, 15)) _x += len(execute_speed) + 1 if selecting: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'SELECTING TARGET', back_color=(15, 15, 15)) _x += len('SELECTING TARGET') + 1 display.write_string('ui', _x - 1, constants.MAP_VIEW_HEIGHT, ' ' * (constants.MAP_VIEW_WIDTH - _x + 1), back_color=(15, 15, 15))
def draw_raid_info(squad_id, camp_id): _camp = world_strategy.MAP['grid'][camp_id] _squad = entities.get_entity(squad_id) _travel_distance = numbers.distance(movement.get_position_via_id(squad_id), camp_id) _highest_speed = 0 _cost = ai_squads.get_attack_cost(_squad, camp_id) for member_id in _squad['members']: _member = entities.get_entity(member_id) _speed = movement.get_move_cost(_member) if _speed > _highest_speed: _highest_speed = _speed _travel_time = _travel_distance * (_highest_speed * 80) _time_string = '%s hours %s minutes' % (_travel_time / 60, _travel_time - ((_travel_time / 60) * 60)) _info = 'Right Click Camp to Confirm Order, ESC to cancel' if time.time() % 1 >= .5: _info_color = (200, 0, 0) else: _info_color = (200, 80, 80) display.write_string('ui_bar', (constants.WINDOW_WIDTH / 2) - (len(_info) / 2), 0, _info, fore_color=_info_color) display.write_string('ui_bar', 1, 1, 'Raid Order', fore_color=(200, 50, 70)) flavor_print(1, 3, [('Risk: ', 'Low', constants.STATUS_GOOD), ('Cost: $ ', '%i' % _cost, constants.STATUS_GOOD), ('Supplies needed: ', '%i' % 12, constants.STATUS_OK), ('Travel time: ', _time_string, constants.STATUS_OK)]) flavor_print(35, 3, [('Test value: ', 'Low', constants.STATUS_GOOD)])
def draw_turn_bar(): if not ai_flow.is_flow_active(): return _squad = entities.get_entity(ai_flow.get_active_squad()) _current_action_points = sum([ entities.get_entity(m)['stats']['action_points'] for m in _squad['members'] ]) _max_action_points = sum([ entities.get_entity(m)['stats']['action_points_max'] for m in _squad['members'] ]) _mod = _current_action_points / float(_max_action_points) _filled_value = int(round(constants.MAP_VIEW_WIDTH * _mod)) if _squad['faction'] == 'Rogues': _message = 'Action points: %s' % _current_action_points _fore_color = (0, 200, 0) _back_color = (0, 50, 0) elif entities.get_entity( _squad['leader'] )['ai']['faction'] in ai_factions.FACTIONS['Rogues']['enemies']: _message = 'Enemy' _fore_color = (200, 0, 0) _back_color = (50, 0, 0) else: _message = 'Friendly' _fore_color = (0, 200, 200) _back_color = (0, 50, 50) _n = len(_message) _string = _message + ('=' * (_filled_value - _n)) + (' ' * ( (constants.MAP_VIEW_WIDTH - _filled_value - 1))) display.write_string('nodes', 0, 0, _string[:constants.MAP_VIEW_WIDTH], fore_color=_fore_color, back_color=_back_color)
def _printer_draw(entity): _text = flags.get_flag(entity, 'text') _text_index = flags.get_flag(entity, 'text_index') _text_center = flags.get_flag(entity, 'text_center') _text_fore_color = flags.get_flag(entity, 'text_fore_color') _text_back_color = flags.get_flag(entity, 'text_back_color') _x, _y = flags.get_flag(entity, 'text_pos') if _text_center: if _x + len(_text[:_text_index])/2 >= camera.X + constants.MAP_VIEW_WIDTH-1: return if _x - len(_text[:_text_index])/2 < camera.X: return if _y >= camera.Y + constants.MAP_VIEW_HEIGHT: return _x -= len(_text[:_text_index])/2 display.write_string('ui', _x-camera.X, _y-camera.Y, _text[:_text_index], fore_color=_text_fore_color, back_color=_text_back_color)
def draw(dialog, surface): _y_mod = 0 _text = dialog['text'].split('\n') _widest = max([len(l) for l in _text]) + 2 for i in range(-3, 3): if i == -3: display.write_string(surface, dialog['x'], dialog['y'] + _y_mod, ' %s ' % dialog['title'] + ' ' * ((_widest - len(dialog['title'])) - 2), fore_color=(250, 250, 250), back_color=(60, 60, 60)) _y_mod += 1 elif i: display.write_string(surface, dialog['x'], dialog['y'] + _y_mod, ' ' * _widest, back_color=(10, 10, 10)) _y_mod += 1 else: for line in _text: display.write_string(surface, dialog['x'], dialog['y'] + _y_mod, ' %s ' % (line + ' ' * (_widest - len(line) - 2)), back_color=(10, 10, 10)) _y_mod += 1
def draw_raid_info(squad_id, camp_id): _camp = world_strategy.MAP["grid"][camp_id] _squad = entities.get_entity(squad_id) _travel_distance = numbers.distance(movement.get_position_via_id(squad_id), camp_id) _highest_speed = 0 _cost = ai_squads.get_attack_cost(_squad, camp_id) for member_id in _squad["members"]: _member = entities.get_entity(member_id) _speed = movement.get_move_cost(_member) if _speed > _highest_speed: _highest_speed = _speed _travel_time = _travel_distance * (_highest_speed * 80) _time_string = "%s hours %s minutes" % (_travel_time / 60, _travel_time - ((_travel_time / 60) * 60)) _info = "Right Click Camp to Confirm Order, ESC to cancel" if time.time() % 1 >= 0.5: _info_color = (200, 0, 0) else: _info_color = (200, 80, 80) display.write_string("ui_bar", (constants.WINDOW_WIDTH / 2) - (len(_info) / 2), 0, _info, fore_color=_info_color) display.write_string("ui_bar", 1, 1, "Raid Order", fore_color=(200, 50, 70)) flavor_print( 1, 3, [ ("Risk: ", "Low", constants.STATUS_GOOD), ("Cost: $ ", "%i" % _cost, constants.STATUS_GOOD), ("Supplies needed: ", "%i" % 12, constants.STATUS_OK), ("Travel time: ", _time_string, constants.STATUS_OK), ], ) flavor_print(35, 3, [("Test value: ", "Low", constants.STATUS_GOOD)])
def draw(dialog, surface): _y_mod = 0 _text = dialog['text'].split('\n') _widest = max([len(l) for l in _text]) + 2 for i in range(-3, 3): if i == -3: display.write_string(surface, dialog['x'], dialog['y']+_y_mod, ' %s ' % dialog['title'] + ' ' * ((_widest - len(dialog['title']))-2), fore_color=(250, 250, 250), back_color=(60, 60, 60)) _y_mod += 1 elif i: display.write_string(surface, dialog['x'], dialog['y']+_y_mod, ' ' * _widest, back_color=(10, 10, 10)) _y_mod += 1 else: for line in _text: display.write_string(surface, dialog['x'], dialog['y']+_y_mod, ' %s ' % (line + ' ' * (_widest-len(line)-2)), back_color=(10, 10, 10)) _y_mod += 1
def draw_life_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = [i for i in PLAYER['ai']['life_memory'] if PLAYER['ai']['life_memory'][i]['can_see']] if PLAYER['_id'] in entities.ENTITIES: _draw_life.append(PLAYER['_id']) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _back_color = None if settings.OBSERVER_MODE: _label = _entity['ai']['current_action'] else: _label = life.get_status_string(_entity) if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][entity_id]['mission_related'] and time.time() % 1 >= .5: _back_color = (200, 0, 0) _render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label)) _render_y = numbers.clip(_y - 2, 0, _height) if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _label, back_color=_back_color)
def draw_mission_details(): for mission_id in PLAYER['missions']['active']: _mission = entities.get_entity(mission_id) _valid_goals = [g for g in _mission['goals']] _y_mod = constants.MAP_VIEW_HEIGHT - len(_valid_goals) - 1 display.write_string('ui', 1, _y_mod - 2, _mission['title'], fore_color=(200, 200, 200), back_color=(10, 10, 10)) for goal_id in _valid_goals: _goal = entities.get_entity(goal_id) entities.trigger_event(_goal, 'get_message', member_id=PLAYER['_id']) if not _goal['draw']: continue if PLAYER['missions']['active'][mission_id]['goals'][goal_id][ 'complete']: _fore_color = (200, 200, 200) _text = '+ %s' % _goal['message'] else: _fore_color = (255, 255, 255) _text = '- %s' % _goal['message'] display.write_string('ui', 1, _y_mod, _text, fore_color=_fore_color, back_color=(30, 30, 30)) _y_mod += 1
def draw(menu): _y_mod = 0 _yy_mod = 0 for item_id in menu['items']: _item = menu['items'][item_id] _text = ' %s '% _item['text'] if ACTIVE_MENU == menu and menu['index'] == _y_mod: _back_color = (65, 65, 65) else: _back_color = _item['back_color'] for i in range(-1, 2): if i: display.write_string(menu['surface'], menu['x'], menu['y']+_y_mod+_yy_mod, ' ' * len(_text), fore_color=_item['fore_color'], back_color=_back_color) else: display.write_string(menu['surface'], menu['x'], menu['y']+_y_mod+_yy_mod, _text, fore_color=_item['fore_color'], back_color=_back_color) _yy_mod += 1 _yy_mod -= 1 _y_mod += 1
def _message_draw(entity): _text = flags.get_flag(entity, 'text') _index = flags.get_flag(entity, 'index') _center = flags.get_flag(entity, 'center') _vert_center = flags.get_flag(entity, 'vert_center') if _center: _x = (constants.MAP_VIEW_WIDTH / 2) - (len(_text) / 2) else: _x = 3 if _vert_center: _y = (constants.MAP_VIEW_HEIGHT / 2) - 1 else: _y = 1 for i in range(0, 3): if i == 1: display.write_string('ui', _x, _y + i + (4 * _index), ' %s ' % _text, fore_color=(200, 200, 200), back_color=(60, 60, 60)) else: display.write_string('ui', _x, _y + i + (4 * _index), ' ' * (len(_text) + 4), fore_color=(20, 20, 20), back_color=(60, 60, 60))
def draw_item_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_items = entities.get_entity_group('items') else: _draw_items = [ item for _items in PLAYER['ai']['visible_items'].values() for item in _items ] for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _label = _entity['stats']['name'] _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label)) _render_y = numbers.clip(_y + 2, 0, _height) if _render_y == _y: _render_y -= 1 display.write_string('ui', _render_x, _render_y, _label)
def draw_status_bar(planning=False, executing=False, execute_speed='', selecting=False): _x = 0 if planning: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'PLANNING', back_color=(15, 15, 15)) _x += len('PLANNING')+1 if executing: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'EXECUTING', back_color=(15, 15, 15)) _x += len('EXECUTING')+1 if execute_speed: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, execute_speed, back_color=(15, 15, 15)) _x += len(execute_speed)+1 if selecting: display.write_string('ui', _x, constants.MAP_VIEW_HEIGHT, 'SELECTING TARGET', back_color=(15, 15, 15)) _x += len('SELECTING TARGET')+1 display.write_string('ui', _x - 1, constants.MAP_VIEW_HEIGHT, ' ' * (constants.MAP_VIEW_WIDTH - _x + 1), back_color=(15, 15, 15))
def draw_squad_info(squad_id): _text_y_mod = 0 _squad = entities.get_entity(squad_id) for member_id in _squad['members']: _member = entities.get_entity(member_id) _health_string = '[OK]' _weapon = items.get_items_in_holder(_member, 'weapon') if _weapon: _weapon_name = '<%s>' % entities.get_entity( _weapon[0])['stats']['name'] else: _weapon_name = '<None>' _class = _member['stats']['class'] display.write_string('ui_bar', 1, 1 + _text_y_mod, _member['stats']['name'], fore_color=(204, 200, 204)) display.write_string('ui_bar', 2 + len(_member['stats']['name']), 1 + _text_y_mod, _health_string, fore_color=(200, 200, 34)) display.write_string('ui_bar', 3 + len(_member['stats']['name']) + len(_health_string), 1 + _text_y_mod, _weapon_name, fore_color=(0, 200, 34)) display.write_string('ui_bar', 4 + len(_member['stats']['name']) + len(_health_string) + len(_weapon_name), 1 + _text_y_mod, _class, fore_color=(200, 50, 200), back_color=(50, 12, 50)) _text_y_mod += 1
def draw_squad_info(squad_id): _text_y_mod = 0 _squad = entities.get_entity(squad_id) for member_id in _squad["members"]: _member = entities.get_entity(member_id) _health_string = "[OK]" _weapon = items.get_items_in_holder(_member, "weapon") if _weapon: _weapon_name = "<%s>" % entities.get_entity(_weapon[0])["stats"]["name"] else: _weapon_name = "<None>" _class = _member["stats"]["class"] display.write_string("ui_bar", 1, 1 + _text_y_mod, _member["stats"]["name"], fore_color=(204, 200, 204)) display.write_string( "ui_bar", 2 + len(_member["stats"]["name"]), 1 + _text_y_mod, _health_string, fore_color=(200, 200, 34) ) display.write_string( "ui_bar", 3 + len(_member["stats"]["name"]) + len(_health_string), 1 + _text_y_mod, _weapon_name, fore_color=(0, 200, 34), ) display.write_string( "ui_bar", 4 + len(_member["stats"]["name"]) + len(_health_string) + len(_weapon_name), 1 + _text_y_mod, _class, fore_color=(200, 50, 200), back_color=(50, 12, 50), ) _text_y_mod += 1
def draw_fps(): display.write_string('ui', 0, 0, '%s fps' % display.get_fps(), fore_color=(255, 255, 255))
def draw_life_memory(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life = set() _can_see_life = set() _last_seen_locations = {} for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _can_see_life.update([ i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES ]) _draw_life.update(_member['ai']['targets'] - _member['ai']['visible_life']) for memory_id in _member['ai']['life_memory'].keys(): if not member_id in _last_seen_locations and _member['ai'][ 'life_memory'][memory_id]['last_seen_at']: _last_seen_locations[memory_id] = _member['ai'][ 'life_memory'][memory_id]['last_seen_at'] _draw_life = list(_draw_life) for entity_id in _draw_life: if entity_id in _can_see_life or not entity_id in entities.ENTITIES: continue if not entity_id in _last_seen_locations: continue _entity = entities.get_entity(entity_id) _x, _y = _last_seen_locations[entity_id] _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue if time.time() % 1 >= .5: _char = _entity['tile']['char'] _fore_color = _entity['tile']['fore_color'] else: _char = '!' _fore_color = (255, 0, 0) _render_x = numbers.clip(_x - len(_char) / 2, 0, _width - len(_char) - 1) _render_y = numbers.clip(_y, 0, _height) #if _x - len(_char)/2 < 0 or _x + len(_char)/2 >= _width: # continue if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _char, fore_color=_fore_color)
def draw_time(): _minutes = int(round(world_strategy.TIME)) _time = "%s:%02d" % (_minutes / 60, _minutes - ((_minutes / 60) * 60)) display.write_string("ui_bar", constants.WINDOW_WIDTH - len(_time) - 1, 1, _time, back_color=(30, 30, 30))
def clear_bar(): for y in range(constants.WINDOW_HEIGHT - constants.STRAT_MAP_HEIGHT): display.write_string("ui_bar", 0, y, " " * constants.WINDOW_WIDTH, back_color=(30, 30, 30))
def draw(): #Title _i = 0 _dst_x = 9999 for c in TEXT[0]: _alpha = numbers.clip( FADE_ALPHA * numbers.clip(16 - _i, 7, 16) / SPARK_SIZE, 0, 1) _dx = ((constants.WINDOW_WIDTH / 2) - (len(''.join(TEXT)) / 2)) + _i if _dx < _dst_x: _dst_x = _dx _batch = display.create_batch(len(TEXT[0]), 1, _dst_x, 12) _i = 0 for c in TEXT[0]: _alpha = numbers.clip( FADE_ALPHA * numbers.clip(16 - _i, 7, 16) / SPARK_SIZE, 0, 1) display.write_char_batch( _batch, ((constants.WINDOW_WIDTH / 2) - (len(''.join(TEXT)) / 2)) + _i, 12, c, fore_color=(200 * _alpha, 200 * _alpha, 200 * _alpha)) _i += 1 display.draw_batch(_batch, 'text') _i = 0 for c in TEXT[1]: _alpha = numbers.clip( FADE_ALPHA * numbers.clip(18 - _i, 0, 18) / SPARK_SIZE, 0, 1) display.write_char('text', ((constants.WINDOW_WIDTH / 2) - (len(TEXT[1]) / 2)) + _i, 13, c.upper(), fore_color=(200 * _alpha, 60 * _alpha, 80 * _alpha)) _i += 1 #Menu _i = 0 for item in [('Continue', False), ('New', True), ('Quit', True)]: if item[1]: _fore_color = (200 * FADE_ALPHA, 200 * FADE_ALPHA, 200 * FADE_ALPHA) else: _fore_color = (100 * FADE_ALPHA, 100 * FADE_ALPHA, 100 * FADE_ALPHA) if MENU_ITEM_SELECTED == _i: _text = '> %s <' % item[0] else: _text = item[0] display.write_string('text', (constants.WINDOW_WIDTH / 2) - (len(_text) / 2), 18 + _i, _text, fore_color=_fore_color) _i += 1 paint_map() display.blit_surface_viewport('background', 0, 0, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT) display.blit_surface('text')
def draw_long_range_life(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life_targets = set() if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _draw_life.add(member_id) _draw_life.update([ i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES ]) _draw_life_targets.update([ i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and _member['ai']['life_memory'][i]['is_target'] and i in entities.ENTITIES ]) _draw_life = list(_draw_life) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: _x = numbers.clip(_x, 0, _width - 1) _y = numbers.clip(_y, 0, _height - 1) else: continue if time.time() % 1 >= .5: _char = 'X' else: _char = 'O' if entity_id in _draw_life_targets: _fore_color = (255, 0, 0) _back_color = (100, 0, 0) else: _fore_color = (255, 255, 255) _back_color = (100, 100, 100) display.write_string('ui', _x, _y, _char, fore_color=_fore_color, back_color=_back_color)
def draw(): # Title _i = 0 _dst_x = 9999 for c in TEXT[0]: _alpha = numbers.clip(FADE_ALPHA * numbers.clip(16 - _i, 7, 16) / SPARK_SIZE, 0, 1) _dx = ((constants.WINDOW_WIDTH / 2) - (len("".join(TEXT)) / 2)) + _i if _dx < _dst_x: _dst_x = _dx _batch = display.create_batch(len(TEXT[0]), 1, _dst_x, 12) _i = 0 for c in TEXT[0]: _alpha = numbers.clip(FADE_ALPHA * numbers.clip(16 - _i, 7, 16) / SPARK_SIZE, 0, 1) display.write_char_batch( _batch, ((constants.WINDOW_WIDTH / 2) - (len("".join(TEXT)) / 2)) + _i, 12, c, fore_color=(200 * _alpha, 200 * _alpha, 200 * _alpha), ) _i += 1 display.draw_batch(_batch, "text") _i = 0 for c in TEXT[1]: _alpha = numbers.clip(FADE_ALPHA * numbers.clip(18 - _i, 0, 18) / SPARK_SIZE, 0, 1) display.write_char( "text", ((constants.WINDOW_WIDTH / 2) - (len(TEXT[1]) / 2)) + _i, 13, c.upper(), fore_color=(200 * _alpha, 60 * _alpha, 80 * _alpha), ) _i += 1 # Menu _i = 0 for item in [("Continue", False), ("New", True), ("Quit", True)]: if item[1]: _fore_color = (200 * FADE_ALPHA, 200 * FADE_ALPHA, 200 * FADE_ALPHA) else: _fore_color = (100 * FADE_ALPHA, 100 * FADE_ALPHA, 100 * FADE_ALPHA) if MENU_ITEM_SELECTED == _i: _text = "> %s <" % item[0] else: _text = item[0] display.write_string( "text", (constants.WINDOW_WIDTH / 2) - (len(_text) / 2), 18 + _i, _text, fore_color=_fore_color ) _i += 1 paint_map() display.blit_surface_viewport("background", 0, 0, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT) display.blit_surface("text")
def draw(): _x = 3 _y_mod = 0 _total_money = 0 display.write_string('text', (SIDEBAR_WIDTH / 2) - (len(TITLE) / 2), 3, TITLE, fore_color=(255, 255, 255)) for squad_member in HIRED_MEMBERS: _y = 10 + _y_mod _name = squad_member['name'] display.write_string('text', _x, _y - 2, _name, fore_color=(255, 255, 255)) display.write_string('text', _x, _y - 1, squad_member['skill_focus'].title() + ' ' * (len(_name) - len(squad_member['skill_focus'])), fore_color=(180, 180, 180), back_color=(40, 40, 40)) for stat in SKILL_NAMES: _r = int(round(220 * (1 - (squad_member[stat] / 75.0)))) _g = int(round(250 * (squad_member[stat] / 75.0))) display.write_string('text', _x, _y + 1, '%s' % stat.upper()) display.write_string('text', _x + len(stat), _y + 1, '.' * (15 - len(stat)), fore_color=(80, 80, 80)) display.write_string('text', _x + 15, _y + 1, '%s' % squad_member[stat], fore_color=(_r, _g, 0)) _y += 1 display.write_string('text', _x, _y + 2, 'Pay: ') display.write_string('text', _x + 6, _y + 2, '$%.2f' % squad_member['pay'], fore_color=(0, 200, 0), back_color=(0, 40, 0)) display.write_string('text', _x + 6 + len('$%.2f' % squad_member['pay']) + 0, _y + 2, '/week', fore_color=(150, 150, 150), back_color=(0, 0, 0)) _x += 20 if _x > 40: _x = 3 _y_mod += 12 _total_money += squad_member['pay'] #for y in range(12, 14): #for x in range(SIDEBAR_WIDTH + 10, constants.WINDOW_WIDTH - 14): display.write_string('text', SIDEBAR_WIDTH + 10, 12, 'Operation', fore_color=(255, 255, 255)) display.write_string('text', SIDEBAR_WIDTH + 10, 13, 'Dark Wing', fore_color=(255, 255, 255)) for y in range(20, 28): for x in range(SIDEBAR_WIDTH + 10, constants.WINDOW_WIDTH - 14): display.write_char('text', x, y, '#', fore_color=(255, 255, 255)) display.write_string('text', SIDEBAR_WIDTH + 5, 29, 'No contact outside the town.', fore_color=(255, 255, 255)) _i = 0 for feat in FEATS: display.write_string('text', 3, _y + 5 + _i, feat[0][0], fore_color=feat[0][1]) display.write_string('text', 3 + len(feat[0][0]), _y + 5 + _i, '- ' + feat[1], fore_color=(255, 255, 255)) _i += 1 display.write_string('text', 3, constants.WINDOW_HEIGHT - 4, '<Space>', fore_color=(255, 255, 255)) display.write_string('text', 10, constants.WINDOW_HEIGHT - 4, ' - Reroll', fore_color=(200, 200, 200)) display.write_string('text', 3, constants.WINDOW_HEIGHT - 5, '<Enter>', fore_color=(255, 255, 255)) display.write_string('text', 10, constants.WINDOW_HEIGHT - 5, ' - Accept', fore_color=(200, 200, 200)) display.write_string('text', 3, constants.WINDOW_HEIGHT - 2, 'Total Cost: ') display.write_string('text', 15, constants.WINDOW_HEIGHT - 2, '$%.2f' % _total_money, fore_color=(0, 200, 0), back_color=(0, 40, 0)) display.blit_surface_viewport('background', 0, 0, constants.WINDOW_WIDTH, constants.WINDOW_HEIGHT) display.blit_surface('text')
def _draw_message(): _minutes = int(round(TIME)) _time = '%s:%02d' % (_minutes / 60, _minutes - ((_minutes / 60) * 60)) _message = 'Day 1 - %s' % _time display.write_string('map_squads', (constants.STRAT_MAP_WIDTH / 2) - len(_message) / 2 , constants.STRAT_MAP_HEIGHT / 2, _message)