Browse Source

Convert all modifier lists to ui_list

The world lists (pages and games) require special operators, so it seems
best to just leave them as they are for now.
pull/104/head
Adam Johnson 6 years ago
parent
commit
25e8a82875
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 41
      korman/operators/op_modifier.py
  2. 33
      korman/ui/modifiers/anim.py
  3. 22
      korman/ui/modifiers/logic.py
  4. 15
      korman/ui/modifiers/render.py
  5. 15
      korman/ui/modifiers/sound.py
  6. 18
      korman/ui/modifiers/water.py
  7. 9
      korman/ui/ui_list.py

41
korman/operators/op_modifier.py

@ -233,44 +233,3 @@ class ModifierLogicWizOperator(ModifierOperator, bpy.types.Operator):
end = time.process_time()
print("\nLogicWiz finished in {:.2f} seconds".format(end-start))
return {"FINISHED"}
class ModifierCollectionAddOperator(ModifierOperator, bpy.types.Operator):
bl_idname = "object.plasma_modifier_collection_add"
bl_label = "Add Item"
bl_description = "Adds an item to the collection"
modifier = StringProperty(name="Modifier", description="Attribute name of the Plasma Modifier")
collection = StringProperty(name="Collection", description="Attribute name of the collection property")
name_prefix = StringProperty(name="Name Prefix", description="Prefix for autogenerated item names", default="Item")
name_prop = StringProperty(name="Name Property", description="Attribute name of the item name property")
def execute(self, context):
obj = context.active_object
mod = getattr(obj.plasma_modifiers, self.modifier)
collection = getattr(mod, self.collection)
idx = len(collection)
collection.add()
if self.name_prop:
setattr(collection[idx], self.name_prop, "{} {}".format(self.name_prefix, idx+1))
return {"FINISHED"}
class ModifierCollectionRemoveOperator(ModifierOperator, bpy.types.Operator):
bl_idname = "object.plasma_modifier_collection_remove"
bl_label = "Remove Item"
bl_description = "Removes an item from the collection"
modifier = StringProperty(name="Modifier", description="Attribute name of the Plasma Modifier")
collection = StringProperty(name="Collection", description="Attribute name of the collection property")
index = IntProperty(name="Index", description="Item index to remove")
def execute(self, context):
obj = context.active_object
mod = getattr(obj.plasma_modifiers, self.modifier)
collection = getattr(mod, self.collection)
if len(collection) > self.index:
collection.remove(self.index)
return {"FINISHED"}
else:
return {"CANCELLED"}

33
korman/ui/modifiers/anim.py

