Browse Source

Add mass assign/select for page objects.

Closes #168.
pull/172/head
Adam Johnson 5 years ago
parent
commit
cc60a6bd26
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 71
      korman/operators/op_toolbox.py
  2. 4
      korman/ui/ui_toolbox.py

71
korman/operators/op_toolbox.py

@ -15,6 +15,7 @@
import bpy import bpy
from bpy.props import * from bpy.props import *
import pickle
class ToolboxOperator: class ToolboxOperator:
@classmethod @classmethod
@ -22,6 +23,39 @@ class ToolboxOperator:
return context.scene.render.engine == "PLASMA_GAME" return context.scene.render.engine == "PLASMA_GAME"
class PageSearchOperator(ToolboxOperator):
_pages_ref_hack = []
@property
def desired_page(self):
result = pickle.loads(self.page.encode())
PageSearchOperator._pages_ref_hack.clear()
return result
def _get_pages(self, context):
# WTF? Pickle, you ask??? Apparently Blender changes the output if we return an empty string,
# making it impossible to select the default page... Ugh.
page_defns = context.scene.world.plasma_age.pages
pages = [(pickle.dumps(i.name, 0).decode(), i.name, "") for i in page_defns]
# Ensure an entry exists for the default page
manual_default_page = next((i.name for i in page_defns if i.seq_suffix == 0), None)
if not manual_default_page:
pages.append((pickle.dumps("", 0).decode(), "Default", "Default Page"))
# Have to hold a reference to this numb-skullery so Blender won't crash.
PageSearchOperator._pages_ref_hack = pages
return pages
def invoke(self, context, event):
context.window_manager.invoke_search_popup(self)
return {"RUNNING_MODAL"}
@classmethod
def poll(cls, context):
return super().poll(context) and context.scene.world is not None
class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator): class PlasmaConvertLayerOpacitiesOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "texture.plasma_convert_layer_opacities" bl_idname = "texture.plasma_convert_layer_opacities"
bl_label = "Convert Layer Opacities" bl_label = "Convert Layer Opacities"
@ -89,6 +123,42 @@ class PlasmaEnableTexturesOperator(ToolboxOperator, bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class PlasmaMovePageObjectsOperator(PageSearchOperator, bpy.types.Operator):
bl_idname = "object.plasma_move_selection_to_page"
bl_label = "Move Selection to Page"
bl_description = "Moves all selected objects to a new page"
bl_property = "page"
page = EnumProperty(name="Page",
description= "Page whose objects should be selected",
items=PageSearchOperator._get_pages,
options=set())
def execute(self, context):
desired_page = self.desired_page
for i in context.selected_objects:
i.plasma_object.page = desired_page
return {"FINISHED"}
class PlasmaSelectPageObjectsOperator(PageSearchOperator, bpy.types.Operator):
bl_idname = "object.plasma_select_page_objects"
bl_label = "Select Objects in Page"
bl_description = "Selects all objects in a specific page"
bl_property = "page"
page = EnumProperty(name="Page",
description= "Page whose objects should be selected",
items=PageSearchOperator._get_pages,
options=set())
def execute(self, context):
desired_page = self.desired_page
for i in context.scene.objects:
i.select = i.plasma_object.page == desired_page
return {"FINISHED"}
class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator): class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "object.plasma_toggle_all_objects" bl_idname = "object.plasma_toggle_all_objects"
bl_label = "Toggle All Plasma Objects" bl_label = "Toggle All Plasma Objects"
@ -120,7 +190,6 @@ class PlasmaToggleEnvironmentMapsOperator(ToolboxOperator, bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class PlasmaTogglePlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator): class PlasmaTogglePlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
bl_idname = "object.plasma_toggle_selected_objects" bl_idname = "object.plasma_toggle_selected_objects"
bl_label = "Toggle Plasma Objects" bl_label = "Toggle Plasma Objects"

4
korman/ui/ui_toolbox.py

@ -41,6 +41,10 @@ class PlasmaToolboxPanel(ToolboxPanel, bpy.types.Panel):
disable_all = col.operator("object.plasma_toggle_all_objects", icon="OBJECT_DATA", text="Disable All") disable_all = col.operator("object.plasma_toggle_all_objects", icon="OBJECT_DATA", text="Disable All")
disable_all.enable = False disable_all.enable = False
col.label("Plasma Pages:")
col.operator("object.plasma_move_selection_to_page", icon="BOOKMARKS", text="Move to Page")
col.operator("object.plasma_select_page_objects", icon="RESTRICT_SELECT_OFF", text="Select Objects")
col.label("Textures:") col.label("Textures:")
col.operator("texture.plasma_enable_all_textures", icon="TEXTURE", text="Enable All") col.operator("texture.plasma_enable_all_textures", icon="TEXTURE", text="Enable All")
col.operator("texture.plasma_toggle_environment_maps", icon="IMAGE_RGB", text="Enable All EnvMaps").enable = True col.operator("texture.plasma_toggle_environment_maps", icon="IMAGE_RGB", text="Enable All EnvMaps").enable = True

Loading…
Cancel
Save