Skip to content

Commit

Permalink
Moved projects panel to a separate scene
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 22, 2023
1 parent d116135 commit dd44b71
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 182 deletions.
6 changes: 3 additions & 3 deletions export_presets.cfg

Large diffs are not rendered by default.

49 changes: 17 additions & 32 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var preview_tesselation_detail : int = 256
@onready var node_library_manager = $NodeLibraryManager
@onready var brush_library_manager = $BrushLibraryManager

@onready var projects = $VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects

@onready var projects_panel = $VBoxContainer/Layout/SplitRight/ProjectsPanel

@onready var layout = $VBoxContainer/Layout
var library
Expand All @@ -33,11 +34,6 @@ var preview_3d
var hierarchy
var brushes

@onready var preview_2d_background = $VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews/Preview2D
@onready var preview_2d_background_button = $VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Preview2DButton
@onready var preview_3d_background = $VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews/Preview3D
@onready var preview_3d_background_button = $VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Preview3DButton
@onready var preview_3d_background_panel = $VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel

var current_mesh : Mesh = null

Expand Down Expand Up @@ -290,10 +286,10 @@ func get_panel(panel_name : String) -> Control:
return layout.get_panel(panel_name)

func get_current_project() -> Control:
return projects.get_current_tab_control()
return projects_panel.get_projects().get_current_tab_control()

func get_current_graph_edit() -> MMGraphEdit:
var graph_edit = projects.get_current_tab_control()
var graph_edit = projects_panel.get_projects().get_current_tab_control()
if graph_edit != null and graph_edit.has_method("get_graph_edit"):
return graph_edit.get_graph_edit()
return null
Expand Down Expand Up @@ -501,8 +497,8 @@ func _on_Create_id_pressed(id) -> void:
func new_graph_panel() -> GraphEdit:
var graph_edit = preload("res://material_maker/panels/graph_edit/graph_edit.tscn").instantiate()
graph_edit.node_factory = $NodeFactory
projects.add_tab(graph_edit)
projects.current_tab = graph_edit.get_index()
projects_panel.get_projects().add_tab(graph_edit)
projects_panel.get_projects().current_tab = graph_edit.get_index()
return graph_edit

func new_material() -> void:
Expand All @@ -525,9 +521,9 @@ func new_paint_project(obj_file_name = null) -> void:

func create_paint_project(mesh, mesh_filename, texture_size, project_filename):
var paint_panel = load("res://material_maker/panels/paint/paint.tscn").instantiate()
projects.add_tab(paint_panel)
projects_panel.get_projects().add_tab(paint_panel)
paint_panel.init_project(mesh, mesh_filename, texture_size, project_filename)
projects.current_tab = paint_panel.get_index()
projects_panel.get_projects().current_tab = paint_panel.get_index()

