def __init__(self, character_id: int, width: int): """ 初始化绘制对象 """ self.character_id = character_id """ 要绘制的角色id """ self.width = width """ 当前最大可绘制宽度 """ character_data = cache.character_data[self.character_id] dormitory = character_data.dormitory dormitory_text = "" if dormitory == "": dormitory_text = _("暂无") else: dormitory_path = map_handle.get_map_system_path_for_str(dormitory) dormitory_text = attr_text.get_scene_path_text(dormitory_path) self.dormitory_text = _("宿舍位置:") + dormitory_text """ 宿舍位置文本 """ classroom = character_data.classroom now_classroom_text = _("教室位置:") if classroom != "": classroom_path = map_handle.get_map_system_path_for_str(classroom) classroom_text = attr_text.get_scene_path_text(classroom_path) now_classroom_text += classroom_text else: now_classroom_text += _("暂无") self.classroom_text = now_classroom_text """ 教室位置文本 """ officeroom = character_data.officeroom now_officeroom_text = _("办公室位置:") if len(officeroom): officeroom_text = attr_text.get_scene_path_text(officeroom) now_officeroom_text += officeroom_text else: now_officeroom_text += _("暂无") self.officeroom_text = now_officeroom_text """ 办公室位置文本 """
def init_character_position(): """ 初始化角色位置 """ for character_id in cache.character_data: character_position = cache.character_data[character_id].position character_dormitory = cache.character_data[character_id].dormitory character_dormitory = map_handle.get_map_system_path_for_str(character_dormitory) map_handle.character_move_scene(character_position, character_dormitory, character_id)
def get_character_officeroom_path_text(character_id: int) -> str: """ 获取角色教室路径描述信息 Keyword arguments: character_id -- 角色id Return arguments: str -- 教室路径描述文本 """ officeroom = cache_contorl.character_data[character_id].officeroom map_path_text = text_loading.get_text_data( constant.FilePath.STAGE_WORD_PATH, "149") if officeroom != "": officeroom_path = map_handle.get_map_system_path_for_str(officeroom) map_list = map_handle.get_map_hierarchy_list_for_scene_path( officeroom_path, []) map_list.reverse() for now_map in map_list: now_map_map_system_str = map_handle.get_map_system_path_str_for_list( now_map) map_name = cache_contorl.map_data[now_map_map_system_str][ "MapName"] map_path_text += map_name + "-" map_path_text += cache_contorl.scene_data[officeroom]["SceneName"] else: map_path_text += text_loading.get_text_data( constant.FilePath.STAGE_WORD_PATH, "150") return map_path_text
def character_move_to_rand_restaurant(character_id: int): """ 设置角色状态为向随机就餐区移动 Keyword arguments: character_id -- 角色id """ character_data: game_type.Character = cache.character_data[character_id] to_restaurant = map_handle.get_map_system_path_for_str( random.choice(constant.place_data["Restaurant"])) _, _, move_path, move_time = character_move.character_move( character_id, map_handle.get_map_system_path_for_str(character_data.classroom), ) character_data.behavior.behavior_id = constant.Behavior.MOVE character_data.behavior.move_target = move_path character_data.behavior.duration = move_time character_data.state = constant.CharacterStatus.STATUS_MOVE
def __init__(self, now_map: List[str], width: int): self.width: int = width """ 绘制的最大宽度 """ self.now_map: List[str] = now_map """ 当前查看的地图坐标 """ self.return_list: List[str] = [] """ 当前面板的按钮返回 """ self.end_index: int = 0 """ 结束按钮id """ character_data: game_type.Character = cache.character_data[0] class_room_path = map_handle.get_map_system_path_for_str( character_data.classroom) office_room_path = character_data.officeroom square_path = ["2"] swim_path = ["14", "0"] big_restaurant_path = ["10", "0", "0"] small_restaurant_path = ["16", "0", "0"] multi_media_class_room_a_path = ["1", "3", "1"] multi_media_class_room_b_path = ["1", "3", "2"] music_class_room_path = ["1", "4", "1"] shop_path = ["11"] dormitory_path = map_handle.get_map_system_path_for_str( character_data.dormitory) path_list = [ dormitory_path, class_room_path, office_room_path, square_path, swim_path, big_restaurant_path, small_restaurant_path, multi_media_class_room_a_path, multi_media_class_room_b_path, music_class_room_path, shop_path, ] path_list = [i for i in path_list if len(i)] self.handle_panel = panel.PageHandlePanel(path_list, ScenePathNameMoveDraw, 20, 3, self.width, 1) self.end_index = self.handle_panel.end_index
def get_path_list(self) -> list: """ 获取公共场景路径列表 Return arguments: list -- 路径列表 """ character_data: game_type.Character = cache.character_data[0] if character_data.classroom == "": class_room_path = [] else: class_room_path = map_handle.get_map_system_path_for_str( character_data.classroom) office_room_path = character_data.officeroom square_path = ["2"] swim_path = ["14", "0"] big_restaurant_path = ["10", "0", "0"] small_restaurant_path = ["16", "0", "0"] multi_media_class_room_a_path = ["1", "3", "1"] multi_media_class_room_b_path = ["1", "3", "2"] music_class_room_path = ["1", "4", "1"] shop_path = ["11"] dormitory_path = map_handle.get_map_system_path_for_str( character_data.dormitory) path_list = [ dormitory_path, class_room_path, office_room_path, square_path, swim_path, big_restaurant_path, small_restaurant_path, multi_media_class_room_a_path, multi_media_class_room_b_path, music_class_room_path, shop_path, ] path_list = [i for i in path_list if len(i)] return path_list
def character_move_to_classroom(character_id: int): """ 移动至所属教室 Keyword arguments: character_id -- 角色id """ character_data: game_type.Character = cache.character_data[character_id] _, _, move_path, move_time = character_move.character_move( character_id, map_handle.get_map_system_path_for_str(character_data.classroom), ) character_data.behavior.behavior_id = constant.Behavior.MOVE character_data.behavior.move_target = move_path character_data.behavior.duration = move_time character_data.state = constant.CharacterStatus.STATUS_MOVE
def character_move_to_rand_cafeteria(character_id: int): """ 移动至随机取餐区 Keyword arguments: character_id -- 角色id """ character_data: game_type.Character = cache.character_data[character_id] to_cafeteria = map_handle.get_map_system_path_for_str( random.choice(constant.place_data["Cafeteria"])) _, _, move_path, move_time = character_move.character_move( character_id, to_cafeteria) character_data.behavior.behavior_id = constant.Behavior.MOVE character_data.behavior.move_target = move_path character_data.behavior.duration = move_time character_data.state = constant.CharacterStatus.STATUS_MOVE
def draw(self): """ 绘制面板 """ self.return_list = [] map_path_str = map_handle.get_map_system_path_str_for_list( self.now_map) map_data: game_type.Map = cache.map_data[map_path_str] path_edge = map_data.path_edge scene_id_list = list(path_edge.keys()) if len(scene_id_list): character_data: game_type.Character = cache.character_data[0] character_scene_id = map_handle.get_map_scene_id_for_scene_path( self.now_map, character_data.position) scene_path = path_edge[character_scene_id].copy() if character_scene_id in scene_path: del scene_path[character_scene_id] scene_path_list = list(scene_path.keys()) draw_list = [] for scene_id in scene_id_list: load_scene_data = map_handle.get_scene_data_for_map( map_path_str, scene_id) now_scene_path = map_handle.get_map_system_path_for_str( load_scene_data.scene_path) now_id_text = f"{scene_id}:{load_scene_data.scene_name}" now_draw = draw.LeftButton(now_id_text, now_id_text, self.width, cmd_func=self.move_now, args=(now_scene_path, )) self.return_list.append(now_draw.return_text) draw_list.append(now_draw) draw_group = value_handle.list_of_groups(draw_list, 4) now_width_index = 0 for now_draw_list in draw_group: if len(now_draw_list) > now_width_index: now_width_index = len(now_draw_list) now_width = self.width / now_width_index for now_draw_list in draw_group: for now_draw in now_draw_list: now_draw.width = now_width now_draw.draw() line_feed.draw() self.end_index = len(scene_id_list) - 1
def character_move_to_rand_scene(character_id: int): """ 移动至随机场景 Keyword arguments: character_id -- 角色id """ character_data: game_type.Character = cache.character_data[character_id] scene_list = list(cache.scene_data.keys()) now_scene_str = map_handle.get_map_system_path_str_for_list( character_data.position) scene_list.remove(now_scene_str) target_scene = random.choice(scene_list) _, _, move_path, move_time = character_move.character_move( character_id, map_handle.get_map_system_path_for_str(target_scene), ) character_data.behavior.behavior_id = constant.Behavior.MOVE character_data.behavior.move_target = move_path character_data.behavior.duration = move_time character_data.state = constant.CharacterStatus.STATUS_MOVE
def get_character_dormitory_path_text(character_id: int) -> str: """ 获取角色宿舍路径描述信息 Keyword arguments: character_id -- 角色Id Return arguments: map_path_str -- 宿舍路径描述文本 """ dormitory = cache_contorl.character_data[character_id].dormitory dormitory_path = map_handle.get_map_system_path_for_str(dormitory) map_list = map_handle.get_map_hierarchy_list_for_scene_path( dormitory_path, []) map_path_text = text_loading.get_text_data( constant.FilePath.STAGE_WORD_PATH, "143") map_list.reverse() for now_map in map_list: now_map_map_system_str = map_handle.get_map_system_path_str_for_list( now_map) map_name = cache_contorl.map_data[now_map_map_system_str]["MapName"] map_path_text += map_name + "-" map_path_text += cache_contorl.scene_data[dormitory]["SceneName"] return map_path_text
def init_teacher_table(): """ 初始化教师上课时间数据 """ teacher_table = {} for school_id in cache.course_time_table_data: for phase in cache.course_time_table_data[school_id]: class_time_table = cache.course_time_table_data[school_id][phase] phase_room_id = 0 if school_id == 0: phase_room_id = 1 + phase elif school_id == 1: phase_room_id = 7 + phase else: phase_room_id = 10 + phase if f"Classroom_{phase_room_id}" not in cache.classroom_teacher_data: continue classroom_list = constant.place_data[f"Classroom_{phase_room_id}"] for day in class_time_table: for classroom in classroom_list: if classroom not in cache.classroom_teacher_data[ f"Classroom_{phase_room_id}"]: continue for i in class_time_table[day]: now_course = class_time_table[day][i] if (now_course not in cache.classroom_teacher_data[ f"Classroom_{phase_room_id}"][classroom]): continue for now_teacher in cache.classroom_teacher_data[ f"Classroom_{phase_room_id}"][classroom][ now_course]: if now_teacher not in teacher_table: cache.character_data[ now_teacher].officeroom = constant.place_data[ f"Office_{phase_room_id}"] teacher_table.setdefault(now_teacher, 0) if teacher_table[now_teacher] < 18: teacher_table[now_teacher] += 1 cache.teacher_class_time_table.setdefault( day, {}) cache.teacher_class_time_table[day].setdefault( school_id, {}) cache.teacher_class_time_table[day][ school_id].setdefault(phase, {}) cache.teacher_class_time_table[day][school_id][ phase].setdefault(i, {}) cache.teacher_class_time_table[day][school_id][ phase][i][now_teacher] = { classroom: now_course } cache.class_timetable_teacher_data.setdefault( school_id, {}) cache.class_timetable_teacher_data[ school_id].setdefault(phase, {}) cache.class_timetable_teacher_data[school_id][ phase].setdefault(classroom, {}) cache.class_timetable_teacher_data[school_id][ phase][classroom].setdefault(day, {}) cache.class_timetable_teacher_data[school_id][ phase][classroom][day][i] = now_teacher teacher_timetable = game_type.TeacherTimeTable( ) teacher_timetable.class_room = map_handle.get_map_system_path_for_str( classroom) teacher_timetable.class_times = i teacher_timetable.course = now_course cache.teacher_class_week_day_data.setdefault( now_teacher, set()) if day not in cache.teacher_class_week_day_data[ now_teacher]: cache.teacher_class_week_day_data[ now_teacher].add(day) now_config_id = game_config.config_school_session_data[ school_id][i] now_config = game_config.config_school_session[ now_config_id] teacher_timetable.time = now_config.start_time teacher_timetable.week_day = day teacher_timetable.end_time = now_config.end_time cache.teacher_school_timetable.setdefault( now_teacher, []) cache.teacher_school_timetable[ now_teacher].append(teacher_timetable)
def draw(self): """ 绘制对象 """ move_menu_panel_data = { 0: MapSceneNameDraw(self.now_map, self.width), 1: GlobalSceneNamePanel(self.now_map, self.width), 2: SocialSceneNamePanel(self.now_map, self.width), 3: CollectionSceneNamePanel(self.now_map, self.width), } move_menu_panel = MoveMenuPanel(self.width) while 1: line_feed.draw() if cache.now_panel_id != constant.Panel.SEE_MAP: break map_path_str = map_handle.get_map_system_path_str_for_list( self.now_map) map_data: game_type.Map = cache.map_data[map_path_str] map_name = attr_text.get_map_path_text(self.now_map) title_draw = draw.TitleLineDraw(_("移动:") + map_name, self.width) title_draw.draw() now_draw_list: game_type.MapDraw = map_data.map_draw character_data: game_type.Character = cache.character_data[0] character_scene_id = map_handle.get_map_scene_id_for_scene_path( self.now_map, character_data.position) return_list = [] index = 0 for now_draw_line in now_draw_list.draw_text: fix_width = int((self.width - now_draw_line.width) / 2) fix_text = " " * fix_width fix_draw = draw.NormalDraw() fix_draw.text = fix_text fix_draw.width = fix_width fix_draw.draw() for draw_text in now_draw_line.draw_list: if draw_text.is_button and draw_text.text != character_scene_id: scene_path = map_handle.get_scene_path_for_map_scene_id( self.now_map, draw_text.text) now_draw = draw.Button(draw_text.text, draw_text.text, cmd_func=self.move_now, args=(scene_path, )) now_draw.width = self.width now_draw.draw() return_list.append(now_draw.return_text) else: now_draw = draw.NormalDraw() now_draw.text = draw_text.text now_draw.width = self.width if draw_text.is_button and draw_text.text == character_scene_id: now_draw.style = "nowmap" now_draw.draw() line_feed.draw() path_edge = map_data.path_edge scene_path = path_edge[character_scene_id].copy() if character_scene_id in scene_path: del scene_path[character_scene_id] scene_path_list = list(scene_path.keys()) if len(scene_path_list): line = draw.LineDraw(".", self.width) line.draw() message_draw = draw.NormalDraw() message_draw.text = _("你可以从这里前往:\n") message_draw.width = self.width message_draw.draw() draw_list = [] for scene in scene_path_list: load_scene_data = map_handle.get_scene_data_for_map( map_path_str, scene) now_scene_path = map_handle.get_map_system_path_for_str( load_scene_data.scene_path) now_draw = draw.CenterButton( f"[{load_scene_data.scene_name}]", load_scene_data.scene_name, self.width / 4, cmd_func=self.move_now, args=(now_scene_path, ), ) return_list.append(now_draw.return_text) draw_list.append(now_draw) draw_group = value_handle.list_of_groups(draw_list, 4) for now_draw_list in draw_group: for now_draw in now_draw_list: now_draw.draw() line_feed.draw() scene_id_list = list(path_edge.keys()) now_index = len(scene_id_list) index = now_index move_menu_panel.update() move_menu_panel.draw() return_list.extend(move_menu_panel.return_list) if move_menu_panel.now_type in move_menu_panel_data: now_move_menu = move_menu_panel_data[move_menu_panel.now_type] now_move_menu.update(self.now_map, index) now_move_menu.draw() now_index = now_move_menu.end_index + 1 return_list.extend(now_move_menu.return_list) line = draw.LineDraw("=", self.width) line.draw() if self.now_map != []: now_id = text_handle.id_index(now_index) now_text = now_id + _("查看上级地图") up_button = draw.CenterButton(now_text, str(now_index), self.width / 3, cmd_func=self.up_map) up_button.draw() return_list.append(up_button.return_text) now_index += 1 else: now_draw = draw.NormalDraw() now_draw.text = " " * int(self.width / 3) now_draw.width = self.width / 3 now_draw.draw() back_id = text_handle.id_index(now_index) now_text = back_id + _("返回") back_button = draw.CenterButton(now_text, str(now_index), self.width / 3) back_button.draw() return_list.append(back_button.return_text) now_index += 1 character_map = map_handle.get_map_for_path( character_data.position) if character_map != self.now_map: now_id = text_handle.id_index(now_index) now_text = now_id + _("查看下级地图") down_button = draw.CenterButton(now_text, str(now_index), self.width / 3, cmd_func=self.down_map) down_button.draw() return_list.append(down_button.return_text) line_feed.draw() yrn = flow_handle.askfor_all(return_list) py_cmd.clr_cmd() if yrn == back_button.return_text: cache.now_panel_id = constant.Panel.IN_SCENE break