Améliorationdes fenetres et fix du plugin de fenetre qui repetait mal les texture a cause du filtre manquant sur la texture créer par le script.

This commit is contained in:
osquallo 2018-08-16 14:53:10 +02:00
parent d6a355142a
commit d573beff97
6 changed files with 125 additions and 74 deletions

View file

@ -5,11 +5,22 @@ export(bool) var is_resizable = true
export(bool) var is_borderless = false
export(String) var title = "Window"
export(Color) var background_color = Color( 1.0, 1.0, 1.0, 1.0 )
export(String) var background_texture = "res://assets/GUI/images/background_test.png"
signal window_clicked( window )
var current_rect_size = Vector2( 0, 0 )
var current_rect_position = Vector2( -1, -1 )
var is_resizing = false
var is_moving = false
func set_mouse_pass_to_children( node ):
for child in node.get_children():
set_mouse_pass_to_children( child )
if node is Control:
node.mouse_filter = MOUSE_FILTER_PASS
#func _ready():
func _enter_tree():
###
@ -21,6 +32,9 @@ func _enter_tree():
self.set( "custom_constants/margin_top", 0)
self.set( "custom_constants/margin_left", 0)
self.set( "custom_constants/margin_bottom", 0)
self.connect ( "gui_input", self, "_on_window_gui_input" )
###
###
# Background
@ -29,22 +43,24 @@ func _enter_tree():
background = NinePatchRect.new()
background.name = "Background"
var background_image = Image.new()
if not background_image.load( "res://assets/GUI/images/bg2.jpg" ):
print("Erreur lors du chargement de l'image: res://assets/GUI/images/bg2.jpg" )
if not background_image.load( background_texture ):
print("Erreur lors du chargement de l'image: "+background_texture )
background.texture = ImageTexture.new()
background.texture.create_from_image( background_image )
background.texture.flags = Texture.FLAG_FILTER | Texture.FLAG_REPEAT
background.axis_stretch_horizontal = NinePatchRect.AXIS_STRETCH_MODE_TILE
background.axis_stretch_vertical = NinePatchRect.AXIS_STRETCH_MODE_TILE
background.size_flags_horizontal = SIZE_EXPAND_FILL
background.size_flags_vertical = SIZE_EXPAND_FILL
background.region_rect = Rect2( 0, 0, 0, 0 )
# background.rect_clip_content = true
# background.region_rect = Rect2( 0, 0, 0, 0 )
background.patch_margin_left = 4
background.patch_margin_top = 32
background.patch_margin_right = 4
background.patch_margin_bottom = 3
background.patch_margin_bottom = 4
background.self_modulate = background_color
@ -67,7 +83,7 @@ func _enter_tree():
###
# Header
var header
if not self.has_node( "Header" ):
if not v_box_container.has_node( "Header" ):
header = MarginContainer.new()
header.name = "Header"
header.size_flags_horizontal = SIZE_EXPAND_FILL
@ -87,7 +103,7 @@ func _enter_tree():
###
var header_box
# Header/HBoxContainer
if not self.has_node( "HBoxContainer" ):
if not header.has_node( "HBoxContainer" ):
header_box = HBoxContainer.new()
header_box.name = "HBoxContainer"
header_box.size_flags_horizontal = SIZE_EXPAND_FILL
@ -100,7 +116,7 @@ func _enter_tree():
###
# Quit
var quit_button
if not self.has_node( "Quit" ):
if not header_box.has_node( "Quit" ):
quit_button = TextureButton.new()
quit_button.name = "Quit"
quit_button.size_flags_horizontal = SIZE_SHRINK_END
@ -118,7 +134,7 @@ func _enter_tree():
###
# Close
var close_button = TextureButton.new()
if not self.has_node( "Close" ):
if not header_box.has_node( "Close" ):
close_button = TextureButton.new()
close_button.name = "Close"
close_button.size_flags_horizontal = SIZE_SHRINK_END
@ -136,7 +152,7 @@ func _enter_tree():
###
# Open
var open_button
if not self.has_node( "Open" ):
if not header_box.has_node( "Open" ):
open_button = TextureButton.new()
open_button.name = "Open"
open_button.size_flags_horizontal = SIZE_SHRINK_END
@ -155,7 +171,7 @@ func _enter_tree():
###
# Title Label
var title_label
if not self.has_node( "Label" ):
if not header_box.has_node( "Label" ):
title_label = Label.new()
title_label.name = "Label"
title_label.text = title
@ -169,7 +185,7 @@ func _enter_tree():
###
# Content
var content
if not self.has_node( "Content" ):
if not v_box_container.has_node( "Content" ):
content = MarginContainer.new()
content.name = "Content"
content.size_flags_horizontal = SIZE_EXPAND_FILL
@ -184,7 +200,7 @@ func _enter_tree():
###
# Footer
var footer
if not self.has_node( "Footer" ):
if not v_box_container.has_node( "Footer" ):
footer = MarginContainer.new()
footer.name = "Footer"
footer.size_flags_horizontal = SIZE_FILL
@ -199,7 +215,7 @@ func _enter_tree():
###
# Header/HBoxContainer
var footer_box
if not self.has_node( "HBoxContainer" ):
if not footer.has_node( "HBoxContainer" ):
footer_box = HBoxContainer.new()
footer_box.name = "HBoxContainer"
footer_box.size_flags_horizontal = SIZE_FILL
@ -210,7 +226,7 @@ func _enter_tree():
###
# Open
var resize_button
if not self.has_node( "Resize" ):
if not footer_box.has_node( "Resize" ):
resize_button = TextureButton.new()
resize_button.name = "Resize"
resize_button.size_flags_horizontal = SIZE_EXPAND | SIZE_SHRINK_END
@ -245,7 +261,9 @@ func _enter_tree():
if not is_resizable:
$VBoxContainer/Footer/HBoxContainer/Resize.visible = false
func _ready():
set_mouse_pass_to_children( self )
func _on_Window_mouse_entered():
print("mouse_entered")
@ -309,17 +327,35 @@ func _input( event ):
if event is InputEventMouseMotion and is_resizing:
var delta = event.relative
self.rect_size += delta
#
# var mouse_position = get_viewport().get_mouse_position()
# var size_modulo = Vector2( int(self.rect_size.x) % 2, int(self.rect_size.y) % 2 )
# self.rect_size -= size_modulo
# get_viewport().warp_mouse( mouse_position - size_modulo )
func _on_Header_gui_input(ev):
func check_if_clicked( event ):
if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 :
emit_signal( "window_clicked", self )
func _on_Header_gui_input( event ):
check_if_clicked( event )
if is_movable:
if is_moving and ev is InputEventMouseButton and not ev.pressed:
if is_moving and event is InputEventMouseButton and not event.pressed:
is_moving = false
elif not is_moving and ev is InputEventMouseButton and ev.pressed:
elif not is_moving and event is InputEventMouseButton and event.pressed:
is_moving = true
if ev is InputEventMouseMotion and is_moving:
var delta = ev.relative
if event is InputEventMouseMotion and is_moving:
var delta = event.relative
self.rect_position += delta
# self.rect_position -= Vector2( int(self.rect_size.x) % 2, int(self.rect_size.y) % 2 )
# get_viewport().warp_mouse( get_viewport().get_mouse_position() - Vector2( int(get_viewport().get_mouse_position().x) % 2, int(get_viewport().get_mouse_position().y) % 2 ) )
func _on_window_gui_input( event ):
check_if_clicked( event )
func load_from_file( config_file ):
if config_file.has_section( self.name ):
self.rect_position = config_file.get_value( self.name, "position" )

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -91,9 +91,9 @@ anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 237.0
margin_left = 238.0
margin_top = 15.0
margin_right = 526.0
margin_right = 527.0
margin_bottom = 143.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
@ -136,10 +136,11 @@ patch_margin_right = 4
patch_margin_bottom = 4
axis_stretch_horizontal = 1
axis_stretch_vertical = 1
_sections_unfolded = [ "Axis Stretch", "Material", "Mouse", "Patch Margin", "Rect", "Size Flags", "Theme", "Visibility" ]
_sections_unfolded = [ "Axis Stretch", "Grow Direction", "Material", "Mouse", "Patch Margin", "Rect", "Size Flags", "Theme", "Visibility" ]
[node name="VBoxContainer" type="VBoxContainer" parent="Windows/Test" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -158,6 +159,7 @@ _sections_unfolded = [ "Mouse", "Rect", "Size Flags", "Visibility", "custom_cons
[node name="Header" type="MarginContainer" parent="Windows/Test/VBoxContainer" index="0"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -178,6 +180,7 @@ _sections_unfolded = [ "Margin", "Mouse", "Rect", "Size Flags", "custom_constant
[node name="HBoxContainer" type="HBoxContainer" parent="Windows/Test/VBoxContainer/Header" index="0"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -288,7 +291,6 @@ _sections_unfolded = [ "Hint", "Mouse", "Size Flags" ]
[node name="Content" type="MarginContainer" parent="Windows/Test/VBoxContainer" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -298,7 +300,7 @@ margin_right = 289.0
margin_bottom = 104.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -306,7 +308,7 @@ custom_constants/margin_right = 8
custom_constants/margin_top = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8
_sections_unfolded = [ "Rect", "Size Flags", "custom_constants" ]
_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ]
[node name="RichTextLabel" type="RichTextLabel" parent="Windows/Test/VBoxContainer/Content" index="0"]
@ -321,7 +323,7 @@ margin_bottom = 72.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
focus_mode = 2
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
@ -336,10 +338,11 @@ scroll_active = true
scroll_following = true
selection_enabled = true
override_selected_font_color = false
_sections_unfolded = [ "BBCode", "Rect", "Size Flags" ]
_sections_unfolded = [ "BBCode", "Mouse", "Rect", "Size Flags" ]
[node name="Footer" type="MarginContainer" parent="Windows/Test/VBoxContainer" index="2"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -404,15 +407,14 @@ _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ]
[node name="TestBorderless" type="MarginContainer" parent="Windows" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 266.0
margin_top = 154.0
margin_top = 153.0
margin_right = 513.0
margin_bottom = 341.0
margin_bottom = 340.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
hint_tooltip = "Tooltips test."
@ -452,12 +454,13 @@ patch_margin_left = 4
patch_margin_top = 32
patch_margin_right = 4
patch_margin_bottom = 4
axis_stretch_horizontal = 1
axis_stretch_vertical = 1
axis_stretch_horizontal = 2
axis_stretch_vertical = 2
_sections_unfolded = [ "Axis Stretch", "Material", "Patch Margin", "Rect", "Size Flags", "Theme", "Visibility" ]
[node name="VBoxContainer" type="VBoxContainer" parent="Windows/TestBorderless" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -472,10 +475,11 @@ size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 0
alignment = 0
_sections_unfolded = [ "Rect", "Size Flags", "Visibility", "custom_constants" ]
_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "Visibility", "custom_constants" ]
[node name="Header" type="MarginContainer" parent="Windows/TestBorderless/VBoxContainer" index="0"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -484,7 +488,7 @@ margin_right = 247.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 13
size_flags_horizontal = 1
size_flags_vertical = 0
@ -496,6 +500,7 @@ _sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ]
[node name="HBoxContainer" type="HBoxContainer" parent="Windows/TestBorderless/VBoxContainer/Header" index="0"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -606,7 +611,6 @@ _sections_unfolded = [ "Hint", "Mouse", "Size Flags" ]
[node name="Content" type="MarginContainer" parent="Windows/TestBorderless/VBoxContainer" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -616,7 +620,7 @@ margin_right = 247.0
margin_bottom = 163.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -624,7 +628,7 @@ custom_constants/margin_right = 8
custom_constants/margin_top = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8
_sections_unfolded = [ "Rect", "Size Flags", "custom_constants" ]
_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ]
[node name="VBoxContainer" type="VBoxContainer" parent="Windows/TestBorderless/VBoxContainer/Content" index="0"]
@ -643,6 +647,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Mouse" ]
[node name="RichTextLabel" type="RichTextLabel" parent="Windows/TestBorderless/VBoxContainer/Content/VBoxContainer" index="0"]
@ -655,7 +660,7 @@ margin_bottom = 59.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
focus_mode = 2
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
@ -670,7 +675,7 @@ scroll_active = true
scroll_following = true
selection_enabled = true
override_selected_font_color = false
_sections_unfolded = [ "BBCode", "Focus", "Rect", "Size Flags" ]
_sections_unfolded = [ "BBCode", "Focus", "Mouse", "Rect", "Size Flags" ]
[node name="RichTextLabel2" type="RichTextLabel" parent="Windows/TestBorderless/VBoxContainer/Content/VBoxContainer" index="1"]
@ -684,7 +689,7 @@ margin_bottom = 123.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
focus_mode = 2
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 5
size_flags_vertical = 11
@ -699,7 +704,7 @@ scroll_active = true
scroll_following = true
selection_enabled = true
override_selected_font_color = false
_sections_unfolded = [ "BBCode", "Focus", "Rect", "Size Flags" ]
_sections_unfolded = [ "BBCode", "Focus", "Mouse", "Rect", "Size Flags" ]
[node name="Footer" type="MarginContainer" parent="Windows/TestBorderless/VBoxContainer" index="2"]
@ -739,6 +744,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Mouse" ]
[node name="Resize" type="TextureButton" parent="Windows/TestBorderless/VBoxContainer/Footer/HBoxContainer" index="0"]
@ -752,7 +758,7 @@ margin_bottom = 16.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 12
size_flags_horizontal = 10
size_flags_vertical = 2
@ -766,6 +772,7 @@ _sections_unfolded = [ "Mouse", "Size Flags", "Textures" ]
[node name="Music" type="MarginContainer" parent="Windows" index="2"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
@ -979,7 +986,7 @@ margin_right = 129.0
margin_bottom = 106.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -987,7 +994,7 @@ custom_constants/margin_right = 8
custom_constants/margin_top = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8
_sections_unfolded = [ "Rect", "Size Flags", "custom_constants" ]
_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ]
[node name="RichTextLabel" type="RichTextLabel" parent="Windows/Music/VBoxContainer/Content" index="0"]
@ -1003,7 +1010,7 @@ margin_bottom = 74.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
focus_mode = 2
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
@ -1108,14 +1115,16 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
script = ExtResource( 10 )
_sections_unfolded = [ "custom_constants" ]
__meta__ = {
"_editor_icon": ExtResource( 11 )
}
is_movable = true
is_resizable = true
is_borderless = false
title = "Window test"
title = "Test window plugin"
background_color = Color( 0.808594, 0.808594, 0.808594, 1 )
background_texture = "res://assets/GUI/images/background_test.png"
[node name="Music" parent="." index="3" instance=ExtResource( 9 )]
@ -1368,6 +1377,8 @@ flat = false
align = 1
_sections_unfolded = [ "Size Flags" ]
[connection signal="gui_input" from="Windows/Test" to="Windows/Test" method="_on_window_gui_input"]
[connection signal="gui_input" from="Windows/Test/VBoxContainer/Header" to="Windows/Test" method="_on_Header_gui_input"]
[connection signal="pressed" from="Windows/Test/VBoxContainer/Header/HBoxContainer/Quit" to="Windows/Test" method="_on_Quit_pressed"]
@ -1378,6 +1389,8 @@ _sections_unfolded = [ "Size Flags" ]
[connection signal="pressed" from="Windows/Test/VBoxContainer/Footer/HBoxContainer/Resize" to="Windows/Test" method="_on_Resize_pressed"]
[connection signal="gui_input" from="Windows/TestBorderless" to="Windows/TestBorderless" method="_on_window_gui_input"]
[connection signal="gui_input" from="Windows/TestBorderless/VBoxContainer/Header" to="Windows/TestBorderless" method="_on_Header_gui_input"]
[connection signal="pressed" from="Windows/TestBorderless/VBoxContainer/Header/HBoxContainer/Quit" to="Windows/TestBorderless" method="_on_Quit_pressed"]
@ -1386,8 +1399,12 @@ _sections_unfolded = [ "Size Flags" ]
[connection signal="pressed" from="Windows/TestBorderless/VBoxContainer/Header/HBoxContainer/Open" to="Windows/TestBorderless" method="_on_Open_pressed"]
[connection signal="gui_input" from="Windows/TestBorderless/VBoxContainer/Footer" to="Windows/TestBorderless" method="_on_footer_gui_input"]
[connection signal="pressed" from="Windows/TestBorderless/VBoxContainer/Footer/HBoxContainer/Resize" to="Windows/TestBorderless" method="_on_Resize_pressed"]
[connection signal="gui_input" from="Windows/Music" to="Windows/Music" method="_on_window_gui_input"]
[connection signal="gui_input" from="Windows/Music/VBoxContainer/Header" to="Windows/Music" method="_on_Header_gui_input"]
[connection signal="pressed" from="Windows/Music/VBoxContainer/Header/HBoxContainer/Quit" to="Windows/Music" method="_on_Quit_pressed"]

View file

@ -11,6 +11,12 @@ var current_rect_position = Vector2( -1, -1 )
var is_resizing = false
var is_moving = false
func set_mouse_pass_to_children( node ):
for child in node.get_children():
set_mouse_pass_to_children( child )
if node is Control:
node.mouse_filter = MOUSE_FILTER_PASS
func _ready():
current_rect_size = self.rect_min_size
@ -28,6 +34,9 @@ func _ready():
# $VBoxContainer/Header/HBoxContainer/Label.visible = true
if not is_resizable:
$VBoxContainer/Footer/HBoxContainer/Resize.visible = false
set_mouse_pass_to_children( self )
func _on_Window_mouse_entered():
print("mouse_entered")
@ -85,10 +94,7 @@ func _on_Open_pressed():
func _on_Resize_pressed():
is_resizing = true
func _input( event ):
func _input( event ):
if is_resizable:
if is_resizing and event is InputEventMouseButton and not event.pressed:
is_resizing = false
@ -96,11 +102,14 @@ func _input( event ):
var delta = event.relative
self.rect_size += delta
func check_if_clicked( event ):
if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 :
emit_signal( "window_clicked", self )
func _on_Header_gui_input( event ):
if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 :
put_above_other()
check_if_clicked( event )
if is_movable:
if is_moving and event is InputEventMouseButton and not event.pressed:
@ -143,23 +152,10 @@ func save_to_file( config_file ):
config_file.set_value(self.name, "opened", false)
config_file.set_value(self.name, "borderless", is_borderless)
func put_above_other():
# var index = 0
# for child in get_parent().get_children():
# get_parent().move_child(child, index)
# index += 1
# get_parent().move_child(self, index)
# var parent = self.get_parent()
# var last_child = parent.get_child( parent.get_child_count()-1 )
# if not self.is_greater_than( last_child ):
# parent.remove_child( self )
# parent.add_child_below_node( last_child, self )
# self.raise()
emit_signal( "window_clicked", self )
pass
func _on_window_gui_input( event ):
check_if_clicked( event )
func _on_footer_gui_input( event ):
# check_if_clicked( event )
pass

View file

@ -11,4 +11,6 @@ func _on_window_clicked( window ):
for child in self.get_children():
self.move_child(child, index)
index += 1
self.move_child(window, index)
self.move_child(window, index)
# TODO deplacer le deplacement des fenetres ici et tout ce qui est management des fenetre et non de leur contenu.