Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Preview2D Panel UI/UX #707

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
71b8be9
Adjust Add Node panel size and font size
Jowan-Spooner Aug 16, 2024
225c272
Implement better filtering and sorting in library search
Jowan-Spooner Aug 16, 2024
7701d92
Library Panel: Improve scroll to section
Jowan-Spooner Aug 16, 2024
0c694af
Initial Commit of better PreviewPanel menus
Jowan-Spooner Aug 20, 2024
326cac4
Implement new PixelMenuBar and remove old Context Menu
Jowan-Spooner Aug 20, 2024
265af53
Improvements to Pixel Menu Bar
Jowan-Spooner Aug 20, 2024
0c2954e
Implement new splines menu
Jowan-Spooner Aug 20, 2024
72be5d8
Small fixes
Jowan-Spooner Aug 20, 2024
52c7419
Implement new Lattice Menu Bar
Jowan-Spooner Aug 22, 2024
0b6a619
Improve Theming of MenuBar (and VSeparators)
Jowan-Spooner Aug 22, 2024
1a634f7
Try to improve theme once more...
Jowan-Spooner Aug 22, 2024
3ced8af
Improve Export menu
Jowan-Spooner Aug 22, 2024
8b4212d
Small fixes to preview 2D panel scene
Jowan-Spooner Aug 22, 2024
debd7d0
Fix PixelEdit in popup view
Jowan-Spooner Aug 22, 2024
433cff4
Implement Preview Lock Button and new Icons
Jowan-Spooner Sep 4, 2024
c205b70
Small cleanup/fixes
Jowan-Spooner Sep 4, 2024
0d51535
Cleanup + Small fixes
Jowan-Spooner Sep 4, 2024
9381486
Fix merge conflicts
Jowan-Spooner Sep 4, 2024
05f50e1
Fix Lock Icon
Jowan-Spooner Sep 4, 2024
b1f50be
Fix Easy SDF 2D preview UI
Jowan-Spooner Sep 7, 2024
3579926
Fix preview locking
Jowan-Spooner Sep 8, 2024
4f1e115
Only change preview if node has output port
Jowan-Spooner Sep 8, 2024
ac11277
Multiple fixes
Jowan-Spooner Sep 8, 2024
8d9b056
Reintroduce custom grid size
Jowan-Spooner Sep 8, 2024
c928ad6
Reimplement custom export size
Jowan-Spooner Sep 8, 2024
d65318d
Fix view menu size
Jowan-Spooner Sep 8, 2024
1199b6f
Make menu button shortcuts work when buttons are hidden
Jowan-Spooner Sep 15, 2024
434142b
Adjust menu labels for readability
Jowan-Spooner Sep 15, 2024
5627481
Adjust shortcuts
Jowan-Spooner Sep 15, 2024
d83326c
Make SHIFT-selecting a node preview in second preview
Jowan-Spooner Sep 15, 2024
4e1a7c5
Fix shortcut not stopping event propagation
Jowan-Spooner Sep 16, 2024
018a0bd
Improve export browser title
Jowan-Spooner Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/material_maker/engine/nodes/gen_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ func _ready() -> void:

static func get_default_generated_shader() -> ShaderCode:
var rv : ShaderCode = ShaderCode.new()
rv.output_type = "f"
rv.output_type = "rgba"
rv.output_values.f = "0.0"
rv.output_values.rgb = "vec3(0.0)"
rv.output_values.rgba = "vec4(0.0, 0.0, 0.0, 1.0)"
rv.output_values.rgba = "vec4(0.0, 0.0, 0.0, 0.0)"
return rv

func _post_load() -> void:
Expand Down
8 changes: 4 additions & 4 deletions export_presets.cfg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ func update_preview_2d() -> void:
var generator : MMGenBase = null
var output_index : int = -1
if preview == null or not is_instance_valid(preview.generator):
previews[i].clear()
continue
generator = preview.generator
output_index = preview.output_index
Expand Down
8 changes: 4 additions & 4 deletions material_maker/main_window_layout.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ extends HBoxContainer

