diff --git a/korman/operators/__init__.py b/korman/operators/__init__.py index 94b352f..006053c 100644 --- a/korman/operators/__init__.py +++ b/korman/operators/__init__.py @@ -19,8 +19,8 @@ from . import op_mesh as mesh from . import op_modifier as modifier from . import op_nodes as nodes from . import op_sound as sound -from . import op_texture as texture from . import op_toolbox as toolbox +from . import op_ui as ui from . import op_world as world def register(): diff --git a/korman/operators/op_texture.py b/korman/operators/op_texture.py deleted file mode 100644 index 86d5391..0000000 --- a/korman/operators/op_texture.py +++ /dev/null @@ -1,61 +0,0 @@ -# This file is part of Korman. -# -# Korman is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Korman is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Korman. If not, see . - -import bpy -from bpy.props import * - -class TextureOperator: - @classmethod - def poll(cls, context): - return context.scene.render.engine == "PLASMA_GAME" and context.texture - - -class TextureCollectionAddOperator(TextureOperator, bpy.types.Operator): - bl_idname = "texture.plasma_collection_add" - bl_label = "Add Item" - bl_description = "Adds an item to the collection" - - group = StringProperty(name="Modifier", description="Attribute name of the PropertyGroup") - 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): - mod = getattr(context.texture, self.group) - 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 TextureCollectionRemoveOperator(TextureOperator, bpy.types.Operator): - bl_idname = "texture.plasma_collection_remove" - bl_label = "Remove Item" - bl_description = "Removes an item from the collection" - - group = StringProperty(name="Modifier", description="Attribute name of the PropertyGroup") - collection = StringProperty(name="Collection", description="Attribute name of the collection property") - index = IntProperty(name="Index", description="Item index to remove") - - def execute(self, context): - mod = getattr(context.texture, self.group) - collection = getattr(mod, self.collection) - if len(collection) > self.index: - collection.remove(self.index) - return {"FINISHED"} - else: - return {"CANCELLED"} diff --git a/korman/operators/op_ui.py b/korman/operators/op_ui.py new file mode 100644 index 0000000..0f23da4 --- /dev/null +++ b/korman/operators/op_ui.py @@ -0,0 +1,89 @@ +# This file is part of Korman. +# +# Korman is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Korman is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Korman. If not, see . + +import bpy +from bpy.props import * + +class UIOperator: + @classmethod + def poll(cls, context): + return context.scene.render.engine == "PLASMA_GAME" + + +class CollectionAddOperator(UIOperator, bpy.types.Operator): + bl_idname = "ui.plasma_collection_add" + bl_label = "Add Item" + bl_description = "Adds an item to the collection" + + context = StringProperty(name="ID Path", + description="Path to the relevant datablock from the current context", + options=set()) + group_path = StringProperty(name="Property Group Path", + description="Path to the property group from the ID", + options=set()) + collection_prop = StringProperty(name="Collection Property", + description="Name of the collection property", + options=set()) + index_prop = StringProperty(name="Index Property", + description="Name of the active element index property", + options=set()) + name_prefix = StringProperty(name="Name Prefix", + description="Prefix for autogenerated item names", + default="Item", + options=set()) + name_prop = StringProperty(name="Name Property", + description="Attribute name of the item name property", + options=set()) + + def execute(self, context): + props = getattr(context, self.context).path_resolve(self.group_path) + collection = getattr(props, self.collection_prop) + idx = len(collection) + collection.add() + if self.name_prop: + setattr(collection[idx], self.name_prop, "{} {}".format(self.name_prefix, idx+1)) + if self.index_prop: + setattr(props, self.index_prop, idx) + return {"FINISHED"} + + +class CollectionRemoveOperator(UIOperator, bpy.types.Operator): + bl_idname = "ui.plasma_collection_remove" + bl_label = "Remove Item" + bl_description = "Removes an item from the collection" + + context = StringProperty(name="ID Path", + description="Path to the relevant datablock from the current context", + options=set()) + group_path = StringProperty(name="Property Group Path", + description="Path to the property group from the ID", + options=set()) + collection_prop = StringProperty(name="Collection Property", + description="Name of the collection property", + options=set()) + index_prop = StringProperty(name="Index Property", + description="Name of the active element index property", + options=set()) + + def execute(self, context): + props = getattr(context, self.context).path_resolve(self.group_path) + collection = getattr(props, self.collection_prop) + index = getattr(props, self.index_prop) + if len(collection) > index: + collection.remove(index) + setattr(props, self.index_prop, index - 1) + return {"FINISHED"} + else: + return {"CANCELLED"} diff --git a/korman/ui/ui_texture.py b/korman/ui/ui_texture.py index 2bc3d7a..9821ca3 100644 --- a/korman/ui/ui_texture.py +++ b/korman/ui/ui_texture.py @@ -46,13 +46,16 @@ class PlasmaEnvMapPanel(TextureButtonsPanel, bpy.types.Panel): row.template_list("VisRegionListUI", "vis_regions", layer_props, "vis_regions", layer_props, "active_region_index", rows=2, maxrows=3) col = row.column(align=True) - op = col.operator("texture.plasma_collection_add", icon="ZOOMIN", text="") - op.group = "plasma_layer" - op.collection = "vis_regions" - op = col.operator("texture.plasma_collection_remove", icon="ZOOMOUT", text="") - op.group = "plasma_layer" - op.collection = "vis_regions" - op.index = layer_props.active_region_index + op = col.operator("ui.plasma_collection_add", icon="ZOOMIN", text="") + op.context = "texture" + op.group_path = "plasma_layer" + op.collection_prop = "vis_regions" + op.index_prop = "active_region_index" + op = col.operator("ui.plasma_collection_remove", icon="ZOOMOUT", text="") + op.context = "texture" + op.group_path = "plasma_layer" + op.collection_prop = "vis_regions" + op.index_prop = "active_region_index" rgns = layer_props.vis_regions if layer_props.vis_regions: layout.prop(rgns[layer_props.active_region_index], "control_region")