feat: store session widget settings to preferences

This commit is contained in:
Swann 2020-10-22 15:48:13 +02:00
parent 6f364d2b88
commit 92bde00a5a
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
3 changed files with 46 additions and 33 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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")