[feat] add full element icons

- add more element icons. now element icons is not problem.
- change icon load strategy. now icon is loaded outside plugin. this operations might slow down blender but now I can apply my custom map to some operators to get better using experience.
- use new element icons to decorate some group name to let user know what this group stands for.
This commit is contained in:
yyc12345 2023-01-30 11:12:15 +08:00
parent 8d7a982e50
commit 807e006245
21 changed files with 40 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import bpy, mathutils
from . import UTILS_constants, UTILS_functions
from . import UTILS_constants, UTILS_functions, UTILS_icons_manager
# ================================================= actual add
@ -12,7 +12,12 @@ class BALLANCE_OT_add_components(bpy.types.Operator):
elements_type: bpy.props.EnumProperty(
name="Type",
description="This element type",
items=tuple(map(lambda x: (x, x, ""), UTILS_constants.bmfile_componentList)),
#items=tuple(map(lambda x: (x, x, ""), UTILS_constants.bmfile_componentList)),
items=tuple(
# token, display name, descriptions, icon, index
(blk, blk, "", UTILS_icons_manager.get_element_icon(blk), idx)
for idx, blk in enumerate(UTILS_constants.bmfile_componentList)
),
)
attentionElements = ("PC_TwoFlames", "PR_Resetpoint")

View File

@ -15,16 +15,16 @@ class BALLANCE_OT_add_floors(bpy.types.Operator):
floor_type: bpy.props.EnumProperty(
name="Type",
description="Floor type",
items=tuple(
# token, display name, descriptions
(blk, blk, "")
for blk in UTILS_constants.floor_blockDict.keys()
),
#items=tuple(
# # token, display name, descriptions, icon, index
# (blk, blk, "", UTILS_icons_manager.get_floor_icon(blk), idx)
# for idx, blk in enumerate(UTILS_constants.floor_blockDict.keys())
# # token, display name, descriptions
# (blk, blk, "")
# for blk in UTILS_constants.floor_blockDict.keys()
#),
items=tuple(
# token, display name, descriptions, icon, index
(blk, blk, "", UTILS_icons_manager.get_floor_icon(blk), idx)
for idx, blk in enumerate(UTILS_constants.floor_blockDict.keys())
),
)

View File

@ -15,6 +15,13 @@ floor_icons_map: dict = {}
element_icons = None
element_icons_map: dict = {}
group_map_to_element: dict = {
"PS_Levelstart": "PS_FourFlames",
"PE_Levelende": "PE_Balloon",
"PC_Checkpoints": "PC_TwoFlames",
"PR_Resetpoints": "PR_Resetpoint"
}
def register_icons():
global floor_icons, floor_icons_map
global element_icons, element_icons_map
@ -51,3 +58,12 @@ def get_element_icon(element_name: str):
global element_icons_map
# default return 0
return element_icons_map.get(element_name, 0)
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))
# no matter how, register icon always
# and no unregister call
register_icons()

View File

@ -1,5 +1,5 @@
import bpy
from . import UTILS_constants, UTILS_functions
from . import UTILS_constants, UTILS_functions, UTILS_icons_manager
class BALLANCE_PG_virtools_material(bpy.types.PropertyGroup):
enable_virtools_material: bpy.props.BoolProperty(
@ -92,7 +92,12 @@ class common_group_name_props(bpy.types.Operator):
group_name: bpy.props.EnumProperty(
name="Group Name",
description="Pick vanilla Ballance group name.",
items=tuple((x, x, "") for x in UTILS_constants.propsVtGroups_availableGroups),
#items=tuple((x, x, "") for x in UTILS_constants.propsVtGroups_availableGroups),
items=tuple(
# token, display name, descriptions, icon, index
(grp, grp, "", UTILS_icons_manager.get_group_icon(grp), idx)
for idx, grp in enumerate(UTILS_constants.propsVtGroups_availableGroups)
),
)
custom_group_name: bpy.props.StringProperty(

View File

@ -223,7 +223,7 @@ def menu_func_ballance_grouping(self, context):
def register():
# we need init all icon first
UTILS_icons_manager.register_icons()
#UTILS_icons_manager.register_icons()
for cls in classes:
bpy.utils.register_class(cls)
@ -264,7 +264,7 @@ def unregister():
bpy.utils.unregister_class(cls)
# we need uninstall all icon after all classes unregister
UTILS_icons_manager.unregister_icons()
#UTILS_icons_manager.unregister_icons()
if __name__=="__main__":
register()

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 904 B

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB