1209 lines
54 KiB
GDScript
Executable File
1209 lines
54 KiB
GDScript
Executable File
@tool
|
|
class_name PdPanel
|
|
extends VSplitContainer
|
|
## Right panel, split in the middle: HIERARCHY on top, CONTEXTUAL SETTINGS
|
|
## on the bottom. The bottom half only ever shows the extra options for the
|
|
## current mode / selection / tool - never a feature that already lives in
|
|
## the toolbar (grid, snap, gizmo, background are all hotbar-only). Each
|
|
## settings block sits in its own bordered group box. Both the panel width
|
|
## (drag the outer splitter) and the two halves (drag this splitter) are
|
|
## resizable.
|
|
|
|
var doc: PdDocument
|
|
var main: Control
|
|
|
|
var _tree: Tree
|
|
var _props: VBoxContainer
|
|
var _stats: Label
|
|
var _updating := false
|
|
var _refreshers: Array = []
|
|
var _defer_depth := 0 # >0 while a picker popup / spinner drag is live
|
|
var _pending := false
|
|
var _refresh_scheduled := false # a deferred refresh is already queued
|
|
var _user_split := false # user dragged the top/bottom divider
|
|
var _face_pick_before: Array = [] # snapshot captured when the FACE-mode
|
|
# picker opens (lambdas capture locals
|
|
# by value - this must be a member)
|
|
|
|
const PALETTE := PdDocument.PALETTE
|
|
|
|
|
|
## Five animated rating stars at the top of the hierarchy panel. They bob
|
|
## up and down in sequence and light up white-to-yellow one after another;
|
|
## clicking anywhere on them opens the plugin's rating page.
|
|
class PdStars:
|
|
extends Control
|
|
|
|
const STAR_SEGS := 10
|
|
const YELLOW := Color(1.0, 0.83, 0.15)
|
|
|
|
var _t := 0.0
|
|
|
|
func _init() -> void:
|
|
custom_minimum_size = Vector2(84, 18)
|
|
size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
tooltip_text = "Enjoying Polydoodle? Rate it!\nOpens the rating page in your browser"
|
|
focus_mode = Control.FOCUS_NONE
|
|
|
|
func _process(delta: float) -> void:
|
|
if not is_visible_in_tree():
|
|
return
|
|
_t += delta
|
|
queue_redraw()
|
|
|
|
func _star_poly(center: Vector2, outer: float) -> PackedVector2Array:
|
|
var pts := PackedVector2Array()
|
|
pts.resize(STAR_SEGS)
|
|
for i in STAR_SEGS:
|
|
var a := -PI * 0.5 + TAU * i / STAR_SEGS
|
|
var r := outer if i % 2 == 0 else outer * 0.45
|
|
pts[i] = center + Vector2(cos(a), sin(a)) * r
|
|
return pts
|
|
|
|
func _draw() -> void:
|
|
var step := _t * 2.4
|
|
for i in 5:
|
|
# sequential phase: each star peaks a beat after the
|
|
# previous one, bobbing up while it brightens
|
|
var ph := step - i * 0.62
|
|
var wave := 0.5 + 0.5 * sin(ph)
|
|
var lift := -3.2 * wave * wave
|
|
var col := Color(1, 1, 1, 0.30).lerp(YELLOW, wave)
|
|
var c := Vector2(9 + i * 16.5, 9 + lift)
|
|
var poly := _star_poly(c, 7.2)
|
|
var cols := PackedColorArray()
|
|
cols.resize(poly.size())
|
|
cols.fill(col)
|
|
draw_polygon(poly, cols)
|
|
|
|
func _gui_input(event: InputEvent) -> void:
|
|
if event is InputEventMouseButton \
|
|
and event.button_index == MOUSE_BUTTON_LEFT \
|
|
and event.pressed:
|
|
accept_event()
|
|
OS.shell_open(PdDocs.URL_RATE)
|
|
|
|
|
|
func setup(d: PdDocument, m: Control) -> void:
|
|
doc = d
|
|
main = m
|
|
_build()
|
|
doc.doc_changed.connect(_schedule_refresh)
|
|
doc.sel_changed.connect(_schedule_refresh)
|
|
doc.settings_changed.connect(_schedule_refresh)
|
|
|
|
|
|
func _build() -> void:
|
|
add_theme_constant_override("separation", 10)
|
|
var top_box := VBoxContainer.new()
|
|
top_box.custom_minimum_size = Vector2(0, 96)
|
|
top_box.add_theme_constant_override("separation", 4)
|
|
var head_row := HBoxContainer.new()
|
|
head_row.add_theme_constant_override("separation", 6)
|
|
var top_head := Label.new()
|
|
top_head.text = "Hierarchy"
|
|
top_head.add_theme_font_size_override("font_size", 12)
|
|
top_head.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
head_row.add_child(top_head)
|
|
head_row.add_child(PdStars.new())
|
|
top_box.add_child(head_row)
|
|
_tree = Tree.new()
|
|
_tree.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
_tree.columns = 4
|
|
_tree.set_column_title(0, "Name")
|
|
_tree.set_column_title(1, "Verts")
|
|
_tree.set_column_title(2, "")
|
|
_tree.set_column_title(3, "")
|
|
_tree.set_column_titles_visible(true)
|
|
for c in 4:
|
|
_tree.set_column_expand(c, c == 0)
|
|
_tree.set_column_custom_minimum_width(1, 34)
|
|
_tree.set_column_custom_minimum_width(2, 26)
|
|
_tree.set_column_custom_minimum_width(3, 26)
|
|
_tree.hide_root = true
|
|
_tree.allow_reselect = true
|
|
# multi-select: rows mirror the viewport's object multi-selection
|
|
# and ctrl/shift-clicking rows multi-selects objects back - the
|
|
# rebuild already lights up every row in doc.sel_objs
|
|
_tree.select_mode = Tree.SELECT_MULTI
|
|
_tree.add_theme_font_size_override("font_size", 12)
|
|
_tree.item_selected.connect(_on_tree_sel)
|
|
_tree.multi_selected.connect(func(_item: TreeItem, _col: int, _sel: bool):
|
|
_on_tree_sel())
|
|
_tree.item_edited.connect(_on_tree_edited)
|
|
_tree.button_clicked.connect(_on_tree_button)
|
|
top_box.add_child(_tree)
|
|
_stats = Label.new()
|
|
_stats.add_theme_font_size_override("font_size", 11)
|
|
_stats.add_theme_color_override("font_color", Color(1, 1, 1, 0.45))
|
|
top_box.add_child(_stats)
|
|
add_child(top_box)
|
|
|
|
var bottom_scroll := ScrollContainer.new()
|
|
bottom_scroll.custom_minimum_size = Vector2(0, 96)
|
|
bottom_scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
bottom_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
|
_props = VBoxContainer.new()
|
|
_props.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
_props.add_theme_constant_override("separation", 8)
|
|
bottom_scroll.add_child(_props)
|
|
add_child(bottom_scroll)
|
|
|
|
# start with the divider in the middle: hierarchy half, settings half
|
|
resized.connect(_balance_split)
|
|
dragged.connect(func(_off: int):
|
|
_user_split = true
|
|
queue_redraw())
|
|
_balance_split.call_deferred()
|
|
_full_refresh()
|
|
|
|
|
|
## Visible separator between the hierarchy and settings halves, styled
|
|
## like the gaps between the four viewports (dark gap + thin light line
|
|
## with a grabber in the middle) so the panel reads as part of the same
|
|
## layout family.
|
|
func _draw() -> void:
|
|
if size.y < 60.0:
|
|
return
|
|
var y := _divider_y()
|
|
draw_line(Vector2(0, y), Vector2(size.x, y), Color(1, 1, 1, 0.10), 1.0)
|
|
var w := 44.0
|
|
draw_line(Vector2(size.x * 0.5 - w * 0.5, y),
|
|
Vector2(size.x * 0.5 + w * 0.5, y), Color(1, 1, 1, 0.30), 2.0)
|
|
for i in 3:
|
|
var dx := size.x * 0.5 + (i - 1) * 5.0
|
|
draw_circle(Vector2(dx, y), 1.2, Color(1, 1, 1, 0.45))
|
|
|
|
|
|
func _divider_y() -> float:
|
|
if get_child_count() > 0:
|
|
var top := get_child(0) as Control
|
|
if top != null and top.size.y > 0.0:
|
|
return top.size.y + 5.0
|
|
return size.y * 0.5
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
if what == NOTIFICATION_SORT_CHILDREN:
|
|
queue_redraw.call_deferred()
|
|
|
|
|
|
func _balance_split() -> void:
|
|
if _user_split or size.y < 240.0:
|
|
return
|
|
split_offset = clampf(size.y * 0.5 - 24.0, 96.0, size.y - 96.0)
|
|
|
|
|
|
var _pending_guard := false
|
|
|
|
|
|
## Rebuilding the panel while the user is interacting with one of its
|
|
## widgets would kill the widget (e.g. free a ColorPickerButton while its
|
|
## popup window is still tearing down - that hard-crashes the editor).
|
|
## Refreshes are therefore ALWAYS deferred to the next idle frame and
|
|
## coalesced; interactions raise _defer_depth so they wait even longer.
|
|
## A live viewport gesture (paint stroke, drag) ALSO holds refreshes off:
|
|
## emitting doc_changed every drag step would rebuild this whole panel per
|
|
## frame; the gesture end emits one final change and everything catches up.
|
|
func _schedule_refresh() -> void:
|
|
if _defer_depth > 0:
|
|
_pending = true
|
|
return
|
|
if doc != null and doc.gesture_depth > 0:
|
|
_pending = true
|
|
return
|
|
if _refresh_scheduled:
|
|
return
|
|
_refresh_scheduled = true
|
|
_run_refresh.call_deferred()
|
|
|
|
|
|
func _run_refresh() -> void:
|
|
_refresh_scheduled = false
|
|
if _defer_depth > 0:
|
|
_pending = true
|
|
return
|
|
_full_refresh()
|
|
|
|
|
|
func _begin_interact() -> void:
|
|
_defer_depth += 1
|
|
|
|
|
|
func _end_interact() -> void:
|
|
_defer_depth = maxi(0, _defer_depth - 1)
|
|
if _defer_depth == 0 and _pending:
|
|
# extra frame of margin: popup_closed arrives while the
|
|
# popup is still hiding; freeing its owner too early
|
|
# crashes the editor
|
|
_flush_pending.call_deferred()
|
|
|
|
|
|
func _flush_pending() -> void:
|
|
if _defer_depth == 0 and _pending:
|
|
_pending = false
|
|
_full_refresh()
|
|
|
|
|
|
func _full_refresh() -> void:
|
|
_updating = true
|
|
_refreshers = []
|
|
for c in _props.get_children():
|
|
_props.remove_child(c)
|
|
c.queue_free()
|
|
_rebuild_tree()
|
|
_rebuild_props()
|
|
_updating = false
|
|
queue_redraw()
|
|
|
|
|
|
# ----------------------------------------------------------- hierarchy ---
|
|
func _rebuild_tree() -> void:
|
|
_tree.clear()
|
|
var root := _tree.create_item()
|
|
if root == null:
|
|
return
|
|
for i in doc.objects.size():
|
|
var o: PdPolyObj = doc.objects[i]
|
|
var item := _tree.create_item(root)
|
|
if item == null:
|
|
continue
|
|
item.set_text(0, o.obj_name)
|
|
item.set_editable(0, true)
|
|
item.set_metadata(0, i)
|
|
item.set_text(1, str(o.nverts()))
|
|
item.set_selectable(1, false)
|
|
item.set_selectable(2, false)
|
|
item.set_selectable(3, false)
|
|
if not o.is_visible:
|
|
item.set_custom_color(0, Color(1, 1, 1, 0.38))
|
|
elif o.is_locked:
|
|
item.set_custom_color(0, Color(1, 1, 1, 0.62))
|
|
# visibility toggle (eye / crossed-out eye) - the texture
|
|
# must be pre-resized to 16px: Tree.add_button() has no
|
|
# icon-scaling theme knob of its own.
|
|
item.add_button(2, PdIcons.get_icon_sized("eye" if o.is_visible else "eye_off", 16),
|
|
0, false,
|
|
"Visible - click to hide\n(auto-locks the object)" if o.is_visible
|
|
else "Hidden - click to show\n(releases the auto-lock)")
|
|
# lock toggle (padlock)
|
|
item.add_button(3, PdIcons.get_icon_sized("lock" if o.is_locked else "unlock", 16),
|
|
1, false,
|
|
"Locked - click to unlock" if o.is_locked
|
|
else "Unlocked - click to lock\n(blocks picking and editing)")
|
|
if doc.mode == PdDocument.Mode.OBJECT and doc.sel_objs.has(i):
|
|
item.select(0)
|
|
elif i == doc.active_obj and doc.mode != PdDocument.Mode.TEXTURE \
|
|
and doc.mode != PdDocument.Mode.DRAW:
|
|
item.select(0)
|
|
var nv := 0
|
|
var nf := 0
|
|
for o in doc.objects:
|
|
nv += o.nverts()
|
|
nf += o.nfaces()
|
|
_stats.text = "%d object(s) · %d verts · %d faces" % [
|
|
doc.objects.size(), nv, nf]
|
|
|
|
|
|
## Defer the document call out of the Tree's own mouse-selection event:
|
|
## selecting an item emits sel_changed, and rebuilding the tree while Godot
|
|
## is still processing that selection is forbidden ("The tree cannot be
|
|
## cleared during mouse selection events" + null item crash).
|
|
## With SELECT_MULTI, ctrl/shift-clicking rows multi-selects objects (and
|
|
## the rebuild already mirrors every doc.sel_objs row back), so viewport
|
|
## multi-selections now show in the hierarchy too.
|
|
func _on_tree_sel() -> void:
|
|
if _updating:
|
|
return
|
|
var idxs := []
|
|
var it := _tree.get_next_selected(null)
|
|
while it != null:
|
|
idxs.append(int(it.get_metadata(0)))
|
|
it = _tree.get_next_selected(it)
|
|
if idxs.is_empty():
|
|
return
|
|
# active object = the row the user actually clicked last
|
|
# (get_selected), unless a ctrl-click toggle-off deselected it;
|
|
# then the last row still selected
|
|
var active := -1
|
|
var cur := _tree.get_selected()
|
|
if cur != null and cur.is_selected(0):
|
|
active = int(cur.get_metadata(0))
|
|
else:
|
|
active = int(idxs[idxs.size() - 1])
|
|
_apply_tree_sel.call_deferred(idxs, active)
|
|
|
|
|
|
func _apply_tree_sel(idxs: Array, active: int) -> void:
|
|
if doc == null or active < 0:
|
|
return
|
|
# REPLACE the object selection (a plain hierarchy click must not
|
|
# keep stale viewport multi-selections alive), then set the active
|
|
# object LAST so gizmos/mode targets follow the clicked row
|
|
doc.clear_all_sel()
|
|
for i in idxs:
|
|
doc.select_object(int(i), true)
|
|
doc.select_object(active, true)
|
|
|
|
|
|
## Eye / padlock clicks in the hierarchy. Deferred like the selection so
|
|
## the rebuild never happens inside the Tree's own input event.
|
|
func _on_tree_button(item: TreeItem, _col: int, id: int, _mb: int) -> void:
|
|
if _updating or item == null:
|
|
return
|
|
var i: int = item.get_metadata(0)
|
|
if id == 0:
|
|
_toggle_visible.call_deferred(i)
|
|
else:
|
|
_toggle_locked.call_deferred(i)
|
|
|
|
|
|
func _toggle_visible(i: int) -> void:
|
|
var o := doc.obj(i)
|
|
if o != null:
|
|
doc.set_object_visible(i, not o.is_visible)
|
|
|
|
|
|
func _toggle_locked(i: int) -> void:
|
|
var o := doc.obj(i)
|
|
if o != null:
|
|
doc.set_object_locked(i, not o.is_locked)
|
|
|
|
|
|
func _on_tree_edited() -> void:
|
|
if _updating:
|
|
return
|
|
var item := _tree.get_edited()
|
|
if item == null:
|
|
return
|
|
var i: int = item.get_metadata(0)
|
|
var t := item.get_text(0)
|
|
_apply_rename.call_deferred(i, t)
|
|
|
|
|
|
func _apply_rename(i: int, t: String) -> void:
|
|
doc.rename_object(i, t)
|
|
_rebuild_tree()
|
|
|
|
|
|
# ------------------------------------------------------- group widgets ---
|
|
## A CARVED group box: solid color darker than the panel, NO outline, and
|
|
## a darker inner bottom edge so the block reads as recessed into the
|
|
## panel (pressed-in 3D) - the inverse of the toolbar buttons' raised look.
|
|
func _group(title: String) -> VBoxContainer:
|
|
var pc := PanelContainer.new()
|
|
var sb := StyleBoxFlat.new()
|
|
sb.bg_color = Color(0, 0, 0, 0.24)
|
|
sb.border_width_bottom = 2
|
|
sb.border_color = Color(0, 0, 0, 0.52)
|
|
sb.set_corner_radius_all(4)
|
|
sb.content_margin_left = 9
|
|
sb.content_margin_right = 9
|
|
sb.content_margin_top = 7
|
|
sb.content_margin_bottom = 9
|
|
pc.add_theme_stylebox_override("panel", sb)
|
|
pc.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 5)
|
|
pc.add_child(v)
|
|
var t := Label.new()
|
|
t.text = title
|
|
t.add_theme_font_size_override("font_size", 11)
|
|
t.add_theme_color_override("font_color",
|
|
Color(PdDocument.ACCENT.r, PdDocument.ACCENT.g, PdDocument.ACCENT.b, 0.85))
|
|
v.add_child(t)
|
|
_props.add_child(pc)
|
|
return v
|
|
|
|
|
|
func _row(parent: Control) -> HBoxContainer:
|
|
var r := HBoxContainer.new()
|
|
r.add_theme_constant_override("separation", 6)
|
|
parent.add_child(r)
|
|
return r
|
|
|
|
|
|
func _label(parent: Control, text: String) -> Label:
|
|
var l := Label.new()
|
|
l.text = text
|
|
l.add_theme_font_size_override("font_size", 12)
|
|
l.custom_minimum_size = Vector2(56, 0)
|
|
parent.add_child(l)
|
|
return l
|
|
|
|
|
|
func _spinner(v: float, tip := "") -> SpinBox:
|
|
var s := SpinBox.new()
|
|
s.min_value = -100000.0
|
|
s.max_value = 100000.0
|
|
s.step = 0.01
|
|
s.allow_greater = true
|
|
s.allow_lesser = true
|
|
s.value = v
|
|
s.custom_minimum_size = Vector2(58, 0)
|
|
s.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
s.add_theme_font_size_override("font_size", 12)
|
|
if tip != "":
|
|
s.tooltip_text = tip
|
|
# Don't rebuild the panel mid-drag (that would kill the drag).
|
|
# SpinBox has no drag signals in 4.x; while the user drags or
|
|
# types, its internal LineEdit holds focus, so defer until the
|
|
# focus goes away.
|
|
var le := s.get_line_edit()
|
|
# the LineEdit's intrinsic 4-char minimum (~71 px) would force
|
|
# every vec_row to ~350 px and shove the panel off-screen; the
|
|
# SpinBox itself already reserves the right width
|
|
le.add_theme_constant_override("minimum_character_width", 0)
|
|
le.focus_entered.connect(_begin_interact)
|
|
le.focus_exited.connect(_end_interact)
|
|
return s
|
|
|
|
|
|
## Slider + numeric spinner bound to one setting: drag for feel, type for
|
|
## precision. Both stay in sync and route through the same setter.
|
|
func _slider_spin(parent: Control, label: String, getter: Callable,
|
|
setter: Callable, mn: float, mx: float, st: float, tip: String) -> void:
|
|
var r := _row(parent)
|
|
_label(r, label)
|
|
var sl := HSlider.new()
|
|
sl.min_value = mn
|
|
sl.max_value = mx
|
|
sl.step = st
|
|
sl.value = getter.call()
|
|
sl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
sl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
sl.custom_minimum_size = Vector2(56, 16)
|
|
sl.tooltip_text = tip
|
|
# Slider drags need the same protection the SpinBox's LineEdit focus
|
|
# already gives its own drags: value_changed fires on EVERY frame of
|
|
# the drag, notify_doc() schedules a panel rebuild, and a rebuild
|
|
# would destroy the slider under the pressed mouse - the drag dies
|
|
# after one step ("sliders are clickable but not slidable"). Godot
|
|
# 4.7.1 arities (probed): Slider.drag_started() emits 0 args,
|
|
# Slider.drag_ended(value_changed: bool) emits 1 - the callbacks
|
|
# must match or Godot errors on every press.
|
|
sl.drag_started.connect(_begin_interact)
|
|
sl.drag_ended.connect(func(_value_changed: bool): _end_interact())
|
|
var sp := _spinner(getter.call(), tip)
|
|
sp.min_value = mn
|
|
sp.max_value = mx
|
|
sp.step = st
|
|
sp.allow_greater = false
|
|
sp.allow_lesser = false
|
|
sp.custom_minimum_size = Vector2(62, 0)
|
|
# Spinner drags need the same protection: a left press over the
|
|
# SpinBox starts a horizontal value drag whose value_changed storm
|
|
# would otherwise schedule the killing rebuild mid-gesture.
|
|
sp.gui_input.connect(func(ev: InputEvent):
|
|
if ev is InputEventMouseButton \
|
|
and ev.button_index == MOUSE_BUTTON_LEFT:
|
|
if ev.pressed:
|
|
_begin_interact()
|
|
else:
|
|
_end_interact())
|
|
sl.value_changed.connect(func(v: float):
|
|
if _updating:
|
|
return
|
|
_updating = true
|
|
sp.value = v
|
|
_updating = false
|
|
setter.call(v)
|
|
doc.notify_doc())
|
|
sp.value_changed.connect(func(v: float):
|
|
if _updating:
|
|
return
|
|
_updating = true
|
|
sl.value = v
|
|
_updating = false
|
|
setter.call(v)
|
|
doc.notify_doc())
|
|
r.add_child(sl)
|
|
r.add_child(sp)
|
|
_refreshers.append(func():
|
|
if _updating:
|
|
return
|
|
_updating = true
|
|
var v: float = getter.call()
|
|
sl.value = v
|
|
sp.value = v
|
|
_updating = false)
|
|
|
|
|
|
## Color picker whose open popup survives panel refreshes.
|
|
func _color_pick(c: Color, tip: String) -> ColorPickerButton:
|
|
var p := ColorPickerButton.new()
|
|
p.color = c
|
|
p.focus_mode = Control.FOCUS_NONE
|
|
p.tooltip_text = tip
|
|
p.pressed.connect(_begin_interact)
|
|
p.popup_closed.connect(_end_interact)
|
|
return p
|
|
|
|
|
|
# ---------------------------------------------------- tactile buttons ---
|
|
## Same tactile button styling as the toolbar: flat dark idle, solid
|
|
## accent pressed with a darker bottom bevel - clear on/off at a glance.
|
|
func _style(b: Button) -> void:
|
|
var base := StyleBoxFlat.new()
|
|
base.bg_color = Color(1, 1, 1, 0.04)
|
|
base.set_corner_radius_all(4)
|
|
base.content_margin_left = 5
|
|
base.content_margin_right = 5
|
|
base.content_margin_top = 3
|
|
base.content_margin_bottom = 3
|
|
var hover := base.duplicate()
|
|
hover.bg_color = Color(1, 1, 1, 0.10)
|
|
var pressed := base.duplicate()
|
|
pressed.bg_color = PdDocument.ACCENT
|
|
pressed.border_width_bottom = 3
|
|
pressed.border_color = PdDocument.ACCENT_DARK
|
|
pressed.content_margin_top = 4
|
|
pressed.content_margin_bottom = 2
|
|
var hover_pressed := base.duplicate()
|
|
hover_pressed.bg_color = PdDocument.ACCENT.lightened(0.08)
|
|
hover_pressed.border_width_bottom = 3
|
|
hover_pressed.border_color = PdDocument.ACCENT_DARK
|
|
hover_pressed.content_margin_top = 4
|
|
hover_pressed.content_margin_bottom = 2
|
|
b.add_theme_stylebox_override("normal", base)
|
|
b.add_theme_stylebox_override("hover", hover)
|
|
b.add_theme_stylebox_override("pressed", pressed)
|
|
b.add_theme_stylebox_override("hover_pressed", hover_pressed)
|
|
b.add_theme_color_override("icon_pressed_color", Color(1, 1, 1, 1))
|
|
b.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.82))
|
|
b.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 1))
|
|
|
|
|
|
func _vec_row(parent: Control, label: String,
|
|
getter: Callable, setter: Callable) -> void:
|
|
var r := _row(parent)
|
|
_label(r, label)
|
|
for i in 3:
|
|
var cur0: Vector3 = getter.call()
|
|
var s := _spinner([cur0.x, cur0.y, cur0.z][i], "%s %s" % [label, ["X", "Y", "Z"][i]])
|
|
var idx := i
|
|
s.value_changed.connect(func(v: float):
|
|
if _updating:
|
|
return
|
|
var cur: Vector3 = getter.call()
|
|
var arr := [cur.x, cur.y, cur.z]
|
|
arr[idx] = v
|
|
setter.call(Vector3(arr[0], arr[1], arr[2]))
|
|
_sync_spinners())
|
|
r.add_child(s)
|
|
_refreshers.append(func():
|
|
if _updating:
|
|
return
|
|
_updating = true
|
|
var cur: Vector3 = getter.call()
|
|
s.value = [cur.x, cur.y, cur.z][idx]
|
|
_updating = false)
|
|
|
|
|
|
func _sync_spinners() -> void:
|
|
# one spinner changed -> update the rest of the registered ones
|
|
_updating = true
|
|
for f in _refreshers:
|
|
f.call()
|
|
_updating = false
|
|
doc.notify_sel()
|
|
doc.notify_doc()
|
|
|
|
|
|
func _static_row(parent: Control, label: String, value: String) -> void:
|
|
var r := _row(parent)
|
|
_label(r, label)
|
|
var l := Label.new()
|
|
l.text = value
|
|
l.add_theme_font_size_override("font_size", 12)
|
|
l.add_theme_color_override("font_color", Color(1, 1, 1, 0.7))
|
|
r.add_child(l)
|
|
|
|
|
|
func _hint(parent: Control, text: String) -> void:
|
|
var l := Label.new()
|
|
l.text = text
|
|
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
l.add_theme_font_size_override("font_size", 11)
|
|
l.add_theme_color_override("font_color", Color(1, 1, 1, 0.45))
|
|
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
parent.add_child(l)
|
|
|
|
|
|
# ---------------------------------------------------------- properties ---
|
|
## Rebuild the contextual half. Anything already offered by the toolbar
|
|
## (mode buttons, tool dropdowns, snap/grid/gizmo toggles, background
|
|
## color, undo/redo, file ops) is deliberately NOT duplicated here.
|
|
func _rebuild_props() -> void:
|
|
match doc.mode:
|
|
PdDocument.Mode.OBJECT:
|
|
_props_object()
|
|
PdDocument.Mode.VERTEX:
|
|
_props_vertex()
|
|
PdDocument.Mode.EDGE:
|
|
_props_edge()
|
|
PdDocument.Mode.FACE:
|
|
_props_face()
|
|
PdDocument.Mode.DRAW:
|
|
_props_draw()
|
|
PdDocument.Mode.TEXTURE:
|
|
_props_texture()
|
|
|
|
_updating = false
|
|
for f in _refreshers:
|
|
f.call()
|
|
_updating = false
|
|
|
|
|
|
func _props_object() -> void:
|
|
if doc.sel_objs.is_empty():
|
|
var g := _group("Object")
|
|
_hint(g, "Click a shape to select it.\nDrag empty space to box-select. Shift-click to multi-select - a dragged selection moves as one.")
|
|
return
|
|
var g := _group("Object")
|
|
if doc.sel_objs.size() > 1:
|
|
_static_row(g, "Selected", "%d objects" % doc.sel_objs.size())
|
|
var o := doc.obj(doc.active_obj)
|
|
if o == null:
|
|
return
|
|
var name_row := _row(g)
|
|
_label(name_row, "Name")
|
|
var ne := LineEdit.new()
|
|
ne.text = o.obj_name
|
|
ne.add_theme_font_size_override("font_size", 12)
|
|
ne.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
ne.focus_entered.connect(_begin_interact)
|
|
ne.focus_exited.connect(_end_interact)
|
|
ne.text_submitted.connect(func(t: String):
|
|
doc.rename_object(doc.active_obj, t)
|
|
_sync_spinners())
|
|
name_row.add_child(ne)
|
|
_vec_row(g, "Position",
|
|
func(): return doc.obj(doc.active_obj).position if doc.obj(doc.active_obj) else Vector3.ZERO,
|
|
func(v: Vector3): doc.set_object_pos(doc.active_obj, v))
|
|
_vec_row(g, "Scale",
|
|
func(): return doc.obj(doc.active_obj).scale3 if doc.obj(doc.active_obj) else Vector3.ONE,
|
|
func(v: Vector3): doc.set_object_scale(doc.active_obj, v))
|
|
# per-object shading: flat (hard faceted edges) or smooth (averaged
|
|
# vertex normals) - each object carries its own flag
|
|
var shrw := _row(g)
|
|
_label(shrw, "Shading")
|
|
var sgrp := ButtonGroup.new()
|
|
var sflat := Button.new()
|
|
sflat.text = "Flat"
|
|
sflat.toggle_mode = true
|
|
sflat.button_group = sgrp
|
|
sflat.focus_mode = Control.FOCUS_NONE
|
|
sflat.add_theme_font_size_override("font_size", 12)
|
|
sflat.custom_minimum_size = Vector2(0, 26)
|
|
sflat.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
sflat.tooltip_text = "FLAT shading\nEvery face keeps its own hard normal - the classic\nlow-poly faceted look."
|
|
sflat.pressed.connect(func(): doc.set_object_smooth(doc.active_obj, false))
|
|
_style(sflat)
|
|
var ssmooth := Button.new()
|
|
ssmooth.text = "Smooth"
|
|
ssmooth.toggle_mode = true
|
|
ssmooth.button_group = sgrp
|
|
ssmooth.focus_mode = Control.FOCUS_NONE
|
|
ssmooth.add_theme_font_size_override("font_size", 12)
|
|
ssmooth.custom_minimum_size = Vector2(0, 26)
|
|
ssmooth.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
ssmooth.tooltip_text = "SMOOTH shading\nShared corners average their face normals - rounded,\ncontinuous shading (per object, saved with the project)."
|
|
ssmooth.pressed.connect(func(): doc.set_object_smooth(doc.active_obj, true))
|
|
_style(ssmooth)
|
|
sflat.set_pressed_no_signal(not o.shade_smooth)
|
|
ssmooth.set_pressed_no_signal(o.shade_smooth)
|
|
shrw.add_child(sflat)
|
|
shrw.add_child(ssmooth)
|
|
_static_row(g, "Verts", str(o.nverts()))
|
|
_static_row(g, "Faces", str(o.nfaces()))
|
|
|
|
|
|
func _props_vertex() -> void:
|
|
if doc.sel_verts.is_empty():
|
|
var g := _group("Vertices")
|
|
_hint(g, "Click a vertex to select it (Shift for more).\nDrag to move. Drag empty space to box-select.\nDel removes the selection.")
|
|
return
|
|
var g := _group("Vertices")
|
|
_static_row(g, "Count", "%d vertex(es)" % doc.sel_verts.size())
|
|
_vec_row(g, "Center",
|
|
func(): return doc.sel_center_w(),
|
|
func(v: Vector3): _move_sel_to(v))
|
|
_hint(g, "Editing the center moves the whole selection.")
|
|
|
|
|
|
func _props_edge() -> void:
|
|
if doc.sel_edges.is_empty():
|
|
var g := _group("Edges")
|
|
_hint(g, "Click an edge to select it (Shift for more).\nDrag to move the edge. Del removes it.")
|
|
return
|
|
var g := _group("Edges")
|
|
var o := doc.active()
|
|
_static_row(g, "Count", "%d edge(s)" % doc.sel_edges.size())
|
|
if o != null and doc.sel_edges.size() == 1:
|
|
var e: Vector2i = doc.sel_edges[0]
|
|
_static_row(g, "Length",
|
|
"%.3f" % o.wvert(e.x).distance_to(o.wvert(e.y)))
|
|
_vec_row(g, "Center",
|
|
func(): return doc.sel_center_w(),
|
|
func(v: Vector3): _move_sel_to(v))
|
|
|
|
|
|
func _props_face() -> void:
|
|
if doc.sel_faces.is_empty():
|
|
var g := _group("Faces")
|
|
_hint(g, "Click inside a face to select it (Shift for more).\nDrag to move the face. Del removes it.")
|
|
return
|
|
var g := _group("Faces")
|
|
_static_row(g, "Count", "%d face(s)" % doc.sel_faces.size())
|
|
_vec_row(g, "Center",
|
|
func(): return doc.sel_center_w(),
|
|
func(v: Vector3): _move_sel_to(v))
|
|
# color of the selected faces - editable right here
|
|
var cur := Color(1, 1, 1, 0)
|
|
var o := doc.active()
|
|
if o != null:
|
|
for fi in doc.sel_faces:
|
|
if fi < o.nfaces() and o.face_color(fi).a > 0.01:
|
|
cur = o.face_color(fi)
|
|
break
|
|
var crow := _row(g)
|
|
_label(crow, "Color")
|
|
var pick := _color_pick(cur, "Color of the selected faces")
|
|
pick.custom_minimum_size = Vector2(40, 24)
|
|
# live preview while dragging, ONE undo commit when the popup
|
|
# closes (snapshot captured at press = state before the drag).
|
|
# NOTE: the snapshot lives on the INSTANCE - two lambdas capturing
|
|
# the same local variable do not share rebindings in GDScript 2.
|
|
pick.pressed.connect(func(): _face_pick_before = doc.snapshot())
|
|
pick.color_changed.connect(func(c: Color):
|
|
if doc.sel_faces.is_empty():
|
|
return
|
|
doc.paint_faces_live(PackedInt32Array(doc.sel_faces), c))
|
|
pick.popup_closed.connect(func():
|
|
if _face_pick_before.is_empty():
|
|
return
|
|
doc.commit("Edit face color", _face_pick_before)
|
|
_face_pick_before = []
|
|
_sync_spinners())
|
|
crow.add_child(pick)
|
|
_hint(g, "Pick a color to paint the selected face(s).")
|
|
# Inset / Outset depth: used by the right-click menu's Inset/Outset
|
|
# Face(s) actions (Face mode) - each selected face gets a coplanar
|
|
# ring strip plus an inner face, with no duplicate faces.
|
|
_slider_spin(g, "Inset",
|
|
func(): return doc.inset_dist,
|
|
func(v: float): doc.set_inset_dist(v),
|
|
0.05, 4.0, 0.05,
|
|
"INSET / OUTSET DEPTH\nDistance used by the right-click Inset Face(s) /\nOutset Face(s) actions in Face mode. The ring moves\ntoward the face center (inset) or away from it\n(outset) by this many world units.")
|
|
_hint(g, "Right-click in a viewport for Inset / Outset.")
|
|
|
|
|
|
func _props_draw() -> void:
|
|
var g := _group("Draw")
|
|
_hint(g, "Drag in any viewport to sketch - pick the shape from the dropdown on the Draw button. Shift drags a square / circle.")
|
|
|
|
|
|
func _props_texture() -> void:
|
|
# Paint-only controls (palette, brush sizes) belong to the PAINT
|
|
# submode. Edit UV swaps the right panel to its own toolset - the
|
|
# color picker and brush rows make no sense while re-mapping UVs.
|
|
if not doc.tex_edit:
|
|
var pal := _group("Paint color")
|
|
var row := _row(pal)
|
|
var pick := _color_pick(doc.paint_color, "Paint color")
|
|
pick.custom_minimum_size = Vector2(40, 28)
|
|
pick.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
# color_changed streams continuously while the user drags
|
|
# inside the picker popup - only mirror the live color here.
|
|
# The Recent row is updated ONCE on popup_closed, otherwise
|
|
# one drag would fill it with near-identical intermediates.
|
|
pick.color_changed.connect(func(c: Color):
|
|
doc.paint_color = c)
|
|
pick.popup_closed.connect(func():
|
|
doc.remember_color(doc.paint_color)
|
|
doc.settings_changed.emit())
|
|
row.add_child(pick)
|
|
var grid := GridContainer.new()
|
|
grid.columns = 6
|
|
grid.add_theme_constant_override("h_separation", 3)
|
|
grid.add_theme_constant_override("v_separation", 3)
|
|
row.add_child(grid)
|
|
for c in PALETTE:
|
|
var b := Button.new()
|
|
b.custom_minimum_size = Vector2(22, 22)
|
|
b.focus_mode = Control.FOCUS_NONE
|
|
b.tooltip_text = c.to_html(false)
|
|
var col := c
|
|
b.pressed.connect(func():
|
|
doc.paint_color = col
|
|
doc.remember_color(col)
|
|
doc.settings_changed.emit())
|
|
var sb := StyleBoxFlat.new()
|
|
sb.bg_color = c
|
|
sb.set_corner_radius_all(4)
|
|
sb.border_width_bottom = 2
|
|
sb.border_color = c.darkened(0.35) # tactile 3D bottom edge
|
|
b.add_theme_stylebox_override("normal", sb)
|
|
var sbh := StyleBoxFlat.new()
|
|
sbh.bg_color = c.lightened(0.2)
|
|
sbh.set_corner_radius_all(4)
|
|
sbh.border_width_bottom = 2
|
|
sbh.border_color = c.darkened(0.35)
|
|
b.add_theme_stylebox_override("hover", sbh)
|
|
grid.add_child(b)
|
|
if not doc.recent_colors.is_empty():
|
|
var rrow := _row(pal)
|
|
_label(rrow, "Recent")
|
|
var rgrid := HBoxContainer.new()
|
|
rgrid.add_theme_constant_override("separation", 3)
|
|
rrow.add_child(rgrid)
|
|
for c in doc.recent_colors:
|
|
var b := Button.new()
|
|
b.custom_minimum_size = Vector2(20, 20)
|
|
b.focus_mode = Control.FOCUS_NONE
|
|
var col := c
|
|
b.pressed.connect(func():
|
|
doc.paint_color = col
|
|
doc.settings_changed.emit())
|
|
var sb := StyleBoxFlat.new()
|
|
sb.bg_color = c
|
|
sb.set_corner_radius_all(4)
|
|
sb.border_width_bottom = 2
|
|
sb.border_color = c.darkened(0.35)
|
|
b.add_theme_stylebox_override("normal", sb)
|
|
rgrid.add_child(b)
|
|
|
|
# --- TEXTURE settings: resolution + filter mode stay in BOTH
|
|
# submodes (the atlas geometry and its sampling are shared state).
|
|
var tg := _group("Texture")
|
|
var resrow := _row(tg)
|
|
_label(resrow, "Resolution")
|
|
var res := OptionButton.new()
|
|
res.focus_mode = Control.FOCUS_NONE
|
|
res.add_theme_font_size_override("font_size", 12)
|
|
res.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
res.tooltip_text = "Texture atlas resolution (texels per side).\nResamples the paint, keeps the UV mapping, undoable.\n\"Custom...\" shows a size row for any resolution 16-1024."
|
|
for s in PdPolyObj.ATLAS_SIZES:
|
|
res.add_item("%d x %d" % [s, s])
|
|
res.add_item("Custom...")
|
|
var o := doc.active()
|
|
var cur_n := o.atlas_size() if o != null else 256
|
|
var best_i := -1
|
|
for i in PdPolyObj.ATLAS_SIZES.size():
|
|
if int(PdPolyObj.ATLAS_SIZES[i]) == cur_n:
|
|
best_i = i
|
|
res.selected = best_i if best_i >= 0 else PdPolyObj.ATLAS_SIZES.size()
|
|
var custom_box := VBoxContainer.new()
|
|
custom_box.add_theme_constant_override("separation", 2)
|
|
_slider_spin(custom_box, "Size",
|
|
func(): return float(cur_n),
|
|
func(v: float): doc.set_atlas_size_px(int(v)),
|
|
16.0, float(PdPolyObj.ATLAS_MAX), 1.0,
|
|
"Custom atlas resolution in texels per side (16-1024).\nResamples the paint and keeps the UV mapping, undoable.")
|
|
custom_box.visible = best_i < 0
|
|
res.item_selected.connect(func(idx: int):
|
|
if idx < PdPolyObj.ATLAS_SIZES.size():
|
|
custom_box.visible = false
|
|
doc.set_atlas_size_px(int(PdPolyObj.ATLAS_SIZES[idx]))
|
|
else:
|
|
# show the manual size row (the Custom... picker
|
|
# entry); the canvas resamples exactly like a preset
|
|
custom_box.visible = true)
|
|
resrow.add_child(res)
|
|
tg.add_child(custom_box)
|
|
|
|
var frow := _row(tg)
|
|
_label(frow, "Filter")
|
|
var fgrp := ButtonGroup.new()
|
|
var fsmooth := Button.new()
|
|
fsmooth.text = "Smooth"
|
|
fsmooth.toggle_mode = true
|
|
fsmooth.button_group = fgrp
|
|
fsmooth.focus_mode = Control.FOCUS_NONE
|
|
fsmooth.add_theme_font_size_override("font_size", 12)
|
|
fsmooth.custom_minimum_size = Vector2(0, 26)
|
|
fsmooth.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
fsmooth.tooltip_text = "SMOOTH mode\nThe texture is filtered (linear): soft look on the model and in\nthe editor. Best with the normal Brush."
|
|
fsmooth.pressed.connect(func(): doc.set_tex_filter(0))
|
|
_style(fsmooth)
|
|
var fpixel := Button.new()
|
|
fpixel.text = "Pixel"
|
|
fpixel.toggle_mode = true
|
|
fpixel.button_group = fgrp
|
|
fpixel.focus_mode = Control.FOCUS_NONE
|
|
fpixel.add_theme_font_size_override("font_size", 12)
|
|
fpixel.custom_minimum_size = Vector2(0, 26)
|
|
fpixel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
fpixel.tooltip_text = "PIXEL mode\nNo filter anywhere: crisp texels on the model AND in the editor.\nBest with the texel-perfect Pixel brush."
|
|
fpixel.pressed.connect(func(): doc.set_tex_filter(1))
|
|
_style(fpixel)
|
|
fsmooth.set_pressed_no_signal(doc.tex_filter == 0)
|
|
fpixel.set_pressed_no_signal(doc.tex_filter == 1)
|
|
frow.add_child(fsmooth)
|
|
frow.add_child(fpixel)
|
|
|
|
if not doc.tex_edit:
|
|
_slider_spin(tg, "Brush size",
|
|
func(): return doc.brush_size,
|
|
func(v: float): doc.set_brush_size(v),
|
|
0.05, 4.0, 0.05,
|
|
"Brush radius in world units")
|
|
# opacity + edge smoothness, shared by the Brush AND the
|
|
# Eraser tool (the eraser restores the checker with the same
|
|
# strength and falloff).
|
|
if doc.paint_tool == "Brush" or doc.paint_tool == "Eraser":
|
|
_slider_spin(tg, "Opacity",
|
|
func(): return doc.brush_opacity,
|
|
func(v: float): doc.set_brush_opacity(v),
|
|
0.02, 1.0, 0.02,
|
|
"Stamp strength: 100% = solid paint, lower = see-through\n(builds up along the stroke). Shared by the Eraser.")
|
|
_slider_spin(tg, "Edge smoothness",
|
|
func(): return doc.brush_smooth,
|
|
func(v: float): doc.set_brush_smooth(v),
|
|
0.0, 1.0, 0.02,
|
|
"Airbrush falloff: 0 = hard circle edge, 1 = fully\nsoft airbrush spray. Shared by the Eraser.")
|
|
# FACE LOCK - paint (or erase) stays inside the face the
|
|
# stroke started on; its edges still get fully covered by the
|
|
# same bleed margin the Fill tool uses, but no other face is
|
|
# touched.
|
|
if doc.paint_tool == "Brush" or doc.paint_tool == "Eraser" \
|
|
or doc.paint_tool == "Pixel":
|
|
var lockrow := _row(tg)
|
|
var lockbtn := Button.new()
|
|
lockbtn.text = "Face lock"
|
|
lockbtn.icon = PdIcons.get_icon("lock")
|
|
lockbtn.toggle_mode = true
|
|
lockbtn.button_pressed = doc.face_lock
|
|
lockbtn.focus_mode = Control.FOCUS_NONE
|
|
lockbtn.add_theme_font_size_override("font_size", 12)
|
|
lockbtn.custom_minimum_size = Vector2(0, 26)
|
|
lockbtn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
lockbtn.tooltip_text = "FACE LOCK\nPaint stays inside the face the stroke started on (in the\n2D canvas AND on the 3D model). The face's own edges still get\nfully covered, but no other face - or empty canvas - is touched.\nWorks for the Brush, Eraser and Pixel tools."
|
|
lockbtn.pressed.connect(func(): doc.set_face_lock(lockbtn.button_pressed))
|
|
_style(lockbtn)
|
|
lockrow.add_child(lockbtn)
|
|
_slider_spin(tg, "Pixel size",
|
|
func(): return float(doc.pixel_px),
|
|
func(v: float): doc.set_pixel_px(v),
|
|
1.0, 64.0, 1.0,
|
|
"Pixel brush size in ATLAS TEXELS (texel-perfect: 1 = one texel)")
|
|
# REPLACE tool match radius
|
|
if doc.paint_tool == "Replace":
|
|
_slider_spin(tg, "Tolerance",
|
|
func(): return doc.replace_tolerance,
|
|
func(v: float): doc.set_replace_tolerance(v),
|
|
0.0, 1.0, 0.01,
|
|
"How wide a color match the Replace tool accepts:\n0% replaces only the exact color, higher values also replace\nnearby shades. Replace acts on the WHOLE canvas (all faces).")
|
|
|
|
# Tool details moved to the Docs window (book button in the
|
|
# toolbar) - the panel only shows controls, no reading material.
|
|
if doc.tex_edit:
|
|
_uv_edit_group()
|
|
|
|
|
|
## The Edit-UV right-panel toolset: element mode (what clicks and box
|
|
## selects grab), snapping, the island actions and the Rotate / Scale
|
|
## precise sliders.
|
|
func _uv_edit_group() -> void:
|
|
var ug := _group("Edit UV")
|
|
# element mode: what a click / box select grabs
|
|
var mrow := _row(ug)
|
|
_label(mrow, "Select")
|
|
var mgrp := ButtonGroup.new()
|
|
for m in [["Vertex", "vertex"], ["Edge", "edge"], ["Face", "face"]]:
|
|
var mb := Button.new()
|
|
mb.text = m[0]
|
|
mb.toggle_mode = true
|
|
mb.button_group = mgrp
|
|
mb.focus_mode = Control.FOCUS_NONE
|
|
mb.add_theme_font_size_override("font_size", 12)
|
|
mb.custom_minimum_size = Vector2(0, 26)
|
|
mb.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
mb.tooltip_text = "%s mode\nClicks and the rectangular selection work on UV %ss.\nCtrl or Shift+click adds to the selection, a plain click\nreplaces it, an empty click clears it." % [m[0], m[0].to_lower()]
|
|
mb.pressed.connect(func(): doc.set_uv_elem_mode(m[1]))
|
|
_style(mb)
|
|
mb.set_pressed_no_signal(doc.uv_elem_mode == m[1])
|
|
mrow.add_child(mb)
|
|
# snapping toggle (same state the toolbar button drives)
|
|
var snaprow := _row(ug)
|
|
var snapb := Button.new()
|
|
snapb.text = "Snap to texels"
|
|
snapb.icon = PdIcons.get_icon("snap")
|
|
snapb.toggle_mode = true
|
|
snapb.button_pressed = doc.uv_snap
|
|
snapb.focus_mode = Control.FOCUS_NONE
|
|
snapb.add_theme_font_size_override("font_size", 12)
|
|
snapb.custom_minimum_size = Vector2(0, 26)
|
|
snapb.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
snapb.tooltip_text = "UV snapping (texel grid)\nUV drags land on whole texels. Hold Ctrl to drag freely."
|
|
snapb.pressed.connect(func(): doc.set_uv_snap(snapb.button_pressed))
|
|
_style(snapb)
|
|
snaprow.add_child(snapb)
|
|
var rrow := _row(ug)
|
|
var ru := Button.new()
|
|
ru.text = "Reset UVs"
|
|
ru.focus_mode = Control.FOCUS_NONE
|
|
ru.tooltip_text = "Re-unwrap every face to its planar projection"
|
|
ru.pressed.connect(func(): doc.uv_reset_object(doc.active_obj))
|
|
rrow.add_child(ru)
|
|
var dt := Button.new()
|
|
dt.text = "Detach Selected"
|
|
dt.focus_mode = Control.FOCUS_NONE
|
|
dt.tooltip_text = "Move the selected faces' islands to free texture space so they can be moved individually"
|
|
dt.pressed.connect(func(): doc.uv_detach_selected(doc.active_obj))
|
|
rrow.add_child(dt)
|
|
var rp := Button.new()
|
|
rp.text = "Reset Paint"
|
|
rp.focus_mode = Control.FOCUS_NONE
|
|
rp.tooltip_text = "Clear all paint of this object - the texture slot becomes empty again"
|
|
rp.pressed.connect(func(): doc.tex_clear_object(doc.active_obj))
|
|
rrow.add_child(rp)
|
|
# UV transform tools: the toolbar toggles the tool, this
|
|
# row is its precise control (select faces first)
|
|
if doc.uv_tool == "rotate":
|
|
_uv_transform_slider(ug, "Angle", "rotate",
|
|
"Rotate UVs", 0.0, 360.0, 1.0,
|
|
"Rotate the selected faces' UVs around their center.\nThe angle is ABSOLUTE: 0 = the position the face had when\nthe rotation started, 360 = one full turn. Drag the slider\nor type a number. One undo step per drag / typed value.")
|
|
elif doc.uv_tool == "scale":
|
|
_uv_transform_slider(ug, "Scale %", "scale",
|
|
"Scale UVs", 10.0, 400.0, 1.0,
|
|
"Scale the selected faces' UVs around their\ncenter. Uniform only - the aspect ratio never\nchanges. Drag the slider, type a percent, or drag\na corner handle in the canvas.")
|
|
|
|
|
|
## The Rotate / Scale control row. ROTATE is ABSOLUTE and PERSISTENT: the
|
|
## widgets show the doc's uv_rot_total, dragging or typing sets the face's
|
|
## total rotation for the current chain (0 = default position, 360 = one
|
|
## full turn) and the value STAYS after release instead of snapping back to
|
|
## zero. SCALE keeps the relative gesture semantics (100% = no scale for
|
|
## this gesture). Dragging opens a UV gesture - light live deltas, ONE undo
|
|
## commit on release. Typed values run the same gesture per change.
|
|
func _uv_transform_slider(parent: Control, label: String, tool: String,
|
|
undo_label: String, mn: float, mx: float, st: float,
|
|
tip: String) -> void:
|
|
var r := _row(parent)
|
|
_label(r, label)
|
|
var absolute := tool == "rotate"
|
|
var neutral := 0.0 if tool == "rotate" else 100.0
|
|
var applied := doc.uv_rot_total if absolute else neutral
|
|
var dragging := {"on": false}
|
|
var typed_open := {"on": false}
|
|
var sl := HSlider.new()
|
|
sl.min_value = mn
|
|
sl.max_value = mx
|
|
sl.step = st
|
|
sl.value = doc.uv_rot_total if absolute else neutral
|
|
sl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
sl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
sl.custom_minimum_size = Vector2(56, 16)
|
|
sl.tooltip_text = tip
|
|
var sp := _spinner(doc.uv_rot_total if absolute else neutral, tip)
|
|
sp.min_value = mn
|
|
sp.max_value = mx
|
|
sp.step = st
|
|
sp.allow_greater = false
|
|
sp.allow_lesser = false
|
|
sp.custom_minimum_size = Vector2(62, 0)
|
|
var set_widgets := func(v: float):
|
|
_updating = true
|
|
sl.value = v
|
|
sp.value = v
|
|
_updating = false
|
|
# close a typed gesture: one undo commit for the whole typed run.
|
|
# Rotate keeps its absolute value visible; scale re-arms at 100%.
|
|
var close_typed := func():
|
|
if not typed_open["on"]:
|
|
return
|
|
typed_open["on"] = false
|
|
if doc.uv_gesture_active():
|
|
doc.uv_gesture_end(undo_label)
|
|
applied = doc.uv_rot_total if absolute else neutral
|
|
set_widgets.call(applied)
|
|
var apply_value := func(v: float):
|
|
if _updating:
|
|
return
|
|
if absf(v - applied) < 0.0001:
|
|
return
|
|
if tool == "scale" and applied <= 0.0:
|
|
return
|
|
if not doc.uv_gesture_active():
|
|
if not doc.uv_gesture_begin(doc.active_obj):
|
|
doc.say("Select the faces to %s first"
|
|
% ("rotate" if tool == "rotate" else "scale"))
|
|
set_widgets.call(applied)
|
|
applied = doc.uv_rot_total if absolute else neutral
|
|
return
|
|
if absolute:
|
|
doc.apply_uv_rotation_abs(v)
|
|
elif tool == "rotate":
|
|
doc.apply_uv_rotation(v - applied)
|
|
else:
|
|
doc.apply_uv_scale(v / applied)
|
|
applied = v if not absolute else doc.uv_rot_total
|
|
if not dragging["on"]:
|
|
var le_focused: bool = sp.get_line_edit().has_focus()
|
|
if le_focused:
|
|
# keep ONE gesture open while typing - "4"
|
|
# then "45" lands on 45 degrees total
|
|
typed_open["on"] = true
|
|
else:
|
|
# arrows / programmatic: commit per change
|
|
# (UndoRedo merges the consecutive steps)
|
|
doc.uv_gesture_end(undo_label)
|
|
applied = doc.uv_rot_total if absolute else neutral
|
|
if not absolute:
|
|
set_widgets.call(neutral)
|
|
sl.drag_started.connect(func():
|
|
_begin_interact()
|
|
dragging["on"] = true
|
|
if not doc.uv_gesture_active():
|
|
doc.uv_gesture_begin(doc.active_obj))
|
|
sl.drag_ended.connect(func(_value_changed: bool):
|
|
dragging["on"] = false
|
|
if doc.uv_gesture_active():
|
|
doc.uv_gesture_end(undo_label)
|
|
_end_interact()
|
|
# rotate: the value STAYS (it is the face's real angle);
|
|
# scale re-arms at 100% for the next gesture
|
|
applied = doc.uv_rot_total if absolute else neutral
|
|
if not absolute:
|
|
set_widgets.call(neutral))
|
|
sl.value_changed.connect(func(v: float):
|
|
_updating = true
|
|
sp.value = v
|
|
_updating = false
|
|
apply_value.call(v))
|
|
sp.value_changed.connect(func(v: float):
|
|
_updating = true
|
|
sl.value = v
|
|
_updating = false
|
|
apply_value.call(v))
|
|
sp.get_line_edit().text_submitted.connect(func(_text: String):
|
|
close_typed.call())
|
|
sp.get_line_edit().focus_exited.connect(func():
|
|
close_typed.call())
|
|
r.add_child(sl)
|
|
r.add_child(sp)
|
|
|
|
|
|
## Move the whole current element selection so its center lands at `to`.
|
|
func _move_sel_to(to: Vector3) -> void:
|
|
var o := doc.active()
|
|
if o == null:
|
|
return
|
|
var from := doc.sel_center_w()
|
|
if from == Vector3.INF:
|
|
return
|
|
var delta := to - from
|
|
var affected := doc.affected_verts()
|
|
var targets := {}
|
|
for oi in affected:
|
|
var oo := doc.obj(oi)
|
|
if oo == null:
|
|
continue
|
|
for vi in affected[oi]:
|
|
targets[vi] = oo.wvert(vi) + delta
|
|
doc.move_element_targets(doc.active_obj, targets, "Edit position")
|
|
_sync_spinners()
|