Skip to content

Commit 35507a7

Browse files
committed
Added shortcut(R) to toggle horizontal/vertical label for aperture nodes
1 parent b4fcad0 commit 35507a7

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

addons/material_maker/engine/nodes/gen_portal.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var source : MMGenBase.OutputPort
1717

1818
var editable := false
1919
var color : Color = Color.WHITE
20+
var horizontal_label : bool = false
2021

2122
func is_editable() -> bool:
2223
return true
@@ -93,6 +94,7 @@ func _serialize(data : Dictionary) -> Dictionary:
9394
data.io = io
9495
data.port_type = port_type
9596
data.color = MMType.serialize_value(color)
97+
data.horizontal_label = horizontal_label
9698

9799
# remove unused field
98100
data.erase("seed_int")
@@ -105,3 +107,5 @@ func _deserialize(data : Dictionary) -> void:
105107
port_type = data.port_type
106108
if data.has("color"):
107109
color = MMType.deserialize_value(data.color)
110+
if data.has("horizontal_label"):
111+
horizontal_label = data.horizontal_label

material_maker/doc/user_interface_shortcuts.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Graph Editor
7878
+-------------------------------------------------------+----------------------------------------------------+
7979
| :kbd:`F2` | :kbd:`Enter` | :kbd:`LMB` Double-click | Edit selected aperture node |
8080
+-------------------------------------------------------+----------------------------------------------------+
81+
| :kbd:`R` | Toggle aperture node label position |
82+
| | (vertical/horizontal) |
83+
+-------------------------------------------------------+----------------------------------------------------+
8184
| :kbd:`Ctrl/Cmd-G` | Create group from selected nodes |
8285
+-------------------------------------------------------+----------------------------------------------------+
8386
| :kbd:`Alt-S` | Swap inputs on selected node |

material_maker/nodes/portal/portal.gd

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var is_editing := false
99

1010
var syncing_io := false
1111

12+
const label_y_offset : int = 35
13+
1214
func _ready() -> void:
1315
super._ready()
1416
get_titlebar_hbox().get_children().map(func(n): n.hide())
@@ -22,7 +24,6 @@ func update_node() -> void:
2224

2325
func _draw() -> void:
2426
const label_font_size : int = 16
25-
const label_y_offset : int = 40
2627

2728
# in/out arc decoration
2829
var offset : float = PI if is_portal_out() else 0.0
@@ -31,10 +32,16 @@ func _draw() -> void:
3132
# label
3233
var label_pos := size * 0.5
3334
var label_color : Color = generator.color
35+
var label_draw_pos : Vector2 = label_pos
36+
var label_size : Vector2 = LABEL_FONT.get_string_size(
37+
get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
3438

35-
var label_size = LABEL_FONT.get_string_size(get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
36-
var label_draw_pos := label_pos - Vector2(label_size.x * 0.5, label_y_offset)
3739
if not is_editing:
40+
if generator.horizontal_label:
41+
label_draw_pos += Vector2(31.0, 5.0) if is_portal_in() else Vector2(-label_size.x - 31.0, 5.0)
42+
else:
43+
label_draw_pos -= Vector2(label_size.x * 0.5, label_y_offset)
44+
3845
draw_string_outline(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK)
3946
draw_string(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color)
4047

@@ -84,14 +91,16 @@ func _input(event : InputEvent) -> void:
8491
match event.get_keycode_with_modifiers():
8592
KEY_F2, KEY_ENTER:
8693
setup_portal_edit()
94+
KEY_R:
95+
generator.horizontal_label = !generator.horizontal_label
96+
queue_redraw()
8797
elif event is InputEventMouseMotion:
98+
const tip : String = "#LMB: Select node, #LMB#LMB/F2/Enter: Rename link, R: Toggle label position"
8899
if Rect2(Vector2.ZERO, size).has_point(get_local_mouse_position()):
89-
mm_globals.set_tip_text(tr("#LMB: Select node, #LMB#LMB/F2/Enter: Rename link"), 1.0, 2)
100+
mm_globals.set_tip_text(tr(tip), 1.0, 2)
90101
elif %Dragger.get_rect().has_point(get_local_mouse_position()):
91-
if is_editing:
92-
mm_globals.set_tip_text(tr("Enter: Rename link, Ctrl/Cmd+Enter: Batch rename links"), 1.0, 2)
93-
else:
94-
mm_globals.set_tip_text(tr("#LMB: Select node, #LMB#LMB: Rename link"), 1.0, 2)
102+
mm_globals.set_tip_text(
103+
tr("Enter: Rename link, Ctrl/Cmd+Enter: Batch rename links" if is_editing else tip))
95104

96105
func _on_dragger_gui_input(event : InputEvent) -> void:
97106
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
@@ -257,14 +266,23 @@ func replace_links(new_link : String, from_link : String) -> void:
257266
p.on_parameter_changed("link", new_link)
258267

259268
func edit_box_set_position(edit : LineEdit) -> void:
260-
const y_offset : int = 61
269+
var y_offset : int = label_y_offset + 21
261270
var g : MMGraphEdit = get_parent()
262271
if g == null:
263272
edit.queue_free()
264273
return
265274
edit.scale = Vector2.ONE * g.zoom
266275
edit.position = graph_node_center(self, g)
267-
edit.position -= Vector2(edit.size.x * 0.5 - 0.5, y_offset) * g.zoom
276+
277+
if generator.horizontal_label:
278+
if is_portal_in():
279+
edit.alignment = HORIZONTAL_ALIGNMENT_LEFT
280+
edit.position -= Vector2(-21, edit.size.y * 0.5) * g.zoom
281+
else:
282+
edit.alignment = HORIZONTAL_ALIGNMENT_RIGHT
283+
edit.position -= Vector2(edit.size.x + 21, edit.size.y * 0.5) * g.zoom
284+
else:
285+
edit.position -= Vector2(edit.size.x * 0.5 - 0.5, y_offset) * g.zoom
268286

269287
func setup_portal_edit() -> void:
270288
if is_editing:

0 commit comments

Comments
 (0)