From 92bde00a5aad530d4dd7de433d9171f320854f70 Mon Sep 17 00:00:00 2001 From: Swann Date: Thu, 22 Oct 2020 15:48:13 +0200 Subject: [PATCH] feat: store session widget settings to preferences --- multi_user/preferences.py | 59 ++++++++++++++++++++++----------------- multi_user/presence.py | 11 +++++--- multi_user/ui.py | 9 +++--- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/multi_user/preferences.py b/multi_user/preferences.py index ed052e7..6a82870 100644 --- a/multi_user/preferences.py +++ b/multi_user/preferences.py @@ -238,6 +238,31 @@ class SessionPrefs(bpy.types.AddonPreferences): set=set_log_level, get=get_log_level ) + presence_hud_scale: bpy.props.FloatProperty( + name="Text scale", + description="Adjust the session widget text scale", + min=7, + max=90, + default=15, + ) + presence_hud_hpos: bpy.props.FloatProperty( + name="Horizontal position", + description="Adjust the session widget horizontal position", + min=1, + max=90, + default=10, + step=1, + subtype='PERCENTAGE', + ) + presence_hud_vpos: bpy.props.FloatProperty( + name="Vertical position", + description="Adjust the session widget vertical position", + min=1, + max=94, + default=10, + step=1, + subtype='PERCENTAGE', + ) conf_session_identity_expanded: bpy.props.BoolProperty( name="Identity", description="Identity", @@ -412,6 +437,15 @@ class SessionPrefs(bpy.types.AddonPreferences): emboss=False) if self.conf_session_ui_expanded: box.row().prop(self, "panel_category", text="Panel category", expand=True) + row = box.row() + row.label(text="Session widget:") + + col = box.column(align=True) + col.prop(self, "presence_hud_scale", expand=True) + + + col.prop(self, "presence_hud_hpos", expand=True) + col.prop(self, "presence_hud_vpos", expand=True) if self.category == 'UPDATE': from . import addon_updater_ops @@ -502,31 +536,6 @@ class SessionProps(bpy.types.PropertyGroup): description="Show session status on the viewport", default=True, ) - presence_hud_scale: bpy.props.FloatProperty( - name="Text scale", - description="Adjust the session widget text scale", - min=7, - max=90, - default=15, - ) - presence_hud_hpos: bpy.props.FloatProperty( - name="horizontal position", - description="Adjust the session widget horizontal position", - min=1, - max=90, - default=10, - step=1, - subtype='PERCENTAGE', - ) - presence_hud_vpos: bpy.props.FloatProperty( - name="vertical position", - description="Adjust the session widget vertical position", - min=1, - max=94, - default=10, - step=1, - subtype='PERCENTAGE', - ) filter_owned: bpy.props.BoolProperty( name="filter_owned", description='Show only owned datablocks', diff --git a/multi_user/presence.py b/multi_user/presence.py index 9169b24..4776e03 100644 --- a/multi_user/presence.py +++ b/multi_user/presence.py @@ -35,7 +35,7 @@ from replication.constants import (STATE_ACTIVE, STATE_AUTH, STATE_CONFIG, STATE_SYNCING, STATE_WAITING) from replication.interface import session -from .utils import find_from_attr, get_state_str +from .utils import find_from_attr, get_state_str, get_preferences # Helper functions @@ -384,6 +384,9 @@ class UserNameWidget(Widget): class SessionStatusWidget(Widget): draw_type = 'POST_PIXEL' + def __init__(self): + self.preferences = get_preferences() + @property def settings(self): return getattr(bpy.context.window_manager, 'session', None) @@ -393,7 +396,7 @@ class SessionStatusWidget(Widget): self.settings.enable_presence def draw(self): - text_scale = self.settings.presence_hud_scale + text_scale = self.preferences.presence_hud_scale ui_scale = bpy.context.preferences.view.ui_scale color = [1, 1, 0, 1] state = session.state.get('STATE') @@ -403,8 +406,8 @@ class SessionStatusWidget(Widget): color = [0, 1, 0, 1] elif state == STATE_INITIAL: color = [1, 0, 0, 1] - hpos = (self.settings.presence_hud_hpos*bpy.context.area.width)/100 - vpos = (self.settings.presence_hud_vpos*bpy.context.area.height)/100 + hpos = (self.preferences.presence_hud_hpos*bpy.context.area.width)/100 + vpos = (self.preferences.presence_hud_vpos*bpy.context.area.height)/100 blf.position(0, hpos, vpos, 0) blf.size(0, int(text_scale*ui_scale), 72) diff --git a/multi_user/ui.py b/multi_user/ui.py index 99ed909..bf3fbb3 100644 --- a/multi_user/ui.py +++ b/multi_user/ui.py @@ -448,16 +448,17 @@ class SESSION_PT_presence(bpy.types.Panel): layout = self.layout settings = context.window_manager.session + pref = get_preferences() layout.active = settings.enable_presence col = layout.column() col.prop(settings, "presence_show_session_status") row = col.column() row.active = settings.presence_show_session_status - row.prop(settings, "presence_hud_scale", expand=True) + row.prop(pref, "presence_hud_scale", expand=True) row = col.column(align=True) row.active = settings.presence_show_session_status - row.prop(settings, "presence_hud_hpos", expand=True) - row.prop(settings, "presence_hud_vpos", expand=True) + row.prop(pref, "presence_hud_hpos", expand=True) + row.prop(pref, "presence_hud_vpos", expand=True) col.prop(settings, "presence_show_selected") col.prop(settings, "presence_show_user") row = layout.column() @@ -629,7 +630,7 @@ class VIEW3D_PT_overlay_session(bpy.types.Panel): col.prop(settings, "presence_show_session_status") col.prop(settings, "presence_show_selected") col.prop(settings, "presence_show_user") - + row = layout.column() row.active = settings.presence_show_user row.prop(settings, "presence_show_far_user")