diff --git a/ballance_blender_plugin/UTILS_icons_manager.py b/ballance_blender_plugin/UTILS_icons_manager.py index 3d5c500..8c4681a 100644 --- a/ballance_blender_plugin/UTILS_icons_manager.py +++ b/ballance_blender_plugin/UTILS_icons_manager.py @@ -7,62 +7,91 @@ blender_info_icon = 'INFO' blender_warning_icon = 'ERROR' blender_error_icon = 'CANCEL' -# ImagePreviewCollection ccreated by Blender -floor_icons = None +# universal icon loader, all icon are stored in this preview collection +universal_icons = None + +# empty icon for placeholder +empty_icon_id = 0 + # a map. key is block name, value is loaded icon id floor_icons_map: dict = {} - -element_icons = None element_icons_map: dict = {} +groupext_icons_map: dict = {} -group_map_to_element: dict = { +group_name_conv_map: dict = { "PS_Levelstart": "PS_FourFlames", "PE_Levelende": "PE_Balloon", "PC_Checkpoints": "PC_TwoFlames", - "PR_Resetpoints": "PR_Resetpoint" + "PR_Resetpoints": "PR_Resetpoint", + + "Sound_HitID_01": "SoundID_01", + "Sound_RollID_01": "SoundID_01", + "Sound_HitID_02": "SoundID_02", + "Sound_RollID_02": "SoundID_02", + "Sound_HitID_03": "SoundID_03", + "Sound_RollID_03": "SoundID_03" } def register_icons(): - global floor_icons, floor_icons_map - global element_icons, element_icons_map + global universal_icons + global empty_icon_id + global floor_icons_map, element_icons_map, groupext_icons_map + # create preview collection and get icon folder icon_path = os.path.join(os.path.dirname(__file__), "icons") + universal_icons = bpy.utils.previews.new() - floor_icons = bpy.utils.previews.new() + # load empty + universal_icons.load("BlcBldPlg_EmptyIcon", os.path.join(icon_path, "Empty.png"), 'IMAGE') + empty_icon_id = universal_icons["BlcBldPlg_EmptyIcon"].icon_id + + # add floor icon for key, value in UTILS_constants.floor_blockDict.items(): blockIconName = "BlcBldPlg_FloorIcon_" + key - floor_icons.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE') - floor_icons_map[key] = floor_icons[blockIconName].icon_id + universal_icons.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE') + floor_icons_map[key] = universal_icons[blockIconName].icon_id - element_icons = bpy.utils.previews.new() + # add elements icon for elename in UTILS_constants.bmfile_componentList: blockIconName = "BlcBldPlg_ElementIcon_" + elename - element_icons.load(blockIconName, os.path.join(icon_path, "element", elename + '.png'), 'IMAGE') - element_icons_map[elename] = element_icons[blockIconName].icon_id + universal_icons.load(blockIconName, os.path.join(icon_path, "element", elename + '.png'), 'IMAGE') + element_icons_map[elename] = universal_icons[blockIconName].icon_id + + # add extra group icon + for grp in ("SoundID_01", "SoundID_02", "SoundID_03"): + blockIconName = "BlcBldPlg_GroupIcon_" + grp + universal_icons.load(blockIconName, os.path.join(icon_path, "group", grp + '.png'), 'IMAGE') + groupext_icons_map[grp] = universal_icons[blockIconName].icon_id def unregister_icons(): - global floor_icons, floor_icons_map - global element_icons, element_icons_map + global universal_icons + global floor_icons_map, element_icons_map, groupext_icons_map - bpy.utils.previews.remove(floor_icons) + bpy.utils.previews.remove(universal_icons) floor_icons_map.clear() - bpy.utils.previews.remove(element_icons) element_icons_map.clear() + groupext_icons_map.clear() def get_floor_icon(floor_blk_name: str): - global floor_icons_map - # default return 0 - return floor_icons_map.get(floor_blk_name, 0) + # default return empty icon + return floor_icons_map.get(floor_blk_name, empty_icon_id) def get_element_icon(element_name: str): - global element_icons_map - # default return 0 - return element_icons_map.get(element_name, 0) + # default return empty icon + return element_icons_map.get(element_name, empty_icon_id) def get_group_icon(group_name: str): # try parse string # if not found, return self - return get_element_icon(group_map_to_element.get(group_name, group_name)) + conv_name = group_name_conv_map.get(group_name, group_name) + + # get from extra group icon first + idx = groupext_icons_map.get(conv_name, empty_icon_id) + if idx != empty_icon_id: + return idx + + # if failed, get from element. if still failed, return empty icon + return get_element_icon(conv_name) # no matter how, register icon always # and no unregister call diff --git a/ballance_blender_plugin/icons/Empty.png b/ballance_blender_plugin/icons/Empty.png new file mode 100644 index 0000000..285ac30 Binary files /dev/null and b/ballance_blender_plugin/icons/Empty.png differ diff --git a/ballance_blender_plugin/icons/group/SoundID_01.png b/ballance_blender_plugin/icons/group/SoundID_01.png new file mode 100644 index 0000000..e81c7fb Binary files /dev/null and b/ballance_blender_plugin/icons/group/SoundID_01.png differ diff --git a/ballance_blender_plugin/icons/group/SoundID_02.png b/ballance_blender_plugin/icons/group/SoundID_02.png new file mode 100644 index 0000000..3079b7d Binary files /dev/null and b/ballance_blender_plugin/icons/group/SoundID_02.png differ diff --git a/ballance_blender_plugin/icons/group/SoundID_03.png b/ballance_blender_plugin/icons/group/SoundID_03.png new file mode 100644 index 0000000..bd2f4bf Binary files /dev/null and b/ballance_blender_plugin/icons/group/SoundID_03.png differ