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-27 16:28:32 +08:00
|
|
|
# ImagePreviewCollection ccreated by Blender
|
|
|
|
floor_icons = None
|
|
|
|
# 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 = None
|
|
|
|
element_icons_map: dict = {}
|
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
def register_icons():
|
|
|
|
global floor_icons, floor_icons_map
|
2023-01-29 21:39:24 +08:00
|
|
|
global element_icons, element_icons_map
|
2023-01-27 16:28:32 +08:00
|
|
|
|
|
|
|
icon_path = os.path.join(os.path.dirname(__file__), "icons")
|
2023-01-29 21:39:24 +08:00
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
floor_icons = bpy.utils.previews.new()
|
|
|
|
for key, value in UTILS_constants.floor_blockDict.items():
|
2023-01-29 21:39:24 +08:00
|
|
|
blockIconName = "BlcBldPlg_FloorIcon_" + key
|
2023-01-27 16:28:32 +08:00
|
|
|
floor_icons.load(blockIconName, os.path.join(icon_path, "floor", value["BindingDisplayTexture"]), 'IMAGE')
|
|
|
|
floor_icons_map[key] = floor_icons[blockIconName].icon_id
|
|
|
|
|
2023-01-29 21:39:24 +08:00
|
|
|
element_icons = bpy.utils.previews.new()
|
|
|
|
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
|
|
|
|
|
2023-01-27 16:28:32 +08:00
|
|
|
def unregister_icons():
|
|
|
|
global floor_icons, floor_icons_map
|
2023-01-29 21:39:24 +08:00
|
|
|
global element_icons, element_icons_map
|
2023-01-27 16:28:32 +08:00
|
|
|
|
|
|
|
bpy.utils.previews.remove(floor_icons)
|
|
|
|
floor_icons_map.clear()
|
2023-01-29 21:39:24 +08:00
|
|
|
bpy.utils.previews.remove(element_icons)
|
|
|
|
element_icons_map.clear()
|
2023-01-27 16:28:32 +08:00
|
|
|
|
|
|
|
def get_floor_icon(floor_blk_name: str):
|
|
|
|
global floor_icons_map
|
2023-01-29 21:39:24 +08:00
|
|
|
# default return 0
|
|
|
|
return floor_icons_map.get(floor_blk_name, 0)
|
2023-01-27 16:28:32 +08:00
|
|
|
|
2023-01-29 21:39:24 +08:00
|
|
|
def get_element_icon(element_name: str):
|
|
|
|
global element_icons_map
|
|
|
|
# default return 0
|
|
|
|
return element_icons_map.get(element_name, 0)
|