Skip to content

Commit

Permalink
Feat: preferences.py add alignment replace_top_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
xmx-emm committed May 31, 2024
1 parent 628b985 commit 666a051
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 31 deletions.
50 changes: 37 additions & 13 deletions ui/replace_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,49 @@ def draw_restart_button(layout):


def append_top_editor_menus(self, context):
pref = PublicClass.pref_()

layout = self.layout
region = context.region
screen = context.screen
right = region.alignment != 'RIGHT'

pref = PublicClass.pref_()
sculpt = pref.sculpt or pref.is_sculpt_mode

if right and sculpt:
# layout.label(text=self.__class__.__name__)
# layout.label(text=region.alignment)
# layout.label(text=pref.alignment)

fs = screen.show_fullscreen
cn = self.__class__.__name__
if pref.alignment == 'LEFT':
show = cn == "TOPBAR_MT_editor_menus" or (
cn == "TOPBAR_HT_upper_bar" and region.alignment == "TOP" and pref.replace_top_bar and pref.sculpt)
elif pref.alignment == 'CENTER':
show = cn == "TOPBAR_HT_upper_bar" and region.alignment == "TOP"
elif pref.alignment == 'RIGHT':
show = cn == "TOPBAR_HT_upper_bar" and region.alignment == "RIGHT"
else:
show = False

sculpt = pref.sculpt or pref.is_sculpt_mode
if show and sculpt:
sub_row = layout.row(align=True)
icon = 'EVENT_ESC' if pref.sculpt else 'SCULPTMODE_HLT'
text = "Bbrush" if pref.show_text else ''
sub_row.prop(pref,
'sculpt',
text=text,
icon=icon)
if not pref.always_use_sculpt_mode:
sub_row.prop(pref,
'sculpt',
text=text,
icon=icon)
if pref.sculpt:
sub_row.prop(pref, 'always_use_sculpt_mode', emboss=True, icon='AUTO', text='')

row = layout.row(align=True)
row.prop(pref, 'depth_display_mode', emboss=True, )
row.prop(pref, 'depth_scale', emboss=True, )
row.prop(pref, 'show_shortcut_keys', emboss=True, icon='EVENT_K', text='')
draw_restart_button(row)
if pref.replace_top_bar:
draw_restart_button(row)

if screen.show_fullscreen and pref.sculpt:
if fs and pref.sculpt and pref.replace_top_bar:
layout.operator(
"screen.back_to_previous",
icon='SCREEN_BACK',
Expand All @@ -70,14 +86,22 @@ def replace_top_bar(replace: bool):

def update_top_bar():
pref = PublicClass.pref_()
replace_top_bar(pref.sculpt)

if pref.replace_top_bar:
show = pref.sculpt
else:
show = False
replace_top_bar(show)


def register():
bpy.types.TOPBAR_MT_editor_menus.append(append_top_editor_menus) # 顶部标题栏
bpy.types.TOPBAR_MT_editor_menus.prepend(append_top_editor_menus)
bpy.types.TOPBAR_HT_upper_bar.append(append_top_editor_menus)


def unregister():
if hasattr(bpy.types, 'TOPBAR_MT_editor_menus'):
bpy.types.TOPBAR_MT_editor_menus.remove(append_top_editor_menus)
if hasattr(bpy.types, 'TOPBAR_HT_upper_bar'):
bpy.types.TOPBAR_HT_upper_bar.remove(append_top_editor_menus)
replace_top_bar(False)
58 changes: 43 additions & 15 deletions utils/preferences.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import bpy
from bpy.app.translations import pgettext as _
from bpy.props import BoolProperty, EnumProperty, FloatProperty, IntProperty
from bpy_types import AddonPreferences
from bpy.app.translations import pgettext as _

from . import key
from .public import ADDON_NAME, PublicClass

Expand Down Expand Up @@ -37,7 +38,8 @@ def sculpt_update(self, context):
default=False)

