forked from aresdevo/animaide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefe.py
191 lines (140 loc) · 6.35 KB
/
prefe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# licence
'''
Copyright (C) 2018 Ares Deveaux
Created by Ares Deveaux
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 <http://www.gnu.org/licenses/>.
'''
import bpy
from . import anim_offset, key_manager, utils, ui
from bpy.props import BoolProperty, EnumProperty
from bpy.types import AddonPreferences, PropertyGroup
key_manager_pref = ''
anim_offset_pref = ''
addon_name = __package__
def add_key_manager_header():
for cls in key_manager.ui.header_classes:
bpy.utils.register_class(cls)
bpy.types.TIME_MT_editor_menus.append(key_manager.ui.draw_key_manager)
bpy.types.DOPESHEET_MT_editor_menus.append(key_manager.ui.draw_key_manager)
bpy.types.GRAPH_MT_editor_menus.append(key_manager.ui.draw_key_manager)
def remove_key_manager_header():
for cls in key_manager.ui.header_classes:
bpy.utils.unregister_class(cls)
bpy.types.TIME_MT_editor_menus.remove(key_manager.ui.draw_key_manager)
bpy.types.DOPESHEET_MT_editor_menus.remove(key_manager.ui.draw_key_manager)
bpy.types.GRAPH_MT_editor_menus.remove(key_manager.ui.draw_key_manager)
def add_key_manager_panel():
for cls in key_manager.ui.panel_classes:
bpy.utils.register_class(cls)
def remove_key_manager_panel():
for cls in key_manager.ui.panel_classes:
bpy.utils.unregister_class(cls)
def add_anim_offset_panel():
for cls in anim_offset.ui.panel_classes:
bpy.utils.register_class(cls)
def remove_anim_offset_panel():
for cls in anim_offset.ui.panel_classes:
bpy.utils.unregister_class(cls)
def add_anim_offset_header():
bpy.types.TIME_MT_editor_menus.append(anim_offset.ui.draw_anim_offset)
bpy.types.DOPESHEET_MT_editor_menus.append(anim_offset.ui.draw_anim_offset_mask)
bpy.types.GRAPH_MT_editor_menus.append(anim_offset.ui.draw_anim_offset_mask)
def remove_anim_offset_header():
bpy.types.TIME_MT_editor_menus.remove(anim_offset.ui.draw_anim_offset)
bpy.types.GRAPH_MT_editor_menus.remove(anim_offset.ui.draw_anim_offset_mask)
bpy.types.DOPESHEET_MT_editor_menus.remove(anim_offset.ui.draw_anim_offset_mask)
class Preferences(AddonPreferences):
bl_idname = addon_name
def key_manager_update(self, context):
global key_manager_pref
if self.key_manager_ui == key_manager_pref:
return
if self.key_manager_ui == 'HEADERS':
remove_key_manager_panel()
remove_anim_offset_header()
add_key_manager_header()
if self.anim_offset_ui == 'HEADERS':
add_anim_offset_header()
key_manager_pref = self.key_manager_ui
elif self.key_manager_ui == 'PANEL':
remove_key_manager_header()
add_key_manager_panel()
key_manager_pref = self.key_manager_ui
def anim_offset_update(self, context):
global anim_offset_pref
if self.anim_offset_ui == anim_offset_pref:
return
if self.anim_offset_ui == 'HEADERS':
remove_anim_offset_panel()
add_anim_offset_header()
anim_offset_pref = self.anim_offset_ui
elif self.anim_offset_ui == 'PANEL':
remove_anim_offset_header()
add_anim_offset_panel()
anim_offset_pref = self.anim_offset_ui
def toggle_tool_markers(self, context):
tool = context.scene.animaide.tool
if self.ct_use_markers:
if tool.left_ref_frame > 0:
utils.add_marker(name='', side='L', frame=tool.left_ref_frame)
if tool.right_ref_frame > 0:
utils.add_marker(name='', side='R', frame=tool.right_ref_frame)
else:
for side in ['L', 'R']:
utils.remove_marker(
side=side)
return
def info_panel_update(self, context):
if self.info_panel:
for cls in ui.info_classes:
bpy.utils.register_class(cls)
else:
for cls in reversed(ui.info_classes):
bpy.utils.unregister_class(cls)
key_manager_ui: EnumProperty(
items=[('PANEL', 'Panel', 'Choose if you want "Key Manager" on a panel', '', 1),
('HEADERS', 'Headers', 'Choose if you want "Key Manager" tools on headers', '', 2)],
name="Kay Manager",
default='PANEL',
update=key_manager_update
)
anim_offset_ui: EnumProperty(
items=[('PANEL', 'Panel', 'Choose if you want "Anim Offset" on a panel', '', 1),
('HEADERS', 'Headers', 'Choose if you want "Anim Offset" tools on headers', '', 2)],
name="Anim Offset",
default='PANEL',
update=anim_offset_update
)
tool_on_release: BoolProperty(default=True,
description='Changes how the tools modal work')
ct_use_markers: BoolProperty(default=True,
description='use markers for the reference frames',
update=toggle_tool_markers)
ao_fast_offset: BoolProperty(default=False)
info_panel: BoolProperty(default=True,
update=info_panel_update)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = True
layout.prop(self, "anim_offset_ui", text="Anim Offset on")
layout.prop(self, "key_manager_ui", text="Key Manager on")
col = layout.column(heading='Curve Tools')
col.prop(self, 'tool_on_release', text='Activate on mouse release', toggle=False)
col.prop(self, 'ct_use_markers', text='Use markers', toggle=False)
col = layout.column(heading='Anim Offset')
col.prop(self, 'ao_fast_offset', text='Fast calculation', toggle=False)
col = layout.column(heading='Info')
col.prop(self, 'info_panel', text='Panel', toggle=False)
classes = (
Preferences,
)