multi-user/multi_user/ui.py

402 lines
13 KiB
Python
Raw Normal View History

import bpy
2019-09-30 19:35:50 +08:00
from . import operators
2019-09-30 19:35:50 +08:00
from .libs.replication.replication.constants import (ADDED, ERROR, FETCHED,
MODIFIED, RP_COMMON, UP)
2019-04-24 23:42:23 +08:00
2019-09-13 22:46:26 +08:00
ICONS_PROP_STATES = ['TRIA_DOWN', # ADDED
'TRIA_UP', # COMMITED
'KEYTYPE_KEYFRAME_VEC', # PUSHED
'TRIA_DOWN', # FETCHED
'FILE_REFRESH', # UP
'TRIA_UP'] # CHANGED
2019-08-23 18:28:57 +08:00
class SESSION_PT_settings(bpy.types.Panel):
2019-07-02 22:43:30 +08:00
"""Settings panel"""
bl_idname = "MULTIUSER_SETTINGS_PT_panel"
bl_label = "Session"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
2019-07-02 00:04:35 +08:00
def draw_header(self, context):
self.layout.label(text="", icon='TOOL_SETTINGS')
def draw(self, context):
layout = self.layout
layout.use_property_split = True
2019-08-09 22:47:15 +08:00
row = layout.row()
2019-03-15 23:50:59 +08:00
2019-08-23 18:28:57 +08:00
if hasattr(context.window_manager, 'session'):
2019-08-06 17:34:39 +08:00
# STATE INITIAL
2019-08-23 18:28:57 +08:00
if not operators.client \
or (operators.client and operators.client.state == 0):
2019-08-09 21:20:49 +08:00
pass
2019-04-08 23:01:02 +08:00
else:
2019-08-23 18:28:57 +08:00
# STATE ACTIVE
if operators.client.state == 2:
2019-04-08 23:01:02 +08:00
row = layout.row()
row.operator("session.stop", icon='QUIT', text="Exit")
2019-07-02 00:04:35 +08:00
row = layout.row()
2019-08-06 17:34:39 +08:00
# STATE SYNCING
2019-08-23 18:28:57 +08:00
else:
2019-05-03 17:32:14 +08:00
status = "connecting..."
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-08-09 21:20:49 +08:00
class SESSION_PT_settings_network(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_NETWORK_PT_panel"
bl_label = "Network"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
@classmethod
def poll(cls, context):
2019-08-23 18:28:57 +08:00
return not operators.client \
or (operators.client and operators.client.state == 0)
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
# USER SETTINGS
row = layout.row()
row.prop(settings, "session_mode", expand=True)
row = layout.row()
if settings.session_mode == 'HOST':
box = row.box()
row = box.row()
2019-09-19 19:02:39 +08:00
row.label(text="Start empty:")
2019-08-27 23:33:48 +08:00
row.prop(settings, "start_empty", text="")
row = box.row()
row.label(text="Port:")
row.prop(settings, "port", text="")
2019-08-09 21:20:49 +08:00
row = box.row()
row.label(text="IPC Port:")
row.prop(settings, "ttl_port", text="")
row = box.row()
2019-08-09 21:20:49 +08:00
row.operator("session.start", text="HOST").host = True
else:
box = row.box()
row = box.row()
2019-09-19 19:02:39 +08:00
row.prop(settings, "ip", text="IP")
2019-08-09 21:20:49 +08:00
row = box.row()
2019-09-19 19:02:39 +08:00
row.label(text="Port:")
2019-08-09 21:20:49 +08:00
row.prop(settings, "port", text="")
row = box.row()
row.label(text="IPC Port:")
row.prop(settings, "ttl_port", text="")
2019-08-09 21:20:49 +08:00
row = box.row()
row.operator("session.start", text="CONNECT").host = False
class SESSION_PT_settings_user(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_USER_PT_panel"
bl_label = "User"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
@classmethod
def poll(cls, context):
2019-08-23 18:28:57 +08:00
return not operators.client \
or (operators.client and operators.client.state == 0)
2019-08-09 21:20:49 +08:00
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
row = layout.row()
# USER SETTINGS
2019-09-25 00:37:36 +08:00
row.prop(settings, "username", text="name")
2019-08-23 18:28:57 +08:00
2019-08-09 21:20:49 +08:00
row = layout.row()
2019-08-23 18:28:57 +08:00
row.prop(settings, "client_color", text="color")
2019-08-09 21:20:49 +08:00
row = layout.row()
2019-03-14 19:09:33 +08:00
class SESSION_PT_settings_replication(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_REPLICATION_PT_panel"
bl_label = "Advanced"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
2019-09-24 20:42:59 +08:00
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return not operators.client \
or (operators.client and operators.client.state == 0)
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
2019-09-25 00:37:36 +08:00
# Right managment
if settings.session_mode == 'HOST':
row = layout.row(align=True)
row.label(text="Right strategy:")
row.prop(settings,"right_strategy",text="")
row = layout.row()
2019-09-25 00:37:36 +08:00
row = layout.row()
# Replication frequencies
flow = row .grid_flow(
row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
2019-09-16 04:16:54 +08:00
line = flow.row(align=True)
line.label(text=" ")
line.separator()
line.label(text="refresh (sec)")
line.label(text="apply (sec)")
2019-09-19 05:10:36 +08:00
for item in settings.supported_datablock:
2019-09-16 04:16:54 +08:00
line = flow.row(align=True)
2019-09-16 19:43:43 +08:00
line.prop(item, "auto_push", text="", icon=item.icon)
2019-09-16 04:16:54 +08:00
line.separator()
line.prop(item, "bl_delay_refresh", text="")
line.prop(item, "bl_delay_apply", text="")
class SESSION_PT_user(bpy.types.Panel):
bl_idname = "MULTIUSER_USER_PT_panel"
bl_label = "Online users"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
2019-08-09 21:20:49 +08:00
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
2019-08-23 18:28:57 +08:00
2019-03-14 00:02:53 +08:00
@classmethod
def poll(cls, context):
2019-08-23 18:28:57 +08:00
return operators.client and operators.client.state == 2
2019-03-14 00:02:53 +08:00
def draw(self, context):
layout = self.layout
online_users = context.window_manager.online_users
selected_user = context.window_manager.user_index
settings = context.window_manager.session
active_user = online_users[selected_user] if len(online_users)-1>=selected_user else 0
2019-08-23 18:28:57 +08:00
2019-03-14 00:02:53 +08:00
# Create a simple row.
row = layout.row()
box = row.box()
2020-01-22 21:33:34 +08:00
split = box.split(factor=0.5)
split.label(text="user")
split.label(text="frame")
split.label(text="ping")
2019-08-09 22:47:15 +08:00
row = layout.row()
layout.template_list("SESSION_UL_users", "", context.window_manager, "online_users", context.window_manager, "user_index")
2019-08-23 18:28:57 +08:00
if active_user != 0 and active_user.username != settings.username:
row = layout.row()
user_operations = row.split()
user_operations.alert = context.window_manager.session.time_snap_running
user_operations.operator(
"session.snapview",
text="",
2020-01-22 22:15:44 +08:00
icon='VIEW_CAMERA').target_client = active_user.username
user_operations.alert = context.window_manager.session.user_snap_running
user_operations.operator(
"session.snaptime",
text="",
icon='TIME').target_client = active_user.username
2019-08-23 18:28:57 +08:00
2019-04-17 19:39:36 +08:00
class SESSION_UL_users(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
2020-01-20 06:10:22 +08:00
session = operators.client
settings = context.window_manager.session
is_local_user = item.username == settings.username
2020-01-20 06:10:22 +08:00
ping = '-'
frame_current = '-'
2020-01-20 06:10:22 +08:00
if session:
user = session.online_users.get(item.username)
if user:
ping = str(user['latency'])
metadata = user.get('metadata')
if metadata:
frame_current = str(metadata['frame_current'])
2020-01-22 21:33:34 +08:00
split = layout.split(factor=0.5)
split.label(text=item.username)
split.label(text=frame_current)
2020-01-20 06:10:22 +08:00
split.label(text=ping)
2019-07-01 21:59:51 +08:00
2019-09-24 20:42:59 +08:00
class SESSION_PT_presence(bpy.types.Panel):
bl_idname = "MULTIUSER_MODULE_PT_panel"
bl_label = "Presence overlay"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
bl_parent_id = 'MULTIUSER_SETTINGS_PT_panel'
2019-09-25 00:37:36 +08:00
bl_options = {'DEFAULT_CLOSED'}
2019-09-24 20:42:59 +08:00
@classmethod
def poll(cls, context):
return True
def draw_header(self, context):
self.layout.prop(context.window_manager.session, "enable_presence", text="")
def draw(self, context):
layout = self.layout
settings = context.window_manager.session
layout.active = settings.enable_presence
col = layout.column()
col.prop(settings,"presence_show_selected")
col.prop(settings,"presence_show_user")
row = layout.row()
2019-08-23 18:28:57 +08:00
def draw_property(context, parent, property_uuid, level=0):
settings = context.window_manager.session
item = operators.client.get(uuid=property_uuid)
2019-08-23 18:28:57 +08:00
2020-01-22 21:33:34 +08:00
if item.state == ERROR:
return
2019-08-23 18:28:57 +08:00
area_msg = parent.row(align=True)
if level > 0:
for i in range(level):
area_msg.label(text="")
line = area_msg.box()
2019-10-09 20:09:11 +08:00
name = item.data['name'] if item.data else item.uuid
2019-08-23 18:28:57 +08:00
detail_item_box = line.row(align=True)
detail_item_box.label(text="",
icon=settings.supported_datablock[item.str_type].icon)
2019-08-28 22:19:32 +08:00
detail_item_box.label(text="{} ".format(name))
# Operations
2019-09-24 20:42:59 +08:00
have_right_to_modify = settings.is_admin or \
item.owner == settings.username or \
item.owner == RP_COMMON
2019-09-27 23:16:02 +08:00
if have_right_to_modify:
detail_item_box.operator(
"session.commit",
text="",
icon='TRIA_UP').target = item.uuid
detail_item_box.separator()
2019-08-28 22:19:32 +08:00
if item.state in [FETCHED, UP]:
2019-08-23 18:28:57 +08:00
detail_item_box.operator(
"session.apply",
text="",
icon=ICONS_PROP_STATES[item.state]).target = item.uuid
2019-09-13 22:46:26 +08:00
elif item.state in [MODIFIED, ADDED]:
2019-08-28 19:13:32 +08:00
detail_item_box.operator(
"session.commit",
text="",
icon=ICONS_PROP_STATES[item.state]).target = item.uuid
else:
detail_item_box.label(text="", icon=ICONS_PROP_STATES[item.state])
right_icon = "DECORATE_UNLOCKED"
2019-09-24 20:42:59 +08:00
if not have_right_to_modify:
2019-08-23 18:28:57 +08:00
right_icon = "DECORATE_LOCKED"
2019-08-28 22:19:32 +08:00
if have_right_to_modify:
ro = detail_item_box.operator(
"session.right", text="", icon=right_icon)
ro.key = property_uuid
2019-08-28 22:19:32 +08:00
detail_item_box.operator(
"session.remove_prop", text="", icon="X").property_path = property_uuid
else:
detail_item_box.label(text="", icon="DECORATE_LOCKED")
2019-08-08 20:46:59 +08:00
class SESSION_PT_outliner(bpy.types.Panel):
bl_idname = "MULTIUSER_PROPERTIES_PT_panel"
bl_label = "Properties"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Multiuser"
2019-03-14 00:02:53 +08:00
@classmethod
def poll(cls, context):
2019-08-23 18:28:57 +08:00
return operators.client and operators.client.state == 2
2019-03-14 00:02:53 +08:00
2019-07-02 00:04:35 +08:00
def draw_header(self, context):
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')
2019-08-23 18:28:57 +08:00
2019-03-14 00:02:53 +08:00
def draw(self, context):
layout = self.layout
2019-08-23 18:28:57 +08:00
if hasattr(context.window_manager, 'session'):
2019-09-19 05:10:36 +08:00
# Filters
settings = context.window_manager.session
flow = layout.grid_flow(
row_major=True,
columns=0,
even_columns=True,
even_rows=False,
align=True)
for item in settings.supported_datablock:
2019-09-13 23:00:15 +08:00
col = flow.column(align=True)
col.prop(item, "use_as_filter", text="", icon=item.icon)
2019-04-01 22:14:21 +08:00
2019-09-19 05:10:36 +08:00
row = layout.row(align=True)
row.prop(settings, "filter_owned", text="Show only owned")
2019-04-11 20:39:31 +08:00
row = layout.row(align=True)
2019-09-19 05:10:36 +08:00
# Properties
types_filter = [t.type_name for t in settings.supported_datablock
if t.use_as_filter]
2019-09-13 23:00:15 +08:00
2019-09-19 05:10:36 +08:00
key_to_filter = operators.client.list(
filter_owner=settings.username) if settings.filter_owned else operators.client.list()
client_keys = [key for key in key_to_filter
if operators.client.get(uuid=key).str_type
in types_filter]
2019-08-09 22:47:15 +08:00
if client_keys and len(client_keys) > 0:
col = layout.column(align=True)
2019-08-09 22:47:15 +08:00
for key in client_keys:
2019-08-23 18:28:57 +08:00
draw_property(context, col, key)
2019-04-11 20:39:31 +08:00
else:
2019-09-13 23:00:15 +08:00
row.label(text="Empty")
2019-04-11 20:39:31 +08:00
classes = (
SESSION_UL_users,
SESSION_PT_settings,
2019-08-09 21:20:49 +08:00
SESSION_PT_settings_user,
SESSION_PT_settings_network,
2019-09-25 00:37:36 +08:00
SESSION_PT_presence,
SESSION_PT_settings_replication,
SESSION_PT_user,
2019-09-24 20:42:59 +08:00
SESSION_PT_outliner
)
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
2019-03-14 19:09:33 +08:00
register()