2023-01-27 16:28:32 +08:00
|
|
|
import bpy
|
|
|
|
import bpy.utils.previews
|
|
|
|
import os
|
|
|
|
from . import UTILS_constants
|
|
|
|
|
2023-01-29 10:32:43 +08:00
|
|
|
blender_info_icon = 'INFO'
|
|
|
|
blender_warning_icon = 'ERROR'
|
|
|
|
blender_error_icon = 'CANCEL'
|
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
# universal icon loader, all icon are stored in this preview collection
|
|
|
|
universal_icons = None
|
|
|
|
|
|
|
|
# empty icon for placeholder
|
|
|
|
empty_icon_id = 0
|
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
# a map. key is block name, value is loaded icon id
|
|
|
|
floor_icons_map: dict = {}
|
2023-01-29 21:39:24 +08:00
|
|
|
element_icons_map: dict = {}
|
2023-01-30 15:00:29 +08:00
|
|
|
groupext_icons_map: dict = {}
|
2023-01-29 21:39:24 +08:00
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
group_name_conv_map: dict = {
|
2023-01-30 11:12:15 +08:00
|
|
|
"PS_Levelstart": "PS_FourFlames",
|
|
|
|
"PE_Levelende": "PE_Balloon",
|
|
|
|
"PC_Checkpoints": "PC_TwoFlames",
|
2023-01-30 15:00:29 +08:00
|
|
|
"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"
|
2023-01-30 11:12:15 +08:00
|
|
|
}
|
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
def register_icons():
|
2023-01-30 15:00:29 +08:00
|
|
|
global universal_icons
|
|
|
|
global empty_icon_id
|
|
|
|
global floor_icons_map, element_icons_map, groupext_icons_map
|
2023-01-27 16:28:32 +08:00
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
# create preview collection and get icon folder
|
2023-01-27 16:28:32 +08:00
|
|
|
icon_path = os.path.join(os.path.dirname(__file__), "icons")
|
2023-01-30 15:00:29 +08:00
|
|
|
universal_icons = bpy.utils.previews.new()
|
2023-01-29 21:39:24 +08:00
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
# 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
|
2023-01-27 16:28:32 +08:00
|
|
|
for key, value in UTILS_constants.floor_blockDict.items():
|
2023-01-29 21:39:24 +08:00
|
|
|
blockIconName = "BlcBldPlg_FloorIcon_" + key
|
2023-01-30 15:00:29 +08:00
|
|
|
universal_icons.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE')
|
|
|
|
floor_icons_map[key] = universal_icons[blockIconName].icon_id
|
2023-01-27 16:28:32 +08:00
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
# add elements icon
|
2023-01-29 21:39:24 +08:00
|
|
|
for elename in UTILS_constants.bmfile_componentList:
|
|
|
|
blockIconName = "BlcBldPlg_ElementIcon_" + elename
|
2023-01-30 15:00:29 +08:00
|
|
|
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
|
2023-01-29 21:39:24 +08:00
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
def unregister_icons():
|
2023-01-30 15:00:29 +08:00
|
|
|
global universal_icons
|
|
|
|
global floor_icons_map, element_icons_map, groupext_icons_map
|
2023-01-27 16:28:32 +08:00
|
|
|
|
2023-01-30 15:00:29 +08:00
|
|
|
bpy.utils.previews.remove(universal_icons)
|
2023-01-27 16:28:32 +08:00
|
|
|
floor_icons_map.clear()
|
2023-01-29 21:39:24 +08:00
|
|
|
element_icons_map.clear()
|
2023-01-30 15:00:29 +08:00
|
|
|
groupext_icons_map.clear()
|
2023-01-27 16:28:32 +08:00
|
|
|
|
|
|
|
def get_floor_icon(floor_blk_name: str):
|
2023-01-30 15:00:29 +08:00
|
|
|
# default return empty icon
|
|
|
|
return floor_icons_map.get(floor_blk_name, empty_icon_id)
|
2023-01-27 16:28:32 +08:00
|
|
|
|
2023-01-29 21:39:24 +08:00
|
|
|
def get_element_icon(element_name: str):
|
2023-01-30 15:00:29 +08:00
|
|
|
# default return empty icon
|
|
|
|
return element_icons_map.get(element_name, empty_icon_id)
|
2023-01-30 11:12:15 +08:00
|
|
|
|
|
|
|
def get_group_icon(group_name: str):
|
|
|
|
# try parse string
|
|
|
|
# if not found, return self
|
2023-01-30 15:00:29 +08:00
|
|
|
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)
|
2023-01-30 11:12:15 +08:00
|
|
|
|
|
|
|
# no matter how, register icon always
|
|
|
|
# and no unregister call
|
|
|
|
register_icons()
|