Skip to content

Commit

Permalink
Started integrating flexible layout
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 23, 2023
1 parent dd44b71 commit 9c3785b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 78 deletions.
20 changes: 20 additions & 0 deletions addons/flexible_layout/flexible_layout.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class FlexNode:
if what == NOTIFICATION_PREDELETE:
print("removing %s!" % type)

func serialize() -> Dictionary:
var rv : Dictionary = { type=type, w=rect.size.x, h=rect.size.y, children=[] }
for c in get_children():
rv.children.append(c.serialize())
return rv

func get_children() -> Array[FlexNode]:
return []

Expand Down Expand Up @@ -100,6 +106,11 @@ class FlexSplit:
super._init(p, fl)
type = "FlexSplit"

func serialize() -> Dictionary:
var rv : Dictionary = super.serialize()
rv.dir = "v" if vertical else "h"
return rv

func get_children() -> Array[FlexNode]:
return children

Expand Down Expand Up @@ -214,6 +225,14 @@ class FlexTab:
flexible_layout.add_child(tabs)
tabs.set_flex_tab(self)

func serialize() -> Dictionary:
var rv : Dictionary = super.serialize()
rv.tabs = []
for t in children:
rv.tabs.append(t.name)
rv.current = tabs.current
return rv

func add(fp : FlexPanel):
children.push_back(fp)
tabs.add(fp)
Expand Down Expand Up @@ -403,3 +422,4 @@ func move_panel(panel, reference_panel : FlexNode, destination):
panel.flex_node.remove(panel.flex_panel)
tab.add(panel.flex_panel)
layout()
print(top.serialize())
4 changes: 4 additions & 0 deletions addons/flexible_layout/flexible_tab.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ text = "Blah"
[node name="Undock" type="TextureButton" parent="Container"]
visible = false
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture_normal = SubResource("PlaceholderTexture2D_b47q6")

[node name="Close" type="TextureButton" parent="Container"]
visible = false
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture_normal = SubResource("PlaceholderTexture2D_bok24")
6 changes: 3 additions & 3 deletions export_presets.cfg

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var preview_tesselation_detail : int = 256
@onready var brush_library_manager = $BrushLibraryManager


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

@onready var layout = $VBoxContainer/Layout
var library
Expand Down Expand Up @@ -658,7 +658,7 @@ func quit() -> void:
quitting = false
return
if mm_globals.get_config("confirm_close_project"):
var result = await $VBoxContainer/Layout/SplitRight/ProjectsPanel/Projects.check_save_tabs()
var result = await $VBoxContainer/Layout/FlexibleLayout/Main/Projects.check_save_tabs()
if !result:
quitting = false
return
Expand Down Expand Up @@ -1024,16 +1024,16 @@ func _on_Projects_tab_changed(_tab) -> void:
var new_graph_edit = null
if new_tab is GraphEdit:
new_graph_edit = new_tab
$VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews.show()
$VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI.show()
$VBoxContainer/Layout/FlexibleLayout/Main/BackgroundPreviews.show()
$VBoxContainer/Layout/FlexibleLayout/Main/PreviewUI.show()
set_current_mode("material")
if current_mesh and new_graph_edit.top_generator:
new_graph_edit.top_generator.set_current_mesh(current_mesh)
else:
if new_tab.has_method("get_graph_edit"):
new_graph_edit = new_tab.get_graph_edit()
$VBoxContainer/Layout/SplitRight/ProjectsPanel/BackgroundPreviews.hide()
$VBoxContainer/Layout/SplitRight/ProjectsPanel/PreviewUI.hide()
$VBoxContainer/Layout/FlexibleLayout/Main/BackgroundPreviews.hide()
$VBoxContainer/Layout/FlexibleLayout/Main/PreviewUI.hide()
set_current_mode("paint")
current_tab = new_tab
if new_graph_edit != null:
Expand Down
61 changes: 9 additions & 52 deletions material_maker/main_window.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

