Skip to content

Commit

Permalink
Merge pull request #685 from Jowan-Spooner/improve_mm_ui
Browse files Browse the repository at this point in the history
Improve UI styling possibilities
  • Loading branch information
RodZill4 authored Jul 1, 2024
2 parents 543bd29 + e8f0593 commit 3a8c6d2
Show file tree
Hide file tree
Showing 36 changed files with 986 additions and 443 deletions.
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_layout.gd
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class FlexWindow:
if first_panel:
position = Vector2i(first_panel.get_global_rect().position)+first_panel.get_window().position
size = first_panel.size
theme = main_control.owner.theme
panel = Control.new()
add_child(panel)
panel.position = Vector2i(0, 0)
Expand Down
22 changes: 15 additions & 7 deletions addons/flexible_layout/flexible_tab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ extends Container


var flex_panel : Control
var updating : bool = false


func _ready():
$Container/Close.texture_normal = get_theme_icon("close", "TabBar")
update()

func _notification(what):
match what:
NOTIFICATION_THEME_CHANGED:
update()

func init(fp : Control):
flex_panel = fp
Expand All @@ -15,11 +22,14 @@ func get_flex_layout():
var flex_tab = get_parent().get_parent().get_flex_tab()
return flex_tab.flexible_layout

func _draw():
var is_current : bool = (get_index() == get_parent().get_parent().current)
draw_style_box(get_theme_stylebox("tab_selected" if is_current else "tab_unselected", "TabBar"), Rect2(Vector2(), size))
$Container/Undock.visible = is_current and get_flex_layout().main_control.allow_undock
$Container/Close.visible = is_current
func update():
if not updating:
updating = true
var is_current: bool = (get_index() == get_parent().get_parent().current)
add_theme_stylebox_override("panel", get_theme_stylebox("tab_selected" if is_current else "tab_unselected", "MM_FlexibleTab"))
$Container/Undock.visible = is_current and get_flex_layout().main_control.allow_undock
$Container/Close.visible = is_current
updating = false

func _on_undock_pressed():
get_flex_layout().undock(flex_panel)
Expand All @@ -35,5 +45,3 @@ func _gui_input(event):

func _get_drag_data(_position):
return preload("res://addons/flexible_layout/flexible_layout.gd").PanelInfo.new(flex_panel)


8 changes: 3 additions & 5 deletions addons/flexible_layout/flexible_tab.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_bok24"]
size = Vector2(16, 16)

[node name="Tab" type="MarginContainer"]
[node name="Tab" type="PanelContainer"]
offset_right = 41.0
offset_bottom = 26.0
size_flags_horizontal = 0
size_flags_vertical = 0
mouse_filter = 0
theme_override_constants/margin_left = 3
theme_override_constants/margin_right = 3
size_flags_vertical = 8
theme_type_variation = &"MM_FlexibleTab"
script = ExtResource("1")

[node name="Container" type="HBoxContainer" parent="."]
Expand Down
5 changes: 2 additions & 3 deletions addons/flexible_layout/flexible_tabs.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Control
extends Container


var flex_tab : WeakRef
Expand All @@ -24,7 +24,6 @@ func add(ft : Control):
var tab = load("res://addons/flexible_layout/flexible_tab.tscn").instantiate()
tab.init(ft)
$Tabs.add_child(tab)
custom_minimum_size.y = $Tabs.get_minimum_size().y
if current == -1:
set_current(0)
else:
Expand All @@ -51,7 +50,7 @@ func set_current(c : int):
current = c
for i in range($Tabs.get_child_count()):
$Tabs.get_child(i).flex_panel.visible = (i == current)
$Tabs.get_child(i).queue_redraw()
$Tabs.get_child(i).update()

func _on_resized():
#print("%s: %s - %s" % [ str(self), str(position), str(size) ])
Expand Down
11 changes: 5 additions & 6 deletions addons/flexible_layout/flexible_tabs.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

[ext_resource type="Script" path="res://addons/flexible_layout/flexible_tabs.gd" id="1"]

[node name="TabBar" type="Control"]
clip_contents = true
layout_mode = 3
anchors_preset = 0
[node name="TabBar" type="ScrollContainer"]
horizontal_scroll_mode = 3
vertical_scroll_mode = 0
script = ExtResource("1")

