From 709ab057131e3b0b208d78607f1e8da3d3078e8f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 9 Sep 2012 13:22:52 +0900 Subject: [PATCH] Add preliminary support for entity properties. Only classname and flags are supported right now, and only classname gets set when the entity is added (via the add menu). --- tools/io_qfmap/__init__.py | 1 + tools/io_qfmap/entity.py | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tools/io_qfmap/__init__.py b/tools/io_qfmap/__init__.py index 2e2fbf6db..59f694de5 100644 --- a/tools/io_qfmap/__init__.py +++ b/tools/io_qfmap/__init__.py @@ -238,6 +238,7 @@ def register(): bpy.types.INFO_MT_add.append(menu_func_add) bpy.app.handlers.load_post.append(scene_load_handler) + entity.register() def unregister(): diff --git a/tools/io_qfmap/entity.py b/tools/io_qfmap/entity.py index 1c0f15588..c1e5d7296 100644 --- a/tools/io_qfmap/entity.py +++ b/tools/io_qfmap/entity.py @@ -20,6 +20,45 @@ # import bpy +from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty +from bpy.props import BoolVectorProperty, PointerProperty + +def qfentity_items(self, context): + qfmap = context.scene.qfmap + entclasses = qfmap.entity_classes.entity_classes + eclist = list(entclasses.keys()) + eclist.sort() + return tuple(map(lambda ec: (ec, ec, entclasses[ec].comment), eclist)) + +class QFEntity(bpy.types.PropertyGroup): + classname = EnumProperty(items = qfentity_items, name = "Entity Class") + flags = BoolVectorProperty(size=12) + +class EntityPanel(bpy.types.Panel): + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = 'object' + bl_label = 'QF Entity' + + @classmethod + def poll(cls, context): + return True + + def draw(self, context): + layout = self.layout + obj = context.active_object + qfmap = context.scene.qfmap + ec = qfmap.entity_classes.entity_classes[obj.qfentity.classname] + flags = ec.flagnames + [""] * (8 - len(ec.flagnames)) + flags += ["!easy", "!medium", "!hard", "!dm"] + layout.prop(obj.qfentity, "classname") + split = layout.split() + for c in range(3): + col = split.column() + sub = col.column(align=True) + for r in range(4): + idx = c * 4 + r + sub.prop(obj.qfentity, "flags", text = flags[idx], index = idx) def default_brush_entity(entityclass): name = entityclass.name @@ -75,7 +114,11 @@ def add_entity(self, context, entclass): obj = bpy.data.objects.new(entity_class.name, mesh) obj.location = context.scene.cursor_location obj.select = True + obj.qfentity.classname = entclass context.scene.objects.link(obj) bpy.context.scene.objects.active=obj context.user_preferences.edit.use_global_undo = True return {'FINISHED'} + +def register(): + bpy.types.Object.qfentity = PointerProperty(type=QFEntity)