const PANELS = [
{ name="Library", scene=preload("res://material_maker/panels/library/library.tscn"), position="TopLeft" },
{ name="Preview2D", scene=preload("res://material_maker/panels/preview_2d/preview_2d_panel.tscn"), position="TopRight" },
{ name="Preview2D", scene=preload("res://material_maker/panels/preview_2d/preview_2d_panel.tscn"), position="TopRight" , parameters={preview_mode=1} },
{ name="Preview3D", scene=preload("res://material_maker/panels/preview_3d/preview_3d_panel.tscn"), position="BottomLeft" },
{ name="Preview2D (2)", scene=preload("res://material_maker/panels/preview_2d/preview_2d_panel.tscn"), position="BottomRight", parameters={ config_var_suffix="_2" } },
{ name="Preview2D (2)", scene=preload("res://material_maker/panels/preview_2d/preview_2d_panel.tscn"), position="BottomRight", parameters={preview_mode=2} },
{ name="Histogram", scene=preload("res://material_maker/widgets/histogram/histogram.tscn"), position="BottomRight" },
{ name="Hierarchy", scene=preload("res://material_maker/panels/hierarchy/hierarchy_panel.tscn"), position="TopRight" },
{ name="Reference", scene=preload("res://material_maker/panels/reference/reference_panel.tscn"), position="BottomLeft" },
{ name="Hierarchy", scene=preload("res://material_maker/panels/hierarchy/hierarchy_panel.tscn"), position="TopRight"},
{ name="Reference", scene=preload("res://material_maker/panels/reference/reference_panel.tscn"), position="BottomLeft"},
{ name="Brushes", scene=preload("res://material_maker/panels/brushes/brushes.tscn"), position="TopLeft" },
{ name="Layers", scene=preload("res://material_maker/panels/layers/layers.tscn"), position="BottomRight" },
{ name="Parameters", scene=preload("res://material_maker/panels/parameters/parameters.tscn"), position="TopRight" },
Expand Down
2 changes: 1 addition & 1 deletion material_maker/nodes/generic/generic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func update_node() -> void:

func load_generator() -> void:
var dialog = preload("res://material_maker/windows/file_dialog/file_dialog.tscn").instantiate()
dialog.custom_minimum_size = Vector2(500, 500)
dialog.min_size = Vector2(500, 500)
dialog.access = FileDialog.ACCESS_FILESYSTEM
dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
dialog.add_filter("*.mmg;Material Maker Generator")
Expand Down
82 changes: 82 additions & 0 deletions material_maker/panels/common/menu_bar_button_with_panel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
extends Button

@onready var panel := get_child(0)

var pinned := false
var theme_arrow_icon: Texture2D

func _ready() -> void:
custom_minimum_size = Vector2(35, 25)
toggle_mode = true
button_mask = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT
toggled.connect(_on_toggled)
owner.resized.connect(position_panel)

panel.hide()

theme_arrow_icon = get_theme_icon("arrow", "OptionButton")


func _draw() -> void:
if pinned:
draw_circle(Vector2(size.x-2, 2), 4, get_theme_color("icon_pressed_color"))
draw_texture(theme_arrow_icon, Vector2(18, 5))


func _on_toggled(pressed:bool) -> void:
panel.visible = pressed

if panel.visible:
position_panel()
if panel.has_method("_open"):
panel._open()
else:
pinned = false


func position_panel() -> void:
var at_position := global_position
at_position.x += size.x/2 - panel.size.x/2
at_position.x = max(at_position.x, get_parent().get_child(0).global_position.x)
at_position.y += size.y + 6
panel.global_position = at_position


func _input(event:InputEvent) -> void:
if shortcut_context and shortcut_context.get_global_rect().has_point(get_global_mouse_position()) and event.is_pressed():
propagate_shortcuts(get_child(0), event)

if not panel.visible:
return

if event is InputEventMouseButton:
var node := get_viewport().gui_get_hovered_control()
if node != self and not is_ancestor_of(node) and (not pinned or (node and node.script == self.script)):
button_pressed = false


func propagate_shortcuts(node:Control, event:InputEvent) -> void:
for child in node.get_children():
if not child is Control or child.is_visible_in_tree():
continue
if child is Button:
if child.shortcut and child.shortcut.matches_event(event):
accept_event()
if child.toggle_mode:
child.button_pressed = not child.button_pressed
child.toggled.emit(child.button_pressed)
if child is MM_OptionEdit:
child.roll()
else:
child.pressed.emit()

propagate_shortcuts(child, event)


func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton and not event.pressed:
if event.button_index == MOUSE_BUTTON_RIGHT:
if not pinned and button_pressed:
get_viewport().set_input_as_handled()
pinned = true
grab_focus()
35 changes: 24 additions & 11 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ class_name MMGraphEdit
class Preview:
var generator
var output_index : int
var node : Node

func _init(g, i : int = 0):
func _init(g, i : int = 0, n = null):
generator = g
output_index = i
node = n


# warning-ignore:unused_class_variable
@export var shader_context_defs : String = "" # (String, MULTILINE)

var node_factory = null

var save_path = null: set = set_save_path
var save_path := "": set = set_save_path
var need_save : bool = false
var save_crash_recovery_path = ""
var need_save_crash_recovery : bool = false
Expand Down Expand Up @@ -362,7 +364,7 @@ func update_tab_title() -> void:
#print("no set_tab_title method")
return
var title = "[unnamed]"
if save_path != null:
if not save_path.is_empty():
title = save_path.right(-(save_path.rfind("/")+1))
if need_save:
title += " *"
Expand All @@ -375,7 +377,7 @@ func set_need_save(ns = true) -> void:
update_tab_title()
need_save_crash_recovery = true

func set_save_path(path) -> void:
func set_save_path(path: String) -> void:
if path != save_path:
remove_crash_recovery_file()
need_save_crash_recovery = false
Expand Down Expand Up @@ -483,7 +485,7 @@ func new_material(init_nodes = {nodes=[{name="Material", type="material",paramet
move_child(top_generator, 0)
update_view(top_generator)
center_view()
set_save_path(null)
set_save_path("")
set_need_save(false)

func get_free_name(type) -> String:
Expand Down Expand Up @@ -624,7 +626,7 @@ func save_as() -> bool:
return true
return false

func save_file(filename) -> bool:
func save_file(filename:String) -> bool:
mm_loader.current_project_path = filename.get_base_dir()
var data = top_generator.serialize()
mm_loader.current_project_path = ""
Expand Down Expand Up @@ -863,7 +865,11 @@ func _on_GraphEdit_node_selected(node : GraphNode) -> void:
for n in get_selected_nodes():
if n.generator == current_preview[0].generator:
return
set_current_preview(0, node)
if node.get_output_port_count():
if Input.is_key_pressed(KEY_SHIFT):
set_current_preview(1, node)
else:
set_current_preview(0, node)
undoredo_move_node_selection_changed = true
mm_globals.main_window.update_menus()

Expand All @@ -872,17 +878,19 @@ func _on_GraphEdit_node_unselected(_node):
undoredo_move_node_selection_changed = true
mm_globals.main_window.update_menus()

func get_current_preview(slot : int = 0):

func get_current_preview(slot : int = 0) -> Preview:
if locked_preview[slot] != null:
return locked_preview[slot]
return current_preview[slot]

func set_current_preview(slot : int, node, output_index : int = 0, locked = false) -> void:

func set_current_preview(slot: int, node: GraphNode, output_index: int = 0, locked := false, force_unlock := false) -> void:
var preview = null
var old_preview = null
var old_locked_preview = null
if is_instance_valid(node):
preview = Preview.new(node.generator, output_index)
preview = Preview.new(node.generator, output_index, node)
if locked:
if is_instance_valid(node) and locked_preview[slot] != null and locked_preview[slot].generator != node.generator:
old_locked_preview = locked_preview[slot].generator
Expand All @@ -893,15 +901,20 @@ func set_current_preview(slot : int, node, output_index : int = 0, locked = fals
else:
if is_instance_valid(node) and current_preview[slot] != null and current_preview[slot].generator != node.generator:
old_preview = current_preview[slot].generator
if force_unlock:
locked_preview[slot] = null
current_preview[slot] = preview
emit_signal("preview_changed", self)

preview_changed.emit(self)

if is_instance_valid(node):
node.queue_redraw()
if old_preview != null or old_locked_preview != null:
for c in get_children():
if c is GraphNode and (c.generator == old_preview or c.generator == old_locked_preview):
c.queue_redraw()


func request_popup(node_name : String , slot_index : int, _release_position : Vector2, connect_output : bool) -> void:
# Check if the connector was actually dragged
var node : GraphNode = get_node(node_name)
Expand Down
5 changes: 4 additions & 1 deletion material_maker/panels/library/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ func _on_Section_Button_pressed(category : String) -> void:
if item.get_text(0) == category:
item.select(0)
item.collapsed = false
tree.ensure_cursor_is_visible()
for node in tree.get_children(true):
if node is VScrollBar:
node.value = tree.get_item_area_rect(item).position.y
break
break

func _on_Section_Button_event(event : InputEvent, category : String) -> void:
Expand Down
Loading