2020-03-20 21:56:50 +08:00
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
2021-07-19 22:03:12 +08:00
from logging import log
2019-02-08 22:44:02 +08:00
import bpy
2021-07-12 20:55:41 +08:00
import bpy . utils . previews
2019-09-30 19:35:50 +08:00
2020-10-06 05:38:52 +08:00
from . utils import get_preferences , get_expanded_icon , get_folder_size , get_state_str
2020-07-10 22:50:09 +08:00
from replication . constants import ( ADDED , ERROR , FETCHED ,
2020-02-08 00:56:58 +08:00
MODIFIED , RP_COMMON , UP ,
STATE_ACTIVE , STATE_AUTH ,
STATE_CONFIG , STATE_SYNCING ,
STATE_INITIAL , STATE_SRV_SYNC ,
2020-03-20 18:46:43 +08:00
STATE_WAITING , STATE_QUITTING ,
2020-06-16 06:02:02 +08:00
STATE_LOBBY ,
2021-03-09 21:07:59 +08:00
CONNECTING )
2020-09-19 05:25:01 +08:00
from replication import __version__
2020-10-02 06:05:33 +08:00
from replication . interface import session
2020-12-22 23:04:50 +08:00
from . timers import registry
2019-04-24 23:42:23 +08:00
2019-09-13 22:46:26 +08:00
ICONS_PROP_STATES = [ ' TRIA_DOWN ' , # ADDED
2019-08-29 00:58:18 +08:00
' TRIA_UP ' , # COMMITED
' KEYTYPE_KEYFRAME_VEC ' , # PUSHED
' TRIA_DOWN ' , # FETCHED
2020-10-15 23:09:50 +08:00
' RECOVER_LAST ' , # RESET
' TRIA_UP ' , # CHANGED
' ERROR ' ] # ERROR
2019-08-23 18:28:57 +08:00
2020-06-16 22:40:00 +08:00
def printProgressBar ( iteration , total , prefix = ' ' , suffix = ' ' , decimals = 1 , length = 100 , fill = ' █ ' , fill_empty = ' ' ) :
2020-02-09 07:41:00 +08:00
"""
Call in a loop to create terminal progress bar
@params :
iteration - Required : current iteration ( Int )
total - Required : total iterations ( Int )
prefix - Optional : prefix string ( Str )
suffix - Optional : suffix string ( Str )
decimals - Optional : positive number of decimals in percent complete ( Int )
length - Optional : character length of bar ( Int )
fill - Optional : bar fill character ( Str )
2020-02-10 06:37:02 +08:00
From here :
https : / / gist . github . com / greenstick / b23e475d2bfdc3a82e34eaa1f6781ee4
2020-02-09 07:41:00 +08:00
"""
2020-07-07 21:50:05 +08:00
if total == 0 :
return " "
2020-02-09 07:41:00 +08:00
filledLength = int ( length * iteration / / total )
bar = fill * filledLength + fill_empty * ( length - filledLength )
2020-04-22 23:04:14 +08:00
return f " { prefix } | { bar } | { iteration } / { total } { suffix } "
2020-02-09 07:41:00 +08:00
2020-06-16 22:40:00 +08:00
2019-05-15 20:52:45 +08:00
class SESSION_PT_settings ( bpy . types . Panel ) :
2019-07-02 22:43:30 +08:00
""" Settings panel """
2019-06-14 00:09:16 +08:00
bl_idname = " MULTIUSER_SETTINGS_PT_panel "
2020-07-24 20:55:14 +08:00
bl_label = " "
2019-06-14 00:09:16 +08:00
bl_space_type = ' VIEW_3D '
bl_region_type = ' UI '
bl_category = " Multiuser "
2019-02-08 22:44:02 +08:00
2020-06-17 18:10:16 +08:00
def draw_header ( self , context ) :
layout = self . layout
2021-07-12 20:55:41 +08:00
settings = get_preferences ( )
from multi_user import icons
offline_icon = icons . icons_col [ " session_status_offline " ]
waiting_icon = icons . icons_col [ " session_status_waiting " ]
online_icon = icons . icons_col [ " session_status_online " ]
2021-03-04 21:22:54 +08:00
if session and session . state != STATE_INITIAL :
2020-10-02 06:05:33 +08:00
cli_state = session . state
2021-03-04 21:22:54 +08:00
state = session . state
2021-07-12 20:55:41 +08:00
connection_icon = offline_icon
2020-06-17 18:10:16 +08:00
if state == STATE_ACTIVE :
2021-07-12 20:55:41 +08:00
connection_icon = online_icon
2020-06-17 18:10:16 +08:00
else :
2021-07-12 20:55:41 +08:00
connection_icon = waiting_icon
2020-06-17 18:10:16 +08:00
2021-07-12 20:55:41 +08:00
layout . label ( text = f " { str ( settings . server_name ) } - { get_state_str ( cli_state ) } " , icon_value = connection_icon . icon_id )
2020-06-17 18:10:16 +08:00
else :
2021-07-12 20:55:41 +08:00
layout . label ( text = f " Multi-user - v { __version__ } " , icon = " ANTIALIASED " )
2020-06-17 18:10:16 +08:00
2021-06-08 21:02:53 +08:00
def draw ( self , context ) :
2019-02-08 22:44:02 +08:00
layout = self . layout
2020-06-18 04:11:20 +08:00
runtime_settings = context . window_manager . session
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2019-03-15 23:50:59 +08:00
2021-07-21 17:12:17 +08:00
if settings . is_first_launch :
# USER SETTINGS
row = layout . row ( )
row . label ( text = " 1. Enter your username and color: " )
row = layout . row ( )
split = row . split ( factor = 0.7 , align = True )
split . prop ( settings , " username " , text = " " )
split . prop ( settings , " client_color " , text = " " )
2019-05-03 17:32:14 +08:00
2021-07-21 17:12:17 +08:00
# DOC
row = layout . row ( )
row . label ( text = " 2. New here ? See the doc: " )
row = layout . row ( )
row . operator ( " doc.get " , text = " Documentation " , icon = " HELP " )
# START
row = layout . row ( )
row . label ( text = " 3: Start the Multi-user: " )
row = layout . row ( )
row . scale_y = 2
row . operator ( " firstlaunch.verify " , text = " Continue " )
if not settings . is_first_launch :
if hasattr ( context . window_manager , ' session ' ) :
# STATE INITIAL
if not session \
or ( session and session . state == STATE_INITIAL ) :
layout = self . layout
settings = get_preferences ( )
server_preset = settings . server_preset
selected_server = context . window_manager . server_index if context . window_manager . server_index < = len ( server_preset ) - 1 else 0
active_server_name = server_preset [ selected_server ] . name if len ( server_preset ) > = 1 else " "
is_server_selected = True if active_server_name else False # TODO : issues when removing the lowest server in the list
# SERVER LIST
row = layout . row ( )
box = row . box ( )
2021-07-22 15:38:01 +08:00
box . scale_y = 0.7
2021-07-21 17:12:17 +08:00
split = box . split ( factor = 0.7 )
split . label ( text = " Server " )
split . label ( text = " Online " )
2021-07-22 15:38:01 +08:00
col = row . column ( align = True )
2021-07-22 16:55:18 +08:00
col . operator ( " session.get_info " , icon = " FILE_REFRESH " , text = " " ) # TODO : Replace add by refresh operator
2021-07-21 17:12:17 +08:00
row = layout . row ( )
2021-07-22 15:38:01 +08:00
col = row . column ( align = True )
col . template_list ( " SESSION_UL_network " , " " , settings , " server_preset " , context . window_manager , " server_index " )
col . separator ( )
connectOp = col . row ( )
2021-07-23 18:51:16 +08:00
connectOp . operator ( " session.host " , text = " Host " ) # TODO : add a pop-up for admin and server password ? add port
2021-07-22 15:38:01 +08:00
connectopcol = connectOp . column ( )
connectopcol . enabled = is_server_selected
connectopcol . operator ( " session.connect " , text = " Connect " )
col = row . column ( align = True )
2021-07-23 18:51:16 +08:00
col . operator ( " session.preset_server_add " , icon = " ADD " , text = " " ) # TODO : add conditions (need a name, etc..) + add a checkbox for password without creating preferences
2021-07-22 15:38:01 +08:00
row_visible = col . row ( align = True )
col_visible = row_visible . column ( align = True )
col_visible . enabled = is_server_selected
col_visible . operator ( " session.preset_server_remove " , icon = " REMOVE " , text = " " ) . target_server_name = active_server_name
col_visible . separator ( )
col_visible . operator ( " session.preset_server_edit " , icon = " GREASEPENCIL " , text = " " ) . target_server_name = active_server_name
2021-07-21 17:12:17 +08:00
else :
2021-07-22 15:38:01 +08:00
exitbutton = layout . row ( )
exitbutton . scale_y = 1.5
exitbutton . operator ( " session.stop " , icon = ' QUIT ' , text = " Disconnect " )
2021-07-21 17:12:17 +08:00
2021-07-22 15:38:01 +08:00
progress = session . state_progress
2021-07-21 17:12:17 +08:00
current_state = session . state
info_msg = None
2021-07-22 15:38:01 +08:00
2021-07-21 17:12:17 +08:00
if current_state == STATE_LOBBY :
2021-07-22 15:38:01 +08:00
row = layout . row ( )
2021-07-21 17:12:17 +08:00
info_msg = " Waiting for the session to start. "
if info_msg :
info_box = row . box ( )
info_box . row ( ) . label ( text = info_msg , icon = ' INFO ' )
# PROGRESS BAR
if current_state in [ STATE_SYNCING , STATE_SRV_SYNC , STATE_WAITING ] :
2021-07-22 15:38:01 +08:00
row = layout . row ( )
row . label ( text = f " Status: { get_state_str ( current_state ) } " )
row = layout . row ( )
2021-07-21 17:12:17 +08:00
info_box = row . box ( )
2021-07-22 15:38:01 +08:00
info_box . label ( text = printProgressBar (
2021-07-21 17:12:17 +08:00
progress [ ' current ' ] ,
progress [ ' total ' ] ,
length = 16
) )
2020-06-11 00:43:21 +08:00
2020-06-17 18:10:16 +08:00
class SESSION_PT_advanced_settings ( bpy . types . Panel ) :
2019-08-29 00:58:18 +08:00
bl_idname = " MULTIUSER_SETTINGS_REPLICATION_PT_panel "
2019-09-16 23:24:48 +08:00
bl_label = " Advanced "
2019-08-29 00:58:18 +08:00
bl_space_type = ' VIEW_3D '
bl_region_type = ' UI '
bl_parent_id = ' MULTIUSER_SETTINGS_PT_panel '
2019-09-24 20:42:59 +08:00
bl_options = { ' DEFAULT_CLOSED ' }
2019-08-29 00:58:18 +08:00
@classmethod
def poll ( cls , context ) :
2021-07-13 00:01:35 +08:00
settings = get_preferences ( )
2020-10-02 06:05:33 +08:00
return not session \
2021-07-13 00:01:35 +08:00
or ( session and session . state == 0 ) \
2021-07-21 17:12:17 +08:00
and not settings . sidebar_advanced_shown \
and not settings . is_first_launch
2019-08-29 00:58:18 +08:00
2020-06-16 22:40:00 +08:00
def draw_header ( self , context ) :
2020-06-17 18:10:16 +08:00
self . layout . label ( text = " " , icon = ' PREFERENCES ' )
2020-06-16 22:40:00 +08:00
2019-08-29 00:58:18 +08:00
def draw ( self , context ) :
layout = self . layout
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2020-02-29 00:34:30 +08:00
2021-07-21 17:12:17 +08:00
#ADVANCED HOST
host_selection = layout . row ( ) . box ( )
host_selection . prop (
settings , " sidebar_advanced_hosting_expanded " , text = " Hosting " ,
icon = get_expanded_icon ( settings . sidebar_advanced_hosting_expanded ) ,
emboss = False )
if settings . sidebar_advanced_hosting_expanded :
2021-07-23 18:51:16 +08:00
host_selection_row = host_selection . row ( )
host_selection_row . prop ( settings , " host_port " , text = " Port: " )
2021-07-21 17:12:17 +08:00
host_selection_row = host_selection . row ( )
host_selection_row . label ( text = " Init the session from: " )
host_selection_row . prop ( settings , " init_method " , text = " " )
host_selection_row = host_selection . row ( )
host_selection_col = host_selection_row . column ( )
2021-07-23 18:51:16 +08:00
host_selection_col . prop ( settings , " host_use_server_password " , text = " Server password: " )
2021-07-21 17:12:17 +08:00
host_selection_col = host_selection_row . column ( )
2021-07-23 18:51:16 +08:00
host_selection_col . enabled = True if settings . host_use_server_password else False
host_selection_col . prop ( settings , " host_server_password " , text = " " )
2021-07-21 17:12:17 +08:00
host_selection_row = host_selection . row ( )
host_selection_col = host_selection_row . column ( )
2021-07-23 18:51:16 +08:00
host_selection_col . prop ( settings , " host_use_admin_password " , text = " Admin password: " )
2021-07-21 17:12:17 +08:00
host_selection_col = host_selection_row . column ( )
2021-07-23 18:51:16 +08:00
host_selection_col . enabled = True if settings . host_use_admin_password else False
host_selection_col . prop ( settings , " host_admin_password " , text = " " )
2021-07-21 17:12:17 +08:00
#ADVANCED NET
2020-06-17 18:10:16 +08:00
net_section = layout . row ( ) . box ( )
2020-09-15 18:31:46 +08:00
net_section . prop (
settings ,
" sidebar_advanced_net_expanded " ,
text = " Network " ,
icon = get_expanded_icon ( settings . sidebar_advanced_net_expanded ) ,
emboss = False )
if settings . sidebar_advanced_net_expanded :
net_section_row = net_section . row ( )
net_section_row . label ( text = " Timeout (ms): " )
net_section_row . prop ( settings , " connection_timeout " , text = " " )
2020-06-17 18:10:16 +08:00
2021-07-21 17:12:17 +08:00
#ADVANCED REPLICATION
2020-06-17 18:10:16 +08:00
replication_section = layout . row ( ) . box ( )
2020-09-15 18:31:46 +08:00
replication_section . prop (
settings ,
" sidebar_advanced_rep_expanded " ,
text = " Replication " ,
icon = get_expanded_icon ( settings . sidebar_advanced_rep_expanded ) ,
emboss = False )
if settings . sidebar_advanced_rep_expanded :
replication_section_row = replication_section . row ( )
replication_section_row . prop ( settings . sync_flags , " sync_render_settings " )
2020-09-09 05:09:42 +08:00
replication_section_row = replication_section . row ( )
2020-09-25 17:33:35 +08:00
replication_section_row . prop ( settings . sync_flags , " sync_active_camera " )
replication_section_row = replication_section . row ( )
2020-09-25 17:23:36 +08:00
replication_section_row . prop ( settings . sync_flags , " sync_during_editmode " )
2020-09-15 18:31:46 +08:00
replication_section_row = replication_section . row ( )
2020-09-25 17:23:36 +08:00
if settings . sync_flags . sync_during_editmode :
2020-09-15 18:31:46 +08:00
warning = replication_section_row . box ( )
warning . label ( text = " Don ' t use this with heavy meshes ! " , icon = ' ERROR ' )
replication_section_row = replication_section . row ( )
2021-02-12 17:49:04 +08:00
replication_section_row . prop ( settings , " depsgraph_update_rate " , text = " Apply delay " )
2020-09-15 18:31:46 +08:00
2021-07-21 17:12:17 +08:00
#ADVANCED CACHE
2020-09-21 18:12:19 +08:00
cache_section = layout . row ( ) . box ( )
cache_section . prop (
settings ,
" sidebar_advanced_cache_expanded " ,
text = " Cache " ,
icon = get_expanded_icon ( settings . sidebar_advanced_cache_expanded ) ,
emboss = False )
if settings . sidebar_advanced_cache_expanded :
cache_section_row = cache_section . row ( )
cache_section_row . label ( text = " Cache directory: " )
cache_section_row = cache_section . row ( )
cache_section_row . prop ( settings , " cache_directory " , text = " " )
cache_section_row = cache_section . row ( )
cache_section_row . label ( text = " Clear memory filecache: " )
cache_section_row . prop ( settings , " clear_memory_filecache " , text = " " )
2020-09-21 22:47:49 +08:00
cache_section_row = cache_section . row ( )
cache_section_row . operator ( ' session.clear_cache ' , text = f " Clear cache ( { get_folder_size ( settings . cache_directory ) } ) " )
2021-07-21 17:12:17 +08:00
#ADVANCED LOG
2020-09-15 18:40:51 +08:00
log_section = layout . row ( ) . box ( )
log_section . prop (
2020-09-15 18:31:46 +08:00
settings ,
" sidebar_advanced_log_expanded " ,
text = " Logging " ,
icon = get_expanded_icon ( settings . sidebar_advanced_log_expanded ) ,
emboss = False )
if settings . sidebar_advanced_log_expanded :
2020-09-15 18:40:51 +08:00
log_section_row = log_section . row ( )
log_section_row . label ( text = " Log level: " )
2020-09-15 18:31:46 +08:00
log_section_row . prop ( settings , ' logging_level ' , text = " " )
2021-07-13 00:01:35 +08:00
2019-05-15 20:52:45 +08:00
class SESSION_PT_user ( bpy . types . Panel ) :
2019-06-14 00:09:16 +08:00
bl_idname = " MULTIUSER_USER_PT_panel "
2020-01-18 01:15:37 +08:00
bl_label = " Online users "
2019-06-14 00:09:16 +08:00
bl_space_type = ' VIEW_3D '
bl_region_type = ' UI '
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 ) :
2021-07-21 17:12:17 +08:00
return session \
and session . state in [ STATE_ACTIVE , STATE_LOBBY ]
2019-03-14 00:02:53 +08:00
2020-06-16 22:40:00 +08:00
def draw_header ( self , context ) :
self . layout . label ( text = " " , icon = ' USER ' )
2019-03-14 00:02:53 +08:00
def draw ( self , context ) :
layout = self . layout
2020-01-18 01:15:37 +08:00
online_users = context . window_manager . online_users
selected_user = context . window_manager . user_index
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2020-06-16 22:40:00 +08:00
active_user = online_users [ selected_user ] if len (
online_users ) - 1 > = selected_user else 0
2019-08-23 18:28:57 +08:00
2021-07-21 17:12:17 +08:00
#USER LIST
2020-01-18 01:15:37 +08:00
row = layout . row ( )
box = row . box ( )
2020-06-11 21:25:58 +08:00
split = box . split ( factor = 0.35 )
2020-01-18 01:15:37 +08:00
split . label ( text = " user " )
2021-07-01 17:58:52 +08:00
split = split . split ( factor = 0.3 )
2021-06-29 23:10:59 +08:00
split . label ( text = " mode " )
2020-01-18 01:15:37 +08:00
split . label ( text = " frame " )
2021-07-01 17:58:52 +08:00
split . label ( text = " location " )
2020-01-18 01:15:37 +08:00
split . label ( text = " ping " )
2019-08-09 22:47:15 +08:00
2020-01-18 01:15:37 +08:00
row = layout . row ( )
2020-06-16 22:40:00 +08:00
layout . template_list ( " SESSION_UL_users " , " " , context . window_manager ,
" online_users " , context . window_manager , " user_index " )
2019-08-23 18:28:57 +08:00
2021-07-21 17:12:17 +08:00
#OPERATOR ON USER
2020-01-18 01:15:37 +08:00
if active_user != 0 and active_user . username != settings . username :
row = layout . row ( )
user_operations = row . split ( )
2021-03-04 21:22:54 +08:00
if session . state == STATE_ACTIVE :
2020-07-24 22:02:19 +08:00
user_operations . alert = context . window_manager . session . time_snap_running
user_operations . operator (
" session.snapview " ,
text = " " ,
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
2020-10-02 06:05:33 +08:00
if session . online_users [ settings . username ] [ ' admin ' ] :
2020-04-03 20:59:33 +08:00
user_operations . operator (
" session.kick " ,
text = " " ,
icon = ' CANCEL ' ) . user = active_user . username
2019-04-17 19:39:36 +08:00
2020-01-18 01:15:37 +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-09-15 18:31:46 +08:00
settings = get_preferences ( )
2020-01-18 01:15:37 +08:00
is_local_user = item . username == settings . username
2020-01-20 06:10:22 +08:00
ping = ' - '
2020-01-22 23:17:48 +08:00
frame_current = ' - '
2020-03-05 23:19:13 +08:00
scene_current = ' - '
2021-06-29 23:10:59 +08:00
mode_current = ' - '
mode_icon = ' BLANK1 '
2020-06-18 04:11:20 +08:00
status_icon = ' BLANK1 '
2020-01-20 06:10:22 +08:00
if session :
2020-01-22 23:17:48 +08:00
user = session . online_users . get ( item . username )
if user :
ping = str ( user [ ' latency ' ] )
metadata = user . get ( ' metadata ' )
2020-02-08 00:08:36 +08:00
if metadata and ' frame_current ' in metadata :
2020-08-28 21:27:46 +08:00
frame_current = str ( metadata . get ( ' frame_current ' , ' - ' ) )
scene_current = metadata . get ( ' scene_current ' , ' - ' )
2021-06-29 23:10:59 +08:00
mode_current = metadata . get ( ' mode_current ' , ' - ' )
if mode_current == " OBJECT " :
mode_icon = " OBJECT_DATAMODE "
elif mode_current == " EDIT_MESH " :
mode_icon = " EDITMODE_HLT "
elif mode_current == ' EDIT_CURVE ' :
mode_icon = " CURVE_DATA "
elif mode_current == ' EDIT_SURFACE ' :
mode_icon = " SURFACE_DATA "
elif mode_current == ' EDIT_TEXT ' :
mode_icon = " FILE_FONT "
elif mode_current == ' EDIT_ARMATURE ' :
mode_icon = " ARMATURE_DATA "
elif mode_current == ' EDIT_METABALL ' :
mode_icon = " META_BALL "
elif mode_current == ' EDIT_LATTICE ' :
mode_icon = " LATTICE_DATA "
elif mode_current == ' POSE ' :
mode_icon = " POSE_HLT "
elif mode_current == ' SCULPT ' :
mode_icon = " SCULPTMODE_HLT "
elif mode_current == ' PAINT_WEIGHT ' :
mode_icon = " WPAINT_HLT "
elif mode_current == ' PAINT_VERTEX ' :
mode_icon = " VPAINT_HLT "
elif mode_current == ' PAINT_TEXTURE ' :
mode_icon = " TPAINT_HLT "
elif mode_current == ' PARTICLE ' :
mode_icon = " PARTICLES "
elif mode_current == ' PAINT_GPENCIL ' or mode_current == ' EDIT_GPENCIL ' or mode_current == ' SCULPT_GPENCIL ' or mode_current == ' WEIGHT_GPENCIL ' or mode_current == ' VERTEX_GPENCIL ' :
mode_icon = " GREASEPENCIL "
2020-06-10 05:56:20 +08:00
if user [ ' admin ' ] :
status_icon = ' FAKE_USER_ON '
2020-06-11 21:25:58 +08:00
split = layout . split ( factor = 0.35 )
2020-06-10 05:56:20 +08:00
split . label ( text = item . username , icon = status_icon )
2021-07-01 17:58:52 +08:00
split = split . split ( factor = 0.3 )
2021-06-29 23:10:59 +08:00
split . label ( icon = mode_icon )
2020-01-22 23:17:48 +08:00
split . label ( text = frame_current )
2021-07-01 17:58:52 +08:00
split . label ( text = scene_current )
2020-01-20 06:10:22 +08:00
split . label ( text = ping )
2020-03-05 23:19:13 +08:00
2019-08-23 18:28:57 +08:00
def draw_property ( context , parent , property_uuid , level = 0 ) :
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2021-06-04 20:02:09 +08:00
item = session . repository . graph . get ( property_uuid )
2021-05-19 15:37:50 +08:00
type_id = item . data . get ( ' type_id ' )
2020-10-02 23:22:14 +08:00
area_msg = parent . row ( align = True )
2020-01-22 21:33:34 +08:00
if item . state == ERROR :
2020-10-02 23:22:14 +08:00
area_msg . alert = True
else :
area_msg . alert = False
2019-08-22 21:35:21 +08:00
line = area_msg . box ( )
2019-10-09 20:09:11 +08:00
name = item . data [ ' name ' ] if item . data else item . uuid
2021-05-19 15:37:50 +08:00
icon = settings . supported_datablocks [ type_id ] . icon if type_id else ' ERROR '
2019-08-23 18:28:57 +08:00
detail_item_box = line . row ( align = True )
2019-08-22 21:35:21 +08:00
2021-05-19 15:37:50 +08:00
detail_item_box . label ( text = " " , icon = icon )
2020-04-22 23:04:14 +08:00
detail_item_box . label ( text = f " { name } " )
2019-08-28 22:19:32 +08:00
# Operations
2020-10-02 23:22:14 +08:00
have_right_to_modify = ( item . owner == settings . username or \
item . owner == RP_COMMON ) and item . state != ERROR
2020-06-16 22:40:00 +08:00
2021-07-23 18:51:16 +08:00
from multi_user import icons
sync_status = icons . icons_col [ " repository_push " ] #TODO: Link all icons to the right sync (push/merge/issue). For issue use "UNLINKED" for icon
# sync_status = icons.icons_col["repository_merge"]
2019-09-27 23:16:02 +08:00
if have_right_to_modify :
detail_item_box . operator (
" session.commit " ,
text = " " ,
2021-07-23 18:51:16 +08:00
icon_value = sync_status . icon_id ) . target = item . uuid
2019-09-27 23:16:02 +08:00
detail_item_box . separator ( )
2020-06-16 22:40:00 +08:00
2019-08-28 22:19:32 +08:00
if item . state in [ FETCHED , UP ] :
2020-10-15 23:09:50 +08:00
apply = detail_item_box . operator (
2019-08-23 18:28:57 +08:00
" session.apply " ,
text = " " ,
2020-10-15 23:09:50 +08:00
icon = ICONS_PROP_STATES [ item . state ] )
apply . target = item . uuid
apply . reset_dependencies = True
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 = " " ,
2019-08-29 00:58:18 +08:00
icon = ICONS_PROP_STATES [ item . state ] ) . target = item . uuid
2019-08-22 21:35:21 +08:00
else :
2019-08-29 00:58:18 +08:00
detail_item_box . label ( text = " " , icon = ICONS_PROP_STATES [ item . state ] )
2019-08-22 21:35:21 +08:00
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-22 21:35:21 +08:00
2019-08-28 22:19:32 +08:00
detail_item_box . operator (
" session.remove_prop " , text = " " , icon = " X " ) . property_path = property_uuid
else :
2019-08-29 00:58:18 +08:00
detail_item_box . label ( text = " " , icon = " DECORATE_LOCKED " )
2021-07-22 15:38:01 +08:00
class SESSION_PT_sync ( bpy . types . Panel ) :
bl_idname = " MULTIUSER_SYNC_PT_panel "
bl_label = " Synchronize "
bl_space_type = ' VIEW_3D '
bl_region_type = ' UI '
bl_parent_id = ' MULTIUSER_SETTINGS_PT_panel '
bl_options = { ' DEFAULT_CLOSED ' }
@classmethod
def poll ( cls , context ) :
return session \
and session . state in [ STATE_ACTIVE ]
def draw_header ( self , context ) :
self . layout . label ( text = " " , icon = ' UV_SYNC_SELECT ' )
def draw ( self , context ) :
layout = self . layout
settings = get_preferences ( )
row = layout . row ( )
row = row . grid_flow ( row_major = True , columns = 0 , even_columns = True , even_rows = False , align = True )
row . prop ( settings . sync_flags , " sync_render_settings " , text = " " , icon_only = True , icon = ' SCENE ' )
row . prop ( settings . sync_flags , " sync_during_editmode " , text = " " , icon_only = True , icon = ' EDITMODE_HLT ' )
row . prop ( settings . sync_flags , " sync_active_camera " , text = " " , icon_only = True , icon = ' VIEW_CAMERA ' )
2020-06-16 21:19:38 +08:00
class SESSION_PT_repository ( bpy . types . Panel ) :
2019-06-14 00:09:16 +08:00
bl_idname = " MULTIUSER_PROPERTIES_PT_panel "
2020-06-11 00:43:21 +08:00
bl_label = " Repository "
2019-06-14 00:09:16 +08:00
bl_space_type = ' VIEW_3D '
bl_region_type = ' UI '
2020-04-14 23:22:28 +08:00
bl_parent_id = ' MULTIUSER_SETTINGS_PT_panel '
2021-07-22 15:38:01 +08:00
bl_options = { ' DEFAULT_CLOSED ' }
2019-03-14 00:02:53 +08:00
@classmethod
def poll ( cls , context ) :
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2020-07-24 22:02:19 +08:00
admin = False
if session and hasattr ( session , ' online_users ' ) :
usr = session . online_users . get ( settings . username )
if usr :
admin = usr [ ' admin ' ]
2020-06-11 00:43:21 +08:00
return hasattr ( context . window_manager , ' session ' ) and \
2020-10-02 06:05:33 +08:00
session and \
2021-03-04 21:22:54 +08:00
( session . state == STATE_ACTIVE or \
2021-07-13 00:01:35 +08:00
session . state == STATE_LOBBY and admin ) and \
not settings . sidebar_repository_shown
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
2020-06-11 00:43:21 +08:00
# Filters
2020-09-15 18:31:46 +08:00
settings = get_preferences ( )
2020-06-11 00:43:21 +08:00
runtime_settings = context . window_manager . session
2020-06-16 21:19:38 +08:00
usr = session . online_users . get ( settings . username )
2020-06-16 22:40:00 +08:00
2021-03-04 21:22:54 +08:00
if session . state == STATE_ACTIVE :
2020-12-22 23:04:50 +08:00
if ' SessionBackupTimer ' in registry :
2021-07-22 15:38:01 +08:00
row = layout . row ( )
2020-12-22 23:04:50 +08:00
row . alert = True
row . operator ( ' session.cancel_autosave ' , icon = " CANCEL " )
row . alert = False
2021-07-22 15:38:01 +08:00
# else:
# row.operator('session.save', icon="FILE_TICK")
2020-12-22 23:04:50 +08:00
2021-05-19 21:59:36 +08:00
box = layout . box ( )
row = box . row ( )
2021-07-23 18:51:16 +08:00
row . prop ( runtime_settings , " filter_owned " , text = " Only show owned data blocks " , icon_only = True , icon = " DECORATE_UNLOCKED " )
2021-05-19 21:59:36 +08:00
row = box . row ( )
row . prop ( runtime_settings , " filter_name " , text = " Filter " )
row = box . row ( )
2019-09-19 05:10:36 +08:00
# Properties
2021-06-04 20:02:09 +08:00
owned_nodes = [ k for k , v in session . repository . graph . items ( ) if v . owner == settings . username ]
2019-09-13 23:00:15 +08:00
2021-06-24 20:35:59 +08:00
filtered_node = owned_nodes if runtime_settings . filter_owned else list ( session . repository . graph . keys ( ) )
2019-09-19 05:10:36 +08:00
2021-05-19 21:59:36 +08:00
if runtime_settings . filter_name :
2021-06-24 20:35:59 +08:00
filtered_node = [ n for n in filtered_node if runtime_settings . filter_name . lower ( ) in session . repository . graph . get ( n ) . data . get ( ' name ' ) . lower ( ) ]
2019-08-09 22:47:15 +08:00
2021-05-19 21:59:36 +08:00
if filtered_node :
2019-08-08 23:17:58 +08:00
col = layout . column ( align = True )
2021-05-19 21:59:36 +08:00
for key in filtered_node :
2019-08-23 18:28:57 +08:00
draw_property ( context , col , key )
2019-04-11 20:39:31 +08:00
else :
2021-05-19 21:59:36 +08:00
layout . row ( ) . label ( text = " Empty " )
2019-04-11 20:39:31 +08:00
2021-03-04 21:22:54 +08:00
elif session . state == STATE_LOBBY and usr and usr [ ' admin ' ] :
2021-07-23 18:51:16 +08:00
row = layout . row ( )
2020-06-11 00:43:21 +08:00
row . operator ( " session.init " , icon = ' TOOL_SETTINGS ' , text = " Init " )
else :
2021-07-23 18:51:16 +08:00
row = layout . row ( )
2020-06-17 18:10:16 +08:00
row . label ( text = " Waiting to start " )
2019-02-08 22:44:02 +08:00
2020-10-02 04:55:06 +08:00
class VIEW3D_PT_overlay_session ( bpy . types . Panel ) :
bl_space_type = ' VIEW_3D '
bl_region_type = ' HEADER '
bl_parent_id = ' VIEW3D_PT_overlay '
bl_label = " Multi-user "
@classmethod
def poll ( cls , context ) :
return True
def draw ( self , context ) :
layout = self . layout
settings = context . window_manager . session
2021-06-29 23:10:59 +08:00
pref = get_preferences ( )
2020-10-02 04:55:06 +08:00
layout . active = settings . enable_presence
2021-06-29 23:10:59 +08:00
row = layout . row ( )
2021-07-13 23:14:32 +08:00
row . prop ( settings , " presence_show_selected " , text = " Selected Objects " )
row = layout . row ( align = True )
row . prop ( settings , " presence_show_user " , text = " Users camera " )
row . prop ( settings , " presence_show_mode " , text = " Users mode " )
2020-10-02 04:55:06 +08:00
col = layout . column ( )
2021-07-13 23:14:32 +08:00
if settings . presence_show_mode or settings . presence_show_user :
2021-06-30 21:34:03 +08:00
row = col . column ( )
2021-07-13 23:14:32 +08:00
row . prop ( pref , " presence_text_distance " , expand = True )
row = col . column ( )
row . prop ( settings , " presence_show_far_user " , text = " Users on different scenes " )
2020-10-06 05:38:52 +08:00
col . prop ( settings , " presence_show_session_status " )
2021-06-29 23:10:59 +08:00
if settings . presence_show_session_status :
2021-07-13 23:14:32 +08:00
split = layout . split ( )
text_pos = split . column ( align = True )
text_pos . active = settings . presence_show_session_status
text_pos . prop ( pref , " presence_hud_hpos " , expand = True )
text_pos . prop ( pref , " presence_hud_vpos " , expand = True )
text_scale = split . column ( )
text_scale . active = settings . presence_show_session_status
text_scale . prop ( pref , " presence_hud_scale " , expand = True )
2021-06-30 21:34:03 +08:00
2021-07-21 17:12:17 +08:00
2021-07-19 22:03:12 +08:00
class SESSION_UL_network ( bpy . types . UIList ) :
def draw_item ( self , context , layout , data , item , icon , active_data , active_propname , index , flt_flag ) :
settings = get_preferences ( )
server_name = ' - '
server_status = ' BLANK1 '
server_private = ' BLANK1 '
server_name = item . server_name
split = layout . split ( factor = 0.7 )
2021-07-23 18:51:16 +08:00
if item . is_private :
2021-07-19 22:03:12 +08:00
server_private = ' LOCKED '
split . label ( text = server_name , icon = server_private )
else :
split . label ( text = server_name )
from multi_user import icons
2021-07-21 17:12:17 +08:00
server_status = icons . icons_col [ " server_offline " ]
2021-07-23 18:51:16 +08:00
if item . is_online :
server_status = icons . icons_col [ " server_online " ]
2021-07-19 22:03:12 +08:00
split . label ( icon_value = server_status . icon_id )
2020-06-16 22:40:00 +08:00
2019-02-08 22:44:02 +08:00
classes = (
2020-01-18 01:15:37 +08:00
SESSION_UL_users ,
2021-07-19 22:03:12 +08:00
SESSION_UL_network ,
2019-05-15 20:52:45 +08:00
SESSION_PT_settings ,
2020-06-17 18:10:16 +08:00
SESSION_PT_advanced_settings ,
2019-05-15 20:52:45 +08:00
SESSION_PT_user ,
2021-07-22 15:38:01 +08:00
SESSION_PT_sync ,
2020-06-16 21:19:38 +08:00
SESSION_PT_repository ,
2020-10-02 04:55:06 +08:00
VIEW3D_PT_overlay_session ,
2019-02-08 22:44:02 +08:00
)
register , unregister = bpy . utils . register_classes_factory ( classes )
if __name__ == " __main__ " :
2019-03-14 19:09:33 +08:00
register ( )