multi-user/ui.py
2019-05-09 15:56:30 +02:00

237 lines
8.5 KiB
Python

import bpy
from . import client, operators
ICONS = {'Curve':'CURVE_DATA', 'Client':'SOLO_ON','Collection': 'FILE_FOLDER', 'Mesh': 'MESH_DATA', 'Object': 'OBJECT_DATA', 'Material': 'MATERIAL_DATA',
'Texture': 'TEXTURE_DATA', 'Scene': 'SCENE_DATA', 'Light': 'LIGHT_DATA', 'Camera': 'CAMERA_DATA', 'Action': 'ACTION_DATA', 'Armature': 'ARMATURE_DATA', 'Grease Pencil': 'GREASEPENCIL'}
class SessionSettingsPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET settings"
bl_idname = "SCENE_PT_SessionSettings"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
if hasattr(context.scene, 'session_settings'):
net_settings = context.scene.session_settings
scene = context.scene
row = layout.row()
if operators.client_instance is None:
row = layout.row()
box = row.box()
row = box.row()
row.label(text="USER", icon='TRIA_RIGHT')
row = box.row()
row.prop(scene.session_settings, "username", text="id")
row = box.row()
row.prop(scene.session_settings, "client_color", text="color")
row = box.row()
row = layout.row()
box = row.box()
row = box.row()
row.label(text="NETWORK", icon = "TRIA_RIGHT")
row = box.row()
row.label(text="draw overlay:")
row.prop(net_settings, "enable_draw", text="")
row = box.row()
row.prop(scene.session_settings, "session_mode", expand=True)
row = box.row()
if scene.session_settings.session_mode == 'HOST':
box = row.box()
row = box.row()
row.label(text="init scene:")
row.prop(net_settings, "init_scene", text="")
row = layout.row()
row.operator("session.create", text="HOST")
else:
box = row.box()
row = box.row()
row.prop(net_settings, "ip", text="ip")
row = box.row()
row.label(text="port:")
row.prop(scene.session_settings, "port", text="")
row = box.row()
row.label(text="load data:")
row.prop(net_settings, "load_data", text="")
row = box.row()
row.label(text="clear scene:")
row.prop(net_settings, "clear_scene", text="")
row = layout.row()
row.operator("session.join", text="CONNECT")
else:
if operators.client_state == 3:
row = layout.row()
row.operator("session.stop", icon='QUIT', text="Exit")
row = layout.row()
# row = layout.row()
# row.label(text="serial ",icon="KEYTYPE_EXTREME_VEC")
# row = layout.row()
# row.label(text="serial ",icon="KEYTYPE_BREAKDOWN_VEC")
# row = layout.row()
# row.label(text="serial ",icon="KEYTYPE_JITTER_VEC")
box = row.box()
row = box.row()
row.label(text="", icon='INFO')
row = box.row()
row.label(text="Sync tasks: {}".format(operators.client_instance.active_tasks))
else:
status = "connecting..."
if net_settings.is_admin:
status = "init scene...({} tasks remaining)".format(operators.client_instance.active_tasks)
row.label(text=status)
row = layout.row()
row.operator("session.stop", icon='QUIT', text="CANCEL")
row = layout.row()
class SessionUsersPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET users"
bl_idname = "SCENE_PT_SessionUsers"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
return operators.client_state == 3
def draw(self, context):
layout = self.layout
net_settings = context.scene.session_settings
scene = context.scene
# Create a simple row.
row = layout.row()
if operators.client_keys and len(operators.client_keys) > 0:
for key in operators.client_keys:
if 'Client' in key[0]:
info = ""
item_box = row.box()
detail_item_box = item_box.row()
username = key[0].split('/')[1]
if username == net_settings.username:
info = "(self)"
# detail_item_box = item_box.row()
detail_item_box.label(
text="{} - {}".format(username, info))
if net_settings.username not in key[0]:
detail_item_box.operator(
"session.snapview", text="", icon='VIEW_CAMERA').target_client = username
row = layout.row()
else:
row.label(text="Empty")
row = layout.row()
def get_client_key(item):
return item[0]
class SessionPropertiesPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET properties"
bl_idname = "SCENE_PT_SessionProps"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
return operators.client_state == 3
def draw(self, context):
layout = self.layout
if hasattr(context.scene,'session_settings'):
net_settings = context.scene.session_settings
scene = context.scene
# Create a simple row.
row = layout.row()
row = layout.row(align=True)
row.prop(net_settings, "buffer", text="")
row.prop(net_settings, "add_property_depth", text="")
add = row.operator("session.add_prop", text="",
icon="ADD")
add.property_path = net_settings.buffer
add.depth = net_settings.add_property_depth
row = layout.row()
# Property area
area_msg = row.box()
area_msg.operator("session.refresh", text="",
icon="UV_SYNC_SELECT")
if operators.client_keys and len(operators.client_keys) > 0:
for item in sorted(operators.client_keys, key=get_client_key):
owner = 'toto'
try:
owner = item[1]
except:
owner = item[1].decode()
pass
store_type,store_name = item[0].split('/')
item_box = area_msg.box()
detail_item_box = item_box.row(align = True)
# detail_item_box = item_box.row()
detail_item_box.label(text="",icon=ICONS[store_type])
detail_item_box.label(text="{} ".format(store_name))
# detail_item_box.prop(net_settings, "clients", text="")
detail_item_box.label(text="{} ".format(owner))
right_icon = "DECORATE_UNLOCKED"
if owner == net_settings.username:
right_icon="DECORATE_UNLOCKED"
else:
right_icon="DECORATE_LOCKED"
ro = detail_item_box.operator("session.right", text="",emboss=net_settings.is_admin, icon=right_icon)
ro.key = item[0]
# detail_item_box.operator(
# "session.remove_prop", text="", icon="X").property_path = key
else:
area_msg.label(text="Empty")
classes = (
SessionSettingsPanel,
SessionUsersPanel,
SessionPropertiesPanel,
)
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
register()