depth_display_items = (
('ALWAYS_DISPLAY', 'DisplayedAllTheTime', 'Keep the silhouette displayed all the time, even when not in sculpting mode'),
('ALWAYS_DISPLAY', 'DisplayedAllTheTime',
'Keep the silhouette displayed all the time, even when not in sculpting mode'),
('ONLY_SCULPT', 'SculptModeOnly', 'Display silhouette images only in sculpting mode'),
('ONLY_BBRUSH', 'BbrushModeOnly', 'Display silhouette images only in Bbrush mode'),
('NOT_DISPLAY', 'NotShown', 'Never display silhouette images at any time'),
Expand All @@ -61,7 +63,8 @@ def sculpt_update(self, context):

always_use_sculpt_mode: BoolProperty(
name=_('Always use Bbrush sculpting mode'),
description=_('If entering sculpting mode, Bbrush mode will automatically activate; if exiting sculpting mode, Bbrush mode will deactivate'),
description=_(
'If entering sculpting mode, Bbrush mode will automatically activate; if exiting sculpting mode, Bbrush mode will deactivate'),
default=False)

depth_ray_size: IntProperty(
Expand All @@ -81,23 +84,48 @@ def sculpt_update(self, context):
default=20, max=114514, min=0)
shortcut_show_size: FloatProperty(name=_('Shortcut key display size'), min=0.1, default=1, max=114)

def update_top(self, context):
from ..ui.replace_ui import update_top_bar
update_top_bar()

replace_top_bar: BoolProperty(name='Replace top bar', default=True, update=update_top)
alignment: EnumProperty(
items=[
("LEFT", "LIFT", ""),
("CENTER", "CENTER", ""),
("RIGHT", "RIGHT", ""), ],
default="CENTER",
)

def draw(self, context):
layout = self.layout
layout.prop(self, 'show_text')
layout.prop(self, 'depth_display_mode')
layout.prop(self, 'depth_ray_size')
layout.prop(self, 'always_use_sculpt_mode')

layout.label(text='Silhouette:')
layout.prop(self, 'depth_scale')
row = layout.row(align=True)

box = layout.box()
box.prop(self, 'always_use_sculpt_mode')
row = box.row(align=True)
row.prop(self, 'depth_display_mode')
row.prop(self, 'depth_ray_size')
layout.separator()
layout.label(text="顶部栏")
row = layout.box().row(align=True)
row.prop(self, 'show_text')
row.prop(self, 'replace_top_bar')
row.prop(self, 'alignment')

layout.separator()
layout.label(text='Silhouette')
box = layout.box()
box.prop(self, 'depth_scale')
row = box.row(align=True)
row.prop(self, 'depth_offset_x')
row.prop(self, 'depth_offset_y')

layout.label(text=_('shortcut:'))
layout.prop(self, 'show_shortcut_keys')
layout.prop(self, 'shortcut_show_size')
row = layout.row(align=True)
layout.separator()
layout.label(text='Shortcut')
box = layout.box()
box.prop(self, 'show_shortcut_keys')
box.prop(self, 'shortcut_show_size')
row = box.row(align=True)
row.prop(self, 'shortcut_offset_x')
row.prop(self, 'shortcut_offset_y')

Expand Down
8 changes: 5 additions & 3 deletions zh_CN.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
'Display shortcut keys': '显示快捷键',
'Shortcut key offset': '快捷键偏移',
'Shortcut key display size': '快捷键显示大小',
'Silhouette:': '剪影图',
'shortcut:': '快捷键',
'Silhouette': '剪影图',
'Shortcut': '快捷键',
'Setting log file path error': '设置Log文件路径错误',
"Check if the mouse is placed over the model, mouse cursor's range size": '检查鼠标是否放在模型上,鼠标范围大小',
'Control handle for moving the sculpting origin': '用于移动雕刻原点的操作控制柄',
Expand Down Expand Up @@ -70,7 +70,6 @@
'ctrl+shift+left Click in blank area': '在空白处ctrl+shift+左键单击',
'ctrl+shift+left or ctrl+shift+alt+left Drag in blank area': '在空白处ctrl+shift 或 ctrl+shift+alt+左键拖拽',


'mouse_right': '右键',
'middle': '中键',
'left': '左键',
Expand Down Expand Up @@ -111,4 +110,7 @@
'Mask brush': '遮罩笔刷',
'Display top text': '显示顶部文本',
'Depth ray check size(px)': '深度射线检查大小(px)',
'Replace top bar': '替换顶部栏',
'LIFT': '左',
'CENTER': '中',
}

0 comments on commit 666a051

Please sign in to comment.