Skip to content

Commit 14a462e

Browse files
Cam Lock UI Button, Keymap fixes
1 parent 5ab5079 commit 14a462e

4 files changed

Lines changed: 101 additions & 26 deletions

File tree

__init__.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1-
from .Preferences import RightMouseNavigationPreferences
2-
from .RightMouseNavigation import RMN_OT_right_mouse_navigation
31
import bpy
42

3+
from .operators import (
4+
RMN_OT_right_mouse_navigation,
5+
RMN_OT_toggle_cam_navigation,
6+
)
7+
from .preferences import RightMouseNavigationPreferences
8+
59
addon_keymaps = []
10+
classes = [
11+
RightMouseNavigationPreferences,
12+
RMN_OT_right_mouse_navigation,
13+
RMN_OT_toggle_cam_navigation,
14+
]
615

716

817
def register():
918
if not bpy.app.background:
10-
bpy.utils.register_class(RightMouseNavigationPreferences)
11-
bpy.utils.register_class(RMN_OT_right_mouse_navigation)
19+
for cls in classes:
20+
bpy.utils.register_class(cls)
1221

1322
wm = bpy.context.window_manager
1423
addon_kc = wm.keyconfigs.addon
1524

16-
km = addon_kc.keymaps.new(name="3D View", space_type="VIEW_3D")
17-
kmi = km.keymap_items.new("rmn.right_mouse_navigation", "RIGHTMOUSE", "PRESS")
25+
km = addon_kc.keymaps.new(
26+
name="3D View",
27+
space_type="VIEW_3D",
28+
)
29+
kmi = km.keymap_items.new(
30+
"rmn.right_mouse_navigation",
31+
"RIGHTMOUSE",
32+
"PRESS",
33+
)
1834
kmi.active = True
1935

20-
km2 = addon_kc.keymaps.new(name="Node Editor", space_type="NODE_EDITOR")
21-
kmi2 = km2.keymap_items.new("rmn.right_mouse_navigation", "RIGHTMOUSE", "PRESS")
36+
km2 = addon_kc.keymaps.new(
37+
name="Node Editor",
38+
space_type="NODE_EDITOR",
39+
)
40+
kmi2 = km2.keymap_items.new(
41+
"rmn.right_mouse_navigation",
42+
"RIGHTMOUSE",
43+
"PRESS",
44+
)
2245
kmi2.active = False
2346

2447
addon_keymaps.append((km, kmi))
@@ -36,7 +59,12 @@ def register():
3659
"Font",
3760
"Pose",
3861
]
39-
panelmodes = ["Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"]
62+
panelmodes = [
63+
"Vertex Paint",
64+
"Weight Paint",
65+
"Image Paint",
66+
"Sculpt",
67+
]
4068

4169
# These Modes all call standard menus
4270
# "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
@@ -54,11 +82,7 @@ def register():
5482
# "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
5583
for i in panelmodes:
5684
for key in active_kc.keymaps[i].keymap_items:
57-
if (
58-
key.idname == "wm.call_panel"
59-
and key.type == "RIGHTMOUSE"
60-
and key.active
61-
):
85+
if key.idname == "wm.call_panel" and key.type == "RIGHTMOUSE" and key.active:
6286
key.active = False
6387

6488
# Changing the Walk Modal Map
@@ -73,8 +97,8 @@ def register():
7397

7498
def unregister():
7599
if not bpy.app.background:
76-
bpy.utils.unregister_class(RMN_OT_right_mouse_navigation)
77-
bpy.utils.unregister_class(RightMouseNavigationPreferences)
100+
for cls in classes:
101+
bpy.utils.unregister_class(cls)
78102

79103
wm = bpy.context.window_manager
80104
active_kc = wm.keyconfigs.active
@@ -91,7 +115,12 @@ def unregister():
91115
"Pose",
92116
"Node Editor",
93117
]
94-
panelmodes = ["Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"]
118+
panelmodes = [
119+
"Vertex Paint",
120+
"Weight Paint",
121+
"Image Paint",
122+
"Sculpt",
123+
]
95124

96125
# Reactivating menus
97126
# "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",

blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version = "1.0.0"
22

