multi-user/ui.py

243 lines
8.8 KiB
Python
Raw Normal View History

import bpy
2019-03-25 22:30:05 +08:00
2019-04-10 23:01:21 +08:00
from . import client, operators
2019-03-07 20:45:44 +08:00
2019-04-24 23:42:23 +08:00
2019-05-08 23:06:52 +08:00
ICONS = {'Curve':'CURVE_DATA', 'Client':'SOLO_ON','Collection': 'FILE_FOLDER', 'Mesh': 'MESH_DATA', 'Object': 'OBJECT_DATA', 'Material': 'MATERIAL_DATA',
2019-05-13 17:49:46 +08:00
'Texture': 'TEXTURE_DATA', 'Scene': 'SCENE_DATA', 'Light': 'LIGHT_DATA', 'SpotLight': 'LIGHT_DATA', 'SunLight': 'LIGHT_DATA', 'PointLight': 'LIGHT_DATA', 'Camera': 'CAMERA_DATA', 'Action': 'ACTION_DATA', 'Armature': 'ARMATURE_DATA', 'Grease Pencil': 'GREASEPENCIL'}
2019-04-24 23:42:23 +08:00
2019-03-14 00:02:53 +08:00
class SessionSettingsPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
2019-03-14 00:02:53 +08:00
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
2019-03-14 19:09:33 +08:00
2019-05-10 23:00:47 +08:00
if hasattr(context.window_manager, 'session_settings'):
net_settings = context.window_manager.session_settings
window_manager = context.window_manager
2019-03-15 23:50:59 +08:00
2019-03-14 00:02:53 +08:00
row = layout.row()
2019-04-10 23:01:21 +08:00
if operators.client_instance is None:
row = layout.row()
2019-03-25 21:56:09 +08:00
box = row.box()
row = box.row()
2019-05-03 17:32:14 +08:00
row.label(text="USER", icon='TRIA_RIGHT')
row = box.row()
2019-05-10 23:00:47 +08:00
row.prop(window_manager.session_settings, "username", text="id")
row = box.row()
2019-05-10 23:00:47 +08:00
row.prop(window_manager.session_settings, "client_color", text="color")
row = box.row()
2019-03-25 22:30:05 +08:00
2019-03-15 23:50:59 +08:00
row = layout.row()
box = row.box()
row = box.row()
2019-05-03 17:32:14 +08:00
row.label(text="NETWORK", icon = "TRIA_RIGHT")
row = box.row()
row.label(text="draw overlay:")
row.prop(net_settings, "enable_draw", text="")
2019-05-10 21:12:52 +08:00
row = box.row()
row.label(text="clear blend:")
row.prop(net_settings, "clear_scene", text="")
row = box.row()
row = box.row()
2019-05-10 23:00:47 +08:00
row.prop(net_settings, "session_mode", expand=True)
row = box.row()
2019-05-10 21:12:52 +08:00
2019-03-25 22:30:05 +08:00
2019-05-10 23:00:47 +08:00
if window_manager.session_settings.session_mode == 'HOST':
2019-04-01 22:14:21 +08:00
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:")
2019-05-10 23:00:47 +08:00
row.prop(window_manager.session_settings, "port", text="")
2019-04-01 22:14:21 +08:00
row = box.row()
row.label(text="load data:")
row.prop(net_settings, "load_data", text="")
2019-05-10 21:12:52 +08:00
2019-04-01 22:14:21 +08:00
row = layout.row()
row.operator("session.join", text="CONNECT")
2019-03-25 22:30:05 +08:00
2019-04-08 23:01:02 +08:00
else:
if operators.client_state == 3:
2019-04-08 23:01:02 +08:00
row = layout.row()
row.operator("session.stop", icon='QUIT', text="Exit")
2019-05-03 17:32:14 +08:00
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")
2019-05-03 17:32:14 +08:00
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")
2019-04-01 22:14:21 +08:00
2019-05-03 17:32:14 +08:00
2019-04-01 22:14:21 +08:00
row = layout.row()
2019-03-14 00:02:53 +08:00
2019-03-14 19:09:33 +08:00
2019-03-14 00:02:53 +08:00
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
2019-03-14 00:02:53 +08:00
def draw(self, context):
layout = self.layout
2019-03-14 19:09:33 +08:00
2019-05-10 23:00:47 +08:00
net_settings = context.window_manager.session_settings
scene = context.window_manager
2019-03-14 00:02:53 +08:00
# Create a simple row.
row = layout.row()
2019-04-17 19:39:36 +08:00
if operators.client_keys and len(operators.client_keys) > 0:
for key in operators.client_keys:
2019-04-22 18:14:39 +08:00
if 'Client' in key[0]:
2019-04-17 19:39:36 +08:00
info = ""
item_box = row.box()
detail_item_box = item_box.row()
2019-03-14 19:09:33 +08:00
2019-04-22 18:14:39 +08:00
username = key[0].split('/')[1]
2019-04-17 19:39:36 +08:00
if username == net_settings.username:
info = "(self)"
# detail_item_box = item_box.row()
detail_item_box.label(
text="{} - {}".format(username, info))
2019-04-22 18:14:39 +08:00
if net_settings.username not in key[0]:
2019-04-17 19:39:36 +08:00
detail_item_box.operator(
"session.snapview", text="", icon='VIEW_CAMERA').target_client = username
row = layout.row()
else:
row.label(text="Empty")
row = layout.row()
2019-03-14 00:02:53 +08:00
2019-05-09 21:56:30 +08:00
def get_client_key(item):
return item[0]
2019-03-14 00:02:53 +08:00
class SessionPropertiesPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET properties"
2019-04-01 22:14:21 +08:00
bl_idname = "SCENE_PT_SessionProps"
2019-03-14 00:02:53 +08:00
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
return operators.client_state == 3
2019-03-14 00:02:53 +08:00
def draw(self, context):
layout = self.layout
2019-03-14 19:09:33 +08:00
2019-05-10 23:00:47 +08:00
if hasattr(context.window_manager,'session_settings'):
net_settings = context.window_manager.session_settings
scene = context.window_manager
2019-04-01 22:14:21 +08:00
# Create a simple row.
2019-02-09 01:34:10 +08:00
row = layout.row()
2019-04-01 22:14:21 +08:00
2019-04-11 20:39:31 +08:00
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:
2019-05-09 21:56:30 +08:00
for item in sorted(operators.client_keys, key=get_client_key):
owner = 'toto'
try:
owner = item[1]
except:
owner = item[1].decode()
pass
2019-04-26 22:41:07 +08:00
store_type,store_name = item[0].split('/')
2019-04-11 20:39:31 +08:00
item_box = area_msg.box()
2019-04-22 18:14:39 +08:00
detail_item_box = item_box.row(align = True)
2019-04-11 20:39:31 +08:00
# detail_item_box = item_box.row()
2019-04-26 22:41:07 +08:00
detail_item_box.label(text="",icon=ICONS[store_type])
detail_item_box.label(text="{} ".format(store_name))
2019-04-22 18:14:39 +08:00
2019-04-24 23:42:23 +08:00
# detail_item_box.prop(net_settings, "clients", text="")
2019-04-22 18:14:39 +08:00
detail_item_box.label(text="{} ".format(owner))
2019-04-24 23:42:23 +08:00
right_icon = "DECORATE_UNLOCKED"
2019-04-22 18:14:39 +08:00
if owner == net_settings.username:
2019-04-24 23:42:23 +08:00
right_icon="DECORATE_UNLOCKED"
2019-04-22 18:14:39 +08:00
else:
2019-04-24 23:42:23 +08:00
right_icon="DECORATE_LOCKED"
2019-04-26 22:41:07 +08:00
ro = detail_item_box.operator("session.right", text="",emboss=net_settings.is_admin, icon=right_icon)
2019-04-24 23:42:23 +08:00
ro.key = item[0]
2019-04-11 20:39:31 +08:00
# detail_item_box.operator(
# "session.remove_prop", text="", icon="X").property_path = key
else:
area_msg.label(text="Empty")
classes = (
2019-03-14 00:02:53 +08:00
SessionSettingsPanel,
2019-04-17 19:39:36 +08:00
SessionUsersPanel,
2019-04-09 00:21:48 +08:00
SessionPropertiesPanel,
2019-04-26 22:41:07 +08:00
)
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
2019-03-14 19:09:33 +08:00
register()