[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://eiq3i53x72m2" path="res://addons/flexible_layout/flexible_layout.tscn" id="6_ygla4"]
[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/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"]
[ext_resource type="PackedScene" uid="uid://dnttargjmhjh8" path="res://material_maker/tools/share/share_button.tscn" id="12"]
[ext_resource type="Script" path="res://material_maker/panel_container.gd" id="12_7mn0u"]
[ext_resource type="PackedScene" uid="uid://dmyq6xxfx88m0" path="res://material_maker/tools/environment_manager/environment_manager.tscn" id="13"]
[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"]
Expand Down Expand Up @@ -143,58 +143,22 @@ layout_mode = 2
layout_mode = 2
size_flags_horizontal = 3
[node name="Layout" type="HSplitContainer" parent="VBoxContainer"]
[node name="Layout" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
split_offset = -1118
script = ExtResource("2")
[node name="Left" type="VSplitContainer" parent="VBoxContainer/Layout"]
[node name="FlexibleLayout" parent="VBoxContainer/Layout" instance=ExtResource("6_ygla4")]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
split_offset = 312
[node name="Top" type="TabContainer" parent="VBoxContainer/Layout/Left"]
layout_mode = 2
drag_to_rearrange_enabled = true
tabs_rearrange_group = 0
use_hidden_tabs_for_min_size = true
script = ExtResource("12_7mn0u")
[node name="Bottom" type="TabContainer" parent="VBoxContainer/Layout/Left"]
layout_mode = 2
drag_to_rearrange_enabled = true
tabs_rearrange_group = 0
use_hidden_tabs_for_min_size = true
script = ExtResource("12_7mn0u")
[node name="SplitRight" type="HSplitContainer" parent="VBoxContainer/Layout"]
layout_mode = 2
split_offset = 133
[node name="ProjectsPanel" parent="VBoxContainer/Layout/SplitRight" instance=ExtResource("7_ih0ps")]
layout_mode = 2
[node name="Right" type="VSplitContainer" parent="VBoxContainer/Layout/SplitRight"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
split_offset = 312
[node name="Top" type="TabContainer" parent="VBoxContainer/Layout/SplitRight/Right"]
layout_mode = 2
drag_to_rearrange_enabled = true
tabs_rearrange_group = 0
use_hidden_tabs_for_min_size = true
script = ExtResource("12_7mn0u")
[node name="Bottom" type="TabContainer" parent="VBoxContainer/Layout/SplitRight/Right"]
[node name="Main" parent="VBoxContainer/Layout/FlexibleLayout" instance=ExtResource("7_ih0ps")]
layout_mode = 2
drag_to_rearrange_enabled = true
tabs_rearrange_group = 0
use_hidden_tabs_for_min_size = true
script = ExtResource("12_7mn0u")
anchors_preset = 0
offset_left = 18.0
offset_top = 4.0
offset_right = 263.0
offset_bottom = 32.0
[node name="StatusBar" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
Expand Down Expand Up @@ -264,12 +228,5 @@ libraries = {
"": SubResource("AnimationLibrary_kxf7t")
}
[connection signal="dragged" from="VBoxContainer/Layout" to="VBoxContainer/Layout" method="_on_Left_dragged"]
[connection signal="resized" from="VBoxContainer/Layout" to="VBoxContainer/Layout" method="_on_Layout_resized"]
[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="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"]
[connection signal="timeout" from="VBoxContainer/StatusBar/ClipBoardAnalyzer/Timer" to="VBoxContainer/StatusBar/ClipBoardAnalyzer" method="_on_Timer_timeout"]
21 changes: 18 additions & 3 deletions material_maker/main_window_layout.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends HSplitContainer
extends HBoxContainer

const PANEL_POSITIONS = {
TopLeft="Left/Top",
Expand Down Expand Up @@ -38,15 +38,19 @@ func toggle_side_panels() -> void:

func load_panels() -> void:
# Create panels
"""
for panel_pos in PANEL_POSITIONS.keys():
get_node(PANEL_POSITIONS[panel_pos]).set_tabs_rearrange_group(1)
"""
for panel in PANELS:
var node : Node = panel.scene.instantiate()
node.name = panel.name
if panel.has("parameters"):
for p in panel.parameters.keys():
node.set(p, panel.parameters[p])
panels[panel.name] = node
$FlexibleLayout.add(panel.name, node)
"""
var tab = get_node(PANEL_POSITIONS[panel.position])
var config_panel_name = panel.name.replace(" ", "_").replace("(", "_").replace(")", "_")
if mm_globals.config.has_section_key("layout", config_panel_name+"_location"):
Expand All @@ -57,7 +61,9 @@ func load_panels() -> void:
else:
tab.add_child(node)
node.set_meta("hidden", false)
"""
# Split positions
"""
await get_tree().process_frame
if mm_globals.config.has_section_key("layout", "LeftVSplitOffset"):
split_offset = mm_globals.config.get_value("layout", "LeftVSplitOffset")
Expand All @@ -67,8 +73,10 @@ func load_panels() -> void:
$SplitRight.split_offset = mm_globals.config.get_value("layout", "RightVSplitOffset")
if mm_globals.config.has_section_key("layout", "RightHSplitOffset"):
$SplitRight/Right.split_offset = mm_globals.config.get_value("layout", "RightHSplitOffset")
"""

func save_config() -> void:
return
for p in panels:
var config_panel_name = p.replace(" ", "_").replace("(", "_").replace(")", "_")
var location = panels[p].get_parent()
Expand All @@ -80,10 +88,12 @@ func save_config() -> void:
for l in PANEL_POSITIONS.keys():
if location == get_node(PANEL_POSITIONS[l]):
mm_globals.config.set_value("layout", config_panel_name+"_location", l)
"""
mm_globals.config.set_value("layout", "LeftVSplitOffset", split_offset)
mm_globals.config.set_value("layout", "LeftHSplitOffset", $Left.split_offset)
mm_globals.config.set_value("layout", "RightVSplitOffset", $SplitRight.split_offset)
mm_globals.config.set_value("layout", "RightHSplitOffset", $SplitRight/Right.split_offset)
"""

func get_panel(n) -> Control:
if panels.has(n):
Expand Down Expand Up @@ -112,11 +122,14 @@ func set_panel_visible(panel_name : String, v : bool) -> void:

func change_mode(m : String) -> void:
current_mode = m
return
for p in panels:
set_panel_visible(p, !panels[p].get_meta("hidden"))
update_panels()

func update_panels() -> void:
return
"""
var left_width = $Left.size.x
var left_requested = left_width
var right_width = $SplitRight/Right.size.x
Expand Down Expand Up @@ -146,6 +159,7 @@ func update_panels() -> void:
split_offset += left_requested - left_width + right_requested - right_width
clamp_split_offset()
$SplitRight.split_offset += right_width - right_requested
"""

func _on_Left_dragged(_offset : int) -> void:
$Left.clamp_split_offset()
Expand All @@ -157,6 +171,7 @@ func _on_tab_changed(_tab):
update_panels()

func _on_Layout_resized():
pass
# warning-ignore:narrowing_conversion
split_offset -= size.x - previous_width
previous_width = size.x
#split_offset -= size.x - previous_width
#previous_width = size.x
39 changes: 25 additions & 14 deletions material_maker/projects_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,30 @@ atlas = ExtResource("5_1qnqj")
region = Rect2(96, 64, 32, 31)

[node name="ProjectsPanel" type="Control"]
clip_contents = true
custom_minimum_size = Vector2(100, 100)
layout_mode = 3
anchors_preset = 0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
script = ExtResource("1_m3usq")

[node name="BackgroundPreviews" type="Control" parent="."]
layout_mode = 1
anchors_preset = 0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 28.0

[node name="Preview2D" parent="BackgroundPreviews" instance=ExtResource("2_oiaqi")]
visible = false
material = SubResource("ShaderMaterial_8fw7q")
layout_mode = 1
offset_right = 0.0
offset_bottom = 0.0
offset_right = 64.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
shader = "uniform vec2 preview_2d_size = vec2(100.0, 100.0);
Expand Down Expand Up @@ -76,33 +81,39 @@ ui_path = NodePath("../../PreviewUI/Panel/HBoxContainer/Preview3DUI")

[node name="Projects" type="Panel" parent="."]
self_modulate = Color(1, 1, 1, 0)
layout_mode = 0
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = 5.0
offset_bottom = 5.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("4_mpinq")

[node name="TabBar" type="TabBar" parent="Projects"]
layout_mode = 0
offset_right = 950.0
offset_bottom = 24.0
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
tab_close_display_policy = 1

[node name="CrashRecoveryTimer" type="Timer" parent="Projects"]
wait_time = 15.0
autostart = true

[node name="PreviewUI" type="HBoxContainer" parent="."]
layout_mode = 0
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 1.0
offset_top = -45.0
offset_right = 331.0
offset_bottom = -13.0
offset_left = 5.5
offset_top = -53.5
offset_right = 335.5
offset_bottom = -13.5
grow_vertical = 0
mouse_filter = 2

[node name="Preview2DButton" type="Button" parent="PreviewUI"]
Expand Down

0 comments on commit 9c3785b

Please sign in to comment.