33
id = "right_mouse_navigation"
4-
version = "2.5.2"
4+
version = "2.6.0"
55
name = "Right Mouse Navigation"
66
tagline = "Game Engine Movement and Menus"
77
maintainer = "Spectral Vectors and Contributors"
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,10 @@ def callMenu(self, context):
102102
if space_type == "NODE_EDITOR":
103103
node_tree = context.space_data.node_tree
104104
if node_tree:
105-
if (
106-
node_tree.nodes.active is not None
107-
and node_tree.nodes.active.select
108-
):
105+
if node_tree.nodes.active is not None and node_tree.nodes.active.select:
109106
bpy.ops.wm.call_menu(name="NODE_MT_context_menu")
110107
else:
111-
bpy.ops.wm.search_single_menu(
112-
"INVOKE_DEFAULT", menu_idname="NODE_MT_add"
113-
)
108+
bpy.ops.wm.search_single_menu("INVOKE_DEFAULT", menu_idname="NODE_MT_add")
114109
else:
115110
try:
116111
bpy.ops.wm.call_menu(name=self.menu_by_mode[context.mode])
@@ -133,11 +128,11 @@ def execute(self, context):
133128
disable_camera = addon_prefs.disable_camera_navigation
134129

135130
space_type = context.space_data.type
136-
view = context.space_data.region_3d.view_perspective
137131

138132
# Execute is the first thing called in our operator, so we start by
139133
# calling Blender's built-in Walk Navigation
140134
if space_type == "VIEW_3D":
135+
view = context.space_data.region_3d.view_perspective
141136
if not (view == "CAMERA" and disable_camera):
142137
try:
143138
bpy.ops.view3d.walk("INVOKE_DEFAULT")
@@ -167,3 +162,17 @@ def execute(self, context):
167162
def cancel(self, context):
168163
wm = context.window_manager
169164
wm.event_timer_remove(self._timer)
165+
166+
167+
class RMN_OT_toggle_cam_navigation(Operator):
168+
"""Turn Mouse Navigation of Camera On and Off"""
169+
170+
bl_idname = "rmn.toggle_cam_navigation"
171+
bl_label = "Toggle Mouse Camera Navigation"
172+
bl_options = {"REGISTER", "UNDO"}
173+
174+
def execute(self, context):
175+
context.preferences.addons[__package__].preferences.disable_camera_navigation = (
176+
not context.preferences.addons[__package__].preferences.disable_camera_navigation
177+
)
178+
return {"FINISHED"}

Preferences.py renamed to preferences.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@
66
from bpy.types import AddonPreferences
77

88

9+
def draw_cam_lock(self, context):
10+
preferences = context.preferences
11+
addon_prefs = preferences.addons[__package__].preferences
12+
cam_nav = addon_prefs.disable_camera_navigation
13+
14+
layout = self.layout
15+
16+
row = layout.row(align=True)
17+
row.alert = cam_nav
18+
col = row.column()
19+
col.scale_x = 1.3
20+
icon = "VIEW_UNLOCKED" if cam_nav else "VIEW_LOCKED"
21+
row.operator(text="", operator="rmn.toggle_cam_navigation", icon=icon)
22+
23+
row = row.row(align=True)
24+
row.label(text="", icon="CAMERA_DATA")
25+
row.label(text="", icon="MOUSE_MOVE")
26+
27+
28+
def cam_lock_update(self, context):
29+
preferences = context.preferences
30+
addon_prefs = preferences.addons[__package__].preferences
31+
32+
if addon_prefs.show_cam_lock_ui:
33+
bpy.types.VIEW3D_HT_tool_header.prepend(draw_cam_lock)
34+
else:
35+
bpy.types.VIEW3D_HT_tool_header.remove(draw_cam_lock)
36+
37+
938
def update_node_keymap(self, context):
1039
wm = context.window_manager
1140
active_kc = wm.keyconfigs.active
@@ -57,6 +86,13 @@ class RightMouseNavigationPreferences(AddonPreferences):
5786
default=False,
5887
)
5988

89+
show_cam_lock_ui: BoolProperty(
90+
name="Show Camera Navigation Lock button",
91+
description="Displays the Camera Navigation Lock button in the 3D Viewport",
92+
default=False,
93+
update=cam_lock_update,
94+
)
95+
6096
def draw(self, context):
6197
layout = self.layout
6298

@@ -80,6 +116,7 @@ def draw(self, context):
80116
box = row.box()
81117
box.label(text="Camera", icon="CAMERA_DATA")
82118
box.prop(self, "disable_camera_navigation")
119+
box.prop(self, "show_cam_lock_ui")
83120

84121
# Keymap Customization
85122
import rna_keymap_ui

0 commit comments

Comments
 (0)