Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Fake User" setting for traits + reorder trait UI #1646

Merged
merged 2 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/armory/logicnode/TraitNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TraitNode extends LogicNode {

var cname = Type.resolveClass(Main.projectPackage + "." + property0);
if (cname == null) cname = Type.resolveClass(Main.projectPackage + ".node." + property0);
if (cname == null) throw 'No trait with the name "$property0" found, make sure that the trait is exported!';
value = Type.createInstance(cname, []);
return value;
}
Expand Down
6 changes: 5 additions & 1 deletion blender/arm/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,8 +2467,12 @@ def add_constraints(self, bobject, o, bone=False):
def export_traits(self, bobject, o):
if hasattr(bobject, 'arm_traitlist'):
for t in bobject.arm_traitlist:
if t.enabled_prop == False:
# Don't export disabled traits but still export those
# with fake user enabled so that nodes like `TraitNode`
# still work
if not t.enabled_prop and not t.fake_user:
continue

x = {}
if t.type_prop == 'Logic Nodes' and t.node_tree_prop != None and t.node_tree_prop.name != '':
x['type'] = 'Script'
Expand Down
66 changes: 37 additions & 29 deletions blender/arm/props_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ArmTraitListItem(bpy.types.PropertyGroup):
name: StringProperty(name="Name", description="A name for this item", default="")
enabled_prop: BoolProperty(name="", description="A name for this item", default=True, update=trigger_recompile)
is_object: BoolProperty(name="", default=True)
fake_user: BoolProperty(name="Fake User", description="Export this trait even if it is deactivated", default=False)
type_prop: EnumProperty(
items = [('Haxe Script', 'Haxe', 'Haxe Script'),
('WebAssembly', 'Wasm', 'WebAssembly'),
Expand Down Expand Up @@ -88,12 +89,16 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
# Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.prop(item, "enabled_prop")
layout.label(text=item.name, icon=custom_icon, icon_value=custom_icon_value)
# Display " " for props without a name to right-align the
# fake_user button
layout.label(text=item.name if item.name != "" else " ", icon=custom_icon, icon_value=custom_icon_value)

elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon=custom_icon, icon_value=custom_icon_value)

layout.prop(item, "fake_user", text="", icon="FAKE_USER_ON" if item.fake_user else "FAKE_USER_OFF")

class ArmTraitListNewItem(bpy.types.Operator):
# Add a new item to the list
bl_idname = "arm_traitlist.new_item"
Expand Down Expand Up @@ -562,33 +567,8 @@ def draw_traits(layout, obj, is_object):

if obj.arm_traitlist_index >= 0 and len(obj.arm_traitlist) > 0:
item = obj.arm_traitlist[obj.arm_traitlist_index]
# Default props
if item.type_prop == 'Haxe Script' or item.type_prop == 'Bundled Script':
item.name = item.class_name_prop
row = layout.row()
if item.type_prop == 'Haxe Script':
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_scripts_list", text="Class")
else:
# Bundled scripts not yet fetched
if not bpy.data.worlds['Arm'].arm_bundled_scripts_list:
arm.utils.fetch_bundled_script_names()
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_bundled_scripts_list", text="Class")

# Props
if item.arm_traitpropslist:
layout.label(text="Trait Properties:")
if item.arm_traitpropswarnings:
box = layout.box()
box.label(text=f"Warnings ({len(item.arm_traitpropswarnings)}):", icon="ERROR")

for warning in item.arm_traitpropswarnings:
box.label(text=warning.warning)

propsrow = layout.row()
propsrows = max(len(item.arm_traitpropslist), 6)
row = layout.row()
row.template_list("ARM_UL_PropList", "The_List", item, "arm_traitpropslist", item, "arm_traitpropslist_index", rows=propsrows)

if item.type_prop == 'Haxe Script' or item.type_prop == 'Bundled Script':
if item.type_prop == 'Haxe Script':
row = layout.row(align=True)
row.alignment = 'EXPAND'
Expand All @@ -615,6 +595,17 @@ def draw_traits(layout, obj, is_object):
op.is_object = is_object
op = row.operator("arm.refresh_scripts")

# Default props
item.name = item.class_name_prop
row = layout.row()
if item.type_prop == 'Haxe Script':
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_scripts_list", text="Class")
else:
# Bundled scripts not yet fetched
if not bpy.data.worlds['Arm'].arm_bundled_scripts_list:
arm.utils.fetch_bundled_script_names()
row.prop_search(item, "class_name_prop", bpy.data.worlds['Arm'], "arm_bundled_scripts_list", text="Class")

elif item.type_prop == 'WebAssembly':
item.name = item.webassembly_prop
row = layout.row()
Expand All @@ -633,8 +624,6 @@ def draw_traits(layout, obj, is_object):

elif item.type_prop == 'UI Canvas':
item.name = item.canvas_name_prop
row = layout.row()
row.prop_search(item, "canvas_name_prop", bpy.data.worlds['Arm'], "arm_canvas_list", text="Canvas")

row = layout.row(align=True)
row.alignment = 'EXPAND'
Expand All @@ -648,10 +637,29 @@ def draw_traits(layout, obj, is_object):
op.is_object = is_object
op = row.operator("arm.refresh_canvas_list")

row = layout.row()
row.prop_search(item, "canvas_name_prop", bpy.data.worlds['Arm'], "arm_canvas_list", text="Canvas")

elif item.type_prop == 'Logic Nodes':
row = layout.row()
row.prop_search(item, "node_tree_prop", bpy.data, "node_groups", text="Tree")

if item.type_prop == 'Haxe Script' or item.type_prop == 'Bundled Script':
# Props
if item.arm_traitpropslist:
layout.label(text="Trait Properties:")
if item.arm_traitpropswarnings:
box = layout.box()
box.label(text=f"Warnings ({len(item.arm_traitpropswarnings)}):", icon="ERROR")

for warning in item.arm_traitpropswarnings:
box.label(text=warning.warning)

propsrow = layout.row()
propsrows = max(len(item.arm_traitpropslist), 6)
row = layout.row()
row.template_list("ARM_UL_PropList", "The_List", item, "arm_traitpropslist", item, "arm_traitpropslist_index", rows=propsrows)

def register():
global icons_dict
bpy.utils.register_class(ArmTraitListItem)
Expand Down