func load_project() -> void:
if OS.get_name() == "HTML5":
Expand Down Expand Up @@ -615,9 +611,9 @@ func do_load_material_from_data(filename : String, data : String, update_hierarc

func do_load_painting(filename : String) -> bool:
var paint_panel = load("res://material_maker/panels/paint/paint.tscn").instantiate()
projects.add_tab(paint_panel)
projects_panel.get_projects().add_tab(paint_panel)
var status : bool = paint_panel.load_project(filename)
projects.current_tab = paint_panel.get_index()
projects_panel.get_projects().current_tab = paint_panel.get_index()
return status

func load_material_from_website() -> void:
Expand Down Expand Up @@ -646,11 +642,11 @@ func save_project_as(project : Control = null) -> bool:
return false

func save_all_projects() -> void:
for i in range(projects.get_tab_count()):
await projects.get_tab(i).save()
for i in range(projects_panel.get_projects().get_tab_count()):
await projects_panel.get_projects().get_tab(i).save()

func close_project() -> void:
projects.close_tab()
projects_panel.get_projects().close_tab()

func quit() -> void:
if quitting:
Expand Down Expand Up @@ -763,7 +759,7 @@ func edit_select_sources() -> void:

func edit_select_targets_is_disabled() -> bool:
var graph_edit : MMGraphEdit = get_current_graph_edit()
return graph_edit.get_selected_nodes().is_empty()
return graph_edit.get_selected_nodes().is_empty() if graph_edit else true

func edit_select_targets() -> void:
edit_select_connected("from", "to")
Expand Down Expand Up @@ -970,7 +966,7 @@ func about() -> void:

func update_preview() -> void:
update_preview_2d()
update_preview_3d([ preview_3d, preview_3d_background ])
update_preview_3d([ preview_3d, projects_panel.preview_3d_background ])

func get_current_node(graph_edit : MMGraphEdit) -> Node:
for n in graph_edit.get_children():
Expand All @@ -993,7 +989,7 @@ func update_preview_2d() -> void:
previews[i].set_generator(generator, output_index)
if i == 0:
histogram.set_generator(generator, output_index)
preview_2d_background.set_generator(generator, output_index)
projects_panel.preview_2d_background.set_generator(generator, output_index)

var current_gen_material = null
func update_preview_3d(previews : Array, _sequential = false) -> void:
Expand All @@ -1019,7 +1015,7 @@ func _on_Projects_tab_changed(_tab) -> void:
var project = get_current_project()
if project.has_method("project_selected"):
project.call("project_selected")
var new_tab = projects.get_current_tab_control()
var new_tab = projects_panel.get_projects().get_current_tab_control()
if new_tab != current_tab:
# TODO: ???
# for c in get_incoming_connections():
Expand Down Expand Up @@ -1074,17 +1070,6 @@ func dim_window() -> void:
# (it won't respond to user input in this state).
modulate = Color(0.5, 0.5, 0.5)

func show_background_preview_2d(button_pressed):
preview_2d_background.visible = button_pressed
if button_pressed:
preview_3d_background_button.button_pressed = false

func show_background_preview_3d(button_pressed):
preview_3d_background.visible = button_pressed
preview_3d_background_panel.visible = button_pressed
if button_pressed:
preview_2d_background_button.button_pressed = false

func generate_screenshots():
var result = await library.generate_screenshots(get_current_graph_edit())
print(result)
Expand Down
149 changes: 3 additions & 146 deletions material_maker/main_window.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
[gd_scene load_steps=28 format=3 uid="uid://cgfeik04a5qqs"]
[gd_scene load_steps=19 format=3 uid="uid://cgfeik04a5qqs"]

[ext_resource type="Script" path="res://material_maker/main_window.gd" id="1"]
[ext_resource type="Script" path="res://material_maker/main_window_layout.gd" id="2"]
[ext_resource type="PackedScene" uid="uid://bb6iar0tbj2qt" path="res://material_maker/panels/preview_2d/preview_2d.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://dpaxvlnn2u1f6" path="res://material_maker/panels/preview_3d/preview_3d.tscn" id="4"]
[ext_resource type="PackedScene" uid="uid://brlp703awvxbn" path="res://material_maker/panels/preview_3d/preview_3d_ui.tscn" id="5"]
[ext_resource type="Script" path="res://material_maker/widgets/tabs/tabs.gd" id="6"]
[ext_resource type="PackedScene" uid="uid://clw8sb0p8webl" path="res://material_maker/windows/add_node_popup/add_node_popup.tscn" id="7"]
[ext_resource type="PackedScene" uid="uid://bnqq3vhwmudkw" path="res://material_maker/projects_panel.tscn" id="7_ih0ps"]
[ext_resource type="Texture2D" uid="uid://c0j4px4n72di5" path="res://material_maker/icons/icons.tres" id="8"]
[ext_resource type="Script" path="res://material_maker/main_window_projects_panel.gd" id="8_4er2h"]
[ext_resource type="Script" path="res://material_maker/node_factory.gd" id="9"]
[ext_resource type="Theme" uid="uid://3f6cl7v1oyqo" path="res://material_maker/theme/default.tres" id="10"]
[ext_resource type="PackedScene" uid="uid://cp2mbbfmrv6sf" path="res://material_maker/widgets/render_counter/render_counter.tscn" id="11"]
Expand All @@ -18,26 +14,6 @@
[ext_resource type="Script" path="res://material_maker/tools/library_manager/library_manager.gd" id="14"]
[ext_resource type="Texture2D" path="res://material_maker/icons/paste_none.tres" id="15"]

[sub_resource type="Shader" id="1"]
resource_local_to_scene = true

[sub_resource type="ShaderMaterial" id="ShaderMaterial_8fw7q"]
resource_local_to_scene = true
render_priority = 0
shader = SubResource("1")

[sub_resource type="AtlasTexture" id="3"]
atlas = ExtResource("8")
region = Rect2(96, 96, 32, 32)

[sub_resource type="AtlasTexture" id="4"]
atlas = ExtResource("8")
region = Rect2(96, 32, 32, 32)

[sub_resource type="AtlasTexture" id="5"]
atlas = ExtResource("8")
region = Rect2(96, 64, 32, 31)

[sub_resource type="GDScript" id="9"]
script/source = "extends HBoxContainer

Expand Down Expand Up @@ -197,115 +173,7 @@ script = ExtResource("12_7mn0u")
layout_mode = 2
split_offset = 133
[node name="ProjectsPanel" type="Control" parent="VBoxContainer/Layout/SplitRight"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
script = ExtResource("8_4er2h")
[node name="BackgroundPreviews" type="Control" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel"]
anchors_preset = 0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 28.0
[node name="Preview2D" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews" instance=ExtResource("3")]
visible = false
material = SubResource("ShaderMaterial_8fw7q")
layout_mode = 1
offset_right = 0.0
offset_bottom = 0.0
grow_horizontal = 2
grow_vertical = 2
shader = "uniform vec2 preview_2d_size = vec2(100.0, 100.0);
const float preview_2d_scale = 1.2;
const vec2 preview_2d_center = vec2(0.5);

void fragment() {
vec2 ratio = preview_2d_size;
vec2 uv = preview_2d_center+(UV-0.5)*preview_2d_scale*ratio/min(ratio.x, ratio.y);
vec4 image = preview_2d(uv);
float checkerboard = mod(floor(uv.x*32.0)+floor(uv.y*32.0), 2.0);
vec3 image_with_background = mix(vec3(checkerboard), image.xyz, image.a);
COLOR = vec4(image_with_background, 1.0);
}
"
[node name="Preview3D" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews" instance=ExtResource("4")]
visible = false
layout_mode = 1
offset_left = 0.0
offset_top = 0.0
offset_right = 0.0
offset_bottom = 0.0
grow_horizontal = 2
grow_vertical = 2
ui_path = NodePath("../../PreviewUI/Panel/HBoxContainer/Preview3DUI")
[node name="Projects" type="Panel" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel"]
self_modulate = Color(1, 1, 1, 0)
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = 5.0
offset_bottom = 5.0
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("6")
[node name="TabBar" type="TabBar" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects"]
layout_mode = 0
offset_right = 950.0
offset_bottom = 24.0
tab_close_display_policy = 1
[node name="CrashRecoveryTimer" type="Timer" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects"]
wait_time = 15.0
autostart = true
[node name="PreviewUI" type="HBoxContainer" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel"]
layout_mode = 0
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 1.0
offset_top = -45.0
offset_right = 331.0
offset_bottom = -13.0
mouse_filter = 2
[node name="Preview2DButton" type="Button" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI"]
layout_mode = 2
tooltip_text = "Show 2D preview"
toggle_mode = true
icon = SubResource("3")
[node name="Preview3DButton" type="Button" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI"]
layout_mode = 2
tooltip_text = "Show 3D preview"
toggle_mode = true
icon = SubResource("4")
[node name="Panel" type="PanelContainer" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI"]
visible = false
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel"]
layout_mode = 2
[node name="SpaceLeft" type="Control" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel/HBoxContainer"]
layout_mode = 2
[node name="ControlView" type="TextureRect" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel/HBoxContainer"]
layout_mode = 2
size_flags_vertical = 4
texture = SubResource("5")
[node name="Preview3DUI" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel/HBoxContainer" instance=ExtResource("5")]
layout_mode = 2
size_flags_vertical = 4
[node name="SpaceRight" type="Control" parent="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel/HBoxContainer"]
[node name="ProjectsPanel" parent="VBoxContainer/Layout/SplitRight" instance=ExtResource("7_ih0ps")]
layout_mode = 2
[node name="Right" type="VSplitContainer" parent="VBoxContainer/Layout/SplitRight"]
Expand Down Expand Up @@ -401,17 +269,6 @@ libraries = {
[connection signal="tab_changed" from="VBoxContainer/Layout/Left/Top" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="tab_changed" from="VBoxContainer/Layout/Left/Bottom" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="dragged" from="VBoxContainer/Layout/SplitRight" to="VBoxContainer/Layout" method="_on_Right_dragged"]
[connection signal="resized" from="VBoxContainer/Layout/SplitRight/ProjectsPanel" to="VBoxContainer/Layout/SplitRight/ProjectsPanel" method="_on_projects_panel_resized"]
[connection signal="need_update" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews/Preview3D" to="." method="update_preview_3d"]
[connection signal="no_more_tabs" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" to="." method="new_material"]
[connection signal="resized" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" to="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" method="_on_Projects_resized"]
[connection signal="tab_changed" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" to="." method="_on_Projects_tab_changed"]
[connection signal="tab_changed" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects/TabBar" to="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" method="set_current_tab"]
[connection signal="tab_close_pressed" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects/TabBar" to="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" method="close_tab"]
[connection signal="timeout" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects/CrashRecoveryTimer" to="VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects" method="_on_CrashRecoveryTimer_timeout"]
[connection signal="toggled" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Preview2DButton" to="." method="show_background_preview_2d"]
[connection signal="toggled" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Preview3DButton" to="." method="show_background_preview_3d"]
[connection signal="gui_input" from="VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI/Panel/HBoxContainer/ControlView" to="VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews/Preview3D" method="on_gui_input"]
[connection signal="tab_changed" from="VBoxContainer/Layout/SplitRight/Right/Top" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="tab_changed" from="VBoxContainer/Layout/SplitRight/Right/Bottom" to="VBoxContainer/Layout" method="_on_tab_changed"]
[connection signal="timeout" from="VBoxContainer/StatusBar/Tip/Timer" to="." method="_on_Tip_Timer_timeout"]
Expand Down
29 changes: 29 additions & 0 deletions material_maker/main_window_projects_panel.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
extends Control


@onready var projects = $Projects
@onready var preview_2d_background = $BackgroundPreviews/Preview2D
@onready var preview_2d_background_button = $PreviewUI/Preview2DButton
@onready var preview_3d_background = $BackgroundPreviews/Preview3D
@onready var preview_3d_background_button = $PreviewUI/Preview3DButton
@onready var preview_3d_background_panel = $PreviewUI/Panel


func get_projects():
return projects

func _on_projects_panel_resized():
var preview_position : Vector2 = Vector2(0.0, 0.0)
var preview_size : Vector2 = size
preview_position.y += $Projects/TabBar.size.y
preview_size.y -= $Projects/TabBar.size.y
$BackgroundPreviews.position = preview_position
$BackgroundPreviews.size = preview_size

func show_background_preview_2d(button_pressed):
preview_2d_background.visible = button_pressed
if button_pressed:
preview_3d_background_button.button_pressed = false

func show_background_preview_3d(button_pressed):
preview_3d_background.visible = button_pressed
preview_3d_background_panel.visible = button_pressed
if button_pressed:
preview_2d_background_button.button_pressed = false

func _on_projects_no_more_tabs():
mm_globals.main_window.new_material()

func _on_projects_tab_changed(tab : int):
mm_globals.main_window._on_Projects_tab_changed(tab)
Loading

0 comments on commit dd44b71

Please sign in to comment.