mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-26 07:07:58 +00:00
Addon: Added custom drone actions and UI
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import bpy
|
||||
from bpy.types import PropertyGroup
|
||||
|
||||
from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, FloatProperty, IntProperty
|
||||
from bpy.props import PointerProperty, CollectionProperty, \
|
||||
StringProperty, BoolProperty, EnumProperty, FloatProperty, IntProperty
|
||||
from .operators.export import ExportSwarmAnimation
|
||||
from .operators.check import CheckSwarmAnimation
|
||||
from .ui.drone_panel import DronePanel
|
||||
from .operators.drone_props import DroneCustomPropsActions
|
||||
from .ui.drone_panel import DronePanel, CustomDroneItems
|
||||
from .ui.led_panel import LedPanel
|
||||
from .ui.swarm_panel import SwarmPanel, SwarmFilteringPanel
|
||||
|
||||
@@ -112,6 +114,15 @@ class CleverShowProperties(PropertyGroup):
|
||||
min=0,
|
||||
)
|
||||
|
||||
class CustomDroneProperties(PropertyGroup):
|
||||
name: StringProperty()
|
||||
active: BoolProperty(
|
||||
name="Active",
|
||||
default=False,
|
||||
)
|
||||
args: StringProperty(
|
||||
default="{}",
|
||||
)
|
||||
|
||||
class CleverDroneProperties(PropertyGroup):
|
||||
is_drone: BoolProperty(name="Is drone")
|
||||
@@ -121,6 +132,12 @@ class CleverDroneProperties(PropertyGroup):
|
||||
default=True,
|
||||
)
|
||||
|
||||
active_index: IntProperty(
|
||||
name="Active custom drone commands index",
|
||||
options=set(), # not animateable
|
||||
)
|
||||
custom_props: CollectionProperty(type=CustomDroneProperties)
|
||||
|
||||
|
||||
class CleverLedProperties(PropertyGroup):
|
||||
is_led: BoolProperty(
|
||||
@@ -148,9 +165,9 @@ class CleverLedProperties(PropertyGroup):
|
||||
)
|
||||
|
||||
|
||||
classes1 = (CleverShowProperties, CleverDroneProperties, CleverLedProperties,
|
||||
ExportSwarmAnimation, CheckSwarmAnimation,
|
||||
SwarmPanel, DronePanel, LedPanel,
|
||||
classes1 = (CleverShowProperties, CustomDroneProperties, CleverDroneProperties, CleverLedProperties,
|
||||
ExportSwarmAnimation, CheckSwarmAnimation, DroneCustomPropsActions,
|
||||
SwarmPanel, CustomDroneItems, DronePanel, LedPanel,
|
||||
)
|
||||
classes2 = (SwarmFilteringPanel, )
|
||||
|
||||
|
||||
71
blender-addon/clever-show-addon-src/operators/drone_props.py
Normal file
71
blender-addon/clever-show-addon-src/operators/drone_props.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import re
|
||||
|
||||
from bpy.types import Operator
|
||||
from bpy.props import EnumProperty
|
||||
|
||||
class DroneCustomPropsActions(Operator):
|
||||
"""Move items up and down, add and remove"""
|
||||
bl_idname = "clever_show.list_action"
|
||||
bl_label = "List Actions"
|
||||
bl_description = "Move items up and down, add and remove"
|
||||
bl_options = {'REGISTER', 'INTERNAL'}
|
||||
|
||||
action: EnumProperty(
|
||||
items=(
|
||||
('UP', "Up", ""),
|
||||
('DOWN', "Down", ""),
|
||||
('REMOVE', "Remove", ""),
|
||||
('ADD', "Add", "")))
|
||||
|
||||
def _add(self, context):
|
||||
drone = context.object.drone
|
||||
|
||||
item = drone.custom_props.add()
|
||||
item.name = f"empty_action {len(drone.custom_props)}"
|
||||
|
||||
drone.active_index = len(drone.custom_props) - 1
|
||||
self.report({'INFO'}, f"Item '{item.name}' added to {context.object.name}")
|
||||
|
||||
def _move(self, context, item):
|
||||
drone = context.object.drone
|
||||
index = drone.active_index
|
||||
|
||||
if self.action == 'DOWN':
|
||||
to_index = index + 1 if index < len(drone.custom_props) - 1 else 0
|
||||
else: # elif self.action == 'UP':
|
||||
to_index = index - 1 if index > 0 else len(drone.custom_props) - 1
|
||||
|
||||
drone.custom_props.move(index, to_index)
|
||||
drone.active_index = to_index
|
||||
self.report({'INFO'}, f"Item '{item.name}' "
|
||||
f"moved to position {to_index}")
|
||||
|
||||
def _remove(self, context, item):
|
||||
drone = context.object.drone
|
||||
index = drone.active_index
|
||||
|
||||
info = f"Item '{item.name}' removed from list"
|
||||
drone.active_index = max(index - 1, 0) if index > 0 else index + 1
|
||||
drone.active_index = drone.active_index if len(drone.custom_props) > 1 else 0
|
||||
drone.custom_props.remove(index)
|
||||
self.report({'INFO'}, info)
|
||||
|
||||
def invoke(self, context, event):
|
||||
if self.action == 'ADD':
|
||||
self._add(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
try:
|
||||
drone = context.object.drone
|
||||
index = drone.active_index
|
||||
item = drone.custom_props[index]
|
||||
except IndexError:
|
||||
return {'CANCELLED'}
|
||||
|
||||
if self.action == 'REMOVE':
|
||||
self._remove(context, item)
|
||||
elif self.action in ('DOWN', 'UP'):
|
||||
self._move(context, item)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
1
blender-addon/clever-show-addon-src/operators/icons.txt
Normal file
1
blender-addon/clever-show-addon-src/operators/icons.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -1,4 +1,15 @@
|
||||
from bpy.types import Panel
|
||||
from bpy.types import Panel, UIList
|
||||
|
||||
|
||||
class CustomDroneItems(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
split = layout.split(factor=0.66, align=True)
|
||||
split.prop(item, "name", text="", emboss=False)
|
||||
row = split.row(align=True)
|
||||
row.label(text="Active: ")
|
||||
checkbox = "CHECKBOX_HLT" if item.active else "CHECKBOX_DEHLT"
|
||||
row.prop(item, "active", text="", emboss=False, icon=checkbox)
|
||||
|
||||
|
||||
class DronePanel(Panel):
|
||||
bl_label = "Clever-Show Drone"
|
||||
@@ -12,9 +23,32 @@ class DronePanel(Panel):
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
drone = context.object.drone
|
||||
layout.use_property_split = True
|
||||
# layout.use_property_decorate = True
|
||||
layout.use_property_decorate = True
|
||||
|
||||
layout.enabled = context.object.drone.is_drone
|
||||
|
||||
layout.prop(context.object.drone, "armed")
|
||||
items = len(drone.custom_props)
|
||||
|
||||
rows = 3
|
||||
if items > 0:
|
||||
rows = 5
|
||||
|
||||
row = layout.row()
|
||||
row.template_list("CustomDroneItems", "", drone, "custom_props", drone, "active_index", rows=rows)
|
||||
|
||||
col = row.column(align=True)
|
||||
col.operator("clever_show.list_action", icon='ADD', text="").action = 'ADD'
|
||||
col.operator("clever_show.list_action", icon='REMOVE', text="").action = 'REMOVE'
|
||||
col.separator()
|
||||
# col.menu("", icon='DOWNARROW_HLT', text="")
|
||||
|
||||
if items > 0:
|
||||
col.separator()
|
||||
sub = col.column(align=True)
|
||||
sub.operator("clever_show.list_action", icon='TRIA_UP', text="").action = 'UP'
|
||||
sub.operator("clever_show.list_action", icon='TRIA_DOWN', text="").action = 'DOWN'
|
||||
|
||||
sub.enabled = items > 1
|
||||
|
||||
Reference in New Issue
Block a user