[node name="Tabs" type="HBoxContainer" parent="."]
clip_contents = true
layout_mode = 0
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
theme_override_constants/separation = 0
theme_type_variation = &"MM_FlexibleTab"
1 change: 0 additions & 1 deletion addons/material_maker/engine/nodes/gen_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class ShaderCode:
add_global(g.code, g.source)

func get_globals_string(code : String = "") -> String:
assert(code != "")
var rv : String = ""
if true:
var reverse_globals : Array[GlobalDefs] = globals.duplicate()
Expand Down
9 changes: 6 additions & 3 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Panel
extends Control

var quitting : bool = false

Expand Down Expand Up @@ -45,7 +45,7 @@ const IDLE_FPS_LIMIT_MAX = 100

const RECENT_FILES_COUNT = 15

const THEMES = [ "Dark", "Default", "Green", "Birch", "Mangosteen", "Light" ]
const THEMES = [ "Dark", "Default", "Green", "Birch", "Mangosteen", "Light", "Modern"]

const MENU : Array[Dictionary] = [
{ menu="File/New material", command="new_material", shortcut="Control+N" },
Expand Down Expand Up @@ -141,7 +141,7 @@ func _ready() -> void:
get_window().position = mm_globals.config.get_value("window", "position")
if mm_globals.config.has_section_key("window", "size"):
get_window().size = mm_globals.config.get_value("window", "size")

# Restore the theme
var theme_name : String = "default"
if mm_globals.config.has_section_key("window", "theme"):
Expand Down Expand Up @@ -228,6 +228,9 @@ func _ready() -> void:
await get_tree().process_frame
new_material()

size = get_window().size
position = Vector2.ZERO
set_anchors_preset(Control.PRESET_FULL_RECT)
update_menus()

mm_logger.message("Material Maker "+ProjectSettings.get_setting("application/config/actual_release"))
Expand Down
28 changes: 13 additions & 15 deletions material_maker/main_window.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,20 @@ _data = {
"show": SubResource("7")
}
[node name="MainWindow" type="Panel" groups=["preview"]]
[node name="MainWindow" type="PanelContainer" groups=["preview"]]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -160.0
offset_top = -21.0
offset_right = 160.0
offset_bottom = 15.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource("10")
theme_type_variation = &"MM_MainBackground"
script = ExtResource("1")
[node name="NodeLibraryManager" type="Node" parent="."]
Expand Down Expand Up @@ -127,13 +134,7 @@ config_section = "brush_lib"
[node name="EnvironmentManager" parent="." instance=ExtResource("13")]
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 6.0
offset_top = 6.0
offset_right = -6.0
offset_bottom = -6.0
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
Expand Down Expand Up @@ -178,10 +179,11 @@ scroll_following = true
layout_mode = 2
[node name="Tip" type="RichTextLabel" parent="VBoxContainer/StatusBar"]
custom_minimum_size = Vector2(0, 28)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
bbcode_enabled = true
fit_content = true
scroll_active = false
[node name="Timer" type="Timer" parent="VBoxContainer/StatusBar/Tip"]
Expand Down Expand Up @@ -237,12 +239,8 @@ script = ExtResource("9")
visible = false
[node name="UndoRedoLabel" type="Label" parent="."]
layout_mode = 0
anchor_left = 0.5
anchor_right = 0.5
offset_left = -82.5
offset_right = 82.5
offset_bottom = 22.0
modulate = Color(1, 1, 1, 0)
layout_mode = 2
text = "Undo/Redo action added"
script = SubResource("6")
Expand Down
47 changes: 36 additions & 11 deletions material_maker/nodes/base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static func wrap_string(s : String, l : int = 50) -> String:

func _ready() -> void:
super._ready()
_notification(NOTIFICATION_THEME_CHANGED)
gui_input.connect(self._on_gui_input)
update.call_deferred()

Expand Down Expand Up @@ -125,6 +126,35 @@ func update():
buffer_button.texture_normal = BUFFER_ICON if generator.get_buffers(MMGenBase.BUFFERS_PAUSED).is_empty() else BUFFER_PAUSED_ICON
buffer_button.tooltip_text = tr("%d buffer(s), %d paused") % [ generator.get_buffers().size(), generator.get_buffers(MMGenBase.BUFFERS_PAUSED).size() ]

func _notification(what : int) -> void:
if what == NOTIFICATION_THEME_CHANGED:
on_theme_changed()

var portgroup_width : int
var portgroup_stylebox : StyleBox

func on_theme_changed() -> void:
portgroup_width = get_theme_constant("width", "MM_NodePortGroup")
portgroup_stylebox = get_theme_stylebox("panel", "MM_NodePortGroup")
queue_redraw()

func _draw_port(slot_index: int, position: Vector2i, left: bool, color: Color):
if left:
var inputs = generator.get_input_defs()
if slot_index < inputs.size() and inputs[slot_index].has("group_size") and inputs[slot_index].group_size > 1:
var conn_pos1 = get_input_port_position(slot_index)
# warning-ignore:narrowing_conversion
var conn_pos2 = get_input_port_position(min(slot_index+inputs[slot_index].group_size-1, inputs.size()-1))
draw_portgroup_stylebox(conn_pos1, conn_pos2)
else:
var outputs = generator.get_output_defs()
if slot_index < outputs.size() and outputs[slot_index].has("group_size") and outputs[slot_index].group_size > 1:
# warning-ignore:narrowing_conversion
var conn_pos1 = get_output_port_position(slot_index)
var conn_pos2 = get_output_port_position(min(slot_index+outputs[slot_index].group_size-1, outputs.size()-1))
draw_portgroup_stylebox(conn_pos1, conn_pos2)
draw_circle(position, 5, color, true, -1, true)

func _draw() -> void:
var color : Color = get_theme_color("title_color")
# warning-ignore:narrowing_conversion
Expand All @@ -133,11 +163,6 @@ func _draw() -> void:
if generator != null and generator.model == null and (generator is MMGenShader or generator is MMGenGraph):
draw_texture_rect(CUSTOM_ICON, Rect2(3, 8, 7, 7), false, color)
for i in range(inputs.size()):
if inputs[i].has("group_size") and inputs[i].group_size > 1:
var conn_pos1 = get_input_port_position(i)
# warning-ignore:narrowing_conversion
var conn_pos2 = get_input_port_position(min(i+inputs[i].group_size-1, inputs.size()-1))
draw_line(conn_pos1, conn_pos2, color)
if show_inputs:
var string : String = TranslationServer.translate(inputs[i].shortdesc) if inputs[i].has("shortdesc") else TranslationServer.translate(inputs[i].name)
var string_size : Vector2 = font.get_string_size(string)
Expand All @@ -155,11 +180,6 @@ func _draw() -> void:
preview_port[1] = -1
preview_locked[0] = preview_locked[0] || preview_locked[1]
for i in range(outputs.size()):
if outputs[i].has("group_size") and outputs[i].group_size > 1:
# warning-ignore:narrowing_conversion
var conn_pos1 = get_output_port_position(i)
var conn_pos2 = get_output_port_position(min(i+outputs[i].group_size-1, outputs.size()-1))
draw_line(conn_pos1, conn_pos2, color)
var j = -1
if i == preview_port[0]:
j = 0
Expand All @@ -178,6 +198,11 @@ func _draw() -> void:
var time_color : Color = get_rendering_time_color(generator.rendering_time)
draw_string(font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, time_color)

func draw_portgroup_stylebox(first_port : Vector2, last_port : Vector2) -> void:
var stylebox_position: Vector2 = first_port + Vector2(-0.5,-0.5) * portgroup_width
var stylebox_size: Vector2 = Vector2(portgroup_width, last_port.y - first_port.y + portgroup_width)
draw_style_box(portgroup_stylebox, Rect2(stylebox_position, stylebox_size))

func set_generator(g) -> void:
super.set_generator(g)
g.rendering_time_updated.connect(self.update_rendering_time)
Expand Down Expand Up @@ -283,7 +308,7 @@ func get_slot_tooltip(pos : Vector2, io : Dictionary = {}) -> String:
if input_def.has("longdesc"):
return MMGraphNodeBase.wrap_string(TranslationServer.translate(input_def.longdesc))
"output":

var output_def = generator.get_output_defs()[io.index]
if output_def.has("longdesc"):
return MMGraphNodeBase.wrap_string(TranslationServer.translate(output_def.longdesc))
Expand Down
Loading

0 comments on commit 3a8c6d2

Please sign in to comment.