@ -15,6 +15,8 @@
import bpy
from .. import ui_list
def _check_for_anim(layout, modifier):
try:
action = modifier.blender_action
@ -67,18 +69,8 @@ def animation_group(modifier, layout, context):
if action is None:
return
row = layout.row()
row.template_list("GroupListUI", "children", modifier, "children", modifier, "active_child_index",
rows=3, maxrows=4)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "children"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "children"
op.index = modifier.active_child_index
ui_list.draw_modifier_list(layout, "GroupListUI", modifier, "children",
"active_child_index", rows=3, maxrows=4)
if modifier.children:
layout.prop(modifier.children[modifier.active_child_index], "child_anim", icon="ACTION")
@ -96,20 +88,9 @@ def animation_loop(modifier, layout, context):
elif action is None:
return
row = layout.row()
row.template_list("LoopListUI", "loops", modifier, "loops", modifier, "active_loop_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "loops"
op.name_prefix = "Loop"
op.name_prop = "loop_name"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "loops"
op.index = modifier.active_loop_index
ui_list.draw_modifier_list(layout, "LoopListUI", modifier, "loops",
"active_loop_index", name_prefix="Loop",
name_prop="loop_name", rows=2, maxrows=3)
# Modify the loop points
if modifier.loops:
loop = modifier.loops[modifier.active_loop_index]

22
korman/ui/modifiers/logic.py

@ -15,27 +15,19 @@
import bpy
from .. import ui_list
class LogicListUI(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_property, index=0, flt_flag=0):
layout.prop(item, "name", emboss=False, text="", icon="NODETREE")
def advanced_logic(modifier, layout, context):
row = layout.row()
row.template_list("LogicListUI", "logic_groups", modifier, "logic_groups", modifier, "active_group_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "logic_groups"
op.name_prefix = "Logic"
op.name_prop = "name"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "logic_groups"
op.index = modifier.active_group_index
# Modify the loop points
ui_list.draw_modifier_list(layout, "LogicListUI", modifier, "logic_groups",
"active_group_index", name_prefix="Logic",
name_prop="name", rows=2, maxrows=3)
# Modify the logic groups
if modifier.logic_groups:
logic = modifier.logic_groups[modifier.active_group_index]
layout.row().prop_menu_enum(logic, "version")

15
korman/ui/modifiers/render.py

@ -15,6 +15,8 @@
import bpy
from .. import ui_list
def fademod(modifier, layout, context):
layout.prop(modifier, "fader_type")
@ -147,17 +149,8 @@ class VisRegionListUI(bpy.types.UIList):
def visibility(modifier, layout, context):
row = layout.row()
row.template_list("VisRegionListUI", "regions", modifier, "regions", modifier, "active_region_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "regions"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "regions"
op.index = modifier.active_region_index
ui_list.draw_modifier_list(layout, "VisRegionListUI", modifier, "regions",
"active_region_index", rows=2, maxrows=3)
if modifier.regions:
layout.prop(modifier.regions[modifier.active_region_index], "control_region")

15
korman/ui/modifiers/sound.py

@ -15,6 +15,8 @@
import bpy
from .. import ui_list
def _draw_fade_ui(modifier, layout, label):
layout.label(label)
layout.prop(modifier, "fade_type", text="")
@ -30,17 +32,8 @@ class SoundListUI(bpy.types.UIList):
def soundemit(modifier, layout, context):
row = layout.row()
row.template_list("SoundListUI", "sounds", modifier, "sounds", modifier, "active_sound_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "sounds"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "sounds"
op.index = modifier.active_sound_index
ui_list.draw_modifier_list(layout, "SoundListUI", modifier, "sounds",
"active_sound_index", rows=2, maxrows=3)
try:
sound = modifier.sounds[modifier.active_sound_index]

18
korman/ui/modifiers/water.py

@ -15,6 +15,8 @@
import bpy
from .. import ui_list
def swimregion(modifier, layout, context):
split = layout.split()
col = split.column()
@ -111,19 +113,9 @@ class ShoreListUI(bpy.types.UIList):
def water_shore(modifier, layout, context):
row = layout.row()
row.template_list("ShoreListUI", "shores", modifier, "shores", modifier, "active_shore_index",
rows=2, maxrows=3)
col = row.column(align=True)
op = col.operator("object.plasma_modifier_collection_add", icon="ZOOMIN", text="")
op.modifier = modifier.pl_id
op.collection = "shores"
op.name_prefix = "Shore"
op.name_prop = "display_name"
op = col.operator("object.plasma_modifier_collection_remove", icon="ZOOMOUT", text="")
op.modifier = modifier.pl_id
op.collection = "shores"
op.index = modifier.active_shore_index
ui_list.draw_modifier_list(layout, "ShoreListUI", modifier, "shores",
"active_shore_index", name_prefix="Shore",
name_prop="display_name", rows=2, maxrows=3)
# Display the active shore
if modifier.shores:

9
korman/ui/ui_list.py

@ -26,9 +26,14 @@ def draw_list(layout, listtype, context_attr, prop_base, collection_name, index_
- prop_base: property group owning the collection
- collection_name: name of the collection property
- index_name: name of the active element index property
- name_prefix: (optional) prefix to apply to display name of new elements
- name_prop: (optional) property for each element's display name
*** any other arguments are passed as keyword arguments to the template_list call
"""
prop_path = prop_base.path_from_id()
name_prefix = kwargs.pop("name_prefix", "")
name_prop = kwargs.pop("name_prop", "")
row = layout.row()
row.template_list(listtype, collection_name, prop_base, collection_name,
prop_base, index_name, **kwargs)
@ -38,9 +43,13 @@ def draw_list(layout, listtype, context_attr, prop_base, collection_name, index_
op.group_path = prop_path
op.collection_prop = collection_name
op.index_prop = index_name
op.name_prefix = name_prefix
op.name_prop = name_prop
op = col.operator("ui.plasma_collection_remove", icon="ZOOMOUT", text="")
op.context = context_attr
op.group_path = prop_path
op.collection_prop = collection_name
op.index_prop = index_name
def draw_modifier_list(layout, listtype, prop_base, collection_name, index_name, **kwargs):
draw_list(layout, listtype, "object", prop_base, collection_name, index_name, **kwargs)

Loading…
Cancel
Save